/* ────────────────────────────── tokens ────────────────────────────── */
:root {
  --bg:        #160c2e;
  --bg-2:      #1e1140;
  --surface:   rgba(255,255,255,.07);
  --surface-2: rgba(255,255,255,.12);
  --line:      rgba(255,255,255,.14);
  --text:      #f4f0ff;
  --muted:     #a99fc8;
  --accent:    #ffc93c;
  --accent-2:  #ff8a3d;
  --truth:     #2ee6a8;
  --wrong:     #ff5d73;
  --radius:    20px;
  --shadow:    0 14px 40px rgba(0,0,0,.38);
  --pad:       clamp(14px, 4vw, 22px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ───────────────────────── animated backdrop ──────────────────────── */
.blobs { position: fixed; inset: 0; z-index: -2; overflow: hidden;
         background: radial-gradient(120% 90% at 50% 0%, var(--bg-2), var(--bg) 70%); }
.blob { position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%;
        filter: blur(70px); opacity: .32; }
.b1 { background: #7c3aed; top: -22vmax; left: -18vmax; animation: drift 26s ease-in-out infinite; }
.b2 { background: #ff8a3d; bottom: -26vmax; right: -20vmax; animation: drift 32s ease-in-out infinite reverse; }
.b3 { background: #2ee6a8; top: 35%; left: 45%; opacity: .16; animation: drift 40s ease-in-out infinite; }
@keyframes drift {
  0%,100% { transform: translate(0,0) scale(1); }
  33%     { transform: translate(8vmax,-6vmax) scale(1.12); }
  66%     { transform: translate(-7vmax,7vmax) scale(.92); }
}
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 40; pointer-events: none; }

/* ───────────────────────────── layout ────────────────────────────── */
#app { min-height: 100dvh; }

.screen { display: none; }
.screen.active { display: block; animation: screen-in .32s cubic-bezier(.2,.8,.3,1); }
@keyframes screen-in { from { opacity: 0; transform: translateY(14px); } }

.stack {
  width: min(560px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) var(--pad)
           calc(28px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}
.stack.center { align-items: center; text-align: center; justify-content: center;
                min-height: 100dvh; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.center { text-align: center; }

/* ───────────────────────────── type ─────────────────────────────── */
.logo {
  margin: 0; font-size: clamp(46px, 15vw, 76px); line-height: .92;
  font-weight: 900; letter-spacing: -.03em;
  filter: drop-shadow(0 6px 18px rgba(255,138,61,.28));
  animation: pop-in .6s cubic-bezier(.2,1.3,.4,1) both;
}
/* Each half carries its own clipped gradient. A transformed element must never
   sit inside a background-clip:text parent — Chrome ghosts its glyphs. */
.logo span {
  display: inline-block;
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
/* background-image, not the `background` shorthand — the shorthand would reset
   background-clip back to border-box and paint solid blocks. */
.logo .l1 { background-image: linear-gradient(100deg, var(--accent), var(--accent-2)); }
.logo .l2 {
  background-image: linear-gradient(100deg, var(--accent-2), #ff6bd6);
  animation: wobble 5s ease-in-out infinite;
}
.logo.small {
  font-size: clamp(26px, 8vw, 38px);
  background: linear-gradient(100deg, var(--accent), var(--accent-2) 55%, #ff6bd6);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
@keyframes wobble { 0%,100%{transform:rotate(-3deg)} 50%{transform:rotate(3deg)} }
@keyframes pop-in { from { opacity:0; transform: scale(.86); } }

.tagline { margin: 0; color: var(--muted); font-size: 15px; }
.big-title { margin: 0; font-size: clamp(26px, 8vw, 36px); font-weight: 850; letter-spacing: -.02em; }
.eyebrow { margin: 0 0 10px; font-size: 11.5px; font-weight: 750;
           letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.hint { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.question { margin: 0; font-size: clamp(19px, 5.4vw, 25px); font-weight: 800;
            line-height: 1.28; letter-spacing: -.01em; }
.counter { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ───────────────────────────── cards ────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.card.pad { padding: var(--pad); display: flex; flex-direction: column; gap: 12px; }
.question-card { border-color: rgba(255,201,60,.3);
                 background: linear-gradient(160deg, rgba(255,201,60,.14), var(--surface)); }

/* ───────────────────────────── inputs ───────────────────────────── */
.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 13px; color: var(--muted); font-weight: 600; }

input, textarea {
  width: 100%; padding: 15px 16px; font: inherit; color: var(--text);
  background: rgba(0,0,0,.28); border: 1.5px solid var(--line);
  border-radius: 14px; outline: none; resize: none;
  transition: border-color .18s, box-shadow .18s;
}
input::placeholder, textarea::placeholder { color: rgba(255,255,255,.28); }
input:focus, textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255,201,60,.16);
}
.code-input {
  flex: 1; text-align: center; font-size: 26px; font-weight: 850;
  letter-spacing: .34em; text-indent: .34em; text-transform: uppercase;
}

.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 750;
  min-height: 52px; padding: 0 22px; border-radius: 14px; color: #2a1600;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  transition: transform .12s, filter .18s, opacity .18s;
  box-shadow: 0 8px 22px rgba(255,138,61,.26);
}
.btn:active { transform: scale(.97); }
.btn.big { width: 100%; min-height: 58px; font-size: 17px; }
.btn.small { min-height: 42px; font-size: 14px; padding: 0 16px; }
.btn.ghost {
  background: var(--surface-2); color: var(--text);
  border: 1.5px solid var(--line); box-shadow: none;
}
.btn:disabled { opacity: .42; cursor: not-allowed; filter: grayscale(.5); }

.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px;
      text-transform: uppercase; letter-spacing: .12em; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Arrived by QR code or a shared link, so the code is already filled in:
   joining becomes the primary action and starting a new game is demoted.
   Otherwise the biggest button on screen creates a stray room by mistake. */
body.via-link #joinRow { order: 1; flex-direction: column; align-items: stretch; gap: 8px; }
body.via-link #codeLabel { text-align: center; }
body.via-link #orDivider { order: 2; }
body.via-link #createBtn { order: 3; }

/* ───────────────────────────── lobby ───────────────────────────── */
.head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.room-code {
  margin: 0; font-size: clamp(42px, 14vw, 62px); font-weight: 900;
  letter-spacing: .1em; line-height: 1;
  background: linear-gradient(100deg, #fff, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.qr { width: 104px; height: 104px; border-radius: 14px; background: #fff;
      padding: 6px; box-shadow: var(--shadow); flex: none; }

.players { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 9px; }
.players li {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 8px;
  background: var(--surface-2); border-radius: 999px; font-weight: 650; font-size: 14.5px;
  animation: pop-in .34s cubic-bezier(.2,1.4,.4,1) both;
}
.players li.offline { opacity: .4; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-size: 17px; background: rgba(0,0,0,.3); flex: none;
}
.crown { font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none; cursor: pointer; font: inherit; font-weight: 750;
  min-width: 54px; min-height: 48px; padding: 0 14px; border-radius: 13px;
  color: var(--text); background: var(--surface-2); border: 1.5px solid var(--line);
  transition: all .16s;
}
.chip[aria-pressed="true"] {
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: #2a1600; border-color: transparent; transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(255,138,61,.3);
}

/* ───────────────────────────── loading ──────────────────────────── */
.shuffle-deck { position: relative; width: 120px; height: 150px; margin-bottom: 10px; }
.shuffle-deck i {
  position: absolute; inset: 0; border-radius: 16px; border: 2px solid var(--line);
  background: linear-gradient(160deg, rgba(255,201,60,.22), var(--surface));
  animation: shuffle 1.6s cubic-bezier(.4,0,.3,1) infinite;
}
.shuffle-deck i:nth-child(2) { animation-delay: .2s; }
.shuffle-deck i:nth-child(3) { animation-delay: .4s; }
.shuffle-deck i:nth-child(4) { animation-delay: .6s; }
@keyframes shuffle {
  0%      { transform: translate(0,0) rotate(0); }
  40%     { transform: translate(46px,-18px) rotate(13deg); }
  80%,100%{ transform: translate(0,0) rotate(0); }
}

/* ───────────────────────── timers & topbar ──────────────────────── */
.topbar { display: flex; justify-content: space-between; align-items: center; }
.pill {
  padding: 7px 14px; border-radius: 999px; background: var(--surface-2);
  font-size: 13px; font-weight: 750; letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
.pill.accent { background: linear-gradient(145deg, var(--accent), var(--accent-2)); color: #2a1600; }
.pill.urgent { animation: throb .7s ease-in-out infinite;
               background: linear-gradient(145deg, #ff6b6b, var(--wrong)); color: #fff; }
@keyframes throb { 50% { transform: scale(1.11); } }

.timerbar { height: 7px; border-radius: 99px; background: rgba(0,0,0,.32); overflow: hidden; }
.timerbar i {
  display: block; height: 100%; width: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--truth), var(--accent) 60%, var(--wrong));
  transform-origin: left; transition: transform .3s linear;
}

.dots { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.dots li {
  display: flex; align-items: center; gap: 6px; padding: 5px 11px 5px 5px;
  border-radius: 999px; background: rgba(0,0,0,.24); font-size: 13px;
  border: 1.5px solid transparent; transition: all .25s;
}
.dots li .avatar { width: 24px; height: 24px; font-size: 14px; }
.dots li.ready { border-color: var(--truth); background: rgba(46,230,168,.14); }
.dots li.ready::after { content: "✓"; color: var(--truth); font-weight: 800; }
.dots li.offline { opacity: .35; }

/* ───────────────────────────── answers ──────────────────────────── */
.answers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.answers li { animation: card-in .4s cubic-bezier(.2,.9,.3,1) both; }
@keyframes card-in { from { opacity: 0; transform: translateY(16px) scale(.97); } }

.answer {
  width: 100%; text-align: left; cursor: pointer; font: inherit; font-size: 16.5px;
  font-weight: 650; line-height: 1.35; padding: 17px 18px; color: var(--text);
  background: var(--surface); border: 2px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow); position: relative;
  transition: transform .15s, border-color .2s, background .2s;
  display: flex; gap: 12px; align-items: center;
}
.answer .marker {
  width: 26px; height: 26px; flex: none; border-radius: 50%; display: grid;
  place-items: center; font-size: 13px; font-weight: 850;
  background: rgba(0,0,0,.3); color: var(--muted);
}
.answer:active { transform: scale(.985); }
.answer[aria-pressed="true"] {
  border-color: var(--accent); background: rgba(255,201,60,.15);
  transform: translateX(4px);
}
.answer[aria-pressed="true"] .marker { background: var(--accent); color: #2a1600; }
.answer:disabled { cursor: default; opacity: .55; }
.answer .own-tag {
  margin-left: auto; flex: none; font-size: 10.5px; font-weight: 800;
  letter-spacing: .1em; text-transform: uppercase; color: var(--accent);
}

/* ───────────────────────────── reveal ──────────────────────────── */
.reveal-list li { animation: flip-in .55s cubic-bezier(.2,.9,.3,1) both; }
@keyframes flip-in {
  from { opacity: 0; transform: perspective(700px) rotateX(-78deg); }
}
.reveal-card {
  padding: 15px 17px; border-radius: 16px; border: 2px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow);
}
.reveal-card.truth {
  border-color: var(--truth);
  background: linear-gradient(150deg, rgba(46,230,168,.22), var(--surface));
  animation: truth-burst .8s cubic-bezier(.2,1.2,.4,1) .1s both;
}
@keyframes truth-burst {
  0%   { box-shadow: 0 0 0 0 rgba(46,230,168,.55); }
  70%  { box-shadow: 0 0 0 20px rgba(46,230,168,0); }
  100% { box-shadow: var(--shadow); }
}
.reveal-card.mine { outline: 2px dashed rgba(255,201,60,.55); outline-offset: 3px; }
.reveal-text { font-size: 16.5px; font-weight: 700; line-height: 1.35; }
.reveal-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
               margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px 4px 4px;
  border-radius: 999px; background: rgba(0,0,0,.28); font-weight: 650; font-size: 12.5px;
  color: var(--text);
}
.tag .avatar { width: 20px; height: 20px; font-size: 12px; }
.tag.truth-tag { background: rgba(46,230,168,.2); color: var(--truth); padding: 4px 11px; }
.label { font-size: 11px; font-weight: 780; letter-spacing: .1em;
         text-transform: uppercase; color: var(--muted); margin-right: 2px; }

.deltas { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.deltas li {
  display: flex; align-items: center; gap: 9px; font-weight: 650;
  animation: slide-in .4s cubic-bezier(.2,.9,.3,1) both;
}
@keyframes slide-in { from { opacity: 0; transform: translateX(-22px); } }
.deltas .delta { margin-left: auto; font-weight: 850; font-variant-numeric: tabular-nums; }
.deltas .delta.plus { color: var(--truth); }
.deltas .delta.zero { color: var(--muted); }
.deltas .why { font-size: 12px; color: var(--muted); font-weight: 550; }

/* ─────────────────────────── scoreboard ────────────────────────── */
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.board li {
  display: flex; align-items: center; gap: 11px; padding: 13px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  position: relative; overflow: hidden; transition: transform .55s cubic-bezier(.2,.8,.3,1);
}
.board li .bar {
  position: absolute; inset: 0 auto 0 0; z-index: 0;
  background: linear-gradient(90deg, rgba(255,201,60,.24), rgba(255,138,61,.05));
  transition: width .8s cubic-bezier(.2,.8,.3,1);
}
.board li > * { position: relative; z-index: 1; }
.board li.me { border-color: var(--accent); }
.board .rank { font-size: 15px; font-weight: 850; color: var(--muted); min-width: 26px;
               font-variant-numeric: tabular-nums; }
.board .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .score { margin-left: auto; font-size: 21px; font-weight: 900;
                font-variant-numeric: tabular-nums; }
.board .gain { font-size: 13px; font-weight: 800; color: var(--truth);
               animation: float-up 1.4s ease-out both; }
@keyframes float-up { 0%{opacity:0;transform:translateY(10px)} 30%{opacity:1} 100%{opacity:.85} }
.board .avatar { width: 34px; height: 34px; font-size: 19px; }

/* ───────────────────────────── podium ──────────────────────────── */
.podium { list-style: none; margin: 8px 0 0; padding: 0;
          display: flex; align-items: flex-end; justify-content: center; gap: 10px; width: 100%; }
.podium li { flex: 1; max-width: 150px; display: flex; flex-direction: column;
             align-items: center; gap: 8px; }
.podium .plinth {
  width: 100%; border-radius: 16px 16px 0 0; display: grid; place-items: start center;
  padding-top: 10px; font-size: 30px; font-weight: 900; color: rgba(255,255,255,.4);
  background: linear-gradient(180deg, var(--surface-2), rgba(255,255,255,.03));
  border: 1px solid var(--line); border-bottom: 0;
  animation: grow .8s cubic-bezier(.2,1.1,.3,1) both;
}
.podium .medal { font-size: 26px; line-height: 1; }
@keyframes grow { from { height: 0 !important; opacity: 0; } }
.podium .p1 .plinth {
  height: 132px; color: rgba(42,22,0,.5); border-color: rgba(255,201,60,.5);
  background: linear-gradient(180deg, var(--accent), rgba(255,138,61,.25));
}
.podium .p2 .plinth { height: 96px; }
.podium .p3 .plinth { height: 72px; }
.podium .avatar { width: 52px; height: 52px; font-size: 30px; }
.podium .p1 .avatar { width: 66px; height: 66px; font-size: 38px;
                      box-shadow: 0 0 0 3px var(--accent), 0 0 34px rgba(255,201,60,.5); }
.podium .pname { font-weight: 800; font-size: 15px; }
.podium .pscore { font-size: 13px; color: var(--accent); font-weight: 800; }
.board.rest { margin-top: 8px; width: 100%; }

/* ─────────────────────────── misc / util ───────────────────────── */
.locked-panel { border-color: rgba(46,230,168,.4);
                background: linear-gradient(160deg, rgba(46,230,168,.13), var(--surface)); }
.locked-answer { margin: 0; font-size: 18px; font-weight: 750; }

.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translate(-50%, 130%); z-index: 60; max-width: min(420px, calc(100vw - 32px));
  padding: 13px 20px; border-radius: 14px; font-weight: 650; font-size: 14.5px;
  background: #2c1a4e; border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: transform .34s cubic-bezier(.2,1.2,.4,1);
}
.toast.show { transform: translate(-50%, 0); }

.sound-btn {
  position: fixed; bottom: max(12px, env(safe-area-inset-bottom)); left: 12px; z-index: 50;
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 17px; cursor: pointer;
  backdrop-filter: blur(8px);
}
.sound-btn.muted { opacity: .45; }

/* ── in-game chrome: leave / end game ── */
.chrome-actions {
  position: fixed; z-index: 50; display: flex; flex-direction: column; gap: 7px;
  right: 12px; bottom: max(12px, env(safe-area-inset-bottom));
}
/* Keep scrollable content clear of the fixed chrome, so the phase button at the
   bottom of a long screen is never sitting underneath Leave / End game. */
body.has-chrome .stack { padding-bottom: calc(136px + env(safe-area-inset-bottom)); }
.chrome-btn {
  appearance: none; cursor: pointer; font: inherit; font-size: 13px; font-weight: 700;
  min-height: 40px; padding: 0 15px; border-radius: 999px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line);
  backdrop-filter: blur(8px); transition: color .18s, border-color .18s;
}
.chrome-btn:active { transform: scale(.96); }
#endGameBtn { color: var(--accent); border-color: rgba(255,201,60,.35); }

/* ── confirmation dialog ── */
.modal {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center;
  padding: 20px; background: rgba(8,4,20,.66); backdrop-filter: blur(6px);
  animation: fade-in .18s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }
.modal-sheet {
  width: min(390px, 100%); padding: 24px; border-radius: var(--radius);
  background: #2a1a4c; border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
  animation: sheet-in .3s cubic-bezier(.2,1.15,.4,1) both;
}
@keyframes sheet-in { from { opacity: 0; transform: translateY(22px) scale(.96); } }
.modal-title { margin: 0; font-size: 21px; font-weight: 850; letter-spacing: -.01em; }
.modal-text { margin: 0; color: var(--muted); font-size: 14.5px; line-height: 1.45; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; padding: 0 12px; }
.btn.danger {
  background: linear-gradient(145deg, #ff7a85, var(--wrong)); color: #fff;
  box-shadow: 0 8px 22px rgba(255,93,115,.28);
}

[hidden] { display: none !important; }
.waiting-note { animation: pulse-soft 2.2s ease-in-out infinite; }
@keyframes pulse-soft { 50% { opacity: .45; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important;
                            transition-duration: .01ms !important; }
}
