/* ===== 色（ライト / ダーク） ===== */
:root {
  color-scheme: light;
  --bg: #f5f8fb;
  --surface: #ffffff;
  --text: #17212e;
  --muted: #5a6a7e;
  --border: #dbe3ec;
  --accent: #1d64c8;
  --accent-2: #0b8f72;
  --accent-soft: #e8f1fd;
  --ok: #0a8a5f;
  --ok-bg: #e5f6ef;
  --ng: #c93a3a;
  --ng-bg: #fcebeb;
  --grad: linear-gradient(135deg, #1d64c8, #0b8f72);
  --shadow: 0 1px 2px rgba(20, 40, 70, .06), 0 4px 14px rgba(20, 40, 70, .05);
  --radius: 14px;
  /* 図の塗り(n型・p型・絶縁膜・金属・空乏層・帯・不良) */
  --fig-n: #d6e6fb;
  --fig-p: #fde6d4;
  --fig-ox: #fff1b8;
  --fig-metal: #c7d0db;
  --fig-dep: #f1f4f8;
  --fig-band: #e3ecf7;
  --fig-ng: #f6c9c9;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d1520;
    --surface: #152131;
    --text: #e4ebf3;
    --muted: #93a3b7;
    --border: #273649;
    --accent: #6aa9ff;
    --accent-2: #3cc9a3;
    --accent-soft: #1a2c44;
    --ok: #46d19c;
    --ok-bg: #12332a;
    --ng: #ff7b7b;
    --ng-bg: #3a1e24;
    --shadow: none;
    --fig-n: #1d3557;
    --fig-p: #4a2f22;
    --fig-ox: #4d4420;
    --fig-metal: #3a4656;
    --fig-dep: #1b2533;
    --fig-band: #1f2d40;
    --fig-ng: #5a2a2e;
  }
}

/* ===== 基本 ===== */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 17px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  line-height: 1.75;
  overflow-wrap: anywhere;
}
a { color: var(--accent); }
h1 { font-size: 1.55rem; line-height: 1.4; margin: 1.2rem 0 .6rem; }
h2 { font-size: 1.25rem; line-height: 1.45; margin: 2rem 0 .8rem; }
h3 { font-size: 1.05rem; margin: 1.4rem 0 .6rem; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 760px; margin: 0 auto; padding-inline: 16px; }
main.wrap { padding-block: 8px 48px; min-height: 60vh; }
.muted { color: var(--muted); }
.lead { font-size: 1.05rem; color: var(--muted); }

/* ===== ヘッダー・フッター ===== */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; flex-wrap: wrap; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; font-size: .95rem; }
.logo-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--grad); flex: none; }
.header-nav { display: flex; gap: 4px; margin-left: auto; }
.header-nav a { padding: 8px 12px; border-radius: 10px; text-decoration: none; font-size: .9rem; font-weight: 600; }
.header-nav a:hover, .header-nav a[aria-current] { background: var(--accent-soft); }
.lang-switch { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; font-size: .8rem; font-weight: 600; }
.lang-switch a, .lang-switch span { padding: 6px 10px; text-decoration: none; }
.lang-switch a:hover { background: var(--accent-soft); }
.lang-switch span { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 560px) {
  .header-inner { padding-block: 8px; }
  .header-nav { order: 3; width: 100%; margin-left: 0; justify-content: space-between; }
  .header-nav a { flex: 1 1 auto; padding-inline: 8px; text-align: center; white-space: nowrap; }
}

.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding-block: 24px; font-size: .85rem; color: var(--muted); }
.unofficial { margin-top: 0; }
.footer-nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.footer-nav a { color: var(--muted); padding-block: 6px; }
.copyright { margin-bottom: 0; }

/* ===== ボタン ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 52px; padding: 0 24px; border-radius: 12px;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  border: 2px solid transparent;
}
.btn-primary { background: var(--grad); color: #fff; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: var(--surface); color: var(--accent); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-block { display: flex; width: 100%; }

/* ===== トップ ===== */
.hero h1 { font-size: 1.75rem; margin-top: 1.6rem; }
.notice {
  font-size: .85rem; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent-2);
  border-radius: 10px; padding: 10px 14px;
}
.group-title { display: flex; align-items: center; gap: 8px; }
.group-title::before { content: ""; width: 4px; height: 1.1em; border-radius: 2px; background: var(--grad); }

