:root {
  color-scheme: light;
  --paper: #f5f4ef;
  --surface: #fbfaf6;
  --ink: #222824;
  --muted: #687069;
  --line: #cfd3cc;
  --line-strong: #9fa79f;
  --accent: #245b49;
  --accent-dark: #173f32;
  --accent-soft: #e2ebe5;
  --warm: #9a5b27;
  --warm-soft: #f3e8dc;
  --danger: #9b2f2f;
  --danger-soft: #f8e9e7;
  --methyl-orange: #d97732;
  --bromothymol-blue: #4f81bd;
  --phenolphthalein: #c05f95;
  --symbol-font: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
button, input { font: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
sub { line-height: 0; }

.intro { margin-bottom: 20px; }
.lead { max-width: 790px; }

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

.calculator-panel,
.result-panel {
  min-width: 0;
  padding: 24px;
}

.calculator-panel { border-right: 1px solid var(--line); }
.section-heading { margin-bottom: 16px; }
.section-kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.section-heading h2,
.result-heading-row h2,
.content-section h2 {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.5rem);
  line-height: 1.38;
}

.mode-fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.mode-fieldset legend { margin-bottom: 8px; font-weight: 780; }
.mode-grid { display: grid; gap: 8px; }
.mode-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-height: 46px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  background: #fff;
  cursor: pointer;
  line-height: 1.45;
}
.mode-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.mode-option input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

