/* css/base.css — reset, layout, typography, safe-area insets, dvh sizing, the
   figure plate. A's mobile fixes kept: safe areas, 100dvh, no horizontal scroll,
   ≥44px tap targets on phones, [hidden] always wins. */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-height: 100dvh; }
body {
  margin: 0;
  background: var(--page-bg);
  color: var(--anatomy-text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
  min-height: 100dvh;
  padding: 12px max(10px, env(safe-area-inset-left)) max(28px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-right));
}
@media (min-width: 640px) { body { padding: 16px 24px 36px; } }
@media (min-width: 1024px) { body { padding: 20px 32px 44px; } }

h1, h2, h4, p { margin: 0; }
button { font: inherit; color: inherit; }
a { color: var(--anatomy-lit); }

code {
  font-family: var(--font-num);
  font-size: .93em;
  padding: 0 3px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--panel-bg) 82%, var(--anatomy-shade-1));
}
kbd {
  display: inline-block; padding: 1px 4px; font-size: 10px; border-radius: 3px;
  border: 1px solid var(--panel-border); background: var(--panel-bg);
  font-family: var(--font-num);
}

.container-main { max-width: 1152px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

.serif-title { font-family: var(--font-title); font-weight: 400; }
.mono { font-family: var(--font-label); font-variant-numeric: tabular-nums; }
.hand { font-family: var(--font-hand); font-size-adjust: .5; letter-spacing: .3px; }

/* ---------- header + search ---------- */
.header-bar { display: flex; flex-direction: column; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--panel-border); }
@media (min-width: 768px) { .header-bar { flex-direction: row; align-items: center; justify-content: space-between; } }
.main-heading {
  font-size: clamp(1.35rem, 3.5vw, 1.875rem);
  font-weight: 400; letter-spacing: -0.015em; line-height: 1.2; color: var(--anatomy-strong);
}
.header-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; min-width: 0; }
.status-group, .theme-group { display: flex; align-items: center; gap: 5px; min-width: 0; }
.status-group { flex-wrap: wrap; }
.header-bar > * { min-width: 0; }

.search-bar { display: flex; gap: 6px; }
.search-bar input {
  flex: 1; min-width: 0; font-size: 13px; padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--panel-border); border-radius: 8px;
  background: var(--anatomy-card); color: var(--anatomy-text); font-family: var(--font-num);
  -webkit-appearance: none; appearance: none;
}
.search-bar input::placeholder { color: var(--anatomy-muted); opacity: .8; }
.search-bar input:focus-visible { outline: 2px solid var(--anatomy-lit); outline-offset: 1px; }
.search-bar .ctrl-btn { min-height: 44px; padding-inline: 16px; }
.search-bar.busy .ctrl-btn { opacity: .6; pointer-events: none; }
.search-msg { font-size: 11.5px; color: var(--anatomy-muted); margin-top: -6px; overflow-wrap: anywhere; }
.search-msg:empty { display: none; }

/* ---------- figure plate ---------- */
.iso-card {
  position: relative;
  background: var(--anatomy-card);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  contain: layout paint;
}
.iso-card:focus-visible { box-shadow: 0 0 0 2px var(--anatomy-lit); }

.corner-bar-top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px;
  padding: 10px 14px 4px; font-size: 11px; pointer-events: none;
}
.corner-bar-bottom {
  display: flex; flex-direction: column; gap: 6px; padding: 6px 14px 10px; font-size: 11px;
  border-top: 1px solid var(--panel-border);
}
@media (min-width: 768px) { .corner-bar-bottom { flex-direction: row; align-items: center; justify-content: space-between; } }

.cb-left { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 10px; min-width: 0; }
.cb-fig { font-weight: 600; color: var(--anatomy-strong); white-space: nowrap; }
.cb-title { color: var(--anatomy-muted); }
.cb-right { color: var(--anatomy-muted); text-align: right; }

.stage-frame { position: relative; width: 100%; max-width: min(880px, calc(76dvh * 4 / 3)); margin: 0 auto; }
@media (max-width: 639px) { .stage-frame { max-width: none; } }

