:root {
  --paper: #f6f1e7;
  --card: #fffdf8;
  --ink: #1d1b19;
  --muted: #6f675d;
  --line: #ddd4c4;
  --accent: #b8382a;
  --accent-ink: #fff;
  --good: #3f7d4e;
  --warn: #b7791f;
  --bad: #b8382a;
  --soft: #ece5d6;
  --jp: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  --ui: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151412;
    --card: #1f1d1a;
    --ink: #ece6da;
    --muted: #9c9387;
    --line: #35312b;
    --accent: #e0584a;
    --accent-ink: #1a0f0d;
    --good: #6fb381;
    --warn: #d9a441;
    --bad: #e0584a;
    --soft: #2a2723;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 16px/1.55 var(--ui); }
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; font-weight: 650; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
small, .muted { color: var(--muted); }
[lang="ja"], .jp { font-family: var(--jp); }

.shell { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.nav { border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); position: relative; }
.nav a i { font: normal 600 .95rem var(--jp); width: 2.4em; color: var(--ink); opacity: .75; }
.nav a:hover { background: var(--soft); }
.nav a.active { background: var(--soft); color: var(--ink); }
.nav a.active i { color: var(--accent); opacity: 1; }
.brand { margin-bottom: 14px; color: var(--ink) !important; }
.brand:hover { background: none !important; }
.seal { display: grid; place-items: center; width: 38px; height: 38px; background: var(--accent); color: var(--accent-ink); font: 700 1.3rem var(--jp); border-radius: 7px; }
.brand-text { font: 700 1.05rem var(--jp); display: flex; flex-direction: column; line-height: 1.1; }
.brand-text small { font: 400 .7rem var(--ui); letter-spacing: .08em; }
.badge { margin-left: auto; background: var(--accent); color: var(--accent-ink); font-size: .72rem; padding: 1px 7px; border-radius: 99px; }

main { padding: 28px clamp(16px, 4vw, 48px) 80px; max-width: 980px; width: 100%; outline: none; }
.sub { color: var(--muted); margin-top: -.3em; margin-bottom: 1.4em; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stack > * + * { margin-top: 14px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { justify-content: space-between; }

.stat .n { font: 650 1.9rem var(--ui); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .82rem; }

button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 8px 14px; border-radius: 8px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.ghost { border-color: transparent; background: none; color: var(--muted); padding: 4px 8px; }
.big { padding: 12px 22px; font-size: 1.05rem; }
input, select { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
input:focus-visible, button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
kbd { font: .72rem ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--muted); }

.primary kbd { color: inherit; border-color: currentColor; opacity: .8; }
.bar { height: 8px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.good > span { background: var(--good); }
.tag { font-size: .72rem; padding: 2px 8px; border-radius: 99px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.tag.hot { background: var(--accent); color: var(--accent-ink); }
.tag.ok { background: color-mix(in srgb, var(--good) 22%, transparent); color: var(--good); }

/* quests */
.quest { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.quest:first-of-type { border-top: 0; }
.quest .check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; flex: none; font-size: .9rem; }
.quest.done .check { background: var(--good); border-color: var(--good); color: #fff; }
.quest.done .qt { text-decoration: line-through; color: var(--muted); }
.quest .qt { font-weight: 600; }
.quest .grow { flex: 1; min-width: 0; }

/* study card */
.session { max-width: 640px; margin: 0 auto; }
.flash { text-align: center; padding: 34px 20px; min-height: 300px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.flash .front { font: 500 clamp(3rem, 12vw, 5.5rem)/1.15 var(--jp); word-break: keep-all; }
.flash .front.long { font-size: clamp(1.8rem, 6vw, 2.8rem); }
.flash .reading { font: 1.4rem var(--jp); }
.flash .romaji { color: var(--muted); font-style: italic; }
.flash .meaning { font-size: 1.35rem; font-weight: 600; }
.flash .note { color: var(--muted); font-size: .9rem; max-width: 46ch; }
.flash hr { width: 60%; border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.grades button { flex-direction: column; gap: 0; justify-content: center; padding: 10px 4px; }
.grades small { font-size: .72rem; }
.g1 { border-color: var(--bad); } .g3 { border-color: var(--good); }
.choices { display: grid; gap: 8px; margin-top: 14px; }
.choices button { justify-content: flex-start; text-align: left; padding: 12px 14px; }
.choices button.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 16%, var(--card)); }
.choices button.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, var(--card)); }
.answer { font-size: 1.4rem; text-align: center; width: 9em; }
.feedback { font-weight: 600; min-height: 1.6em; }
.feedback.ok { color: var(--good); } .feedback.no { color: var(--bad); }
.examples { text-align: left; font-size: .95rem; }
.examples div { padding: 3px 0; }
.speak { border-radius: 50%; width: 34px; height: 34px; padding: 0; justify-content: center; flex: none; }

.aid-img { width: min(260px, 70%); border-radius: 10px; border: 1px solid var(--line); margin-top: 8px; }
#kana-info { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
#kana-info .aid-img { width: 150px; margin: 0; }
.aid { text-align: left; max-width: 52ch; font-size: .93rem; margin-top: 8px; }
.aid p { margin: 6px 0; }
.aid .parts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; margin-bottom: 6px; }
.aid .parts span { background: var(--soft); border-radius: 8px; padding: 3px 10px; }
.aid .parts b { font: 500 1.3rem var(--jp); margin-right: 4px; }
.aid .parts i { color: var(--muted); font-style: normal; }

/* kana chart */
.kana-row { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; padding: 5px 0; }
.kana-cells { display: flex; flex-wrap: wrap; gap: 6px; }
.kana-cell { width: 54px; padding: 6px 0; text-align: center; border: 1px solid var(--line); border-radius: 8px; background: var(--card); cursor: pointer; flex-direction: column; gap: 0; }
.kana-cell b { font: 500 1.35rem var(--jp); display: block; }
.kana-cell small { font-size: .68rem; }
.kana-cell.known { border-color: var(--good); }
.kana-cell.new { opacity: .55; }

/* grammar */
.gp { display: flex; gap: 12px; align-items: baseline; padding: 10px 0; border-top: 1px solid var(--line); text-decoration: none; }
.gp:first-child { border-top: 0; }
.gp .t { font: 600 1.05rem var(--jp); }
.ex { padding: 10px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.ex .j { font: 1.25rem var(--jp); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 46px; padding: 8px; border: 1px dashed var(--line); border-radius: 8px; }
.chips button { font-family: var(--jp); font-size: 1.1rem; }

/* plan */
.week { border-left: 3px solid var(--line); padding: 2px 0 2px 16px; }
.week.now { border-color: var(--accent); }
.week.past { opacity: .7; }
.week label { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; cursor: pointer; }
.week input { margin-top: 5px; }

/* charts */
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: 3px; justify-content: start; }
.heat i { width: 13px; height: 13px; border-radius: 3px; background: var(--soft); }
.heat i[data-l="1"] { background: color-mix(in srgb, var(--accent) 30%, var(--soft)); }
.heat i[data-l="2"] { background: color-mix(in srgb, var(--accent) 60%, var(--soft)); }
.heat i[data-l="3"] { background: var(--accent); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 110px; }
.bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars div span { position: absolute; top: -1.4em; left: 0; right: 0; text-align: center; font-size: .68rem; color: var(--muted); }
.axis { display: flex; gap: 4px; font-size: .68rem; color: var(--muted); }
.axis span { flex: 1; text-align: center; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 99px; font-weight: 600; z-index: 10; }
.rank { font: 700 1.5rem var(--jp); }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); background: var(--paper); padding: 4px; overflow-x: auto; z-index: 5; gap: 0; }
  .brand { display: none !important; }
  .nav a { flex-direction: column; gap: 0; padding: 5px 9px; font-size: .68rem; flex: none; }
  .nav a i { width: auto; font-size: .9rem; }
  .badge { position: absolute; top: 0; right: 0; }
  main { padding-bottom: 110px; }
  .kana-row { grid-template-columns: 1fr; }
}

