@import "tailwindcss";
@import "./tokens.css";

/* ---- Display face: Chakra Petch (self-hosted woff2, OFL — see public/fonts) -
   Latin subset, ~10KB/weight. font-display:swap so text paints instantly in the
   sans fallback and swaps when the face loads (zero layout-shift on the headline). */
@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/chakra-petch-600.woff2") format("woff2");
}
@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/chakra-petch-700.woff2") format("woff2");
}
/* Facelift: Chakra Petch becomes the site-wide face (300–700), body included. */
@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url("/fonts/chakra-petch-300.woff2") format("woff2");
}
@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/chakra-petch-400.woff2") format("woff2");
}
@font-face {
  font-family: "Chakra Petch";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/chakra-petch-500.woff2") format("woff2");
}
/* JetBrains Mono — one variable file covers 400–700 (nav, chips, eyebrows, receipt). */
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/jetbrains-mono-var.woff2") format("woff2");
}

/* ---- Base ---------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  /* Offset for the sticky nav when jumping to #sections */
  scroll-padding-top: 5rem;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 3px;
  border-radius: 4px;
  /* Board-glow halo around the focus ring. The solid outline carries WCAG
     visibility; the halo is on-brand polish (focusable els have no resting
     box-shadow here, so nothing is clobbered). */
  box-shadow: 0 0 0 4px var(--accent-glow);
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

/* Themed scrollbar — thin, board-tinted. The track dissolves into the page; the
   thumb carries a cyan→magenta accent (padding-boxed so it reads slim with
   breathing room) and brightens on hover. Firefox + WebKit. */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--accent-strong) transparent;
}
::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: padding-box;
  background-color: color-mix(in srgb, var(--accent) 55%, var(--accent-2));
}
::-webkit-scrollbar-thumb:hover {
  background-color: color-mix(in srgb, var(--accent) 72%, var(--accent-2));
}

img,
svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ---- Layout helpers ------------------------------------------------------ */

.container {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

.section {
  padding-block: var(--space-9);
  position: relative;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
}

.lead {
  font-size: var(--step-1);
  color: var(--text-dim);
  line-height: 1.6;
}

.mono {
  font-family: var(--font-mono);
}

/* ---- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  letter-spacing: 0.02em;
  padding: 0.7rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  color: var(--text);
  background: var(--surface);
  /* transform is owned by the Motion layer (spring hover/press) — kept out of
     this transition so CSS and Motion don't fight over the same property. */
  transition: border-color 0.2s var(--ease),
    background 0.2s var(--ease), color 0.2s var(--ease);
  text-decoration: none;
}
.btn:hover {
  text-decoration: none;
  border-color: var(--accent-line);
}
.btn--primary {
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
}
.btn--primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 8px 22px var(--accent-glow);
}

/* ---- Cards / tags -------------------------------------------------------- */

.card {
  position: relative;
  /* Frosted glass over the Bat-Computer board — semi-opaque surface + blur so a
     hint of the circuitry diffuses through without hurting legibility. */
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(14px) saturate(1.1);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* A 1px inner top highlight — light catching the glass edge — so cards read as
     raised even at rest (depth layering). The lift+glow stack lands on hover. */
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.05);
  transition: border-color 0.25s var(--ease), transform 0.25s var(--ease),
    box-shadow 0.25s var(--ease);
}
/* A cyan→magenta hairline that ignites along the top edge on hover. Inset from
   the corners so it stays inside the border radius (no clip needed). */
.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 16px;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--accent),
    var(--accent-2),
    transparent
  );
  opacity: 0;
  transition: opacity 0.25s var(--ease);
  pointer-events: none;
}
.card:hover {
  border-color: var(--accent-line);
  transform: translateY(-2px);
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.08), var(--shadow),
    0 0 22px var(--accent-glow);
}
.card:hover::before {
  opacity: 0.9;
}
@media (prefers-reduced-motion: reduce) {
  .card {
    transition: border-color 0.25s var(--ease);
  }
  .card:hover {
    transform: none;
  }
}

.tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.6rem 1rem;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus {
  left: 0;
}

