@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&display=swap');

:root {
  --paper: #f5f1ea; --ink: #1d1b19; --muted: #6f6a62; --line: #e2dcd2; --card: #fffdf9;
  --accent: #ff5a3c; --good: #1f9d6b; --bad: #d9443a;
  --a: #3b5bdb; --b: #0f9d9a; --c: #e8a317; --d: #c2418c;
}
* { box-sizing: border-box; }
html { font-size: 18px; }
html, body { margin: 0; }
body {
  font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
  background: var(--paper); color: var(--ink); font-weight: 500; min-height: 100vh; min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 880px; margin: 0 auto; padding: 16px; }
h1, h2, h3 { margin: .4em 0; letter-spacing: -.02em; font-weight: 700; }
h1 { font-size: clamp(1.8em, 6vw, 2.8em); line-height: 1.15; }
h2 { font-size: 1.6em; }
.center { text-align: center; }
.muted { color: var(--muted); }
.brand { font-weight: 700; font-size: 1.1em; letter-spacing: -.02em; }
.brand::before { content: "⚡"; display: inline-block; margin-right: 6px; animation: zap 1.8s infinite; }
@keyframes zap { 50% { transform: scale(1.25) rotate(-10deg); } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin: 12px 0; }
input, select, button, textarea { font: inherit; color: inherit; }
input, select { width: 100%; padding: 14px 16px; border-radius: 12px; border: 2px solid var(--line); font-size: 1.2em; font-weight: 700; background: #fff; margin: 6px 0; }
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
button { cursor: pointer; border: 2px solid var(--ink); border-radius: 999px; padding: 14px 26px; font-size: 1.1em; font-weight: 700;
  background: var(--ink); color: var(--paper); transition: transform .1s; }
button:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.ghost { background: transparent; color: var(--ink); }
button.small { padding: 8px 16px; font-size: .95em; }
button.big { padding: 18px 44px; font-size: 1.4em; }
.error { color: var(--bad); min-height: 1.2em; }

/* Answers: lettered cards in a list */
.answers { display: grid; gap: 10px; margin-top: 16px; }
@media (min-width: 700px) { .answers { grid-template-columns: 1fr 1fr; } }
.answers button { display: flex; align-items: center; gap: 16px; text-align: left; min-height: 96px; font-size: 1.4em;
  background: var(--card); color: var(--ink); border: 2px solid var(--line); border-radius: 16px; padding: 16px 18px; }
.answers button:not(:disabled):hover { border-color: var(--ink); }
.shape { flex: none; width: 54px; height: 54px; border-radius: 12px; font-size: 1.1em; display: grid; place-items: center; color: #fff; font-weight: 700; }
.c0 .shape, .shape.c0 { background: var(--a); } .c1 .shape, .shape.c1 { background: var(--b); }
.c2 .shape, .shape.c2 { background: var(--c); } .c3 .shape, .shape.c3 { background: var(--d); }
.answers .picked { border: 3px solid var(--ink); }
.answers .dim { opacity: .35; }
.answers.host button { cursor: default; }

/* Timer: a draining bar with the seconds on top */
.timebar { position: relative; height: 48px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 12px 0; }
.timebar i { position: absolute; inset: 0 auto 0 0; background: var(--accent); transition: width .25s linear; }
.timebar span { position: relative; display: block; text-align: center; line-height: 48px; font-weight: 700; font-size: 1.4em; }

.bigcode { font-size: clamp(3em, 14vw, 7em); line-height: 1; font-weight: 700; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; background: var(--card); border: 2px solid var(--line); border-radius: 999px; padding: 8px 16px; margin: 4px; font-weight: 700;
  animation: pop .3s ease-out; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

.banner { font-size: 2.2em; font-weight: 700; padding: 18px; border-radius: 14px; color: #fff; animation: pop .4s ease-out; }
.banner.ok { background: var(--good); } .banner.bad { background: var(--bad); }

/* Leaderboard: rows slide from old rank to new, score bars grow */
.board { position: relative; margin: 12px 0; }
.row { position: absolute; left: 0; right: 0; height: 58px; font-size: 1.2em; display: flex; align-items: center; gap: 10px; overflow: hidden;
  background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 0 16px; font-weight: 700;
  transition: transform 1s cubic-bezier(.2,.8,.2,1), opacity .6s; }
.row .fill { position: absolute; inset: 0 auto 0 0; background: rgba(255,90,60,.12); transition: width 1.2s ease-out .4s; }
.row > span { position: relative; }
.row .rank { width: 32px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .gain { color: var(--good); font-size: .85em; animation: pop .5s 1s both; }
.row .score { font-variant-numeric: tabular-nums; }
.row.me { border: 3px solid var(--ink); }
.row.up .rank::after { content: "↑"; color: var(--good); margin-left: 2px; }

/* Answer distribution */
.bars { display: flex; justify-content: center; align-items: flex-end; gap: 14px; height: 150px; margin: 12px 0; }
.bar { width: 64px; font-size: 1.2em; border-radius: 10px 10px 0 0; display: flex; justify-content: center; color: #fff; font-weight: 700;
  padding-top: 6px; animation: grow .8s ease-out both; transform-origin: bottom; }
.bar.c0 { background: var(--a); } .bar.c1 { background: var(--b); } .bar.c2 { background: var(--c); } .bar.c3 { background: var(--d); }
@keyframes grow { from { transform: scaleY(0); } }

/* Final: top 3 cards revealed from 3rd to 1st */
.top3 { display: grid; gap: 10px; max-width: 520px; margin: 16px auto; }
.place { display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 18px; text-align: left; animation: rise .6s cubic-bezier(.2,.8,.2,1) both; }
.place .num { font-size: 2em; font-weight: 700; width: 44px; }
.place .who { flex: 1; font-weight: 700; font-size: 1.4em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place.p1 { order: 1; background: var(--ink); color: var(--paper); transform-origin: center; animation-delay: 2s; font-size: 1.15em; }
.place.p1 .num { color: var(--accent); }
.place.p2 { order: 2; animation-delay: 1s; } .place.p3 { order: 3; animation-delay: 0s; }
@keyframes rise { from { opacity: 0; transform: translateY(30px) scale(.95); } }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 8px; height: 8px; border-radius: 50%; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh); } }

.qedit { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.optrow { display: flex; align-items: center; gap: 8px; }
.optrow input[type=text] { flex: 1; }
.optrow input[type=radio] { width: 20px; height: 20px; accent-color: var(--good); }
.list-item { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 160px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Host lobby: PIN on the left, QR on the right (stacked on phones) */
.join { display: flex; justify-content: center; align-items: center; gap: 40px; flex-wrap: wrap; text-align: center; margin: 16px 0; }
.join p { font-size: 1.3em; margin: 0 0 8px; }
.qr { width: min(300px, 70vw); image-rendering: pixelated; border-radius: 16px; background: #fff; border: 2px solid var(--line); display: block; }
.names { display: flex; flex-wrap: wrap; justify-content: center; max-width: 900px; margin: 0 auto; }
.names .pill { font-size: 1.15em; }
.pill.mine { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* Join page */
.hero { margin-top: 9vh; }
.logo { font-size: clamp(2.6em, 12vw, 4em); }
.tagline { font-size: 1.15em; font-weight: 600; color: var(--muted); }
.join-form { max-width: 480px; margin: 12px auto; display: grid; gap: 22px; padding: 26px 22px; box-shadow: 0 18px 40px rgba(29,27,25,.08); }
.join-form label { display: grid; gap: 8px; font-weight: 700; }
.join-form input { margin: 0; }
.join-form button { margin-top: 6px; }
.join-form .error { margin: 0; }

/* Lively animated background for the player pages */
body.lively { background: linear-gradient(-45deg, #ffe1d6, #f5f1ea, #dde5ff, #d4f3ec, #fbe1ee);
  background-size: 400% 400%; animation: bgshift 16s ease infinite; }
@keyframes bgshift { 50% { background-position: 100% 50%; } }
.floaters { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.floaters span { position: absolute; bottom: -80px; display: grid; place-items: center; width: 1.7em; height: 1.7em;
  border-radius: .35em; font-weight: 700; opacity: .5; animation: floatup linear infinite; }
@keyframes floatup { to { transform: translateY(-120vh) rotate(320deg); } }
body.lively main { position: relative; z-index: 1; }
@media (prefers-reduced-motion: reduce) { body.lively, .floaters span, .brand::before { animation: none; } .floaters { display: none; } }
.pw { position: relative; display: block; }
.pw input { display: block; padding-right: 84px; } /* block: no gap under the input, so the button centers */
.pw button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: transparent;
  color: var(--muted); padding: 8px 12px; font-size: .9em; margin: 0; }
.pw button:hover { color: var(--ink); }
.pw button:active { transform: translateY(-50%); }
.join-form .error:empty { display: none; }

/* ---------- Host lobby, built for a projector ---------- */
main.wide { max-width: 1500px; }
.quiz-title { font-size: 1.2em; }
.stage { display: grid; grid-template-columns: 1.3fr 1fr; gap: 3vw; align-items: center; margin: 1vh 0 2vh; }
@media (max-width: 800px) { .stage { grid-template-columns: 1fr; } }
.pin-card { background: var(--ink); color: var(--paper); border-radius: 28px; padding: 3vh 2vw; text-align: center;
  box-shadow: 0 24px 60px rgba(29,27,25,.25); }
.pin-card .step { font-size: clamp(1.2em, 2.2vw, 2.2em); font-weight: 700; margin: .3em 0; }
.pin-card .step b { color: var(--paper); text-decoration: underline 5px var(--accent); text-underline-offset: 8px; } /* stays readable with dark brand colors */
.pin-card .bigcode { font-size: clamp(3.5em, 10vw, 10em); margin: .1em 0; }
.pin-card .bigcode span { display: inline-block; animation: hop 2.4s ease-in-out infinite; }
@keyframes hop { 0%, 70%, 100% { transform: none; } 80% { transform: translateY(-.12em); color: var(--accent); } }
.pin-card button { color: var(--paper); border-color: rgba(245,241,234,.4); }
.qr-card { position: relative; justify-self: center; background: #fff; border-radius: 28px; padding: 18px;
  transform: rotate(2deg); box-shadow: 0 24px 60px rgba(29,27,25,.18); }
.qr-card .qr { width: min(34vw, 46vh, 420px); border: 0; border-radius: 12px; }
.sticker { position: absolute; top: -22px; right: -18px; background: var(--c); color: var(--ink); font-weight: 700;
  font-size: clamp(1em, 1.6vw, 1.6em); padding: 10px 18px; border-radius: 999px; transform: rotate(8deg);
  box-shadow: 0 8px 20px rgba(0,0,0,.15); animation: wiggle 1.8s ease-in-out infinite; }
@keyframes wiggle { 50% { transform: rotate(-4deg) scale(1.06); } }
.lobby-bottom { margin-top: 1vh; }
.count-row { display: flex; align-items: center; justify-content: center; gap: 18px; flex-wrap: wrap;
  font-size: clamp(1.4em, 2.6vw, 2.6em); font-weight: 700; }
.count { font-size: 2em; line-height: 1; color: var(--accent); min-width: 1.2em; display: inline-block; }
.count.bump { animation: bump .5s cubic-bezier(.3,1.8,.5,1); }
@keyframes bump { 40% { transform: scale(1.35); } }
.count-row .big { font-size: .7em; margin-left: 12px; }
.glow { animation: glow 2s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 12px rgba(255,90,60,.18), 0 0 40px rgba(255,90,60,.35); } }
.quip { font-size: clamp(1.1em, 1.8vw, 1.8em); font-weight: 600; color: var(--muted); margin: .6em 0; }
.quip.swap { animation: pop .4s ease-out; }
.names.colorful .pill { color: #fff; border: 0; font-size: clamp(1em, 1.5vw, 1.5em); padding: 10px 20px;
  animation: bounce-in .6s cubic-bezier(.3,1.7,.5,1) both; box-shadow: 0 6px 14px rgba(0,0,0,.12); }
.names.colorful .pill:nth-child(5n+1) { background: var(--a); transform: rotate(-3deg); }
.names.colorful .pill:nth-child(5n+2) { background: var(--b); transform: rotate(2deg); }
.names.colorful .pill:nth-child(5n+3) { background: var(--c); color: var(--ink); transform: rotate(-1deg); }
.names.colorful .pill:nth-child(5n+4) { background: var(--d); transform: rotate(3deg); }
.names.colorful .pill:nth-child(5n+5) { background: var(--accent); transform: rotate(-2deg); }
@keyframes bounce-in { from { opacity: 0; transform: scale(.2) translateY(30px); } }
@media (prefers-reduced-motion: reduce) { .pin-card .bigcode span, .sticker, .glow, .names.colorful .pill { animation: none; } }

/* ---------- Host final standings, built for a projector ---------- */
/* Sizes follow the screen height (vh) so the whole top 10 fits on any projector without overlap. */
.final-title { text-align: center; font-size: clamp(1.6em, 6vh, 4.5em); margin: 0 0 1vh; animation: pop .6s ease-out; }
.podium2 { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 1.5vw; max-width: 1100px; margin: 0 auto; }
.ps { display: flex; flex-direction: column; align-items: center; text-align: center; min-width: 0; }
.ps > * { flex-shrink: 0; } /* never squeeze (and clip) the name or score */
.ps .medal { font-size: clamp(1.4em, 5vh, 4em); line-height: 1.1; }
.ps .pname { font-weight: 700; font-size: clamp(1.1em, 4.2vh, 3em); line-height: 1.3; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps .pscore { font-weight: 700; font-size: clamp(1em, 3.2vh, 2.2em); line-height: 1.2; color: var(--muted); margin-bottom: .3em; font-variant-numeric: tabular-nums; }
.ps .block { width: 100%; border-radius: 20px 20px 0 0; display: grid; place-items: start center; padding-top: .15em; color: #fff;
  font-weight: 700; font-size: clamp(2em, 8vh, 7em); line-height: 1; transform-origin: bottom; animation: rise-up .9s cubic-bezier(.2,.9,.3,1.2) both; }
.ps .medal, .ps .pname, .ps .pscore { animation: pop .5s ease-out both; }
.p1 .block { height: 22vh; background: linear-gradient(180deg, rgba(255,255,255,.3), rgba(255,255,255,0)) var(--accent); animation-delay: 1.8s; }
.p2 .block { height: 15vh; background: linear-gradient(180deg, #7c93f0, var(--a)); animation-delay: .9s; }
.p3 .block { height: 10vh; background: linear-gradient(180deg, #e46fb0, var(--d)); animation-delay: 0s; }
.p1 > :not(.block):not(.crown) { animation-delay: 2.4s; } .p2 > :not(.block) { animation-delay: 1.5s; } .p3 > :not(.block) { animation-delay: .6s; }
.p1 .pname { font-size: clamp(1.3em, 5.2vh, 3.6em); color: var(--ink); }
.p1 .pscore { color: var(--accent); }
.crown { font-size: clamp(1.6em, 5.5vh, 5em); line-height: 1; animation: crown-drop .8s cubic-bezier(.3,1.6,.5,1) 2.9s both, sway 2.4s ease-in-out 3.7s infinite; }
@keyframes rise-up { from { transform: scaleY(0); } }
@keyframes crown-drop { from { opacity: 0; transform: translateY(-120px) rotate(-30deg); } }
@keyframes sway { 50% { transform: rotate(-8deg); } }
.runners { display: grid; grid-template-columns: 1fr 1fr; gap: 1vh 2vw; max-width: 1100px; margin: 2vh auto 0; }
.runner { display: flex; align-items: center; gap: 14px; background: var(--card); border-radius: 14px; padding: .9vh 20px;
  font-size: clamp(1em, 2.6vh, 1.8em); font-weight: 700; box-shadow: 0 8px 20px rgba(29,27,25,.08); animation: slide-in .5s ease-out both; }
.runner:nth-child(4n+1) { border-left: 8px solid var(--a); } .runner:nth-child(4n+2) { border-left: 8px solid var(--b); }
.runner:nth-child(4n+3) { border-left: 8px solid var(--c); } .runner:nth-child(4n+4) { border-left: 8px solid var(--d); }
.runner .rk { color: var(--muted); width: 2.4em; } .runner .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes slide-in { from { opacity: 0; transform: translateY(20px); } }
@media (max-width: 700px) { .runners { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { .ps *, .crown, .runner, .final-title { animation: none !important; } }

/* Client branding */
.client-logo { max-height: 56px; max-width: 200px; object-fit: contain; background: #fff; padding: 6px 12px; border-radius: 12px; }
.client-logo.big { display: block; margin: 0 auto 12px; max-height: 110px; max-width: 320px; padding: 10px 16px; }
.brand-edit { border: 2px dashed var(--line); border-radius: 12px; padding: 14px; margin: 10px 0; display: grid; gap: 10px; }
.brand-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand-row input[type=color] { width: 64px; height: 44px; padding: 2px; margin: 0; }
.check { display: flex; align-items: center; gap: 8px; } .check input { width: 22px; height: 22px; margin: 0; }
