/* ---------------------------------------------------------------------------
   Responsive + motion layer.

   Both design artifacts are desktop-only and style everything with inline `style`
   attributes, which a stylesheet can only override with !important. These rules
   live OUTSIDE design-source/ on purpose: re-exporting the artifacts overwrites
   the .dc.html files, and mobile support must not vanish when that happens.

   Selectors lean on inline-style substrings (the artifacts have almost no classes),
   which is brittle by nature — so build.mjs asserts on real viewports that the
   pages do not overflow. A re-export that breaks these fails the build loudly.
   --------------------------------------------------------------------------- */

/* The ambient layers are fixed and full-bleed; the hero swarm canvas is absolutely
   positioned. body hides overflow but html is the scroll container. */
html {
  overflow-x: hidden;
}

img,
svg,
canvas,
iframe {
  max-width: 100%;
}

/* ---------- The [hidden] invariant ------------------------------------------
   The UA stylesheet hides [hidden] elements with `[hidden]{display:none}`, which
   is a *stylesheet* rule — so an inline `display:flex` on the element beats it.
   The artifact styles everything inline, so panels that buildlog.js/ventures.js
   marked hidden stayed fully visible while `el.hidden` cheerfully reported true.
   Restore the invariant: hidden means hidden, whatever the inline style says. */
[hidden] {
  display: none !important;
}

/* ---------- Reduced motion --------------------------------------------------
   The design leans hard on continuous animation: a scrolling grid, scanlines, two
   marquees, a blinking cursor, and a rAF particle swarm. Honour the OS setting.
   (scene.js additionally hides the swarm canvas, which is rAF-driven, not CSS.) */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Mobile nav (markup built by mobile-nav.js) ---------------------- */

.sh-mobilebar,
.sh-menu {
  display: none;
}

.sh-burger {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px; /* keeps the tap target at the accessible minimum */
  height: 44px;
  padding: 0 9px;
  background: transparent;
  border: 1px solid rgba(0, 255, 65, 0.35);
  cursor: pointer;
}

.sh-burger span {
  display: block;
  height: 2px;
  width: 100%;
  background: #00ff41;
  box-shadow: 0 0 8px rgba(0, 255, 65, 0.7);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.sh-burger.sh-open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.sh-burger.sh-open span:nth-child(2) {
  opacity: 0;
}
.sh-burger.sh-open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.sh-menu-link {
  display: block;
  padding: 14px 4px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #00ff41;
  border-bottom: 1px solid rgba(0, 255, 65, 0.15);
}

@media (max-width: 900px) {
  /* Hide the artifact's desktop nav row and show ours. */
  nav > a,
  nav > div:not(.sh-mobilebar):not(.sh-menu) {
    display: none !important;
  }

  nav {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 10px clamp(14px, 4vw, 24px) !important;
  }

  .sh-mobilebar {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .sh-menu {
    display: none;
  }

  .sh-menu.sh-open {
    display: block !important;
    padding: 6px 0 10px;
  }
}

/* ---------- Layout ----------------------------------------------------------
   The Build Log and Story layer map use fixed desktop grid tracks (160px/24px/1fr
   and auto/130px/1fr/auto) that cannot fit a phone: at 390px the chapter header's
   tracks need ~458px, so the title ran off the right edge and collided with the
   caret.

   These hooks (data-chapter-head etc.) are injected by build/build.mjs beside the
   artifact's own markup. They deliberately replace inline-style substring
   selectors: the artifact writes `grid-template-columns:auto 130px 1fr auto`, but
   React re-serializes it spaced, so a selector copied from the source matches
   nothing at all — silently, which is the worst way to be wrong. */
@media (max-width: 720px) {
  /* Story layer map rows: era -> arrow -> name becomes a single column. */
  [data-layer-row] {
    grid-template-columns: 1fr !important;
    gap: 2px !important;
  }

  /* Build Log chapter header. */
  [data-chapter-head] {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  /* The era chip was centred for a 130px track it no longer has. */
  [data-chapter-head] > span {
    justify-self: start;
    text-align: left !important;
  }

  /* Chapter body: narrative + media side by side -> stacked. */
  [data-chapter-grid] {
    grid-template-columns: 1fr !important;
  }

  /* The year is sized per tier (22/30/40px) for a desktop column; at phone width the
     40px flagship year crowds the row it now shares. */
  [data-chapter-head] > span:first-child {
    min-width: 0 !important;
  }
}

/* Marquee tiles and the proof strip carry desktop min-widths. */
@media (max-width: 600px) {
  [style*="min-width: 210px"],
  [style*="min-width: 200px"] {
    min-width: 150px !important;
  }
}

/* ---------- Forms -----------------------------------------------------------
   The artifact's inputs carry inline styles but no focus-visible treatment beyond
   the design's own style-focus, which flattening drops. */
input:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible,
[role='button']:focus-visible {
  outline: 2px solid #00e5ff;
  outline-offset: 2px;
}

/* Placeholder contrast: the design's rgba(0,255,65,.x) placeholders sit near the
   floor of legibility on #050805. */
::placeholder {
  color: rgba(0, 255, 65, 0.45);
  opacity: 1;
}

.sh-form-status {
  font-size: 13px;
  line-height: 1.7;
  padding: 12px 14px;
  border: 1px solid rgba(0, 255, 65, 0.4);
  background: rgba(0, 255, 65, 0.05);
  color: #00ff41;
}

.sh-form-status[data-state='error'] {
  border-color: rgba(255, 90, 90, 0.6);
  background: rgba(255, 90, 90, 0.06);
  color: #ff8a8a;
}

/* Honeypot: present for bots, gone for humans and screen readers. */
.sh-hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
}
