:root {
  /* Colors: every color lives in ../css/theme.css (light + dark palettes). */
  --max: 1240px;
  --gutter: clamp(20px, 5vw, 80px);
  --mono: "DM Mono", "SFMono-Regular", Consolas, monospace;
  --sans: "Manrope", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--paper); scroll-behavior: smooth; }

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* Glacier-blue gradient, top to bottom -- kept identical to the same
   rule in index.html. A position:fixed pseudo-element rather than
   background-attachment:fixed on body -- the latter is unreliable on
   iOS Safari, while position:fixed itself is solidly supported
   everywhere. Sits behind the dot texture below. */
body::after {
  content: "";
  position: fixed;
  z-index: -2;
  inset: 0;
  background: linear-gradient(180deg, var(--paper-highlight) 0%, var(--paper) 50%, var(--paper-strong) 100%);
  pointer-events: none;
}

body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  background-image: radial-gradient(var(--dot-color) 0.65px, transparent 0.65px);
  background-size: 22px 22px;
  content: "";
  mask-image: linear-gradient(to bottom, black, transparent 34%, transparent 74%, black);
  pointer-events: none;
}

a { color: inherit; text-decoration: none; }
a:focus-visible { outline: 2px solid var(--blue-text); outline-offset: 4px; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 82px;
  padding: 20px var(--gutter);
  border-bottom: 1px solid var(--rule);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.16em;
  line-height: 1;
  text-transform: uppercase;
}

.wordmark-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: -0.04em;
}

.header-nav { display: flex; align-items: center; gap: 20px; margin-left: auto; }
.header-nav a,
.back-link,
.source-link,
.footer-link { color: var(--ink-soft); font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }
.header-nav a:hover,
.back-link:hover,
.source-link:hover,
.footer-link:hover { color: var(--coral); }

.header-contact {
  flex: 0 0 auto;
  padding: 10px 13px;
  white-space: nowrap;
  border: 1px solid var(--blue);
  border-radius: 999px;
  background: var(--blue);
  color: var(--on-fill);
  font-size: 11px;
  font-weight: 800;
  transition: background 180ms ease, border-color 180ms ease;
}

.header-contact:hover { background: var(--blue-hover); border-color: var(--blue-hover); }

.page-shell { max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter); }

.case-hero {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(360px, 1.1fr);
  gap: clamp(36px, 8vw, 132px);
  align-items: end;
  padding: clamp(70px, 10vw, 140px) 0 84px;
}

.eyebrow,
.section-label,
.metric-label,
.chart-kicker,
.source-kicker {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  line-height: 1.4;
  text-transform: uppercase;
}

.eyebrow { margin: 0 0 25px; color: var(--coral); }
.case-hero h1 { max-width: 680px; margin: 0; font-size: clamp(50px, 8vw, 104px); font-weight: 500; letter-spacing: -0.085em; line-height: 0.93; }
.hero-dek { max-width: 580px; margin: 28px 0 0; color: var(--ink-soft); font-size: clamp(15px, 1.45vw, 19px); line-height: 1.68; }
.back-link { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 28px; }
.back-link span { color: var(--coral); font-size: 15px; }

.signal-panel {
  padding: 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 1px 2px var(--shadow-1), 0 8px 24px var(--shadow-2);
}

