/* Y2K newspaper look, matched to The Dove Times artwork */
:root {
  --paper: #f3f1ec;      /* newsprint */
  --ink: #1a1a1a;        /* headline black */
  --navy: #1d3166;       /* Dove blue / handwriting */
  --gold: #c9a35a;       /* rule + sticker gold */
  --muted: #5d5a54;

  --f-display: "Playfair Display", "Didot", "Bodoni 72", Georgia, serif;
  --f-body: "Old Standard TT", "Times New Roman", Times, serif;

  --gutter: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 16px;
}

/* ── Booth: the template on top, its buttons underneath, centred on screen ── */
.booth {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: var(--gutter);
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
  padding-bottom: max(var(--gutter), env(safe-area-inset-bottom, 0px));
}

/* ── Stage ──
   --reserve is the height kept free for the buttons below the template.
   The result step reserves more, which is what makes the template smaller. */
.stage {
  --reserve: 112px;
  --fit-h: calc(100vh - var(--reserve));
  position: relative;
  width: min(100%, calc(var(--fit-h) * var(--ar, 0.707)));
  aspect-ratio: var(--ar, 0.707);
  flex: none;
  background: #fff;
  box-shadow: 0 1px 0 #0002, 0 18px 40px -18px #0006;
  overflow: hidden;
  transition: width 0.35s ease;
}
@supports (height: 100svh) {
  .stage { --fit-h: calc(100svh - var(--reserve)); }
}
.booth.is-result .stage {
  --reserve: 330px;
  width: min(80%, calc(var(--fit-h) * var(--ar, 0.707)));
}

.hole {
  position: absolute;
  background: #222;
  overflow: hidden;
}
.hole video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.hole video.mirror { transform: scaleX(-1); }
.hole video.tone-bw { filter: grayscale(1) contrast(1.08); }
.hole video.tone-sepia { filter: sepia(0.75) contrast(1.05); }

.cam-msg {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 20px;
  text-align: center;
  color: #eee;
  font-size: 15px;
  line-height: 1.4;
}
.frame, .result {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
.result { background: var(--paper); }

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--f-display);
  font-style: italic;
  font-weight: 900;
  font-size: clamp(90px, 22vw, 220px);
  color: #fff;
  text-shadow: 0 4px 0 var(--navy), 0 0 30px #0008;
  pointer-events: none;
}
.countdown.pop { animation: pop 0.9s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } 30% { opacity: 1; } to { transform: scale(1); } }

.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash 0.45s ease-out; }
@keyframes flash { from { opacity: 0.95; } to { opacity: 0; } }

/* ── Buttons under the template ── */
.controls {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.controls-row { flex-direction: row; }
.controls-row .btn { flex: 1; }

.save-error {
  margin: -4px 0 0;
  max-width: 420px;
  text-align: center;
  font-size: 14px;
  color: #9b2c1f;
}

.btn {
  appearance: none;
  display: block;
  width: 100%;
  text-align: center;
  font: 700 18px/1 var(--f-body);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 20px 16px;
  border: 2px solid var(--ink);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:focus-visible { outline: 3px solid var(--navy); outline-offset: 3px; }
.btn-main { background: var(--ink); color: var(--paper); box-shadow: 4px 4px 0 var(--gold); }
.btn-main:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--gold); }
.btn-gold { background: var(--gold); color: var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.btn-gold:active { box-shadow: 1px 1px 0 var(--ink); }
.btn-ghost { background: transparent; color: var(--ink); font-size: 13px; padding: 12px; }
.btn-ghost.btn-big { font-size: 18px; padding: 20px 16px; }   /* ghost button at full size, e.g. Retake */
@media (hover: hover) { .btn-ghost:hover { background: #0000000a; } }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Photo code ── */
.code-box {
  border: 1.5px solid var(--ink);
  background: #fff;
  padding: 12px 16px 14px;
  text-align: center;
}
.code-label {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}
.code {
  margin: 6px 0 8px;
  font-family: var(--f-body);   /* upright, so letters can't be misread */
  font-weight: 700;
  font-size: 40px;
  line-height: 1;
  letter-spacing: 0.16em;
  color: var(--navy);
  user-select: all;
}
.code-help {
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
  color: var(--muted);
}
.code-url { color: var(--ink); overflow-wrap: anywhere; }
.code-error { color: #9b2c1f; }

/* ── Download page ── */
.lookup {
  min-height: 100vh;
  min-height: 100svh;
  max-width: 460px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
  padding: 32px var(--gutter);
  padding-bottom: max(32px, env(safe-area-inset-bottom, 0px));
}
.lookup-title {
  margin: 0;
  text-align: center;
  font-family: var(--f-display);
  font-weight: 900;
  font-size: clamp(34px, 10vw, 52px);
  line-height: 1;
  letter-spacing: -0.01em;
  border-bottom: 3px double var(--ink);
  padding-bottom: 12px;
}
.lookup-title em { font-style: italic; font-weight: 700; color: var(--navy); }
.lookup-kicker {
  margin: 0;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  border-bottom: 3px solid var(--gold);
  padding-bottom: 10px;
}
.lookup-form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.lookup-form .code-label { text-align: center; }
.code-input {
  width: 100%;
  border: 2px solid var(--ink);
  background: #fff;
  color: var(--navy);
  padding: 14px 12px;
  text-align: center;
  font: 700 34px/1 var(--f-body);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.code-input::placeholder { color: #0002; }
.code-input:focus-visible { outline: 3px solid var(--navy); outline-offset: 3px; }
.lookup-msg { margin: 0; min-height: 1.4em; text-align: center; font-size: 15px; color: var(--muted); }
.lookup-msg.is-error { color: #9b2c1f; }
.lookup-result { display: flex; flex-direction: column; gap: 14px; text-align: center; }
.lookup-photo {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 1px 0 #0002, 0 18px 40px -18px #0006;
}
a.btn { text-decoration: none; }

/* ── Phones ── */
@media (max-width: 520px) {
  .btn, .btn-ghost.btn-big { font-size: 16px; padding: 18px 12px; }
  .code { font-size: 34px; }
  .code-help { font-size: 13px; }
  .booth.is-result .stage { --reserve: 330px; }
}

/* ── Short landscape screens (phones held sideways): controls beside the template ── */
@media (orientation: landscape) and (max-height: 600px) {
  .booth { flex-direction: row; }
  .stage, .booth.is-result .stage { --reserve: 32px; }
  .controls { max-width: 300px; }
  .code { font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .countdown.pop, .flash.go { animation: none; }
  .stage { transition: none; }
}

/* ── Print: only the final photo, full A4 page ── */
#printSheet { display: none; }
@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; }
  .booth, canvas { display: none !important; }
  #printSheet { display: block; width: 100%; }
  #printSheet img { display: block; width: 100%; height: auto; }
}
