:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --text: #22201c;
  --text-2: #5f5b53;
  --text-3: #8d887e;
  --border: #e2ddd3;
  --border-strong: #cbc4b6;
  --accent: #b8432f;
  --accent-text: #ffffff;
  --accent-soft: #f7e3dd;
  --good: #2f7d4f;
  --good-soft: #e1f2e6;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --warn: #8a5a00;
  --warn-soft: #fbefd6;
  --sel: #2c5ea8;
  --sel-soft: #e2ebf8;
  --apprentice: #c2407a;
  --guru: #7a4bb5;
  --master: #2f63b8;
  --enlightened: #148a8a;
  --burned: #6b675f;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(40, 30, 10, 0.06), 0 4px 16px rgba(40, 30, 10, 0.05);
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Noto Sans JP", sans-serif;
  --font-jp: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", "Meiryo", "Noto Sans JP", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412;
    --surface: #1f1d1a;
    --surface-2: #29261f;
    --text: #f0ece4;
    --text-2: #bdb6a9;
    --text-3: #8f887b;
    --border: #36322b;
    --border-strong: #4b453b;
    --accent: #e0745f;
    --accent-text: #1a0d09;
    --accent-soft: #3a221c;
    --good: #6cc48e;
    --good-soft: #17301f;
    --bad: #f08a80;
    --bad-soft: #3a1b18;
    --warn: #e8b85c;
    --warn-soft: #36290f;
    --sel: #8fb4ee;
    --sel-soft: #1d2a3d;
    --apprentice: #e879a8;
    --guru: #b48ae6;
    --master: #7fa6ea;
    --enlightened: #5cc8c8;
    --burned: #a39d92;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151412;
  --surface: #1f1d1a;
  --surface-2: #29261f;
  --text: #f0ece4;
  --text-2: #bdb6a9;
  --text-3: #8f887b;
  --border: #36322b;
  --border-strong: #4b453b;
  --accent: #e0745f;
  --accent-text: #1a0d09;
  --accent-soft: #3a221c;
  --good: #6cc48e;
  --good-soft: #17301f;
  --bad: #f08a80;
  --bad-soft: #3a1b18;
  --warn: #e8b85c;
  --warn-soft: #36290f;
  --sel: #8fb4ee;
  --sel-soft: #1d2a3d;
  --apprentice: #e879a8;
  --guru: #b48ae6;
  --master: #7fa6ea;
  --enlightened: #5cc8c8;
  --burned: #a39d92;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--sel); }
.jp { font-family: var(--font-jp); }
rt { font-size: 0.5em; color: var(--text-2); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shell */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-in {
  max-width: 760px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: 0.01em; display: flex; align-items: baseline; gap: 6px; margin-right: auto; }
.brand .jp { color: var(--accent); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--text-2); min-height: 34px;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.nav { max-width: 760px; margin: 0 auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; }
.nav button {
  border: 0; background: none; padding: 8px 12px 10px; cursor: pointer; font-weight: 600; font-size: 14px;
  color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap;
}
.nav button[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
main { max-width: 760px; margin: 0 auto; padding: 20px 16px 64px; }

/* ---------- building blocks */
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 28px 0 10px; }
h3 { font-size: 16px; margin: 0 0 6px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; }
.stat .label { font-size: 13px; color: var(--text-2); }
.stat .value { font-size: 24px; font-weight: 700; line-height: 1.2; }
.big-num { font-size: 40px; font-weight: 700; line-height: 1.1; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; min-height: 42px;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn.small { min-height: 34px; padding: 5px 12px; font-size: 14px; }
.kbd { font-size: 11px; color: var(--text-3); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; margin-left: 4px; font-weight: 500; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.apprentice { background: color-mix(in srgb, var(--apprentice) 16%, transparent); color: var(--apprentice); }
.badge.guru { background: color-mix(in srgb, var(--guru) 16%, transparent); color: var(--guru); }
.badge.master { background: color-mix(in srgb, var(--master) 16%, transparent); color: var(--master); }
.badge.enlightened { background: color-mix(in srgb, var(--enlightened) 16%, transparent); color: var(--enlightened); }
.badge.burned { background: color-mix(in srgb, var(--burned) 18%, transparent); color: var(--burned); }
.badge.ok { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.stages { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.stages span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text-2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; padding-top: 6px; }
.bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: 0.85; position: relative; }
.bars div.zero { background: var(--border); }
.bars-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); margin-top: 4px; }
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-top: 12px; text-align: center; }
.days div { background: var(--surface-2); border-radius: var(--radius-sm); padding: 6px 2px; }
.days b { display: block; font-size: 18px; }
.days span { font-size: 12px; color: var(--text-2); }

