:root {
  color-scheme: light;
  --paper: #f5f4ef;
  --surface: #fbfaf6;
  --ink: #222824;
  --muted: #687069;
  --line: #cfd3cc;
  --line-strong: #9fa79f;
  --accent: #245b49;
  --accent-soft: #e2ebe5;
  --accent-strong: #173f32;
  --reference: #2f5d8a;
  --reference-soft: #e4edf5;
  --measured: #9a5a20;
  --measured-soft: #f6eadf;
  --danger: #9b2f2f;
  --danger-soft: #f8e9e7;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); line-height: 1.65; }
button, input { font: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.eyebrow,
.section-kicker {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: .78rem;
  font-weight: 780;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h2 { margin: 0; font-size: clamp(1.2rem, 2vw, 1.48rem); line-height: 1.35; }

.tool-shell {
  display: grid;
  grid-template-columns: minmax(0, .98fr) minmax(0, 1.02fr);
  border: 1px solid var(--line-strong);
  background: var(--surface);
}

.calculator-panel,
.visual-panel { min-width: 0; padding: 24px; }
.calculator-panel { border-right: 1px solid var(--line); }
.section-heading { margin-bottom: 15px; }

.input-fieldset { display: grid; gap: 15px; margin: 16px 0 0; padding: 0; border: 0; }
.input-fieldset legend { margin-bottom: 8px; font-weight: 760; }
.input-row { min-width: 0; }
.input-row label { display: block; margin-bottom: 5px; font-weight: 720; }
.input-row input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--surface);
}
.input-row input[aria-invalid="true"] { border-color: var(--danger); background: #fff8f8; }
.field-help { margin: 4px 0 0; color: var(--muted); font-size: .78rem; }
.field-error { min-height: 1.25em; margin: 2px 0 0; color: var(--danger); font-size: .82rem; }

.form-error {
  margin: 12px 0 0;
  padding: 8px 10px;
  border-left: 4px solid var(--danger);
  background: var(--danger-soft);
  color: #762525;
}
.form-error[hidden] { display: none; }
.form-actions { display: flex; gap: 8px; margin-top: 17px; }
.button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 2px;
  padding: 8px 15px;
  cursor: pointer;
  font-weight: 760;
}
.button-primary { background: var(--accent); color: #fff; }
.button-primary:hover { background: var(--accent-strong); }
.button-secondary { background: var(--surface); color: var(--accent); }
.button:hover:not(:disabled) { border-color: var(--ink); }

.result-box {
  margin-top: 20px;
  padding: 15px 16px;
  border: 1px solid var(--accent);
  border-left-width: 4px;
  background: var(--accent-soft);
}
.result-box[data-state="error"] { border-color: var(--danger); background: var(--danger-soft); }
.result-label { margin: 0; color: var(--accent); font-size: .8rem; font-weight: 780; }
.result-box[data-state="error"] .result-label { color: var(--danger); }
.result-value {
  display: block;
  margin-top: 2px;
  font-size: clamp(1.35rem, 3vw, 1.95rem);
  line-height: 1.28;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.result-status { margin: 5px 0 0; color: #3f4c46; font-size: .9rem; overflow-wrap: anywhere; }

.result-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 14px;
  border-top: 1px solid rgba(36, 91, 73, .35);
  border-left: 1px solid rgba(36, 91, 73, .35);
}
.result-metrics[hidden] { display: none; }
.result-metrics article { min-width: 0; padding: 10px; border-right: 1px solid rgba(36, 91, 73, .35); border-bottom: 1px solid rgba(36, 91, 73, .35); }
.result-metrics h3 { margin: 0; color: var(--muted); font-size: .76rem; }
.metric-value { margin: 2px 0 0; font-size: 1.02rem; font-weight: 780; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-meaning { margin: 3px 0 0; color: #455048; font-size: .78rem; overflow-wrap: anywhere; }

.result-details {
  display: grid;
  margin: 14px 0 0;
  border-top: 1px solid rgba(36, 91, 73, .35);
  border-left: 1px solid rgba(36, 91, 73, .35);
}
.result-details[hidden] { display: none; }
.result-details > div { min-width: 0; padding: 9px 10px; border-right: 1px solid rgba(36, 91, 73, .35); border-bottom: 1px solid rgba(36, 91, 73, .35); }
.result-details dt { color: var(--muted); font-size: .76rem; font-weight: 760; }
.result-details dd { margin: 2px 0 0; font-size: .85rem; font-weight: 620; overflow-wrap: anywhere; }
.step-list { margin: 5px 0 0; padding-left: 1.35rem; }
.step-list li + li { margin-top: 3px; }

.visual-heading-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.status-badge {
  flex: 0 0 auto;
  padding: 3px 8px;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--muted);
  font-size: .75rem;
  font-weight: 760;
}
.status-badge[data-state="ready"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.visual-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 15px 0 0;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.visual-metrics div { min-width: 0; padding: 9px 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.visual-metrics dt { color: var(--muted); font-size: .75rem; font-weight: 750; }
.visual-metrics dd { margin: 2px 0 0; font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.error-figure {
  --reference-position: 32%;
  --measured-position: 68%;
  --band-left: 32%;
  --band-width: 36%;
  margin: 15px 0 0;
  padding: 18px 14px 14px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, #fbfaf6 0%, #f0efe9 100%);
}
.number-line { position: relative; width: 100%; height: 220px; overflow: hidden; }
.axis-line { position: absolute; left: 7%; right: 7%; top: 126px; height: 3px; background: var(--line-strong); }
.axis-line::before,
.axis-line::after { content: ""; position: absolute; top: -5px; width: 2px; height: 13px; background: var(--line-strong); }
.axis-line::before { left: 0; }
.axis-line::after { right: 0; }
.axis-end { position: absolute; top: 132px; color: var(--muted); font-size: .82rem; font-weight: 760; }
.axis-end-left { left: 6%; }
.axis-end-right { right: 6%; }
.error-band {
  position: absolute;
  left: var(--band-left);
  top: 121px;
  width: max(var(--band-width), 8px);
  height: 13px;
  border-left: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
  background: rgba(36, 91, 73, .26);
  transform-origin: center;
}
.error-band::before,
.error-band::after { content: ""; position: absolute; top: 4px; width: 6px; height: 6px; border-top: 2px solid var(--accent); border-right: 2px solid var(--accent); }
.error-band::before { left: 2px; transform: rotate(-135deg); }
.error-band::after { right: 2px; transform: rotate(45deg); }

.marker {
  position: absolute;
  top: 32px;
  width: min(32%, 170px);
  min-width: 92px;
  transform: translateX(-50%);
  text-align: center;
}
.marker-reference { left: var(--reference-position); color: var(--reference); }
.marker-measured { left: var(--measured-position); color: var(--measured); }
.marker-label {
  display: inline-block;
  max-width: 100%;
  padding: 3px 6px;
  border: 1px solid currentColor;
  background: var(--surface);
  font-size: .78rem;
  font-weight: 760;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.marker-line { display: block; width: 2px; height: 57px; margin: 0 auto; background: currentColor; }
.marker-dot { display: block; width: 14px; height: 14px; margin: -1px auto 0; border: 3px solid var(--surface); border-radius: 50%; background: currentColor; box-shadow: 0 0 0 2px currentColor; }
.error-figure[data-direction="equal"] .marker {
  left: 50%;
  width: 14px;
  min-width: 14px;
}
.error-figure[data-direction="equal"] .marker-label {
  position: absolute;
  top: 0;
  width: min(34vw, 155px);
  max-width: none;
}
.error-figure[data-direction="equal"] .marker-reference .marker-label { right: 12px; }
.error-figure[data-direction="equal"] .marker-measured .marker-label { left: 12px; }
.error-figure[data-direction="equal"] .marker-line { margin-top: 30px; }
.error-figure[data-direction="equal"] .marker-reference .marker-dot {
  width: 22px;
  height: 22px;
  margin-top: -5px;
  margin-left: -4px;
  background: var(--surface);
}
.error-figure[data-direction="equal"] .error-band { left: calc(50% - 5px); width: 10px; border-radius: 50%; }
.error-figure[data-state="waiting"] .marker,
.error-figure[data-state="waiting"] .error-band { visibility: hidden; }
.visual-caption { margin: 0; color: var(--muted); font-size: .82rem; text-align: center; overflow-wrap: anywhere; }
.visual-description { margin: 11px 0 0; color: #38413b; font-size: .9rem; }
.scale-note { margin: 7px 0 0; padding-left: 11px; border-left: 3px solid var(--line-strong); color: var(--muted); font-size: .78rem; }

.content-section { margin-top: 30px; padding-top: 25px; border-top: 1px solid var(--line-strong); }
.formula-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.formula-list article { min-width: 0; display: grid; gap: 3px; padding: 12px 13px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.formula-list strong { overflow-wrap: anywhere; }
.formula-list span { color: var(--muted); }
.proof-guide { margin-top: 18px; border: 1px solid var(--line); }
.proof-guide h3 { margin: 0; padding: 10px 13px; border-bottom: 1px solid var(--line); color: var(--accent); font-size: .92rem; }
.proof-guide ul { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; padding: 0; list-style: none; }
.proof-guide li { min-width: 0; padding: 10px 13px 10px 30px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); font-size: .86rem; overflow-wrap: anywhere; }
.proof-guide li:nth-child(2n) { border-right: 0; }
.proof-guide li:nth-last-child(-n + 2) { border-bottom: 0; }
.proof-guide li::before { content: "—"; margin-left: -17px; margin-right: 7px; color: var(--accent); }

@media (max-width: 900px) {
  .tool-shell { grid-template-columns: 1fr; }
  .calculator-panel { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media (max-width: 620px) {
  .calculator-panel,
  .visual-panel { padding: 17px 14px; }
  .form-actions { display: grid; grid-template-columns: 1fr; }
  .button { width: 100%; }
  .result-metrics,
  .formula-list,
  .proof-guide ul { grid-template-columns: 1fr; }
  .formula-list article,
  .proof-guide li,
  .proof-guide li:nth-child(2n),
  .proof-guide li:nth-last-child(-n + 2) { border-right: 0; border-bottom: 1px solid var(--line); }
  .formula-list article:last-child,
  .proof-guide li:last-child { border-bottom: 0; }
  .visual-metrics { grid-template-columns: 1fr; }
  .number-line { height: 208px; }
  .marker { width: 32%; min-width: 78px; }
  .marker-label { font-size: .72rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
