/* ============================================================================
   gilly.space — site.css  (the "Heliostatic" design system)
   ----------------------------------------------------------------------------
   One hand-authored, dependency-free stylesheet for the whole site. The token
   palette and dark mode are lifted VERBATIM from enso/index.html so the site
   and the interactive toys share a single source of truth (and a single
   `enso-theme` localStorage key). No Sass, no build, no jQuery.

   This file is GROUNDWORK: it is not linked by any legacy page yet. Pages adopt
   it one at a time during the redesign; until a page links it, that page renders
   exactly as before.
   ========================================================================== */

/* ---- Tokens: light (default) ---- */
:root {
  --bg: #faf8f3;            /* warm paper            */
  --text: #1a2a5a;          /* ink-navy              */
  --muted: #555;
  --card-bg: #ffffff;
  --card-border: #ddd;
  --accent: #d9a91a;        /* gold / corona (decorative fills only) */
  --accent-ink: #1a1814;    /* text on accent fills  */
  --accent-text: #8a6a00;   /* gold dark enough for AA text on the light bg */
  --btn-bg: #1a2a5a;
  --btn-text: #ffffff;
  --rule: #e4ddcf;          /* hairline section rule */
  --link: #1a2a5a;
  --link-hover: var(--accent-text);
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --modal-backdrop: rgba(0,0,0,0.55);

  --maxw: 1080px;           /* page container        */
  --measure: 68ch;          /* prose reading measure */
  --radius: 12px;
  --pad: clamp(16px, 4vw, 32px);
}

/* ---- Tokens: dark (the enso "deep space" twin) ---- */
:root.dark {
  --bg: #1a1814;
  --text: #e8e2d0;
  --muted: #a8a094;
  --card-bg: #25221c;
  --card-border: #3a362c;
  --accent: #d9a91a;
  --accent-ink: #1a1814;
  --accent-text: #d9a91a;
  --btn-bg: #d9a91a;
  --btn-text: #1a1814;
  --rule: #3a362c;
  --link: #e8e2d0;
  --link-hover: #d9a91a;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --modal-backdrop: rgba(0,0,0,0.78);
}

/* ---- Reset / base ---- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; background: var(--bg); }

body {
  margin: 0;
  background: transparent;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

img, video, iframe { max-width: 100%; height: auto; }

/* ---- Fluid type scale (the sudoku clamp() trick — responsive, no breakpoints) ---- */
h1 { font-size: clamp(28px, 5vw, 44px); line-height: 1.15; margin: 0 0 .5em; }
h2 { font-size: clamp(22px, 3.4vw, 30px); line-height: 1.2;  margin: 1.6em 0 .5em; }
h3 { font-size: clamp(18px, 2.4vw, 22px); line-height: 1.25; margin: 1.3em 0 .4em; }
p  { margin: 0 0 1em; }

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }
a:focus-visible,
button:focus-visible,
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

hr,
.rule {
  border: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--rule) 18%, var(--rule) 82%, transparent);
  margin: 2.5rem 0;
}

/* ---- Layout container ---- */
.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 var(--pad); }
main { flex: 1 0 auto; width: 100%; }
.section { padding: clamp(28px, 6vw, 56px) 0; }

/* ---- Skip link (accessibility — none exists on the legacy site) ---- */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--btn-bg); color: var(--btn-text);
  padding: 10px 16px; border-radius: 0 0 8px 0; z-index: 1000;
}
.skip-link:focus { left: 0; }

/* ============================================================================
   Site header / persistent nav  — the thing the legacy site never had
   ========================================================================== */
/* The header/footer are injected into these wrappers; display:contents removes
   the wrapper box so the sticky header's containing block is <body> (otherwise
   it would only "stick" within the wrapper's own height and scroll away). */
[data-include="header"], [data-include="footer"] { display: contents; }

