/* Stages, forms, the Street View round, the guess map, the video bar.
   Design language: everything interactive is a piece of postal paper sitting on
   the dark desk — cream stock, sepia ink, airmail hatching, sealing wax,
   handwriting. The envelope is the hero; the UI is its stationery. */

#stages {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;      /* individual stages opt back in */
}

.stage { pointer-events: auto; }
.stage[hidden] { display: none !important; }

/* ------------------------------------------------------------ card stages */
/* A card is a rectangle of paper: uneven corners (die-cut, not CSS-modern),
   an airmail hatched strip along the top edge, faint fibre grain, and a
   half-degree tilt so it reads as laid down rather than rendered. */

.stage--card {
  position: absolute;
  left: 50%;
  bottom: clamp(2rem, 7vh, 5rem);
  transform: translateX(-50%) rotate(-0.4deg);
  width: min(46rem, 90vw);
  padding: clamp(1.9rem, 3.2vw, 2.6rem) clamp(1.8rem, 3.4vw, 3rem) clamp(1.6rem, 3vw, 2.2rem);
  text-align: center;

  color: var(--sepia);
  background:
    url("data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'>\
<filter id='p'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/>\
<feColorMatrix values='0 0 0 0 0.28 0 0 0 0 0.22 0 0 0 0 0.16 0 0 0 0.05 0'/></filter>\
<rect width='140' height='140' filter='url(%23p)'/></svg>"),
    linear-gradient(173deg, var(--paper) 0%, var(--paper-2) 100%);
  border-radius: 7px 4px 8px 5px;
  box-shadow:
    0 30px 60px -18px rgba(0, 0, 0, 0.75),
    0 3px 12px rgba(0, 0, 0, 0.35),
    inset 0 0 60px rgba(122, 96, 60, 0.09);
  animation: card-in 0.7s var(--ease) both;
}

/* the airmail edge — par avion */
.stage--card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 7px;
  border-radius: 7px 4px 0 0;
  background: repeating-linear-gradient(
    -45deg,
    var(--post-red) 0 9px,
    var(--paper) 9px 18px,
    var(--post-blue) 18px 27px,
    var(--paper) 27px 36px
  );
  opacity: 0.85;
}

/* a faded circular postmark in the corner, like it passed through a sorting office */
.stage--card::after {
  content: "";
  position: absolute;
  top: 0.9rem;
  right: 1.1rem;
  width: 3.4rem;
  height: 3.4rem;
  border: 2px double var(--post-red);
  border-radius: 50%;
  opacity: 0.14;
  transform: rotate(-14deg);
  pointer-events: none;
}

@keyframes card-in {
  from { opacity: 0; transform: translateX(-50%) translateY(22px) rotate(-0.4deg); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) rotate(-0.4deg); }
}

.stage--full { position: absolute; inset: 0; }
.stage--bare { position: absolute; inset: 0; display: grid; place-items: center; }

.eyebrow {
  margin: 0 0 0.55rem;
  font-family: var(--hand);
  font-size: 1.35rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--post-red);
  transform: rotate(-0.8deg);
}

.prompt {
  margin: 0 0 0.5rem;
  font-size: clamp(1.5rem, 3.1vw, 2.3rem);
  font-weight: 400;
  line-height: 1.22;
  letter-spacing: -0.01em;
  color: var(--sepia);
}

.body {
  margin: 0.4rem auto 1.4rem;
  max-width: 34rem;
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--ink-soft);
}

/* an optional photograph pinned to a stage — printed with a white border,
   the way photos come back from the shop */
.stage__image {
  display: block;
  margin: 0.9rem auto;
  max-width: min(24rem, 80%);
  max-height: 36vh;
  object-fit: contain;
  padding: 8px 8px 10px;
  background: #fbf8f1;
  border-radius: 2px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
  transform: rotate(0.9deg);
}

/* ------------------------------------------------------------------ answer */

.answer { position: relative; margin-top: 1.4rem; }

