:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #15201e;
  --muted: #5d6b68;
  --border: #dde4e2;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d8efec;
  --ok: #15803d;
  --ok-soft: #dcf3e3;
  --ng: #c2410c;
  --ng-soft: #fde6da;
  --warn-soft: #fff4d6;
  --c-kenri: #2563eb;
  --c-gyoho: #0f766e;
  --c-seigen: #9333ea;
  --c-zei: #d97706;
  --c-menjo: #64748b;
  --shadow: 0 1px 2px rgb(16 24 22 / 6%), 0 2px 8px rgb(16 24 22 / 4%);
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1416; --surface: #121e20; --surface-2: #19282a; --text: #e5eeec; --muted: #93a3a0; --border: #24363a;
    --accent: #2dd4bf; --accent-ink: #062523; --accent-soft: #123a37; --ok: #4ade80; --ok-soft: #12301f; --ng: #fb923c; --ng-soft: #3a1f12; --warn-soft: #33290f;
    --c-kenri: #60a5fa; --c-gyoho: #2dd4bf; --c-seigen: #c084fc; --c-zei: #fbbf24; --c-menjo: #94a3b8;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1416; --surface: #121e20; --surface-2: #19282a; --text: #e5eeec; --muted: #93a3a0; --border: #24363a;
  --accent: #2dd4bf; --accent-ink: #062523; --accent-soft: #123a37; --ok: #4ade80; --ok-soft: #12301f; --ng: #fb923c; --ng-soft: #3a1f12; --warn-soft: #33290f;
  --c-kenri: #60a5fa; --c-gyoho: #2dd4bf; --c-seigen: #c084fc; --c-zei: #fbbf24; --c-menjo: #94a3b8;
  --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.7 system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }
code { font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.ic { width: 22px; height: 22px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.dim { opacity: .25; }
.ok { color: var(--ok); }
.ng { color: var(--ng); }

/* ヘッダー・ナビ */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; letter-spacing: .02em; }
.sync { padding: 8px; }
.sdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--border); flex: none; }
.sdot.ok { background: var(--ok); }
.sdot.syncing { background: var(--accent); animation: pulse 1s infinite alternate; }
.sdot.error { background: var(--ng); }
.sdot.offline { background: #eab308; }
@keyframes pulse { to { opacity: .3; } }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: .7rem; }
.nav a svg { width: 24px; height: 24px; }
.nav a.active { color: var(--accent); font-weight: 700; }

.main { max-width: 760px; margin: 0 auto; padding: 16px; }
.loading { text-align: center; color: var(--muted); padding: 40px; }

@media (min-width: 960px) {
  body { padding-bottom: 32px; padding-left: 220px; }
  .top { margin-left: -220px; padding-left: 20px; z-index: 40; }
  .nav {
    top: 0; right: auto; width: 220px; height: 100vh; flex-direction: column; justify-content: flex-start;
    padding: 72px 12px 12px; border-top: 0; border-right: 1px solid var(--border); gap: 4px; background: var(--surface);
  }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; border-radius: 10px; font-size: .95rem; }
  .nav a.active { background: var(--accent-soft); }
  .main { padding: 24px; }
}

