:root {
  --bg: #f1f4ff;
  --bg2: #e6ecff;
  --card: #ffffff;
  --ink: #1d2142;
  --muted: #646a8f;
  --line: #dfe3f5;
  --brand: #6d4aff;
  --brand-2: #8f73ff;
  --ok: #16a34a;
  --ok-bg: #e5f8ec;
  --bad: #e11d48;
  --bad-bg: #ffe8ee;
  --gold: #f5b301;
  --c-solids: #7c5cff;
  --c-circle: #ff7a2f;
  --c-volume: #0fb5a6;
  --c-warm: #e64fa8;
  --c-final: #f5a300;
  --radius: 20px;
  --shadow: 0 6px 22px rgba(40, 44, 110, 0.10);
  --shadow-lg: 0 14px 40px rgba(40, 44, 110, 0.18);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Rubik', system-ui, 'Segoe UI', Arial, sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 600px at 100% -10%, #dcd3ff 0%, transparent 60%),
              radial-gradient(900px 500px at -10% 110%, #c9f1ec 0%, transparent 60%), var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  font-size: 18px;
  line-height: 1.55;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
.grid > * { min-width: 0; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 16px; }
.hidden { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
.muted { color: var(--muted); }
.center { text-align: center; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 16px; padding: 14px 22px; font-weight: 700; font-size: 1.05rem;
  background: var(--brand); color: #fff; box-shadow: 0 4px 0 #4b2fd1;
  transition: transform .08s, box-shadow .08s, filter .15s; display: inline-flex; align-items: center; gap: 8px;
  justify-content: center;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #4b2fd1; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 4px 0 var(--line); border: 2px solid var(--line); }
.btn.ok { background: var(--ok); box-shadow: 0 4px 0 #0f7a36; }
.btn.small { padding: 8px 14px; font-size: .95rem; border-radius: 12px; }
.btn.big { padding: 18px 30px; font-size: 1.25rem; border-radius: 20px; }
.btn.block { width: 100%; }
.icon-btn { background: #fff; border: 2px solid var(--line); border-radius: 14px; width: 46px; height: 46px; font-size: 1.3rem; display: inline-grid; place-items: center; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.86); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar .wrap { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; }
.logo { font-weight: 800; font-size: 1.2rem; display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); }
.logo .gem { font-size: 1.6rem; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 2px solid var(--line); border-radius: 999px; padding: 4px 12px; font-weight: 700; }
.pill.gold { border-color: #ffe08a; background: #fff8dc; }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 1.6rem; background: #efeaff; border: 2px solid #d8ceff; flex: none; }
.avatar.lg { width: 84px; height: 84px; font-size: 3rem; }

/* ---------- login ---------- */
.hero { text-align: center; padding: 40px 16px 10px; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.4rem); font-weight: 800; letter-spacing: -.5px; }
.hero h1 span { background: linear-gradient(90deg, var(--c-solids), var(--c-circle), var(--c-volume)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero .shapes { font-size: 2.6rem; letter-spacing: 10px; animation: float 4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px); } }
.login-box { max-width: 520px; margin: 20px auto; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 700; }
.input { width: 100%; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line); background: #fff; font-size: 1.1rem; outline: none; }
.input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 4px rgba(109,74,255,.15); }
.code-input { letter-spacing: 12px; text-align: center; font-size: 1.6rem; font-weight: 700; direction: ltr; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 8px 14px; font-weight: 700; }
.seg button.on { border-color: var(--brand); background: #efeaff; color: var(--brand); }
.avatars { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px; }
.avatars button { font-size: 2rem; aspect-ratio: 1; border-radius: 16px; border: 3px solid transparent; background: #f4f2ff; transition: transform .1s; }
.avatars button:hover { transform: scale(1.08); }
.avatars button.on { border-color: var(--brand); background: #e6dfff; transform: scale(1.08); }
.tabs2 { display: grid; grid-template-columns: 1fr 1fr; background: #eceffd; border-radius: 16px; padding: 5px; margin-bottom: 18px; }
.tabs2 button { border: 0; background: transparent; padding: 12px; border-radius: 12px; font-weight: 700; }
.tabs2 button.on { background: #fff; box-shadow: var(--shadow); color: var(--brand); }
.err { color: var(--bad); font-weight: 700; min-height: 1.4em; }
.teacher-link { display: block; text-align: center; margin: 30px auto; color: var(--muted); font-size: .9rem; background: none; border: 0; text-decoration: underline; }

/* ---------- home map ---------- */
.welcome { display: flex; gap: 16px; align-items: center; margin: 10px 0 18px; }
.welcome h2 { margin: 0; font-size: 1.6rem; }
.chapter { margin: 26px 0 8px; display: flex; align-items: center; gap: 10px; }
.chapter h3 { margin: 0; font-size: 1.35rem; }
.chapter .bar { flex: 1; height: 4px; border-radius: 4px; background: linear-gradient(90deg, transparent, var(--chap)); opacity: .4; }
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.unit-card { position: relative; text-align: right; border: 0; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 16px 14px; transition: transform .15s, box-shadow .15s; border-top: 6px solid var(--chap); display: grid; gap: 6px; }
.unit-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.unit-card .num { position: absolute; left: 14px; top: 12px; font-weight: 800; color: var(--chap); opacity: .35; font-size: 1.6rem; }
.unit-card .emoji { font-size: 2.2rem; }
.unit-card .t { font-weight: 800; font-size: 1.12rem; }
.unit-card .s { color: var(--muted); font-size: .9rem; line-height: 1.35; }
.unit-card.next { box-shadow: 0 0 0 3px var(--chap), var(--shadow-lg); }
.unit-card.next .num { display: none; }
.unit-card .next-tag { position: absolute; left: 12px; top: 12px; background: var(--chap); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 700; }
.steps { display: flex; gap: 6px; margin-top: 4px; }
.steps i { flex: 1; height: 7px; border-radius: 6px; background: #eceffd; }
.steps i.on { background: var(--chap); }
.stars { color: var(--gold); letter-spacing: 2px; font-size: 1.05rem; }
.stars .off { color: #d9dbe8; }

/* ---------- unit page ---------- */
.unit-head { display: flex; gap: 14px; align-items: center; padding: 18px; border-radius: var(--radius); color: #fff; background: linear-gradient(120deg, var(--chap), color-mix(in srgb, var(--chap) 60%, #fff)); box-shadow: var(--shadow); margin-bottom: 16px; }
.unit-head .emoji { font-size: 3rem; }
.unit-head h1 { margin: 0; font-size: 1.7rem; }
.unit-head p { margin: 2px 0 0; opacity: .95; }
.acts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.act { border: 0; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; text-align: right; display: grid; gap: 6px; transition: transform .15s; }
.act:hover { transform: translateY(-3px); }
.act .ic { font-size: 2.2rem; }
.act .t { font-weight: 800; font-size: 1.2rem; }
.act .s { color: var(--muted); font-size: .92rem; }
.act .st { font-weight: 700; color: var(--chap); font-size: .92rem; }
.act.done { outline: 3px solid color-mix(in srgb, var(--chap) 35%, transparent); }

/* ---------- lesson ---------- */
.lesson { display: grid; grid-template-columns: 1.05fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 820px) { .lesson { grid-template-columns: 1fr; } }
.lesson .text { font-size: 1.12rem; }
.lesson .text h2 { color: var(--chap); font-size: 1.6rem; }
.lesson .text b, .lesson .text strong { color: color-mix(in srgb, var(--chap) 75%, #000); }
.lesson .viz { min-height: 320px; }
.dots { display: flex; gap: 6px; justify-content: center; margin: 12px 0; flex-wrap: wrap; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: #d7dbf0; }
.dots i.on { background: var(--chap); width: 26px; border-radius: 8px; }
.nav-row { display: flex; gap: 10px; justify-content: space-between; margin-top: 14px; }
.box { background: color-mix(in srgb, var(--chap) 9%, #fff); border-right: 5px solid var(--chap); padding: 12px 14px; border-radius: 12px; margin: 12px 0; }
.formula { direction: ltr; display: inline-block; font-weight: 800; font-size: 1.25rem; background: #fff; border: 2px dashed var(--chap); border-radius: 12px; padding: 6px 14px; margin: 4px 0; unicode-bidi: isolate; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
table.t { border-collapse: collapse; width: 100%; background: #fff; border-radius: 12px; overflow: hidden; font-size: 1rem; }
table.t th, table.t td { border: 1px solid var(--line); padding: 8px; text-align: center; }
table.t th { background: color-mix(in srgb, var(--chap) 12%, #fff); }
.check { margin-top: 14px; }

/* ---------- 3D / svg stage ---------- */
.stage { position: relative; background: linear-gradient(180deg, #fbfbff, #eef1ff); border-radius: var(--radius); box-shadow: inset 0 0 0 2px var(--line); overflow: hidden; touch-action: none; }
.stage canvas { display: block; width: 100%; height: 100%; }
.stage .hint { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; color: var(--muted); font-size: .85rem; pointer-events: none; }
.stage .counter { position: absolute; top: 10px; right: 10px; background: #fff; border-radius: 12px; padding: 4px 12px; font-weight: 800; box-shadow: var(--shadow); }
.tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; justify-content: center; }
.tools button { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 7px 12px; font-weight: 700; font-size: .95rem; }
.tools button.on { border-color: var(--chap); background: color-mix(in srgb, var(--chap) 12%, #fff); color: color-mix(in srgb, var(--chap) 80%, #000); }
.slider-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; justify-content: center; flex-wrap: wrap; font-weight: 700; }
input[type=range] { accent-color: var(--chap, var(--brand)); width: min(260px, 60vw); }
svg text { font-family: 'Rubik', sans-serif; }

/* ---------- questions ---------- */
.qwrap { max-width: 820px; margin: 0 auto; }
.qtop { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.progress { flex: 1; height: 12px; background: #e3e7fb; border-radius: 10px; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--chap), color-mix(in srgb, var(--chap) 55%, #fff)); border-radius: 10px; transition: width .3s; }
.qcard { padding: 22px; }
.qprompt { font-size: 1.3rem; font-weight: 700; margin-bottom: 14px; }
.qvisual { margin: 6px auto 16px; max-width: 460px; }
.qvisual .stage { height: 260px; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.choice { border: 3px solid var(--line); background: #fff; border-radius: 16px; padding: 14px; font-weight: 700; font-size: 1.12rem; transition: transform .08s, border-color .15s; min-height: 58px; }
.choice:hover { border-color: var(--brand-2); }
.choice:active { transform: scale(.98); }
.choice.right { border-color: var(--ok); background: var(--ok-bg); }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); animation: shake .35s; }
.choice.dim { opacity: .5; }
.choice svg { max-width: 100%; height: auto; display: block; margin: 0 auto; }
@keyframes shake { 25% { transform: translateX(6px); } 75% { transform: translateX(-6px); } }
.numrow { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.numrow .input { max-width: 220px; text-align: center; font-size: 1.4rem; font-weight: 700; direction: ltr; }
.feedback { margin-top: 14px; border-radius: 14px; padding: 12px 14px; font-weight: 500; display: none; }
.feedback.show { display: block; animation: pop .25s; }
.feedback.ok { background: var(--ok-bg); color: #0d5c2a; }
.feedback.bad { background: var(--bad-bg); color: #8a1030; }
.feedback.hint { background: #fff6d6; color: #6d5200; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }

/* ---------- results ---------- */
.result { text-align: center; padding: 30px 20px; }
.big-stars { font-size: 3.6rem; letter-spacing: 8px; }
.big-stars span { display: inline-block; animation: starIn .5s both; }
.big-stars span:nth-child(2) { animation-delay: .25s; }
.big-stars span:nth-child(3) { animation-delay: .5s; }
.big-stars .off { filter: grayscale(1) opacity(.25); }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } 70% { transform: scale(1.3); } }
.score-big { font-size: 2.6rem; font-weight: 800; color: var(--chap); }

/* ---------- games ---------- */
.game-hud { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.game-hud .pill { font-size: 1.05rem; }
.timer { flex: 1; min-width: 120px; height: 14px; background: #e3e7fb; border-radius: 10px; overflow: hidden; }
.timer i { display: block; height: 100%; background: linear-gradient(90deg, #ffb703, #fb5607); transition: width .25s linear; }
.combo { font-weight: 800; color: #fb5607; }
.mem-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; max-width: 640px; margin: 0 auto; }
@media (max-width: 520px) { .mem-grid { grid-template-columns: repeat(3, 1fr); } }
.mem { aspect-ratio: 1; border: 0; border-radius: 16px; background: linear-gradient(135deg, var(--chap), color-mix(in srgb, var(--chap) 60%, #fff)); color: #fff; font-size: 2rem; font-weight: 800; box-shadow: var(--shadow); padding: 6px; position: relative; transition: transform .25s; }
.mem.open, .mem.done { background: #fff; color: var(--ink); font-size: .95rem; box-shadow: inset 0 0 0 3px var(--chap); }
.mem.done { opacity: .55; box-shadow: inset 0 0 0 3px var(--ok); }
.mem svg { width: 100%; height: 100%; }
.sort-item { font-size: 1.4rem; font-weight: 800; text-align: center; padding: 18px; background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg); max-width: 360px; margin: 0 auto 18px; min-height: 120px; display: grid; place-items: center; }
.sort-item svg { max-height: 150px; }
.bins { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.bin { border: 3px dashed var(--chap); background: color-mix(in srgb, var(--chap) 7%, #fff); border-radius: 18px; padding: 18px 10px; font-weight: 800; font-size: 1.1rem; min-height: 90px; }
.bin:hover { background: color-mix(in srgb, var(--chap) 15%, #fff); }
.bin.flash-ok { background: var(--ok-bg); border-color: var(--ok); }
.bin.flash-bad { background: var(--bad-bg); border-color: var(--bad); }

/* ---------- toast & confetti ---------- */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(120px); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px; font-weight: 700; z-index: 100; transition: transform .3s; max-width: 90vw; text-align: center; }
#toast.show { transform: translateX(-50%) translateY(0); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- teacher ---------- */
.t-table-wrap { overflow-x: auto; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
table.tt { border-collapse: collapse; width: 100%; font-size: .92rem; }
table.tt th, table.tt td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
table.tt th { position: sticky; top: 0; background: #f6f7ff; font-size: .8rem; }
table.tt td.name { text-align: right; font-weight: 700; cursor: pointer; }
table.tt tr:hover td { background: #fafaff; }
.cell { display: inline-grid; place-items: center; min-width: 34px; height: 30px; border-radius: 8px; font-weight: 800; font-size: .82rem; }
.cell.s0 { background: #f1f2f8; color: #aab; }
.cell.s1 { background: #ffe2e2; color: #9b1c1c; }
.cell.s2 { background: #fff1c2; color: #7a5600; }
.cell.s3 { background: #d7f5df; color: #11602f; }
.cell.p { background: #e9e6ff; color: #4b2fd1; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.kpi b { display: block; font-size: 1.8rem; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 160px 1fr 50px; gap: 8px; align-items: center; font-size: .92rem; }
.bar-row .b { height: 14px; background: #eef0fa; border-radius: 8px; overflow: hidden; }
.bar-row .b i { display: block; height: 100%; background: var(--brand); }
.modal-bg { position: fixed; inset: 0; background: rgba(20, 22, 50, .45); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: var(--radius); max-width: 760px; width: 100%; max-height: 90vh; overflow: auto; padding: 22px; box-shadow: var(--shadow-lg); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin: 8px 0; }

@media (max-width: 600px) {
  body { font-size: 17px; }
  .wrap { padding: 12px 16px; }
  .qprompt { font-size: 1.15rem; }
  .unit-head h1 { font-size: 1.35rem; }
  .bar-row { grid-template-columns: 110px 1fr 44px; }
  .logo .txt { display: none; }
  table.t th, table.t td { padding: 5px 3px; font-size: .85rem; }
  input[type=range] { width: 46vw; }
}
