/* /engineering. Builds on styles.css (tokens, bar, buttons, field, Bloopie); everything here uses the same tokens, so both themes just work. */

/* --- hero: the claim on the left, the page measuring itself on the right ------------------------ */
.eh { position: relative; padding: calc(var(--bar-h) + clamp(48px, 10vh, 120px)) 0 clamp(56px, 9vh, 110px); }
.eh-in { display: grid; gap: 40px; align-items: center; }
.eh h1 { font-size: clamp(40px, 6.6vw, 86px); max-width: 15ch; text-wrap: balance; }
.eh .lede { max-width: 54ch; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); animation: pulse 2.4s var(--ease) infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 10px transparent; } }
@media (min-width: 1000px) { .eh-in { grid-template-columns: 1.08fr .92fr; gap: 56px; } }

.trace { margin: 0; border: 1px solid var(--line-2); border-radius: 18px; background: var(--glass); backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: var(--card-shadow); overflow: hidden; min-width: 0; }
.trace-bar { display: flex; align-items: center; gap: 7px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.trace-bar i { width: 10px; height: 10px; border-radius: 50%; background: var(--line-2); }
.trace-bar i:first-child { background: var(--signal); }
.trace-bar span { margin-left: 8px; font-size: 10.5px; color: var(--faint); text-transform: none; letter-spacing: .02em; }
.trace-out { margin: 0; padding: 16px 18px 18px; min-height: 252px; font: 400 12.5px/1.75 var(--mono); color: var(--code-text); white-space: pre-wrap; word-break: break-word; }
.trace-out .tk { color: var(--signal-text); white-space: pre; }
.trace-out .tl-ok { color: var(--ok); }
.trace-cap { padding: 12px 18px 16px; border-top: 1px solid var(--line); color: var(--faint); font-size: 12.5px; line-height: 1.45; }

/* --- the record ------------------------------------------------------------------------------- */
.rec { padding-top: 24px; }
.rec-stats b { font-size: clamp(26px, 3.6vw, 40px); }

/* --- cases: the steps scroll, the diagram stays put and lights up -------------------------------- */
.case-head { max-width: 900px; margin-bottom: 36px; }
.case-head h2 { font-size: clamp(32px, 6vw, 60px); }
.case-meta { display: grid; gap: 14px; margin: 26px 0 0; }
.case-meta > div { display: grid; gap: 6px; align-content: start; padding-top: 12px; border-top: 1px solid var(--line); }
.case-meta dt { color: var(--faint); font-size: 11px; }
.case-meta dd { margin: 0; color: var(--muted); font-size: 14.5px; line-height: 1.5; }
.case-meta .stack { margin-top: 2px; }
@media (min-width: 900px) { .case-meta { grid-template-columns: 1.3fr .7fr 1.2fr; gap: 28px; } }

.case-body { display: grid; gap: 0; }
.case-fig { position: sticky; top: var(--bar-h); z-index: 2; margin: 0 calc(-1 * var(--gutter)); padding: 10px var(--gutter) 8px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.dg { width: 100%; height: auto; max-height: 42svh; overflow: visible; }
.dg-cap { margin-top: 4px; font-size: 10.5px; color: var(--faint); letter-spacing: .06em; }
.steps { display: grid; gap: 0; padding-top: 8px; }
.step { min-height: 52svh; padding: 26px 0 26px 18px; border-left: 2px solid var(--line); display: grid; align-content: center; gap: 10px; cursor: pointer;
  transition: border-color .35s var(--ease), opacity .35s var(--ease); opacity: .5; }
.step:last-child { min-height: 46svh; }
.step.is-on { border-color: var(--signal); opacity: 1; }
.step .step-k { color: var(--signal-text); font-size: 11px; }
.step h3 { font: 560 clamp(20px, 2.4vw, 26px)/1.2 var(--font); font-stretch: 104%; letter-spacing: -.018em; text-wrap: balance; }
.step p { color: var(--muted); font-size: 15.5px; max-width: 58ch; }
.trade { font-size: 14px !important; padding: 10px 12px; border-radius: 10px; background: var(--bg-3); }
.trade b { color: var(--text); font-weight: 620; margin-right: 6px; }
.calls { display: grid; gap: 8px; color: var(--muted); font-size: 15px; }
.calls li { position: relative; padding-left: 18px; }
.calls li::before { content: ""; position: absolute; left: 0; top: .62em; width: 7px; height: 7px; border-radius: 2px; background: var(--signal); transform: rotate(45deg); }
@media (min-width: 1000px) {
  .case-body { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 56px; align-items: start; }
  .case-fig { order: 2; top: calc(var(--bar-h) + 28px); margin: 0; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--glass); box-shadow: var(--card-shadow); }
  .dg { max-height: calc(100svh - var(--bar-h) - 120px); }
  .steps { order: 1; padding-top: 0; }
  .step { min-height: 72svh; }
  .step:first-child { min-height: 52svh; align-content: start; padding-top: 8px; }
}

/* --- the diagrams ------------------------------------------------------------------------------- */
.dg text { font-family: var(--font); }
.dg-zone { fill: none; stroke: var(--line-2); stroke-width: 1; stroke-dasharray: 3 5; }
.dg-zl { font: 500 9.5px var(--mono) !important; fill: var(--faint); letter-spacing: .08em; text-transform: uppercase; }
.dg-n { transition: opacity .45s var(--ease); }
.dg-box { fill: var(--bg-2); stroke: var(--line-2); stroke-width: 1.2; transition: fill .45s var(--ease), stroke .45s var(--ease); }
.dg-l { font: 600 12.5px var(--font) !important; fill: var(--text); letter-spacing: -.01em; }
.dg-c { font: 500 10.5px var(--mono) !important; fill: var(--muted); }
.dg-s { font: 400 9px var(--mono) !important; fill: var(--faint); letter-spacing: .02em; }
.k-ghost .dg-box { fill: transparent; stroke-dasharray: 4 4; }
.k-dot .dg-box { fill: var(--bg-3); }
.k-dot .dg-l { font: 500 10px var(--mono) !important; fill: var(--muted); }
.dg-n.on .dg-box { stroke: var(--signal); fill: color-mix(in srgb, var(--signal) 16%, var(--bg-2)); }
.k-dot.on .dg-box { fill: var(--signal); }
.k-ghost.on .dg-box { fill: transparent; }
.has-step .dg-n:not(.on) { opacity: .34; }
.dg-line { fill: none; stroke: var(--line-2); stroke-width: 1.2; transition: stroke .45s var(--ease), opacity .45s var(--ease); }
.dg-flow { fill: none; stroke: var(--signal); stroke-width: 1.6; stroke-dasharray: 5 9; opacity: 0; transition: opacity .45s var(--ease); }
.dg-arrow { fill: none; stroke: var(--line-2); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.dg-el { font: 400 8.5px var(--mono) !important; fill: var(--faint); paint-order: stroke; stroke: var(--bg-2); stroke-width: 3px; }
.dg-p { fill: var(--signal); opacity: 0; transition: opacity .3s; }
.dg-e.on .dg-line { stroke: color-mix(in srgb, var(--signal) 45%, var(--line-2)); }
.dg-e.on .dg-flow { opacity: .9; animation: dgflow 1.1s linear infinite; }
.dg-e.on .dg-arrow { stroke: var(--signal); }
.dg-e.on .dg-p { opacity: 1; }
.has-step .dg-e:not(.on) { opacity: .4; }
@keyframes dgflow { to { stroke-dashoffset: -28; } }
/* phones: the diagram is drawn ~0.55x, so its type is set larger to land near 8-9 px on screen */
@media (max-width: 759px) {
  .dg-l { font-size: 16px !important; } .dg-s { font-size: 11px !important; } .dg-c { font-size: 13px !important; }
  .dg-zl { font-size: 11.5px !important; } .dg-el { font-size: 10.5px !important; } .k-dot .dg-l { font-size: 13px !important; }
  .dg-s { display: none; } .dg-n:not(.k-chip):not(.k-dot) .dg-l { transform: translateY(5px); }
}
:root[data-theme="dark"] .dg-n.on .dg-box, :root:not([data-theme="light"]) .dg-n.on .dg-box { filter: drop-shadow(0 0 calc(6px * var(--glow-core, 0)) rgba(var(--signal-rgb), .5)); }

/* --- habits ------------------------------------------------------------------------------------- */
.habits { display: grid; gap: 14px; counter-reset: h; }
.habits li { display: grid; gap: 10px; align-content: start; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); box-shadow: var(--card-shadow); }
.habits span { color: var(--signal-text); }
.habits h3 { font: 560 19px/1.25 var(--font); font-stretch: 104%; letter-spacing: -.012em; }
.habits p { color: var(--muted); font-size: 15px; }
@media (min-width: 760px) { .habits { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .habits { grid-template-columns: repeat(3, 1fr); } }

/* --- matrix ------------------------------------------------------------------------------------- */
.mx-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.mx { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 14px; }
.mx th, .mx td { padding: 0; border-bottom: 1px solid var(--line); }
.mx tbody tr:last-child > * { border-bottom: 0; }
.mx thead th { padding: 14px 10px; font: 500 11px/1.3 var(--mono); letter-spacing: .04em; text-transform: uppercase; color: var(--faint); text-align: center; vertical-align: bottom; }
.mx thead a { color: inherit; text-decoration: none; } .mx thead a:hover { color: var(--signal-text); }
.mx tbody th { text-align: left; width: 34%; }
.mx tbody th button { width: 100%; min-height: 48px; padding: 0 16px; border: 0; background: none; text-align: left; font: 500 14.5px/1.3 var(--font); color: var(--text); }
.mx tbody th button:hover { color: var(--signal-text); }
.mx td { text-align: center; color: var(--line-2); font-size: 12px; }
.mx td[data-on] { color: var(--signal-text); font-size: 15px; }
.mx td:empty::before { content: "·"; color: var(--line-2); }
.mx tr { transition: opacity .3s, background .3s; }
.mx.has-sel tbody tr:not(.sel) { opacity: .35; }
.mx tr.sel { background: var(--signal-dim); }

/* --- talk --------------------------------------------------------------------------------------- */
.talk h2 { font-size: clamp(30px, 5.4vw, 56px); max-width: 18ch; text-wrap: balance; }
.addr { font-family: var(--mono); font-size: 13px; color: var(--text); user-select: all; }
.src-note { margin-top: 28px; color: var(--faint); font-size: 11px; max-width: 62ch; text-transform: none; letter-spacing: .02em; line-height: 1.6; }

/* --- reveals (only when motion is allowed; JS adds .rv) ----------------------------------------- */
.rv { opacity: 0; transform: translateY(14px); transition: opacity .7s var(--ease), transform .7s var(--ease); }
.rv.in { opacity: 1; transform: none; }
.step.rv.in:not(.is-on) { opacity: .5; }
@media (prefers-reduced-motion: reduce) { .rv { opacity: 1; transform: none; } .dg-e.on .dg-flow { animation: none; } }
