/* ===== Токены =====================================================
   Идея: тетрадь гэнко-ёси (клетки для письма), индиго 藍 и киноварь 朱 печати ханко.
   Поверхности разделяются тоном, а не линиями. */
:root {
  --paper: #F3F4F0;
  --side: #EAECE6;
  --card: #FFFFFF;
  --sunk: #ECEEE9;
  --ink: #15171C;
  --ink-2: #4A4F58;
  --ink-3: #646973;
  --line: #DADDD5;
  --guide: #E5B9B3;       /* пунктир клетки прописи */
  --ai: #2B4CA3;          /* индиго — ссылки, акцент */
  --ai-fill: #2B4CA3;     /* заливка главной кнопки */
  --ai-ink: #FFFFFF;
  --ai-soft: #E3E9F7;
  --shu: #D0392B;         /* киноварь — печати и ошибки */
  --shu-soft: #F8E3E0;
  --matcha: #3C7A3A;
  --matcha-soft: #E2EEDD;
  --heat-1: #9DB0E4; --heat-2: #8FA6DF; --heat-3: #2B4CA3;

  --font-ui: "Onest", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-jp: "Noto Serif JP", "Yu Mincho", YuMincho, "Hiragino Mincho ProN", serif;
  --font-jp-sans: "Yu Gothic UI", "Yu Gothic", YuGothic, "Hiragino Sans", "Noto Sans JP", "Noto Sans CJK JP", sans-serif;

  --r: 14px;
  --r-s: 10px;
  --side-w: 236px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0F1115; --side: #13161B; --card: #181B21; --sunk: #1F232A;
    --ink: #ECEDEF; --ink-2: #A9AEB7; --ink-3: #8A909A; --line: #282D35; --guide: #5A3430;
    --ai: #8DA8F2; --ai-fill: #3F63CC; --ai-ink: #FFFFFF; --ai-soft: #1C2644;
    --shu: #E5584A; --shu-soft: #3A201D; --matcha: #86BE78; --matcha-soft: #1D2B1C;
    --heat-1: #22305A; --heat-2: #3450A0; --heat-3: #7F9EF0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0F1115; --side: #13161B; --card: #181B21; --sunk: #1F232A;
  --ink: #ECEDEF; --ink-2: #A9AEB7; --ink-3: #8A909A; --line: #282D35; --guide: #5A3430;
  --ai: #8DA8F2; --ai-fill: #3F63CC; --ai-ink: #FFFFFF; --ai-soft: #1C2644;
  --shu: #E5584A; --shu-soft: #3A201D; --matcha: #86BE78; --matcha-soft: #1D2B1C;
  --heat-1: #22305A; --heat-2: #3450A0; --heat-3: #7F9EF0;
  color-scheme: dark;
}

/* ===== База ======================================================= */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 84px; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.55 var(--font-ui); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[lang="ja"], .jp { font-family: var(--font-jp-sans); }
a { color: var(--ai); text-underline-offset: 3px; }
button, input, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--ai); outline-offset: 2px; border-radius: 6px; }
main:focus, main:focus-visible { outline: none; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; text-wrap: balance; }
h1 { font-size: clamp(1.7rem, 1.2rem + 1.6vw, 2.5rem); font-weight: 650; letter-spacing: -.025em; }
h2 { font-size: 1.4rem; font-weight: 650; letter-spacing: -.015em; }
h3 { font-size: 1.1rem; font-weight: 600; letter-spacing: -.005em; }
h4 { font-size: 1rem; font-weight: 600; margin-top: 1.4em; }
p { margin: 0 0 .8em; }
small { color: var(--ink-2); }
ruby rt { font-size: .55em; color: var(--ink-2); }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
::selection { background: var(--ai-soft); }

/* ===== Каркас ===================================================== */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; padding: 28px 16px 20px;
  background: var(--side); display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: flex-end; gap: 12px; text-decoration: none; color: var(--ink); margin: 0 10px 32px; }
.brand-jp { font-family: var(--font-jp); font-weight: 500; font-size: 2.1rem; writing-mode: vertical-rl; line-height: 1; letter-spacing: .06em; }
.brand-ru { color: var(--ink-2); font-size: .92rem; line-height: 1.3; }
.brand-ru b { display: block; color: var(--ink); font-weight: 600; font-size: 1rem; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
  transition: background-color .15s, color .15s;
}
.nav-link:hover { background: var(--sunk); color: var(--ink); }
.nav-link.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .06); }
.nav-link.on .nav-ico { color: var(--shu); }
.nav-ico { font-family: var(--font-jp); font-size: 1.2rem; width: 1.4em; text-align: center; transition: color .15s; }
.badge { margin-left: auto; background: var(--shu); color: #fff; font-size: .74rem; border-radius: 99px; padding: 1px 8px; font-weight: 600; font-variant-numeric: tabular-nums; }
.side-foot { margin-top: auto; padding: 0 4px; }
.theme-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; border-radius: 12px;
  background: transparent; color: var(--ink-2); cursor: pointer; font-size: .9rem; text-align: left;
}
.theme-btn:hover { background: var(--sunk); color: var(--ink); }
.theme-btn svg { width: 18px; height: 18px; flex: none; }

