:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4e8;
  --text: #1c2128;
  --text-2: #4b5563;
  --muted: #6b7280;
  --accent: #2f6fde;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fd;
  --track: #e9ecf0;
  --ok: #1a7f4b;
  --ok-soft: #e6f4ec;
  --ng: #c62f2f;
  --ng-soft: #fbeaea;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #222730;
    --border: #2e343d;
    --text: #e6e8eb;
    --text-2: #b6bcc5;
    --muted: #8b939e;
    --accent: #6b9cf0;
    --accent-ink: #0d1420;
    --accent-soft: #1d2a40;
    --track: #2a3038;
    --ok: #4cc283;
    --ok-soft: #16301f;
    --ng: #f07070;
    --ng-soft: #3a1c1c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

h1, h2 { line-height: 1.4; }
h2 { font-size: 1rem; margin: 0 0 12px; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- ヘッダー ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
#exam-select {
  font: inherit;
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  overflow-x: auto;
}
.nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  white-space: nowrap;
  font-size: 0.92rem;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.badge {
  display: inline-block;
  min-width: 1.4em;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ng);
  color: #fff;
  font-size: 0.75rem;
  line-height: 1.6;
  text-align: center;
}

/* ---------- レイアウト ---------- */
.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}
.page-title { font-size: 1.4rem; margin: 0 0 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--ng); border-color: var(--ng); }
.btn.danger:hover { background: var(--ng-soft); }

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
}

.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.78rem;
}

/* ---------- ダッシュボード ---------- */
.hero { text-align: center; padding: 40px 20px; }
.hero h1 { font-size: 1.3rem; margin-top: 0; }

.tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.tile { margin: 0; padding: 16px; }
.tile-label { font-size: 0.8rem; color: var(--muted); }
.tile-value {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.tile-value small { font-size: 0.9rem; font-weight: 500; color: var(--text-2); }
.tile-sub { font-size: 0.8rem; color: var(--text-2); }

.cat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.cat-table th, .cat-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.cat-table thead th { font-size: 0.78rem; color: var(--muted); font-weight: 500; }
.cat-table tbody tr:last-child th, .cat-table tbody tr:last-child td { border-bottom: none; }
.cat-table th[scope="row"] { font-weight: 500; white-space: nowrap; }
.cat-table th[scope="row"] a { color: var(--text); text-decoration: none; }
.cat-table th[scope="row"] a:hover { color: var(--accent); text-decoration: underline; }
.cat-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-cell { width: 45%; }

.hbar {
  height: 10px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
  /* ツールチップの当たり判定を広げる */
  outline-offset: 4px;
  box-shadow: 0 0 0 6px transparent;
}
.hbar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.activity {
  display: flex;
  gap: 8px;
  height: 160px;
}
.activity-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-bottom: 22px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.activity-cols {
  flex: 1;
  display: flex;
  gap: 2px;
}
.col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-radius: 4px;
  cursor: default;
}
.col:hover .col-bar, .col:focus .col-bar { filter: brightness(1.15); }
.col:hover .col-plot, .col:focus .col-plot { background: var(--surface-2); }
.col:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.col-plot {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border-bottom: 1px solid var(--border);
  border-radius: 4px 4px 0 0;
}
.col-bar {
  width: 70%;
  max-width: 22px;
  min-height: 3px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
}
.col-empty { height: 0; }
.col-label {
  height: 22px;
  padding-top: 4px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  overflow: visible;
}

.tooltip {
  position: fixed;
  z-index: 100;
  max-width: 260px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-size: 0.8rem;
  line-height: 1.5;
  pointer-events: none;
}

/* ---------- 演習設定 ---------- */
.form fieldset {
  border: none;
  padding: 0;
  margin: 0 0 18px;
}
.form legend { font-weight: 700; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.9rem;
}
.chip span small { color: var(--muted); margin-left: 2px; }
.chip input:checked + span {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 解答画面 ---------- */
.quiz-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  color: var(--text-2);
  margin-bottom: 8px;
}
.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--track);
  margin-bottom: 16px;
  overflow: hidden;
}
.progress div {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}

.q-text { font-size: 1.05rem; font-weight: 600; margin: 12px 0 16px; white-space: pre-line; }
.review-q { white-space: pre-line; }
.tag-source { margin-left: 6px; background: var(--accent-soft); color: var(--accent); }

/* 過去問の図表（白背景の画像なのでダークモードでも白地で見せる） */
.q-figure {
  margin: 0 0 16px;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
}
.q-figure img { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.feedback .source { font-size: 0.78rem; color: var(--muted); margin-top: 10px; }

.choices {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}
.choice {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.choice:not(:disabled):hover { border-color: var(--accent); background: var(--accent-soft); }
.choice:disabled { cursor: default; }
.choice-label {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  font-weight: 700;
  font-size: 0.9rem;
}
.choice-text { flex: 1; padding-top: 1px; white-space: pre-line; }
.choice .mark { flex: none; font-weight: 700; font-size: 1.1rem; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.correct .choice-label { background: var(--ok); color: #fff; }
.choice.correct .mark { color: var(--ok); }
.choice.wrong { border-color: var(--ng); background: var(--ng-soft); }
.choice.wrong .choice-label { background: var(--ng); color: #fff; }
.choice.wrong .mark { color: var(--ng); }

.feedback {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 10px;
  border-left: 4px solid;
}
.feedback.ok { border-color: var(--ok); background: var(--ok-soft); }
.feedback.ok strong { color: var(--ok); }
.feedback.ng { border-color: var(--ng); background: var(--ng-soft); }
.feedback.ng strong { color: var(--ng); }
.feedback p { margin: 6px 0 0; color: var(--text); }

.glossary {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.glossary summary {
  padding: 10px 16px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
}
.glossary summary small { font-weight: 500; color: var(--muted); margin-left: 4px; }
.glossary dl { margin: 0; padding: 0 16px 8px; }
.glossary dl > div {
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.glossary dt { font-weight: 700; font-size: 0.88rem; color: var(--accent); }
.glossary dd { margin: 2px 0 0; font-size: 0.86rem; color: var(--text-2); line-height: 1.6; }

.next { margin-top: 16px; width: 100%; }
.hint { font-size: 0.82rem; margin: 12px 0 0; }

/* ---------- 結果 ---------- */
.result { text-align: center; }
.result h1 { margin-top: 0; font-size: 1.2rem; }
.score { font-size: 2.6rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.score small { font-size: 1rem; font-weight: 500; color: var(--text-2); }
.score-pct { color: var(--text-2); margin-bottom: 16px; }
.result-list {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: left;
}
.result-list li {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.result-list .mark { flex: none; font-weight: 700; }
.result-list .ok .mark { color: var(--ok); }
.result-list .ng .mark { color: var(--ng); }
.result .actions { justify-content: center; }

/* ---------- 復習 ---------- */
.review-list { list-style: none; padding: 0; margin: 0; }
.review-list li p { margin: 8px 0 0; }
.empty { text-align: center; padding: 32px 20px; }

.danger-zone h2 { color: var(--ng); }

.site-footer {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px 40px;
  font-size: 0.75rem;
  line-height: 1.7;
  color: var(--muted);
}

/* ---------- スマホ ---------- */
@media (max-width: 640px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .nav { margin-left: 0; width: 100%; gap: 2px; }
  .nav a { padding: 6px 8px; font-size: 0.85rem; }
  .bar-cell { width: 35%; }
  .cat-table thead th:last-child, .cat-table td:last-child { display: none; }
  .card { padding: 16px; }
}
