/* ───────── Design tokens (taken from the poster) ───────── */
:root {
  --ink: #0b0a09;
  --char: #171513;
  --char-2: #221f1c;
  --paper: #efe5cf;
  --paper-2: #e3d6ba;
  --paper-ink: #16120f;
  --red: #c8161d;
  --red-deep: #8f0d12;
  --gold: #e8a52a;
  --brass: #b8862f;
  --muted: #a99f8f;
  --line: rgba(232, 165, 42, .35);

  --font-display: "Avenir Next Condensed", "Roboto Condensed", "sans-serif-condensed",
                  "Arial Narrow", "Helvetica Neue", Impact, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --gutter: 16px;
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  /* quilted diamond texture + candle glow, like the poster's backdrop */
  background:
    radial-gradient(120% 60% at 50% 110%, rgba(232, 140, 30, .16), transparent 60%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .025) 0 1px, transparent 1px 22px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, .025) 0 1px, transparent 1px 22px),
    var(--ink);
  background-attachment: fixed;
  overscroll-behavior: none;
}

img { display: block; max-width: 100%; }
button, label { font: inherit; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ───────── App shell & screens ───────── */
.app {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    calc(var(--safe-t) + 18px)
    calc(var(--safe-r) + var(--gutter))
    calc(var(--safe-b) + 20px)
    calc(var(--safe-l) + var(--gutter));
}
.screen.is-active { display: flex; animation: screen-in .28s ease-out both; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ───────── Buttons ───────── */
.btn {
  appearance: none;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 0 20px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 700;
  font-stretch: condensed;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .12s ease, filter .12s ease, background-color .12s ease;
}
.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.btn--xl { min-height: 60px; font-size: 21px; }
.btn--lg { min-height: 54px; font-size: 18px; }

.btn--primary {
  color: #fff;
  background: linear-gradient(180deg, #df2229, var(--red) 55%, #a8121a);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 10px 24px -8px rgba(200, 22, 29, .7);
}
.btn--light {
  color: var(--paper-ink);
  background: var(--paper);
  box-shadow: 0 8px 20px -10px rgba(0, 0, 0, .8);
}
.btn--ghost {
  color: var(--paper);
  background: rgba(255, 255, 255, .06);
  box-shadow: 0 0 0 1.5px rgba(239, 229, 207, .35) inset;
}

.btn__icon { width: 22px; height: 22px; fill: currentColor; flex: none; }

.iconbtn {
  appearance: none;
  border: 0;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--paper);
  background: rgba(255, 255, 255, .08);
  cursor: pointer;
  touch-action: manipulation;
}
.iconbtn svg { width: 22px; height: 22px; fill: currentColor; }
.iconbtn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ───────── Torn-paper card (echoes the poster's notice) ───────── */
.paper {
  position: relative;
  color: var(--paper-ink);
  background:
    radial-gradient(140% 90% at 20% 0%, rgba(255, 255, 255, .55), transparent 55%),
    linear-gradient(180deg, var(--paper), var(--paper-2));
  padding: 22px 22px 24px;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, .55));
  clip-path: polygon(
    0% 4px, 6% 0%, 13% 3px, 21% 1px, 30% 4px, 38% 0%, 47% 3px, 55% 1px, 63% 4px,
    71% 0%, 80% 3px, 88% 1px, 95% 4px, 100% 2px,
    100% calc(100% - 3px), 94% 100%, 86% calc(100% - 4px), 78% calc(100% - 1px),
    69% calc(100% - 4px), 61% 100%, 52% calc(100% - 3px), 44% calc(100% - 1px),
    35% calc(100% - 4px), 27% 100%, 18% calc(100% - 3px), 9% calc(100% - 1px),
    3% calc(100% - 4px), 0% 100%
  );
}
.paper__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-stretch: condensed;
  text-transform: uppercase;
  font-size: clamp(34px, 10.5vw, 44px);
  line-height: .95;
  letter-spacing: .005em;
}
.paper__title--sm { font-size: clamp(24px, 7.2vw, 30px); line-height: 1.02; }
.paper__sub {
  margin: 10px 0 0;
  font-size: 17px;
  line-height: 1.4;
  color: #3a3129;
}
.paper__sub:empty { display: none; }

.fineprint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
  color: var(--muted);
}
.fineprint svg { width: 18px; height: 18px; flex: none; fill: var(--gold); margin-top: 1px; }
.fineprint--center { justify-content: center; text-align: center; }

/* ───────── Screen 1: Welcome ───────── */
.screen--welcome { gap: 18px; justify-content: space-between; }

