/* ==========================================================================
   frame.css — site chrome & layout primitives
   Layer 2 of 2. Loads AFTER tokens.css. Per-page CSS loads after this and
   may restyle page content, but should NOT override header/footer/grid rules.

   Contents:
     1. Minimal reset + page shell (body, links, selection)
     2. Utilities (.mono, .visually-hidden, .skip-link, .index-num, .sec-head)
     3. Layout: .container, .grid (12-col), .grid-cards, .lift, .section
     4. Site header: paper-glass bar, mono wordmark, uppercase numbered nav
     5. Site footer: ink slab inversion + ICP + "$ whoami" signature
     6. .marquee: infinite ink ticker (one per page allowed)
     7. Custom cursor: .cursor-dot + .cursor-ring (bootstrapped by nav.js)
     8. .term-cursor: the terminal-line blink

   Specificity rules (avoid selector wars):
     - Everything here is single-class or class > class. No !important
       outside the global reduced-motion kill in tokens.css.
     - Section rhythm is padding-TOP ONLY on .section. Never add margin-top
       or margin-bottom to .section or direct children stacks — it double-
       counts and fights the rhythm.
   ========================================================================== */

/* ---- 1. Reset + page shell ------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html {
  /* Anchor targets (#model-id deep links on /models/) land below the sticky
     header instead of underneath it. */
  scroll-padding-top: calc(var(--header-height) + var(--space-4));
  /* Decorative bleeds must never open a horizontal pan (body repeats this). */
  overflow-x: clip;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  /* Decorative bleeds must never cause horizontal pan. */
  overflow-x: clip;
}

img,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* Links stay ink (16.2:1) with the orange-red underline as the interactive
   signal — the Obys convention. Hover warms the text to --accent-dim
   (4.4:1, body-size safe) and thickens the stroke, so state never rides on
   hue alone. */
a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--dur-fast) var(--ease-out),
              text-decoration-color var(--dur-fast) var(--ease-out),
              text-decoration-thickness var(--dur-fast) var(--ease-out);
}

a:hover {
  color: var(--accent-dim);
  text-decoration-thickness: 2px;
}

/* Spot-color fill, white ink — 3.3:1, a momentary highlight, fine. */
::selection {
  background: var(--accent);
  color: var(--on-accent);
}

/* ---- 2. Utilities ---------------------------------------------------------- */
.mono {
  font-family: var(--font-mono);
}

.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;
}

/* Keyboard users land here first; invisible until focused. */
.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-modal);
  padding: var(--space-2) var(--space-4);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-decoration: none;
  border: 1px solid var(--border-strong);
  transform: translateY(calc(-100% - var(--space-4)));
}

.skip-link:focus {
  transform: none;
}

/* ---- Obys numbering system --------------------------------------------------
   .index-num: small mono orange-red label ("01"). Body-size orange uses
   --accent-dim (4.4:1); bright --accent is for display-size accents only.
   Standalone on meta rows, or inside a .sec-head. */
.index-num {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--accent-dim);
}

/* .sec-head: the poster line — Archivo Black giant, baseline-aligned number.
     <h2 class="sec-head"><span class="index-num">01</span>Selected Works</h2>
   font-weight: 900 is safe because the family is registered as 400 900
   (no synthetic bold on Archivo; CJK fallback renders a true heavy cut). */
.sec-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-4);
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(2.25rem, 1.44rem + 3.6vw, 4rem); /* 36 -> 64px, 360->1140 */
  line-height: 1.05;
  text-wrap: balance;
  color: var(--text);
}

/* ---- 3. Layout -------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

@media (min-width: 720px) {
  .container {
    padding-inline: var(--space-6);
  }
}

/* 12-column grid. Mobile: 4 tracks (children usually span all 4);
   >=720px: 12 tracks with opt-in span classes. gap is fixed at 24px —
   override per-page only with a more specific scoped selector. */
