:root {
  --paper: #f4f2ed;
  --white: #fffefa;
  --ink: #17201f;
  --muted: #64706c;
  --line: #d4cec2;
  --teal: #096f68;
  --teal-dark: #074f4b;
  --oxide: #b34f37;
  --gold: #bb8a28;
  --shadow: 0 10px 30px rgba(22, 31, 29, .07);
  --sans: "Aptos", "Segoe UI", "Microsoft YaHei UI", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Songti SC", "STSong", serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: var(--sans); line-height: 1.45; }
button, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
.is-hidden { display: none !important; }

.skip-link { position: fixed; z-index: 99; left: 1rem; top: -5rem; padding: .7rem 1rem; color: white; background: var(--ink); }
.skip-link:focus { top: 1rem; }

.site-header {
  position: sticky; z-index: 30; top: 0; min-height: 68px; padding: 0 clamp(1rem, 4vw, 4rem);
  display: grid; grid-template-columns: minmax(230px, 1fr) auto minmax(80px, 1fr); align-items: center;
  border-bottom: 1px solid var(--line); background: rgba(244, 242, 237, .96); backdrop-filter: blur(12px);
}
.brand { display: inline-flex; align-items: center; gap: .68rem; width: max-content; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; color: white; background: var(--teal-dark); font: 700 1.1rem/1 var(--serif); }
.brand strong, .brand small { display: block; }
.brand strong { font: 600 1rem/1.15 var(--serif); }
.brand small { margin-top: .18rem; color: var(--muted); font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; }
.top-nav { align-self: stretch; display: flex; }
.nav-tab {
  position: relative; border: 0; padding: 0 1.1rem; color: var(--muted); background: transparent;
  cursor: pointer; font-size: .8rem; font-weight: 700; letter-spacing: .025em;
}
.nav-tab::after { content: ""; position: absolute; left: 1rem; right: 1rem; bottom: -1px; height: 3px; background: transparent; }
.nav-tab:hover, .nav-tab:focus-visible, .nav-tab.is-active { color: var(--ink); }
.nav-tab.is-active::after { background: var(--oxide); }
.language-toggle {
  justify-self: end; min-width: 58px; border: 1px solid var(--line); padding: .45rem .7rem;
  color: var(--teal-dark); background: var(--white); cursor: pointer; font-size: .75rem; font-weight: 800;
}
.language-toggle:hover, .language-toggle:focus-visible { border-color: var(--teal); }

main { overflow: hidden; }
.hero {
  min-height: 205px; padding: 2.5rem clamp(1rem, 7vw, 7rem) 2rem;
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(420px, .8fr); gap: 3rem; align-items: end;
  border-bottom: 1px solid var(--line); background: var(--white);
}
.eyebrow, .section-no { margin: 0 0 .65rem; color: var(--oxide); font-size: .66rem; font-weight: 800; letter-spacing: .16em; }
.hero h1 { margin: 0; font: 500 clamp(2.2rem, 4.2vw, 4.4rem)/.98 var(--serif); letter-spacing: -.035em; }
.hero div > p:last-child { max-width: 760px; margin: .8rem 0 0; color: var(--muted); font-size: .9rem; }
.data-line { margin: 0 0 .35rem; display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; gap: .35rem; color: var(--muted); font-size: .73rem; }
.data-line strong { color: var(--teal-dark); font: 600 1.4rem/1 var(--serif); }
.data-line i { width: 1px; height: 21px; margin: 0 .55rem; background: var(--line); }

.workspace { width: min(1500px, calc(100% - 2rem)); margin: 0 auto; padding: clamp(2.4rem, 4vw, 4.2rem) clamp(.2rem, 1.5vw, 1.4rem); }
.panel[hidden] { display: none; }
.section-heading { display: grid; grid-template-columns: 1fr minmax(300px, 600px); gap: 2rem; align-items: end; margin-bottom: 1.35rem; }
.section-heading h2 { margin: 0; font: 500 clamp(2rem, 3.7vw, 3.7rem)/1 var(--serif); letter-spacing: -.035em; }
.section-heading > p { margin: 0 0 .25rem; color: var(--muted); font-size: .87rem; }

.control-rail {
  display: grid; gap: 1px; padding: 1px; margin-bottom: .8rem;
  border: 1px solid var(--line); background: var(--line); box-shadow: var(--shadow);
}
.control-rail.two-controls { grid-template-columns: minmax(300px, 1.45fr) minmax(240px, 1fr) auto; }
.control-rail.one-control { grid-template-columns: minmax(300px, 1fr) auto; max-width: 760px; }
.control-rail label, .control-rail .field-control {
  min-height: 70px; padding: .58rem .8rem .45rem; display: flex; flex-direction: column; gap: .18rem;
  color: var(--muted); background: var(--white); font-size: .65rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
}
.control-rail select, .variable-search-input {
  width: 100%; min-width: 0; border: 0; border-bottom: 1px solid #ddd8ce; padding: .32rem 0 .24rem;
  color: var(--ink); background: transparent; outline: 0; font-size: .86rem; font-weight: 500; letter-spacing: 0; text-transform: none;
}
.control-rail select:focus, .variable-search-input:focus { border-color: var(--teal); }
.variable-field { position: relative; z-index: 20; }
.variable-search-box { position: relative; }
.variable-search-input { padding-right: 2rem; font-family: var(--sans); }
.variable-field > small {
  min-height: 1em; overflow: hidden; color: #7a847f; font-size: .62rem; font-weight: 500;
  letter-spacing: 0; line-height: 1.25; text-overflow: ellipsis; text-transform: none; white-space: nowrap;
}
.variable-suggestions {
  position: absolute; z-index: 80; top: calc(100% + .45rem); left: -.8rem; right: -.8rem;
  max-height: 390px; overflow-y: auto; border: 1px solid var(--line); background: rgba(255, 254, 250, .985);
  box-shadow: 0 16px 42px rgba(22, 31, 29, .16); text-transform: none;
}
.variable-suggestion {
  width: 100%; border: 0; border-bottom: 1px solid #e8e3da; padding: .7rem .8rem;
  display: grid; grid-template-columns: minmax(150px, .75fr) minmax(260px, 1.6fr) auto;
  gap: .8rem; align-items: center; color: var(--ink); background: transparent; text-align: left; cursor: pointer;
}
.variable-suggestion:last-child { border-bottom: 0; }
.variable-suggestion:hover, .variable-suggestion.is-active { background: #ece8df; }
.variable-suggestion strong { font-size: .78rem; line-height: 1.25; }
.variable-suggestion p { margin: 0; color: var(--muted); font-size: .69rem; font-weight: 400; line-height: 1.3; }
.variable-suggestion small { color: var(--teal-dark); font-size: .61rem; font-weight: 800; white-space: nowrap; }
.variable-no-match { padding: .9rem; color: var(--muted); font-size: .72rem; font-weight: 500; text-transform: none; }
.primary-button { min-height: 70px; border: 0; padding: 0 1.4rem; color: white; background: var(--teal-dark); cursor: pointer; font-size: .78rem; font-weight: 800; letter-spacing: .035em; }
.primary-button:hover, .primary-button:focus-visible { background: var(--oxide); }

.result-banner { min-height: 38px; padding: .58rem .75rem; margin-bottom: .8rem; border-left: 3px solid var(--gold); color: #4e5854; background: #e9e5dc; font-size: .78rem; }
.semantic-note { margin: -.15rem 0 .8rem; padding: .65rem .8rem; border: 1px solid #d8bc85; color: #6e531c; background: #f6ecd4; font-size: .76rem; }
.viz-card { position: relative; border: 1px solid var(--line); background: var(--white); box-shadow: var(--shadow); }
.viz-title { min-height: 70px; padding: .9rem 1.1rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; border-bottom: 1px solid var(--line); }
.viz-title h3 { margin: 0; font: 600 1.14rem/1.2 var(--serif); }
.viz-title p { max-width: 900px; margin: .2rem 0 0; color: var(--muted); font-size: .72rem; }
.legend-chip { color: var(--teal-dark); font-size: .67rem; font-weight: 800; letter-spacing: .035em; white-space: nowrap; }
.visual-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: .42rem .82rem; color: var(--teal-dark); font-size: .67rem; }
.visual-legend span { display: inline-flex; align-items: center; gap: .38rem; white-space: nowrap; }
.visual-legend b { font-size: .67rem; letter-spacing: .025em; }
.visual-legend small { flex-basis: 100%; color: var(--muted); font-size: .61rem; text-align: right; }
.plot-marker { display: inline-block; width: 9px; height: 9px; flex: 0 0 9px; border: 1.4px solid #2b5953; background: #fffefa; }
.marker-cross { border-radius: 50%; }
.marker-follow { border-radius: 1px; border-color: #934521; background: #d9672d; transform: rotate(45deg) scale(.82); }
.canvas-scroll { width: 100%; overflow-x: auto; overflow-y: hidden; }
canvas { display: block; max-width: none; }
.forest-card canvas, .outcome-card canvas { width: 100%; height: auto; min-width: 880px; }
.manhattan-scroll { max-height: 660px; }
.empty-state { position: absolute; inset: 70px 0 0; display: grid; place-items: center; color: #8b958f; background: rgba(255, 254, 250, .9); font: 500 1.05rem var(--serif); }

.data-fallback { margin-top: .75rem; border: 1px solid var(--line); background: rgba(255, 254, 250, .8); }
.data-fallback summary { padding: .68rem .85rem; cursor: pointer; font-size: .74rem; font-weight: 800; }
.table-wrap { max-height: 390px; overflow: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: .72rem; font-variant-numeric: tabular-nums; }
th { position: sticky; z-index: 2; top: 0; padding: .62rem .7rem; text-align: left; color: #4d5753; background: #e9e5dc; letter-spacing: .02em; }
td { padding: .56rem .7rem; border-top: 1px solid #e7e2d8; vertical-align: top; }
td small { color: var(--muted); }
tbody tr:hover { background: #f5f2eb; }

.metric-strip { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: .8rem; border: 1px solid var(--line); background: var(--white); }
.metric-strip div { min-height: 78px; padding: .75rem 1rem; display: flex; flex-direction: column; justify-content: space-between; border-right: 1px solid var(--line); }
.metric-strip div:last-child { border-right: 0; }
.metric-strip span { color: var(--teal-dark); font: 600 1.55rem/1 var(--serif); }
.metric-strip small { color: var(--muted); font-size: .7rem; }
.metric-design-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: .72rem; margin-bottom: .8rem; }
.metric-layer { border: 1px solid var(--line); border-top: 3px solid #2b7168; background: var(--white); box-shadow: 0 4px 16px rgba(33,46,43,.045); }
.metric-layer.is-follow-up { border-top-color: #c75a2c; }
.metric-layer > header { min-height: 38px; padding: .48rem .75rem; display: flex; align-items: center; gap: .43rem; border-bottom: 1px solid var(--line); }
.metric-layer > header strong { font: 600 .86rem/1.2 var(--serif); }
.metric-layer > header small { margin-left: auto; color: var(--muted); font-size: .65rem; font-weight: 800; }
.metric-values { display: grid; grid-template-columns: repeat(4, 1fr); }
.metric-values div { min-height: 66px; padding: .62rem .7rem; display: flex; flex-direction: column; justify-content: space-between; border-right: 1px solid var(--line); }
.metric-values div:last-child { border-right: 0; }
.metric-values span { color: var(--teal-dark); font: 600 1.27rem/1 var(--serif); }
.metric-layer.is-follow-up .metric-values span { color: #934521; }
.metric-values small { color: var(--muted); font-size: .62rem; }

.tooltip {
  position: fixed; z-index: 100; display: none; max-width: 360px; padding: .7rem .8rem;
  border: 1px solid #4f5d58; color: white; background: #17201e; box-shadow: 0 8px 24px rgba(0,0,0,.24);
  pointer-events: none; font-size: .72rem; line-height: 1.45;
}
.tooltip.is-visible { display: block; }
.tooltip strong { color: #e0bd6d; }

footer {
  min-height: 92px; padding: 1.5rem clamp(1rem, 7vw, 7rem); display: flex; justify-content: space-between; align-items: center;
  color: #d9dfdc; background: var(--ink);
}
footer > span { font: 600 1.25rem var(--serif); }
footer nav { display: flex; flex-wrap: wrap; gap: 1.2rem; }
footer a { color: #9ba7a2; font-size: .7rem; text-underline-offset: .2rem; }

@media (max-width: 1000px) {
  .site-header { grid-template-columns: 1fr auto; }
  .top-nav { position: fixed; z-index: 35; left: 0; right: 0; bottom: 0; height: 54px; justify-content: space-around; border-top: 1px solid var(--line); background: var(--paper); }
  .nav-tab { flex: 1; padding: 0 .35rem; font-size: .72rem; }
  .nav-tab::after { top: -1px; bottom: auto; }
  .language-toggle { grid-column: 2; }
  .hero { grid-template-columns: 1fr; gap: 1.3rem; }
  .data-line { justify-content: flex-start; }
  footer { margin-bottom: 54px; }
}

@media (max-width: 720px) {
  .site-header { min-height: 62px; padding: 0 1rem; }
  .brand small { display: none; }
  .hero { min-height: auto; padding: 2rem 1rem 1.5rem; }
  .data-line i { display: none; }
  .section-heading { grid-template-columns: 1fr; gap: .7rem; }
  .control-rail.two-controls, .control-rail.one-control { grid-template-columns: 1fr; max-width: none; }
  .control-rail label, .control-rail .field-control, .primary-button { min-height: 62px; }
  .variable-suggestion { grid-template-columns: 1fr; gap: .25rem; }
  .metric-strip { grid-template-columns: 1fr 1fr; }
  .metric-strip div:nth-child(2) { border-right: 0; }
  .metric-strip div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .legend-chip { display: none; }
  .viz-title { align-items: flex-start; flex-direction: column; }
  .visual-legend { justify-content: flex-start; }
  .visual-legend small { text-align: left; }
  .metric-design-grid { grid-template-columns: 1fr; }
  .metric-values { grid-template-columns: 1fr 1fr; }
  .metric-values div:nth-child(2) { border-right: 0; }
  .metric-values div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  footer { align-items: flex-start; flex-direction: column; gap: .75rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .panel.is-active { animation: enter .22s ease-out; }
  @keyframes enter { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
}
