: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;
  --lod: #5c8f9d;
  --lod-soft: #dcebed;
  --loq: #9a5a20;
  --loq-soft: #f4e6d5;
  --danger: #9b2f2f;
  --danger-soft: #f8e9e7;
  --symbol-font: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  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; }
button, input { font: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.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; }
h2 { margin: 0; font-size: clamp(1.2rem, 2vw, 1.48rem); line-height: 1.35; }

.values-fieldset { min-width: 0; display: grid; gap: 15px; margin: 16px 0 0; padding: 0; border: 0; }
.values-fieldset > legend { margin-bottom: -2px; font-weight: 760; }
.input-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.input-row { min-width: 0; }
.input-row label { display: block; margin-bottom: 5px; font-weight: 720; overflow-wrap: anywhere; }
.plain-input {
  display: block;
  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);
}
.plain-input:focus { border-color: var(--accent); }
.plain-input[aria-invalid="true"] { border-color: var(--danger); background: #fff8f8; }
.field-help { margin: 4px 0 0; color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }
.field-error { min-height: 1.25em; margin: 2px 0 0; color: var(--danger); font-size: .82rem; overflow-wrap: anywhere; }
.coefficient-fieldset { margin-top: 21px; }
.unit-fieldset { margin-top: 21px; }
.format-note {
  margin: 15px 0 0;
  padding: 9px 11px;
  border-left: 3px solid var(--line-strong);
  color: var(--muted);
  font-size: .8rem;
  overflow-wrap: anywhere;
}
.form-error {
  margin: 12px 0 0;
  padding: 8px 10px;
  border-left: 4px solid var(--danger);
  background: var(--danger-soft);
  color: #762525;
  overflow-wrap: anywhere;
}
.form-error[hidden] { display: none; }

.form-actions { display: flex; flex-wrap: wrap; 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-family: var(--symbol-font);
  font-size: clamp(1.15rem, 2.7vw, 1.66rem);
  line-height: 1.4;
  font-weight: 780;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.result-status { margin: 6px 0 0; color: #3f4c46; font-size: .9rem; overflow-wrap: anywhere; }
.result-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  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], .result-notes[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 .detail-wide { grid-column: 1 / -1; }
.result-details dt { color: var(--muted); font-size: .76rem; font-weight: 760; overflow-wrap: anywhere; }
.result-details dd { margin: 2px 0 0; font-size: .85rem; font-weight: 650; overflow-wrap: anywhere; word-break: break-word; font-variant-numeric: tabular-nums; }
.result-notes {
  display: grid;
  gap: 5px;
  margin: 13px 0 0;
  padding: 10px 10px 10px 28px;
  border: 1px solid rgba(36, 91, 73, .3);
  background: rgba(251, 250, 246, .58);
  color: #46524b;
  font-size: .8rem;
}
.result-notes li { overflow-wrap: anywhere; }

.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;
  white-space: nowrap;
}
.status-badge[data-state="ready"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.status-badge[data-state="error"] { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.threshold-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 17px; }
.threshold-card { min-width: 0; padding: 15px; border: 1px solid var(--line); }
.threshold-lod { border-color: var(--lod); background: var(--lod-soft); }
.threshold-loq { border-color: var(--loq); background: var(--loq-soft); }
.threshold-label { margin: 0; font-size: .83rem; font-weight: 800; letter-spacing: .07em; }
.threshold-lod .threshold-label, .threshold-lod .threshold-value { color: #285e6a; }
.threshold-loq .threshold-label, .threshold-loq .threshold-value { color: #744316; }
.threshold-value { min-height: 1.45em; margin: 5px 0 0; font-family: var(--symbol-font); font-size: clamp(1.15rem, 2.5vw, 1.55rem); font-weight: 800; overflow-wrap: anywhere; word-break: break-word; }
.threshold-help { margin: 5px 0 0; color: var(--muted); font-size: .76rem; overflow-wrap: anywhere; }
.visual-metrics {
  display: grid;
  grid-template-columns: repeat(2, 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; overflow-wrap: anywhere; }
.visual-metrics dd { margin: 2px 0 0; font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; word-break: break-word; }

.visual-stage {
  min-height: 190px;
  display: grid;
  place-items: center;
  margin-top: 15px;
  padding: 22px 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #eef5f3 0%, #f8f4ec 100%);
}
.unit-flow { width: min(100%, 440px); display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px; }
.flow-label { min-width: 0; padding: 13px 9px; border: 1px solid var(--line-strong); background: rgba(251, 250, 246, .8); color: var(--accent-strong); text-align: center; font-family: var(--symbol-font); font-size: .86rem; font-weight: 750; overflow-wrap: anywhere; word-break: break-word; }
.flow-arrow { color: var(--accent); font-size: 1.5rem; font-weight: 800; }
.visual-stage-note { max-width: 420px; margin: 17px 0 0; color: var(--muted); font-size: .82rem; text-align: center; overflow-wrap: anywhere; }
.visual-description { margin: 12px 0 0; color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
.scale-note { margin: 6px 0 0; padding-left: 11px; border-left: 3px solid var(--line-strong); color: var(--muted); font-size: .76rem; overflow-wrap: anywhere; }

.content-section { margin-top: 30px; padding-top: 25px; border-top: 1px solid var(--line-strong); }
.steps-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin: 0;
  padding: 0;
  border-block: 1px solid var(--line);
  list-style: none;
  counter-reset: steps;
}
.steps-list li { position: relative; min-width: 0; padding: 35px 12px 13px; border-right: 1px solid var(--line); counter-increment: steps; font-size: .88rem; overflow-wrap: anywhere; }
.steps-list li:last-child { border-right: 0; }
.steps-list li::before { content: counter(steps, decimal-leading-zero); position: absolute; top: 7px; left: 12px; color: var(--accent); font-size: .75rem; font-weight: 800; }
.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: 4px; padding: 13px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.formula-list strong { font-family: var(--symbol-font); overflow-wrap: anywhere; }
.formula-list span { color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.example-box { margin-top: 14px; padding: 14px 16px; border: 1px solid var(--accent); background: var(--accent-soft); }
.example-box h3 { margin: 0; color: var(--accent); font-size: .95rem; }
.example-box p { margin: 7px 0 0; color: #38413b; font-size: .88rem; overflow-wrap: anywhere; }
.source-box { padding: 14px 16px; border: 1px solid var(--line); background: var(--surface); }
.source-box p { margin: 0; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.source-box p + p { margin-top: 9px; }
.source-box a { color: var(--accent); font-weight: 750; text-underline-offset: 4px; }
.scope-box { border: 1px solid var(--line); }
.scope-box ul { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; padding: 0; list-style: none; }
.scope-box 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: .84rem; overflow-wrap: anywhere; }
.scope-box li:nth-child(2n) { border-right: 0; }
.scope-box li:last-child { border-bottom: 0; }
.scope-box li::before { content: "—"; margin-left: -17px; margin-right: 7px; color: var(--accent); }
.scope-box li:nth-last-child(2) { border-bottom: 0; }

@media (max-width: 900px) {
  .tool-shell { grid-template-columns: 1fr; }
  .calculator-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .scope-box ul { grid-template-columns: 1fr; }
  .scope-box li, .scope-box li:nth-child(2n), .scope-box li:nth-last-child(2) { border-right: 0; border-bottom: 1px solid var(--line); }
  .scope-box li:last-child { border-bottom: 0; }
}

@media (max-width: 760px) {
  .calculator-panel, .visual-panel { padding: 18px; }
  .formula-list { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .calculator-panel, .visual-panel { padding: 17px 14px; }
  .input-grid, .threshold-cards { grid-template-columns: 1fr; }
  .form-actions { display: grid; grid-template-columns: 1fr; }
  .button { width: 100%; }
  .result-details { grid-template-columns: 1fr; }
  .result-details .detail-wide { grid-column: auto; }
  .steps-list { grid-template-columns: 1fr; }
  .steps-list li, .steps-list li:nth-child(2) { border-right: 0; border-bottom: 1px solid var(--line); }
  .steps-list li:last-child { border-bottom: 0; }
  .unit-flow { gap: 7px; }
  .flow-label { padding-inline: 6px; font-size: .76rem; }
}

@media (max-width: 430px) {
  .visual-stage { padding-inline: 9px; }
}

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