:root {
  --ink: #0a1628;
  --ink-2: #0f1e33;
  --paper: #f7f5f0;
  --white: #ffffff;
  --line: #e5e1d7;
  --muted: #5b6473;
  --cyan: #06b6d4;
  --cyan-dark: #0891b2;
  --cyan-soft: #e8f8fb;
  --amber: #d97706;
  --amber-soft: #fff7e6;
  --red: #dc2626;
  --red-soft: #fff1f2;
  --shadow: 0 14px 40px rgba(10, 22, 40, 0.08);
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Manrope", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--paper); color: var(--ink); font-family: var(--sans); line-height: 1.45; }
button, input, select { font: inherit; }
button, select, input { accent-color: var(--cyan-dark); }
[hidden] { display: none !important; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid #fde68a; outline-offset: 3px; }

.topbar { min-height: 82px; padding: 14px clamp(20px, 3vw, 48px); background: var(--ink); color: var(--white); display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-block { min-width: 0; }
.brand { display: inline-flex; align-items: center; min-height: 44px; color: var(--white); text-decoration: none; font-family: var(--serif); font-size: clamp(1.4rem, 2vw, 2rem); line-height: 1.1; }
.brand-subtitle { max-width: 640px; margin: 5px 0 0; color: rgba(255,255,255,.72); font-family: var(--sans); font-size: .96rem; font-weight: 500; line-height: 1.35; }
.topbar-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 18px; white-space: nowrap; }
.scenario-tabs { display: flex; border: 1px solid rgba(6,182,212,.65); }
.scenario-tab { min-height: 44px; padding: 0 18px; color: rgba(255,255,255,.82); background: transparent; border: 0; border-right: 1px solid rgba(6,182,212,.65); cursor: pointer; font-size: .84rem; font-weight: 650; white-space: nowrap; }
.scenario-tab:last-child { border-right: 0; }
.scenario-tab.is-active { color: var(--ink); background: var(--cyan); }
.export-button, .reset-button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; padding: 0 17px; border: 1px solid var(--cyan); background: transparent; color: var(--white); cursor: pointer; font-weight: 700; }
.export-button svg, .reset-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.export-button:hover { background: rgba(6,182,212,.12); }

.app-shell { max-width: 1600px; margin: 0 auto; padding: 26px clamp(18px, 2.3vw, 38px) 34px; display: grid; grid-template-columns: minmax(260px, 320px) 1fr; gap: 26px; }
.controls { align-self: start; position: sticky; top: 20px; min-height: calc(100vh - 142px); background: var(--white); border: 1px solid var(--line); padding: 24px 22px; display: flex; flex-direction: column; gap: 28px; box-shadow: 0 8px 24px rgba(10,22,40,.03); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: 1.2rem; }
.controls-intro { margin-bottom: 0; color: var(--muted); font-size: .84rem; }
.control-block { display: block; }
.control-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; font-weight: 750; font-size: .94rem; }
.control-heading output { min-width: 64px; padding: 6px 8px; border: 1px solid var(--line); background: var(--paper); text-align: center; font-variant-numeric: tabular-nums; }
.control-block input[type="range"] { width: 100%; min-height: 44px; margin: 0; cursor: pointer; }
.range-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: .72rem; font-variant-numeric: tabular-nums; }
.control-block small { display: block; margin-top: 10px; color: var(--muted); font-size: .77rem; }
.select-block select { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); background: var(--white); color: var(--ink); }
.reset-button { width: 100%; margin-top: auto; color: var(--cyan-dark); background: var(--white); }
.reset-button:hover { background: var(--cyan-soft); }

