:root {
  --purple: #46178f;
  --purple-dark: #25076b;
  --purple-mid: #381272;
  --red: #e21b3c;
  --red-d: #c01733;
  --blue: #1368ce;
  --blue-d: #0f5bb5;
  --yellow: #d89e00;
  --yellow-d: #c08d00;
  --green: #26890c;
  --green-d: #1f730a;
  --ok: #66bf39;
  --bad: #f35;
  --ink: #333;
  --white: #fff;
  --shadow: 0 4px 0 rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Montserrat', system-ui, sans-serif;
  background: var(--purple);
  color: var(--white);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
button { font: inherit; cursor: pointer; border: 0; }
input { font: inherit; }

/* ---------- background shapes ---------- */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.bg i { position: absolute; display: block; background: rgba(0, 0, 0, .1); }
.bg .s1 { width: 70vmin; height: 70vmin; border-radius: 50%; left: -20vmin; bottom: -24vmin; animation: drift 22s ease-in-out infinite; }
.bg .s2 { width: 60vmin; height: 60vmin; right: -14vmin; top: -18vmin; transform: rotate(45deg); animation: spin 40s linear infinite; }
.bg .s3 { width: 14vmin; height: 14vmin; border-radius: 50%; right: 14vw; bottom: 12vh; background: rgba(255, 255, 255, .05); animation: drift 14s ease-in-out infinite reverse; }
.bg .s4 { width: 0; height: 0; background: none; border-left: 9vmin solid transparent; border-right: 9vmin solid transparent; border-bottom: 15vmin solid rgba(255, 255, 255, .05); left: 12vw; top: 14vh; animation: spin 30s linear infinite reverse; }
@keyframes spin { to { transform: rotate(405deg); } }
@keyframes drift { 50% { transform: translate(4vmin, -5vmin) scale(1.06); } }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0; visibility: hidden; transform: scale(.97);
  transition: opacity .35s ease, transform .35s ease, visibility 0s .35s;
}
.screen.on { opacity: 1; visibility: visible; transform: none; transition: opacity .35s ease, transform .35s ease; }

.logo {
  font-weight: 900; font-size: clamp(56px, 13vw, 96px); letter-spacing: -2px; line-height: 1;
  margin-bottom: 28px; display: flex; text-shadow: 0 4px 0 rgba(0, 0, 0, .18);
}
.logo span { display: inline-block; animation: bob 3.2s ease-in-out infinite; }
.logo span:nth-child(1) { transform: rotate(-6deg); animation-delay: 0s; }
.logo span:nth-child(2) { transform: rotate(4deg); animation-delay: .1s; }
.logo span:nth-child(3) { transform: rotate(-3deg); animation-delay: .2s; }
.logo span:nth-child(4) { transform: rotate(5deg); animation-delay: .3s; }
.logo span:nth-child(5) { transform: rotate(-4deg); animation-delay: .4s; }
.logo span:nth-child(6) { transform: rotate(3deg); animation-delay: .5s; }
.logo span:nth-child(7) { transform: rotate(8deg); animation-delay: .6s; }
@keyframes bob { 50% { translate: 0 -6px; } }

.card {
  width: min(320px, 100%);
  background: var(--white); border-radius: 6px; padding: 16px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .25);
  display: flex; flex-direction: column; gap: 10px;
}
.card.shake { animation: shake .45s; }
@keyframes shake { 20%, 60% { transform: translateX(-9px); } 40%, 80% { transform: translateX(9px); } }
.field {
  height: 48px; width: 100%; text-align: center; font-weight: 700; font-size: 16px;
  border: 2px solid #ccc; border-radius: 4px; color: var(--ink); outline: none;
  transition: border-color .15s;
}
.field:focus { border-color: #333; }
.field::placeholder { color: #a8a8a8; }
.btn-enter {
  height: 48px; width: 100%; border-radius: 4px; background: var(--ink); color: var(--white);
  font-weight: 800; font-size: 16px; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .35);
  transition: background .15s, transform .08s;
}
.btn-enter:hover { background: #222; }
.btn-enter:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .35); }
.btn-enter[disabled] { opacity: .6; cursor: default; }
.err { color: var(--red); font-size: 13px; font-weight: 700; text-align: center; min-height: 0; }

.foot {
  position: fixed; bottom: 16px; left: 0; right: 0; text-align: center; z-index: 1;
  font-size: 14px; font-weight: 700; opacity: .9; padding: 0 16px;
}
.foot b { text-decoration: underline; }
.foot small { display: block; font-weight: 500; margin-top: 6px; opacity: .7; font-size: 12px; }

.mute {
  position: fixed; top: 14px; right: 14px; z-index: 5; width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0, 0, 0, .25); color: #fff; display: grid; place-items: center;
  transition: background .15s;
}
.mute:hover { background: rgba(0, 0, 0, .4); }
.mute svg { width: 22px; height: 22px; }

