:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --text: #1d1b19;
  --muted: #6f6a63;
  --line: #e2ddd5;
  --accent: #c0392b;
  --accent-soft: #f6dfdb;
  --ok: #2e7d4f;
  --ok-soft: #dcefe3;
  --bad: #c0392b;
  --bad-soft: #f8dcd8;
  --s-new: #e2ddd5;
  --s-learn: #f2c46d;
  --s-young: #8cc5a1;
  --s-mature: #2e7d4f;
  --radius: 16px;
  --jp: "Noto Sans JP", "Noto Sans CJK JP", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #212126;
    --surface-2: #2b2b31;
    --text: #f1eee9;
    --muted: #a19c95;
    --line: #34343b;
    --accent: #ef6f5e;
    --accent-soft: #3d2522;
    --ok: #5cc58a;
    --ok-soft: #1e3628;
    --bad: #ef6f5e;
    --bad-soft: #3d2522;
    --s-new: #34343b;
    --s-learn: #b88a2e;
    --s-young: #4f8f68;
    --s-mature: #5cc58a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}
[lang="ja"], .jp { font-family: var(--jp); }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; }

#app { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-b)); }
body.focus #app { padding-bottom: 0; }
.loading { padding: 40vh 0; text-align: center; color: var(--muted); font-size: 20px; }

/* ---------- navegación ---------- */
.nav {
  position: fixed; inset: auto 0 0 0; display: flex; justify-content: center; gap: 4px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-b)); z-index: 5;
}
.nav button {
  flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; gap: 0;
  background: none; border: 0; padding: 6px 0; border-radius: 12px; color: var(--muted); font-size: 12px;
}
.nav button .ni { font-size: 18px; line-height: 1.2; }
.nav button.on { color: var(--accent); background: var(--accent-soft); }

/* ---------- elementos comunes ---------- */
.top { display: flex; align-items: baseline; justify-content: space-between; margin: 4px 0 16px; }
.top h1 { font-size: 26px; letter-spacing: -0.02em; }
.top h1 .jp { color: var(--accent); margin-right: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.big-num { font-size: 34px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 14px; padding: 15px 16px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 17px; text-align: center;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.ghost { background: none; color: var(--muted); font-weight: 500; font-size: 15px; padding: 10px; }
.btn + .btn { margin-top: 8px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); font-size: 12px; color: var(--muted); }
.lv-tag { font-weight: 700; color: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.next-kanji { font-size: 54px; line-height: 1; width: 76px; height: 76px; display: grid; place-items: center; background: var(--surface-2); border-radius: 14px; }

.bar { height: 10px; border-radius: 99px; background: var(--s-new); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.lvrow { display: grid; grid-template-columns: 36px 1fr 70px; align-items: center; gap: 10px; margin: 10px 0; font-size: 14px; }
.lvrow .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- lección ---------- */
.progress { height: 4px; background: var(--line); border-radius: 99px; margin: 0 0 18px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .25s; }
.qhead { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.qhead .x { background: none; border: 0; font-size: 22px; color: var(--muted); padding: 4px 8px 4px 0; }
.qhead .progress { flex: 1; margin: 0; }
.qhead .count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.lesson-kanji { text-align: center; padding: 8px 0 4px; }
.lesson-kanji .k { font-size: 120px; line-height: 1.1; }
.lesson-kanji .m { font-size: 18px; font-weight: 600; }
.lesson-kanji .es { color: var(--muted); font-size: 15px; }
.readings { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; margin: 12px 0 0; }
.readings dt { color: var(--muted); font-size: 13px; padding-top: 2px; }
.readings dd { margin: 0; }
.word {
  display: flex; align-items: center; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line);
}
.word:first-child { border-top: 0; }
.word .w { font-size: 26px; min-width: 92px; }
.word .w ruby rt { font-size: 12px; color: var(--muted); }
.word .g { font-size: 14px; }
.word .g .es { color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--s-new); }

/* ---------- quiz ---------- */
.q-label { text-align: center; color: var(--muted); font-size: 14px; margin-top: 6px; }
.q-prompt {
  text-align: center; font-size: 64px; line-height: 1.25; padding: 28px 8px 8px; min-height: 160px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; word-break: keep-all;
}
.q-prompt.kana { font-size: 46px; }
.q-prompt ruby rt { font-size: 18px; color: var(--muted); }
.q-hint { text-align: center; color: var(--muted); font-size: 15px; min-height: 22px; margin-bottom: 18px; padding: 0 8px; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt {
  background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 16px 8px;
  font-size: 24px; min-height: 72px; font-family: var(--jp); transition: transform .08s;
}
.opt.kanji { font-size: 30px; }
.opt:active { transform: scale(.97); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.dim { opacity: .45; }
.feedback { margin-top: 14px; }
.feedback .verdict { font-weight: 700; margin-bottom: 4px; }
.feedback .verdict.ok { color: var(--ok); }
.feedback .verdict.bad { color: var(--bad); }
.feedback .mean { font-size: 15px; }
.feedback .mean .es { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 10px; padding: 4px 10px; font-size: 13px;
}
.chip .jp { font-size: 20px; }
.nav[hidden] { display: none; }
.actions {
  position: sticky; bottom: 0; margin: 14px -16px 0; padding: 16px 16px calc(12px + var(--safe-b));
  background: linear-gradient(to bottom, transparent, var(--bg) 22%);
}

/* ---------- explorar ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { flex: 1; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 0; font-weight: 600; }
.tabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.search { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 16px; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.cell {
  aspect-ratio: 1; display: grid; place-items: center; font-size: 26px; border-radius: 10px; border: 0;
  background: var(--surface); box-shadow: inset 0 -4px 0 var(--s-new); font-family: var(--jp);
}
.cell.learn { box-shadow: inset 0 -4px 0 var(--s-learn); }
.cell.young { box-shadow: inset 0 -4px 0 var(--s-young); }
.cell.mature { box-shadow: inset 0 -4px 0 var(--s-mature); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 10px 0 14px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--c); }

/* ---------- hoja inferior ---------- */
.sheet { position: fixed; inset: 0; z-index: 10; background: rgb(0 0 0 / .4); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet .panel {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 88dvh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 10px 16px calc(20px + var(--safe-b));
  animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 0 auto 8px; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }

/* ---------- ajustes ---------- */
.set { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.set:first-child { border-top: 0; padding-top: 0; }
.set label { flex: 1; }
.set label small { display: block; color: var(--muted); font-size: 13px; }
.set select, .set input[type=number] { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 16px; }
.set input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.about { font-size: 13px; color: var(--muted); }
.about a { color: inherit; }
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20;
}

/* ---------- fase 2: test de nivel, frases, confusiones ---------- */
.card.hl { border-color: var(--accent); background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%); }
.chip.pair { gap: 4px; }
.chip.bad { border-color: var(--bad); }
mark { background: none; color: inherit; border-bottom: 3px solid var(--accent); padding: 0 2px; }
.q-prompt.sent { display: block; min-height: 0; font-size: 26px; line-height: 2.1; text-align: left; padding: 28px 4px 12px; word-break: normal; }
.q-prompt.sent mark { font-size: 32px; }
.q-prompt.sent ruby rt { font-size: 13px; }
.tr { font-style: italic; }
.mix { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin: 6px 0 8px; font-size: 14px; }
.mix .jp { font-size: 26px; margin-right: 2px; }
.ex { padding: 10px 0; border-top: 1px solid var(--line); }
.ex:first-of-type { border-top: 0; }
.ex [lang="ja"] { font-size: 18px; line-height: 2; }
.ex ruby rt { font-size: 10px; color: var(--muted); }