.site-header {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--rule);
}
.site-header__inner {
  max-width: var(--maxw); margin: 0 auto; padding: 10px var(--pad);
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.brand {
  font-weight: 700; font-size: 18px; letter-spacing: -0.01em;
  color: var(--text); white-space: nowrap;
}
.brand:hover { color: var(--accent-text); }
.brand .dot { color: var(--accent); }

.site-nav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin-right: auto; }
.site-nav a {
  color: var(--muted); font-size: 15px; padding: 6px 10px; border-radius: 6px;
  transition: color .15s ease, background .15s ease;
}
.site-nav a:hover { color: var(--text); background: var(--card-bg); }
.site-nav a[aria-current="page"] { color: var(--text); background: var(--card-bg); box-shadow: inset 0 -2px 0 var(--accent); }

.site-tools { display: flex; align-items: center; gap: 8px; }

/* Academic / social icon row (valid <ul><li>, fixing the bare-text-in-<ul> bug) */
.icon-row { display: flex; gap: 10px; align-items: center; list-style: none; margin: 0; padding: 0; }
.icon-row a { color: var(--muted); font-size: 18px; line-height: 1; }
.icon-row a:hover { color: var(--accent-text); }

/* Theme toggle — same icon-button treatment as the toys */
.theme-toggle {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 16px; padding: 4px 6px; border-radius: 4px;
  opacity: 0.8; line-height: 1;
}
.theme-toggle:hover { opacity: 1; background: var(--card-bg); }

/* a11y + old-browser fallbacks */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* Subtle "opens in new tab" cue on content links (not nav/icon/card/button links). */
main a[target="_blank"]:not(.card a):not(.btn):not(.hero__enso-link)::after {
  content: " ↗"; font-size: .85em; color: var(--accent-text); opacity: .75;
}
main .icon-row a[target="_blank"]::after { content: none; }
/* aspect-ratio fallback for pre-2021 Safari / old WebView */
@supports not (aspect-ratio: 1) {
  .card__img { height: auto; min-height: 160px; }
  .hero__portrait { height: 0; padding-bottom: 100%; }
  .embed-16x9 { height: 0; padding-bottom: 56.25%; }
}

/* ============================================================================
   Footer
   ========================================================================== */
.site-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--rule);
  margin-top: 48px;
  padding: 32px 0;
  color: var(--muted); font-size: 14px;
}
.site-footer__inner { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--pad); display: flex; flex-direction: column; gap: 14px; }
.site-footer .icon-row a { font-size: 20px; }
.site-footer__meta { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }

/* ============================================================================
   Cards + responsive grid (replaces skel's 6u/12u$ classes)
   ========================================================================== */
.grid {
  display: grid; gap: clamp(16px, 3vw, 24px);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
}
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
  display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 26px rgba(0,0,0,0.12), 0 0 0 1px rgba(217,169,26,0.30); }
.card a { color: inherit; display: block; }
.card__img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; background: var(--bg); }
.card__body { padding: 16px 18px; }
.card__body h3 { margin: 0 0 .25em; }
.card__body p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---- Buttons ---- */
.btn {
  display: inline-block; background: var(--btn-bg); color: var(--btn-text);
  padding: 9px 16px; border-radius: 8px; border: none; cursor: pointer;
  font-size: 15px; font-weight: 600; transition: opacity .15s ease;
}
.btn:hover { opacity: .9; color: var(--btn-text); }
.btn--ghost { background: transparent; color: var(--text); border: 1px solid var(--card-border); }