.grid {
  display: grid;
  gap: var(--space-6);
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid > * {
  grid-column: 1 / -1;
}

@media (min-width: 720px) {
  .grid {
    grid-template-columns: repeat(12, minmax(0, 1fr));
  }

  .col-3  { grid-column: span 3; }
  .col-4  { grid-column: span 4; }
  .col-6  { grid-column: span 6; }
  .col-8  { grid-column: span 8; }
  .col-9  { grid-column: span 9; }
  .col-12 { grid-column: span 12; }
}

/* Card grid preset (spec: desktop 3 / tablet 2 / phone 1). Pair children
   with aspect-ratio in page CSS to prevent layout shift. */
.grid-cards {
  display: grid;
  gap: var(--space-6);
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .grid-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .grid-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Hover lift (spec: -4px, 150-200ms). Pointer-capable devices only —
   touch devices skip it entirely. */
@media (hover: hover) {
  .lift {
    transition: transform var(--dur-base) var(--ease-out);
  }

  .lift:hover {
    transform: translateY(-4px);
  }
}

/* Vertical rhythm: padding-top only, so consecutive sections never
   double-count. main carries the bottom padding before the footer. */
.section {
  padding-block-start: var(--space-section);
}

main {
  padding-block-end: var(--space-section);
}

/* ---- 4. Site header ---------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  /* rgba must match --bg (#F2F0EA paper). Update both if the token changes. */
  background: rgba(242, 240, 234, 0.88);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: var(--header-height);
}

/* Wordmark: mono ink with the orange-red $ prompt. */
.wordmark {
  font-family: var(--font-mono);
  font-size: var(--text-base);
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.02em;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out);
}

.wordmark-prompt {
  color: var(--accent);
  margin-right: var(--space-2);
}

.wordmark:hover {
  color: var(--accent-dim);
}

/* Hamburger (mobile only). Three 2px bars morph into an X on .is-open. */
.nav-toggle {
  display: inline-flex;
  flex-direction: column;
  gap: 5px;
  padding: var(--space-3);
  margin-right: calc(-1 * var(--space-3)); /* optically align with gutter */
}

.nav-toggle-bar {
  width: 20px;
  height: 2px;
  background: var(--text);
  transition: transform var(--dur-base) var(--ease-inout),
              opacity var(--dur-fast) var(--ease-out);
}

.nav-toggle.is-open .nav-toggle-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav-toggle.is-open .nav-toggle-bar:nth-child(2) {
  opacity: 0;
}

.nav-toggle.is-open .nav-toggle-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Nav dropdown: mobile-first (absolute panel under the header), flips to an
   inline row at >=720px. .is-open is toggled by nav.js on button + panel. */
.site-nav {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: var(--z-overlay);
  background: var(--surface);
  border-bottom: 1px solid var(--border-color);
  padding: var(--space-2) var(--space-4) var(--space-4);
}

.site-nav.is-open {
  display: block;
}

.site-nav-list {
  display: flex;
  flex-direction: column;
  list-style: none;
  padding: 0;
  counter-reset: nav-index;
}

.site-nav-list li {
  counter-increment: nav-index;
}

.site-nav-list li + li {
  border-top: 1px solid var(--border-color);
}

/* Obys nav: tiny uppercase mono with a free index number ("01 首页") drawn
   by CSS counters — nav markup carries none. Hover/active go --accent per
   the design contract; at xs that is 2.9:1, an accepted trade-off — the
   counter, the tracking and (active) the underline keep state legible
   without the hue. */
.site-nav-link {
  display: block;
  padding: var(--space-3) 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-out);
}

.site-nav-link::before {
  content: counter(nav-index, decimal-leading-zero) "\00a0\00a0";
  color: var(--accent-dim);
}

.site-nav-link:hover {
  color: var(--accent);
}

/* Current page: orange-red + a 2px underline (static cue, no layout shift). */
.site-nav-link.is-active,
.site-nav-link[aria-current="page"] {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
}

@media (min-width: 720px) {
  .nav-toggle {
    display: none;
  }

  .site-nav {
    display: block;
    position: static;
    z-index: auto;
    background: transparent;
    border-bottom: none;
    padding: 0;
  }

  .site-nav.is-open {
    display: block; /* stays a plain row on desktop regardless of state */
  }

  .site-nav-list {
    flex-direction: row;
    align-items: center;
    gap: var(--space-8);
  }

  .site-nav-list li + li {
    border-top: none;
  }

  .site-nav-link {
    padding: var(--space-2) 0;
  }
}

/* ---- 5. Site footer — the ink slab --------------------------------------------
   Full inversion closes the page: #141414 ground (carried by
   --border-strong, same value), paper type. Scope-local colors are literals
   here because the text tokens describe ink-on-paper and cannot invert. */
.site-footer {
  background: var(--border-strong);
  color: var(--bg);
  border-top: 1px solid var(--border-color);
  padding-block: var(--space-8);
}

.site-footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2) var(--space-6);
}