.signal-panel-head,
.signal-panel-foot,
.chart-head,
.case-section-head,
.source-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.signal-panel-head strong { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.signal-code { color: var(--muted); font-family: var(--mono); font-size: 10px; }
.signal-panel svg { display: block; width: 100%; height: auto; margin: 32px 0 26px; }
.signal-panel-foot { align-items: flex-end; }
.signal-panel-foot strong { color: var(--blue-text); font-size: 30px; letter-spacing: -0.07em; }
.signal-panel-foot span { max-width: 210px; color: var(--muted); font-size: 11px; line-height: 1.5; text-align: right; }

.model-chart { margin: 0; padding: 18px; border: 1px solid var(--border); background: var(--surface); box-shadow: 0 1px 2px var(--shadow-1), 0 8px 24px var(--shadow-2); }
.chart-kicker { color: var(--ink-soft); }
.chart-value { color: var(--ink); font-family: var(--mono); font-size: 10px; text-align: right; text-transform: uppercase; }
.model-chart svg { display: block; width: 100%; height: auto; margin-top: 20px; overflow: visible; }
.model-chart .grid-line { stroke: var(--rule); stroke-width: 1; }
.model-chart .axis-label, .model-chart .chart-label { fill: var(--muted); font-family: var(--mono); font-size: 9px; }
.model-chart .chart-label { fill: var(--ink-soft); font-size: 9px; }
.model-chart .axis-label.is-on-bar { fill: var(--on-coral-label); }
.model-chart .chart-line { fill: none; stroke: var(--chart-ink); stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.5; }
.model-chart .chart-line-alt { fill: none; stroke: var(--coral); stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.5; }
.model-chart .chart-area { fill: color-mix(in srgb, var(--chart-blue) 13%, transparent); }
.model-chart .chart-point { fill: var(--coral); stroke: var(--surface); stroke-width: 2; }
.model-chart .chart-bar { fill: var(--chart-bar); }
.model-chart .chart-bar.is-base { fill: var(--coral); }
.model-chart .chart-bar.is-positive { fill: var(--blue); }
.model-chart .chart-bar.is-negative { fill: color-mix(in srgb, var(--chart-neg) 46%, transparent); }
.model-chart .chart-bar.is-capex { fill: var(--coral); }
.model-chart .chart-bar.is-risky { fill: var(--blue); }
.model-chart .chart-bar.is-buffer { fill: var(--gold); }
.model-chart .chart-track { fill: color-mix(in srgb, var(--ink) 9%, transparent); }
.model-chart .chart-rule { stroke: var(--rule-strong); stroke-width: 1; }
.model-chart .lolli { stroke: var(--rule-strong); stroke-width: 1.5; }
.model-chart .ghost-link { stroke: var(--coral); stroke-width: 1; stroke-dasharray: 3 3; }
.model-chart .dot-navy { fill: var(--chart-ink); stroke: var(--surface); stroke-width: 2; }
.model-chart .dot-blue { fill: var(--blue); stroke: var(--surface); stroke-width: 2; }
.model-chart .dot-ghost { fill: var(--surface); stroke: var(--coral); stroke-width: 1.5; }
.model-chart .dot-train { fill: var(--surface); stroke: var(--chart-ink); stroke-width: 1.5; }
.model-chart .flow-lane { margin: 18px 0 9px; color: var(--muted); font-family: var(--mono); font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; }
.model-chart .flow-lane:first-of-type { margin-top: 20px; }
.model-chart .flow-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 22px; margin: 0; padding: 0; list-style: none; }
.model-chart .flow-row li { position: relative; padding: 12px 12px 13px; border: 1px solid var(--rule-strong); background: var(--panel-tint); }
.model-chart .flow-row li::after { position: absolute; top: 50%; right: -17px; color: var(--coral); content: "→"; font-size: 13px; line-height: 1; transform: translateY(-50%); }
.model-chart .flow-row li:last-child::after { content: none; }
.model-chart .flow-row b { display: block; color: var(--ink); font-family: var(--mono); font-size: 11px; font-weight: 500; }
.model-chart .flow-row span { display: block; margin-top: 5px; color: var(--muted); font-family: var(--mono); font-size: 9.5px; line-height: 1.45; }
.model-chart .flow-row li.is-out { border-color: var(--dark-fill); background: var(--dark-fill); }
.model-chart .flow-row li.is-out b { color: var(--on-dark); }
.model-chart .flow-row li.is-out span { color: var(--on-dark-subtle); }
.model-chart .score { width: 100%; margin-top: 18px; border-collapse: collapse; font-family: var(--mono); }
.model-chart .score th,
.model-chart .score td { padding: 11px 0; border-bottom: 1px solid var(--rule); text-align: center; font-size: 11px; font-weight: 500; }
.model-chart .score thead th { padding-top: 0; color: var(--muted); font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; }
.model-chart .score th[scope="row"] { color: var(--ink-soft); text-align: left; }
.model-chart .score thead th:first-child { text-align: left; }
.model-chart .score .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--chart-ink); vertical-align: middle; }
.model-chart .score .dot.partial { background: var(--blue); }
.model-chart .score .dot.gap { background: var(--coral); }
.model-chart .verdicts { margin: 16px 0 0; padding: 0; list-style: none; }
.model-chart .verdicts li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; padding: 14px 0; border-bottom: 1px solid var(--rule); }
.model-chart .verdicts b { color: var(--ink); font-family: var(--mono); font-size: 12px; font-weight: 500; }
.model-chart .verdicts em { align-self: start; padding: 3px 9px; border-radius: 3px; color: var(--on-fill); font-family: var(--mono); font-size: 9.5px; font-style: normal; letter-spacing: 0.08em; text-transform: uppercase; }
.model-chart .verdicts em.v-refuse { background: var(--coral); color: var(--on-coral); }
.model-chart .verdicts em.v-build { background: var(--dark-fill); }
.model-chart .verdicts em.v-pilot { background: var(--blue); }
.model-chart .verdicts span { grid-column: 1 / -1; color: var(--muted); font-family: var(--mono); font-size: 10.5px; line-height: 1.5; }
.callout a { text-decoration: underline; }
.chart-key { display: flex; flex-wrap: wrap; gap: 13px; margin-top: 8px; color: var(--muted); font-family: var(--mono); font-size: 9px; line-height: 1.5; text-transform: uppercase; }
.chart-key span { display: inline-flex; align-items: center; gap: 5px; }
.chart-key i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--chart-ink); }
.chart-key i.coral { background: var(--coral); }
.chart-key i.blue { background: var(--blue); }
.chart-key i.gold { background: var(--gold); }
.model-chart figcaption { margin-top: 12px; color: var(--muted); font-family: var(--mono); font-size: 9px; line-height: 1.5; }

