:root {
  --bg: #fff6ec;
  --ink: #2b2140;
  --muted: #7a6f8c;
  --card: rgba(255, 255, 255, 0.82);
  --line: rgba(43, 33, 64, 0.1);
  --primary: #ff6b4a;
  --primary-2: #ff9a3d;
  --violet: #7c5cff;
  --sky: #3fb6ff;
  --ok: #1fb57a;
  --ok-bg: #e3f8ee;
  --bad: #ef4766;
  --bad-bg: #fde6ea;
  --radius: 22px;
  --shadow: 0 1px 2px rgba(43, 33, 64, .06), 0 12px 32px -12px rgba(43, 33, 64, .22);
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Unbounded", "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Background ---------- */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.blob {
  position: absolute; border-radius: 50%; filter: blur(60px); opacity: .55;
  animation: float 18s ease-in-out infinite alternate;
}
.b1 { width: 46vmax; height: 46vmax; background: #ffc9a8; top: -16vmax; left: -12vmax; }
.b2 { width: 40vmax; height: 40vmax; background: #c9bcff; bottom: -14vmax; right: -10vmax; animation-delay: -6s; }
.b3 { width: 28vmax; height: 28vmax; background: #a8e4ff; top: 40%; left: 55%; animation-delay: -12s; opacity: .4; }
@keyframes float {
  to { transform: translate(4vmax, 3vmax) scale(1.08); }
}
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

/* ---------- Layout ---------- */
.app {
  width: 100%; max-width: 640px; margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  min-height: 100dvh; display: flex; flex-direction: column;
}
.screen { animation: enter .45s cubic-bezier(.2, .8, .2, 1) both; display: flex; flex-direction: column; flex: 1; }
@keyframes enter { from { opacity: 0; transform: translateY(14px); } }

.card {
  background: var(--card);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 56px; padding: 0 26px; border-radius: 999px;
  font-weight: 900; font-size: 1.05rem; letter-spacing: .01em;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 10px 24px -10px rgba(255, 107, 74, .8), inset 0 -3px 0 rgba(0, 0, 0, .08);
  transition: transform .15s ease, box-shadow .2s ease, opacity .2s ease, filter .2s;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(1px) scale(.985); }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; filter: grayscale(.4); }
.btn.violet { background: linear-gradient(135deg, var(--violet), #a07bff); box-shadow: 0 10px 24px -10px rgba(124, 92, 255, .8); }
.btn.ghost { background: rgba(43, 33, 64, .06); color: var(--ink); box-shadow: none; }
.btn.danger { background: var(--bad); box-shadow: 0 10px 24px -10px rgba(239, 71, 102, .7); }
.btn.block { width: 100%; }
.btn:focus-visible, .option:focus-visible, .seq-item:focus-visible, .icon-btn:focus-visible, .link-btn:focus-visible, input:focus-visible {
  outline: 3px solid rgba(124, 92, 255, .55); outline-offset: 3px;
}

.link-btn {
  background: none; border: 0; cursor: pointer; padding: 6px 8px; border-radius: 10px;
  color: var(--muted); font-weight: 700; font-size: .9rem;
}
.link-btn:hover { color: var(--ink); background: rgba(43, 33, 64, .05); }

/* ---------- Start ---------- */
.start { justify-content: center; text-align: center; gap: 22px; }
.hero-badge {
  margin: 0 auto; position: relative; width: 132px; height: 132px; border-radius: 40px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--primary), var(--violet));
  box-shadow: 0 24px 50px -18px rgba(124, 92, 255, .8);
  transform: rotate(-6deg);
  animation: bob 3.2s ease-in-out infinite;
}
.hero-badge span { font-family: var(--display); font-weight: 800; font-size: 82px; color: #fff; line-height: 1; transform: rotate(6deg); }
.hero-badge::after {
  content: "🎈"; position: absolute; right: -26px; top: -28px; font-size: 44px; transform: rotate(14deg);
}
@keyframes bob { 50% { transform: rotate(-3deg) translateY(-6px); } }
.eyebrow { text-transform: uppercase; letter-spacing: .16em; font-weight: 800; font-size: .78rem; color: var(--primary); margin: 0; }
h1 {
  font-family: var(--display); font-weight: 800; margin: 0;
  font-size: clamp(1.8rem, 6.4vw, 2.6rem); line-height: 1.12; letter-spacing: -.01em;
}
h1 .grad { background: linear-gradient(90deg, var(--primary), var(--violet)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { margin: 0 auto; color: var(--muted); font-size: 1.05rem; line-height: 1.5; max-width: 30ch; }
.start form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.field-label { font-weight: 800; font-size: .9rem; color: var(--muted); padding-left: 6px; }
.input {
  width: 100%; min-height: 58px; border-radius: 18px; padding: 0 20px;
  border: 2px solid var(--line); background: #fff; color: var(--ink);
  font: 700 1.1rem var(--font);
  transition: border-color .2s, box-shadow .2s;
}
.input:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 5px rgba(124, 92, 255, .15); }
.rules { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px; font-weight: 800; font-size: .85rem;
  background: rgba(255, 255, 255, .75); border: 1px solid var(--line);
}

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.team {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0;
  font-weight: 900; font-size: .98rem;
}
.team .avatar {
  flex: none; width: 34px; height: 34px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--sky), var(--violet)); color: #fff; font-size: .95rem;
}
.team .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-pill {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px; background: #fff; box-shadow: var(--shadow);
  font-weight: 900; font-variant-numeric: tabular-nums;
}
.score-pill.bump { animation: bump .6s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bump { 40% { transform: scale(1.22); } }

.progress { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.progress-track { flex: 1; height: 10px; border-radius: 99px; background: rgba(43, 33, 64, .08); overflow: hidden; }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--violet)); transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.progress-label { font-weight: 800; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Question ---------- */
.q-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 20px; }
.q-emoji {
  flex: none; width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center;
  font-size: 28px; background: linear-gradient(145deg, #fff1e6, #efe9ff);
}
.q-type { margin: 2px 0 4px; font-size: .78rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; color: var(--violet); }
.q-text { margin: 0; font-family: var(--display); font-weight: 600; font-size: clamp(1.1rem, 4.2vw, 1.38rem); line-height: 1.32; }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .options { grid-template-columns: 1fr; } }
.option {
  position: relative; text-align: left; cursor: pointer;
  min-height: 64px; padding: 14px 16px 14px 56px; border-radius: 18px;
  border: 2px solid var(--line); background: #fff;
  font-weight: 800; font-size: 1.05rem; line-height: 1.3;
  transition: border-color .2s, background .2s, transform .15s, box-shadow .2s;
}
.option::before {
  content: attr(data-letter);
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center;
  font-size: .85rem; font-weight: 900; color: var(--muted); background: rgba(43, 33, 64, .06);
  transition: background .2s, color .2s;
}
.option:hover:not(:disabled) { border-color: rgba(124, 92, 255, .45); transform: translateY(-1px); }
.option.selected { border-color: var(--violet); background: #f4f0ff; box-shadow: 0 0 0 4px rgba(124, 92, 255, .14); }
.option.selected::before { background: var(--violet); color: #fff; }
.option:disabled { cursor: default; }
.option.correct { border-color: var(--ok); background: var(--ok-bg); animation: pop .5s cubic-bezier(.3, 1.6, .5, 1); }
.option.correct::before { content: "✓"; background: var(--ok); color: #fff; }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); animation: shake .45s; }
.option.wrong::before { content: "✕"; background: var(--bad); color: #fff; }
.option.dim { opacity: .45; }
@keyframes pop { 40% { transform: scale(1.04); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- Sequence ---------- */
.hint { margin: -6px 0 14px; color: var(--muted); font-weight: 700; font-size: .92rem; }
.seq { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; position: relative; }
.seq-item {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 62px; padding: 10px 10px 10px 12px; border-radius: 18px;
  background: #fff; border: 2px solid var(--line);
  font-weight: 800; font-size: 1.02rem; line-height: 1.3;
  touch-action: none; user-select: none; -webkit-user-select: none;
  cursor: grab;
  transition: transform .22s cubic-bezier(.2, .8, .2, 1), border-color .2s, background .2s, box-shadow .2s;
}
.seq-item .num {
  flex: none; width: 34px; height: 34px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--primary), var(--primary-2)); color: #fff; font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.seq-item .label { flex: 1; min-width: 0; }
.seq-item .grip { flex: none; color: #b7aec6; font-size: 20px; letter-spacing: -2px; padding: 0 2px; }
.seq-item .arrows { flex: none; display: flex; flex-direction: column; gap: 4px; }
.icon-btn {
  width: 34px; height: 26px; border-radius: 9px; border: 0; cursor: pointer;
  background: rgba(43, 33, 64, .06); color: var(--muted); font-size: 12px; font-weight: 900;
  display: grid; place-items: center; transition: background .15s, color .15s;
}
.icon-btn:hover:not(:disabled) { background: rgba(124, 92, 255, .15); color: var(--violet); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.seq-item.dragging {
  z-index: 5; cursor: grabbing; transition: border-color .2s, box-shadow .2s;
  border-color: var(--violet); box-shadow: 0 18px 40px -14px rgba(124, 92, 255, .6);
  background: #faf8ff;
}
.seq.locked .seq-item { cursor: default; }
.seq-item.correct { border-color: var(--ok); background: var(--ok-bg); }
.seq-item.correct .num { background: var(--ok); }
.seq-item.wrong { border-color: var(--bad); background: var(--bad-bg); }
.seq-item.wrong .num { background: var(--bad); }
.seq-item .verdict { flex: none; font-weight: 900; font-size: .82rem; padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.seq-item.correct .verdict { color: var(--ok); background: #fff; }
.seq-item.wrong .verdict { color: var(--bad); background: #fff; }

.solution { margin-top: 16px; padding: 16px; border-radius: 18px; background: rgba(31, 181, 122, .08); border: 1px dashed rgba(31, 181, 122, .5); }
.solution h4 { margin: 0 0 8px; font-size: .82rem; text-transform: uppercase; letter-spacing: .12em; color: var(--ok); }
.solution ol { margin: 0; padding-left: 22px; font-weight: 800; line-height: 1.7; }

/* ---------- Feedback / footer ---------- */
.feedback {
  margin-top: 18px; display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: 18px; font-weight: 800;
  animation: enter .4s cubic-bezier(.2, .8, .2, 1) both;
}
.feedback .big { font-family: var(--display); font-size: 1.4rem; font-weight: 800; white-space: nowrap; }
.feedback.good { background: var(--ok-bg); color: #0f7a51; }
.feedback.mid { background: #fff3d6; color: #9a6400; }
.feedback.bad { background: var(--bad-bg); color: #b4233f; }
.actions { margin-top: 18px; display: flex; gap: 12px; }
.actions .btn { flex: 1; }

/* ---------- Results ---------- */
.results { text-align: center; gap: 18px; justify-content: center; }
.trophy { font-size: 72px; line-height: 1; animation: bob 2.6s ease-in-out infinite; }
.total {
  font-family: var(--display); font-weight: 800; line-height: 1;
  font-size: clamp(4rem, 20vw, 6.5rem);
  background: linear-gradient(135deg, var(--primary), var(--violet)); -webkit-background-clip: text; background-clip: text; color: transparent;
  font-variant-numeric: tabular-nums;
}
.total-sub { margin: 6px 0 0; color: var(--muted); font-weight: 800; }
.verdict-line { margin: 0; font-size: 1.15rem; font-weight: 800; }
.breakdown { list-style: none; margin: 0; padding: 0; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.breakdown li {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, .7);
  font-weight: 700; font-size: .95rem;
}
.breakdown .bn { flex: none; width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; font-weight: 900; font-size: .8rem; background: rgba(43, 33, 64, .06); }
.breakdown .bt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breakdown .bp { flex: none; font-weight: 900; font-variant-numeric: tabular-nums; padding: 3px 10px; border-radius: 99px; }
.bp.full { background: var(--ok-bg); color: #0f7a51; }
.bp.part { background: #fff3d6; color: #9a6400; }
.bp.zero { background: var(--bad-bg); color: #b4233f; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(43, 33, 64, .35); backdrop-filter: blur(4px); animation: fade .2s both; }
.modal-card { width: 100%; max-width: 380px; background: #fff; border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); animation: enter .3s cubic-bezier(.2, .8, .2, 1) both; }
.modal-card h3 { margin: 0 0 8px; font-family: var(--display); font-weight: 600; }
.modal-card p { margin: 0 0 20px; color: var(--muted); font-weight: 600; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; min-height: 50px; padding: 0 16px; font-size: .98rem; }
@keyframes fade { from { opacity: 0; } }

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