/* ---- Prose (rendered markdown) ------------------------------------------ */
.prose {
  color: var(--text-dim);
  font-size: var(--step-0);
  line-height: 1.75;
  max-width: 70ch;
}
.prose > * + * {
  margin-top: var(--space-4);
}
.prose h2 {
  color: var(--text);
  font-size: var(--step-2);
  margin-top: var(--space-7);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.prose h2::before {
  content: "# ";
  color: var(--accent);
  font-family: var(--font-mono);
  font-weight: 400;
}
.prose h3 {
  color: var(--text);
  font-size: var(--step-1);
  margin-top: var(--space-6);
}
.prose strong {
  color: var(--text);
  font-weight: 600;
}
.prose a {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.prose ul,
.prose ol {
  padding-left: 1.3rem;
  display: grid;
  gap: 0.4rem;
}
.prose li::marker {
  color: var(--accent);
}
.prose blockquote {
  border-left: 2px solid var(--accent);
  padding-left: var(--space-4);
  color: var(--text);
  font-style: italic;
}
.prose code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1rem 0.4rem;
}
.prose pre {
  background: var(--surface) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.6;
}
.prose pre code {
  font-family: var(--font-mono);
}

/* Shiki dual-theme: dark is the default (dark-first / JS-off safe);
   light overrides when the theme is light. We keep our own <pre> background. */
.astro-code,
.astro-code span {
  color: var(--shiki-dark);
}
[data-theme="light"] .astro-code,
[data-theme="light"] .astro-code span {
  color: var(--shiki-light);
}

/* ---- Pre-reveal state (progressive enhancement, Motion-driven) ----------- */
/* Default = visible (JS-off safe). Only once site.js sets `html.js` do we hide
   the pre-reveal elements; the Motion layer (src/scripts/anim.ts) then fades
   them up. Opacity alone gates the flash — Motion owns the y-transform. Under
   reduced-motion the Motion layer no-ops, so we keep everything visible here. */
html.js [data-reveal],
html.js .hero__inner > *,
html.js [data-reveal] .chip {
  opacity: 0;
}
@media (prefers-reduced-motion: reduce) {
  html.js [data-reveal],
  html.js .hero__inner > *,
  html.js [data-reveal] .chip {
    opacity: 1;
  }
}

/* ---- PRO scroll UI — flowing aurora + scroll progress (CSS-only, CSP-safe) -
   Native scroll-driven animations (animation-timeline). Degrades to a gentle
   continuous drift where unsupported; fully disabled under reduced-motion. */

/* A thin royal line at the very top that fills as the page scrolls. Its scaleX
   is scrubbed by scroll progress in the Motion layer (scroll() — cross-browser,
   unlike the Chromium-only CSS animation-timeline this replaced). */
.scroll-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 200;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 14px var(--accent-glow);
  transform: scaleX(0);
  transform-origin: 0 50%;
  pointer-events: none;
}

/* ---- Cinematic backing: the Bat-Computer board, panned by scroll -----------
   A fixed full-screen image (dark/light per theme) that pans S → E → SE → NE as
   the page scrolls. A scrim keeps text legible (darker on the left for the hero
   headline). GPU transform only; static + legible under reduced-motion. */
.site-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  background: var(--bg);
}
.site-bg__img {
  position: absolute;
  top: 50%;
  left: 50%;
  /* Zoomed in — larger than viewport so the board reads big/immersive and the
     scroll-pan has room to travel without ever revealing an edge. */
  width: 215%;
  height: 215%;
  object-fit: cover;
  /* --bg-shift is driven by the scroll handler in site.js (scroll-coupled pan:
     moves only as the page scrolls). Defaults to 0 → centred when JS is off. */
  transform: translate(-50%, calc(-50% + var(--bg-shift, 0px)));
  will-change: transform;
  transition: transform 0.15s linear;
}
.site-bg__img--light {
  display: none;
}
[data-theme="light"] .site-bg__img--dark {
  display: none;
}
[data-theme="light"] .site-bg__img--light {
  display: block;
}
.site-bg__scrim {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      90deg,
      rgba(9, 12, 20, 0.85) 0%,
      rgba(9, 12, 20, 0.52) 44%,
      rgba(9, 12, 20, 0.34) 100%
    ),
    linear-gradient(
      180deg,
      rgba(9, 12, 20, 0.18) 0%,
      rgba(9, 12, 20, 0.5) 58%,
      rgba(9, 12, 20, 0.82) 100%
    );
}
[data-theme="light"] .site-bg__scrim {
  /* Moderate wash — the board stays clearly visible; text legibility comes from
     a light halo behind the type (see below), not from hiding the backdrop. */
  background:
    linear-gradient(
      90deg,
      rgba(246, 248, 251, 0.8) 0%,
      rgba(246, 248, 251, 0.54) 48%,
      rgba(246, 248, 251, 0.44) 100%
    ),
    linear-gradient(
      180deg,
      rgba(246, 248, 251, 0.28) 0%,
      rgba(246, 248, 251, 0.48) 55%,
      rgba(246, 248, 251, 0.78) 100%
    );
}
/* Light-mode legibility: a soft light halo behind running text lifts it off the
   busy board WITHOUT washing the board out. Subtle enough to be invisible on the
   solid card surfaces; only earns its keep over the image. Dark mode needs none
   (light text on a dark board already has the contrast). */
[data-theme="light"]
  main
  :where(h1, h2, h3, h4, p, li, dt, dd, figcaption, .eyebrow) {
  text-shadow:
    0 0 4px rgba(246, 248, 251, 0.92),
    0 1px 2px rgba(246, 248, 251, 0.75);
}

@media (prefers-reduced-motion: reduce) {
  .scroll-progress {
    display: none;
  }
}

/* ---- Cross-document view transitions (facelift polish) --------------------
   Native CSS only: Chromium/Safari get a soft crossfade between pages; Firefox
   ignores. Zero JS, zero CSP surface, and reduced-motion turns it off. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 180ms;
  }
}