/* ---------- connecting / lobby ---------- */
.spinner { width: 64px; height: 64px; position: relative; margin-bottom: 26px; }
.spinner i { position: absolute; inset: 0; border-radius: 6px; background: rgba(255, 255, 255, .9); animation: morph 1.6s ease-in-out infinite; }
@keyframes morph {
  0% { border-radius: 6px; transform: rotate(0) scale(.8); background: var(--red); }
  25% { border-radius: 50%; transform: rotate(90deg) scale(1); background: var(--blue); }
  50% { border-radius: 6px; transform: rotate(225deg) scale(.7); background: var(--yellow); }
  75% { border-radius: 50%; transform: rotate(315deg) scale(1); background: var(--green); }
  100% { border-radius: 6px; transform: rotate(360deg) scale(.8); background: var(--red); }
}
.big { font-size: clamp(26px, 6vw, 40px); font-weight: 900; text-align: center; }
.sub { font-size: 18px; font-weight: 600; opacity: .85; margin-top: 10px; text-align: center; }
.nick-pill {
  margin-top: 22px; background: rgba(0, 0, 0, .25); padding: 12px 26px; border-radius: 6px;
  font-weight: 800; font-size: 24px; animation: pop .5s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes pop { from { transform: scale(.3); opacity: 0; } }

.bar-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; height: 56px; z-index: 3;
  background: var(--white); color: var(--ink);
  display: flex; align-items: center; justify-content: space-between; padding: 0 18px;
  font-weight: 800; font-size: 18px; box-shadow: 0 -2px 6px rgba(0, 0, 0, .15);
  transform: translateY(100%); transition: transform .4s ease;
}
.bar-bottom.on { transform: none; }
.bar-bottom .score { background: var(--ink); color: #fff; border-radius: 4px; padding: 4px 14px; min-width: 64px; text-align: center; }

/* ---------- get ready ---------- */
.ready-num {
  width: 140px; height: 140px; display: grid; place-items: center; font-size: 72px; font-weight: 900;
  position: relative; margin: 26px 0;
}
.ready-num::before {
  content: ''; position: absolute; inset: 0; background: var(--purple-dark); transform: rotate(45deg); border-radius: 12px;
  animation: spin-in .9s cubic-bezier(.3, 1.4, .5, 1);
}
.ready-num span { position: relative; animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes spin-in { from { transform: rotate(-180deg) scale(.2); } }
.ready-bar { width: min(420px, 80vw); height: 10px; background: rgba(0, 0, 0, .25); border-radius: 99px; overflow: hidden; }
.ready-bar i { display: block; height: 100%; width: 0; background: #fff; border-radius: 99px; }

/* ---------- question ---------- */
#question { justify-content: flex-start; padding: 0; background: #f2f2f2; color: var(--ink); }
.q-top {
  width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 12px 70px 0 16px;
  font-weight: 700; font-size: 14px; color: #555;
}
.q-top .pill { background: #fff; border-radius: 99px; padding: 6px 14px; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.q-title {
  margin: 12px 16px 0; background: #fff; border-radius: 6px; padding: 16px 24px;
  font-size: clamp(18px, 3.2vw, 32px); font-weight: 800; text-align: center; line-height: 1.25;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .12); width: calc(100% - 32px); max-width: 1100px;
  animation: drop .6s cubic-bezier(.2, 1.3, .4, 1);
}
@keyframes drop { from { transform: translateY(-40px); opacity: 0; } }
.q-mid {
  flex: 1; width: 100%; max-width: 1100px; display: grid; grid-template-columns: 110px 1fr 110px;
  align-items: center; padding: 8px 16px; min-height: 0;
}
.timer {
  width: 86px; height: 86px; border-radius: 50%; background: var(--purple); color: #fff;
  display: grid; place-items: center; font-size: 36px; font-weight: 900; position: relative;
  justify-self: start;
}
.timer svg { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); transform: rotate(-90deg); }
.timer circle { fill: none; stroke: var(--purple); stroke-width: 5; opacity: .35; stroke-linecap: round; }
.timer.urgent { animation: pulse .5s ease-in-out infinite; background: var(--red); }
.timer.urgent circle { stroke: var(--red); }
@keyframes pulse { 50% { transform: scale(1.1); } }
.answers-count { justify-self: end; text-align: center; font-weight: 800; color: #333; }
.answers-count b { display: block; font-size: 36px; }
.figure { display: grid; place-items: center; min-height: 0; min-width: 0; height: 100%; }
.figure .frame {
  background: #fff; border-radius: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, .1); position: relative;
  width: min(100%, calc(min(36vh, 320px) * 16 / 13)); aspect-ratio: 16 / 13;
}
.figure svg { position: absolute; inset: 12px; width: calc(100% - 24px); height: calc(100% - 24px); overflow: visible; }
.tri { fill: rgba(70, 23, 143, .08); stroke: var(--purple); stroke-width: 4; stroke-linejoin: round; stroke-dasharray: 900; stroke-dashoffset: 900; animation: draw 1.4s ease forwards .2s; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.arc { fill: none; stroke-width: 3.5; opacity: 0; animation: fade .4s forwards; }
.ang { font-weight: 900; font-size: 26px; opacity: 0; animation: fade .4s forwards; text-anchor: middle; dominant-baseline: middle; }
.ang.q { fill: var(--red); font-size: 34px; }
.dot { fill: var(--purple); opacity: 0; animation: fade .3s forwards; }
@keyframes fade { to { opacity: 1; } }
.qbar { width: calc(100% - 32px); max-width: 1100px; height: 8px; border-radius: 99px; background: #ddd; overflow: hidden; margin: 4px 16px 8px; }
.qbar i { display: block; height: 100%; width: 100%; background: var(--purple); transform-origin: left; }

.grid {
  width: 100%; max-width: 1100px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 0 16px 72px; height: min(34vh, 260px);
}
.ans {
  border-radius: 6px; color: #fff; display: flex; align-items: center; gap: 16px; padding: 0 22px;
  font-size: clamp(22px, 4vw, 36px); font-weight: 800; box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .2);
  transition: transform .1s, filter .15s, opacity .3s; text-align: left; position: relative;
  animation: rise .5s cubic-bezier(.2, 1.4, .4, 1) backwards;
}
.ans:nth-child(2) { animation-delay: .07s; } .ans:nth-child(3) { animation-delay: .14s; } .ans:nth-child(4) { animation-delay: .21s; }
@keyframes rise { from { transform: translateY(50px) scale(.9); opacity: 0; } }
.ans:hover { filter: brightness(1.08); }
.ans:active { transform: translateY(3px); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2); }
.ans svg { width: 40px; height: 40px; flex: none; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .2)); }
.ans .k { position: absolute; right: 14px; top: 10px; font-size: 13px; opacity: .55; font-weight: 700; }
.ans.c-red { background: var(--red); } .ans.c-blue { background: var(--blue); }
.ans.c-yellow { background: var(--yellow); } .ans.c-green { background: var(--green); }
.grid.locked .ans { pointer-events: none; }
.grid.reveal .ans:not(.right) { opacity: .25; }
.grid.reveal .ans.right::after {
  content: '✓'; position: absolute; right: 18px; top: 50%; transform: translateY(-50%);
  font-size: 40px; font-weight: 900;
}
.grid.reveal .ans.picked:not(.right)::after {
  content: '✕'; position: absolute; right: 18px; top: 50%; transform: translateY(-50%); font-size: 40px; font-weight: 900;
}