.stage-wrap {
  position: relative;
  aspect-ratio: 720 / 540;
  width: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse 70% 60% at 50% 55%, color-mix(in srgb, var(--anatomy-lit) 14%, transparent), transparent 72%);
}
.stage-wrap::after {
  content: "";
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 56%, color-mix(in srgb, var(--anatomy-paper) 72%, transparent) 100%);
}
.shader-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; will-change: transform; }
#mote-cv { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
.scan {
  position: absolute; left: 0; right: 0; top: 0; height: 36%; z-index: 3; pointer-events: none;
  background: linear-gradient(transparent, color-mix(in srgb, var(--anatomy-lit) 10%, transparent) 50%, transparent);
  transform: translateY(-100%);
  animation: v5scan 7s linear infinite;
}
@keyframes v5scan { to { transform: translateY(300%); } }
body.lite .scan, body.lite #shader-canvas { display: none; }
@media (prefers-reduced-motion: reduce) { .scan { display: none; } }

.iso-svg { display: block; position: relative; z-index: 2; width: 100%; height: 100%; cursor: grab; touch-action: pan-y; }
.iso-svg:active { cursor: grabbing; }
.iso-svg.zoomed { cursor: move; touch-action: none; }
.assembly-hit { cursor: pointer; }

/* ---------- vector classes (A's CAD + sketchbook fills) ---------- */
.iso-paper { fill: var(--anatomy-paper); stroke: none; }
.iso-top { fill: var(--anatomy-top); stroke: none; }
.iso-s0 { fill: var(--anatomy-shade-0); stroke: none; }
.iso-s1 { fill: var(--anatomy-shade-1); stroke: none; }
.iso-s2 { fill: var(--anatomy-shade-2); stroke: none; }
.iso-s3 { fill: var(--anatomy-shade-3); stroke: none; }
.iso-lit-top { fill: var(--anatomy-lit-top); stroke: none; }
.iso-lit-side { fill: var(--anatomy-lit-shade); stroke: none; }

.iso-stroke-hi { fill: none; stroke: var(--anatomy-hi); stroke-width: calc(var(--anatomy-weight) * 1.45); stroke-linecap: round; stroke-linejoin: round; }
.iso-stroke-lit { fill: none; stroke: var(--anatomy-lit); stroke-width: calc(var(--anatomy-weight) * 1.65); stroke-linecap: round; stroke-linejoin: round; }
.iso-stroke-mid { fill: none; stroke: var(--anatomy-mid); stroke-width: calc(var(--anatomy-weight) * 1.1); stroke-linecap: round; stroke-linejoin: round; }
.iso-stroke-lo { fill: none; stroke: var(--anatomy-lo); stroke-width: var(--anatomy-weight); stroke-linecap: round; stroke-linejoin: round; }
.iso-stroke-faint { fill: none; stroke: var(--anatomy-faint); stroke-width: calc(var(--anatomy-weight) * 0.85); stroke-linecap: round; stroke-linejoin: round; }
.iso-pipe-paper { fill: none; stroke: var(--anatomy-paper); stroke-width: 3.4px; stroke-linecap: round; stroke-linejoin: round; }
.iso-dot { fill: var(--anatomy-dot); stroke: none; }
.iso-dot-lit { fill: var(--anatomy-lit); stroke: none; }

/* layer visibility (A's rules) */
#layer-neighbors { transition: opacity .26s ease; }
#layer-neighbors.swap { opacity: 0; }
#iso-stage.nb-far #layer-neighbors { opacity: 0; pointer-events: none; }
#layer-solids, #layer-wires, #layer-fast-kinematics { transition: opacity .26s ease; }
#iso-stage.lod-low #layer-solids, #iso-stage.lod-low #layer-wires, #iso-stage.lod-low #layer-fast-kinematics { opacity: .5; }
#layer-neighbors .nb-dot { display: none; }
#iso-stage.lod-low #layer-neighbors .nb > path { display: none; }
#iso-stage.lod-low #layer-neighbors .nb-dot { display: inline; }
#layer-tx { display: none; }
#iso-stage.txview #layer-tx { display: inline; }
#iso-stage.txview #layer-solids, #iso-stage.txview #layer-wires,
#iso-stage.txview #layer-fast-kinematics, #iso-stage.txview #layer-neighbors { display: none; }
#layer-solids[data-spot="1"] [data-station-hit]:not([data-station-hit="1"]),
#layer-solids[data-spot="2"] [data-station-hit]:not([data-station-hit="2"]),
#layer-solids[data-spot="3"] [data-station-hit]:not([data-station-hit="3"]),
#layer-solids[data-spot="4"] [data-station-hit]:not([data-station-hit="4"]),
#layer-solids[data-spot="5"] [data-station-hit]:not([data-station-hit="5"]),
#layer-solids[data-spot="6"] [data-station-hit]:not([data-station-hit="6"]) { opacity: .3; }