/* ---- Responsive 16:9 embed (fixes the fixed 560x315 iframes that overflow phones) ---- */
.embed-16x9 { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: #000; }
.embed-16x9 > iframe,
.embed-16x9 > video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---- Prose pages (Space-Is-Full, Kelvin) get a real reading measure ---- */
.prose { max-width: var(--measure); margin-inline: auto; }
.prose figure { margin: 1.5rem 0; }
.prose figcaption { color: var(--muted); font-size: 13px; margin-top: .4rem; }

/* ---- Hero (homepage front door) ---- */
.eyebrow { text-transform: uppercase; letter-spacing: .09em; font-size: 13px; color: var(--muted); margin: 0 0 .5em; }
.hero { display: flex; gap: clamp(22px, 5vw, 48px); align-items: center; flex-wrap: wrap; }
/* Hero portrait: your photo circular-cropped in the centre, with today's ensō
   overlaid on top as a frame around it (radius/thickness normalized in JS so the
   ring always frames the face, never crosses it). The gold corona glows off the
   brushstroke itself. */
.hero__portrait { position: relative; width: clamp(190px, 32vw, 260px); aspect-ratio: 1; flex-shrink: 0; }
.hero__enso-link { display: block; width: 100%; height: 100%; position: relative; }
.hero__avatar {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 58%; height: 58%; border-radius: 50%; object-fit: cover; object-position: 28% 36%;
  box-shadow: var(--shadow); border: 0; z-index: 1;
}
.hero__enso {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 2;
  filter: drop-shadow(0 0 22px rgba(217,169,26,0.32));
  animation: coronaBreathe 7s ease-in-out infinite;
}
@keyframes coronaBreathe {
  0%, 100% { filter: drop-shadow(0 0 18px rgba(217,169,26,0.26)); }
  50%      { filter: drop-shadow(0 0 30px rgba(217,169,26,0.46)); }
}
.hero__enso-cap {
  position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%); z-index: 3;
  font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
  white-space: nowrap; background: var(--bg); padding: 1px 7px; border-radius: 8px;
  opacity: 0; transition: opacity .2s ease; pointer-events: none;
}
.hero__portrait:hover .hero__enso-cap, .hero__enso-link:focus-visible ~ .hero__enso-cap { opacity: 1; }
.hero__body { flex: 1 1 340px; }
.hero__body h1 { margin: 0 0 .12em; }
.hero__role { color: var(--accent-text); font-weight: 600; font-size: clamp(15px, 2.2vw, 19px); margin: 0 0 .9em; }
.hero__intro { font-size: clamp(16px, 2vw, 18px); max-width: 58ch; }
.hero__intro a { text-decoration: underline; text-underline-offset: 2px; }