/* ---------- study streak */
.streak-main { display: flex; align-items: center; gap: 14px; }
.streak-main .grow { flex: 1; min-width: 0; }
.streak-num { font-size: 32px; font-weight: 700; line-height: 1.1; }
.streak-num span { font-size: 16px; font-weight: 600; color: var(--text-2); }
.streak-best { text-align: right; }
.streak-best b { font-size: 18px; }
.warn-text { color: var(--warn); }
.daruma { width: 56px; height: 56px; flex: none; }
.daruma .body, .daruma .face { fill: none; stroke: var(--border-strong); stroke-width: 2; stroke-dasharray: 4 4; }
.daruma.done .body { fill: var(--accent); stroke: none; }
.daruma.done .face { fill: #fffaf2; stroke: none; }
.daruma .eye { fill: #22201c; }
.daruma .brow { fill: none; stroke: #22201c; stroke-width: 2; stroke-linecap: round; }
.daruma .belt { fill: none; stroke: #f2c14e; stroke-width: 3; stroke-linecap: round; }
.coin { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--border-strong); stroke-width: 1.5; stroke-dasharray: 3 2.5; }
.coin.ready { fill: #e0b23a; stroke: #a8801c; stroke-width: 1; stroke-dasharray: none; }
.streak-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.streak-week { display: grid; grid-template-columns: repeat(7, minmax(30px, 1fr)); gap: 4px; flex: 1 1 240px; max-width: 340px; }
.wk { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--text-3); }
.wk i { display: block; width: 18px; height: 18px; border-radius: 50%; }
.wk .coin { width: 18px; height: 18px; }
.wk.studied i { background: var(--accent); }
.wk.missed i { border: 2px solid var(--border-strong); }
.wk.pending i { border: 2px dashed var(--accent); }
.wk.none i { width: 8px; height: 8px; margin: 5px; background: var(--border); }
.offerings { display: flex; align-items: center; gap: 6px; }
.streak-banner { display: flex; align-items: center; gap: 12px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 14px; margin: 12px 0; }
.streak-banner .daruma { width: 40px; height: 40px; }

.notice { border-radius: var(--radius-sm); padding: 12px 14px; background: var(--warn-soft); color: var(--warn); font-size: 14px; }
.notice.info { background: var(--sel-soft); color: var(--sel); }

/* ---------- lists */
.list { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--border); }
.li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 52px; }
.li.click { cursor: pointer; }
.li.click:hover { background: var(--surface-2); }
.li .grow { flex: 1; min-width: 0; }
.li .word { font-size: 18px; }
.li .sub { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }
.lesson-body { padding: 4px 14px 14px; background: var(--surface-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 15px; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); cursor: pointer; }
.chip.learned { border-color: var(--good); }
.chip.static { cursor: default; }
.test-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.test-form label { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.test-form .wide { grid-column: 1 / -1; }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; position: absolute; inset: 0; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--sel); outline-offset: 2px; }

input[type="text"], input[type="search"], input[type="number"], select {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); font-size: 16px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--sel); outline-offset: 1px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px; }
.setting .text { flex: 1; min-width: 0; }
.setting .text div:last-child { font-size: 13px; color: var(--text-2); }
.setting select, .setting input[type="number"] { width: auto; min-width: 120px; }