/* 共通パーツ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h2 { font-size: 1rem; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.page-title { font-size: 1.4rem; margin: 4px 0 14px; }
.eyebrow { font-size: .8rem; color: var(--muted); }
.back { display: inline-block; margin-bottom: 10px; font-size: .9rem; color: var(--muted); }
.note { margin: -4px 4px 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 99px; color: var(--bc); background: color-mix(in srgb, var(--bc) 14%, transparent); white-space: nowrap; }
.badge.ghost { color: var(--muted); background: var(--surface-2); font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 18px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; text-align: center;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--ng); border-color: color-mix(in srgb, var(--ng) 40%, var(--border)); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .85rem; }
.btn.wide { width: 100%; margin-top: 16px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.flagged { color: #ca8a04; border-color: #ca8a04; }
.btn .ic { width: 18px; height: 18px; }
.iconbtn { border: 0; background: none; padding: 6px; cursor: pointer; color: var(--muted); border-radius: 8px; margin-left: auto; }
.iconbtn.on { color: #eab308; }
.iconbtn.on svg { fill: currentColor; }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin: 14px 0; align-items: center; }
.actions.left { justify-content: flex-start; margin: 10px 0 0; }
.actions.sticky {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(8px); padding: 10px 0; margin: 0;
}
@media (min-width: 960px) { .actions.sticky { bottom: 8px; } }
.hint { margin-right: auto; }

.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 4px; border: 0; border-bottom: 1px solid var(--border);
  background: none; color: var(--text); text-align: left; cursor: pointer; width: 100%;
}
.row:last-child { border-bottom: 0; }
.row > span { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.row small { display: block; width: 100%; color: var(--muted); font-size: .8rem; }
.row:hover { background: var(--surface-2); }
.chev { color: var(--muted); font-size: 1.4rem; }
.done, .undone { width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.done { background: var(--ok); color: #fff; }
.done .ic { width: 14px; height: 14px; stroke-width: 3; }
.undone { border: 2px solid var(--border); }

/* ホーム */
.hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%); }
.big { font-size: 1.5rem; font-weight: 700; }
.big b { font-size: 2.4rem; color: var(--accent); font-variant-numeric: tabular-nums; }
.ring {
  --p: 0; width: 96px; height: 96px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0);
}
.ring > div { width: 76px; height: 76px; border-radius: 50%; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.ring b { font-size: 1.5rem; }
.ring span { font-size: .7rem; color: var(--muted); }

.quick, .review-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.review-tiles { grid-template-columns: 1fr; }
@media (min-width: 600px) { .quick { grid-template-columns: repeat(4, 1fr); } .review-tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); color: var(--text); text-align: left; cursor: pointer; box-shadow: var(--shadow);
}
.tile .ic { color: var(--accent); }
.tile b { display: block; font-size: .95rem; }
.tile small { color: var(--muted); font-size: .78rem; }
.tile.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tile.primary .ic, .tile.primary small { color: inherit; opacity: .9; }
.tile:disabled { opacity: .5; cursor: default; }

.cats { display: flex; flex-direction: column; gap: 4px; }
.catrow { display: grid; grid-template-columns: 12px 1fr 2fr auto; align-items: center; gap: 10px; padding: 8px 4px; color: var(--text); border-radius: 8px; }
a.catrow:hover { background: var(--surface-2); }
.cname { font-size: .9rem; font-weight: 600; line-height: 1.3; }
.cname small { display: block; color: var(--muted); font-weight: 400; font-size: .72rem; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; }
.nums { text-align: right; line-height: 1.2; min-width: 64px; }
.nums small { display: block; color: var(--muted); font-size: .72rem; }
@media (max-width: 420px) { .catrow { grid-template-columns: 12px 1fr auto; } .catrow .bar { grid-column: 2 / 4; grid-row: 2; } }

.spark { display: flex; align-items: flex-end; gap: 4px; height: 110px; }
.spark .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.spark i { display: block; width: 100%; max-width: 22px; background: color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 4px 4px 2px 2px; }
.spark .hit i { background: var(--accent); }
.spark span { font-size: .65rem; color: var(--muted); }

/* 解説 */
.search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0 12px; margin-bottom: 14px; }
.search input { flex: 1; border: 0; background: none; padding: 12px 0; font: inherit; color: var(--text); outline: none; min-width: 0; }
.search .ic { color: var(--muted); }
.prose h1 { font-size: 1.45rem; margin: 6px 0 12px; }
.prose h3 { font-size: 1.05rem; margin: 22px 0 8px; padding-left: 10px; border-left: 4px solid var(--accent); }
.prose h4 { font-size: .98rem; margin: 16px 0 6px; }
.prose p, .prose li { font-size: .97rem; }
.prose ul, .prose ol { padding-left: 1.3em; margin: 8px 0; }
.prose strong { color: var(--accent); }
.prose mark { background: var(--warn-soft); color: inherit; }
.meta { display: flex; align-items: center; gap: 8px; }
.callout { background: var(--warn-soft); border-radius: 10px; padding: 10px 14px; margin: 14px 0; font-size: .92rem; }
.tbl { overflow-x: auto; margin: 10px 0; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; min-width: 420px; }
th, td { border: 1px solid var(--border); padding: 7px 9px; text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin: 8px 0 20px; font-size: .9rem; }