.answer__input {
  width: 100%;
  padding: 0.7rem 3.2rem 0.55rem 1.1rem;
  font-family: var(--serif);
  font-size: 1.25rem;
  color: var(--sepia);
  text-align: center;
  caret-color: var(--post-red);
  background: none;
  border: 0;
  border-bottom: 2px dotted var(--ink-faint);
  border-radius: 0;
  outline: none;
  transition: border-color 0.3s var(--ease);
}
.answer__input::placeholder {
  font-family: var(--hand);
  font-size: 1.2rem;
  color: var(--ink-faint);
}
.answer__input:focus { border-bottom-color: var(--post-red); }

.answer__input--num {
  font-size: 2.4rem;
  letter-spacing: 0.3em;
  padding-right: 1.1rem;
  text-indent: 0.3em;              /* balance the letter-spacing on the right */
}

.answer__go {
  position: absolute;
  right: 0.4rem;
  top: 0.5rem;
  width: 2.4rem;
  height: 2.4rem;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--ink-faint);
  transition: color 0.25s var(--ease), transform 0.25s var(--ease);
}
.answer__go:hover { color: var(--post-red); transform: translateX(3px); }
.answer__go svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.answer__error {
  min-height: 1.5rem;
  margin: 0.55rem 0 0;
  font-family: var(--hand);
  font-size: 1.15rem;
  color: var(--post-red);
  transform: rotate(-0.6deg);
}

.answer.checking { opacity: 0.6; }
.answer.correct .answer__input { border-bottom-color: var(--post-red); }

.shake { animation: shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

/* --------------------------------------------------------------- number pad */
/* Paper raffle tickets: perforated edges, ink numerals. */

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  max-width: 17rem;
  margin: 1.3rem auto;
}
.pad button {
  padding: 0.72rem 0;
  font-family: var(--serif);
  font-size: 1.25rem;
  color: var(--sepia);
  background: rgba(251, 248, 241, 0.55);
  border: 1px dashed var(--ink-faint);
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.18s var(--ease), transform 0.12s var(--ease), border-color 0.18s var(--ease);
}
.pad button:hover { background: rgba(251, 248, 241, 0.95); border-color: var(--post-red); }
.pad button:active { transform: translateY(1px); }
.pad__wide { font-family: var(--hand) !important; font-size: 1.1rem !important; }

/* ---------------------------------------------------------------- choices */
/* Multiple choice: slips of paper. A wrong one gets struck through in red ink
   and stays on the table; the right one gets the wax ring. */

.choices {
  display: grid;
  gap: 0.6rem;
  max-width: 26rem;
  margin: 1.2rem auto 0;
}
.choice {
  padding: 0.75rem 1.2rem;
  font-family: var(--serif);
  font-size: 1.1rem;
  color: var(--sepia);
  text-align: center;
  background: rgba(251, 248, 241, 0.55);
  border: 1px dashed var(--ink-faint);
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.18s var(--ease), transform 0.15s var(--ease), border-color 0.18s var(--ease);
}
.choice:nth-child(odd) { transform: rotate(-0.4deg); }
.choice:nth-child(even) { transform: rotate(0.35deg); }
.choice:hover:not(:disabled) { background: rgba(251, 248, 241, 0.95); border-color: var(--post-red); transform: translateY(-2px); }
.choice:disabled { cursor: default; }

.choice--wrong {
  color: var(--ink-faint);
  border-color: rgba(165, 60, 44, 0.5);
  background:
    linear-gradient(to top right,
      transparent 46.5%, var(--post-red) 47.5%, var(--post-red) 52.5%, transparent 53.5%),
    rgba(251, 248, 241, 0.4);
}
.choice--right {
  border: 1px solid var(--post-red);
  box-shadow: 0 0 0 3px rgba(165, 60, 44, 0.25);
}

/* ----------------------------------------------------------------- buttons */
/* Primary actions are sealing wax: deep red, softly irregular, pressed into
   the paper. Ghost actions are rubber stamps: an inked outline, nothing more. */

