:root {
  --bg1: #1a1150;
  --bg2: #3b1fa3;
  --ink: #1f1640;
  --muted: #6d6694;
  --line: #e7e2ff;
  --violet: #6c4dff;
  --violet2: #9d6bff;
  --t0a: #ff8a3d;
  --t0b: #ff4d6d;
  --t1a: #1fc8e3;
  --t1b: #3a6dff;
  --ok: #18c27a;
  --bad: #ff4d6d;
  --gold: #ffc23d;
  --display: "Fredoka", "Nunito", system-ui, sans-serif;
  --text: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--text);
  color: var(--ink);
  background: radial-gradient(1200px 700px at 15% 10%, #4a2bd0 0%, transparent 60%),
              radial-gradient(900px 600px at 90% 90%, #b2399e 0%, transparent 55%),
              linear-gradient(160deg, var(--bg1), var(--bg2));
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }

/* ---------- Background ---------- */
.bg { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.bg::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255,255,255,.09) 1.5px, transparent 1.5px);
  background-size: 28px 28px;
}
.blob { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .45; animation: drift 18s ease-in-out infinite alternate; }
.b1 { width: 380px; height: 380px; background: #ff7ab6; top: -80px; right: 10%; }
.b2 { width: 320px; height: 320px; background: #31d6ff; bottom: -60px; left: 5%; animation-delay: -6s; }
.b3 { width: 260px; height: 260px; background: #ffc23d; top: 40%; left: 45%; opacity: .25; animation-delay: -12s; }
@keyframes drift { to { transform: translate(40px, -30px) scale(1.12); } }

/* ---------- Screens ---------- */
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: flex; }

/* ---------- Setup ---------- */
#setup { align-items: center; justify-content: center; overflow-y: auto; padding: 24px 16px; }
.setup-card {
  width: min(880px, 100%); margin: auto;
  background: #fff; border-radius: 32px; padding: 32px 36px 28px;
  box-shadow: 0 30px 80px rgba(10, 0, 60, .45), inset 0 -6px 0 #eee9ff;
  animation: pop .5s cubic-bezier(.2, 1.4, .4, 1);
}
.logo {
  font-family: var(--display); font-weight: 700; font-size: clamp(44px, 7vw, 68px);
  text-align: center; line-height: 1; letter-spacing: -1px; color: var(--violet);
}
.logo span {
  background: linear-gradient(90deg, #ff4d8d, #ff8a3d, #ffc23d);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.subtitle { text-align: center; color: var(--muted); font-weight: 800; margin: 8px 0 22px; font-size: 18px; }

.teams-setup { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center; margin-bottom: 18px; }
.vs { font-family: var(--display); font-weight: 700; font-size: 26px; color: #c5bcff; }
.team-setup { border-radius: 22px; padding: 14px 16px; border: 3px solid; }
.team-setup.t0 { border-color: #ffd2c2; background: #fff6f2; }
.team-setup.t1 { border-color: #c4ddff; background: #f2f8ff; }
.team-setup label { display: block; font-family: var(--display); font-weight: 600; font-size: 15px; color: var(--muted); margin-bottom: 6px; }
.team-setup input {
  width: 100%; font-family: var(--display); font-weight: 600; font-size: 24px; color: var(--ink);
  border: 2px solid var(--line); border-radius: 14px; padding: 8px 12px; outline: none; background: #fff;
}
.team-setup input:focus { border-color: var(--violet); }
.avatars { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.avatars button {
  width: 42px; height: 42px; border-radius: 50%; font-size: 24px; background: #fff;
  border: 2px solid var(--line); transition: transform .15s;
}
.avatars button:hover { transform: scale(1.12); }
.t0 .avatars button.sel { border-color: var(--t0b); background: #ffe3dc; transform: scale(1.12); }
.t1 .avatars button.sel { border-color: var(--t1b); background: #dceaff; transform: scale(1.12); }

.opt-row { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-top: 2px dashed var(--line); flex-wrap: wrap; }
.opt-row h3 { margin: 0; width: 150px; font-family: var(--display); font-weight: 600; font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.chip {
  font-family: var(--display); font-weight: 600; font-size: 18px; padding: 8px 16px; min-width: 52px;
  border-radius: 999px; border: 2px solid var(--line); background: #faf9ff; color: var(--ink);
  transition: transform .12s, background .12s;
}
.chip:hover { transform: translateY(-2px); }
.chip.sel { background: linear-gradient(135deg, var(--violet), var(--violet2)); color: #fff; border-color: transparent; box-shadow: 0 6px 16px rgba(108, 77, 255, .35); }
.summary { text-align: center; font-weight: 800; color: var(--muted); margin: 14px 0 4px; min-height: 1.4em; }
.setup-actions { display: flex; justify-content: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--display); font-weight: 600; font-size: 20px; padding: 12px 24px; border-radius: 999px;
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn.big { font-size: 26px; padding: 16px 40px; }
.btn.primary { color: #fff; background: linear-gradient(135deg, #ff4d8d, #ff8a3d); box-shadow: 0 8px 0 #c7336a, 0 14px 30px rgba(255, 77, 141, .35); }
.btn.primary:active { box-shadow: 0 3px 0 #c7336a; }
.btn.ghost { background: #f1eeff; color: var(--violet); }

/* ---------- Game layout ---------- */
#game { flex-direction: column; }
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: center;
  padding: 16px 22px 6px;
}
.team-panel {
  position: relative; display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; border-radius: 24px; color: #fff; cursor: pointer;
  background: rgba(255, 255, 255, .1); border: 2px solid rgba(255, 255, 255, .14);
  opacity: .62; transition: all .3s;
}
.team-panel.t1 { flex-direction: row-reverse; text-align: right; }
.team-panel.active { opacity: 1; transform: scale(1.03); border-color: transparent; }
.team-panel.t0.active { background: linear-gradient(135deg, var(--t0a), var(--t0b)); box-shadow: 0 10px 30px rgba(255, 77, 109, .45); }
.team-panel.t1.active { background: linear-gradient(135deg, var(--t1a), var(--t1b)); box-shadow: 0 10px 30px rgba(58, 109, 255, .45); }
.avatar {
  width: 64px; height: 64px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-size: 38px; background: rgba(255, 255, 255, .92); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .08);
}
.team-panel.active .avatar { animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px) rotate(-6deg); } }
.tinfo { min-width: 0; }
.tname { font-family: var(--display); font-weight: 600; font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tscore { font-family: var(--display); font-weight: 700; font-size: 46px; line-height: 1; }
.adj { display: flex; flex-direction: column; gap: 4px; margin-left: auto; opacity: 0; transition: opacity .2s; }
.team-panel.t1 .adj { margin-left: 0; margin-right: auto; }
.team-panel:hover .adj { opacity: 1; }
.adj button { background: rgba(255, 255, 255, .25); border-radius: 10px; padding: 2px 10px; font-weight: 800; font-size: 14px; color: #fff; }
.adj button:hover { background: rgba(255, 255, 255, .4); }
.rocket {
  position: absolute; top: -10px; padding: 2px 10px; border-radius: 999px; font-family: var(--display); font-weight: 700;
  font-size: 15px; background: var(--gold); color: #5a3a00; box-shadow: 0 4px 10px rgba(0, 0, 0, .2);
}
.t0 .rocket { right: 14px; }
.t1 .rocket { left: 14px; }
.float {
  position: absolute; top: 4px; font-family: var(--display); font-weight: 700; font-size: 40px; pointer-events: none;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .2); animation: floatUp 1.4s ease-out forwards; z-index: 5;
}
.t0 .float { right: 30%; }
.t1 .float { left: 30%; }
.float.plus { color: #b6ffd9; }
.float.minus { color: #ffd0d8; }
@keyframes floatUp { 0% { transform: translateY(10px) scale(.6); opacity: 0; } 20% { opacity: 1; transform: translateY(0) scale(1.15); } 100% { transform: translateY(-50px) scale(1); opacity: 0; } }

.center { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.turn {
  font-family: var(--display); font-weight: 600; font-size: 20px; color: #fff; white-space: nowrap;
  padding: 6px 18px; border-radius: 999px; background: rgba(255, 255, 255, .14);
}
.tools { display: flex; gap: 6px; }
.tools button {
  width: 42px; height: 42px; border-radius: 14px; font-size: 19px; color: #fff;
  background: rgba(255, 255, 255, .12); transition: background .15s, transform .15s;
}
.tools button:hover { background: rgba(255, 255, 255, .25); transform: translateY(-2px); }

/* ---------- Board ---------- */
.board {
  flex: 1; min-height: 0; display: grid; justify-content: center; align-content: center;
  padding: 14px 22px 22px;
}
.card {
  position: relative; perspective: 1000px; padding: 0;
  animation: cardIn .5s cubic-bezier(.2, 1.4, .4, 1) backwards; animation-delay: calc(var(--i) * 25ms);
  transition: transform .18s;
}
.card:not(.opened):hover { transform: translateY(-5px) rotate(-1.2deg); }
.card:not(.opened):active { transform: translateY(1px) scale(.98); }
.card.opened { cursor: default; }
@keyframes cardIn { from { opacity: 0; transform: translateY(20px) scale(.8); } }
.inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .7s cubic-bezier(.3, 1.3, .5, 1); }
.card.opened .inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; border-radius: clamp(14px, calc(var(--tile-h) * .16), 26px);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: grid; place-items: center; overflow: hidden;
}
.front {
  background: linear-gradient(145deg, var(--c1), var(--c2));
  box-shadow: inset 0 -7px 0 rgba(0, 0, 0, .14), inset 0 3px 0 rgba(255, 255, 255, .35), 0 10px 22px rgba(10, 0, 50, .35);
}
.front::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(115deg, rgba(255, 255, 255, .28) 0 22%, transparent 22% 60%, rgba(255, 255, 255, .1) 60% 70%, transparent 70%);
}
.front::after {
  content: "✦"; position: absolute; top: 8%; right: 9%; color: rgba(255, 255, 255, .55);
  font-size: calc(var(--tile-h) * .16);
}
.num {
  position: relative; font-family: var(--display); font-weight: 700; color: #fff;
  font-size: calc(var(--tile-h) * .5); text-shadow: 0 4px 0 rgba(0, 0, 0, .16);
}
.back {
  transform: rotateY(180deg); background: rgba(255, 255, 255, .1); border: 2px dashed rgba(255, 255, 255, .25);
  color: #fff; gap: 2px; align-content: center;
}
.back.t0 { background: linear-gradient(145deg, rgba(255, 138, 61, .35), rgba(255, 77, 109, .35)); }
.back.t1 { background: linear-gradient(145deg, rgba(31, 200, 227, .35), rgba(58, 109, 255, .35)); }
.back .big { font-size: calc(var(--tile-h) * .34); line-height: 1; }
.back .small { font-family: var(--display); font-weight: 700; font-size: calc(var(--tile-h) * .17); opacity: .95; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 18px;
  background: rgba(16, 6, 50, .62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.modal-card {
  position: relative; width: min(1120px, 100%); max-height: calc(100dvh - 36px); overflow-y: auto;
  background: #fff; border-radius: 30px; padding: 22px 28px 24px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .45);
  animation: pop .45s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: scale(.7) rotate(-2deg); opacity: 0; } }
.m-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pill { font-family: var(--display); font-weight: 600; font-size: 18px; padding: 5px 14px; border-radius: 999px; }
.m-num { background: var(--ink); color: #fff; }
.m-topic { background: #efeaff; color: var(--violet); }
.m-pts { background: #fff3d1; color: #8a5a00; }
.m-pts b { color: #e0521b; }
.m-close {
  margin-left: auto; width: 42px; height: 42px; border-radius: 50%; background: #f2f0fa; font-size: 20px; color: var(--muted);
}
.m-close:hover { background: #e7e3f7; }
.m-turn { margin: 12px 0 0; font-weight: 800; font-size: 18px; color: var(--muted); }
.m-turn b { font-family: var(--display); font-weight: 600; }
.modal-card.t0 .m-turn b { color: var(--t0b); }
.modal-card.t1 .m-turn b { color: var(--t1b); }
.modal-card.t0 { border-top: 10px solid var(--t0a); }
.modal-card.t1 { border-top: 10px solid var(--t1a); }

.timer { position: relative; height: 14px; border-radius: 999px; background: #efedf7; margin-top: 12px; overflow: hidden; }
.timer-fill { position: absolute; inset: 0; transform-origin: left; background: linear-gradient(90deg, var(--ok), var(--gold)); transition: transform 1s linear; }
.timer.low .timer-fill { background: linear-gradient(90deg, var(--bad), #ff8a3d); }
.timer-text { font-family: var(--display); font-weight: 700; font-size: 18px; color: var(--muted); margin-top: 4px; text-align: right; }
.timer-text.up { color: var(--bad); }

.m-body { display: grid; gap: 26px; margin-top: 16px; align-items: center; }
.m-body.has-img { grid-template-columns: minmax(0, 42%) 1fr; }
.m-img { border-radius: 24px; background: #f7f5ff; padding: 10px; display: grid; place-items: center; }
.m-img img { display: block; max-width: 100%; max-height: 46vh; object-fit: contain; border-radius: 16px; }
.m-q { font-family: var(--display); font-weight: 600; font-size: clamp(26px, 3.4vw, 46px); line-height: 1.15; }
.m-cue {
  display: inline-block; margin-top: 12px; font-family: var(--display); font-weight: 600; font-size: clamp(20px, 2.2vw, 28px);
  background: #fff3d1; color: #8a5a00; padding: 4px 18px; border-radius: 999px;
}

.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 20px; }
.opt {
  position: relative; display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 16px 18px; border-radius: 20px; color: #fff; min-height: 76px;
  font-family: var(--display); font-weight: 600; font-size: clamp(20px, 2.3vw, 32px);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .15); transition: transform .15s, opacity .3s, filter .3s, box-shadow .2s;
}
.opt:hover { transform: translateY(-2px); }
.opt .letter {
  flex: none; width: 1.6em; height: 1.6em; border-radius: 12px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .28); font-size: .8em;
}
.opt.o0 { background: linear-gradient(135deg, #ff6a88, #ff4d6d); }
.opt.o1 { background: linear-gradient(135deg, #4f9bff, #3a6dff); }
.opt.o2 { background: linear-gradient(135deg, #ffc23d, #ff9f1c); }
.opt.o3 { background: linear-gradient(135deg, #2fd598, #12b07a); }
.opt.picked { box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .15), 0 0 0 5px #fff, 0 0 0 9px var(--ink); transform: scale(1.03); }
.revealed .opt:not(.correct) { opacity: .3; filter: grayscale(.6); }
.revealed .opt.correct { box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .15), 0 0 0 5px #fff, 0 0 0 10px var(--ok); animation: glow 1s ease-in-out infinite alternate; }
.opt.correct::after { content: "✓"; margin-left: auto; font-size: 1.1em; display: none; }
.revealed .opt.correct::after { display: block; }
.revealed .opt.picked:not(.correct)::after { content: "✗"; margin-left: auto; font-size: 1.1em; }
@keyframes glow { to { transform: scale(1.04); } }

.m-write {
  margin-top: 20px; border: 3px dashed #cfc6ff; border-radius: 22px; padding: 22px; min-height: 104px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 4px;
}
.m-write .ph { font-family: var(--display); font-weight: 600; font-size: clamp(20px, 2.2vw, 28px); color: #a49bd1; }
.m-write .ans { display: none; font-family: var(--display); font-weight: 700; font-size: clamp(28px, 3.4vw, 46px); color: #0f8f57; }
.m-write small { display: none; font-weight: 800; font-size: 18px; color: var(--muted); }
.revealed .m-write { border-style: solid; border-color: var(--ok); background: #eafbf3; animation: pop .4s; }
.revealed .m-write .ph { display: none; }
.revealed .m-write .ans, .revealed .m-write small { display: block; }

.m-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 24px; }
.btn.reveal { background: linear-gradient(135deg, var(--violet), var(--violet2)); color: #fff; box-shadow: 0 6px 0 #4b30c9; }
.btn.wrong { background: #ffe5ea; color: #d6304f; box-shadow: 0 6px 0 #f5bcc7; }
.btn.right { background: linear-gradient(135deg, #2fd598, #12b07a); color: #fff; box-shadow: 0 6px 0 #0b8a5e; }
.m-actions.post { display: none; align-items: center; }
.revealed .m-actions.pre { display: none; }
.revealed .m-actions.post { display: flex; animation: pop .4s cubic-bezier(.2, 1.4, .4, 1); }
.result {
  font-family: var(--display); font-weight: 600; font-size: clamp(20px, 2.2vw, 28px);
  padding: 10px 22px; border-radius: 999px; background: #f2f0fa; color: var(--violet);
}
.result.ok { background: #eafbf3; color: #0f8f57; }
.result.no { background: #ffe5ea; color: #d6304f; }
.btn.next { background: linear-gradient(135deg, var(--violet), var(--violet2)); color: #fff; box-shadow: 0 6px 0 #4b30c9; }
.sound-link { display: block; width: max-content; margin: 14px auto 0; font-weight: 800; color: var(--muted); text-decoration: none; }
.sound-link:hover { color: var(--violet); }
.keys { text-align: center; margin-top: 12px; font-size: 13px; font-weight: 700; color: #b0aacb; }
.keys kbd { font-family: inherit; background: #f2f0fa; border-radius: 6px; padding: 1px 6px; }

/* ---------- Surprise card ---------- */
.modal-card.special {
  width: min(680px, 100%); text-align: center; color: #fff; padding: 36px 30px 32px;
  background: linear-gradient(150deg, var(--s1), var(--s2)); border-top: 0;
}
.sp-label { font-family: var(--display); font-weight: 600; letter-spacing: 2px; text-transform: uppercase; opacity: .85; }
.sp-emoji { font-size: clamp(110px, 18vw, 170px); line-height: 1.1; margin: 10px 0; animation: spin-in .9s cubic-bezier(.2, 1.5, .4, 1); filter: drop-shadow(0 12px 18px rgba(0, 0, 0, .25)); }
@keyframes spin-in { from { transform: scale(0) rotate(-200deg); } }
.special.shake .sp-emoji { animation: spin-in .9s cubic-bezier(.2, 1.5, .4, 1), shake .5s .9s 2; }
@keyframes shake { 25% { transform: translateX(-12px) rotate(-8deg); } 75% { transform: translateX(12px) rotate(8deg); } }
.sp-title { font-family: var(--display); font-weight: 700; font-size: clamp(38px, 6vw, 60px); line-height: 1; text-shadow: 0 4px 0 rgba(0, 0, 0, .15); }
.sp-text { font-size: clamp(22px, 2.8vw, 30px); font-weight: 800; margin: 14px 0 26px; }
.sp-text b { font-family: var(--display); font-weight: 700; }
.btn.light { background: #fff; color: var(--ink); box-shadow: 0 6px 0 rgba(0, 0, 0, .18); }

/* ---------- Winner ---------- */
.modal-card.winner { width: min(760px, 100%); text-align: center; padding: 36px 30px 30px; border-top: 0; }
.trophy { font-size: 120px; line-height: 1; animation: spin-in 1s cubic-bezier(.2, 1.5, .4, 1); }
.win-title { font-family: var(--display); font-weight: 700; font-size: clamp(36px, 6vw, 58px); margin: 8px 0 20px; line-height: 1.05; }
.win-title small { display: block; font-size: 22px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.win-title.t0 { color: var(--t0b); }
.win-title.t1 { color: var(--t1b); }
.final { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; margin-bottom: 26px; }
.final div { min-width: 200px; border-radius: 24px; padding: 14px 20px; color: #fff; font-family: var(--display); font-weight: 600; font-size: 22px; }
.final .t0 { background: linear-gradient(135deg, var(--t0a), var(--t0b)); }
.final .t1 { background: linear-gradient(135deg, var(--t1a), var(--t1b)); }
.final b { display: block; font-size: 56px; line-height: 1.1; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  body { overflow: auto; }
  .setup-card { padding: 24px 18px; }
  .teams-setup { grid-template-columns: 1fr; }
  .vs { text-align: center; }
  .opt-row h3 { width: 100%; }
  .topbar { grid-template-columns: 1fr 1fr; padding: 10px 12px 4px; gap: 8px; }
  .center { grid-column: 1 / -1; grid-row: 2; flex-direction: row; justify-content: space-between; }
  .team-panel { padding: 8px 10px; gap: 8px; }
  .avatar { width: 44px; height: 44px; font-size: 26px; }
  .tname { font-size: 16px; }
  .tscore { font-size: 30px; }
  .board { padding: 10px 12px 14px; }
  .modal-card { padding: 18px 16px 20px; }
  .m-body.has-img { grid-template-columns: 1fr; }
  .opts { grid-template-columns: 1fr; }
  .adj, .keys { display: none; }
}
