:root {
  --bg: #fdf8ef;
  --bg2: #fff;
  --ink: #1f2a3c;
  --muted: #5d6879;
  --line: #e7dfd0;
  --primary: #5b4ee8;
  --primary-ink: #fff;
  --run: #20a852;
  --run-dark: #168a42;
  --warm: #ff9f1c;
  --star: #f5b400;
  --bad-bg: #ffd6d6;
  --bad-ink: #c92a2a;
  --tc: #5b4ee8;
  --radius: 18px;
  --shadow: 0 4px 0 rgba(31, 42, 60, 0.08), 0 10px 30px rgba(31, 42, 60, 0.07);
  --font: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --display: "Fredoka", "Atkinson Hyperlegible", system-ui, sans-serif;
  --mono: "Atkinson Hyperlegible Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --code-size: 21px;
  --base-size: 18px;
}
body.big-text { --code-size: 26px; --base-size: 21px; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: var(--base-size);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  background-image: radial-gradient(circle at 10% 0%, #fff1d6 0, transparent 40%), radial-gradient(circle at 100% 30%, #ece9ff 0, transparent 35%);
  background-attachment: fixed;
  min-height: 100vh;
}
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.15; margin: 0 0 .4em; }
a { color: var(--primary); }
code { font-family: var(--mono); background: #efeafe; color: #3a2fb8; padding: .05em .35em; border-radius: 6px; font-size: .92em; white-space: pre-wrap; }
.muted { color: var(--muted); }
main { outline: none; padding: 20px 16px 60px; max-width: 1400px; margin: 0 auto; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-family: var(--display); font-weight: 600;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  border: 0; border-radius: 14px; padding: .6em 1.1em; cursor: pointer; text-decoration: none;
  background: #ece8dc; color: var(--ink); box-shadow: 0 4px 0 rgba(0,0,0,.12);
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn small { font-family: var(--font); font-weight: 400; font-size: .7em; opacity: .9; }
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.12); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 0 #3d33b0; }
.btn-warm { background: var(--warm); color: #3b2300; box-shadow: 0 4px 0 #cc7a00; }
.btn-star { background: #ffe066; color: #5c4400; box-shadow: 0 4px 0 #e0b800; }
.btn-run { background: var(--run); color: #fff; box-shadow: 0 5px 0 var(--run-dark); font-size: 1.35em; padding: .5em 1.6em; }
.btn-ghost { background: #fff; border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line); }
.btn-lg { font-size: 1.15em; padding: .7em 1.4em; }
.btn-sm { font-size: .85em; padding: .4em .8em; }
.btn-block { width: 100%; }
.icon-btn { font-size: 1.3em; background: #fff; border: 2px solid var(--line); border-radius: 12px; width: 2.2em; height: 2.2em; cursor: pointer; line-height: 1; }
.icon-btn:hover { background: #f6f2ff; }
.link-btn { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; text-decoration: underline; padding: .3em; }
.kbd { display: inline-block; font-family: var(--mono); font-size: .8em; border: 1.5px solid var(--line); border-bottom-width: 3px; border-radius: 6px; padding: 0 .4em; background: #fff; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: rgba(253, 248, 239, .92); backdrop-filter: blur(8px); border-bottom: 2px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-family: var(--display); font-weight: 700; font-size: 1.3em; }
.brand-logo { font-size: 1.4em; }
.top-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.chip { background: #fff; border: 2px solid var(--line); border-radius: 999px; padding: .2em .8em; font-weight: 700; font-size: .9em; white-space: nowrap; }
.chip-streak b { color: #e8590c; }
.chip-xp b { color: var(--primary); }
.demo-banner { background: #fff3bf; color: #664d03; text-align: center; padding: 8px 16px; font-size: .85em; border-bottom: 2px solid #ffe066; }

/* ---------- boot ---------- */
.boot { min-height: 60vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.boot-snake { font-size: 4em; animation: wiggle 1.2s ease-in-out infinite; }
@keyframes wiggle { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg) scale(1.08); } }

/* ---------- auth ---------- */
.auth { display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px; align-items: center; max-width: 980px; margin: 4vh auto; }
.auth-hero { text-align: center; }
.hero-snake { font-size: 6em; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
.auth-hero h1 { font-size: 3em; color: var(--primary); }
.auth-hero p { font-size: 1.2em; color: var(--muted); }
.hero-badges { display: flex; justify-content: center; gap: 10px; font-size: 1.8em; }
.hero-badges span { background: #fff; border-radius: 16px; padding: 8px; box-shadow: var(--shadow); animation: bob 3s ease-in-out infinite; }
.hero-badges span:nth-child(2) { animation-delay: .3s } .hero-badges span:nth-child(3) { animation-delay: .6s }
.hero-badges span:nth-child(4) { animation-delay: .9s } .hero-badges span:nth-child(5) { animation-delay: 1.2s }
.auth-card { background: var(--bg2); border-radius: 24px; padding: 28px; box-shadow: var(--shadow); border: 2px solid var(--line); }
.btn-google { flex-direction: row; gap: 12px; background: #fff; color: var(--ink); border: 2px solid #c9c2b2; box-shadow: 0 4px 0 #c9c2b2; }
.btn-google:hover { background: #f8f9ff; }
.g-icon { display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; border-radius: 50%; background: #4285f4; color: #fff; font-family: var(--font); font-weight: 700; font-size: .9em; }
#googleError { margin: 6px 0 0; min-height: 0; }
.or-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .9em; margin: 14px 0 16px; }
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 2px; background: var(--line); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: #f3eee3; border-radius: 14px; padding: 5px; margin-bottom: 20px; }
.tab { font: inherit; font-family: var(--display); font-weight: 600; font-size: 1.05em; border: 0; background: none; padding: .55em; border-radius: 10px; cursor: pointer; color: var(--muted); }
.tab.active { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 700; margin-bottom: 4px; }
.field input { width: 100%; font: inherit; font-size: 1.05em; padding: .6em .8em; border: 2px solid var(--line); border-radius: 12px; background: #fffdf9; }
.field input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 4px #e3e0ff; }
.pw-row { display: flex; gap: 8px; }
.form-error { color: var(--bad-ink); font-weight: 700; min-height: 1.4em; margin: 4px 0 10px; }
#forgot { display: block; margin: 12px auto 0; }

/* ---------- home ---------- */
.welcome { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; margin: 10px 0 22px; }
.welcome h1 { font-size: 2.3em; margin: 0; }
.home-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 30px; }
.stat { background: #fff; border: 2px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); }
.stat-icon { font-size: 2em; }
.stat-body { flex: 1; min-width: 0; }
.stat-label { font-size: .8em; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.stat-value { font-family: var(--display); font-weight: 600; font-size: 1.3em; }
.stat-sub { font-size: .8em; color: var(--muted); }
.bar { height: 10px; background: #efe9dc; border-radius: 999px; overflow: hidden; margin: 6px 0 2px; }
.bar span { display: block; height: 100%; background: var(--tc, var(--primary)); border-radius: 999px; transition: width .6s; }
.section-title { font-size: 1.6em; margin: 0 0 14px; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.topic-card {
  display: block; text-decoration: none; color: var(--ink); background: #fff; border-radius: 22px; padding: 18px;
  border: 3px solid var(--tc); box-shadow: 0 6px 0 var(--tc); transition: transform .15s; position: relative;
}
.topic-card:hover { transform: translateY(-4px) rotate(-.5deg); }
.topic-card.locked { border-color: #d6d0c3; box-shadow: 0 6px 0 #d6d0c3; background: #f6f3ec; cursor: not-allowed; color: var(--muted); }
.topic-card.locked:hover { transform: none; }
.topic-card.locked .bar span { background: #cfc8b8; }
.topic-card.complete::after { content: "🏆"; position: absolute; top: 10px; right: 14px; font-size: 1.6em; }
.topic-num { font-size: .78em; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.topic-emoji { font-size: 2.6em; margin: 4px 0; }
.topic-emoji.big { font-size: 4em; }
.topic-name { font-family: var(--display); font-weight: 600; font-size: 1.35em; }
.topic-meta { font-size: .85em; color: var(--muted); margin-top: 4px; }

/* ---------- topic ---------- */
.back { display: inline-block; font-weight: 700; text-decoration: none; margin-bottom: 10px; }
.topic-view { max-width: 1000px; margin: 0 auto; }
.topic-head { display: flex; gap: 18px; align-items: center; margin-bottom: 14px; }
.topic-head h1 { font-size: 2.4em; margin: 0; color: var(--tc); filter: brightness(.8); }
.intro-card { position: relative; background: #fff; border-radius: var(--radius); padding: 18px 70px 18px 20px; border: 2px solid var(--line); border-left: 8px solid var(--tc); box-shadow: var(--shadow); margin-bottom: 26px; font-size: 1.08em; }
.intro-card h3 { margin-bottom: 6px; }
.intro-card p { margin: 0; }
.intro-card .speak { position: absolute; top: 14px; right: 14px; }
.level-path { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.lvl {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 14px 10px;
  background: #fff; border: 3px solid var(--line); border-radius: 20px; text-decoration: none; color: var(--ink);
  box-shadow: 0 5px 0 var(--line); transition: transform .12s;
}
.lvl:hover { transform: translateY(-3px); }
.lvl-num { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 1.5em; background: #f3eee3; }
.lvl.done { border-color: var(--tc); box-shadow: 0 5px 0 var(--tc); }
.lvl.done .lvl-num { background: var(--tc); color: #fff; }
.lvl.current { border-color: var(--primary); box-shadow: 0 5px 0 var(--primary); animation: pulse 1.6s infinite; }
.lvl.current .lvl-num { background: var(--primary); color: #fff; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.04); } }
.lvl.locked { opacity: .55; cursor: not-allowed; background: #f6f3ec; }
.lvl.locked:hover { transform: none; }
.lvl.boss .lvl-num { width: 62px; height: 62px; }
.lvl-title { font-weight: 700; font-size: .92em; line-height: 1.2; min-height: 2.4em; display: flex; align-items: center; }
.lvl-badges { display: flex; gap: 6px; font-size: 1.1em; }
.lvl-badges span { filter: grayscale(1); opacity: .3; }
.lvl-badges span.on { filter: none; opacity: 1; }
.legend { text-align: center; color: var(--muted); font-size: .9em; margin-top: 20px; }

/* ---------- level ---------- */
.level-view { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 22px; align-items: start; }
.task-panel { background: #fff; border: 2px solid var(--line); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.warm-pill { display: inline-block; background: #fff0d6; color: #8a4b00; font-weight: 700; border-radius: 999px; padding: .15em .8em; margin-bottom: 8px; font-size: .9em; }
.lvl-kicker { font-weight: 700; color: var(--muted); font-size: .9em; }
.lvl-h1 { font-size: 1.8em; color: var(--ink); margin: 2px 0 12px; }
.task-card { position: relative; background: color-mix(in srgb, var(--tc) 12%, white); border: 2px solid color-mix(in srgb, var(--tc) 45%, white); border-radius: 16px; padding: 14px 60px 14px 16px; }
.task-card .speak { position: absolute; top: 10px; right: 10px; }
.task-label { font-size: .78em; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.task-text { margin: 4px 0 0; font-size: 1.12em; }
.tip { margin-top: 12px; background: #fff9db; border: 2px dashed #f2cc4b; border-radius: 14px; padding: 10px 12px; font-size: .95em; display: flex; gap: 8px; }
.goal { margin-top: 14px; }
.goal-label { font-weight: 700; margin-bottom: 6px; }
.goal-note { font-weight: 400; font-size: .8em; color: var(--muted); }
.hint-row { margin-top: 14px; }
.hint-box { margin-top: 10px; background: #e7f5ff; border-radius: 14px; padding: 10px 14px; border: 2px solid #a5d8ff; }
.earned { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.earn { border: 2px solid var(--line); border-radius: 999px; padding: .2em .8em; font-weight: 700; color: var(--muted); background: #faf8f3; filter: grayscale(1); opacity: .6; font-size: .9em; }
.earn.on { filter: none; opacity: 1; color: var(--ink); background: #fff7d1; border-color: #f5c400; }

.work { min-width: 0; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.tool-btns { display: flex; gap: 8px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.slider { width: 62px; height: 34px; background: #cfc8b8; border-radius: 999px; position: relative; transition: background .2s; flex: none; }
.slider::after { content: ""; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + .slider { background: var(--run); }
.switch input:checked + .slider::after { transform: translateX(28px); }
.switch input:focus-visible + .slider { outline: 3px solid var(--primary); outline-offset: 2px; }
.switch-label { font-family: var(--display); font-weight: 600; font-size: 1.1em; }
.switch-label b { display: inline-block; min-width: 2.6em; text-align: center; margin-left: 4px; padding: 0 .4em; border-radius: 8px; background: #eee; font-size: .85em; }
#guideToggle:checked ~ .switch-label b { background: #d3f9d8; color: #2b8a3e; }

/* ---------- editor ---------- */
.editor {
  display: flex; background: #fffefb; border: 3px solid #2f3a4f; border-radius: 18px; overflow: hidden;
  font-family: var(--mono); font-size: var(--code-size); line-height: 1.6; min-height: 320px;
  box-shadow: 0 6px 0 #2f3a4f;
}
.editor:focus-within { border-color: var(--primary); box-shadow: 0 6px 0 var(--primary), 0 0 0 5px #e3e0ff; }
.ed-gutter { flex: none; padding: 14px 10px 14px 12px; background: #f3efe6; color: #a19a8a; text-align: right; user-select: none; overflow: hidden; min-width: 2.6em; }
.ed-gutter div { height: 1.6em; }
.ed-scroll { flex: 1; overflow: auto; position: relative; }
.ed-wrap { position: relative; display: inline-block; min-width: 100%; min-height: 100%; }
.ed-layer, .ed-input {
  font: inherit; line-height: inherit; letter-spacing: 0; tab-size: 4; white-space: pre; word-wrap: normal;
  margin: 0; padding: 14px 16px; border: 0;
}
.ed-layer { color: var(--ink); pointer-events: none; min-height: 100%; position: relative; z-index: 1; }
.ed-input {
  position: absolute; inset: 0; width: 100%; height: 100%; resize: none; overflow: hidden;
  background: transparent; color: transparent; caret-color: #1f2a3c; outline: none; z-index: 2;
}
.ed-input::selection { background: rgba(91, 78, 232, .25); color: transparent; }
.editor.has-err .ed-wrap::before {
  content: ""; position: absolute; left: 0; right: 0; height: 1.6em; top: calc(14px + var(--err-line) * 1.6em);
  background: #ffe3e3; border-left: 5px solid var(--bad-ink); z-index: 0;
}
.t-kw { color: #9c36b5; }
.t-fn { color: #1864ab; }
.t-str { color: #2b8a3e; }
.t-num { color: #d9480f; }
.t-com { color: #868e96; }
.t-ghost { color: #b3bac7; font-weight: 400; font-style: normal; }
.t-bad { background: var(--bad-bg); box-shadow: inset 0 -3px 0 var(--bad-ink); border-radius: 3px; color: var(--bad-ink); }
.t-next { background: #fff3bf; box-shadow: inset 0 -4px 0 #f59f00; border-radius: 3px; color: #8d7d53; animation: blinkbg 1.1s ease-in-out infinite; }
.t-eol { font-size: .8em; }
@keyframes blinkbg { 0%,100% { background: #fff3bf; } 50% { background: #ffe066; } }

.run-row { display: flex; align-items: center; gap: 16px; margin: 16px 0; flex-wrap: wrap; }
.run-status { color: var(--muted); }

/* ---------- console ---------- */
.console-wrap { background: #1f2536; border-radius: 16px; overflow: hidden; border: 3px solid #1f2536; }
.console-head { display: flex; justify-content: space-between; align-items: center; color: #c9d1e3; padding: 6px 14px; font-weight: 700; background: #2a3147; font-size: .9em; }
.console-head .link-btn { color: #9fb3ff; font-size: .9em; }
.console {
  font-family: var(--mono); font-size: calc(var(--code-size) * .92); line-height: 1.5; margin: 0;
  padding: 14px 16px; white-space: pre-wrap; word-break: break-word; min-height: 120px; color: #f1f3f9; background: #1f2536;
}
.console .muted { color: #8a93aa; font-style: italic; }
.console .in { color: #ffd43b; font-weight: 700; }
.console .err { color: #ff8787; display: block; margin-top: 6px; }
.goal-console { min-height: 0; border-radius: 12px; font-size: calc(var(--code-size) * .8); }
.con-input-wrap { display: inline-flex; align-items: center; gap: 10px; }
.con-input {
  font: inherit; font-weight: 700; color: #ffd43b; background: #2e3650; border: 2px solid #ffd43b; border-radius: 8px;
  padding: 0 .4em; min-width: 8ch; outline: none; animation: glow 1.4s infinite;
}
@keyframes glow { 0%,100% { box-shadow: 0 0 0 0 rgba(255,212,59,.5); } 50% { box-shadow: 0 0 0 5px rgba(255,212,59,0); } }
.con-enter { color: #8a93aa; font-size: .75em; }

/* ---------- feedback ---------- */
#feedback { margin-top: 14px; }
.fb { display: flex; gap: 14px; border-radius: 16px; padding: 14px 16px; border: 3px solid; animation: pop .3s ease-out; }
.fb-icon { font-size: 2em; line-height: 1; }
.fb-title { font-family: var(--display); font-weight: 600; font-size: 1.2em; }
.fb-help { margin-top: 2px; }
.fb-extra { margin-top: 8px; }
.fb-oops { background: #fff5f5; border-color: #ffa8a8; }
.fb-close { background: #fff9db; border-color: #ffd43b; }
.fb-info { background: #e7f5ff; border-color: #74c0fc; }
.fb-good { background: #ebfbee; border-color: #69db7c; }
.compare { display: grid; gap: 6px; }
.compare div { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.compare span { font-weight: 700; min-width: 6.5em; font-size: .9em; color: var(--muted); }
.compare code { font-size: 1em; background: #fff; border: 1.5px solid var(--line); color: var(--ink); }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- modal ---------- */
.modal-root { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(31, 42, 60, .45); animation: fade .2s; }
.modal { position: relative; background: #fff; border-radius: 26px; padding: 26px; width: min(520px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: bounceIn .5s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes fade { from { opacity: 0; } }
@keyframes bounceIn { from { transform: scale(.6) translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.win { text-align: center; }
.win-emoji { font-size: 5em; line-height: 1; animation: spinpop .9s ease-out; }
@keyframes spinpop { 0% { transform: scale(0) rotate(-180deg); } 70% { transform: scale(1.25) rotate(10deg); } 100% { transform: scale(1) rotate(0); } }
.win h2 { font-size: 2.2em; color: var(--primary); margin: 8px 0 0; }
.win-sub { color: var(--muted); margin: 4px 0 14px; }
.win-badges { display: flex; justify-content: center; gap: 14px; margin-bottom: 12px; }
.wb { display: flex; flex-direction: column; align-items: center; font-weight: 700; font-size: .9em; padding: 10px 14px; border-radius: 16px; background: #f5f2ea; filter: grayscale(1); opacity: .45; }
.wb span { font-size: 2.2em; }
.wb.on { filter: none; opacity: 1; background: #fff7d1; }
.wb.new { animation: badgepop .8s .3s both cubic-bezier(.2, 1.8, .4, 1); box-shadow: 0 0 0 3px var(--star); }
@keyframes badgepop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
.win-xp { font-family: var(--display); font-weight: 700; font-size: 2em; color: var(--primary); }
.win-stats { display: flex; justify-content: center; gap: 24px; margin: 10px 0; }
.win-stats div { display: flex; flex-direction: column; }
.win-stats b { font-family: var(--display); font-size: 1.6em; }
.win-stats span { font-size: .8em; color: var(--muted); }
.rank-up { background: linear-gradient(90deg, #fff3bf, #ffe8cc); border-radius: 14px; padding: 10px; font-size: 1.15em; margin: 10px 0; animation: pop .5s .5s both; }
.win-nudge { font-size: .95em; color: var(--muted); }
.win-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 2px solid #f2ede3; cursor: pointer; }
.set-row small { display: block; color: var(--muted); font-size: .85em; }
.set-classes { padding: 12px 0; border-bottom: 2px solid #f2ede3; }
.set-classes ul { list-style: none; padding: 0; margin: 6px 0; }
.set-classes li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; }
.join-row { display: flex; gap: 8px; margin-top: 8px; }
.join-row input { flex: 1; font: inherit; font-family: var(--mono); text-transform: uppercase; letter-spacing: .12em; padding: .4em .7em; border: 2px solid var(--line); border-radius: 10px; }
.set-classes .form-error { min-height: 0; margin: 4px 0 0; }
.set-account { margin-top: 14px; font-size: .9em; word-break: break-all; }

/* ---------- toast / fx ---------- */
.toast { visibility: hidden; opacity: 0; position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 120px); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px; z-index: 60; transition: transform .3s; max-width: calc(100% - 32px); }
.toast.show { visibility: visible; opacity: 1; transform: translate(-50%, 0); }
.fx-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 70; }

/* ---------- success panel (sits under the output, never covers it) ---------- */
.console-wrap { transition: border-color .3s, box-shadow .3s; }
.console-wrap.is-win { border-color: #40c057; box-shadow: 0 0 0 4px rgba(64, 192, 87, .3); }
.console-wrap.is-win .console-head { background: #2b8a3e; color: #fff; }
.win-panel {
  position: relative; overflow: hidden; border-radius: 22px; padding: 18px 20px;
  background: linear-gradient(135deg, #ebfbee 0%, #fff9db 55%, #f3f0ff 100%);
  border: 3px solid #69db7c; box-shadow: 0 6px 0 #40c057; animation: winIn .55s cubic-bezier(.2, 1.5, .4, 1);
}
.win-panel.big { border-color: #fab005; box-shadow: 0 6px 0 #f08c00; background: linear-gradient(135deg, #fff3bf 0%, #ffe8cc 50%, #f3f0ff 100%); }
@keyframes winIn { from { transform: translateY(16px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.win-fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.win-content { position: relative; z-index: 1; }
.win-top { display: flex; align-items: center; gap: 14px; }
.win-top .win-emoji { font-size: 3.2em; line-height: 1; animation: spinpop .9s ease-out; }
.win-titles { flex: 1 1 180px; min-width: 0; }
.win-titles h2 { font-size: 1.9em; color: var(--primary); margin: 0; }
.win-titles p { margin: 2px 0 0; color: var(--muted); }
.win-top .win-xp { font-size: 1.7em; white-space: nowrap; background: #fff; border-radius: 14px; padding: .1em .5em; box-shadow: 0 3px 0 rgba(0,0,0,.08); }
.win-top .win-xp-done { font-size: 1.1em; color: #2b8a3e; }
.win-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; margin-top: 14px; align-items: start; }
.win-summary { background: rgba(255,255,255,.85); border-radius: 16px; padding: 12px 16px; }
.win-summary h3 { font-size: 1.15em; margin: 0 0 6px; }
.win-summary ul { list-style: none; margin: 0; padding: 0; }
.win-summary li { position: relative; padding: 5px 0 5px 34px; animation: liIn .4s var(--d, 0s) both ease-out; }
.win-summary li::before { content: "✓"; position: absolute; left: 0; top: 5px; width: 24px; height: 24px; border-radius: 50%; background: #40c057; color: #fff; font-weight: 700; display: grid; place-items: center; font-size: .85em; }
@keyframes liIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
.win-side { display: flex; flex-direction: column; gap: 10px; }
.win-side .win-badges { justify-content: flex-start; margin: 0; }
.win-progress { background: rgba(255,255,255,.85); border-radius: 14px; padding: 8px 12px; }
.win-progress .bar span { background: var(--tc); }
.win-progress-label { font-size: .9em; }
.win-side .rank-up, .win-side .win-nudge { margin: 0; }
.win-actions-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
@media (max-width: 700px) {
  .win-grid { grid-template-columns: 1fr; }
  .win-top { flex-wrap: wrap; }
  .win-titles h2 { font-size: 1.5em; }
  .win-actions-row .btn { flex: 1 1 100%; }
}

/* ---------- learn window ---------- */
.btn-learn { background: #e7f5ff; color: #1864ab; border: 2px solid #74c0fc; box-shadow: 0 3px 0 #74c0fc; }
.modal.modal-learn { width: min(900px, 100%); padding: 0; display: flex; flex-direction: column; }
.learn { display: flex; flex-direction: column; max-height: 92vh; }
.learn-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 22px 24px 10px; border-bottom: 2px solid #f2ede3; }
.learn-top h2 { font-size: 1.9em; margin: 2px 0 2px; }
.learn-top p { margin: 0; }
.learn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; padding: 16px 24px; overflow: auto; }
.learn-card { background: #fffdf8; border: 2px solid var(--line); border-radius: 18px; padding: 14px 16px; animation: liIn .35s var(--d, 0s) both ease-out; }
.learn-head { display: flex; align-items: center; gap: 12px; }
.learn-head h3 { flex: 1; margin: 0; font-size: 1.2em; }
.learn-sym { font-family: var(--mono); font-weight: 700; font-size: 1.25em; background: #efeafe; color: #3a2fb8; border: 2px solid #d0c8ff; border-radius: 12px; padding: .1em .5em; white-space: nowrap; }
.learn-speak { width: 2em; height: 2em; font-size: 1.05em; flex: none; }
.learn-card p { margin: 10px 0; }
.learn-ex { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.learn-ex-label { display: block; font-size: .75em; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 3px; }
.learn-code, .learn-out { margin: 0; font-family: var(--mono); font-size: .88em; line-height: 1.5; white-space: pre; overflow-x: auto; border-radius: 10px; padding: 8px 10px; min-height: 0; }
.learn-code { background: #fff; border: 2px solid #2f3a4f; color: var(--ink); }
.learn-foot { padding: 12px 24px 20px; border-top: 2px solid #f2ede3; display: flex; justify-content: center; }
@media (max-width: 560px) {
  .learn-grid { grid-template-columns: 1fr; padding: 12px 14px; }
  .learn-top { padding: 16px 14px 8px; }
  .learn-ex { grid-template-columns: 1fr; }
}

/* ---------- unlock early (placement test) ---------- */
.btn-unlock { margin-top: 10px; flex-direction: row; background: #fff3bf; color: #664d03; border: 2px solid #ffd43b; box-shadow: 0 3px 0 #f2c200; }
.topic-card.locked .btn-unlock { filter: none; }
.place-intro { max-width: 760px; }
.place-card { background: #fff; border: 3px solid var(--tc); border-radius: 26px; padding: 26px 28px; box-shadow: 0 6px 0 var(--tc); text-align: center; position: relative; overflow: hidden; }
.place-card.win-panel { animation: winIn .55s cubic-bezier(.2, 1.5, .4, 1); }
.place-emoji { font-size: 4em; line-height: 1; }
.place-card h1 { font-size: 2.2em; color: var(--primary); margin: 8px 0 4px; }
.place-sub { font-size: 1.2em; margin: 0 0 12px; }
.place-topics { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 12px 0; }
.place-topics span, .place-topics a { background: #f3eee3; border-radius: 999px; padding: .2em .8em; font-weight: 700; font-size: .92em; text-decoration: none; color: var(--ink); }
.place-topics a { background: #e7f5ff; border: 2px solid #74c0fc; }
.place-rules { text-align: left; max-width: 520px; margin: 14px auto; padding: 0; list-style: none; }
.place-rules li { padding: 6px 0; }
.place-score { font-size: 1.4em; margin: 6px 0; }
.place-pill { display: inline-block; background: #fff3bf; color: #664d03; font-weight: 700; border-radius: 999px; padding: .15em .8em; margin-bottom: 8px; font-size: .9em; }
.pdots { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.pdots.big { justify-content: center; margin: 12px 0; }
.pdot { width: 16px; height: 16px; border-radius: 50%; background: #e9e4d8; border: 2px solid #d6d0c3; }
.pdots.big .pdot { width: 22px; height: 22px; }
.pdot.cur { background: #fff; border-color: var(--primary); box-shadow: 0 0 0 3px #e3e0ff; }
.pdot.ok { background: #40c057; border-color: #2b8a3e; }
.pdot.miss { background: #ffc9c9; border-color: #fa5252; }
.place-noguide { font-weight: 700; color: var(--muted); background: #f8f5ee; border-radius: 12px; padding: .4em .8em; }
.place-ok .win-top .win-emoji { font-size: 2.6em; }

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

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .level-view { grid-template-columns: 1fr; }
  .task-panel { position: static; max-height: none; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .auth { grid-template-columns: 1fr; gap: 20px; margin-top: 10px; }
  .hero-snake { font-size: 4em; }
  .auth-hero h1 { font-size: 2.3em; }
}
@media (max-width: 560px) {
  body { --code-size: 17px; --base-size: 16px; }
  .chip-rank { display: none; }
  .welcome h1 { font-size: 1.8em; }
  .stat-row { grid-template-columns: 1fr; }
  .brand-name { display: none; }
  .btn-run { width: 100%; }
}