/* モードカード */
.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin: 1rem 0; }
.mode-card {
  display: flex; flex-direction: column; gap: 2px; justify-content: center;
  min-height: 76px; padding: 14px 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none;
}
.mode-card strong { font-size: 1.05rem; color: var(--accent); }
.mode-card span { font-size: .85rem; color: var(--muted); line-height: 1.5; }
.mode-card:hover { border-color: var(--accent); }
.mode-card.primary { background: var(--grad); border-color: transparent; }
.mode-card.primary strong, .mode-card.primary span { color: #fff; }

/* 分野カード */
.cat-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 10px; }
.cat-card {
  display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  height: 100%; min-height: 84px; padding: 12px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none;
}
.cat-card:hover { border-color: var(--accent); }
.cat-name { font-weight: 700; line-height: 1.45; }
.cat-meta { display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); }
.cat-meta b { color: var(--accent-2); }

/* ===== 分野ページ ===== */
.breadcrumb { font-size: .85rem; color: var(--muted); margin-top: 1rem; }
.stat-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 1rem 0; }
@media (min-width: 600px) { .stat-tiles { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); } }
.tile { display: flex; flex-direction: column; padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.tile-num { font-size: 1.6rem; font-weight: 800; line-height: 1.3; color: var(--accent); }
.tile-num small { font-size: .9rem; color: var(--muted); font-weight: 600; }
.tile-label { font-size: .8rem; color: var(--muted); }
.prose p, .prose li { line-height: 1.9; }

/* ===== クイズ ===== */
.quiz { padding-top: 12px; }
.quiz-head { display: flex; justify-content: space-between; gap: 12px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.quiz-title { flex: 1; min-width: 0; }
.quiz-count { font-variant-numeric: tabular-nums; }
.quiz-quit {
  margin: -6px -8px -6px 0; padding: 6px 8px; border: 0; border-radius: 8px; background: none;
  color: var(--muted); font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.quiz-quit:hover { color: var(--text); background: var(--accent-soft); }
.progress { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; margin: 8px 0 16px; }
.progress-bar { height: 100%; background: var(--grad); transition: width .3s; }
.q-cat { display: inline-block; margin: 0; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .8rem; font-weight: 700; }
.q-text { font-size: 1.2rem; line-height: 1.75; margin: .6rem 0 1.2rem; }

.choices { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: flex-start; gap: 12px; width: 100%;
  min-height: 58px; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); color: var(--text); border: 2px solid var(--border);
  font: inherit; text-align: left; line-height: 1.6; cursor: pointer;
}
.choice:not(:disabled):hover { border-color: var(--accent); }
.choice:disabled { cursor: default; }
.choice:disabled:not(.correct):not(.wrong):not(.selected) { opacity: .55; }
.choice-mark {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: .9rem;
}
.choice-text { padding-top: 1px; }
.choice.correct { border-color: var(--ok); background: var(--ok-bg); }
.choice.correct .choice-mark { background: var(--ok); color: var(--surface); }
.choice.wrong { border-color: var(--ng); background: var(--ng-bg); }
.choice.wrong .choice-mark { background: var(--ng); color: var(--surface); }
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }

.feedback { margin-top: 16px; padding: 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--border); }
.feedback.ok { border-left-color: var(--ok); }
.feedback.ng { border-left-color: var(--ng); }
.verdict { margin: 0 0 6px; font-size: 1.15rem; font-weight: 800; }
.verdict.ok { color: var(--ok); }
.verdict.ng { color: var(--ng); }
.explanation { white-space: pre-wrap; line-height: 1.85; }