body:not(.nerd) .nerd-only { display: none !important; }
body.era1 [data-station="4"] { opacity: .4; }

/* ---------- hover/touch fix layer (A's v10.2) ---------- */
@media (hover: none) {
  .ctrl-btn:hover { border-color: var(--panel-border); box-shadow: none; }
  .ctrl-btn.active:hover { border-color: var(--anatomy-lit); }
  .station-pill:hover { border-color: var(--panel-border); color: var(--anatomy-muted); }
  .station-pill.active:hover { border-color: var(--anatomy-lit); color: var(--anatomy-strong); }
  .byte-seg:hover { filter: none; }
  .fl-row:hover:not(.sel), .lv-row:hover, .tx-row:hover { background: transparent; box-shadow: none; }
  .hex-cell:hover:not(.sel), .tk:hover:not(.new) { border-color: var(--panel-border); color: var(--anatomy-text); }
}
@media (pointer: coarse) {
  .hex-cell { font-size: 11px; padding: 6px 8px; min-width: 32px; text-align: center; }
  .tk { min-height: 34px; }
}

/* ---------- phones (A's §phones, kept; callouts stack above; ≥44px taps, ≥11px text) ---------- */
@media (max-width: 639px) {
  .header-tools { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 8px; }
  .status-group .ctrl-btn:first-child { flex: 1 1 auto; justify-content: center; }
  .theme-group { overflow-x: auto; scrollbar-width: none; margin-inline: -10px; padding-inline: 10px; scroll-snap-type: x proximity; }
  .theme-group::-webkit-scrollbar { display: none; }
  .theme-group .ctrl-btn { flex: 0 0 auto; min-height: 40px; padding: 6px 12px; font-size: 12px; scroll-snap-align: start; }

  .corner-bar-top { flex-direction: column; align-items: flex-start; gap: 3px; padding: 10px 12px 6px; }
  .cb-right { text-align: left; font-size: 10.5px; }
  .hud, .hud.tl { position: static; padding: 6px 8px; gap: 6px; }
  .hud.tl { padding-bottom: 2px; }
  .hud.tl #z-dna { margin-left: auto; }
  .hud:not(.tl) { justify-content: space-between; padding-top: 2px; }
  .hud .ctrl-btn { min-width: 42px; min-height: 44px; background: var(--anatomy-card); }
  .hud:not(.tl) #z-tx { min-width: 0; padding: 0 12px; }
  .corner-bar-bottom { padding: 8px 12px 10px; }
  #live-readout { font-size: 11px; }

  .dock .ctrl-btn { min-height: 46px; font-size: 12px; }
  .station-pill { flex-basis: 74%; min-height: 56px; }
  .station-pill-sub { white-space: normal; }
  .dna-actions { width: 100%; }
  #byte-src { flex: 1 0 100%; }
  .dna-actions .ctrl-btn { flex: 1 1 0; justify-content: center; min-height: 40px; }
  .field-list { max-height: none; overflow: visible; }
  .metrics-3col { grid-template-columns: 1fr; }
  .callout-row { display: flex; }
  #layer-sketch { display: none; }
  .byte-strip-svg .bs-note { display: none; }
}
@media (min-width: 640px) {
  .hud { position: absolute; right: 8px; bottom: 8px; z-index: 5; }
  .hud.tl { left: 8px; right: auto; top: 8px; bottom: auto; }
  .callout-row { display: none; }
}

/* prefers-reduced-motion: still the drawing, keep the reading */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01s !important; transition-duration: .01s !important; }
}

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

.noscript-box { border-color: var(--anatomy-lit); color: var(--anatomy-lit); padding: 12px 14px; }
