/*
 * ISC Trivia — InterSystems Frost theme.
 * Brand tokens from @intersystems/styles (Frost): indigo #333695, teal #00a19c.
 * Mobile-first: player screens are designed for phones (320px+), host for projectors.
 */

/* Inter (variable, 400–800) is self-hosted so pages make no third-party requests.
   Font files from @fontsource-variable/inter 5.3.0, SIL OFL 1.1 — see fonts/Inter-LICENSE.txt */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(../fonts/inter-latin-wght-normal.woff2) format("woff2-variations"), url(../fonts/inter-latin-wght-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(../fonts/inter-latin-ext-wght-normal.woff2) format("woff2-variations"), url(../fonts/inter-latin-ext-wght-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
:root {
  --brand: #333695;
  --brand-50: #eef0fb;
  --brand-100: #d9ddf4;
  --brand-200: #b3baea;
  --brand-600: #2c2f83;
  --brand-700: #242679;
  --brand-900: #17194f;
  --teal: #00a19c;
  --teal-50: #dffaf8;
  --teal-100: #b8f0ec;
  --teal-700: #0a6d68;
  --neutral: #646464;
  --amber: #e59a1c;
  --coral: #d6455d;
  --coral-50: #fdecef;

  --paper: #fbfcff;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --surface-3: #ecf0f8;
  --ink: #1b2240;
  --muted: #66708f;
  --line: #dfe4f0;
  --line-strong: #c8d0e3;

  --r-sm: 9px;
  --r-md: 12px;
  --r-lg: 18px;
  --shadow: 0 10px 28px rgba(28, 34, 69, .07);
  --grad: linear-gradient(90deg, #333695, #00a19c);

  --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;
  padding: 0;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

/* ---------- Shared building blocks ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

/* Card with the 4px indigo→teal top strip */
.card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--grad);
}

.title-gradient {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: var(--r-md);
  font-weight: 600;
  transition: background-color .15s, transform .05s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-600); }
.btn-teal { background: var(--teal); color: #fff; }
.btn-teal:hover:not(:disabled) { background: var(--teal-700); }
.btn-ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn:focus-visible, .input:focus-visible, .opt:focus-visible { outline: none; box-shadow: 0 0 0 4px rgba(0, 161, 156, .3); }

.input {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  font-size: 16px; /* ≥16px stops iOS zooming on focus */
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  outline: none;
}
.input:focus { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(0, 161, 156, .15); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--brand-50);
  color: var(--brand-700);
  white-space: nowrap;
}
.chip-teal { background: var(--teal-50); color: var(--teal-700); }

.muted { color: var(--muted); }
.error { color: var(--coral); font-size: 14px; font-weight: 500; min-height: 20px; margin: 8px 0 0; }

/* ---------- Answer options: color + shape + letter ---------- */
.opt-0 { --opt: var(--brand); --opt-ink: #fff; }
.opt-1 { --opt: var(--teal); --opt-ink: #fff; }
.opt-2 { --opt: var(--amber); --opt-ink: var(--ink); }
.opt-3 { --opt: var(--coral); --opt-ink: #fff; }

.shape { width: 1em; height: 1em; flex: none; fill: currentColor; }

/* ---------- Connection banner ---------- */
.banner {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 50;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* =====================================================================
 * PLAYER (phone)
 * ===================================================================== */
.player {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + var(--safe-t)) calc(14px + var(--safe-r)) 8px calc(14px + var(--safe-l));
  background: rgba(255, 255, 255, .92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .mark { width: 36px; height: 36px; border-radius: 8px; flex: none; }
.topbar .who { flex: 1; min-width: 0; line-height: 1.2; }
.topbar .who b { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .who span { font-size: 12px; color: var(--muted); }
.topbar .score { font-weight: 700; font-size: 16px; color: var(--brand); white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--teal); flex: none; }
.dot.off { background: var(--coral); }

.screen {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.screen.center { justify-content: center; }

/* Join */
.join-logo { background: #fff; border-radius: var(--r-lg); padding: 18px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.join-logo img { width: 100%; height: auto; }
.join h1 { font-size: clamp(22px, 6vw, 30px); margin: 4px 0 0; line-height: 1.15; }
.join p { margin: 0; }
.join form { display: flex; flex-direction: column; gap: 12px; }
.join label { font-weight: 600; font-size: 14px; }
.btn-big { min-height: 56px; font-size: 18px; width: 100%; border-radius: var(--r-md); }

/* Waiting / lobby */
.wait { text-align: center; align-items: center; }
.wait h2 { font-size: clamp(24px, 7vw, 32px); margin: 0; }
.pulse {
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--grad);
  animation: pulse 1.6s ease-in-out infinite;
  display: grid; place-items: center; color: #fff; font-size: 34px;
}
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.88); opacity: .75; } }

/* Question */
.qmeta { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.qnum { font-weight: 700; color: var(--muted); font-size: 14px; }
.timebar-wrap {
  position: sticky;
  top: calc(53px + var(--safe-t));
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  background: var(--paper);
}
.timebar { flex: 1; height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.timebar i { display: block; height: 100%; width: 100%; background: var(--grad); transform-origin: left; border-radius: inherit; }
.timebar.low i { background: var(--coral); }
.secs { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 20px; min-width: 2ch; text-align: right; }
.secs.low { color: var(--coral); }
.qtext { font-size: clamp(20px, 5.6vw, 28px); font-weight: 700; line-height: 1.25; margin: 0; overflow-wrap: anywhere; }

.opts { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 600px) { .opts { grid-template-columns: 1fr 1fr; } }
.opt {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--opt);
  color: var(--opt-ink);
  font-size: 17px;
  font-weight: 600;
  text-align: left;
  line-height: 1.25;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .15);
  overflow-wrap: anywhere;
  transition: opacity .2s, transform .1s;
}
.opt:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .15); }
.opt .shape { font-size: 22px; }
.opt .letter { font-weight: 800; opacity: .8; }
.opt:disabled { cursor: default; }
.opts.locked .opt:not(.chosen) { opacity: .3; }
.opt.chosen { outline: 4px solid var(--ink); outline-offset: 2px; }
.status { text-align: center; font-weight: 600; color: var(--muted); }

/* Reveal */
.result { text-align: center; padding: 22px 16px; border-radius: var(--r-lg); color: #fff; }
.result.ok { background: var(--teal); }
.result.bad { background: var(--coral); }
.result.none { background: var(--neutral); }
.result .big { font-size: clamp(26px, 8vw, 36px); font-weight: 800; margin: 0; }
.result .pts { font-size: 18px; font-weight: 600; margin-top: 4px; opacity: .95; }
.answer-pill {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: var(--r-md);
  background: var(--opt); color: var(--opt-ink); font-weight: 700;
}
.answer-pill .shape { font-size: 20px; }
.explain h3 { margin: 4px 0 6px; font-size: 20px; }
.explain p { margin: 0; line-height: 1.5; color: var(--ink); }
.explain img { width: 100%; max-height: 42vh; object-fit: cover; border-radius: var(--r-md); margin-top: 12px; background: var(--surface-2); }
.standing { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 600; }
.standing b { font-size: 22px; color: var(--brand); }

/* Leaderboard (shared by player + host) */
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.board li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line);
}
.board li.me { border-color: var(--teal); background: var(--teal-50); }
.board .rk { width: 2.2em; font-weight: 800; color: var(--brand); font-variant-numeric: tabular-nums; }
.board .nm { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .sc { font-weight: 700; font-variant-numeric: tabular-nums; }
.myrank { text-align: center; }
.myrank .rank { font-size: clamp(44px, 14vw, 64px); font-weight: 800; line-height: 1; margin: 6px 0; }
.empty { text-align: center; color: var(--muted); padding: 20px; }

/* End */
.end-logo { background: #fff; border-radius: var(--r-lg); padding: 16px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.end-logo img { width: 100%; height: auto; }

/* =====================================================================
 * HOST (projector)
 * ===================================================================== */
.host {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
.hostbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.hostbar::after { content: ""; position: absolute; inset: auto 0 -1px 0; height: 4px; background: var(--grad); }
.hostbar .logo { height: 46px; width: auto; }
.hostbar .spacer { flex: 1; }
.hostbar .controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 28px 32px;
}
.hint { text-align: center; font-size: 12px; color: var(--muted); padding: 8px; }

/* Lobby */
.lobby { display: grid; grid-template-columns: 1.3fr 1fr; gap: 28px; align-items: start; }
.lobby h1 { font-size: clamp(36px, 4.4vw, 64px); margin: 0; line-height: 1.05; }
.lobby .sub { font-size: clamp(18px, 1.8vw, 26px); font-weight: 600; margin: 6px 0 14px; color: var(--muted); }
.lobby .desc { font-size: clamp(16px, 1.4vw, 21px); line-height: 1.5; margin: 0 0 18px; }
.lobby .facts { display: flex; gap: 8px; flex-wrap: wrap; }
.steps { list-style: none; padding: 0; margin: 26px 0 0; display: flex; flex-direction: column; gap: 14px; }
.steps li { display: flex; align-items: center; gap: 14px; font-size: clamp(17px, 1.5vw, 22px); font-weight: 600; }
.steps b { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--grad); color: #fff; }
.joinbox { text-align: center; }
.joinbox .qr { width: min(100%, 360px); aspect-ratio: 1; margin: 6px auto 12px; }
.joinbox .qr img { width: 100%; height: 100%; }
.joinbox .url { font-size: clamp(20px, 2vw, 30px); font-weight: 800; color: var(--brand); word-break: break-all; }
.joinbox select { margin-top: 10px; max-width: 100%; }
.players-head { display: flex; align-items: baseline; gap: 12px; }
.players-head h2 { margin: 0; font-size: 24px; }
.names { display: flex; flex-wrap: wrap; gap: 8px; max-height: 32vh; overflow: auto; }
.names button {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; font-size: 16px;
  animation: pop .25s ease-out;
}
.names button:hover { border-color: var(--coral); color: var(--coral); text-decoration: line-through; }
.names button.off { opacity: .45; }
.names button.seen { animation: none; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Question / reveal */
.hq-top { display: flex; align-items: center; gap: 14px; }
.hq-top .qnum { font-size: 18px; }
.hq-top .chip { font-size: 15px; padding: 5px 14px; }
.hq-top .spacer { flex: 1; }
.answered { font-size: 20px; font-weight: 700; color: var(--muted); }
.answered b { color: var(--ink); font-size: 28px; }
.hq-body { display: flex; gap: 28px; align-items: center; }
.hq-text { flex: 1; font-size: clamp(30px, 3.6vw, 56px); font-weight: 800; line-height: 1.15; margin: 0; }
.ring { position: relative; width: 150px; height: 150px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring .bg { stroke: var(--surface-3); }
.ring .fg { stroke: url(#ringgrad); stroke-linecap: round; transition: stroke .2s; }
.ring.low .fg { stroke: var(--coral); }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 54px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ring.low span { color: var(--coral); }

.htiles { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.htile {
  position: relative;
  display: flex; align-items: center; gap: 18px;
  min-height: clamp(110px, 15vh, 190px); padding: 18px 24px;
  border-radius: var(--r-lg);
  background: var(--opt); color: var(--opt-ink);
  font-size: clamp(22px, 2.2vw, 34px); font-weight: 700; line-height: 1.2;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .15);
  overflow: hidden;
  transition: opacity .3s, filter .3s;
}
.htile .shape { font-size: 40px; }
.htile .count { margin-left: auto; font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; position: relative; }
.htile .label { position: relative; flex: 1; }
.htile .bar { position: absolute; inset: auto auto 0 0; height: 8px; background: rgba(255, 255, 255, .55); transition: width .6s ease-out; }
.opt-2 .bar { background: rgba(27, 34, 64, .35); }
.htiles.revealed .htile { min-height: clamp(80px, 10vh, 120px); }
.htiles.revealed .htile:not(.correct) { opacity: .35; filter: saturate(.6); }
.htile.correct { outline: 6px solid var(--ink); outline-offset: 3px; }
.htile.correct .label::after { content: "  ✓"; }

.reveal-row { display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; align-items: stretch; }
.reveal-card h2 { font-size: clamp(28px, 3vw, 48px); margin: 4px 0 10px; }
.reveal-card p { font-size: clamp(18px, 1.6vw, 26px); line-height: 1.45; margin: 0; }
.reveal-img { border-radius: var(--r-lg); overflow: hidden; background: #fff; border: 1px solid var(--line); height: 46vh; }
.reveal-img img { width: 100%; height: 100%; object-fit: contain; }
.hq-small { font-size: clamp(22px, 2.2vw, 34px); font-weight: 700; margin: 0; }

/* Leaderboard */
.hboard-wrap { max-width: 1000px; width: 100%; margin: 0 auto; }
.hboard-wrap h1 { text-align: center; font-size: clamp(34px, 4vw, 58px); margin: 0 0 20px; }
.hboard li { padding: 14px 22px; font-size: clamp(20px, 2vw, 30px); animation: slidein .4s ease-out both; }
.hboard li:nth-child(1) { border-color: var(--brand); background: var(--brand-50); }
@keyframes slidein { from { transform: translateX(-20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* On-demand leaderboard overlay (host) */
.lb-overlay {
  position: fixed;
  inset: 70px 0 0 0;
  z-index: 40;
  overflow: auto;
  padding: 28px 32px;
  background: rgba(251, 252, 255, .97);
  animation: fadein .2s ease-out;
}
.lb-overlay .close-hint { text-align: center; color: var(--muted); margin-top: 18px; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.btn-danger { color: var(--coral); }
.btn-danger:hover:not(:disabled) { background: var(--coral-50); }
.btn.active { background: var(--brand-50); border-color: var(--brand); color: var(--brand-700); }

/* Podium */
.podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; align-items: end; max-width: 1000px; width: 100%; margin: 0 auto; }
.pod { text-align: center; }
.pod .nm { font-size: clamp(22px, 2.4vw, 36px); font-weight: 800; margin-bottom: 4px; overflow-wrap: anywhere; }
.pod .sc { font-size: clamp(16px, 1.6vw, 24px); color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.pod .block {
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  color: #fff; font-size: clamp(40px, 5vw, 80px); font-weight: 800;
  display: grid; place-items: center;
  animation: rise .8s ease-out both;
  transform-origin: bottom;
}
.pod.p1 .block { height: 34vh; background: var(--grad); animation-delay: .6s; }
.pod.p2 .block { height: 25vh; background: var(--brand); animation-delay: .3s; }
.pod.p3 .block { height: 18vh; background: var(--teal); }
@keyframes rise { from { transform: scaleY(0); } to { transform: scaleY(1); } }

/* End */
.end { text-align: center; align-items: center; justify-content: center; }
.end .end-logo { width: min(80vw, 900px); padding: 24px 32px; }
.end h1 { font-size: clamp(40px, 5vw, 80px); margin: 10px 0 0; }
.end p { font-size: clamp(20px, 2vw, 30px); max-width: 900px; line-height: 1.45; margin: 0; }

/* Host auth */
.auth { max-width: 420px; margin: 12vh auto; display: flex; flex-direction: column; gap: 12px; }
.auth h1 { margin: 0; }

@media (max-width: 900px) {
  .lobby, .reveal-row { grid-template-columns: 1fr; }
  .htiles { grid-template-columns: 1fr; }
  .hq-body { flex-direction: column-reverse; align-items: stretch; }
  .ring { width: 110px; height: 110px; align-self: center; }
  .ring span { font-size: 40px; }
  .stage { padding: 18px; }
  .hostbar { padding: 10px 14px; flex-wrap: wrap; }
}