.btn {
  display: inline-block;
  padding: 0.72rem 1.7rem;
  font-family: var(--serif);
  font-size: 1rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  border-radius: 10px 13px 11px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.22s var(--ease), color 0.22s var(--ease),
              border-color 0.22s var(--ease), transform 0.15s var(--ease),
              box-shadow 0.22s var(--ease);
}
.btn:active { transform: translateY(1px) rotate(-0.5deg); }
.btn--primary {
  color: #f6ecdd;
  background: radial-gradient(120% 140% at 30% 20%, #b04a35 0%, var(--wax) 55%, #6f251b 100%);
  border-color: rgba(0, 0, 0, 0.25);
  box-shadow:
    0 6px 16px -6px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 236, 214, 0.28),
    inset 0 -2px 6px rgba(0, 0, 0, 0.3);
  transform: rotate(-0.5deg);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.btn--primary:hover {
  background: radial-gradient(120% 140% at 30% 20%, #bd5540 0%, #97382a 55%, #7a2b20 100%);
  transform: rotate(-0.5deg) translateY(-1px);
}
.btn--primary:disabled {
  background: none;
  color: var(--ink-faint);
  border: 1px dashed var(--ink-faint);
  box-shadow: none;
  text-shadow: none;
  cursor: default;
  transform: none;
}
.btn--ghost {
  color: var(--ink-soft);
  background: none;
  border: 1.5px solid var(--ink-faint);
  border-radius: 6px 9px 7px 10px;
  transform: rotate(0.4deg);
}
.btn--ghost:hover { color: var(--sepia); border-color: var(--ink-soft); }

/* ghost buttons that sit on the DARK desk rather than on paper */
.stage--bare .btn--ghost {
  color: var(--cream-dim);
  border-color: rgba(244, 239, 228, 0.35);
}
.stage--bare .btn--ghost:hover { color: var(--cream); border-color: var(--cream-faint); }

/* ------------------------------------------------------------- street view */

/* Its own layer, below the envelope canvas (z-index 2) and below #stages (10),
   so the envelope stays visible docked in the corner during a round. */
.pano {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: none;
  background: #111112;
}
body[data-stage="geo"] .pano { display: block; }
/* The panorama itself: sized by the layer, because Google replaces the
   container's inline position/overflow and cannot be trusted with layout. */
.pano > div { width: 100%; height: 100%; }

/* The geo stage is only overlays; it must not blanket the panorama. */
.stage--overlay { pointer-events: none; }
.stage--overlay > * { pointer-events: auto; }
/* Google slips a few links into the pano; keep the chrome quiet without
   removing the attribution Google requires. */
.pano .gm-style-cc { opacity: 0.35; }

/* --------------------------------------------- stamp gallery after a round */

/* Above the pano (same z, later in the DOM) but below the envelope canvas
   (z 2), so the envelope floats over a dimmed street. The hint shows through
   the canvas's transparent pixels. */
.stamp-scrim {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: rgba(8, 8, 9, 0.6);
  opacity: 0;
  transition: opacity 0.4s ease;
  cursor: pointer;
}
.stamp-scrim.on { opacity: 1; }
.stamp-scrim__hint {
  position: absolute;
  left: 50%;
  bottom: 6vh;
  transform: translateX(-50%) rotate(-1deg);
  margin: 0;
  font-family: var(--hand);
  font-size: 1.35rem;
  color: var(--cream-dim);
  animation: hint-breathe 2.6s ease-in-out infinite;
}
@keyframes hint-breathe { 50% { opacity: 0.55; } }

/* the geo overlays make no sense while she is looking at the envelope */
body.stamp-viewing .stage[data-stage="geo"] { visibility: hidden; }

/* a parcel tag, tied on with a punched hole */
.round-chip {
  position: absolute;
  z-index: 12;
  top: 1.3rem;
  left: 50%;
  transform: translateX(-50%) rotate(-1deg);
  padding: 0.5rem 1.2rem 0.5rem 2.1rem;
  font-family: var(--hand);
  font-size: 1.15rem;
  color: var(--sepia);
  background: linear-gradient(170deg, var(--paper), var(--paper-2));
  border-radius: 3px 6px 4px 6px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}
.round-chip::before {
  content: "";
  position: absolute;
  left: 0.7rem;
  top: 50%;
  width: 0.55rem;
  height: 0.55rem;
  transform: translateY(-50%);
  border-radius: 50%;
  background: #10131a;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.8), 0 0 0 2px rgba(51, 41, 31, 0.25);
}
.round-chip b { color: var(--post-red); font-weight: 600; margin-left: 0.3rem; }

/* --------------------------------------------------------------- guess map */
/* The guess map is a postcard: cream border, map where the picture goes. */

.guess-panel {
  position: absolute;
  z-index: 14;
  right: 1.2rem;
  bottom: 1.2rem;
  width: 19rem;
  height: 13rem;
  padding: 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: linear-gradient(168deg, var(--paper) 0%, var(--paper-2) 100%);
  border-radius: 4px 6px 4px 7px;
  box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.7);
  opacity: 0.88;
  transform: rotate(0.4deg);
  transition: width 0.32s var(--ease), height 0.32s var(--ease), opacity 0.32s var(--ease);
}
.guess-panel.expanded { width: min(38rem, 46vw); height: min(30rem, 58vh); opacity: 1; transform: none; }
.guess-panel.pinned   { opacity: 1; }
.guess-panel.pinned .guess-panel__pin { color: var(--post-red); }

.guess-panel__pin {
  position: absolute;
  top: -0.85rem;
  left: -0.85rem;
  z-index: 5;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  color: var(--ink-faint);
  background: var(--paper);
  border: 1px solid var(--ink-faint);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  transition: color 0.2s var(--ease);
}
.guess-panel__pin svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; }