/* ---------- result ---------- */
#result { transition-duration: .25s; }
#result.good { background: var(--ok); }
#result.bad { background: var(--bad); }
.res-title { font-size: clamp(34px, 8vw, 54px); font-weight: 900; animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
.res-icon {
  width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; background: #fff;
  margin: 22px 0; animation: pop .6s cubic-bezier(.2, 1.6, .4, 1) .1s backwards;
}
.res-icon svg { width: 56px; height: 56px; }
.res-points {
  background: rgba(0, 0, 0, .28); padding: 10px 28px; border-radius: 6px; font-size: 26px; font-weight: 900;
  animation: pop .5s cubic-bezier(.2, 1.6, .4, 1) .25s backwards;
}
.res-line { margin-top: 14px; font-weight: 700; font-size: 18px; text-align: center; max-width: 520px; }
.res-line .eq { display: inline-block; margin-top: 8px; background: rgba(255, 255, 255, .2); padding: 6px 14px; border-radius: 6px; font-weight: 800; }
.res-actions { margin-top: 26px; display: flex; gap: 10px; }
.btn-white {
  background: #fff; color: var(--ink); font-weight: 800; font-size: 17px; border-radius: 4px; padding: 13px 26px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .15); transition: transform .08s;
}
.btn-white:active { transform: translateY(2px); }
.res-progress { margin-top: 30px; width: min(380px, 80vw); text-align: center; font-weight: 700; }
.res-progress .ready-bar { margin: 10px auto 0; }

#confetti { position: fixed; inset: 0; z-index: 4; pointer-events: none; }

@media (max-width: 640px) {
  .q-mid { grid-template-columns: 70px 1fr 70px; padding: 6px 10px; }
  .timer { width: 58px; height: 58px; font-size: 24px; }
  .answers-count b { font-size: 24px; }
  .answers-count { font-size: 11px; }
  .grid { gap: 6px; padding: 0 10px 66px; height: 30vh; }
  .ans { padding: 0 12px; gap: 10px; }
  .ans svg { width: 28px; height: 28px; }
  .ans .k { display: none; }
  .q-top .pill:nth-child(2) { display: none; }
  .q-title { margin: 10px 10px 0; width: calc(100% - 20px); padding: 12px; }
  .qbar { width: calc(100% - 20px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