main { padding: 44px 56px 120px; min-width: 0; }
.page { max-width: 820px; margin: 0 auto; }
.page.wide { max-width: 1120px; }

/* Планшет: меню сжимается в узкую полосу, как нижнее меню телефона */
@media (min-width: 761px) and (max-width: 1100px) {
  .shell { grid-template-columns: 84px 1fr; }
  .side { padding: 22px 8px 16px; align-items: stretch; }
  .brand { margin: 0 auto 22px; justify-content: center; }
  .brand-ru { display: none; }
  .brand-jp { font-size: 1.7rem; }
  .nav-link { flex-direction: column; gap: 2px; padding: 9px 4px; font-size: .72rem; text-align: center; position: relative; }
  .nav-ico { font-size: 1.3rem; width: auto; }
  .badge { position: absolute; top: 2px; right: 6px; margin: 0; padding: 0 6px; }
  .theme-btn { justify-content: center; padding: 10px 4px; }
  .theme-btn span { display: none; }
  main { padding: 36px 32px 110px; }
}

@media (max-width: 760px) {
  html { scroll-padding-top: 72px; }
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; z-index: 20; top: auto; bottom: 0; left: 0; right: 0; height: auto;
    flex-direction: row; gap: 2px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--side) 94%, transparent); justify-content: space-around;
    box-shadow: 0 -1px 0 var(--line);
  }
  .brand, .side-foot { display: none; }
  .nav-link { flex-direction: column; gap: 1px; font-size: .72rem; padding: 6px 4px; position: relative; flex: 1; border-radius: 10px; }
  .nav-link.on { box-shadow: none; background: transparent; color: var(--ai); }
  .nav-ico { font-size: 1.3rem; }
  .badge { position: absolute; top: 0; right: calc(50% - 26px); margin: 0; padding: 0 6px; }
  main { padding: 22px 16px 110px; }
}

/* ===== Кнопки ===================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 9px 20px; border-radius: 99px; border: 0;
  background: var(--sunk); color: var(--ink); cursor: pointer; text-decoration: none; font-weight: 550;
  transition: background-color .15s, transform .12s var(--ease), filter .15s; white-space: nowrap;
}
.btn:hover { background: color-mix(in srgb, var(--sunk) 80%, var(--ink) 8%); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--ai-fill); color: var(--ai-ink); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; color: var(--ai); padding-left: 10px; padding-right: 10px; }
.btn.ghost:hover { background: var(--ai-soft); }
.btn.small { min-height: 34px; padding: 5px 14px; font-size: .9rem; }
.btn.big { min-height: 50px; padding: 12px 26px; font-size: 1.05rem; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.bar { height: 6px; background: var(--sunk); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ai-fill); border-radius: 99px; transition: width .4s var(--ease); }

/* ===== Клетка гэнко-ёси ========================================== */
.cell {
  --s: 56px;
  position: relative; width: var(--s); height: var(--s); flex: none; display: grid; place-items: center;
  border-radius: 6px; background-color: var(--card);
  background-image:
    repeating-linear-gradient(to bottom, var(--guide) 0 4px, transparent 4px 8px),
    repeating-linear-gradient(to right, var(--guide) 0 4px, transparent 4px 8px);
  background-size: 1px 100%, 100% 1px; background-position: center, center; background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1.5px var(--line);
  font-family: var(--font-jp); font-weight: 500; font-size: 1.1rem; color: var(--ink);
}
.cell span { position: relative; background: var(--card); padding: 0 3px; line-height: 1.1; border-radius: 3px; font-variant-numeric: tabular-nums; }
.cell.next { box-shadow: inset 0 0 0 2px var(--ai); }
.cell.planned { background-color: transparent; background-image: none; color: var(--ink-3); box-shadow: inset 0 0 0 1.5px var(--line); }
.cell.planned span { background: transparent; }