.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin: 0; }
.metric { padding-top: 13px; border-top: 1px solid var(--rule-strong); }
.metric strong { display: block; color: var(--blue-text); font-size: clamp(24px, 3vw, 38px); font-weight: 600; letter-spacing: -0.07em; line-height: 1; }
.metric-label { display: block; margin-top: 8px; font-size: 9px; }

.case-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(250px, 0.32fr); gap: clamp(40px, 8vw, 126px); padding: 0 0 120px; }
.case-main { min-width: 0; }
.case-section { padding: 34px 0 38px; border-top: 1px solid var(--rule); }
.case-section:first-child { padding-top: 0; border-top: 0; }
.case-section h2 { margin: 0; font-size: clamp(24px, 3vw, 42px); font-weight: 500; letter-spacing: -0.065em; line-height: 1; }
.case-section p { max-width: 720px; margin: 18px 0 0; color: var(--ink-soft); font-size: 15px; line-height: 1.75; }
.case-section p + p { margin-top: 12px; }
.callout { margin-top: 26px; padding: 18px 20px; border-left: 3px solid var(--coral); background: color-mix(in srgb, var(--coral) 8%, transparent); color: var(--ink-soft); font-size: 13px; line-height: 1.65; }

.table-wrap { margin-top: 26px; overflow-x: auto; }
.spec-table { width: 100%; min-width: 0; border-collapse: collapse; font-family: var(--mono); font-size: 11px; }
.spec-table th,
.spec-table td { padding: 10px 14px 10px 0; border-bottom: 1px solid var(--rule); text-align: right; }
.spec-table td:not(:first-child) { white-space: nowrap; }
.spec-table th:first-child,
.spec-table td:first-child { text-align: left; color: var(--ink-soft); }
.spec-table th:last-child,
.spec-table td:last-child { padding-right: 0; }
.spec-table thead th { border-bottom-color: var(--rule-strong); color: var(--muted); font-size: 9px; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; }
.spec-table caption { padding-bottom: 10px; color: var(--muted); font-size: 10px; letter-spacing: 0.12em; text-align: left; text-transform: uppercase; }
.spec-table tr.is-divider td { border-top: 1px solid var(--rule-strong); }
.spec-table.is-text th,
.spec-table.is-text td { padding-right: 24px; text-align: left; vertical-align: top; white-space: normal; }
.spec-table.is-text td:first-child { width: 30%; color: var(--ink); }
.spec-table.is-text td:last-child,
.spec-table.is-text th:last-child { padding-right: 0; }
.spec-table td.is-flag { color: var(--coral); }
.spec-table td.is-strong { color: var(--ink); font-weight: 500; }