.input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 12px;
  margin-top: 20px;
}
.field-group { min-width: 0; }
.field-group label { display: block; margin-bottom: 6px; font-weight: 760; }
.input-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  min-width: 0;
}
.input-with-unit input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: #fff;
  color: var(--ink);
}
.input-with-unit span {
  display: grid;
  place-items: center;
  min-width: 58px;
  padding: 7px 8px;
  border: 1px solid var(--line-strong);
  border-left: 0;
  background: #eef0eb;
  color: var(--muted);
  font-size: .78rem;
  white-space: nowrap;
}
.input-with-unit input:focus { z-index: 1; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(36, 91, 73, .16); outline: 0; }
.input-with-unit input[aria-invalid="true"] { border-color: var(--danger); background: #fff8f8; }
.field-help,
.field-error { overflow-wrap: anywhere; }
.field-help { margin: 6px 0 0; color: var(--muted); font-size: .76rem; line-height: 1.55; }
.field-error { min-height: 1.25em; margin: 3px 0 0; color: var(--danger); font-size: .78rem; line-height: 1.45; }
.form-error {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-left: 4px solid var(--danger);
  background: var(--danger-soft);
  color: #762525;
  font-weight: 700;
  line-height: 1.55;
}
.form-error[hidden] { display: none; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.button {
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid var(--accent);
  border-radius: 0;
  cursor: pointer;
  font-weight: 760;
}
.button-primary { background: var(--accent); color: #fff; }
.button-primary:hover { background: var(--accent-dark); }
.button-secondary { background: transparent; color: var(--accent); }
.button-secondary:hover { border-color: var(--ink); color: var(--ink); }

.basis-card {
  margin-top: 20px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  background: #f0f2ed;
}
.basis-card h3 { margin: 0; font-size: 1rem; }
.basis-card p { margin: 7px 0 0; color: var(--muted); font-size: .8rem; line-height: 1.58; }

.result-heading-row,
.curve-heading-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.stage-badge,
.curve-status {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 760;
  line-height: 1.4;
  white-space: nowrap;
}
.curve-status {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: normal;
}
.stage-badge[data-state="before"],
.curve-status[data-state="ready"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.stage-badge[data-state="equivalence"] { border-color: var(--warm); background: var(--warm-soft); color: #75451f; }
.stage-badge[data-state="after"] { border-color: #4c6685; background: #e7edf4; color: #354d69; }
.stage-badge[data-state="error"],
.curve-status[data-state="error"] { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.result-status { min-height: 2.8em; margin: 10px 0 0; color: var(--muted); font-size: .84rem; line-height: 1.55; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 16px 0 0;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.metric {
  min-width: 0;
  padding: 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.metric-emphasis { background: var(--accent-soft); }
.metric dt { color: var(--muted); font-size: .72rem; line-height: 1.4; }
.metric dd { margin: 4px 0 0; overflow-wrap: anywhere; font-size: clamp(1rem, 2.3vw, 1.35rem); font-weight: 800; line-height: 1.4; }

.calculation-details {
  margin-top: 14px;
  padding: 13px;
  border-left: 3px solid var(--accent);
  background: #f0f2ed;
}
.calculation-details h3 { margin: 0; font-size: .96rem; }
.calculation-details dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 10px 0 0;
  background: var(--line);
}
.calculation-details dl div { min-width: 0; padding: 8px; background: var(--surface); }
.calculation-details dt { color: var(--muted); font-size: .68rem; line-height: 1.4; }
.calculation-details dd { margin: 3px 0 0; overflow-wrap: anywhere; font-size: .82rem; font-weight: 760; }
.calculation-details p { margin: 10px 0 0; color: var(--muted); font-size: .76rem; line-height: 1.55; }

.curve-section { margin-top: 22px; }
.curve-heading-row h3 { margin: 0; font-size: 1.05rem; }
.indicator-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  margin-top: 12px;
  color: var(--muted);
  font-size: .7rem;
  line-height: 1.4;
}
.indicator-legend > span { display: inline-flex; align-items: center; gap: 5px; }
.indicator-key { width: 12px; height: 9px; border: 1px solid rgba(34, 40, 36, .22); }
.indicator-key.methyl-orange { background: rgba(217, 119, 50, .35); }
.indicator-key.bromothymol-blue { background: rgba(79, 129, 189, .32); }
.indicator-key.phenolphthalein { background: rgba(192, 95, 149, .3); }
.curve-figure { margin: 12px 0 0; }
.curve-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  border: 1px solid var(--line);
  background: #fff;
}
.band-methyl-orange { fill: rgba(217, 119, 50, .18); }
.band-bromothymol-blue { fill: rgba(79, 129, 189, .16); }
.band-phenolphthalein { fill: rgba(192, 95, 149, .15); }
.plot-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 5; }
.plot-axis { stroke: var(--line-strong); stroke-width: 1.5; }
.curve-path { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.equivalence-line { stroke: var(--warm); stroke-width: 2; stroke-dasharray: 7 5; }
.current-point { fill: #fff; stroke: var(--accent-dark); stroke-width: 4; }
.equivalence-line[hidden],
.current-point[hidden],
.equivalence-label[hidden] { display: none; }
.axis-label { fill: var(--muted); font-size: 11px; }
.axis-title { fill: var(--ink); font-size: 12px; font-weight: 760; }
.equivalence-label { fill: #75451f; font-size: 11px; font-weight: 800; paint-order: stroke; stroke: #fff; stroke-width: 4px; stroke-linejoin: round; }
.curve-figure figcaption,
.curve-note { color: var(--muted); font-size: .74rem; line-height: 1.55; }
.curve-figure figcaption { margin-top: 8px; }
.curve-note { margin: 6px 0 0; }

.content-section { margin-top: 44px; }
.formula-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 16px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.formula-list article {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 14px 15px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.formula-list strong { overflow-wrap: anywhere; font-family: var(--symbol-font); font-size: .87rem; }
.formula-list span { color: var(--muted); font-size: .82rem; line-height: 1.55; }
.proof-guide {
  margin-top: 20px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.proof-guide h3 { margin: 0; font-size: 1rem; }
.proof-guide ul { margin: 10px 0 0; padding-left: 1.25em; }
.proof-guide li { margin-top: 5px; overflow-wrap: anywhere; }
.example-box {
  margin-top: 18px;
  padding: 14px 16px;
  border-left: 3px solid var(--warm);
  background: var(--warm-soft);
}
.example-box h3 { margin: 0; font-size: .98rem; }
.example-box p { margin: 6px 0 0; overflow-wrap: anywhere; font-size: .86rem; }

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

@media (max-width: 700px) {
  .formula-list { grid-template-columns: 1fr; }
  .calculation-details dl { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .calculator-panel,
  .result-panel { padding: 19px 14px; }
  .input-grid,
  .metric-grid { grid-template-columns: 1fr; }
  .form-actions { display: grid; grid-template-columns: 1fr; }
  .button { width: 100%; }
  .result-heading-row { display: block; }
  .stage-badge { display: inline-block; margin-top: 8px; }
  .indicator-legend { display: grid; grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
