:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --sky: #0ea5e9;
  --s0: #9ca3af;   /* 未学習 */
  --s0-bg: #f3f4f6;
  --s1: #d97706;   /* 学習中 */
  --s1-bg: #fef3c7;
  --s2: #059669;   /* 習得 */
  --s2-bg: #d1fae5;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .05);
}

/* ---------- ダークモード（html[data-theme="dark"] で有効化） ---------- */
[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, .16);
  --s0: #94a3b8;
  --s0-bg: rgba(148, 163, 184, .12);
  --s1: #fbbf24;
  --s1-bg: rgba(251, 191, 36, .12);
  --s2: #34d399;
  --s2-bg: rgba(52, 211, 153, .12);
  --danger: #f87171;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
}
[data-theme="dark"] .notice,
[data-theme="dark"] .explain { background: rgba(245, 158, 11, .1); }
[data-theme="dark"] .choice.correct { background: rgba(52, 211, 153, .14); }
[data-theme="dark"] .choice.wrong { background: rgba(248, 113, 113, .14); }
[data-theme="dark"] .btn.danger { background: rgba(248, 113, 113, .15); }
[data-theme="dark"] .kanji-cell.k1, [data-theme="dark"] .vocab-cell.k1 { background: rgba(251, 191, 36, .08); border-color: #b45309; }
[data-theme="dark"] .kanji-cell.k2, [data-theme="dark"] .vocab-cell.k2 { background: rgba(52, 211, 153, .08); border-color: #059669; }
[data-theme="dark"] .chip.s0 { border-color: #475569; }
[data-theme="dark"] .chip.s1 { border-color: #b45309; }
[data-theme="dark"] .chip.s2 { border-color: #059669; }
[data-theme="dark"] .practice-card.warm { background: rgba(245, 158, 11, .09); }
[data-theme="dark"] .practice-card.pc-srs { background: rgba(52, 211, 153, .1); }
[data-theme="dark"] .card.longread { background: var(--card); }
[data-theme="dark"] .card.notebox { background: rgba(129, 140, 248, .12); }
[data-theme="dark"] .genre-chip, [data-theme="dark"] .long-chip, [data-theme="dark"] .sp-note {
  background: rgba(251, 191, 36, .12); color: #fbbf24; border-color: rgba(251, 191, 36, .4);
}
[data-theme="dark"] .cat-chip.cat-k { background: rgba(248, 113, 113, .15); color: #f87171; }
[data-theme="dark"] .cat-chip.cat-v { background: rgba(52, 211, 153, .15); color: #34d399; }
[data-theme="dark"] .cat-chip.cat-m { background: rgba(56, 189, 248, .15); color: #38bdf8; }
[data-theme="dark"] .vpos.p-verb { background: rgba(59, 130, 246, .18); color: #93c5fd; }
[data-theme="dark"] .vpos.p-adj { background: rgba(52, 211, 153, .15); color: #6ee7b7; }
[data-theme="dark"] .vpos.p-noun { background: rgba(148, 163, 184, .15); color: #cbd5e1; }
[data-theme="dark"] .vpos.p-adv { background: rgba(192, 132, 252, .16); color: #d8b4fe; }
[data-theme="dark"] .vpos.p-other { background: rgba(168, 162, 158, .15); color: #d6d3d1; }
[data-theme="dark"] #status-bar .sf0.active { background: rgba(148, 163, 184, .1); }
[data-theme="dark"] #status-bar .sf1.active { background: rgba(251, 191, 36, .1); }
[data-theme="dark"] #status-bar .sf2.active { background: rgba(52, 211, 153, .1); }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
  background: var(--card); color: var(--ink); border-color: var(--line);
}
[data-theme="dark"] .toast { background: #e2e8f0; color: #0f172a; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* キーボード操作でも どこに いるか 見えるように */
:focus-visible {
  outline: 3px solid #a5b4fc;
  outline-offset: 2px;
  border-radius: 6px;
}

.topbar {
  background: linear-gradient(120deg, #4338ca, #0284c7);
  color: #fff;
  padding: 14px 20px;
  box-shadow: 0 2px 12px rgba(49, 46, 129, .18);
}
.topbar .inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { font-size: 18px; font-weight: 700; text-decoration: none; color: #fff; }
.level-badge {
  background: rgba(255, 255, 255, .2);
  border: 1px solid rgba(255, 255, 255, .45);
  border-radius: 999px;
  padding: 1px 12px;
  font-size: 13px;
  font-weight: 700;
}
.topbar .spacer { flex: 1; }
.topbar a.nav { color: #e0e7ff; text-decoration: none; font-size: 14px; }
.topbar a.nav:hover { color: #fff; text-decoration: underline; }
.topbar .who { font-size: 14px; font-weight: 600; }

main { max-width: 1100px; margin: 24px auto 80px; padding: 0 20px; }

h1 { font-size: 24px; margin: 8px 0 4px; }
h2 { font-size: 18px; margin: 28px 0 12px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

/* ---------- カードグリッド（学習者選択） ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.student-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  border: 2px solid transparent;
  transition: border-color .15s, transform .15s;
}
.student-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.student-card .name { font-size: 17px; font-weight: 700; }
.student-card .note { color: var(--muted); font-size: 13px; margin-top: 4px; min-height: 1.5em; }
.search-box {
  width: 100%;
  max-width: 360px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  margin-bottom: 18px;
  font-family: inherit;
}
.search-box:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* ---------- ステータスチップ ---------- */
.chip {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 12px;
  font-size: 12.5px;
  font-weight: 700;
  border: 1.5px solid transparent;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.chip.s0 { color: var(--s0); background: var(--s0-bg); border-color: #d1d5db; }
.chip.s1 { color: var(--s1); background: var(--s1-bg); border-color: #fcd34d; }
.chip.s2 { color: var(--s2); background: var(--s2-bg); border-color: #6ee7b7; }
.chip.readonly { cursor: default; }

/* ---------- プログレスバー ---------- */
.bar {
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  position: relative;
}
.bar > .fill { height: 100%; background: linear-gradient(90deg, #10b981, #059669); border-radius: 999px; }
.bar > .fill.learning { background: linear-gradient(90deg, #fbbf24, #d97706); }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-row .bar { flex: 1; }
.bar-row .pct { font-size: 13px; color: var(--muted); min-width: 7em; text-align: right; }

/* ---------- 統計カード ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 800; }
.stat .value small { font-size: 14px; color: var(--muted); font-weight: 600; }

/* ---------- 単元 ---------- */
.unit { margin-bottom: 18px; }
.unit-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.unit-no {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 13px;
  border-radius: 8px;
  padding: 2px 10px;
}
.unit-title { font-size: 17px; font-weight: 700; }
.unit-desc { color: var(--muted); font-size: 13px; margin: 2px 0 10px; }
.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 4px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.item-row .pattern { font-weight: 700; font-size: 15.5px; text-decoration: none; color: var(--ink); min-width: 11em; }
.item-row .pattern:hover { color: var(--accent); }
.item-row .meaning { color: var(--muted); font-size: 13px; flex: 1; min-width: 12em; }
.item-row .quizacc { font-size: 12px; color: var(--muted); white-space: nowrap; }
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: opacity .15s, transform .06s;
}
.btn:hover { opacity: .9; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.small { padding: 4px 12px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { background: #fee2e2; color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- 文法詳細 ---------- */
.pattern-title { font-size: 28px; font-weight: 800; margin: 4px 0 2px; }
.section-label { font-size: 13px; font-weight: 800; color: var(--accent); margin: 18px 0 6px; letter-spacing: .05em; }
.connection-box {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 15px;
}
.meaning-en { color: var(--muted); font-size: 13.5px; margin-top: 6px; line-height: 1.6; }
.example { padding: 10px 0; border-bottom: 1px dashed var(--line); }
.example:last-child { border-bottom: none; }
.example .ja { font-size: 16px; }
.example .en { color: var(--muted); font-size: 13px; }
.status-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.status-buttons .chip { padding: 7px 18px; font-size: 14px; opacity: .45; }
.status-buttons .chip.selected { opacity: 1; box-shadow: 0 0 0 2px currentColor inset; }

/* ---------- 読解 ---------- */
.reading-card .section-label:first-child { margin-top: 0; }
.voc-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
.voc-row { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; border-bottom: 1px dotted var(--line); }
.voc-w { font-weight: 700; min-width: 7em; }
.voc-m { color: var(--muted); font-size: 13.5px; }
.passage { font-size: 17px; line-height: 2; }
.passage p { margin: 0 0 12px; }
.qnum { color: var(--accent); font-weight: 800; margin-right: 4px; }
@media (max-width: 640px) { .voc-list { grid-template-columns: 1fr; } }

/* ---------- 重厚な長文読解（じっくり読む） ---------- */
.longread-label { font-size: 15px; display: flex; align-items: center; gap: 10px; }
.genre-chip {
  display: inline-block; border-radius: 999px; padding: 2px 12px;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0;
  color: #92400e; background: #fef3c7; border: 1px solid #fcd34d;
}
.card.longread { border-left: 4px solid var(--accent); background: #fcfcff; }
.longread .passage { font-size: 17.5px; line-height: 2.05; }
.longread .passage p { text-indent: 1em; margin: 0 0 14px; }
.card.notebox { background: var(--accent-soft); padding-top: 12px; padding-bottom: 12px; }
.notebox .voc-w { min-width: 8em; }
.note-label { margin-top: 0; }
.long-chip {
  display: inline-block; margin-left: 8px; border-radius: 6px;
  padding: 1px 8px; font-size: 11px; font-weight: 800; white-space: nowrap;
  color: #92400e; background: #fef3c7;
}
/* 二段組（長文）：本文は ページと 一緒に スクロール、問題だけ 右に 固定（sticky） */
.longread-layout { display: flex; gap: 18px; align-items: flex-start; }
.longread-layout .lr-passage { flex: 1 1 56%; min-width: 0; }
.longread-layout .lr-questions {
  flex: 0 0 42%; min-width: 0;
  position: sticky; top: 12px; align-self: flex-start;
  max-height: calc(100vh - 24px); overflow-y: auto;
}
.q-group { display: grid; gap: 10px; }
.lr-controls { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.kana-toggle { padding: 5px 14px; font-size: 13px; }
/* 通常ドリル：内部スクロールは 使わず、ページ全体の スクロールに 任せる（間を 詰める） */
.rd-row { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 4px; }
.rd-row .rd-passage { flex: 1 1 52%; min-width: 0; }
.rd-row .rd-questions { flex: 1 1 48%; min-width: 0; }
/* 唯一のスクロール枠（長文の問題）だけ スクロールバーを 細く */
.lr-questions {
  scrollbar-width: thin;
  scrollbar-color: #c7d2fe transparent;
  padding-right: 4px;
}
.lr-questions::-webkit-scrollbar { width: 8px; }
.lr-questions::-webkit-scrollbar-thumb { background: #c7d2fe; border-radius: 8px; }
.lr-questions::-webkit-scrollbar-track { background: transparent; }
@media (max-width: 860px) {
  .rd-row { display: block; }
  .rd-row .rd-questions { margin-top: 14px; }
  .longread-layout { display: block; }
  .longread-layout .lr-questions {
    position: static; max-height: none; overflow: visible; margin-top: 18px;
  }
}

/* ---------- クイズ ---------- */
.q-meta { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
/* カテゴリチップ（文法=g 漢字=k 語彙=v 文字=m） */
.cat-chip {
  display: inline-block;
  border-radius: 6px;
  padding: 1px 9px;
  font-size: 11.5px;
  font-weight: 800;
  white-space: nowrap;
  flex: none;
}
.cat-chip.cat-g { color: var(--accent); background: var(--accent-soft); }
.cat-chip.cat-k { color: #b91c1c; background: #fee2e2; }
.cat-chip.cat-v { color: #047857; background: #d1fae5; }
.cat-chip.cat-m { color: #0369a1; background: #e0f2fe; }
.item-row .cat-chip { margin-right: 8px; }
.quiz-q { font-size: 18px; margin: 10px 0 18px; }
.choices { display: grid; gap: 10px; }
.choice {
  text-align: left;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice.correct { border-color: var(--s2); background: var(--s2-bg); font-weight: 700; }
.choice.wrong { border-color: var(--danger); background: #fee2e2; }
.explain {
  margin-top: 14px;
  background: #fffbeb;
  border-left: 4px solid #f59e0b;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
}
.quiz-progress { color: var(--muted); font-size: 13.5px; font-weight: 700; }
.score-big { font-size: 44px; font-weight: 800; text-align: center; margin: 10px 0; }

/* ---------- 練習タブ ---------- */
.practice-modes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.practice-card {
  display: block;
  text-decoration: none;
  color: inherit;
  text-align: center;
  border: 2px solid transparent;
  transition: border-color .15s, transform .15s;
}
a.practice-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.practice-card.warm { background: #fffbeb; }
.practice-card.pc-srs { background: #ecfdf5; }
a.practice-card.warm:hover { border-color: var(--s1); }
.practice-card.disabled { opacity: .55; }
.practice-card .pc-emoji { font-size: 30px; line-height: 1.2; }
.practice-card .pc-title { font-size: 18px; font-weight: 800; margin-top: 4px; }
.practice-card .pc-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.practice-unit { text-decoration: none; color: inherit; }
.practice-unit:hover { background: var(--accent-soft); border-radius: 8px; }
.practice-unit .practice-go { color: var(--accent); font-weight: 800; font-size: 13px; }

/* ---------- フラッシュカード ---------- */
.flash-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 260px;
  max-width: 520px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  padding: 30px;
  border: 2px solid transparent;
  transition: border-color .12s;
  user-select: none;
}
.flash-card:hover { border-color: var(--accent); }
.flash-card .fc-front { font-size: 52px; font-weight: 800; line-height: 1.3; }
.flash-card .fc-back .fc-read { font-size: 22px; color: var(--accent); font-weight: 700; }
.flash-card .fc-back .fc-mean { font-size: 20px; font-weight: 700; margin-top: 8px; }
.flash-card .fc-back .fc-words { font-size: 14px; color: var(--muted); margin-top: 10px; }
.fc-btns { display: flex; gap: 12px; justify-content: center; margin-top: 6px; flex-wrap: wrap; }

/* ---------- 特集（カタカナ語・オノマトペ） ---------- */
.sp-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.sp-row:last-child { border-bottom: none; }
.sp-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.sp-word { font-size: 18px; font-weight: 800; }
.sp-mean { color: var(--muted); font-size: 13.5px; }
.sp-note { font-size: 12.5px; color: #92400e; background: #fffbeb; border-radius: 6px; padding: 2px 10px; display: inline-block; margin-top: 4px; }
.sp-ex { font-size: 15px; margin-top: 4px; }

/* ---------- 文型くらべ ---------- */
.cmp-row { display: flex; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.cmp-row:last-child { border-bottom: none; }
.cmp-pattern { flex: 0 0 11em; font-weight: 800; font-size: 16px; }
.cmp-pattern a { color: var(--accent); text-decoration: none; }
.cmp-pattern a:hover { text-decoration: underline; }
.cmp-body { flex: 1; min-width: 16em; }
.cmp-use { font-size: 14px; }
.cmp-ex { font-size: 14.5px; color: var(--muted); margin-top: 3px; }
.cmp-links { display: flex; flex-direction: column; gap: 6px; }
.cmp-links a { text-decoration: none; color: var(--ink); font-weight: 700; }
.cmp-links a:hover { color: var(--accent); }

/* ---------- 用語解説 ---------- */
.gloss-row { align-items: baseline; }
.gloss-term { font-weight: 700; font-size: 15.5px; min-width: 11em; }
.gloss-term small { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.gloss-desc { color: var(--ink); font-size: 14px; flex: 1; min-width: 14em; line-height: 1.6; }

/* ---------- テーブル（先生用） ---------- */
.table-wrap { overflow-x: auto; }
table.matrix { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.matrix th, .matrix td { padding: 8px 10px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
.matrix th { color: var(--muted); font-size: 12px; font-weight: 700; }
.matrix td.name-cell { text-align: left; font-weight: 700; cursor: pointer; }
.matrix td.name-cell:hover { color: var(--accent); text-decoration: underline; }
.matrix .heat { border-radius: 6px; font-weight: 700; }
/* 習得率ヒートマップ（heat-l0=0%台 → heat-l5=100%）。ライト＝白→緑、文字色も段階ごとに確保 */
.heat-l0 { background: hsl(152 45% 96%); color: hsl(152 60% 28%); }
.heat-l1 { background: hsl(152 48% 88%); color: hsl(152 60% 24%); }
.heat-l2 { background: hsl(152 50% 76%); color: hsl(152 65% 18%); }
.heat-l3 { background: hsl(152 55% 62%); color: hsl(152 80% 12%); }
.heat-l4 { background: hsl(152 60% 45%); color: #fff; }
.heat-l5 { background: hsl(152 70% 34%); color: #fff; }
/* ダーク＝暗い緑→明るい緑。進むほど明るく光る方向で、文字は常にコントラスト確保 */
[data-theme="dark"] .heat-l0 { background: hsl(152 24% 17%); color: hsl(152 45% 72%); }
[data-theme="dark"] .heat-l1 { background: hsl(152 30% 22%); color: hsl(152 50% 76%); }
[data-theme="dark"] .heat-l2 { background: hsl(152 36% 27%); color: hsl(152 60% 82%); }
[data-theme="dark"] .heat-l3 { background: hsl(152 45% 33%); color: hsl(150 70% 92%); }
[data-theme="dark"] .heat-l4 { background: hsl(152 55% 41%); color: hsl(152 90% 10%); }
[data-theme="dark"] .heat-l5 { background: hsl(152 65% 50%); color: hsl(152 90% 8%); }
tr.selected-row { outline: 2px solid var(--accent); outline-offset: -2px; }

.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.form-row input {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
}
.form-row input.name { width: 180px; }
.form-row input.note { flex: 1; min-width: 220px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt0 { margin-top: 0; }
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  border-radius: 10px;
  padding: 10px 22px;
  font-size: 14px;
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: .92; }

.archived-row { opacity: .55; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 10px 0; }
.legend .chip { cursor: default; }

/* ---------- タブ ---------- */
.tabs { display: flex; gap: 8px; margin: 4px 0 18px; flex-wrap: wrap; row-gap: 8px; }
.tab-btn {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 8px 24px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color .12s, color .12s, background .12s;
}
.tab-btn:hover:not(.active) { border-color: #c7d2fe; color: var(--accent); }
.tab-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.tab-btn.lvl { padding: 6px 16px; font-size: 13.5px; }
/* 状態フィルタの色分け（選択時） */
#status-bar .sf0.active { border-color: var(--s0); color: var(--s0); background: #f8fafc; }
#status-bar .sf1.active { border-color: #fcd34d; color: var(--s1); background: #fffbeb; }
#status-bar .sf2.active { border-color: #6ee7b7; color: var(--s2); background: #ecfdf5; }

/* ---------- 漢字グリッド ---------- */
.kanji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.kanji-cell {
  position: relative;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 6px 6px;
  text-align: center;
  cursor: pointer;
  background: var(--card);
  user-select: none;
  transition: border-color .12s, box-shadow .12s;
}
.kanji-cell:hover { box-shadow: 0 2px 8px rgba(79, 70, 229, .12); }
.kanji-cell .kmark {
  position: absolute;
  top: 3px;
  right: 3px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}
.kanji-cell .kmark:hover { border-color: var(--accent); color: var(--accent); }
.kanji-cell:hover { border-color: var(--accent); }
.kanji-cell .kchar { font-size: 30px; font-weight: 700; line-height: 1.25; }
.kanji-cell .kread { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kanji-cell .kword { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kanji-cell .kstat { font-size: 10px; font-weight: 700; margin-top: 2px; color: var(--s0); }
.kanji-cell.k1 { border-color: #fcd34d; background: #fffbeb; }
.kanji-cell.k1 .kstat { color: var(--s1); }
.kanji-cell.k2 { border-color: #6ee7b7; background: #ecfdf5; }
.kanji-cell.k2 .kstat { color: var(--s2); }

/* ---------- 語彙グリッド ---------- */
.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.vocab-cell {
  position: relative;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px 6px;
  cursor: pointer;
  background: var(--card);
  user-select: none;
  transition: border-color .12s, box-shadow .12s;
}
.vocab-cell:hover { box-shadow: 0 2px 8px rgba(79, 70, 229, .12); }
.vocab-cell:hover { border-color: var(--accent); }
.vocab-cell .vtop { display: flex; justify-content: space-between; align-items: center; min-height: 18px; margin-bottom: 2px; }
.vocab-cell .vword { font-size: 16.5px; font-weight: 700; line-height: 1.4; }
.vocab-cell .vnote { font-size: 10px; color: var(--muted); margin-top: 1px; line-height: 1.3; }
.vocab-cell .vmark {
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}
.vocab-cell .vmark:hover { border-color: var(--accent); color: var(--accent); }
.vpos {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
}
.vpos.p-verb  { background: #e0edff; color: #1d4ed8; }
.vpos.p-adj   { background: #dcfce7; color: #15803d; }
.vpos.p-noun  { background: #f1f5f9; color: #475569; }
.vpos.p-adv   { background: #f3e8ff; color: #7e22ce; }
.vpos.p-other { background: #f5f5f4; color: #78716c; }
.vocab-cell .vread { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vocab-cell .vmean { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vocab-cell .vstat { font-size: 10px; font-weight: 700; margin-top: 2px; color: var(--s0); }
.vocab-cell.k1 { border-color: #fcd34d; background: #fffbeb; }
.vocab-cell.k1 .vstat { color: var(--s1); }
.vocab-cell.k2 { border-color: #6ee7b7; background: #ecfdf5; }
.vocab-cell.k2 .vstat { color: var(--s2); }

.level-chip {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  padding: 1px 8px;
  font-size: 11.5px;
  font-weight: 800;
  white-space: nowrap;
}
.level-head { display: flex; align-items: center; gap: 10px; margin: 26px 0 10px; }
.level-head h2 { margin: 0; }
.notice {
  background: #fffbeb;
  border-left: 4px solid #f59e0b;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
}
.form-row select {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
}

@media (max-width: 640px) {
  .item-row .pattern { min-width: 100%; }
  .stat .value { font-size: 22px; }
  .kanji-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}

/* ---------- 先生用ログイン（コピーから取り込み） ---------- */
.topbar .nav-button {
  background: transparent;
  border: 0;
  color: #e0e7ff;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  padding: 0;
}
.topbar .nav-button:hover { color: #fff; text-decoration: underline; }

.auth-main {
  max-width: 460px;
  margin-top: 56px;
}
.auth-card { padding: 24px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 6px;
}
.auth-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 18px;
  font-family: inherit;
  letter-spacing: .08em;
}
.auth-input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
.form-error {
  min-height: 1.5em;
  margin: 8px 0 12px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}
.auth-submit { width: 100%; text-align: center; }

/* ---------- 漢字 詳細オーバーレイ ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-card {
  position: relative;
  background: var(--card);
  border-radius: 16px;
  padding: 22px 24px 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
  text-align: center;
  max-height: calc(100vh - 48px);   /* 例文が多い字でも 画面から はみ出さない */
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #c7d2fe transparent;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.modal-card .kd-char { font-size: 56px; font-weight: 700; line-height: 1.1; }
.modal-card .kd-read { font-size: 14px; color: var(--muted); margin-top: 6px; }
.modal-card .kd-mean { font-size: 15px; font-weight: 700; margin-top: 2px; }
.modal-card .section-label { margin: 16px 0 6px; text-align: left; }
.modal-card .kd-words { display: flex; flex-wrap: wrap; gap: 8px; }
.modal-card .kd-word {
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 15px;
  font-weight: 700;
}
.modal-card .kd-word small { font-weight: 400; color: var(--muted); }
.modal-card .kd-ex { text-align: left; font-size: 16px; line-height: 1.6; margin-top: 4px; }
.modal-card .kd-ex-en { text-align: left; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.modal-card .kd-extag {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  border-radius: 6px;
  padding: 1px 7px;
  margin-right: 8px;
  vertical-align: middle;
}
.modal-card .kd-bushu {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
  font-weight: 700;
}
