:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f0eee7;
  --text: #1f2326;
  --muted: #5f666d;
  --border: #d9d6cc;
  --accent: #2f6b4f;
  --accent-text: #ffffff;
  --link: #22603f;
  --trace: #1d3b57;
  --integral: #b45309;
  --ok: #15803d;
  --ok-bg: #e7f5ec;
  --ng: #b91c1c;
  --ng-bg: #fbeaea;
  --warn: #92400e;
  --warn-bg: #fdf1dc;
  --region-0: rgba(59, 130, 246, 0.10);
  --region-1: rgba(22, 163, 74, 0.10);
  --region-2: rgba(234, 88, 12, 0.10);
  --region-3: rgba(147, 51, 234, 0.10);
  --region-4: rgba(220, 38, 38, 0.10);
  --region-5: rgba(8, 145, 178, 0.12);
  --sel: rgba(29, 59, 87, 0.12);
  --radius: 10px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181b;
    --surface: #1d2125;
    --surface-2: #252a2f;
    --text: #e6e8ea;
    --muted: #9aa3ab;
    --border: #353b42;
    --accent: #5fae86;
    --accent-text: #0e1a14;
    --link: #7cc9a0;
    --trace: #a9cdf0;
    --integral: #f0b45a;
    --ok: #4ade80;
    --ok-bg: #16301f;
    --ng: #f87171;
    --ng-bg: #3a1c1c;
    --warn: #fbbf24;
    --warn-bg: #3a2e14;
    --sel: rgba(169, 205, 240, 0.15);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.8;
}
a { color: var(--link); }
main { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }
h1 { font-size: 1.75rem; line-height: 1.4; margin: 0.5em 0 0.6em; }
h2 { font-size: 1.3rem; line-height: 1.4; margin: 2em 0 0.6em; padding-bottom: 0.25em; border-bottom: 1px solid var(--border); }
h3 { font-size: 1.08rem; margin: 1.6em 0 0.4em; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
sub, sup { line-height: 0; }

/* ---- ヘッダー・フッター ---- */
.site-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 20px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px;
  background: var(--accent); color: var(--accent-text); font-family: serif; font-style: italic;
}
.site-header nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.site-header nav a { color: var(--muted); text-decoration: none; padding: 2px 0; border-bottom: 2px solid transparent; }
.site-header nav a:hover, .site-header nav a.active { color: var(--text); border-bottom-color: var(--accent); }
.site-footer { max-width: 960px; margin: 0 auto; padding: 24px 16px 40px; font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--border); }

.lesson-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 0.9rem; margin: 8px 0; flex-wrap: wrap; }
.lesson-nav:last-child { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---- 本文の部品 ---- */
.lead { font-size: 1.08rem; color: var(--muted); }
.box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; margin: 1.2em 0; }
.box > :first-child { margin-top: 0; }
.box > :last-child { margin-bottom: 0; }
.box.easy { border-left: 4px solid var(--accent); }
.box.easy::before { content: "ひとことで言うと"; display: block; font-weight: 700; font-size: 0.85rem; color: var(--accent); margin-bottom: 4px; }
.box.point { border-left: 4px solid var(--trace); }
.box.caution { border-left: 4px solid var(--warn); background: var(--warn-bg); }
table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: 0.93rem; display: block; overflow-x: auto; }
th, td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
th { background: var(--surface-2); white-space: nowrap; }
.structures { display: flex; flex-wrap: wrap; gap: 12px; margin: 1em 0; }
.structures figure, figure[data-smiles] { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; text-align: center; max-width: 100%; }
figure svg.mol { max-width: 100%; height: auto; }
figcaption { font-size: 0.85rem; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 1.2em 0; }
.card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; color: var(--text); text-decoration: none; }
.card:hover { border-color: var(--accent); }
.card strong { display: block; margin-bottom: 4px; }
.card span { font-size: 0.9rem; color: var(--muted); }
.lesson-list { padding-left: 1.5em; }
.lesson-list li { margin: 4px 0; }