.welcome__poster {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
}
.welcome__poster img {
  width: auto;
  max-width: 100%;
  max-height: min(56vh, 520px);
  max-height: min(56dvh, 520px);
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(232, 165, 42, .25), 0 24px 50px -18px rgba(0, 0, 0, .95);
}
.welcome__panel { display: grid; gap: 16px; }
.welcome__panel .fineprint { justify-content: center; }

/* ───────── Screen 2: Camera ───────── */
.screen--camera {
  padding-top: calc(var(--safe-t) + 10px);
  padding-bottom: calc(var(--safe-b) + 16px);
  gap: 12px;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar__hint {
  flex: 1;
  margin: 0;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 17px;
  line-height: 1.15;
  color: var(--paper);
}
.topbar__spacer { width: 44px; flex: none; }

.viewfinder-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
}

/* the live viewfinder is styled as the memorial frame itself */
.frame {
  --vf-w: 260px;
  padding: 12px;
  border-radius: 6px;
  background:
    linear-gradient(145deg, #2b2724, #0d0c0b 45%, #1d1a18);
  box-shadow:
    0 0 0 1.5px #3a3128 inset,
    0 0 0 4px #0a0908 inset,
    0 0 0 5px rgba(232, 165, 42, .55) inset,
    0 28px 60px -20px #000,
    0 0 80px -10px rgba(232, 140, 30, .22);
}
.frame__mat {
  padding: 10px;
  background: linear-gradient(180deg, #e9dfc8, #cfc2a4);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .6) inset;
}
.frame__photo {
  position: relative;
  width: var(--vf-w);
  aspect-ratio: 268 / 406;
  overflow: hidden;
  background: #1a1816;
  box-shadow: 0 0 0 1px #000;
}
@supports not (aspect-ratio: 1) {
  .frame__photo { height: calc(var(--vf-w) * 406 / 268); }
}

.frame__photo video,
.frame__photo .review {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.frame__photo video.is-mirrored { transform: scaleX(-1); }

.frame__garland {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
  transition: opacity .25s ease;
}
.guide ellipse {
  fill: none;
  stroke: rgba(255, 255, 255, .85);
  stroke-width: 2;
  stroke-dasharray: 7 6;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, .8));
}
.is-reviewing .guide { opacity: 0; }

.flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.flash.is-on { animation: flash .35s ease-out; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }

.cam-status {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: #1a1816;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  padding: 12px;
}
.cam-status.is-hidden { display: none; }

.spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(239, 229, 207, .2);
  border-top-color: var(--gold);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.controls { flex: none; }
.controls__row { display: flex; gap: 10px; }
.controls__row--split > .btn,
.result__row > .btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 0 12px;
  gap: 8px;
  font-size: 17px;
  letter-spacing: .02em;
  white-space: nowrap;
}
.controls__row--split .btn__icon,
.result__row .btn__icon { width: 20px; height: 20px; }

.btn--shutter { gap: 12px; }
.shutter-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .35);
}

