:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #14202e;
  --muted: #5d6b7c;
  --line: #dde3ea;
  --navy: #0f2a47;
  --accent: #ff8a1f;
  --accent-ink: #8a4300;
  --ok: #1f8a4c;
  --ok-bg: #e5f5ec;
  --bad: #c43a31;
  --bad-bg: #fbe9e7;
  --soft: #eef3f8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 42, 71, .06), 0 4px 14px rgba(15, 42, 71, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c141d; --card: #142130; --ink: #e8eef5; --muted: #9aabbe; --line: #24354a;
    --navy: #0a1c30; --accent: #ff9d45; --accent-ink: #ffc58f; --ok: #4cc283; --ok-bg: #12301f;
    --bad: #ff7a70; --bad-bg: #3a1714; --soft: #1a2a3c; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0c141d; --card: #142130; --ink: #e8eef5; --muted: #9aabbe; --line: #24354a;
  --navy: #0a1c30; --accent: #ff9d45; --accent-ink: #ffc58f; --ok: #4cc283; --ok-bg: #12301f;
  --bad: #ff7a70; --bad-bg: #3a1714; --soft: #1a2a3c; --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: "Noto Sans JP", "Noto Sans Devanagari", system-ui, sans-serif;
  font-size: 16px; line-height: 1.6; -webkit-text-size-adjust: 100%;
}
.ne, [lang="ne"] { font-family: "Noto Sans Devanagari", "Noto Sans JP", sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* layout */
.top {
  background: var(--navy); color: #fff; padding: 14px 16px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
}
.top .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; max-width: 760px; margin: 0 auto; }
.top h1 { font-size: 17px; margin: 0; font-weight: 700; }
.top .sub { font-size: 13px; opacity: .8; }
.back { background: none; border: 0; color: #fff; font-size: 15px; padding: 4px 0; }
main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  background: none; border: 0; padding: 8px 2px 10px; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabs button svg { width: 22px; height: 22px; }
.tabs button.on { color: var(--accent); font-weight: 700; }

/* cards */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 14px; }
.card h2 { font-size: 17px; margin: 0 0 8px; }
.card h3 { font-size: 15px; margin: 14px 0 4px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.hero { background: linear-gradient(135deg, var(--navy), #1d4a78); color: #fff; border: 0; }
.hero .big { font-size: 44px; font-weight: 700; line-height: 1; }
.hero .muted { color: rgba(255,255,255,.8); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--soft); border-radius: 10px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.bar { height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

/* lists */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow);
}
.item .num { flex: none; width: 34px; height: 34px; border-radius: 9px; background: var(--soft); display: grid; place-items: center; font-weight: 700; color: var(--accent-ink); }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 700; }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); }
.task:first-of-type { border-top: 0; }
.task input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--ok); flex: none; }
.task.done .grow { text-decoration: line-through; color: var(--muted); }
.task .go { flex: none; background: var(--soft); border: 0; border-radius: 8px; padding: 4px 10px; font-size: 13px; }

/* text */
.tr { margin-top: 4px; color: var(--muted); font-size: 14.5px; }
.tr .lbl { display: inline-block; font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 5px; background: var(--soft); margin-right: 6px; vertical-align: 1px; }
.lesson p { margin: 6px 0; }
.lesson .sec { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.lesson .sec:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.lesson ul { margin: 6px 0; padding-left: 20px; }
.key { background: #fff3e6; color: var(--accent-ink); border-radius: 10px; padding: 10px 12px; font-size: 14.5px; margin: 10px 0; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .key { background: #33230f; } }
:root[data-theme="dark"] .key { background: #33230f; }
ruby rt { font-size: .55em; color: var(--muted); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 11px; padding: 12px 18px; font-weight: 700; background: var(--accent); color: #241200; }
.btn.alt { background: var(--soft); color: var(--ink); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }

/* quiz */
.opt { width: 100%; text-align: left; border: 2px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; display: flex; gap: 10px; }
.opt .k { flex: none; font-weight: 700; color: var(--muted); }
.opt.pick { border-color: var(--navy); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.qhead { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.qtext { font-size: 17px; font-weight: 500; }
.explain { border-left: 4px solid var(--accent); padding: 8px 12px; background: var(--soft); border-radius: 0 10px 10px 0; margin: 12px 0; }
.verdict { font-weight: 700; margin: 4px 0 8px; }
.verdict.ok { color: var(--ok); } .verdict.bad { color: var(--bad); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }

/* flashcards */
.flash { min-height: 230px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; cursor: pointer; user-select: none; }
.flash .jp { font-size: 30px; font-weight: 700; }
.flash .kana { color: var(--muted); font-size: 16px; }
.flash .hint { font-size: 12px; color: var(--muted); margin-top: 18px; }
.iconbtn { background: var(--soft); border: 0; border-radius: 999px; width: 40px; height: 40px; display: inline-grid; place-items: center; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, var(--navy), #1d4a78 70%); }
.login .card { width: 100%; max-width: 380px; }
.login h1 { font-size: 21px; margin: 4px 0 2px; }
.login label { display: block; font-size: 13px; font-weight: 700; margin: 14px 0 4px; }
.login input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 16px; }
.err { color: var(--bad); font-size: 14px; margin-top: 10px; min-height: 1.4em; }
.logo { width: 48px; height: 48px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--soft); padding: 4px; border-radius: 11px; }
.seg button { border: 0; background: none; padding: 8px 4px; border-radius: 8px; font-size: 14px; }
.seg button.on { background: var(--card); font-weight: 700; box-shadow: var(--shadow); }
table.res { width: 100%; border-collapse: collapse; font-size: 14px; }
table.res td { padding: 6px 4px; border-top: 1px solid var(--line); }
.para { margin: 6px 0; }
.fig { margin: 12px 0; text-align: center; }
.fig img, .qimg { max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: zoom-in; }
.qimg { display: block; margin: 0 auto 12px; max-height: 340px; }
.fig figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; text-align: left; }
.zoom { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.88); display: grid; place-items: center; padding: 12px; cursor: zoom-out; }
.zoom img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 6px; }