/* ---------- study */
.study { max-width: 560px; margin: 0 auto; }
.study-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress { flex: 1; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.study-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 22px 20px; }
.step-label { font-size: 13px; color: var(--text-2); display: flex; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.prompt { text-align: center; margin: 10px 0 6px; }
.prompt .jp-big { font-size: clamp(34px, 9vw, 52px); line-height: 1.35; font-weight: 600; word-break: keep-all; overflow-wrap: anywhere; }
.prompt .en-big { font-size: clamp(22px, 6vw, 30px); font-weight: 650; line-height: 1.3; }
.prompt .hint { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.prompt-kind { text-align: center; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 6px; border-radius: 999px; margin: 0 auto 12px; width: max-content; padding: 4px 14px; }
.prompt-kind.meaning { background: var(--sel-soft); color: var(--sel); }
.prompt-kind.reading { background: var(--accent-soft); color: var(--accent); }
.prompt-kind.fill { background: var(--warn-soft); color: var(--warn); }
.options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.opt {
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm);
  min-height: 58px; padding: 10px 12px; cursor: pointer; text-align: left; display: flex; align-items: center; gap: 10px;
  font-size: 16px; line-height: 1.3; overflow-wrap: anywhere;
}
.opt:hover { background: var(--surface-2); }
.opt .num { font-size: 12px; color: var(--text-3); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; flex: none; }
.opt .jp-opt { font-size: 21px; display: block; }
.opt .opt-sub { font-size: 12px; color: var(--text-2); display: block; }
.opt.ok, .match .ok { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.opt.bad, .match .bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.opt.sel, .match .sel { background: var(--sel-soft); border-color: var(--sel); color: var(--sel); }
.opt[disabled] { cursor: default; }
.match { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 8px; }
.match button { border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); min-height: 54px; padding: 8px; cursor: pointer; font-size: 15px; overflow-wrap: anywhere; }
.match button.jp { font-size: 21px; }
.match button.done { opacity: .55; cursor: default; }
.answer-row { display: flex; gap: 8px; margin-top: 18px; }
.answer-row input { flex: 1; font-size: 20px; text-align: center; min-height: 54px; }
.answer-row input.ok { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.answer-row input.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.answer-row input.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.feedback { margin-top: 14px; border-radius: var(--radius-sm); padding: 12px 14px; font-size: 15px; }
.feedback.ok { background: var(--good-soft); color: var(--good); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback.info { background: var(--sel-soft); color: var(--sel); }
.feedback .detail { color: var(--text); margin-top: 6px; }
.study-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.sentence { font-size: 22px; line-height: 2; text-align: center; }
.sentence .blank { display: inline-block; min-width: 2.6em; border-bottom: 2px solid var(--text-2); margin: 0 4px; text-align: center; line-height: 1.4; }
.sentence .blank.filled { border-bottom-color: var(--good); color: var(--good); font-weight: 700; }
.meet .meaning { text-align: center; font-size: 22px; font-weight: 600; margin-top: 4px; }
.meet .reading { text-align: center; color: var(--text-2); font-size: 18px; }
.meet .meta { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.example { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 14px; }
.example .ex-jp { font-size: 19px; line-height: 2; }
.example .ex-en { color: var(--text-2); font-size: 15px; }
.explain p { margin: 0 0 10px; }
.pattern { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 17px; margin: 10px 0; overflow-wrap: anywhere; }
.summary-list .li { min-height: 44px; padding: 8px 14px; }

.modal-back { position: fixed; inset: 0; background: rgba(10, 8, 5, 0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
@media (min-width: 640px) { .modal-back { align-items: center; } }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 30; max-width: calc(100vw - 32px); }

/* Mnemonics and the learner's notes */
.mnemo-box { margin-top: 14px; text-align: left; }
.mnemo { background: var(--surface-2); color: var(--text); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px; }
.mnemo.mine { box-shadow: inset 3px 0 0 var(--sel); }
.mnemo.mine p { white-space: pre-line; }
.mnemo p { margin: 4px 0 0; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
.mnemo-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: 13px; }
.mnemo-tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; }
.mnemo-tag.ai { background: var(--warn-soft); color: var(--warn); }
.mnemo-tag.web { background: var(--good-soft); color: var(--text); box-shadow: inset 0 0 0 1px var(--good); }
.mnemo-tag a { color: inherit; }
.mnemo-syn { margin: 0 0 8px; overflow-wrap: anywhere; }
.mnemo-actions { text-align: center; }
.noted { color: var(--sel); white-space: nowrap; }
.notes-word { font-size: 20px; margin-bottom: 4px; overflow-wrap: anywhere; }
.notes-label { display: block; margin: 16px 0 6px; }
.notes-label span { display: block; font-weight: 400; }
.notes-modal textarea {
  width: 100%; min-height: 96px; padding: 10px 14px; border-radius: var(--radius-sm); resize: vertical;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-size: 16px; line-height: 1.45;
}
.notes-modal textarea:focus { outline: 2px solid var(--sel); outline-offset: 1px; }
.notes-add { display: flex; gap: 8px; margin-top: 10px; }
.notes-add input { flex: 1; min-width: 0; }

@media (max-width: 480px) {
  .study-card { padding: 18px 14px; }
  .options { gap: 8px; }
  .opt { min-height: 54px; padding: 8px 10px; }
  .brand small { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