.case-section code,
.aside-list code { padding: 1px 5px; border-radius: 3px; background: var(--code-bg); font-family: var(--mono); font-size: 0.86em; }
.case-section h2 code { font-size: 0.72em; }
.case-section .model-chart { margin-top: 26px; }
.case-section .metric-grid { margin: 26px 0; }
.model-chart .chart-image { display: block; margin-top: 18px; border: 1px solid var(--rule); background: var(--image-backdrop); }
.model-chart .chart-image img { display: block; width: 100%; height: auto; }
.model-chart .chart-video { display: block; width: 100%; height: auto; margin-top: 18px; background: var(--media-bg); }

.case-aside { align-self: start; padding-top: 0; }
.aside-block { padding: 20px 0; border-top: 1px solid var(--rule); }
.aside-block:first-child { padding-top: 0; border-top: 0; }
.aside-block h3 { margin: 0 0 14px; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.aside-list { display: grid; gap: 11px; margin: 0; padding: 0; list-style: none; }
.aside-list li { color: var(--ink-soft); font-size: 12px; line-height: 1.55; }
.aside-list strong { display: block; color: var(--ink); font-size: 11px; }
.source-list { display: grid; gap: 10px; }
.source-link { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--rule); line-height: 1.45; }
.source-link span { color: var(--coral); font-size: 14px; }

.page-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px var(--gutter) 28px; border-top: 1px solid var(--rule); color: var(--muted); font-family: var(--mono); font-size: 9px; line-height: 1.5; text-transform: uppercase; }
.page-footer span:last-child { text-align: right; }

@media (max-width: 860px) {
  .header-nav { display: none; }
}

@media (max-width: 820px) {
  .case-hero { grid-template-columns: 1fr; gap: 54px; }
  .case-body { grid-template-columns: 1fr; padding-bottom: 90px; }
  .case-aside { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; }
  .aside-block, .aside-block:first-child { padding-top: 20px; border-top: 1px solid var(--rule); }
}

@media (max-width: 600px) {
  .model-chart .flow-row { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 16px; }
  .model-chart .flow-row li:nth-child(2n)::after { content: none; }
  .site-header { min-height: 70px; padding-top: 14px; padding-bottom: 14px; }
  .wordmark { font-size: 10px; }
  .wordmark-mark { width: 27px; height: 27px; }
  .header-nav { display: none; }
  .header-contact { padding: 9px 10px; font-size: 10px; }
  .case-hero { padding-top: 66px; padding-bottom: 68px; }
  .case-hero h1 { font-size: clamp(46px, 15vw, 70px); }
  .hero-dek { font-size: 14px; }
  .signal-panel { padding: 17px; }
  .signal-panel svg { margin: 25px 0 20px; }
  .metric-grid { gap: 11px; }
  .metric strong { font-size: 20px; }
  .metric-label { font-size: 8px; }
  .case-aside { grid-template-columns: 1fr; }
  .page-footer { align-items: flex-start; flex-direction: column; }
  .page-footer span:last-child { text-align: left; }
}

/* ============================================================
   App case pages (matatah.html, mineral-trace.html): the live app in a
   "product demo window", the same one as the homepage #apps cards.
   js/app-embed.js creates the iframe on click; below 720px it never
   does, and the cover shows plain links instead.
   ============================================================ */
.signal-panel .app-thumb { display: block; width: 100%; height: auto; margin: 32px 0 26px; border: 1px solid var(--border); }

