:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f3f1ec;
  --text: #1f2328;
  --muted: #5d636b;
  --border: #e2ded6;
  --accent: #2f5fb3;
  --accent-soft: #e8eefa;
  --sin: #c2410c;
  --cos: #0f766e;
  --tan: #6d28d9;
  --warn-bg: #fff7e6;
  --warn-border: #f0c36d;
  --radius: 10px;
  --maxw: 920px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1c1f23;
    --surface-2: #23272c;
    --text: #e6e6e3;
    --muted: #9ba1a8;
    --border: #33383e;
    --accent: #7aa2f7;
    --accent-soft: #1f2a40;
    --sin: #fb923c;
    --cos: #2dd4bf;
    --tan: #a78bfa;
    --warn-bg: #2b2414;
    --warn-border: #7a5c1f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1c1f23;
  --surface-2: #23272c;
  --text: #e6e6e3;
  --muted: #9ba1a8;
  --border: #33383e;
  --accent: #7aa2f7;
  --accent-soft: #1f2a40;
  --sin: #fb923c;
  --cos: #2dd4bf;
  --tan: #a78bfa;
  --warn-bg: #2b2414;
  --warn-border: #7a5c1f;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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.8;
  font-size: 16px;
}

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

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.site-header .inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}
.site-title {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  font-size: 1.1rem;
}
.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  margin-right: 12px;
}
.site-header nav a:hover { color: var(--accent); }
.site-header nav a[aria-current="page"] { color: var(--text); font-weight: 700; }
.sub-nav {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.sub-nav .inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 6px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  font-size: 0.88rem;
}
.site-header .sub-nav a { margin-right: 0; }
.site-header .sub-nav a.sub-home { color: var(--accent); font-weight: 700; }
.site-header .sub-nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 4px;
}

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px 16px 80px;
}

h1 { font-size: 1.8rem; line-height: 1.4; margin: 8px 0 4px; }
h2 {
  font-size: 1.35rem;
  margin: 48px 0 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
}
h3 { font-size: 1.1rem; margin: 28px 0 8px; }
.lead { color: var(--muted); margin-top: 0; }

.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  margin: 20px 0;
}
.toc ol { margin: 4px 0; padding-left: 1.4em; }

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

.formula {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 8px 16px;
  margin: 12px 0;
  overflow-x: auto;
}
.formula .label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}
.note {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.93rem;
}

details.proof {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 8px 0 16px;
  background: var(--surface);
}
details.proof summary {
  cursor: pointer;
  padding: 6px 14px;
  color: var(--accent);
  font-size: 0.93rem;
}
details.proof .body { padding: 0 16px 10px; overflow-x: auto; }

.tag {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  color: #fff;
  vertical-align: middle;
}
.tag.sin { background: var(--sin); }
.tag.cos { background: var(--cos); }
.tag.tan { background: var(--tan); }

/* table */
.table-wrap { overflow-x: auto; margin: 12px 0; }
table.formulas {
  border-collapse: collapse;
  width: 100%;
  background: var(--surface);
  font-size: 0.95rem;
}
table.formulas th, table.formulas td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: middle;
}
table.formulas th { background: var(--surface-2); white-space: nowrap; }
table.formulas td.n { text-align: center; white-space: nowrap; font-weight: 600; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.tabs button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 4px 14px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
}
.tabs button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* calculator */
.calc-controls {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.calc-controls label { font-weight: 600; font-size: 0.93rem; }
.calc-controls input[type="number"] {
  width: 90px;
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
.step-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 1.1rem;
}
.calc-output { margin-top: 12px; overflow-x: auto; }
.calc-output h4 {
  margin: 16px 0 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

.rat-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.rat-inputs label { font-weight: 600; font-size: 0.93rem; display: flex; flex-direction: column; gap: 4px; }
.rat-inputs input {
  font: inherit;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
.examples { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.examples button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 6px;
  padding: 2px 10px;
  cursor: pointer;
  font-size: 0.85rem;
}
.examples button:hover { border-color: var(--accent); }
code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

@media (max-width: 600px) {
  .rat-inputs { grid-template-columns: 1fr; }
}

/* 面積計算ツール */
.coef-grid { display: flex; flex-direction: column; gap: 8px; }
.coef-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.coef-row > span { display: inline-flex; align-items: center; gap: 6px; }
.coef-row input {
  width: 64px;
  font: inherit;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
.coef-name { font-weight: 700; min-width: 48px; }
.coef-name.f { color: var(--sin); }
.coef-name.g { color: var(--cos); }
.plot-wrap { margin: 12px 0 4px; }
.plot-wrap svg {
  width: 100%;
  height: auto;
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.plot-f { fill: none; stroke: var(--sin); stroke-width: 2.5; }
.plot-g { fill: none; stroke: var(--cos); stroke-width: 2.5; }
.plot-region { fill: var(--accent); fill-opacity: 0.22; stroke: none; }
.plot-pt { fill: var(--text); }
.plot-guide { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }
.plot-label { fill: var(--muted); font-size: 13px; font-family: inherit; }
.plot-f-text { fill: var(--sin); font-weight: 700; }
.plot-g-text { fill: var(--cos); font-weight: 700; }

.calc-controls [hidden] { display: none; }

.vol-inputs { grid-template-columns: 2fr 1fr 1fr; }
.plot-caption { font-size: 0.82rem; color: var(--muted); margin: 4px 0 0; }
.plot-caption .plot-f-text { color: var(--sin); font-weight: 700; }
.plot-caption .plot-rot-text { color: var(--accent); font-weight: 700; }
.plot-axis { stroke: var(--muted); stroke-width: 1; }
.plot-axis-rot { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 8 4; }
.plot-mirror { fill: var(--accent); fill-opacity: 0.08; stroke: var(--accent); stroke-opacity: 0.6; stroke-dasharray: 4 4; }
@media (max-width: 600px) {
  .vol-inputs { grid-template-columns: 1fr 1fr; }
  .vol-inputs label:first-child { grid-column: 1 / -1; }
}

.topic-list { list-style: none; padding: 0; }
.topic-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 10px 0;
}
.topic-list li.soon { opacity: 0.55; }
.topic-list a { font-weight: 700; font-size: 1.05rem; text-decoration: none; }
.topic-list p { margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }
.field-title { font-weight: 700; font-size: 1.05rem; }
.badge {
  display: inline-block;
  margin-left: 10px;
  font-size: 0.75rem;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  vertical-align: 2px;
}
.badge.ok { border-color: var(--accent); color: var(--accent); }

.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
/* KaTeX の不可視 MathML（position:absolute）がスクロール枠の外にはみ出さないように */
.katex-display, .formula, .table-wrap, .calc-output, details.proof .body, .katex { position: relative; }

footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 20px 16px;
}

@media (max-width: 600px) {
  h1 { font-size: 1.45rem; }
  .card { padding: 12px 14px; }
  .formula { padding: 6px 10px; }
}