/* Печать ханко */
/* печать сидит на правом верхнем углу клетки и не закрывает номер */
.hanko {
  position: absolute; right: -9px; top: -9px; width: 30px; height: 30px; border-radius: 7px;
  background: var(--shu); color: #fff; display: grid; place-items: center; font-style: normal;
  font-family: var(--font-jp); font-size: 1.05rem; transform: rotate(-9deg);
  box-shadow: inset 0 0 0 2px rgb(255 255 255 / .35);
}
.hanko.big { position: static; width: 84px; height: 84px; font-size: 2.6rem; border-radius: 14px; flex: none; }
.hanko.stamp { animation: stamp .45s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes stamp { 0% { transform: rotate(-20deg) scale(1.8); opacity: 0; } 100% { transform: rotate(-9deg) scale(1); opacity: 1; } }
.hanko-inline { display: inline-grid; place-items: center; width: 1.5em; height: 1.5em; background: var(--shu); color: #fff; border-radius: 4px; font-family: var(--font-jp); transform: rotate(-8deg); font-size: .9em; }

/* ===== Главная ==================================================== */
.hello { color: var(--ink-2); margin-bottom: 14px; }
.hero { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; margin-bottom: 64px; align-items: start; }
.next-card {
  display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: start;
  padding: 30px; border-radius: var(--r); background: var(--card); color: inherit; text-decoration: none;
  transition: transform .2s var(--ease), box-shadow .2s;
}
.next-card:hover { box-shadow: 0 0 0 2px var(--ai); }
.next-card .cell { --s: 104px; font-size: 2rem; }
.next-card .cell .hanko { width: 44px; height: 44px; font-size: 1.4rem; }
.next-card .kicker { color: var(--ai); font-weight: 600; font-size: .95rem; margin-bottom: 6px; }
.next-card h1 { font-size: clamp(1.6rem, 1.1rem + 1.4vw, 2.3rem); margin-bottom: .3em; }
.next-card p { color: var(--ink-2); max-width: 52ch; }
.next-card .bar { margin: 18px 0 8px; max-width: 360px; }
.next-card .bar-meta { font-size: .88rem; color: var(--ink-3); margin-bottom: 18px; }
/* шаги урока сегментами: сделано / текущий / впереди */
.segs { display: flex; gap: 4px; margin: 18px 0 8px; max-width: 420px; }
.segs i { flex: 1; height: 6px; border-radius: 99px; background: var(--sunk); }
.segs i.d { background: var(--matcha); }
.segs i.c { background: var(--ai-fill); }
.next-step { font-size: .92rem; color: var(--ink-2); margin-bottom: 18px; }
.next-step b { color: var(--ink); font-weight: 600; }
.next-card .btn { pointer-events: none; }

.side-panels { display: grid; gap: 16px; align-content: start; }
.panel { padding: 22px; border-radius: var(--r); background: var(--card); }
.panel h3 { font-size: .95rem; color: var(--ink-2); font-weight: 550; margin-bottom: 4px; }
.big-num { font-size: 2.6rem; font-weight: 650; line-height: 1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; margin: 6px 0 4px; }
.big-num.due { color: var(--shu); }
.big-num.zero { color: var(--ink-3); }
.panel .btn { margin-top: 12px; width: 100%; }
.heat { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; margin-top: 12px; }
.heat i { aspect-ratio: 1; border-radius: 4px; background: var(--sunk); }
.heat i.l1 { background: var(--heat-1); } .heat i.l2 { background: var(--heat-2); } .heat i.l3 { background: var(--heat-3); }
.heat i.today { box-shadow: 0 0 0 1.5px var(--ink-3); }
.heat-meta { display: flex; justify-content: space-between; font-size: .78rem; color: var(--ink-3); margin-top: 6px; }

@media (max-width: 1080px) {
  .hero { grid-template-columns: 1fr; }
  .side-panels { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .next-card { grid-template-columns: 1fr; padding: 22px; gap: 18px; }
  .next-card .cell { --s: 76px; font-size: 1.5rem; }
  .side-panels { grid-template-columns: 1fr 1fr; gap: 10px; }
  .panel { padding: 16px; }
  .big-num { font-size: 2rem; }
  .hero { margin-bottom: 48px; }
}

.stage { margin-bottom: 72px; }
.stage-head { display: grid; grid-template-columns: 1fr auto; gap: 6px 24px; align-items: end; margin-bottom: 20px; }
.stage-head h2 { margin: 0; }
.stage-head p { margin: 0; color: var(--ink-2); grid-column: 1; }
.stage-prog { grid-row: 1 / span 2; grid-column: 2; text-align: right; min-width: 140px; }
.stage-prog b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stage-prog span { color: var(--ink-3); font-size: .9rem; }
.stage-prog .bar { margin-top: 8px; height: 5px; }

/* Карта этапа: лист гэнко-ёси, клетка = урок */
.genko { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; margin-bottom: 22px; }
.genko .cell { --s: auto; width: auto; aspect-ratio: 1; font-size: 1rem; text-decoration: none; transition: transform .15s var(--ease), box-shadow .15s; }
.genko a.cell:hover { transform: translateY(-2px); box-shadow: inset 0 0 0 2px var(--ai); }
.genko .cell .hanko { width: 20px; height: 20px; font-size: .72rem; right: -5px; top: -5px; border-radius: 5px; }
.lrow .cell .hanko { width: 22px; height: 22px; font-size: .78rem; right: -7px; top: -7px; border-radius: 5px; }

.lessons { display: grid; gap: 8px; }
.lrow {
  display: grid; grid-template-columns: auto 1fr auto; gap: 20px; align-items: center;
  padding: 14px 18px 14px 14px; border-radius: var(--r); background: var(--card); color: inherit; text-decoration: none;
  transition: box-shadow .15s, transform .15s var(--ease);
}
a.lrow:hover { box-shadow: 0 0 0 2px var(--ai); }
a.lrow:active { transform: scale(.995); }
.lrow.is-done { background: transparent; }
.lrow.is-done .ltitle { color: var(--ink-2); }
.ltitle { font-weight: 600; font-size: 1.04rem; }
.ltitle .jp { font-weight: 400; color: var(--ink-2); margin-left: 8px; }
.lsum { font-size: .92rem; color: var(--ink-2); margin: 2px 0 0; }
.lmeta { font-size: .86rem; color: var(--ink-3); white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.lmeta .bar { width: 72px; height: 4px; margin: 6px 0 0 auto; }
.lmeta .ok { color: var(--matcha); font-weight: 600; }
.more-soon { color: var(--ink-3); font-size: .92rem; margin: 14px 4px 0; }
@media (max-width: 560px) {
  .lrow { grid-template-columns: auto 1fr; gap: 14px; padding: 12px; }
  .lmeta { grid-column: 2; text-align: left; }
  .lmeta .bar { margin-left: 0; }
  .stage-head { grid-template-columns: 1fr; }
  .stage-prog { grid-row: auto; grid-column: 1; text-align: left; }
  .genko { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
}
.foot-note { color: var(--ink-3); font-size: .88rem; padding: 20px; border-radius: var(--r); background: var(--sunk); }
.foot-note b { color: var(--ink); font-weight: 600; user-select: all; }

/* ===== Урок ======================================================= */
.crumb { font-size: .92rem; margin-bottom: 20px; }
.crumb a { color: var(--ink-2); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.crumb a:hover { color: var(--ai); }
.lesson-head { display: grid; grid-template-columns: auto 1fr; gap: 26px; align-items: center; margin-bottom: 28px; }
.lesson-head .cell { --s: 96px; font-size: 1.9rem; }
.lesson-head .hanko { width: 42px; height: 42px; font-size: 1.35rem; }
.lesson-head h1 { margin-bottom: .15em; }
.lesson-head .jp-title { font-family: var(--font-jp); font-size: 1.2rem; color: var(--ink-2); margin-bottom: .4em; }
.lesson-head p { margin: 0; color: var(--ink-2); max-width: 60ch; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: .9rem; color: var(--ink-3); }
@media (max-width: 560px) { .lesson-head { gap: 16px; } .lesson-head .cell { --s: 68px; font-size: 1.4rem; } }

.lprog {
  position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 16px;
  margin: 0 -16px 24px; padding: 12px 16px; background: color-mix(in srgb, var(--paper) 92%, transparent);
}
.lprog .bar { flex: 1; }
.lprog .lbl { font-size: .9rem; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.lprog .lbl b { color: var(--ink); }

.goals { margin: 0 0 32px; padding: 20px 24px; background: var(--ai-soft); border-radius: var(--r); }
.goals h3, .goals h2 { font-size: 1rem; margin-bottom: .5em; letter-spacing: 0; }
.goals ul { margin: 0; padding-left: 1.2em; }
.goals li + li { margin-top: 4px; }

.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.step { background: var(--card); border-radius: var(--r); padding: 18px 22px 20px; scroll-margin-top: 80px; transition: background-color .2s, box-shadow .3s; }
.step.flash-in { box-shadow: 0 0 0 2px var(--ai); }
.step-head { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; }
.step-num {
  width: 36px; height: 36px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  background: var(--sunk); display: grid; place-items: center;
  font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink-2);
  transition: background-color .15s, color .15s, transform .12s var(--ease);
}
.step-num:hover { box-shadow: inset 0 0 0 2px var(--ai); }
.step-num:active { transform: scale(.92); }
.step-num svg { width: 18px; height: 18px; display: none; }
.step.done .step-num { background: var(--matcha); color: #fff; }
.step.done .step-num span { display: none; }
.step.done .step-num svg { display: block; }
.step-h { margin: 0; min-width: 0; font-size: 1.1rem; }
.step-title { background: none; border: 0; padding: 4px 0; text-align: left; cursor: pointer; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; width: 100%; font-weight: 600; }
.step.future .step-h { color: var(--ink-2); font-weight: 550; }
.step.future.collapsed { padding-top: 12px; padding-bottom: 12px; }
.kind { font-size: .8rem; color: var(--ink-3); white-space: nowrap; background: var(--sunk); border-radius: 99px; padding: 2px 10px; }
.chev { width: 20px; height: 20px; color: var(--ink-3); transition: transform .2s var(--ease); }
.step.collapsed .chev { transform: rotate(-90deg); }
.step-content { padding: 14px 0 0 50px; }
.step.collapsed .step-content { display: none; }
.step.done.collapsed { background: transparent; padding-top: 10px; padding-bottom: 10px; }
.step.done.collapsed .step-h { color: var(--ink-2); }
.step.done.collapsed .step-title { font-weight: 550; }
.step-body { max-width: 68ch; }
.step-body ul, .step-body ol { padding-left: 1.3em; margin: 0 0 .8em; }
.step-body li { margin-bottom: .3em; }
.step-foot { margin-top: 16px; }
.note { padding: 10px 14px; margin: 10px 0 14px; background: var(--ai-soft); border-radius: var(--r-s); font-size: .95rem; }
.jp-example {
  font-family: var(--font-jp-sans); font-size: 1.15rem; line-height: 1.8;
  padding: 12px 18px; background: var(--sunk); border-radius: var(--r-s); margin: 6px 0 10px;
}
.jp-example small { font-family: var(--font-ui); font-size: .86rem; }
@media (max-width: 560px) {
  .step { padding: 14px 14px 16px; }
  .step-head { gap: 10px; }
  .step-content { padding-left: 0; }
  .kind { display: none; }
}

.refs { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.ref-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  padding: 10px 14px; border: 0; border-radius: var(--r-s); background: var(--sunk);
  transition: box-shadow .15s;
}
.ref-btn:hover { box-shadow: inset 0 0 0 2px var(--ai); }
.ref-btn svg { width: 20px; height: 20px; color: var(--ai); flex: none; }
.ref-btn .bk { font-weight: 600; white-space: nowrap; }
.ref-btn .nt { color: var(--ink-2); min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-btn .pg { color: var(--ink-3); font-variant-numeric: tabular-nums; margin-left: auto; white-space: nowrap; font-size: .9rem; }
.ref-btn[aria-expanded="true"] { border-bottom-left-radius: 0; border-bottom-right-radius: 0; box-shadow: inset 0 0 0 2px var(--ai); }
.ref-preview { margin-top: -8px; border-radius: 0 0 var(--r-s) var(--r-s); background: var(--sunk); padding: 10px; box-shadow: inset 0 0 0 2px var(--ai); }
.ref-preview img { display: block; width: 100%; height: auto; background: #fff; min-height: 240px; border-radius: 4px; }
.ref-preview .row { margin-top: 10px; justify-content: space-between; }
@media (max-width: 560px) { .ref-btn { flex-wrap: wrap; gap: 4px 10px; } .ref-btn .nt { flex: 1 1 60%; } }

/* Аудио */
.audios { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; margin: 12px 0; }
.player {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center;
  padding: 8px 8px 8px 8px; border-radius: 99px; background: var(--sunk);
}
.player.playing { background: var(--ai-soft); }
.pl-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  background: var(--ai-fill); color: var(--ai-ink); display: grid; place-items: center; transition: transform .12s var(--ease);
}
.pl-btn:active { transform: scale(.9); }
.pl-btn svg { width: 16px; height: 16px; }
.pl-main { min-width: 0; }
.pl-label { display: block; font-size: .86rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-bar { height: 14px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.pl-bar i { display: block; height: 4px; width: 100%; border-radius: 99px; background: color-mix(in srgb, var(--ink-3) 30%, transparent); overflow: hidden; }
.pl-bar i b { display: block; height: 100%; width: 0; background: var(--ai); border-radius: 99px; }
.pl-time { font-size: .8rem; color: var(--ink-3); font-variant-numeric: tabular-nums; min-width: 2.6em; text-align: right; }
.pl-rate { border: 0; background: transparent; cursor: pointer; font-size: .8rem; font-weight: 600; color: var(--ink-2); padding: 6px 8px; border-radius: 99px; min-width: 3.4em; font-variant-numeric: tabular-nums; }
.pl-rate:hover { background: var(--card); }

/* Словарь */
.vocab-tools { margin: 6px 0 12px; }
.vocab { list-style: none; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px; }
.w {
  display: grid; grid-template-columns: 1fr; width: 100%; height: 100%; text-align: left; cursor: pointer;
  padding: 10px 14px; border: 0; border-radius: var(--r-s); background: var(--sunk); transition: box-shadow .15s, transform .12s var(--ease);
}
.w:hover { box-shadow: inset 0 0 0 2px var(--ai); }
.w:active { transform: scale(.98); }
.w-jp { font-family: var(--font-jp-sans); font-size: 1.15rem; line-height: 1.35; }
.w-rd { color: var(--ink-3); font-size: .85rem; }
.w-tr { font-size: .95rem; color: var(--ink); margin-top: 2px; }
.w-rd, .w-tr, .w-jp { transition: filter .2s, opacity .2s; }
.vocab[data-mode="jp"] .w:not(.open) .w-tr,
.vocab[data-mode="jp"] .w:not(.open) .w-rd,
.vocab[data-mode="ru"] .w:not(.open) .w-jp,
.vocab[data-mode="ru"] .w:not(.open) .w-rd { filter: blur(7px); opacity: .5; }

/* Проверка */
.quiz { margin-top: 48px; padding: 28px; border-radius: var(--r); background: var(--card); scroll-margin-top: 70px; }
.quiz > .muted { margin-bottom: 24px; }
.q { margin-bottom: 26px; }
.q-text { font-weight: 600; margin-bottom: 10px; }
.q-opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.q-opt {
  display: flex; gap: 10px; align-items: center; padding: 12px 16px; border: 0; min-height: 48px;
  border-radius: var(--r-s); background: var(--sunk); cursor: pointer; text-align: left; transition: box-shadow .15s, background-color .15s;
}
.q-opt:hover { box-shadow: inset 0 0 0 2px var(--ink-3); }
.q-opt.sel { box-shadow: inset 0 0 0 2px var(--ai); background: var(--ai-soft); }
.q-opt.ok { box-shadow: inset 0 0 0 2px var(--matcha); background: var(--matcha-soft); }
.q-opt.bad { box-shadow: inset 0 0 0 2px var(--shu); background: var(--shu-soft); }
.q-why { font-size: .92rem; color: var(--ink-2); margin-top: 8px; padding-left: 12px; }
.result { display: flex; gap: 24px; align-items: center; padding: 22px; background: var(--sunk); border-radius: var(--r); margin-top: 16px; }
.result h3 { margin-bottom: .3em; }
@media (max-width: 560px) { .quiz { padding: 18px; margin-left: -4px; margin-right: -4px; } .result { flex-direction: column; align-items: flex-start; } }
.lesson-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 28px; }
.lesson-nav a { display: block; padding: 16px 20px; border-radius: var(--r); background: var(--sunk); color: inherit; text-decoration: none; transition: box-shadow .15s; }
.lesson-nav a:hover { box-shadow: inset 0 0 0 2px var(--ai); }
.lesson-nav a small { display: block; color: var(--ink-3); font-size: .85rem; }
.lesson-nav a b { font-weight: 600; }
.lesson-nav .nx { text-align: right; grid-column: 2; }

/* ===== Кана ======================================================= */
.tabs { display: inline-flex; gap: 4px; padding: 4px; border-radius: 99px; background: var(--sunk); margin-bottom: 28px; }
.tab { padding: 8px 18px; border: 0; background: none; cursor: pointer; color: var(--ink-2); border-radius: 99px; font-weight: 550; transition: background-color .15s, color .15s; }
.tab:hover { color: var(--ink); }
.tab.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 99px; background: var(--sunk); }
.seg button { border: 0; background: transparent; padding: 7px 16px; cursor: pointer; border-radius: 99px; color: var(--ink-2); transition: background-color .15s, color .15s; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--ai-fill); color: var(--ai-ink); }
@media (max-width: 560px) { .seg { border-radius: 18px; } .seg button { border-radius: 14px; } }
.field { margin-bottom: 22px; }
.field > label, .field > .lbl { display: block; font-weight: 600; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 0; background: var(--sunk); border-radius: 99px; padding: 6px 14px; cursor: pointer; font-family: var(--font-jp-sans); transition: background-color .15s, color .15s, transform .12s var(--ease); }
.chip:hover { box-shadow: inset 0 0 0 1.5px var(--ai); }
.chip:active { transform: scale(.95); }
.chip.on { background: var(--ai-fill); color: var(--ai-ink); }
.chip-group { margin-bottom: 12px; }
.chip-group .dim { font-size: .88rem; margin-bottom: 6px; display: flex; align-items: center; gap: 4px; }

.kana-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; align-items: start; }
.kana-preview { position: sticky; top: 24px; padding: 22px; border-radius: var(--r); background: var(--card); }
.kana-preview h3 { font-size: .95rem; color: var(--ink-2); font-weight: 550; }
.kana-preview .chars { font-family: var(--font-jp); font-size: 1.6rem; line-height: 1.6; letter-spacing: .12em; word-break: break-all; margin: 4px 0 18px; min-height: 2em; }
.kana-preview .btn { width: 100%; }
@media (max-width: 900px) {
  .kana-layout { grid-template-columns: 1fr; gap: 8px; }
  .kana-preview { position: sticky; top: auto; bottom: 76px; z-index: 5; padding: 14px 16px; box-shadow: 0 6px 24px rgb(0 0 0 / .18); }
  .kana-preview h3, .kana-preview .chars { display: none; }
}

.kana-table { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; max-width: 540px; }
.kana-table.combo { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 330px; }
.kt {
  position: relative; border: 0; border-radius: var(--r-s); background: var(--sunk);
  display: flex; flex-direction: column; align-items: center; padding: 8px 2px 6px; cursor: pointer;
  transition: background-color .15s, transform .12s var(--ease);
}
.step .kt { background: var(--paper); }
.kt:hover { background: var(--ai-soft); }
.kt:active { transform: scale(.94); }
.kt.empty { background: transparent; cursor: default; }
.kt b { font-family: var(--font-jp); font-weight: 500; font-size: 1.9rem; line-height: 1.25; }
.kt span { font-size: .76rem; color: var(--ink-3); }
.kt .hint-dot { position: absolute; top: 7px; right: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--shu); }
.kt-hint { min-height: 1.6em; margin: 12px 0 18px; color: var(--ink-2); font-size: .95rem; }
.table-block h3 { margin-top: 22px; }

.drill { text-align: center; padding: 10px 0; max-width: 560px; margin: 0 auto; }
.drill-meta { display: flex; justify-content: space-between; color: var(--ink-3); font-size: .9rem; margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.drill-bar { margin-bottom: 30px; }
.big-kana {
  --s: 1.5em; font-family: var(--font-jp); font-weight: 500; font-size: clamp(5rem, 22vw, 9rem); line-height: 1; margin: 6px auto 30px;
}
.big-kana.cell { border-radius: 18px; box-shadow: inset 0 0 0 2px var(--line); }
.big-kana.wide { width: auto; min-width: 1.5em; padding: 0 .2em; font-size: clamp(3.5rem, 15vw, 6.5rem); }
.big-kana span { background: var(--card); line-height: 1.1; }
.big-romaji { font-size: clamp(2.6rem, 10vw, 4rem); font-weight: 650; margin: 20px 0 28px; letter-spacing: -.02em; }
.answer-in { font-size: 1.4rem; text-align: center; width: min(300px, 100%); padding: 12px; border: 0; border-radius: 99px; background: var(--card); box-shadow: inset 0 0 0 2px var(--line); }
.answer-in:focus { outline: none; box-shadow: inset 0 0 0 2px var(--ai); }
.answer-in.ok { box-shadow: inset 0 0 0 2px var(--matcha); background: var(--matcha-soft); }
.answer-in.bad { box-shadow: inset 0 0 0 2px var(--shu); background: var(--shu-soft); }
.opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 440px; margin: 0 auto; }
.opts.kana-opts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.opt { padding: 16px; font-size: 1.3rem; font-weight: 550; border: 0; background: var(--card); border-radius: var(--r); cursor: pointer; transition: box-shadow .15s, transform .12s var(--ease); }
.opts.kana-opts .opt { font-family: var(--font-jp); font-size: 2rem; padding: 10px; font-weight: 500; }
.opt:hover { box-shadow: inset 0 0 0 2px var(--ai); }
.opt:active { transform: scale(.96); }
.opt.ok { box-shadow: inset 0 0 0 2px var(--matcha); background: var(--matcha-soft); }
.opt.bad { box-shadow: inset 0 0 0 2px var(--shu); background: var(--shu-soft); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.feedback { min-height: 3.2em; margin-top: 18px; color: var(--ink-2); }
.feedback b { color: var(--ink); font-size: 1.2em; }
.miss-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0 24px; }
.miss-list span { font-family: var(--font-jp); font-size: 1.6rem; background: var(--shu-soft); color: var(--shu); border-radius: var(--r-s); padding: 2px 12px; }
.finish-num { font-size: clamp(3rem, 10vw, 5rem); font-weight: 650; letter-spacing: -.04em; line-height: 1; margin: 20px 0 6px; font-variant-numeric: tabular-nums; }

/* ===== Повторение ================================================= */
.review-wrap { max-width: 620px; margin: 0 auto; }
.flash { text-align: center; padding: 36px 24px 28px; border-radius: 22px; background: var(--card); margin-top: 10px; }
.flash-front { font-family: var(--font-jp-sans); font-size: clamp(2.4rem, 9vw, 3.8rem); line-height: 1.3; margin: 18px 0 10px; word-break: keep-all; }
.flash-front.kana { font-family: var(--font-jp); font-size: clamp(4rem, 18vw, 7rem); font-weight: 500; }
.flash-back { min-height: 96px; margin: 18px 0 22px; }
.flash-back .meaning { font-size: 1.45rem; font-weight: 600; animation: rise .25s var(--ease); }
.flash-back .reading { color: var(--ink-2); margin-top: 4px; animation: rise .3s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.grades { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.grade { padding: 12px 4px; border-radius: var(--r-s); border: 0; background: var(--sunk); cursor: pointer; font-weight: 600; transition: transform .12s var(--ease), box-shadow .15s; }
.grade:hover { box-shadow: inset 0 0 0 2px var(--ink-3); }
.grade:active { transform: scale(.96); }
.grade small { display: block; font-size: .76rem; font-weight: 400; margin-top: 2px; }
.grade.g0 { background: var(--shu-soft); color: var(--shu); }
.grade.g2 { background: var(--matcha-soft); color: var(--matcha); }
.grade.g3 { background: var(--ai-soft); color: var(--ai); }
.empty-state { text-align: center; padding: 56px 24px; border-radius: 22px; background: var(--card); }
.empty-state .big { font-family: var(--font-jp); font-size: 4.5rem; color: var(--matcha); line-height: 1.2; margin-bottom: 10px; }
.empty-state .big.cell { --s: 1.5em; margin: 0 auto 18px; color: var(--matcha); }
.empty-state p { max-width: 44ch; margin-left: auto; margin-right: auto; }

/* ===== Библиотека и просмотр ===================================== */
.books { list-style: none; padding: 0; margin: 24px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.book { display: grid; grid-template-columns: 96px 1fr; gap: 18px; padding: 16px; border-radius: var(--r); background: var(--card); color: inherit; text-decoration: none; transition: box-shadow .15s; }
.book:hover { box-shadow: 0 0 0 2px var(--ai); }
.book .cover { width: 96px; aspect-ratio: 3 / 4.2; border-radius: 6px; background: var(--sunk); object-fit: cover; object-position: top; display: block; }
.book h3 { margin-bottom: .3em; font-size: 1.02rem; }
.book p { margin: 0 0 .5em; color: var(--ink-2); font-size: .92rem; }
.book .when { color: var(--ink-3); font-size: .85rem; }
.viewer-bar {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 0; margin-bottom: 14px; background: color-mix(in srgb, var(--paper) 92%, transparent);
}
.viewer-bar .title { font-weight: 600; margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.viewer-bar input { width: 64px; padding: 6px; border: 0; border-radius: 99px; background: var(--sunk); text-align: center; font-variant-numeric: tabular-nums; }
.viewer-img { display: block; margin: 0 auto; max-width: 100%; height: auto; background: #fff; border-radius: 6px; }
.viewer-img.zoom { max-width: none; width: 160%; }
.viewer-scroll { overflow-x: auto; }

#toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: var(--paper); padding: 12px 20px; border-radius: 99px; font-size: .95rem;
  transition: opacity .2s, transform .25s var(--ease); pointer-events: none; z-index: 50; max-width: calc(100% - 32px);
  box-shadow: 0 8px 30px rgb(0 0 0 / .25);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 760px) { #toast { bottom: 88px; border-radius: 16px; } }
kbd { font: .78em var(--font-ui); background: color-mix(in srgb, currentColor 14%, transparent); border-radius: 5px; padding: 1px 6px; }
@media (hover: none) { kbd { display: none; } }

/* ===== Урок по шагам (режим фокуса) =============================== */
body.focus-mode .side { display: none; }
body.focus-mode .shell { grid-template-columns: 1fr; }
body.focus-mode main { padding: 0; }
body.focus-mode #toast { bottom: 100px; }
.player-view { --pv-w: 760px; min-height: 100vh; display: flex; flex-direction: column; }
.pv-top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px;
  padding: calc(12px + env(safe-area-inset-top)) max(16px, calc((100% - var(--pv-w)) / 2)) 12px;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
}
.pv-x { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-2); flex: none; margin-left: -8px; transition: background-color .15s; }
.pv-x:hover { background: var(--sunk); color: var(--ink); }
.pv-x svg { width: 22px; height: 22px; }
.pv-segs { flex: 1; display: flex; gap: 4px; min-width: 0; }
.pv-segs button { flex: 1; min-width: 0; border: 0; background: none; padding: 12px 0; cursor: pointer; border-radius: 4px; }
.pv-segs i { display: block; height: 6px; border-radius: 99px; background: var(--sunk); transition: background-color .25s, transform .2s var(--ease); }
.pv-segs button.d i { background: var(--matcha); }
.pv-segs button.c i { background: var(--ai-fill); transform: scaleY(1.35); }
.pv-segs button:hover i { box-shadow: 0 0 0 2px var(--ai-soft); }
.pv-count { font-size: .9rem; color: var(--ink-2); min-width: 3.4em; text-align: right; font-variant-numeric: tabular-nums; }
.pv-stage { flex: 1; padding: 8px max(16px, calc((100% - var(--pv-w)) / 2)) 128px; }
.pv-inner.in-next { animation: pv-in-next .3s var(--ease); }
.pv-inner.in-prev { animation: pv-in-prev .3s var(--ease); }
@keyframes pv-in-next { from { opacity: 0; transform: translateX(28px); } }
@keyframes pv-in-prev { from { opacity: 0; transform: translateX(-28px); } }
.pv-meta { color: var(--ink-3); font-size: .92rem; margin: 14px 0 8px; }
.pv-title { font-size: clamp(1.8rem, 1.3rem + 1.8vw, 2.6rem); margin-bottom: .3em; }
.player-view .kind { display: inline-block; }
.pv-content { margin-top: 22px; }
.pv-content .step-body { font-size: 1.05rem; max-width: none; }
.player-view .quiz { margin-top: 18px; }
.player-view .step .kt, .pv-content .kt { background: var(--card); }
.pv-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 12px max(16px, calc((100% - var(--pv-w)) / 2)) calc(12px + env(safe-area-inset-bottom));
  background: var(--paper); box-shadow: 0 -1px 0 var(--line);
}
.pv-foot-in { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.pv-foot .btn { width: 100%; min-height: 52px; }

/* ===== Появление ================================================== */
.page > * { animation: rise .35s var(--ease) both; }
.page > *:nth-child(2) { animation-delay: .04s; }
.page > *:nth-child(3) { animation-delay: .08s; }
.page > *:nth-child(4) { animation-delay: .12s; }
.page > *:nth-child(n+5) { animation-delay: .16s; }
.page.no-anim > * { animation: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ===== Профиль и вход ============================================ */
.input {
  width: 100%; max-width: 420px; min-height: 46px; padding: 10px 14px; border: 0; border-radius: 12px;
  background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); font: inherit;
}
.input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--ai); }
.field .hint { font-size: .85rem; color: var(--ink-3); margin-top: 6px; }
.acc-block { margin-bottom: 40px; }
.acc-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 18px 0 14px; }
.acc-stats div { background: var(--card); border-radius: var(--r); padding: 16px 18px; }
.acc-stats b { display: block; font-size: 1.9rem; font-weight: 650; line-height: 1.05; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.acc-stats span { font-size: .88rem; color: var(--ink-2); }
@media (max-width: 640px) { .acc-stats { grid-template-columns: 1fr 1fr; } }
.acc-block h2 { margin-bottom: .6em; }
.acc-form .field { margin-bottom: 16px; }
.acc-theme { width: auto; }
.form-msg { min-height: 1.5em; margin: 12px 0 0; }
.form-msg.err { color: var(--shu); }
.form-msg.ok { color: var(--matcha, var(--ai)); }
.acc-list { list-style: none; padding: 0; margin: 18px 0 0; display: flex; flex-direction: column; gap: 8px; }
.acc-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--r-s); background: var(--card);
}
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .04em; }
.small { font-size: .85rem; }
.btn.danger { color: var(--shu); }
.btn.danger:hover { background: color-mix(in srgb, var(--shu) 12%, transparent); }