.case-app { margin: 0 0 clamp(64px, 8vw, 110px); }
.case-app .section-label { margin-bottom: 16px; }
.app-window { overflow: hidden; border: 1px solid var(--border); background: var(--surface); box-shadow: 0 1px 2px var(--shadow-1), 0 8px 24px var(--shadow-2); }
.app-window-bar { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-bottom: 1px solid var(--border); }
.app-window-bar i { width: 8px; height: 8px; border-radius: 50%; background: color-mix(in srgb, var(--ink) 18%, transparent); }
.app-window-bar i:first-child { background: var(--coral); }
.app-window-bar span { margin-left: 10px; color: var(--muted); font-family: var(--mono); font-size: 10px; }
.app-window-view { position: relative; display: block; height: 640px; background: var(--section-dark); }
.app-window-view iframe { display: block; width: 100%; height: 100%; border: 0; background: var(--surface); }
.app-window:fullscreen { display: flex; flex-direction: column; border: 0; }
.app-window:fullscreen .app-window-view { flex: 1; height: auto; }

.app-cover { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; color: var(--on-dark); text-align: center; isolation: isolate; }
.app-cover::before { position: absolute; z-index: -1; inset: 0; background: linear-gradient(color-mix(in srgb, var(--section-dark) 78%, transparent), color-mix(in srgb, var(--section-dark) 90%, transparent)), var(--cover-img, none) center top / cover no-repeat; filter: blur(2px); content: ""; }
.app-cover-name { margin: 0; font-size: clamp(28px, 3.4vw, 48px); font-weight: 600; letter-spacing: -0.075em; line-height: 1; }
.app-cover-load { display: inline-flex; align-items: center; min-height: 40px; padding: 0 18px; border: 1px solid var(--on-dark); border-radius: 999px; background: transparent; color: var(--on-dark); font: 800 12px/1 var(--sans); cursor: pointer; transition: background 180ms ease, color 180ms ease; }
.app-cover-load:hover, .app-cover-load:focus-visible { background: var(--on-dark); color: var(--section-dark); }
.app-cover-note { max-width: 320px; margin: 0; color: var(--on-dark-soft); font-family: var(--mono); font-size: 10px; line-height: 1.5; }
.app-cover-links { display: none; flex-wrap: wrap; justify-content: center; gap: 8px; }
.app-cover-links a { padding: 7px 10px; border: 1px solid color-mix(in srgb, var(--on-dark) 40%, transparent); border-radius: 5px; color: var(--on-dark); font-family: var(--mono); font-size: 10px; }
.app-embed.is-loading .app-cover-load { opacity: 0.6; pointer-events: none; }


.app-embed-bar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 14px; }
.app-embed-bar p { margin: 0; color: var(--muted); font-family: var(--mono); font-size: 10px; line-height: 1.5; }
.app-embed-actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; gap: 8px; }
.app-action { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 11px; border: 1px solid var(--border); border-radius: 5px; background: transparent; color: var(--ink-soft); font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; cursor: pointer; transition: border-color 180ms ease, color 180ms ease; }
.app-action span { color: var(--coral); }
.app-action:hover { border-color: var(--coral); color: var(--coral); }
.app-embed-actions .is-narrow { display: none; }

@media (max-width: 719.98px) {
  .app-window-view { height: 360px; }
  .app-cover-load { display: none; }
  .app-cover-links { display: flex; }
  .app-embed-bar { align-items: flex-start; flex-direction: column; }
  .app-embed-actions .is-wide { display: none; }
  .app-embed-actions .is-narrow { display: inline-flex; }
}
.app-signal .signal-panel-head + .signal-panel-foot { margin-top: 56px; }

/* "Results · try the model" (ai-energy-nexus.html): headline stats, the
   note line and the live slider panel. The panel itself is styled in
   css/live-model.css, shared with the homepage. */
.case-results { margin: 34px 0 0; }
.case-results .section-label { margin-bottom: 16px; }
.results-note { margin: 16px 0 0; color: var(--muted); font-family: var(--mono); font-size: 10px; line-height: 1.5; }
