/* Quality Showdown — game-show set. The stage art is layered: set, host, then the podium in front
   of him, so the host can change poses. Scoreboard sits above the stage; question, lit answer board
   and controls follow. Single dark studio look by choice. */
:root {
  --night: #050d26;
  --navy: #0a1f55;
  --navy-2: #12307a;
  --neon: #3a8dff;
  --gold: #ffc61a;
  --gold-hi: #ffe27a;
  --gold-dk: #b07a00;
  --red: #ff3b4e;
  --green: #22b14c;
  --ink: #eef3ff;
  --muted: #a3b6de;
  --display: "Lilita One", "Arial Black", Impact, sans-serif;
  --body: "Barlow", "Segoe UI", system-ui, sans-serif;
  --label: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  /* stage layout (generated from the art; see README) */
  --stage-aspect: 1270 / 941;
  --host-left: 11.358%; --host-top: 5.778%; --host-width: 76.181%;
  --pod-left: 7.795%; --pod-top: 60.361%; --pod-width: 83.543%;
  color-scheme: dark;
}
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse 90% 40% at 50% 0%, #1a3f9a66, transparent 70%), var(--night);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
}
img { max-width: 100%; display: block; }
.wrap {
  max-width: 660px;
  margin: 0 auto;
  padding-block: 10px 28px;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}