/* 演習フォーム */
.form label:not(.switch) { display: block; font-size: .82rem; font-weight: 700; color: var(--muted); margin: 14px 0 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button, .chips button {
  border: 1px solid var(--border); background: var(--surface); padding: 7px 14px; border-radius: 99px; cursor: pointer; font-size: .88rem; min-height: 38px;
}
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button.on { border-color: var(--bc); background: color-mix(in srgb, var(--bc) 14%, var(--surface)); color: var(--bc); font-weight: 700; }
.input, .select { width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); min-height: 44px; }
.switch { display: flex; align-items: center; gap: 10px; margin: 16px 0 4px; font-size: .95rem; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.mockcard { display: flex; align-items: center; gap: 12px; color: var(--text); }
.mockcard .ic { color: var(--accent); width: 28px; height: 28px; }
.mockcard span:not(.chev) { flex: 1; }
.mockcard small { display: block; color: var(--muted); font-size: .8rem; }

/* 問題 */
.quizbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.quizbar .back { margin: 0; }
.progress { height: 4px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-bottom: 12px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.qmeta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.qtext { font-size: 1.05rem; line-height: 1.85; margin: 4px 0 16px; }
.choices { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--border);
  background: var(--surface); cursor: pointer; line-height: 1.7; font-size: .97rem; transition: border-color .12s, background .12s;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice .num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; font-size: .85rem; margin-top: 1px; }
.choice.picked { border-color: var(--accent); background: var(--accent-soft); }
.choice.picked .num { background: var(--accent); color: var(--accent-ink); }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.correct .num { background: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--ng); background: var(--ng-soft); }
.choice.wrong .num { background: var(--ng); color: #fff; }
.choice.dim { opacity: .55; }
.choice:disabled { cursor: default; }
.tf { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tfbtn { flex-direction: column; align-items: center; gap: 0; padding: 14px; font-weight: 700; }
.tfbtn .mark { font-size: 2rem; line-height: 1.2; }
.explain { margin-top: 16px; border-radius: 12px; padding: 12px 14px; border-left: 4px solid; }
.explain.ok { background: var(--ok-soft); border-color: var(--ok); }
.explain.ng { background: var(--ng-soft); border-color: var(--ng); }
.explain p { margin: 6px 0; }
.verdict { font-weight: 800; font-size: 1.05rem; }
.explain.ok .verdict { color: var(--ok); }
.explain.ng .verdict { color: var(--ng); }

.result { text-align: center; padding: 28px 16px; }
.score { font-size: 1.4rem; margin: 6px 0; }
.score b { font-size: 3.2rem; color: var(--accent); font-variant-numeric: tabular-nums; }
details.rev { border-bottom: 1px solid var(--border); padding: 10px 0; }
details.rev summary { cursor: pointer; font-size: .9rem; list-style-position: inside; }
details.rev[open] summary { margin-bottom: 10px; }

/* 模試 */
.mockbar { position: sticky; top: calc(env(safe-area-inset-top) + 53px); z-index: 10; background: var(--bg); padding: 6px 0; }
.timer { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; font-size: 1.05rem; background: var(--surface); border: 1px solid var(--border); padding: 4px 10px; border-radius: 99px; }
.timer .ic { width: 18px; height: 18px; }
.timer.low { color: var(--ng); border-color: var(--ng); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; }
.grid button { min-height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .85rem; font-variant-numeric: tabular-nums; }
.grid button.ans { background: var(--accent-soft); border-color: var(--accent); }
.grid button.flag { box-shadow: inset 0 -3px 0 #eab308; }
.grid button.cur { outline: 2px solid var(--accent); outline-offset: 1px; font-weight: 800; }
.card.warn { background: var(--warn-soft); }

/* 設定 */
.syncstate { display: flex; align-items: center; gap: 8px; font-size: .9rem; margin: 10px 0; }
.keybox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.keybox code { font-size: 1rem; padding: 8px 10px; letter-spacing: .04em; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.keybox .input { flex: 1; min-width: 200px; font-family: ui-monospace, monospace; letter-spacing: .04em; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: .9rem; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 960px) { #toast { bottom: 24px; left: calc(50% + 110px); } }
