:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --ink: #1d1c1a;
  --muted: #5f5c55;
  --line: #e2dfd7;
  --accent: #b13a2e;
  --accent-ink: #ffffff;
  --ok: #2f6b3f;
  --ok-bg: #e6f2e8;
  --warn: #8a5a00;
  --warn-bg: #fbf0d6;
  --idle-bg: #efede7;
  --focus: #1f5fbf;
  --radius: 10px;
  --jp: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, system-ui, sans-serif;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, var(--jp);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --surface: #201f1c;
    --ink: #efede7;
    --muted: #aaa69c;
    --line: #36342f;
    --accent: #e0685c;
    --accent-ink: #1a0b09;
    --ok: #8fd19e;
    --ok-bg: #1d3323;
    --warn: #f0c36a;
    --warn-bg: #3a2f14;
    --idle-bg: #2a2925;
    --focus: #7db0ff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5; }
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 64px; outline: none; }
h1 { font-size: 1.6rem; margin: 0.2em 0 0.4em; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 0.6em; }
p { margin: 0.4em 0; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.jp { font-family: var(--jp); }

.site-header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; min-height: 56px; }
.brand { font-family: var(--jp); font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--ink); }
.brand span { font-weight: 500; color: var(--muted); font-size: 0.9rem; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { text-decoration: none; color: var(--ink); padding: 8px 12px; border-radius: 8px; font-size: 0.95rem; }
nav a:hover { background: var(--idle-bg); }
nav a[aria-current="page"] { background: var(--idle-bg); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.badge[hidden] { display: none; }
.badge { display: inline-block; min-width: 1.4em; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 0.75rem; text-align: center; font-weight: 700; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; }
.card > :first-child { margin-top: 0; }
.grid2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .grid2 { grid-template-columns: 1fr 1fr; } }

button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 8px; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { background: var(--idle-bg); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--accent); }
button.link { border: 0; background: none; padding: 2px 4px; color: var(--accent); text-decoration: underline; }
button[disabled] { opacity: 0.5; cursor: not-allowed; }
input[type="text"], textarea, select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; max-width: 100%; }
input[type="text"], textarea { width: 100%; }
textarea { min-height: 120px; font-family: var(--jp); }
label { display: block; font-weight: 600; font-size: 0.9rem; margin: 10px 0 4px; }
label.inline { display: inline-flex; gap: 8px; align-items: center; font-weight: 400; margin: 0; }
input[type="checkbox"] { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); flex: none; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }

progress { width: 100%; height: 12px; accent-color: var(--accent); }

.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: var(--idle-bg); color: var(--muted); white-space: nowrap; }
.chip.in-progress { background: var(--warn-bg); color: var(--warn); }
.chip.mastered { background: var(--ok-bg); color: var(--ok); }
.tag { display: inline-block; font-size: 0.78rem; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }

.chapters { list-style: none; margin: 0; padding: 0; }
.chapters li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.chapters li:first-child { border-top: 0; }
.chapters a.name { font-weight: 600; color: var(--ink); text-decoration: none; }
.chapters a.name:hover { text-decoration: underline; }
.chapters .meta { grid-column: 1 / -1; font-size: 0.85rem; color: var(--muted); }

ol.stages, ul.gates, ul.plain { list-style: none; padding: 0; margin: 0; }
.stages li, .gates li { padding: 10px 0; border-top: 1px solid var(--line); }
.stages li:first-child, .gates li:first-child { border-top: 0; }
.stages p, .gates p { margin: 2px 0 0 1.9rem; }
.gates li.pass strong { color: var(--ok); }
.banner { background: var(--ok-bg); color: var(--ok); border-radius: 8px; padding: 10px 14px; font-weight: 600; margin-bottom: 12px; }

.qlist li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); }
.qlist li:first-child { border-top: 0; }
.qlist .qtext { flex: 1; }
.qlist li.answered .qtext { color: var(--muted); text-decoration: line-through; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 8px 8px; border-top: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; border-top: 0; }
td.jp-cell { font-family: var(--jp); font-size: 1.05rem; }
td .reading { display: block; font-size: 0.8rem; color: var(--muted); font-family: var(--jp); }

.flash { text-align: center; padding: 28px 12px; }
.flash .dir { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; }
.flash .prompt { font-family: var(--jp); font-size: clamp(2rem, 8vw, 3.4rem); margin: 14px 0; line-height: 1.25; word-break: break-word; }
.flash .answer { font-size: 1.3rem; margin: 10px 0 18px; font-family: var(--jp); }
.flash .answer .reading { display: block; color: var(--muted); font-size: 1rem; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-width: 520px; margin: 0 auto; }
.grades button { padding: 12px 4px; }
.grades kbd, kbd { font-size: 0.75rem; color: var(--muted); display: block; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: 90vw; z-index: 20; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--accent); color: var(--accent-ink); }

@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