.workspace { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 24px 22px; }
.chart-region, .operating-table-region, .tradeoff-region, .memo-region, .model-context { min-width: 0; background: var(--white); border: 1px solid var(--line); }
.chart-region { padding: 20px 22px 12px; }
.section-heading-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.section-heading-row h2, .memo-heading h2 { margin-bottom: 2px; font-size: 1.08rem; }
.section-heading-row p, .memo-heading p { margin-bottom: 0; color: var(--muted); font-size: .78rem; }
.section-heading-row.compact { margin-bottom: 14px; align-items: center; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 16px; color: var(--muted); font-size: .74rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-line { display: inline-block; width: 24px; border-top: 3px solid var(--cyan); }
.legend-line.capacity { border-top-style: dashed; border-color: var(--cyan-dark); }
.legend-line.adjusted-demand { border-color: #7c3aed; }
.legend-line.adjusted-capacity { border-color: #7c3aed; border-top-style: dashed; border-top-width: 3px; }
.legend-gap { width: 16px; height: 10px; background: rgba(6,182,212,.18); }
.chart-wrap { min-height: 300px; }
#capacity-chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart-text-summary { margin: 4px 0 0; padding: 10px 12px; border-left: 3px solid var(--cyan-dark); background: #f2f6f7; color: var(--ink-2); font-size: .78rem; line-height: 1.45; }

.metric-rail { min-width: 0; display: grid; grid-template-rows: repeat(4, 1fr); gap: 10px; }
.metric-rail article { min-width: 0; padding: 14px 17px; background: var(--white); border: 1px solid var(--line); }
.metric-rail h3 { margin-bottom: 2px; font-size: .78rem; }
.metric-rail strong { display: block; color: var(--cyan-dark); font-family: var(--serif); font-size: 2.5rem; line-height: 1.05; font-weight: 500; font-variant-numeric: tabular-nums; }
.metric-rail strong.risk { color: var(--red); }
.metric-rail p { margin-bottom: 0; color: var(--muted); font-size: .7rem; }

.model-context { grid-column: 1 / -1; padding: 18px 22px; border-left: 4px solid var(--cyan); }
.model-context h2 { margin-bottom: 3px; font-size: 1.02rem; }
.model-context p { margin-bottom: 0; color: var(--muted); font-size: .76rem; }
.context-details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 22px; margin: 16px 0 0; }
.context-details div { min-width: 0; }
.context-details .context-decision { grid-column: 1 / -1; }
.context-details dt { margin-bottom: 4px; color: var(--muted); font-size: .68rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.context-details dd { margin: 0; font-size: .8rem; font-weight: 500; line-height: 1.4; }

.operating-table-region { padding: 20px 22px; }
.analysis-bottom { min-width: 0; grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1.38fr) minmax(360px, .82fr); gap: 22px; align-items: start; }
.table-scroll { overflow-x: visible; }
.mobile-operating-cards { display: none; }
table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: .78rem; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 7px; border: 1px solid var(--line); text-align: right; }
th:nth-child(1) { width: 12%; }
th:nth-child(2) { width: 13%; }
th:nth-child(3) { width: 17%; }
th:nth-child(4) { width: 12%; }
th:nth-child(5) { width: 19%; }
th:nth-child(6) { width: 27%; }
th:first-child, td:first-child, th:last-child, td:last-child { text-align: left; }
thead th { background: #f2f6f7; font-weight: 750; }
tfoot th, tfoot td { background: var(--cyan-soft); font-weight: 800; }
.status-cell { display: inline-flex; min-width: 0; align-items: flex-start; gap: 7px; font-weight: 700; line-height: 1.35; text-transform: capitalize; }
.status-cell::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--cyan-dark); }
.status-cell.at-risk { color: var(--amber); }
.status-cell.at-risk::before { background: var(--amber); }
.status-cell.impossible { color: var(--red); }
.status-cell.impossible::before { background: var(--red); }
.before-after { white-space: nowrap; font-variant-numeric: tabular-nums; }
.metric-rail .before-after { white-space: normal; font-size: 1.7rem; line-height: 1.1; }
.before-after b { color: #7c3aed; padding: 0 2px; }
.positive-gap { color: var(--red); font-weight: 700; }
.negative-gap { color: var(--cyan-dark); font-weight: 700; }
.formula-note { margin: 12px 0 0; color: var(--muted); font-size: .72rem; }
.text-button { display: inline-flex; align-items: center; min-width: 44px; min-height: 44px; padding: 0 6px; border: 0; background: transparent; color: var(--cyan-dark); font-size: .79rem; font-weight: 750; cursor: pointer; }

.tradeoff-region { padding: 20px 18px; }
.tradeoff-list { display: grid; gap: 10px; }
.tradeoff-option { position: relative; display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 10px; align-items: start; min-height: 44px; padding: 13px; border: 1px solid var(--line); cursor: pointer; }
.tradeoff-option:hover { border-color: var(--cyan-dark); }
.tradeoff-option.is-selected { border: 2px solid var(--cyan); padding: 12px; background: #fbfeff; }
.tradeoff-option input { margin-top: 3px; }
.tradeoff-option:focus-within { outline: 3px solid #fde68a; outline-offset: 3px; }
.tradeoff-copy { min-width: 0; }
.tradeoff-copy strong { display: block; margin-bottom: 3px; font-size: .84rem; }
.tradeoff-copy span { display: block; color: var(--muted); font-size: .72rem; }
.tradeoff-impact { grid-column: 2; min-width: 0; padding-top: 8px; border-top: 1px solid var(--line); text-align: left; }
.tradeoff-impact small { color: var(--muted); font-size: .64rem; }
.tradeoff-impact strong { display: block; margin-top: 2px; color: var(--cyan-dark); font-size: .8rem; overflow-wrap: anywhere; }

.memo-region { grid-column: 1 / -1; padding: 24px 26px 26px; border-left: 5px solid var(--cyan); }
.memo-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.memo-region > h3 { margin: 24px 0 8px; font-family: var(--serif); font-size: clamp(1.4rem, 2.2vw, 2rem); font-weight: 500; }
.memo-region > p { max-width: 1050px; }
.memo-decision { font-weight: 750; }
.claims-boundary { margin: 22px 0 0; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: .75rem; }
.status-label { padding: 6px 10px; background: var(--amber-soft); color: var(--amber); border: 1px solid #f2cf8e; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.status-label.feasible { background: var(--cyan-soft); color: var(--cyan-dark); border-color: #b5eaf3; }
.status-label.impossible { background: var(--red-soft); color: var(--red); border-color: #fecdd3; }

.demonstrates { max-width: 1600px; margin: 0 auto; padding: 0 clamp(18px, 2.3vw, 38px) 18px; color: var(--ink); }
.demonstrates-panel { padding: 18px 22px; border: 1px solid var(--line); border-top: 4px solid var(--cyan); background: var(--white); }
.demonstrates h2 { margin: 0 0 12px; font-size: 1.02rem; }
.demonstrates ul { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 24px; margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: .8rem; }
.demonstrates li { display: flex; align-items: center; gap: 9px; }
.demonstrates li::before { content: ""; flex: 0 0 5px; width: 5px; height: 5px; background: var(--cyan-dark); border-radius: 50%; }
.synthetic-disclosure { margin: 15px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: .75rem; }
footer { max-width: 1600px; margin: 0 auto; padding: 0 clamp(18px, 2.3vw, 38px) 34px; display: flex; justify-content: flex-end; gap: 18px; color: var(--muted); font-size: .74rem; }
footer p { margin-bottom: 0; }
footer a { display: inline-flex; align-items: center; min-height: 44px; color: var(--cyan-dark); font-weight: 700; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 360px; padding: 12px 15px; background: var(--ink); color: var(--white); box-shadow: var(--shadow); transform: translateY(20px); opacity: 0; pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; font-size: .8rem; }
.toast.is-visible { transform: translateY(0); opacity: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1120px) {
  .topbar { align-items: flex-start; }
  .topbar-actions { align-items: flex-end; flex-direction: column-reverse; }
  .app-shell { grid-template-columns: 270px 1fr; }
  .workspace { grid-template-columns: 1fr; }
  .metric-rail { grid-template-columns: repeat(4, 1fr); grid-template-rows: none; }
  .analysis-bottom { grid-template-columns: 1fr; }
  .memo-region { grid-column: 1; }
}

@media (max-width: 820px) {
  .topbar { flex-direction: column; gap: 12px; }
  .topbar-actions { width: 100%; align-items: stretch; flex-direction: column; }
  .scenario-tabs { overflow-x: auto; }
  .scenario-tab { flex: 1 1 33.33%; padding: 0 9px; font-size: .76rem; white-space: nowrap; }
  .export-button { width: 100%; }
  .app-shell { grid-template-columns: 1fr; padding-top: 18px; }
  .controls { position: static; min-height: auto; }
  .reset-button { margin-top: 4px; }
  .metric-rail { grid-template-columns: repeat(2, 1fr); }
  footer { flex-direction: column; }
}

@media (max-width: 639px) {
  .topbar { min-height: 0; padding: 12px 20px; }
  .brand { font-size: 1.35rem; }
  .brand-subtitle { margin-top: 4px; font-size: .94rem; line-height: 1.3; }
  .workspace { gap: 14px; }
  .chart-region, .operating-table-region, .tradeoff-region, .memo-region { padding: 17px 14px; }
  .section-heading-row { flex-direction: column; }
  .chart-legend { gap: 10px; }
  .metric-rail { gap: 8px; }
  .metric-rail strong { font-size: 2rem; }
  .tradeoff-option { grid-template-columns: 20px minmax(0, 1fr); }
  .memo-heading { flex-direction: column; }
  .context-details { grid-template-columns: 1fr; gap: 10px; }
  .demonstrates-panel { padding: 16px 14px; }
  .demonstrates ul { grid-template-columns: 1fr; gap: 8px; }
  .operating-table-region { overflow: hidden; }
  .table-scroll { display: none !important; }
  .mobile-operating-cards { display: grid; gap: 10px; width: 100%; }
  .month-card { padding: 14px; border: 1px solid var(--line); background: #fbfdfd; }
  .aggregate-card { background: var(--cyan-soft); border-color: #b5eaf3; }
  .month-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
  .month-card-heading h3 { margin: 0; font-size: 1.05rem; }
  .month-card-values { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin: 12px 0 0; font-size: .875rem; font-variant-numeric: tabular-nums; }
  .month-card-values dt { color: var(--muted); font-size: .875rem; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; }
  .month-card-values dd { margin: 2px 0 0; font-size: .875rem; font-weight: 750; }
  .controls-intro, .control-block small, .formula-note, .memo-region > p, .model-context p, .section-heading-row p, .demonstrates li, footer { font-size: 1rem; line-height: 1.5; }
  .metric-rail h3, .metric-rail p, .chart-legend, .context-details dd { font-size: .875rem; }
  .tradeoff-copy strong, .tradeoff-copy span, .tradeoff-impact strong { font-size: 1rem; line-height: 1.45; }
  .chart-legend { font-size: .875rem; }
  #capacity-chart text { font-size: 14px !important; }
}

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