/* ---- ビューア ---- */
.viewer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 1.2em 0; }
.viewer-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 12px; }
.viewer-title .meta { color: var(--muted); font-size: 0.85rem; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; cursor: help; }
.badge.sim { background: var(--surface-2); }
.badge.real, .badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-bg); }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
button {
  font: inherit; font-size: 0.85rem; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 3px 10px; cursor: pointer; line-height: 1.6;
}
button:hover { border-color: var(--accent); }
button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); padding: 6px 16px; font-size: 0.95rem; }
button.link { background: none; border: none; color: var(--link); text-decoration: underline; padding: 0 4px; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.readout { font-family: var(--mono); font-size: 0.82rem; color: var(--muted); margin-left: auto; }
.plot-wrap { position: relative; }
svg.plot { width: 100%; height: auto; display: block; touch-action: none; user-select: none; cursor: crosshair; }
svg.plot .trace { fill: none; stroke: var(--trace); stroke-width: 1.3; stroke-linejoin: round; }
svg.plot .integral-curve { fill: none; stroke: var(--integral); stroke-width: 1.4; }
svg.plot .axis { stroke: var(--text); stroke-width: 1; }
svg.plot .grid { stroke: var(--border); stroke-width: 0.6; }
svg.plot .frame { fill: none; stroke: var(--border); }
svg.plot text { fill: var(--text); font-family: var(--font); }
svg.plot .tick { font-size: 12px; fill: var(--muted); }
svg.plot .axis-title { font-size: 12px; fill: var(--muted); }
svg.plot .peak-label { font-size: 11.5px; font-weight: 600; }
svg.plot .region-label { font-size: 11px; fill: var(--muted); }
svg.plot .region.r0 { fill: var(--region-0); }
svg.plot .region.r1 { fill: var(--region-1); }
svg.plot .region.r2 { fill: var(--region-2); }
svg.plot .region.r3 { fill: var(--region-3); }
svg.plot .region.r4 { fill: var(--region-4); }
svg.plot .region.r5 { fill: var(--region-5); }
svg.plot .sel { fill: var(--sel); stroke: var(--trace); stroke-dasharray: 4 3; }
svg.plot .sel.int { fill: rgba(180, 83, 9, 0.12); stroke: var(--integral); }
svg.plot .int-bar { fill: var(--integral); opacity: 0.7; }
svg.plot .int-label { font-size: 12px; fill: var(--integral); font-weight: 700; }
svg.plot .mark { stroke-width: 2; stroke-dasharray: 5 3; }
svg.plot .mark.ok, svg.plot .mark2d.ok { stroke: var(--ok); }
svg.plot .mark.ng, svg.plot .mark2d.ng { stroke: var(--ng); }
svg.plot .mark.target, svg.plot .mark2d.target { stroke: var(--ok); stroke-dasharray: none; }
svg.plot .mark2d { fill: none; stroke-width: 2.5; }
.tip {
  position: absolute; z-index: 5; max-width: 240px; pointer-events: none; font-size: 0.82rem; line-height: 1.5;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}
.tip[hidden] { display: none; }
.integrals { font-size: 0.88rem; }
.integrals ul { margin: 4px 0; padding-left: 1.2em; }
.ref-input { width: 5em; font: inherit; font-size: 0.85rem; padding: 0 4px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 4px; }
.viewer-desc { font-size: 0.92rem; margin: 6px 0; }
details.source { font-size: 0.82rem; color: var(--muted); }
details.source summary { cursor: pointer; }
details.source ul { padding-left: 1.2em; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.82rem; margin-top: 6px; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ---- 演習 ---- */
.set-list { list-style: none; padding: 0; display: grid; gap: 10px; }
.set-btn { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; text-align: left; padding: 12px 16px; background: var(--surface); font-size: 1rem; }
.set-btn .bar { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.set-btn .bar span { display: block; height: 100%; background: var(--accent); }
.q-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: 0.9rem; }
.prompt { font-size: 1.1rem; font-weight: 600; }
.choices { display: grid; gap: 8px; margin: 12px 0; }
.choice { text-align: left; font-size: 0.97rem; padding: 10px 14px; background: var(--surface); }
.choice.correct { border-color: var(--ok); background: var(--ok-bg); }
.choice.wrong { border-color: var(--ng); background: var(--ng-bg); }
.choice:disabled { cursor: default; color: var(--text); }
.feedback { margin: 12px 0; padding: 0; }
.feedback.ok, .feedback.ng { padding: 10px 14px; border-radius: var(--radius); }
.feedback.ok { background: var(--ok-bg); border: 1px solid var(--ok); }
.feedback.ng { background: var(--ng-bg); border: 1px solid var(--ng); }
.feedback.ok strong { color: var(--ok); }
.feedback.ng strong { color: var(--ng); }
.feedback p { margin: 6px 0 0; }

.catalog-select { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.catalog-select select { font: inherit; padding: 4px 8px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; max-width: 100%; }

@media (max-width: 600px) {
  body { font-size: 15px; }
  h1 { font-size: 1.45rem; }
  .readout { margin-left: 0; width: 100%; }
}
