@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("../fonts/bricolage-grotesque-latin.woff2") format("woff2");
}
@font-face {
  font-family: "DM Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/dm-mono-500-latin.woff2") format("woff2");
}

:root {
  --paper: #F3F6FA;
  --grid: #DCE4EF;
  --grid-strong: #B9C6D8;
  --card: #FFFFFF;
  --ink: #16203A;
  --ink-soft: #5A6682;
  --blue: #2F5BFF;
  --blue-hover: #2449E6;
  --blue-tint: #E6ECFF;
  --sun: #FFC933;
  --sun-tint: #FFF4CC;
  --green: #12B76A;
  --green-ink: #0A8A4F;
  --green-tint: #E2F7EC;
  --red: #F0445A;
  --red-ink: #C62239;
  --red-tint: #FDE7EA;
  --pink: #FF6FB1;
  --display: "Bricolage Grotesque", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --mono: "DM Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { overscroll-behavior: none; height: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: var(--display);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- screens ---------- */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  margin-inline: auto;
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: calc(24px + var(--safe-b));
}
.screen.centered { justify-content: center; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  min-height: 40px;
}
.topbar .title { font-weight: 800; font-size: 1.1rem; letter-spacing: -.01em; text-align: center; flex: 1; }
.icon-btn {
  font: inherit; font-weight: 800; font-size: 1.1rem;
  width: 44px; height: 44px; border-radius: 14px;
  background: var(--card); color: var(--ink); border: 3px solid var(--ink);
  box-shadow: 0 4px 0 var(--ink); cursor: pointer; touch-action: manipulation;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

.panel {
  position: relative;
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 24px;
  padding: clamp(18px, 5vw, 32px);
  box-shadow: 8px 8px 0 var(--ink);
}
.panel + .panel { margin-top: 20px; }

h1 { margin: 0; font-size: clamp(2.4rem, 11vw, 3.8rem); font-weight: 800; line-height: .95; letter-spacing: -.035em; text-wrap: balance; }
h2 { margin: 0 0 8px; font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
h3 { margin: 0; font-size: 1.1rem; font-weight: 800; }
.hl { background: linear-gradient(transparent 58%, var(--sun) 58%, var(--sun) 92%, transparent 92%); padding-inline: .06em; }
.lead { margin: 10px 0 0; font-size: 1.25rem; font-weight: 600; }
.meta { margin: 0; font-family: var(--mono); font-size: .8rem; color: var(--ink-soft); letter-spacing: .04em; }
.eyebrow { margin: 0; font-family: var(--mono); font-size: .74rem; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-soft); }

.sticker {
  position: absolute; top: -24px; right: -10px; width: 88px; height: 88px; border-radius: 50%;
  background: var(--sun); border: 3px solid var(--ink); display: grid; place-content: center; text-align: center; transform: rotate(10deg);
}
.sticker .count { font-family: var(--mono); font-size: 1.8rem; line-height: 1; }
.sticker .label { font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; margin-top: 2px; }
.sticker.pop { animation: sticker-pop .7s cubic-bezier(.3, 1.6, .5, 1); }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 800; font-size: 1.25rem; letter-spacing: -.01em; color: #fff;
  background: var(--blue); border: 3px solid var(--ink); border-radius: 18px; padding: 14px 24px;
  box-shadow: 0 6px 0 var(--ink); cursor: pointer; touch-action: manipulation; width: 100%;
  transition: transform .08s ease-out, box-shadow .08s ease-out;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn:hover { background: var(--blue-hover); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.btn:focus-visible { outline: 4px solid var(--sun); outline-offset: 3px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--card); color: var(--ink); }
.btn.green { background: var(--green); }
.btn.sun { background: var(--sun); color: var(--ink); }
.btn.small { font-size: 1rem; padding: 10px 16px; box-shadow: 0 4px 0 var(--ink); border-radius: 14px; }
.actions { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }

/* ---------- Mo ---------- */
.mo { display: flex; gap: 14px; align-items: flex-start; margin-top: 22px; }
.mo .face { font-size: 2.2rem; line-height: 1; flex: none; width: 56px; height: 56px; border-radius: 50%; background: var(--sun-tint); border: 3px solid var(--ink); display: grid; place-items: center; }
.mo .bubble { flex: 1; background: var(--paper); border: 2px dashed var(--grid-strong); border-radius: 16px; padding: 12px 14px; font-weight: 600; font-size: 1.05rem; line-height: 1.35; }
.mo .bubble .btn { margin-top: 10px; }

/* ---------- lists (subjects, topics, journey) ---------- */
.cards { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.card-btn {
  font: inherit; text-align: left; width: 100%; display: flex; align-items: center; gap: 14px;
  background: var(--card); color: var(--ink); border: 3px solid var(--ink); border-radius: 20px; padding: 16px 18px;
  box-shadow: 6px 6px 0 var(--ink); cursor: pointer; touch-action: manipulation;
}
.card-btn:active { transform: translate(3px, 3px); box-shadow: 3px 3px 0 var(--ink); }
.card-btn .emoji { font-size: 2rem; line-height: 1; }
.card-btn .text { flex: 1; }
.card-btn .text strong { display: block; font-size: 1.2rem; font-weight: 800; letter-spacing: -.01em; }
.card-btn .text span { color: var(--ink-soft); font-size: .9rem; font-weight: 600; }
.card-btn .arrow { font-size: 1.4rem; font-weight: 800; }
.bar { display: block; height: 10px; border-radius: 999px; background: var(--paper); border: 2px solid var(--ink); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--blue); }

.chapter { margin-top: 22px; }
.chapter h3 { font-family: var(--mono); font-size: .78rem; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-soft); margin-bottom: 10px; }
.journey { display: flex; flex-direction: column; gap: 10px; position: relative; padding-left: 26px; }
.journey::before { content: ""; position: absolute; left: 9px; top: 12px; bottom: 12px; border-left: 4px dotted var(--grid-strong); }
.station {
  font: inherit; text-align: left; width: 100%; display: flex; align-items: center; gap: 12px; position: relative;
  background: var(--card); color: var(--ink); border: 3px solid var(--ink); border-radius: 16px; padding: 12px 14px;
  box-shadow: 4px 4px 0 var(--ink); cursor: pointer; touch-action: manipulation;
}
.station::before {
  content: ""; position: absolute; left: -26px; top: 50%; width: 16px; height: 16px; border-radius: 50%; transform: translate(0, -50%);
  background: var(--card); border: 3px solid var(--ink);
}
.station.passed::before { background: var(--green); }
.station.next::before { background: var(--sun); animation: pulse 1.4s ease-in-out infinite; }
.station.locked { opacity: .45; box-shadow: none; cursor: default; }
.station .kind { font-family: var(--mono); font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-soft); }
.station .name { font-weight: 800; font-size: 1.05rem; }
.station .text { flex: 1; }
.station .stars { font-size: 1rem; letter-spacing: .05em; color: var(--sun); -webkit-text-stroke: 1px var(--ink); }
.station.learn .kind::before { content: "📖 "; }
.station.practice .kind::before { content: "✏️ "; }
.station.test .kind::before { content: "🏁 "; }