@media (min-width: 400px) {
  .wrap { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
}

.panel {
  background: linear-gradient(var(--navy-2), var(--navy));
  border: 2px solid var(--neon);
  border-radius: 12px;
  box-shadow: 0 0 0 3px #7c88a6, 0 0 18px #3a8dff55, inset 0 0 22px #0006;
}

/* ---------- Scoreboard ---------- */
.stagecol { display: grid; gap: 8px; min-width: 0; }
.hud { display: grid; grid-template-columns: .9fr 1.1fr 1fr 1.25fr; gap: 6px; }
.hud .hcell {
  background: linear-gradient(#0f2a6e, #061646);
  border: 2px solid var(--gold);
  border-radius: 10px;
  text-align: center;
  padding: 3px 4px 4px;
  box-shadow: 0 0 10px #ffc61a44, inset 0 0 12px #0008;
  min-width: 0;
}
.hud .k { display: block; font-family: var(--label); font-weight: 700; font-size: 11.5px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
.hud b { display: block; font-family: var(--display); font-weight: 400; font-size: clamp(20px, 5.6vw, 27px); line-height: 1.05;
  font-variant-numeric: tabular-nums; background: linear-gradient(var(--gold-hi), var(--gold) 55%, #d98f00); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hud .xs { display: flex; justify-content: center; gap: 4px; padding-top: 2px; }
.strike { font-style: normal; font-family: var(--display); font-size: clamp(16px, 4.6vw, 22px); line-height: 1; width: 1.25em; height: 1.25em;
  display: grid; place-items: center; border-radius: 5px; background: #041038; border: 1px solid #2f6fd6; color: transparent; transition: background .2s, color .2s; }
.strike.on { background: var(--red); color: #fff; border-color: #ffb0b8; box-shadow: 0 0 10px var(--red); }

/* ---------- Stage ---------- */
.stage {
  position: relative;
  aspect-ratio: var(--stage-aspect);
  width: 100%;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 0 0 3px #7c88a6, 0 0 30px #3a8dff44;
  container-type: inline-size;
  background: #050d26;
}
.stage > .stage-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.host { position: absolute; left: var(--host-left); top: var(--host-top); width: var(--host-width); max-width: none; transform-origin: 50% 80%; }
.host.offstage { visibility: hidden; }   /* empty stage behind the title card */
.host.pop { animation: hostpop .35s cubic-bezier(.3,1.5,.5,1); }
@keyframes hostpop { from { transform: translateY(3%) scale(.97); } to { transform: none; } }
.podium { position: absolute; left: var(--pod-left); top: var(--pod-top); width: var(--pod-width); max-width: none; pointer-events: none; }
.stage.bad { animation: shake .45s; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

.react {
  position: absolute; right: 6%; top: 8%;
  width: 13cqw; height: 13cqw; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--display); font-size: 8cqw; color: #fff;
  opacity: 0; transform: scale(.4) rotate(-12deg);
  transition: opacity .2s, transform .3s cubic-bezier(.3,1.6,.5,1);
  pointer-events: none;
}
.stage.good .react { opacity: 1; transform: scale(1) rotate(-8deg); background: var(--green); box-shadow: 0 0 0 4px #fff, 0 0 24px var(--green); }
.stage.bad .react { opacity: 1; transform: scale(1) rotate(-8deg); background: var(--red); box-shadow: 0 0 0 4px #fff, 0 0 24px var(--red); }

/* Title card over the stage (audio needs a tap before it can play) */
.curtain {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2.5cqw;
  padding: 4cqw 4cqw 6cqw;
  background: linear-gradient(rgba(5,13,38,.15) 0%, rgba(5,13,38,.55) 45%, rgba(5,13,38,.92) 100%);
}
.curtain-logo { width: 62%; filter: drop-shadow(0 6px 10px rgba(0,0,0,.6)); animation: logoin .7s cubic-bezier(.2,1.3,.4,1) both; }
@keyframes logoin { from { transform: scale(.7); opacity: 0; } to { transform: none; opacity: 1; } }
.curtain .tag { margin: 0; font-family: var(--label); font-weight: 700; font-size: clamp(14px, 4.4cqw, 22px); letter-spacing: 1.5px; text-transform: uppercase; color: #fff; text-shadow: 0 2px 4px #000; }
.curtain button { font-size: clamp(19px, 5.4cqw, 28px); padding: 12px 30px; }

/* ---------- Host message ---------- */
.msg {
  padding: 11px 16px; text-align: center; font-weight: 700; font-size: 19px; line-height: 1.25;
  min-height: 52px; display: grid; place-items: center;
  border-color: var(--gold); box-shadow: 0 0 0 3px #7c88a6, 0 0 16px #ffc61a44, inset 0 0 22px #0006;
}
.msg.good { color: var(--gold-hi); }
.msg.bad { color: #ff8a95; }

/* ---------- Question ---------- */
.question { padding: 11px 16px 13px; display: grid; gap: 4px; text-align: center; }
.eyebrow { font-family: var(--label); font-weight: 700; font-size: 13.5px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--muted); }
.eyebrow .double { color: var(--gold); }
.question h1 { margin: 0; font-family: var(--body); font-weight: 700; font-size: clamp(20px, 5vw, 26px); line-height: 1.2; text-wrap: balance; }

/* ---------- Answer board (lit art, live tiles over its six panels) ---------- */
.board {
  position: relative;
  aspect-ratio: 1672 / 941;
  width: 100%;
  background: url("../assets/board.webp") center / 100% 100% no-repeat;
  border-radius: 12px;
  container-type: inline-size;
  filter: drop-shadow(0 8px 18px rgba(0,0,0,.55));
}
.tile { position: absolute; width: 39.6%; height: 17%; perspective: 700px; }
.tile:nth-child(odd) { left: 8.97%; }
.tile:nth-child(even) { left: 51.55%; }
.tile:nth-child(1), .tile:nth-child(2) { top: 19.7%; }
.tile:nth-child(3), .tile:nth-child(4) { top: 42.9%; }
.tile:nth-child(5), .tile:nth-child(6) { top: 65.2%; }
.tile-inner { position: relative; height: 100%; transition: transform .6s cubic-bezier(.3, 1.4, .5, 1); transform-style: preserve-3d; }
.tile.open .tile-inner { transform: rotateX(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 3cqw; display: flex; align-items: center; gap: 1.6cqw; padding: 0 2.4cqw; }
.front { justify-content: center; }
.front .num {
  width: 7.2cqw; height: 7.2cqw; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--display); font-size: 4.4cqw; color: #2a1a00;
  background: radial-gradient(circle at 35% 30%, var(--gold-hi), var(--gold) 60%, #c27f00);
  box-shadow: 0 0 2cqw #ffc61a99;
}
.back {
  transform: rotateX(180deg);
  background: linear-gradient(#fdfeff, #cfdcf4);
  color: #08184d;
  box-shadow: inset 0 0 0 .5cqw #ffffff, 0 0 3cqw #8fc6ff;
}
.tile.flash .back { animation: flash .7s ease-out; }
@keyframes flash { 0% { box-shadow: inset 0 0 0 .5cqw #fff, 0 0 6cqw #fff8b0; } 100% { box-shadow: inset 0 0 0 .5cqw #fff, 0 0 3cqw #8fc6ff; } }
.mark { flex: none; width: 4.4cqw; height: 4.4cqw; border-radius: 50%; display: grid; place-items: center; background: var(--green); color: #fff; font-size: 2.6cqw; font-weight: 700; }
.back .ans { flex: 1; min-width: 0; font-family: var(--label); font-weight: 700; font-size: clamp(11px, 3.3cqw, 19px); line-height: 1.02; text-transform: uppercase; letter-spacing: .3px; }
.back .pts { font-family: var(--display); font-size: clamp(14px, 4.4cqw, 24px); font-variant-numeric: tabular-nums; padding-left: 1.6cqw; border-left: 2px solid #08184d44; }
.tile.missed .back { background: linear-gradient(#6d7a99, #46526f); color: #eef2fb; box-shadow: inset 0 0 0 .5cqw #8f9bba; }
.tile.missed .mark { background: var(--red); }
.tile.missed .back .pts { border-left-color: #ffffff44; }

/* ---------- Controls ---------- */
.controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
form.guess { display: flex; gap: 8px; }
#guess-input {
  flex: 1; min-width: 0; width: 100%;
  font: 700 18px var(--body); color: var(--ink);
  background: #020a24; border: 2px solid var(--neon); border-radius: 12px; padding: 12px 14px;
  box-shadow: inset 0 0 12px #3a8dff33;
}
#guess-input::placeholder { color: #6f82ad; }
#guess-input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px #ffc61a55; }
button {
  font: 400 19px var(--display); letter-spacing: .6px; text-transform: uppercase;
  color: #fff; border: 2px solid #7fc0ff; border-radius: 12px; padding: 11px 18px; cursor: pointer;
  background: linear-gradient(#2d7cf0, #0d3fa8);
  box-shadow: 0 4px 0 #04103a, 0 0 14px #3a8dff88, inset 0 1px 0 #ffffff55;
}
button:active { transform: translateY(2px); box-shadow: 0 2px 0 #04103a, 0 0 10px #3a8dff88; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
button:disabled { opacity: .4; cursor: default; }
button.ghost { background: transparent; box-shadow: none; border-color: #3a5a9a; color: var(--muted); font-family: var(--label); font-weight: 700; font-size: 15px; letter-spacing: 1px; }
button.gold { background: linear-gradient(var(--gold-hi), var(--gold) 55%, #d98f00); color: #2a1a00; border-color: #fff2b0; box-shadow: 0 5px 0 var(--gold-dk), 0 0 16px #ffc61a88, inset 0 2px 0 #ffffffaa; }
button.big { font-size: clamp(22px, 6vw, 28px); padding: 14px; width: 100%; }
.row { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.bigx {
  position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-family: var(--display); font-size: min(50vw, 300px); color: var(--red);
  text-shadow: 0 0 40px #ff3b4e, 0 0 4px #fff; opacity: 0; z-index: 20;
}
.bigx.show { animation: xflash .7s ease-out; }
@keyframes xflash { 0% { opacity: 0; transform: scale(1.4); } 20% { opacity: 1; transform: scale(1); } 100% { opacity: 0; } }

/* ---------- Final inspection ---------- */
.final { display: grid; gap: 12px; }
.endhero { position: relative; border-radius: 14px; overflow: hidden; border: 3px solid var(--rc, var(--gold)); box-shadow: 0 0 26px var(--rg, #ffc61a66); }
.endhero img { width: 100%; aspect-ratio: 1400 / 788; object-fit: cover; }
.endtitle { position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 12px 10px; text-align: center; background: linear-gradient(transparent, rgba(3,8,20,.9)); }
.endtitle b { display: block; font-family: var(--display); font-weight: 400; font-size: clamp(38px, 11vw, 60px); line-height: 1; color: var(--rc, var(--gold)); text-shadow: 0 3px 0 #000, 0 0 18px var(--rg, #ffc61a); letter-spacing: 1px; }
.endtitle span { display: block; font-family: var(--label); font-weight: 700; font-size: 14px; letter-spacing: 1.6px; text-transform: uppercase; margin-top: 3px; }
.endhero.rework { --rc: #ff5a6a; --rg: #ff3b4e88; }
.rankp { text-align: center; padding: 12px; }
.rankp .k { font-family: var(--label); font-weight: 700; letter-spacing: 1.6px; font-size: 13px; color: var(--muted); text-transform: uppercase; }
.rankname { font-family: var(--display); font-size: clamp(28px, 8.5vw, 42px); line-height: 1.05; margin: 4px 0 8px;
  background: linear-gradient(var(--gold-hi), var(--gold) 55%, #d98f00); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 3px 0 #3d2a00); }
.ladder { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.ladder span { font-family: var(--label); font-weight: 700; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; padding: 4px 9px; border-radius: 999px; background: #041038; color: var(--muted); border: 1px solid #2f4f8f; }
.ladder span.on { background: var(--gold); color: #2a1a00; border-color: var(--gold); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: #041038; border: 1px solid #2f4f8f; border-radius: 10px; padding: 9px; text-align: center; }
.kpi b { display: block; font-family: var(--display); font-weight: 400; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--gold-hi); }
.kpi span { font-family: var(--label); font-weight: 700; font-size: 12.5px; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; }
.recap { padding: 12px 14px; }
.recap h2 { margin: 0 0 8px; font-family: var(--display); font-weight: 400; font-size: 20px; color: var(--gold-hi); text-align: center; letter-spacing: .5px; }
.rq { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-top: 1px solid #2f4f8f; }
.rq:first-of-type { border-top: 0; }
.rq .q { font-size: 14.5px; color: var(--muted); grid-column: 1 / -1; }
.rq .a { font-family: var(--label); font-weight: 700; font-size: 16px; text-transform: uppercase; letter-spacing: .4px; }
.rq .s { font-family: var(--display); font-size: 16px; color: var(--gold); text-align: right; }
.rq .ok { color: #7dffa8; }

/* ---------- Footer ---------- */
.foot { text-align: center; padding: 12px 14px; display: grid; gap: 4px; border-top: 3px solid var(--gold); background: linear-gradient(#0a215e, #04103a); border-radius: 0 0 12px 12px; }
.foot .ethics { font-style: italic; font-size: 18px; }
.foot .values { color: var(--muted); font-family: var(--label); font-weight: 700; font-size: 15px; letter-spacing: 1px; }
.foot small { color: #7c8fb8; font-size: 12.5px; line-height: 1.45; }

/* ---------- Phone landscape / fullscreen ----------
   Short, wide screens: scoreboard and stage in a sticky left column sized from the screen height,
   everything else in a right column. Desktop and portrait layouts are untouched. */
@media (orientation: landscape) and (max-height: 540px) {
  .wrap {
    --gap: 8px;
    --col-h: calc(100vh - 2 * var(--gap));
    max-width: none;
    padding-block: var(--gap);
    grid-template-columns: min(calc((var(--col-h) - 56px) * var(--stage-aspect)), 50vw) minmax(0, 1fr);
    align-items: start;
    column-gap: 14px;
    row-gap: 8px;
  }
  @supports (height: 100dvh) { .wrap { --col-h: calc(100dvh - 2 * var(--gap)); } }
  .stagecol { grid-column: 1; grid-row: 1 / span 8; position: sticky; top: var(--gap); }
  .wrap > :not(.stagecol) { grid-column: 2; }
  .hud .k { font-size: 10px; } .hud b { font-size: 19px; }
  .msg { min-height: 0; padding: 7px 12px; font-size: 16px; }
  .question { padding: 7px 12px 9px; }
  .question h1 { font-size: clamp(16px, 2.5vw, 21px); }
  #guess-input { padding: 9px 12px; font-size: 17px; }
  button { padding: 8px 14px; font-size: 17px; }
  button.ghost { font-size: 14px; }
  .foot { padding: 8px 12px; } .foot .ethics { font-size: 16px; }
}
/* ---------- Desktop / wide screens ----------
   Stage on the left, question, board and answer box on the right, so the whole show
   fits on one screen without scrolling. */
@media (min-width: 960px) and (min-height: 541px) {
  .wrap {
    max-width: min(1640px, calc((100vh - 110px) * 2.75));
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 22px;
    align-items: start;
    padding-block: 16px 28px;
  }
  .stagecol { grid-column: 1; grid-row: 1 / span 5; position: sticky; top: 16px;
    width: 100%; max-width: calc((100vh - 110px) * 1270 / 941); justify-self: end; }
  .wrap > :not(.stagecol) { grid-column: 2; }
  .wrap > .final, .wrap > .foot { grid-column: 1 / -1; width: 100%; max-width: 760px; justify-self: center; }
  .question h1 { font-size: clamp(22px, 2vw, 28px); }
}

/* ---------- Phone, portrait ----------
   Put the answer box right under the question, so when the keyboard opens you still see
   the question, what you're typing and the top of the board. */
@media (max-width: 700px) and (orientation: portrait) {
  /* Fit stage, question, answer box and the board on the first screen. */
  .wrap { gap: 8px; padding-top: 6px; }
  .stagecol { order: 0; gap: 6px; }
  .msg { order: 1; } .question { order: 2; }
  /* The answer box stays above the board; Sound / Give up drop below it. */
  .controls { display: contents; }
  form.guess { order: 3; } .board { order: 4; }
  .controls .row { order: 5; margin-top: 2px; }
  .final { order: 6; } .foot { order: 7; }

  /* Tighter camera on the stage: trim truss above the host's head and floor under the
     podium (55px top and bottom of the 941px art). Host and podium keep their size;
     their top offsets are re-based on the shorter frame. */
  .stage { --stage-aspect: 1270 / 831; }
  .host { top: -0.08%; }
  .podium { top: 61.73%; }
  .curtain-logo { width: 54%; }
  .curtain button { padding-block: 9px; }

  .hud .hcell { padding: 2px 4px 3px; }
  .msg { padding: 7px 12px; font-size: 16px; line-height: 1.2; min-height: 0; }
  .question { padding: 7px 14px 9px; gap: 2px; }
  /* "We surveyed 100 inspectors" is already said by the host; keep the line only for double points */
  .eyebrow:not(:has(.double)) { display: none; }
  .eyebrow { font-size: 12.5px; }
  .question h1 { font-size: clamp(18px, 5vw, 21px); }
  #guess-input { padding: 10px 14px; }
  form.guess button { padding-block: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile-inner, .react, .strike, .host, .curtain-logo { transition: none; animation: none; }
  .stage.bad { animation: none; }
  .bigx.show { animation-duration: .01s; }
}