.footer-icp {
  color: rgba(242, 240, 234, 0.7); /* ≈8.3:1 on ink */
  font-size: var(--text-xs);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-out);
}

.footer-icp:hover {
  color: var(--bg);
  text-decoration: underline;
}

/* Signature renders as a shell command and its output:
   $ whoami  no man, just AI */
.footer-sign {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: rgba(242, 240, 234, 0.64); /* ≈7.1:1 on ink */
}

.footer-sign .prompt {
  color: var(--accent); /* 5.5:1 on ink — the prompt survives inversion */
  margin-right: var(--space-2);
}

.footer-sign .cmd {
  margin-right: var(--space-4);
}

.footer-sign .out {
  color: var(--bg); /* the payload reads brightest: 16.2:1 */
}

/* ---- 6. Marquee -------------------------------------------------------------------
   Obys-style infinite ticker: ink slab, paper display caps. One per page.
   Markup contract — the track holds TWO identical chunks; animating the
   track to translateX(-50%) loops seamlessly:
     <div class="marquee">
       <div class="marquee-track">
         <div class="marquee-chunk">
           <span class="marquee-item">No Man, Just AI</span>
           <span class="marquee-item">Design — Code — 3D</span>
         </div>
         <div class="marquee-chunk" aria-hidden="true">…duplicate…</div>
       </div>
     </div>
   Speed is tunable per page: style="--marquee-duration: 20s". Item padding
   (not track gap) creates the spacing, which is what hides the seam. */
.marquee {
  overflow: clip;
  background: var(--border-strong);
  color: var(--bg);
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}

.marquee-track {
  display: flex;
  width: max-content;
  animation: marquee-scroll var(--marquee-duration, 28s) linear infinite;
  will-change: transform; /* continuous 60fps transform — the justified case */
}

.marquee-chunk {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.marquee-item {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: var(--text-md);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  padding-inline: var(--space-6);
}

.marquee:hover .marquee-track {
  animation-play-state: paused;
}

@keyframes marquee-scroll {
  to { transform: translateX(-50%); }
}

@media (prefers-reduced-motion: reduce) {
  .marquee-track {
    animation: none; /* static strip; the -0.01ms global would park it at
                        translateX(-50%) anyway — identical frame, but be
                        explicit. */
  }
}

/* ---- 7. Custom cursor -----------------------------------------------------------------
   Bootstrapped by nav.js on (pointer: fine): it creates .cursor-dot and
   .cursor-ring and adds .has-cursor to <html>. Pages need zero markup.
   The dot tracks the pointer 1:1; the ring lerps behind (JS-side, single
   rAF loop) and scales 1.6x over interactive elements. Reduced motion: JS
   places both directly, no lerp — nothing extra to do here. */
.cursor-dot,
.cursor-ring {
  display: none; /* opt-in: only .has-cursor ever shows them */
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  border-radius: 50%;
  z-index: 999; /* chrome — above modals (--z-modal), not content stacking */
}

html.has-cursor .cursor-dot,
html.has-cursor .cursor-ring {
  display: block;
}

.cursor-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  /* Optional Obys inversion over slabs — off by default: --accent already
     reads on both paper and ink, and difference shifts it blue on paper.
     mix-blend-mode: difference; */
}

.cursor-ring {
  width: 28px;
  height: 28px;
  border: 1px solid var(--text);
}

/* Native pointer retired site-wide once the cursor is live. */
html.has-cursor body {
  cursor: none;
}

/* :where() = zero specificity, so a page may opt an element back to its own
   cursor (e.g. a zoom canvas) by styling it directly. */
html.has-cursor :where(a, button, input, textarea, select, label, summary,
                       [role="button"]) {
  cursor: none;
}

/* Touch never sees the custom cursor (JS also gates on pointer: fine). */
@media (pointer: coarse) {
  .cursor-dot,
  .cursor-ring {
    display: none;
  }
}

/* ---- 8. Terminal cursor -----------------------------------------------------------
   A block cursor that blinks like a real terminal — for $ prompts and log
   lines. Ambient budget: .marquee (section 6) is the one page-level
   ambient animation; this blink is line-local. Reduced motion: stays
   solidly visible (the global rule would otherwise blink it off once). */
.term-cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.1em;
  margin-left: var(--space-1);
  background: var(--accent);
  vertical-align: text-bottom;
  animation: term-blink 1.1s steps(1, end) infinite;
}

@keyframes term-blink {
  0%, 55% { opacity: 1; }
  56%, 100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .term-cursor {
    animation: none;
  }
}