/* 結果 */
.result { text-align: center; padding: 16px; margin-top: 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.result h1 { margin-top: .2rem; }
.score { margin: 0; font-size: 1.1rem; }
.score b { font-size: 3.2rem; line-height: 1.1; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.score-pct { margin: 0; font-weight: 700; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 12px; }
.actions .btn { flex: 1 1 240px; }

.review { list-style: none; padding: 0; display: grid; gap: 10px; }
.review > li { border-radius: 12px; background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--ok); }
.review > li.ng { border-left-color: var(--ng); }
.review summary { display: flex; gap: 10px; padding: 12px 14px; cursor: pointer; font-weight: 600; line-height: 1.6; }
.review .badge { flex: none; font-weight: 800; color: var(--ok); }
.review .ng .badge { color: var(--ng); }
.review details > :not(summary) { margin-inline: 14px; }
.review-choices { padding-left: 0; list-style: none; font-size: .95rem; }
.review-choices li { padding: 4px 0; }
.review-choices .is-answer { color: var(--ok); font-weight: 700; }
.review-choices .is-chosen { color: var(--ng); }

.term-link { text-decoration-style: dotted; text-underline-offset: 3px; }
.q-report { margin: 4px 0 8px; font-size: .82rem; text-align: right; }
.report-link { color: var(--muted); }

/* ===== 問題ページ ===== */
.q-page { padding-top: 8px; }
.q-choices { list-style: none; padding: 0; display: grid; gap: 10px; }
.q-choices li {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 2px solid var(--border); line-height: 1.6;
}
.q-answer { margin-top: 16px; padding: 4px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--ok); }
.q-answer summary { padding: 10px 0; cursor: pointer; font-weight: 700; color: var(--accent); }
.q-answer .verdict { font-size: 1.05rem; }
.q-list { padding-left: 1.6em; display: grid; gap: 6px; line-height: 1.6; }
/* 図(data/figures/*.svg)。色はクラスで指定し、ダークモードでも読めるようにする */
.fig { margin: 12px 0; padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.fig svg { display: block; width: 100%; height: auto; max-width: 560px; margin: 0 auto; }
.fig text { fill: var(--text); font-size: 15px; font-family: inherit; }
.fig text.sm { font-size: 13px; }
.fig text.m { fill: var(--muted); }
.fig text.a { fill: var(--accent); font-weight: 700; }
.fig .ln { stroke: var(--text); stroke-width: 2; fill: none; }
.fig .thin { stroke: var(--muted); stroke-width: 1.2; fill: none; }
.fig .dash { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 6 4; fill: none; }
.fig .ac { stroke: var(--accent); stroke-width: 3; fill: none; }
.fig .ac2 { stroke: var(--accent-2); stroke-width: 3; fill: none; }
.fig .ink { fill: var(--text); }
.fig .fa { fill: var(--accent); }
.fig .fa2 { fill: var(--accent-2); }
.fig .hole { fill: var(--surface); stroke: var(--text); stroke-width: 1.5; }
.fig .n { fill: var(--fig-n); stroke: var(--muted); }
.fig .p { fill: var(--fig-p); stroke: var(--muted); }
.fig .ox { fill: var(--fig-ox); stroke: var(--muted); }
.fig .metal { fill: var(--fig-metal); stroke: var(--muted); }
.fig .dep { fill: var(--fig-dep); stroke: var(--muted); stroke-dasharray: 4 3; }
.fig .band { fill: var(--fig-band); }
.fig .ng { fill: var(--fig-ng); stroke: var(--muted); }
.fig .ok { fill: var(--surface); stroke: var(--muted); }
.choice-notes { padding-left: 0; list-style: none; font-size: .92rem; line-height: 1.7; color: var(--muted); }
.choice-notes li { padding: 3px 0; }

/* 難易度の絞り込み・今日の復習・バックアップ */
.level-filter { display: flex; flex-wrap: wrap; gap: 6px; margin: 1rem 0 0; }
.chip { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .88rem; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.review-due .btn { width: 100%; }
.backup { display: flex; flex-wrap: wrap; gap: 10px; }

/* ===== 学習コース・連続学習 ===== */
.streak { margin: .2rem 0 0; font-weight: 700; color: var(--accent-2); }
.mode-card.done { opacity: .75; }
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin: 1rem 0; }
.course-card {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text); text-decoration: none;
}
.course-card:hover { border-color: var(--accent); }
.course-card strong { color: var(--accent); font-size: 1.02rem; }
.course-card > span:nth-of-type(1) { font-size: .85rem; color: var(--muted); line-height: 1.55; flex: 1; }
.course-meta { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); }
.course-meta b { color: var(--text); font-variant-numeric: tabular-nums; }
.course-card .meter, .course-progress .meter { display: block; }
.course-progress { margin: 1rem 0; }
.course-progress-text { margin: 0 0 6px; font-weight: 700; }
.course-next { padding: 14px 16px; border-radius: 12px; background: var(--accent-soft); margin: 1rem 0; }
.course-next p { margin: 0 0 8px; }
.course-next p:last-child { margin-bottom: 0; }
.course-next-label { font-size: .85rem; font-weight: 700; color: var(--accent); }
.course-next-name { font-size: 1.15rem; font-weight: 800; }
.course-steps { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: 8px; counter-reset: step; }
.course-step {
  counter-increment: step; position: relative; padding: 12px 14px 12px 52px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
}
.course-step::before {
  content: counter(step); position: absolute; left: 14px; top: 12px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: .85rem; font-weight: 800; background: var(--border); color: var(--text);
}
.course-step.done::before { content: "✓"; background: var(--ok); color: #fff; }
.course-step.next { border: 2px solid var(--accent); }
.course-step.next::before { background: var(--accent); color: #fff; }
.course-step a { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; text-decoration: none; }
.step-status { font-size: .8rem; color: var(--ok); }
.step-meta { display: block; font-size: .8rem; color: var(--muted); margin-top: 2px; }

/* ===== 成績 ===== */
.stat-rows { display: grid; gap: 2px; }
.stat-row {
  display: grid; grid-template-columns: 1fr 3.2em; grid-template-areas: "name pct" "meter meter" "sub sub";
  gap: 2px 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border);
}
.stat-name { grid-area: name; font-weight: 600; text-decoration: none; }
.meter { grid-area: meter; height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.meter-bar { height: 100%; background: var(--grad); }
.stat-pct { grid-area: pct; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { grid-area: sub; font-size: .8rem; color: var(--muted); }
@media (min-width: 600px) {
  .stat-row { grid-template-columns: 11em 1fr 3.2em 7.5em; grid-template-areas: "name meter pct sub"; }
  .stat-sub { text-align: right; }
}
.diagnosis .cat-grid { margin-top: 10px; }
.diag-cats { margin-top: 1.5rem; }
.diag-cats summary { cursor: pointer; font-weight: 700; }
.diag-cats h3 { font-size: .95rem; margin: 1rem 0 .3rem; }
.diag-cats ul { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 16px; }
.diag-cats li { display: flex; gap: 8px; font-size: .92rem; }
.diag-cats .badge { font-weight: 800; color: var(--ok); }
.diag-cats .ng .badge { color: var(--ng); }
.history { list-style: none; padding: 0; }
.history li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.history li span:nth-child(2) { flex: 1; }

/* ===== 用語集 ===== */
.search { display: flex; align-items: center; gap: 12px; margin: 1rem 0; }
.search input {
  flex: 1; min-width: 0; min-height: 52px; padding: 0 16px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
.search input:focus { border-color: var(--accent); outline: none; }
.glossary { margin: 0; display: grid; gap: 10px; }
.term { padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); scroll-margin-top: 16px; }
.term:target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.term dt { font-weight: 800; font-size: 1.05rem; }
.term dt small { margin-left: 8px; font-weight: 400; font-size: .78rem; color: var(--muted); }
.term dd { margin: 4px 0 0; line-height: 1.8; }
.glossary-nav { margin: 1rem 0 1.5rem; display: grid; gap: 10px; }
.glossary-nav p { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.glossary-nav b { margin-right: 4px; font-size: .9rem; }
.glossary-nav .chip { text-decoration: none; }
.glossary-nav .chip small { color: var(--muted); }
.glossary-group > h2 { margin: 2rem 0 .5rem; }
.glossary-cat { scroll-margin-top: 16px; }
.glossary-cat h3 { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin: 1.25rem 0 .6rem; }
.glossary-cat h3 a { font-size: .85rem; font-weight: 400; }

/* ===== 広告枠 ===== */
.ad-slot { margin: 28px 0; }
[data-ad-ph] .ad-slot {
  display: grid; place-items: center; min-height: 100px; border-radius: 12px;
  border: 2px dashed var(--border); color: var(--muted); font-size: .8rem;
}

/* ===== 多言語 ===== */
.logo small { display: block; font-size: .68rem; font-weight: 600; color: var(--muted); letter-spacing: .02em; line-height: 1.2; }
.logo small:empty { display: none; }