/* ---------- task screen: three zones ---------- */
.task-screen { padding-bottom: 0; height: 100dvh; min-height: 0; overflow: hidden; }
.task-screen .zone-top { flex: 1 1 auto; min-height: 90px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.task-screen .zone-task { flex: none; padding-block: 10px 6px; }
.task-screen .zone-keys { flex: none; padding-bottom: calc(10px + var(--safe-b)); }

.progress { margin-bottom: 10px; }
.progress-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; font-family: var(--mono); font-size: .82rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.progress-top strong { color: var(--ink); font-weight: 500; }
.segments { list-style: none; margin: 0; padding: 0; display: flex; gap: 5px; }
.seg { flex: 1; height: 14px; border-radius: 999px; background: var(--card); border: 2.5px solid var(--ink); }
.seg.done { background: var(--blue); }
.seg.wrong { background: var(--red); }
.seg.current { background: var(--sun); animation: pulse 1.4s ease-in-out infinite; }
.seg.just { animation: seg-pop .5s cubic-bezier(.3, 1.8, .5, 1); }

.hint-box {
  background: var(--sun-tint); border: 3px solid var(--ink); border-radius: 18px; padding: 12px 14px; font-weight: 700; font-size: 1.05rem; line-height: 1.35;
  box-shadow: 4px 4px 0 var(--ink); margin-bottom: 10px;
}
.hint-box.good { background: var(--green-tint); }
.hint-box.bad { background: var(--red-tint); }
.hint-box.neutral { background: var(--card); }

.card-task { border-radius: 22px; padding: 16px 18px; transition: background-color .2s, border-color .2s, box-shadow .2s; }
.card-task .ask { margin: 0 0 8px; }
.line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; font-size: clamp(1.35rem, 6vw, 1.9rem); font-weight: 700; line-height: 1.25; letter-spacing: -.01em; }
.line .txt { overflow-wrap: anywhere; }
.line .txt.long { font-size: 1.15rem; font-weight: 600; width: 100%; }
.line.enter { animation: word-in .4s cubic-bezier(.2, 1.2, .4, 1); }
.blank {
  -webkit-user-select: none; user-select: none; font-family: var(--mono); font-size: 1.1em; min-width: 3.2ch; padding: 4px 10px; text-align: center;
  color: var(--ink); background: var(--paper); border: 3px solid var(--ink); border-radius: 12px; cursor: pointer; line-height: 1.3; font-variant-numeric: tabular-nums;
}
.blank:empty::before { content: "?"; color: var(--grid-strong); }
.blank.active { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(47, 91, 255, .18); background: #fff; }
.blank.active::after { content: ""; display: inline-block; width: 2px; height: 1em; background: var(--blue); vertical-align: -.15em; margin-left: 2px; animation: blink 1s steps(2) infinite; }
.card-task.is-correct { background: var(--green-tint); border-color: var(--green-ink); box-shadow: 8px 8px 0 var(--green-ink); animation: pop .45s cubic-bezier(.3, 1.6, .5, 1); }
.card-task.is-correct .blank { border-color: var(--green-ink); color: var(--green-ink); }
.card-task.is-wrong { background: var(--red-tint); border-color: var(--red-ink); box-shadow: 8px 8px 0 var(--red-ink); animation: shake .45s; }
.card-task.nudge { animation: nudge .3s; }
.feedback { margin: 10px 0 0; min-height: 1.4em; font-size: 1.05rem; font-weight: 700; line-height: 1.3; }
.feedback.good { color: var(--green-ink); }
.feedback.bad { color: var(--red-ink); }
.feedback.hint { color: var(--ink-soft); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key {
  font: inherit; font-family: var(--mono); font-size: 1.6rem; font-weight: 500; color: var(--ink);
  background: var(--card); border: 3px solid var(--ink); border-radius: 14px; padding: 10px 0; min-height: 54px;
  box-shadow: 0 4px 0 var(--ink); cursor: pointer; touch-action: manipulation; transition: transform .06s, box-shadow .06s;
}
.key:active, .key.down { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.key.ok { background: var(--blue); color: #fff; font-family: var(--display); font-weight: 800; font-size: 1.3rem; }
.key.del { font-size: 1.3rem; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 10px; }
.choice { font: inherit; font-family: var(--mono); font-size: 1.6rem; color: var(--ink); background: var(--card); border: 3px solid var(--ink); border-radius: 16px; padding: 14px 0; box-shadow: 0 5px 0 var(--ink); cursor: pointer; touch-action: manipulation; }
.choice:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.choice.picked { background: var(--sun); }
.choice.right { background: var(--green-tint); border-color: var(--green-ink); }
.choice.wrong { background: var(--red-tint); border-color: var(--red-ink); }
.continue { margin-top: 0; }

/* ---------- steps ---------- */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.steps li { background: var(--card); border: 3px solid var(--ink); border-radius: 14px; padding: 10px 14px; font-size: 1.15rem; font-weight: 700; animation: word-in .35s; }
.steps li .eq { font-family: var(--mono); font-size: 1.15rem; font-weight: 500; }
.steps li .say { display: block; font-size: .95rem; font-weight: 600; color: var(--ink-soft); margin-top: 4px; }
.steps li.final { background: var(--green-tint); border-color: var(--green-ink); }

/* ---------- viz ---------- */
.viz { background: var(--card); border: 3px solid var(--ink); border-radius: 18px; padding: 12px; margin-bottom: 10px; box-shadow: 4px 4px 0 var(--ink); }
.viz-caption { margin: 8px 0 0; font-family: var(--mono); font-size: .85rem; color: var(--ink-soft); text-align: center; }
.viz-table { overflow-x: auto; }
.viz table { border-collapse: separate; border-spacing: 4px; margin-inline: auto; font-family: var(--mono); font-size: 1.25rem; }
.viz th { font-family: var(--display); font-weight: 700; font-size: .78rem; color: var(--ink-soft); padding: 0 2px; }
.viz th.unit { font-size: .95rem; color: var(--ink); background: var(--blue-tint); border-radius: 8px; padding: 2px 6px; }
.viz td { width: 2.1rem; height: 2.3rem; text-align: center; border: 2.5px solid var(--ink); border-radius: 8px; background: var(--paper); }
.viz tr.result td { background: var(--green-tint); border-color: var(--green-ink); color: var(--green-ink); }
.viz tr.read td { background: var(--sun-tint); }
.viz td.zero { background: var(--sun-tint); color: var(--red-ink); font-weight: 700; }
.viz td .gap { color: var(--red-ink); }
.stairs { width: 100%; height: auto; display: block; }
.stairs .step { fill: var(--paper); stroke: var(--ink); stroke-width: 2.5; }
.stairs .step.on { fill: var(--blue-tint); }
.stairs .step.from { fill: var(--sun); }
.stairs .step.to { fill: var(--green-tint); stroke: var(--green-ink); }
.stairs .step-label { font: 700 15px var(--display); fill: var(--ink); text-anchor: middle; }
.stairs .factor { font: 500 12px var(--mono); fill: var(--ink-soft); text-anchor: middle; }
.stairs .factor.on { fill: var(--blue); font-weight: 700; }
.stairs .dir { font: 700 13px var(--display); fill: var(--ink); }
.sense { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sense-item { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; font-size: .72rem; padding: 8px 4px; border-radius: 12px; border: 2px solid transparent; }
.sense-item .icon { font-size: 1.7rem; }
.sense-item.on { background: var(--sun-tint); border-color: var(--ink); }
.hb-row { display: flex; flex-wrap: wrap; gap: 6px; }
.hb { height: 44px; width: 72px; border: 3px solid var(--ink); border-radius: 10px; display: grid; place-items: center; font-family: var(--mono); font-weight: 500; background: var(--blue-tint); position: relative; overflow: hidden; }
.hb.full { background: var(--blue); color: #fff; }
.hb.rest { background: var(--card); }
.hb.rest::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: var(--w); background: var(--sun); }
.hb span { position: relative; }
.twenty .field, .dot-field { display: grid; gap: 6px; justify-content: center; }
.twenty .field { grid-template-columns: repeat(10, 22px); }
.twenty .field .dot:nth-child(5n) { margin-right: 8px; }
.dot { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--ink); background: var(--card); display: inline-block; }
.dot.a { background: var(--blue); }
.dot.b { background: var(--sun); }
.dot.r { background: var(--pink); }
.dots .dot-field { gap: 4px; }
.dot-row { display: flex; gap: 4px; justify-content: center; }
.dots .dot { width: 18px; height: 18px; }
.dot-row.rest { margin-top: 6px; }
.nline { width: 100%; height: auto; display: block; }
.nline .axis { stroke: var(--ink); stroke-width: 3; }
.nline .tick { stroke: var(--ink); stroke-width: 2.5; }
.nline .tick-label { font: 500 12px var(--mono); fill: var(--ink); text-anchor: middle; }
.nline .jump { fill: none; stroke: var(--blue); stroke-width: 3; }
.nline .jump.neg { stroke: var(--red); }
.nline .jump-label { font: 700 13px var(--display); fill: var(--ink); text-anchor: middle; }

/* ---------- learn cards ---------- */
.learn-card .title { font-size: 1.5rem; font-weight: 800; margin: 0 0 8px; letter-spacing: -.02em; }
.learn-card p.text { margin: 0; font-size: 1.15rem; font-weight: 600; line-height: 1.4; }
.dots-nav { display: flex; gap: 6px; justify-content: center; margin: 14px 0; }
.dots-nav i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); background: var(--card); }
.dots-nav i.on { background: var(--sun); }
.dots-nav i.done { background: var(--blue); }

/* ---------- results ---------- */
.result-stars { font-size: 3rem; letter-spacing: .1em; margin: 10px 0; color: var(--sun); -webkit-text-stroke: 1.5px var(--ink); }
.result-stars .off { color: var(--card); }
.done-banner { margin: 14px 0 0; display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--green-tint); border: 2px solid var(--green-ink); border-radius: 999px; color: var(--green-ink); font-weight: 700; }
.done-banner.soft { background: var(--sun-tint); border-color: var(--ink); color: var(--ink); }
.review-list { margin: 14px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.review-list li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; border-radius: 12px; border: 2px solid var(--ink); font-family: var(--mono); font-size: .95rem; }
.review-list li.ok { background: var(--green-tint); }
.review-list li.bad { background: var(--red-tint); }

/* ---------- papa ---------- */
.papa table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.papa th, .papa td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.papa td.num { font-family: var(--mono); text-align: right; }
.papa .weak { color: var(--red-ink); font-weight: 700; }
.papa details { margin-top: 6px; }
.papa textarea { width: 100%; height: 160px; font-family: var(--mono); font-size: .75rem; -webkit-user-select: text; user-select: text; }

.flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(240, 68, 90, .45) 100%); z-index: 40; }
.flash.on { animation: flash .7s ease-out; }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

@keyframes pulse { 50% { transform: scaleY(1.25); } }
@keyframes blink { to { opacity: 0; } }
@keyframes seg-pop { 50% { transform: scale(1.35); } }
@keyframes pop { 40% { transform: scale(1.02) rotate(-.4deg); } }
@keyframes shake { 15% { transform: translateX(-12px) rotate(-1deg); } 35% { transform: translateX(10px) rotate(1deg); } 55% { transform: translateX(-7px); } 75% { transform: translateX(4px); } }
@keyframes nudge { 30% { transform: translateX(-5px); } 70% { transform: translateX(5px); } }
@keyframes flash { 20% { opacity: 1; } 100% { opacity: 0; } }
@keyframes word-in { from { opacity: .2; transform: translateY(10px); } }
@keyframes sticker-pop { 40% { transform: rotate(-12deg) scale(1.25); } 100% { transform: rotate(10deg) scale(1); } }

@media (max-height: 600px) {
  .key { min-height: 44px; padding: 6px 0; font-size: 1.35rem; }
  .task-screen .zone-top { min-height: 60px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
