:root {
  /* The Big Quiz Live colours */
  --navy: #0a0a1f;
  --pink: #f0197d;
  --yellow: #ffc915;
  --blue: #19a7f0;
  --purple: #7b2fd0;
  --bg: var(--navy);
  --bg-2: #0f0f2b;
  --card: #15153a;
  --line: #2c2c63;
  --text: #fbf6ee;
  --muted: #b9b7d6;
  /* coin colours */
  --gold: #f7c62a;
  --gold-2: #ffe27a;
  --gold-deep: #b97800;
  --silver: #cfd6df;
  --danger: #ff5c5c;
  --ok: #2ecc71;
  --radius: 20px;
  --display: "Lilita One", Impact, system-ui, sans-serif;
  --body: Nunito, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(1100px 560px at 50% -12%, rgba(240, 25, 125, .16), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(25, 167, 240, .13), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--body);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; }
a { color: var(--gold-2); }
.muted { color: var(--muted); }
.small { font-size: .88em; }
.error { color: var(--danger); min-height: 1.4em; margin: .5em 0 0; font-weight: 600; }

.title {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(44px, 14vw, 72px);
  line-height: .95;
  letter-spacing: .01em;
  color: var(--yellow);
  text-shadow: 4px 4px 0 var(--pink);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.title span { color: var(--text); text-shadow: 4px 4px 0 var(--blue); }
.title.small { font-size: 28px; text-shadow: 2px 2px 0 var(--pink); flex-direction: row; gap: .35em; align-items: baseline; }
.title.small span { text-shadow: 2px 2px 0 var(--blue); }
.title.small em { font-family: var(--body); font-style: normal; font-weight: 600; font-size: 15px; color: var(--muted); text-shadow: none; letter-spacing: .08em; text-transform: uppercase; }
.logo { max-width: 140px; max-height: 90px; object-fit: contain; }

.chip {
  display: inline-grid; place-items: center;
  width: 2.1em; height: 2.1em; border-radius: 50%;
  font-weight: 800; font-size: .85em; margin-right: .45em;
  color: #3a2600;
  background: radial-gradient(circle at 35% 30%, #fff7c9, var(--gold) 55%, var(--gold-deep));
  box-shadow: inset 0 0 0 2px rgba(122, 77, 0, .55);
}
.chip.silver { color: #262a30; background: radial-gradient(circle at 35% 30%, #fff, var(--silver) 55%, #8c95a1); box-shadow: inset 0 0 0 2px rgba(61, 67, 76, .55); }
.chip.time { color: var(--text); background: var(--line); box-shadow: none; }

.btn {
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  font: 700 16px/1 var(--body);
  padding: 14px 20px; border-radius: 14px;
  background: var(--line); color: var(--text);
  text-decoration: none;
  transition: transform .08s ease, filter .15s ease, background .15s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { font-family: var(--display); font-weight: 400; letter-spacing: .01em; background: var(--pink); color: #fff; border: 3px solid var(--text); box-shadow: 5px 5px 0 var(--yellow); }
.btn.primary:hover { filter: none; transform: translate(2px, 2px); box-shadow: 3px 3px 0 var(--yellow); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--line); }
.btn.small { padding: 10px 14px; font-size: 14px; }
.btn.big { font-size: 20px; padding: 18px 28px; }
.danger-text { color: var(--danger) !important; }
.link { background: none; border: 0; padding: 4px 6px; cursor: pointer; font: 600 14px var(--body); }

input[type="text"], input[type="password"], input:not([type]) {
  width: 100%; font: 600 20px var(--body); color: var(--text);
  background: var(--bg-2); border: 2px solid var(--line); border-radius: 14px;
  padding: 14px 16px; outline: none;
}
input:focus { border-color: var(--yellow); }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
label { font-weight: 600; color: var(--muted); display: block; margin-bottom: 8px; }

/* ===================================================== PLAYER (phones) */
body.player { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body.player.playing { overflow: hidden; position: fixed; inset: 0; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.screen {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  max-width: 480px; margin: 0 auto;
}
.lede { font-size: 19px; margin: 0; }
.rules { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin: 4px 0 6px; }
.rule { display: inline-flex; align-items: center; font-weight: 600; }
.join-form { width: 100%; text-align: left; margin-top: 6px; }
.join-form .btn { width: 100%; margin-top: 14px; font-size: 19px; padding: 18px; }
.kicker { text-transform: uppercase; letter-spacing: .14em; font-weight: 800; color: var(--pink); margin: 0; font-size: 14px; }
.team-name { font-family: var(--display); font-weight: 400; font-size: clamp(28px, 9vw, 44px); line-height: 1.05; word-break: break-word; }
.hint { color: var(--muted); font-size: 15px; max-width: 30ch; }
.pulse-coin {
  width: 86px; height: 86px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff7c9, var(--gold) 55%, var(--gold-deep));
  box-shadow: inset 0 0 0 5px rgba(122, 77, 0, .5), 0 0 40px rgba(247, 198, 42, .5);
  animation: flip 2.4s ease-in-out infinite;
}
@keyframes flip { 0%, 100% { transform: scaleX(1); } 50% { transform: scaleX(.12); } }

.play { position: fixed; inset: 0; overflow: hidden; touch-action: none; }
#field { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.hud {
  position: absolute; left: 0; right: 0; top: 0;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  background: linear-gradient(180deg, rgba(11, 13, 23, .92), rgba(11, 13, 23, 0));
  pointer-events: none;
}
.hud-item { display: flex; flex-direction: column; line-height: 1; min-width: 64px; }
.hud-item.right { text-align: right; align-items: flex-end; }
.hud-item small { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 800; }
.hud-item b { font-family: var(--display); font-weight: 400; font-size: 34px; color: var(--gold); display: inline-block; }
.hud-team { text-align: center; font-weight: 800; color: var(--muted); font-size: 14px; min-width: 0; align-items: center; gap: 4px; }
.hud-team span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-team small { color: var(--yellow); letter-spacing: .06em; }
body.hurry #time { color: var(--danger); animation: throb .5s ease-in-out infinite alternate; }
@keyframes throb { to { transform: scale(1.15); } }
#score.bump-up { animation: bumpUp .3s ease; }
#score.bump-down { animation: bumpDown .35s ease; }
@keyframes bumpUp { 40% { transform: scale(1.35); color: var(--gold-2); } }
@keyframes bumpDown { 30% { transform: translateX(-6px); color: var(--danger); } 60% { transform: translateX(6px); color: var(--danger); } }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; font-family: var(--display); color: var(--gold); text-shadow: 0 5px 0 var(--gold-deep), 0 0 40px rgba(247, 198, 42, .5); }
.overlay.ov-count { font-size: 42vmin; animation: pop .9s ease-out infinite; }
.overlay.ov-go { font-size: 24vmin; color: var(--ok); text-shadow: 0 5px 0 #138a5b; }
.overlay.ov-over { font-size: 12vmin; background: rgba(11, 13, 23, .55); }
@keyframes pop { from { transform: scale(1.25); opacity: .4; } 30% { transform: scale(1); opacity: 1; } }

.final-score { display: flex; flex-direction: column; align-items: center; line-height: 1; margin: 6px 0; }
.final-score span { font-family: var(--display); font-size: 96px; color: var(--gold); text-shadow: 0 5px 0 var(--gold-deep); }
.final-score small { color: var(--muted); font-weight: 800; letter-spacing: .14em; text-transform: uppercase; margin-top: 8px; }
.rank { font-size: 24px; font-weight: 800; margin: 0; }
.offline-pill { position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--danger); color: #fff; font-weight: 700; padding: 8px 16px; border-radius: 99px; z-index: 10; }

/* ===================================================== TV */
body.tv { overflow: hidden; height: 100vh; font-size: clamp(14px, 1.15vw, 28px); }
.tv-wrap {
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(250px, 24vw) 1fr;
  grid-template-rows: auto 1fr;
  gap: 2vh 2.4vw;
  padding: 3vh 3vw;
}
.tv-head { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.brand { display: flex; align-items: center; gap: 1.2vw; }
.brand .logo { max-height: 9vh; max-width: 14vw; }
.tv .title { flex-direction: row; gap: .3em; font-size: 4.6vw; }
.tv-status { font-weight: 800; font-size: 2vw; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); text-align: center; }
.tv.phase-running .tv-status { color: var(--yellow); }
.tv.phase-finished .tv-status { color: var(--gold-2); }
.tv-timer { justify-self: end; font-family: var(--display); font-size: 6vw; line-height: 1; color: var(--text); font-variant-numeric: tabular-nums; min-width: 4.2ch; text-align: right; }
.tv-timer.hurry { color: var(--danger); animation: throb .5s ease-in-out infinite alternate; }

.tv-join {
  background: var(--card); border: 3px solid var(--pink); border-radius: 2vw;
  padding: 2.4vh 1.6vw; display: flex; flex-direction: column; align-items: center; gap: 1.2vh; text-align: center;
  align-self: start;
}
.qr { width: 100%; max-width: 20vw; aspect-ratio: 1; background: #fff; border-radius: 1.2vw; padding: .6vw; }
.qr svg, .qr img { width: 100%; height: 100%; display: block; }
.join-label { margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .14em; font-weight: 800; font-size: .8em; }
.join-url { margin: 0; font-family: var(--display); font-size: 1.3em; word-break: break-all; color: var(--yellow); }
.legend { display: flex; gap: 1.2vw; font-weight: 600; justify-content: center; flex-wrap: wrap; }
.legend > span { display: inline-flex; align-items: center; }
.team-count { margin: 0; font-weight: 800; font-size: 1.4em; }

.tv-main { min-height: 0; position: relative; overflow: hidden; }
/* One team per line, big enough to read from the back of the pub. */
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.2vh; grid-template-columns: 1fr; align-content: start; }
.board-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 2.4vw; font-weight: 600; margin: 0; }
.row {
  --pct: 0;
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: 2.2em 1fr auto 3em; align-items: center; gap: 1.4vw;
  padding: .9vh 1.4vw; border-radius: 1vw;
  background: var(--card); border: 3px solid var(--line);
  font-size: clamp(26px, min(3.6vw, 7.5vh), 96px); line-height: 1.15;
  transition: transform .6s cubic-bezier(.2, .8, .2, 1), opacity .3s ease;
}
.row::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(90deg, rgba(247, 198, 42, .28), rgba(247, 198, 42, .08));
  transform-origin: left; transform: scaleX(var(--pct));
  transition: transform .5s ease;
}
.row > * { position: relative; z-index: 1; }
.row .rank { font-family: var(--display); color: var(--muted); text-align: center; font-size: 1em; font-weight: 400; }
.row .name.long { font-size: .78em; }
.row .name.longer { font-size: .64em; }
.row .name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .split { display: flex; gap: .6em; font-size: .5em; font-weight: 700; color: var(--muted); }
.row .split i { font-style: normal; display: inline-flex; align-items: center; gap: .3em; }
.row .split i::before { content: ""; width: .9em; height: .9em; border-radius: 50%; background: var(--gold); }
.row .split i.s::before { background: var(--silver); }
.row .pts { font-family: var(--display); text-align: right; color: var(--gold); font-variant-numeric: tabular-nums; }
.row.neg .pts { color: var(--danger); }
.row.is-offline { opacity: .55; }
.row.enter { animation: rowIn .45s ease; }
.row.up { animation: flashUp .6s ease; }
.row.down { animation: flashDown .6s ease; }
@keyframes rowIn { from { opacity: 0; transform: translateY(14px) scale(.97); } }
@keyframes flashUp { 30% { border-color: var(--gold); box-shadow: 0 0 24px rgba(247, 198, 42, .45); } }
@keyframes flashDown { 30% { border-color: var(--danger); } }

.tv.phase-finished .row[data-rank="1"] { border-color: var(--gold); box-shadow: 0 0 34px rgba(247, 198, 42, .45); }
.tv.phase-finished .row[data-rank="1"] .rank { color: var(--gold); }
.tv.phase-finished .row[data-rank="2"] .rank { color: var(--silver); }
.tv.phase-finished .row[data-rank="3"] .rank { color: #e0985b; }

.tv-count {
  position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-family: var(--display); font-size: 34vh; color: var(--gold);
  text-shadow: 0 1.2vh 0 var(--gold-deep), 0 0 8vh rgba(247, 198, 42, .5);
  background: rgba(11, 13, 23, .6);
  opacity: 0; transition: opacity .2s ease;
}
.tv-count.show { opacity: 1; animation: pop .95s ease-out infinite; }
.tv-count.go { color: var(--ok); text-shadow: 0 1.2vh 0 #138a5b; }

.sound-gate {
  position: fixed; inset: 0; z-index: 20; border: 0; cursor: pointer;
  background: rgba(11, 13, 23, .88); color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.5vh;
  font-family: var(--body); font-size: 2.2vw;
}
.sound-gate small { color: var(--muted); font-size: .6em; }
.sound-icon { width: 12vh; height: 12vh; border-radius: 50%; display: grid; place-items: center; font-size: 7vh; background: var(--gold); color: #2a1c00; }
.sound-toggle { position: fixed; right: 1.5vw; bottom: 1.5vh; z-index: 5; border: 0; cursor: pointer; border-radius: 99px; padding: .5em 1em; font: 700 14px var(--body); background: var(--line); color: var(--text); opacity: .5; }
.sound-toggle:hover { opacity: 1; }
.sound-toggle.off { background: var(--danger); opacity: .9; }

/* ===================================================== HOST */
body.host { padding-bottom: 40px; }
.host-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; max-width: 1100px; margin: 0 auto; }
.badge { font-weight: 800; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; padding: 6px 12px; border-radius: 99px; background: var(--line); color: var(--muted); }
.badge.countdown, .badge.running { background: var(--ok); color: #05301e; }
.badge.finished { background: var(--yellow); color: var(--navy); }
.card { background: var(--card); border: 3px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card h2 { font-size: 20px; margin-bottom: 10px; display: flex; align-items: center; gap: 10px; }
.card.narrow { max-width: 420px; margin: 8vh auto 0; }
.card.narrow .btn { width: 100%; margin-top: 14px; }
.host-grid { max-width: 1100px; margin: 0 auto; padding: 0 16px; display: grid; gap: 16px; grid-template-columns: 1.2fr 1fr; }
.host-grid .control { grid-row: span 1; }
.host-grid .teams { grid-column: 1 / -1; }
.timer-wrap { text-align: center; margin-bottom: 16px; }
.big-timer { font-family: var(--display); font-size: clamp(56px, 12vw, 96px); line-height: 1; color: var(--gold); font-variant-numeric: tabular-nums; }
.timer-wrap p { margin: 6px 0 0; font-weight: 600; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn-row .btn.big { flex: 1 1 260px; }
.btn-row.secondary { margin-top: 12px; }
.btn-row.secondary .btn { flex: 1 1 200px; font-size: 14px; padding: 12px; }
.toggle { display: flex; align-items: center; gap: 10px; margin-top: 16px; color: var(--text); font-weight: 600; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--gold); }
.now-playing { font-weight: 700; padding: 12px 14px; border-radius: 12px; background: var(--bg-2); margin: 10px 0; color: var(--muted); word-break: break-word; }
.now-playing.set { color: var(--gold-2); }
#preview, #cheerPreview { width: 100%; margin-bottom: 10px; }
.upload-row { display: flex; gap: 10px; flex-wrap: wrap; }
.progress { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; margin-top: 12px; }
.progress span { display: block; height: 100%; width: 0; background: var(--gold); transition: width .15s; }
.count { background: var(--line); border-radius: 99px; padding: 2px 10px; font-size: 14px; }
.team-table { width: 100%; border-collapse: collapse; font-size: 16px; }
.team-table th { text-align: left; color: var(--muted); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; padding: 6px 8px; border-bottom: 2px solid var(--line); }
.team-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); }
.team-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.team-table .strong { font-weight: 800; color: var(--gold); }
.team-table .act { text-align: right; width: 1%; }
.team-table tr.is-offline td { opacity: .6; }
.team-table .team { font-weight: 700; word-break: break-word; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); margin-right: 8px; vertical-align: middle; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

@media (max-width: 760px) {
  .host-grid { grid-template-columns: 1fr; }
  .team-table th:nth-child(4), .team-table th:nth-child(5), .team-table td:nth-child(4), .team-table td:nth-child(5) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Everyone is level before the first game, so hide the rank numbers in the lobby. */
.tv.phase-lobby .row .rank { visibility: hidden; }