.guess-map { flex: 1; border-radius: 2px; overflow: hidden; background: #d8d2c2; box-shadow: inset 0 0 0 1px rgba(51, 41, 31, 0.25); }
.guess-panel__go { width: 100%; padding: 0.55rem; font-size: 0.95rem; }

/* leaflet sits inside the postcard now; keep its chrome papery */
.leaflet-container { background: #e6e0d1; font-family: var(--serif); }
.leaflet-control-attribution {
  background: rgba(241, 233, 214, 0.8) !important;
  color: rgba(51, 41, 31, 0.55) !important;
  font-size: 9px !important;
}
.leaflet-control-attribution a { color: rgba(51, 41, 31, 0.75) !important; }
.leaflet-bar a { background: var(--paper) !important; color: var(--sepia) !important; border-color: rgba(51, 41, 31, 0.3) !important; }

.pin__dot {
  position: absolute;
  left: 50%;
  top: 0;
  width: 15px;
  height: 15px;
  margin-left: -7.5px;
  border-radius: 50%;
  border: 2px solid #fbf8f1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
.pin__stick {
  position: absolute;
  left: 50%;
  top: 13px;
  width: 2px;
  height: 17px;
  margin-left: -1px;
  background: rgba(51, 41, 31, 0.75);
}
.pin--guess .pin__dot { background: var(--post-blue); }
.pin--truth .pin__dot { background: var(--post-red); }

/* ------------------------------------------------------------ round result */

.round-result {
  position: absolute;
  z-index: 20;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-0.3deg);
  width: min(30rem, 88vw);
  padding: 1.9rem 2rem 1.7rem;
  text-align: center;
  color: var(--sepia);
  background: linear-gradient(173deg, var(--paper) 0%, var(--paper-2) 100%);
  border-radius: 6px 4px 7px 5px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.8), 0 2px 10px rgba(0, 0, 0, 0.4);
  animation: result-in 0.5s var(--ease) both;
}
@keyframes result-in {
  from { opacity: 0; transform: translate(-50%, -46%) rotate(-0.3deg); }
  to   { opacity: 1; transform: translate(-50%, -50%) rotate(-0.3deg); }
}
.round-result[hidden] { display: none; }
.round-result h2 {
  margin: 0 0 0.3rem;
  font-family: var(--hand);
  font-size: 1.9rem;
  font-weight: 400;
  color: var(--post-red);
}
.result__praise { margin: 0 0 1.1rem; color: var(--ink-soft); font-size: 1.02rem; }

.result__stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin: 0 0 1.4rem;
}
.result__stats div { display: grid; gap: 0.2rem; }
.result__stats dt {
  font-family: var(--hand);
  font-size: 1.05rem;
  color: var(--ink-faint);
}
.result__stats dd { margin: 0; font-size: 1.4rem; color: var(--sepia); }

/* ------------------------------------------------------------------ reveal */

