: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;
  --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; }
button, input, select { font: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

[data-kw-shell="v1"] [hidden] { display: none !important; }
[data-kw-shell="v1"] h2,
[data-kw-shell="v1"] h3 { color: var(--ink); }

.tool-shell {
  display: grid;
  grid-template-columns: minmax(320px, .88fr) minmax(0, 1.12fr);
  gap: 20px;
  align-items: start;
  min-width: 0;
}

.calculator-panel,
.result-panel {
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.calculator-panel,
#rainfall-form { display: grid; gap: 20px; }
.result-panel { background: rgba(251, 250, 246, .68); }
.section-heading { display: grid; gap: 1px; }
.section-kicker { margin: 0; color: var(--accent); font-size: .76rem; font-weight: 780; letter-spacing: .08em; text-transform: uppercase; }
.section-heading h2,
.result-heading-row h2 { margin: 0; font-size: clamp(1.2rem, 2vw, 1.48rem); line-height: 1.35; }

.input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.field-group {
  display: grid;
  gap: 6px;
  min-width: 0;
  align-content: start;
  padding: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.field-group label { color: var(--ink); font-size: .88rem; font-weight: 740; }
.value-with-unit { display: grid; grid-template-columns: minmax(0, 1fr) minmax(70px, .42fr); gap: 7px; min-width: 0; }
.value-with-unit input,
.value-with-unit select,
.unit-suffix {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
}
.value-with-unit input { appearance: textfield; }
.value-with-unit input[aria-invalid="true"] { border-color: var(--danger); background: #fff8f8; }
.value-with-unit select { cursor: pointer; }
.unit-suffix { display: grid; place-items: center; background: var(--paper); color: var(--muted); font-weight: 700; }
.field-help { min-height: 2.5em; margin: 0; color: var(--muted); font-size: .76rem; line-height: 1.5; overflow-wrap: anywhere; }
.field-error { min-height: 1.25em; margin: 0; color: var(--danger); font-size: .78rem; line-height: 1.4; overflow-wrap: anywhere; }

.form-error {
  margin: 0;
  padding: 9px 10px;
  border-left: 3px solid var(--danger);
  background: var(--danger-soft);
  color: #762525;
  font-size: .84rem;
  font-weight: 700;
  line-height: 1.5;
}
.form-error[hidden] { display: none; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.button {
  min-height: 44px;
  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); }
.button:disabled { border-color: var(--line); background: var(--paper); color: #8a918b; cursor: not-allowed; }

.scope-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-left: 3px solid var(--line-strong);
  background: #f0f2ed;
}
.scope-card h2 { margin: 0; font-size: 1rem; line-height: 1.4; }
.scope-card p { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.65; overflow-wrap: anywhere; }
.scope-card .formula-line { color: var(--accent-strong); font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", system-ui, sans-serif; font-size: .95rem; font-weight: 760; }

.result-heading-row,
.diagram-heading-row { display: flex; align-items: flex-start; justify-content: space-between; 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;
  line-height: 1.4;
}
.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); }
.result-status { min-height: 1.65em; margin: 8px 0 0; color: var(--muted); font-size: .82rem; line-height: 1.6; overflow-wrap: anywhere; }

.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: 11px 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.metric-emphasis { background: var(--accent-soft); }
.metric dt { color: var(--muted); font-size: .75rem; font-weight: 760; }
.metric dd { min-height: 1.5em; margin: 3px 0 0; color: var(--ink); font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", system-ui, sans-serif; font-size: clamp(1rem, 2.2vw, 1.35rem); font-weight: 780; line-height: 1.35; overflow-wrap: anywhere; }

.calculation-details { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-strong); }
.calculation-details h3 { margin: 0 0 9px; font-size: 1rem; line-height: 1.4; }
.details-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.details-list div { min-width: 0; padding: 8px 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.details-list dt { color: var(--muted); font-size: .74rem; font-weight: 760; }
.details-list dd { margin: 3px 0 0; color: var(--ink); font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", system-ui, sans-serif; font-size: .8rem; font-weight: 650; line-height: 1.5; overflow-wrap: anywhere; }

.diagram-card { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line-strong); }
.diagram-heading-row h3 { margin: 0; font-size: 1rem; line-height: 1.4; }
.diagram-heading-row output { min-height: 1.4em; color: var(--accent); font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", system-ui, sans-serif; font-size: .78rem; font-weight: 760; text-align: right; }
.runoff-diagram {
  position: relative;
  min-height: 250px;
  margin-top: 13px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, #eef5f1 0 51%, #dce9df 51% 100%);
}
.diagram-cloud { position: absolute; top: 34px; left: 50%; width: 116px; height: 42px; transform: translateX(-50%); }
.diagram-cloud span { position: absolute; bottom: 0; border-radius: 50% 50% 42% 42%; background: #fff; box-shadow: 0 2px 0 rgba(36, 91, 73, .12); }
.diagram-cloud span:nth-child(1) { left: 5px; width: 44px; height: 32px; }
.diagram-cloud span:nth-child(2) { left: 32px; width: 58px; height: 42px; }
.diagram-cloud span:nth-child(3) { right: 0; width: 48px; height: 30px; }
.diagram-rain { position: absolute; top: 78px; left: 50%; display: flex; gap: 16px; transform: translateX(-50%); }
.diagram-rain i { display: block; width: 2px; height: 30px; border-radius: 2px; background: var(--accent); opacity: .65; transform: rotate(15deg); }
.diagram-rain i:nth-child(2), .diagram-rain i:nth-child(5) { height: 23px; opacity: .45; }
.diagram-rain i:nth-child(3) { height: 35px; }
.diagram-catchment { position: absolute; right: 11%; bottom: 32px; left: 11%; height: 96px; }
.diagram-ground { position: absolute; right: 0; bottom: 0; left: 0; height: 70px; border: 2px solid var(--accent); border-top: 0; border-radius: 0 0 18px 18px; background: rgba(255, 255, 255, .38); clip-path: polygon(0 25%, 20% 5%, 48% 39%, 72% 17%, 100% 45%, 100% 100%, 0 100%); }
.diagram-channel { position: absolute; right: 14%; bottom: 6px; width: 38%; height: 27px; border: 2px solid #427a67; border-radius: 50%; background: #a9d0bd; transform: rotate(-7deg); }
.diagram-runoff { position: absolute; right: 25%; bottom: 43px; width: 28px; height: 42px; border-right: 4px solid var(--accent); border-bottom: 4px solid var(--accent); transform: rotate(40deg); }
.diagram-runoff::after { position: absolute; right: -8px; bottom: -8px; width: 15px; height: 15px; border-right: 4px solid var(--accent); border-bottom: 4px solid var(--accent); content: ""; }
.diagram-label { position: absolute; padding: 2px 6px; border: 1px solid rgba(36, 91, 73, .28); background: rgba(251, 250, 246, .92); color: var(--accent-strong); font-size: .76rem; font-weight: 760; line-height: 1.35; }
.diagram-label-rain { top: 116px; left: 12%; }
.diagram-label-area { bottom: 84px; left: 14%; }
.diagram-label-runoff { right: 11%; bottom: 14px; }
.diagram-empty { margin: 10px 0 0; color: var(--muted); font-size: .82rem; line-height: 1.6; }
.scale-note { margin: 7px 0 0; padding-left: 10px; border-left: 3px solid var(--line-strong); color: var(--muted); font-size: .76rem; line-height: 1.6; overflow-wrap: anywhere; }

.content-section { margin-top: 30px; padding-top: 25px; border-top: 1px solid var(--line-strong); }
.content-section > .section-heading { margin-bottom: 15px; }
.steps-list { display: grid; grid-template-columns: repeat(4, 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: 16px 13px 14px 42px; border-inline-end: 1px solid var(--line); font-size: .82rem; line-height: 1.55; }
.steps-list li:last-child { border-inline-end: 0; }
.steps-list li::before { position: absolute; top: 14px; left: 13px; display: grid; width: 22px; height: 22px; place-items: center; border: 1px solid var(--accent); border-radius: 50%; color: var(--accent); content: counter(steps); counter-increment: steps; font-size: .75rem; font-weight: 800; }
.formula-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.formula-list div { display: grid; gap: 3px; min-width: 0; padding: 13px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.formula-list strong { color: var(--accent-strong); font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", system-ui, sans-serif; font-size: 1.05rem; line-height: 1.4; overflow-wrap: anywhere; }
.formula-list span { color: var(--muted); font-size: .77rem; }
.proof-guide { margin-top: 18px; padding: 16px; border-left: 3px solid var(--accent); background: #f0f2ed; }
.proof-guide h3 { margin: 0 0 8px; font-size: 1rem; }
.proof-guide ul { display: grid; gap: 7px; margin: 0; padding-left: 1.25em; color: var(--muted); font-size: .82rem; line-height: 1.6; }

@media (max-width: 800px) {
  .tool-shell { grid-template-columns: 1fr; gap: 16px; }
  .calculator-panel, .result-panel { padding: 18px; }
  .calculator-panel { border-right: 0; }
  .formula-list { grid-template-columns: 1fr; }
  .steps-list { grid-template-columns: repeat(2, 1fr); }
  .steps-list li:nth-child(2) { border-inline-end: 0; }
  .steps-list li:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 520px) {
  .input-grid, .metric-grid, .details-list { grid-template-columns: 1fr; }
  .field-group { padding: 11px; }
  .value-with-unit { grid-template-columns: minmax(0, 1fr) minmax(64px, .38fr); }
  .form-actions { display: grid; grid-template-columns: 1fr; }
  .button { width: 100%; }
  .runoff-diagram { min-height: 230px; }
  .diagram-catchment { right: 7%; left: 7%; }
  .diagram-label-rain { left: 6%; }
  .diagram-label-area { left: 8%; }
  .diagram-label-runoff { right: 6%; }
  .steps-list { grid-template-columns: 1fr; }
  .steps-list li,
  .steps-list li:nth-child(2) { border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .steps-list li:last-child { border-bottom: 0; }
}