/* handwriting */
.pad { position: relative; width: min(100%, 340px); aspect-ratio: 1; margin: 12px auto; border: 1px solid var(--line); border-radius: 10px; background:
  linear-gradient(var(--line), var(--line)) center / 100% 1px no-repeat, linear-gradient(var(--line), var(--line)) center / 1px 100% no-repeat, var(--card); }
.pad .guide { position: absolute; inset: 0; display: grid; place-items: center; font: 400 230px/1 "Hiragino Sans", "Yu Gothic", sans-serif; color: color-mix(in srgb, var(--muted) 30%, transparent); user-select: none; }
.pad canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.sheet-row { display: grid; grid-template-columns: repeat(9, 1fr); break-inside: avoid; }
.sheet .cell { aspect-ratio: 1; border: 1px solid var(--muted); margin: -0.5px; display: grid; place-items: center; font: 400 clamp(1.4rem, 6vw, 3rem)/1 "Hiragino Sans", "Yu Gothic", sans-serif; position: relative;
  background: linear-gradient(var(--line), var(--line)) center / 100% 1px no-repeat, linear-gradient(var(--line), var(--line)) center / 1px 100% no-repeat; }
.sheet .trace { color: color-mix(in srgb, var(--muted) 35%, transparent); }
.sheet .model small { position: absolute; bottom: 2px; left: 0; right: 0; text-align: center; font: .6rem var(--ui); color: var(--muted); white-space: nowrap; overflow: hidden; }
@media print {
  .nav, .noprint, .toast { display: none !important; }
  .shell { display: block; } main { padding: 0; max-width: none; }
  body { background: #fff; color: #000; }
  .sheet .cell { border-color: #777; font-size: 34pt; }
  .sheet .trace { color: #ccc; }
}

/* stroke order */
.strokes { width: 100%; height: 100%; display: block; }
.strokes path { fill: none; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.strokes .base path { stroke: color-mix(in srgb, var(--muted) 32%, transparent); }
.strokes .anim path { stroke: var(--accent); opacity: .75; stroke-dasharray: 1000; stroke-dashoffset: 1000; }
.strokes .nums text { font: 600 6px var(--ui); fill: var(--muted); }
.so { display: flex; flex-direction: column; align-items: center; }
.so svg { width: 130px; height: 130px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.pad .guide svg { width: 100%; height: 100%; }
.pad .guide .anim path { stroke-width: 5; }

/* photo homework */
.hw-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.hw-grid figure { margin: 0; }
.hw-grid img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.hw-grid figcaption { display: flex; justify-content: space-between; align-items: center; font-size: .78rem; color: var(--muted); }
@media print { #homework { display: none; } }

/* sign-in gate */
#gate { display: none; }
.locked .shell { display: none; }
.locked #gate { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.gate-card { text-align: center; max-width: 360px; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 32px 24px; }
.gate-card h1 { font-family: var(--jp); margin: 0; }
