: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;
  --warm: #9a5a20;
  --warm-soft: #f6eadf;
  --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; }
body { margin: 0; color: var(--ink); background: var(--paper); line-height: 1.65; }
button, input, select { font: inherit; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.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; }

.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-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  min-width: 0;
}
.input-row input,
.input-row select {
  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 select { width: auto; min-width: 74px; cursor: pointer; }
.input-row input[aria-invalid="true"],
.input-row select[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; }
.temperature-note {
  margin: 16px 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],
.physical-note[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); }
.button:disabled { border-color: var(--line); background: var(--paper); color: #8a918b; cursor: not-allowed; }
.form-status { min-height: 1.3em; margin: 10px 0 0; color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }

.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-overview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 6px;
}
.result-overview > div { min-width: 0; }
.result-term { display: block; color: var(--muted); font-size: .76rem; font-weight: 740; }
.result-value {
  display: block;
  margin-top: 1px;
  font-size: clamp(1.22rem, 2.8vw, 1.7rem);
  line-height: 1.3;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.result-status { margin: 7px 0 0; color: #3f4c46; font-size: .9rem; overflow-wrap: anywhere; }
.physical-note {
  margin: 9px 0 0;
  padding: 8px 10px;
  border-left: 3px solid var(--warm);
  background: var(--warm-soft);
  color: #744316;
  font-size: .8rem;
  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: .84rem; font-weight: 620; overflow-wrap: anywhere; word-break: break-word; }
.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;
  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); }
.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; word-break: break-word; }

.dimension-figure {
  --final-width: 50%;
  margin: 15px 0 0;
  padding: 17px 14px 14px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, #fbfaf6 0%, #f0efe9 100%);
}
.dimension-graphic { position: relative; min-width: 0; padding: 4px 0 30px; }
.dimension-scale {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
}
.measure-row { display: grid; grid-template-columns: 76px minmax(0, 1fr); align-items: center; gap: 9px; margin-top: 18px; min-width: 0; }
.measure-label { min-width: 0; color: var(--ink); font-size: .78rem; font-weight: 760; overflow-wrap: anywhere; }
.measure-track { position: relative; min-width: 0; height: 28px; border-bottom: 2px solid var(--line-strong); }
.measure-bar { position: absolute; left: 0; bottom: 4px; height: 18px; border: 1px solid var(--accent); background: rgba(36, 91, 73, .25); }
.measure-bar-initial { width: 50%; }
.measure-bar-final { width: var(--final-width); border-color: var(--warm); background: rgba(154, 90, 32, .3); }
.change-arrow {
  position: absolute;
  left: calc(76px + 9px + 25%);
  right: 25%;
  bottom: 2px;
  height: 12px;
  opacity: 0;
}
.dimension-figure[data-state="ready"] .change-arrow { opacity: .85; }
.arrow-line { position: absolute; top: 5px; left: 8px; right: 8px; height: 2px; background: var(--accent); }
.arrow-head { position: absolute; top: 1px; width: 9px; height: 9px; border-top: 2px solid var(--accent); border-right: 2px solid var(--accent); }
.arrow-head-right { right: 0; transform: rotate(45deg); }
.arrow-head-left { left: 0; transform: rotate(-135deg); }
.dimension-figure[data-direction="contraction"] .arrow-line,
.dimension-figure[data-direction="contraction"] .arrow-head { background: var(--warm); border-color: var(--warm); }
.dimension-figure[data-direction="unchanged"] .change-arrow { display: none; }
.dimension-figure[data-state="waiting"] .measure-bar,
.dimension-figure[data-state="waiting"] .change-arrow { visibility: hidden; }
.visual-caption { margin: 11px 0 0; color: var(--muted); font-size: .82rem; text-align: center; overflow-wrap: anywhere; }
.visual-description { margin: 11px 0 0; color: #38413b; font-size: .9rem; overflow-wrap: anywhere; }
.scale-note { margin: 7px 0 0; padding-left: 11px; border-left: 3px solid var(--line-strong); color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }

.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 { font-family: var(--symbol-font); overflow-wrap: anywhere; }
.formula-list span { color: var(--muted); overflow-wrap: anywhere; }
.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: .86rem; overflow-wrap: anywhere; }
.scope-box li:nth-child(2n) { border-right: 0; }
.scope-box li:nth-last-child(-n + 2) { border-bottom: 0; }
.scope-box li::before { content: "—"; margin-left: -17px; margin-right: 7px; color: var(--accent); }
.footer-links { display: flex; flex-wrap: wrap; gap: 14px; }
.footer-links a { text-underline-offset: 3px; }
.footer-links a:hover { 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: 700px) {
  .visual-heading-row { gap: 8px; }
  .status-badge { font-size: .7rem; }
  .formula-list,
  .scope-box ul { grid-template-columns: 1fr; }
  .formula-list article,
  .scope-box li,
  .scope-box li:nth-child(2n),
  .scope-box li:nth-last-child(-n + 2) { border-right: 0; border-bottom: 1px solid var(--line); }
  .formula-list article:last-child,
  .scope-box li:last-child { border-bottom: 0; }
}

@media (max-width: 600px) {
  .calculator-panel,
  .visual-panel { padding: 17px 14px; }
  .input-with-unit { grid-template-columns: minmax(0, 1fr) 74px; }
  .form-actions { display: grid; grid-template-columns: 1fr; }
  .button { width: 100%; }
  .result-overview,
  .visual-metrics { grid-template-columns: 1fr; }
  .measure-row { grid-template-columns: 68px minmax(0, 1fr); gap: 7px; }
  .change-arrow { left: calc(68px + 7px + 25%); }
  .footer-links { gap: 10px; }
}

@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; }
}