/* Tag chips for the toy/text cards that have no thumbnail */
.card--text .card__body { padding: 22px 20px; }
.card__kicker { font-size: 12px; letter-spacing: .07em; text-transform: uppercase; color: var(--accent-text); margin: 0 0 .4em; }
.card--sun .card__img, .card--art .card__img { background: linear-gradient(135deg, #1a2a5a, #d9a91a); }

/* ============================================================================
   Cosmic atmosphere — the "this is gilly.SPACE" layer.
   All decorative, all performant, all reduced-motion-safe.
   ========================================================================== */
/* Fixed backdrop behind everything: a warm corona glow up top, plus a faint
   tiled starfield in dark mode. (html paints --bg; body is transparent.) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(1100px 520px at 50% -14%, rgba(217,169,26,0.10), transparent 70%);
}
:root.dark body::before {
  background:
    radial-gradient(1100px 640px at 50% -14%, rgba(217,169,26,0.16), transparent 70%),
    radial-gradient(1px 1px   at 40px 60px,  rgba(255,255,255,0.35) 1px, transparent 2px),
    radial-gradient(1px 1px   at 150px 160px, rgba(255,255,255,0.22) 1px, transparent 2px),
    radial-gradient(1.5px 1.5px at 90px 210px, rgba(255,255,255,0.16) 1px, transparent 2px);
  background-size: 100% 100%, 230px 230px, 290px 290px, 350px 350px;
  background-repeat: no-repeat, repeat, repeat, repeat;
}

/* Sunrise-gradient headline. */
/* Fallback: readable solid ink where background-clip:text is unsupported. */
.gradient-text { color: var(--text); }
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .gradient-text {
    /* background-IMAGE (longhand) so it never resets background-clip */
    background-image: linear-gradient(100deg, var(--text) 0%, #9a7400 60%, #7a5a00 100%); /* light: AA-safe */
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent; color: transparent;
  }
  :root.dark .gradient-text {
    background-image: linear-gradient(100deg, var(--text) 0%, var(--accent) 58%, #f0c24a 100%); /* dark: glowy */
  }
}

/* Ensō brushstroke divider — the signature motif. */
.enso-divider { display: flex; justify-content: center; margin: 40px 0; }
.enso-divider svg { width: 58px; height: 58px; opacity: 0.85; }
.enso-divider circle, .enso-divider path { stroke: var(--accent); }

/* Scroll-reveal. Armed only by JS (adds .js-reveal) when motion is allowed, so
   content is NEVER hidden if JS fails or the user prefers reduced motion. */
html.js-reveal .reveal { opacity: 0; transform: translateY(16px); transition: opacity .6s ease, transform .6s ease; }
html.js-reveal .reveal.in { opacity: 1; transform: none; }

/* ---- Motion: respect the user's preference (hard requirement) ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ---- Narrow screens: let the nav scroll rather than crush ---- */
@media (max-width: 640px) {
  .site-nav { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .site-nav a { white-space: nowrap; }
}

/* ============================================================================
   Bells & whistles — all progressive enhancement, all reduced-motion-safe.
   ========================================================================== */

/* Smooth cross-document page transitions (Chromium; degrades to instant). */
@view-transition { navigation: auto; }

/* Animated starfield canvas swaps in for the CSS tiled stars in dark mode. */
.starfield { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
:root.dark.canvas-stars body::before {
  background: radial-gradient(1100px 640px at 50% -14%, rgba(217,169,26,0.16), transparent 70%);
}

/* Scroll progress bar */
.scroll-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 100%; z-index: 200;
  background: linear-gradient(90deg, var(--accent), #f0c24a);
  transform: scaleX(0); transform-origin: 0 50%; will-change: transform;
}

/* Back-to-top */
.to-top {
  position: fixed; right: 18px; bottom: 18px; z-index: 150;
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--card-border);
  background: var(--card-bg); color: var(--text); font-size: 18px; cursor: pointer;
  box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: opacity .2s ease, transform .2s ease, background .15s;
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Card tilt: give cards a 3D context + keep transform transitions snappy */
.card { transform-style: preserve-3d; will-change: transform; }

/* Image lightbox */
.zoomable { cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 1100; display: none; place-items: center;
  background: var(--modal-backdrop); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  padding: 4vmin;
}
.lightbox.open { display: grid; }
.lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 10px; box-shadow: 0 12px 48px rgba(0,0,0,.5); }
.lightbox__close {
  position: absolute; top: 14px; right: 16px; width: 40px; height: 40px; border-radius: 50%;
  border: none; background: rgba(255,255,255,.12); color: #fff; font-size: 18px; cursor: pointer;
}
.lightbox__close:hover { background: rgba(255,255,255,.25); }

/* Reading time */
.reading-time { color: var(--muted); font-size: 13px; letter-spacing: .04em; margin: -.4em 0 1.4em; }
.reading-time::before { content: "◷ "; color: var(--accent); }

/* Command palette (⌘K) */
.cmdk { position: fixed; inset: 0; z-index: 1000; display: none; justify-content: center; align-items: flex-start; padding-top: 14vh; background: var(--modal-backdrop); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.cmdk.open { display: flex; }
.cmdk__box { width: min(560px, 92vw); background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.4); overflow: hidden; }
.cmdk__input { width: 100%; box-sizing: border-box; border: 0; border-bottom: 1px solid var(--rule); background: transparent; color: var(--text); font-size: 17px; padding: 16px 18px; outline: none; font-family: inherit; }
.cmdk__list { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow-y: auto; }
.cmdk__list li { padding: 10px 14px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.cmdk__list li.on, .cmdk__list li:hover { background: var(--btn-bg); color: var(--btn-text); }
.cmdk__hint { padding: 8px 14px; border-top: 1px solid var(--rule); color: var(--muted); font-size: 12px; }

/* Konami solar flare */
.solar-flare {
  position: fixed; inset: 0; z-index: 2000; pointer-events: none;
  background: radial-gradient(circle at 50% 120%, rgba(255,225,150,.95), rgba(217,169,26,.6) 30%, rgba(217,169,26,0) 65%);
  animation: flareUp 1.8s ease-out forwards;
}
@keyframes flareUp {
  0% { opacity: 0; transform: scale(0.6); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.6); }
}

/* Print: drop the chrome, ink on white, reveal nothing hidden */
@media print {
  .site-header, .site-footer, .scroll-progress, .to-top, .starfield, .cmdk, .lightbox,
  .hero__enso, .hero__enso-cap, .theme-toggle, .enso-divider, body::before { display: none !important; }
  html, body { background: #fff !important; color: #000 !important; }
  .reveal { opacity: 1 !important; transform: none !important; }
  a { color: #000 !important; text-decoration: underline; }
  .card { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
}