#reveal-video {
  /* The VideoTexture reads from this element; it must stay in the document and
     must not be display:none (Chrome will not decode a display:none video),
     so it is parked off-screen at 1px instead. */
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0.001;
  left: -10px;
  bottom: -10px;
  pointer-events: none;
  z-index: -1;
}
body.no-webgl #reveal-video,
body:not(.reveal-3d) #reveal-video[controls] {
  position: static;
  width: min(94vw, 1400px);
  height: auto;
  opacity: 1;
  pointer-events: auto;
  z-index: auto;
}

.notice { position: static !important; transform: none !important; }


/* --------------------------------------------------------------- video bar */
/* Projection-room hardware: a strip of warm dark leather under the film,
   with a brass seek thumb. Deliberately not paper — nothing should glow next
   to the picture. */

.video-bar {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: 1.6rem;
  transform: translateX(-50%);
  width: min(60rem, 92vw);
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.6rem 1rem;
  background: rgba(24, 17, 12, 0.82);
  border: 1px solid rgba(223, 174, 99, 0.22);
  border-radius: 999px;
  backdrop-filter: blur(12px);
  animation: bar-in 0.6s var(--ease) both;
}
@keyframes bar-in {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
}
.video-bar[hidden] { display: none; }

.vb__btn {
  flex: none;
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  color: var(--cream);
  background: none;
  border: 0;
  cursor: pointer;
  opacity: 0.82;
  transition: opacity 0.2s var(--ease), color 0.2s var(--ease);
}
.vb__btn:hover { opacity: 1; color: var(--gold); }
.vb__btn svg { width: 19px; height: 19px; fill: currentColor; }
.vb__btn--sm svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.vb__btn--sm[aria-label="Mute"] svg path:first-child { fill: currentColor; stroke: none; }

.vb__btn[data-state="paused"] .vb__pause,
.vb__btn[data-state="playing"] .vb__play { display: none; }
.vb__btn[data-state="muted"] .vb__wave { opacity: 0.2; }

.vb__time {
  flex: none;
  font-family: var(--serif);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--cream-dim);
  min-width: 8.5ch;
  text-align: center;
}

.vb__seek { flex: 1; }
.vb__vol  { flex: none; width: 5rem; }

.video-bar input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: rgba(244, 239, 228, 0.22);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
.video-bar input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 3px rgba(223, 174, 99, 0.2);
}
.video-bar input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border: 0; border-radius: 50%; background: var(--gold);
}

/* ------------------------------------------------------------------ final */

.scorecard {
  margin: 1.4rem auto 1.6rem;
  padding: 1.2rem 1.4rem;
  max-width: 30rem;
  border: 1px dashed var(--ink-faint);
  border-radius: 4px;
  background: rgba(251, 248, 241, 0.45);
}
.scorecard[hidden] { display: none; }
.scorecard h3 {
  margin: 0 0 0.9rem;
  font-family: var(--hand);
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--post-red);
}
.scorecard__best { margin: 0; font-size: 0.95rem; color: var(--ink-soft); font-style: italic; }
.scorecard__best strong { color: var(--post-red); font-weight: 400; font-style: normal; }

/* ------------------------------------------------------------------- focus */

.stage--card :focus-visible,
.round-result :focus-visible {
  outline: 2px dashed var(--post-red);
  outline-offset: 3px;
}
:focus-visible {
  outline: 2px dashed var(--gold);
  outline-offset: 3px;
}

/* --------------------------------------------------------------- narrow-ish */
/* Desktop-first by decision; this only keeps a phone from being broken. */

@media (max-width: 860px) {
  .guess-panel { width: 12rem; height: 9rem; right: 0.7rem; bottom: 0.7rem; }
  .guess-panel.expanded { width: calc(100vw - 1.4rem); height: 58vh; }
  .stage--card { width: 94vw; bottom: 1rem; padding: 1.5rem 1.1rem 1.2rem; }
  .stage--card::after { display: none; }
  .hint-dock { right: 0.8rem; bottom: 0.8rem; max-width: 70vw; }
  .video-bar { gap: 0.5rem; padding: 0.5rem 0.7rem; }
  .vb__vol { display: none; }
}