/* ───────── Screen 3: Processing ───────── */
.screen--processing {
  align-items: center;
  justify-content: center;
  gap: 26px;
}
.diya { position: relative; width: 92px; height: 92px; }
.diya__bowl {
  position: absolute;
  left: 8px; right: 8px; bottom: 6px;
  height: 30px;
  border-radius: 0 0 46px 46px / 0 0 30px 30px;
  background: linear-gradient(180deg, #f0c25a, var(--brass) 60%, #6e4d17);
  box-shadow: 0 6px 16px -4px rgba(0, 0, 0, .8);
}
.diya__flame {
  position: absolute;
  left: 50%;
  bottom: 34px;
  width: 22px; height: 40px;
  margin-left: -11px;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(60% 55% at 50% 72%, #fff8e1 0 25%, #ffd166 45%, #ff8c1a 72%, rgba(255, 80, 0, 0) 100%);
  box-shadow: 0 0 40px 14px rgba(255, 150, 40, .35);
  transform-origin: 50% 100%;
  animation: flicker 1.1s ease-in-out infinite alternate;
}
@keyframes flicker {
  0%   { transform: scale(1, 1) rotate(-1.5deg); opacity: .95; }
  40%  { transform: scale(.94, 1.06) rotate(1.2deg); opacity: 1; }
  100% { transform: scale(1.04, .95) rotate(-.6deg); opacity: .9; }
}
.processing__text {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: 22px;
}

/* ───────── Screen 4: Result ───────── */
.screen--result { gap: 18px; justify-content: center; }
.result__title {
  margin: 0;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-stretch: condensed;
  text-transform: uppercase;
  letter-spacing: .02em;
  font-size: 26px;
  color: var(--paper);
}
.result__image {
  flex: 0 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
}
.result__image img {
  width: auto;
  max-width: 100%;
  max-height: 60vh;
  max-height: 60dvh;
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(232, 165, 42, .3), 0 24px 50px -18px #000;
  -webkit-touch-callout: default; /* keep long-press "Save Image" on iPhone */
}
.result__actions { display: grid; gap: 12px; }
.result__row { display: flex; gap: 10px; }

/* ───────── Error screen ───────── */
.screen--error { gap: 22px; justify-content: center; }
.paper--error { padding-top: 26px; }
.error__badge {
  width: 52px; height: 52px;
  margin-bottom: 14px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--red);
}
.error__badge svg { width: 28px; height: 28px; fill: #fff; }
.steps {
  margin: 14px 0 0;
  padding-left: 22px;
  font-size: 16px;
  line-height: 1.45;
  color: #2b241e;
}
.steps:empty { display: none; }
.steps li + li { margin-top: 6px; }
.steps strong { color: var(--paper-ink); }
.error__actions { display: grid; gap: 12px; }

/* ───────── Toast ───────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 24px);
  transform: translateX(-50%);
  width: min(440px, calc(100vw - 32px));
  padding: 14px 18px;
  border-radius: 12px;
  background: var(--paper);
  color: var(--paper-ink);
  font-size: 15px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 16px 40px -10px #000;
  z-index: 50;
  animation: screen-in .25s ease-out both;
}

.noscript {
  max-width: 420px;
  margin: 40px auto;
  padding: 0 16px;
  text-align: center;
  color: var(--paper);
}

/* ───────── Small phones / landscape ───────── */
@media (max-height: 640px) {
  .screen { padding-top: calc(var(--safe-t) + 12px); padding-bottom: calc(var(--safe-b) + 12px); }
  .btn--xl { min-height: 54px; font-size: 19px; }
  .paper { padding: 16px 18px 18px; }
  .paper__title { font-size: 32px; }
  .paper__sub { font-size: 16px; margin-top: 6px; }
}

@media (max-width: 374px) {
  .controls__row--split > .btn,
  .result__row > .btn { font-size: 15px; padding: 0 8px; gap: 6px; letter-spacing: .01em; }
  .controls__row--split .btn__icon,
  .result__row .btn__icon { width: 18px; height: 18px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .btn { white-space: nowrap; }
  .btn--xl { font-size: 18px; }
  .screen--welcome { flex-direction: row; align-items: center; }
  .welcome__poster img { max-height: calc(100dvh - 40px); }
  .welcome__panel { flex: 1; }
  .screen--camera { display: none; }
  .screen--camera.is-active {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 1fr;
  }
  .screen--camera .topbar { grid-column: 1 / -1; }
  .screen--camera .controls { align-self: center; width: 200px; }
  .screen--camera .controls__row--split { flex-direction: column; }
  .screen--result { display: none; }
  .screen--result.is-active { display: grid; grid-template-columns: 1fr 220px; grid-template-rows: auto 1fr; align-items: center; }
  .result__title { grid-column: 1 / -1; font-size: 20px; }
  .result__image img { max-height: calc(100dvh - 90px); }
  .result__row { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* ───────── QR code page (qr.html) ───────── */
.qrpage { gap: 18px; justify-content: flex-start; }
.qrpage__label {
  display: block;
  margin-top: 16px;
  font-size: 14px;
  font-weight: 600;
  color: #3a3129;
}
.qrpage__input {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 1.5px solid #b9ab8e;
  border-radius: 10px;
  background: #fffaf0;
  color: var(--paper-ink);
  font: 16px/1.3 var(--font-body);
}
.qrpage__input:focus { outline: 3px solid var(--gold); outline-offset: 1px; }
.qrpage__error { margin: 8px 0 0; color: var(--red-deep); font-size: 14px; font-weight: 600; }
.qrpage__code {
  width: min(280px, 72vw);
  margin: 4px auto 0;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 40px -16px #000;
}
.qrpage__code:empty { display: none; }
.qrpage__code svg { display: block; width: 100%; height: auto; }
.qrpage__caption {
  margin: 0;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  word-break: break-all;
}
.qrpage .btn { white-space: normal; text-align: center; line-height: 1.1; }
.qrpage__tips { color: var(--muted); font-size: 15px; line-height: 1.5; }
.qrpage__tips h2 {
  margin: 6px 0 6px;
  font-family: var(--font-display);
  font-weight: 700;
  font-stretch: condensed;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 18px;
  color: var(--paper);
}
.qrpage__tips ul { margin: 0; padding-left: 20px; }
.qrpage__tips li + li { margin-top: 6px; }
.qrpage__tips strong { color: var(--paper); }
.qrpage__tips a { color: var(--gold); }
