/* ==========================================================================
   Tokens. Every recurring value lives here (standard §5.1).
   See docs/design-system.md for the reasoning.
   ========================================================================== */
:root {
  /* Color: the void is true black; text is plain white. */
  --c-void: #000;
  --c-surface: #0b0b0d;
  --c-surface-raised: #141418;
  --c-border: #2a2a31;
  --c-text: #fff;
  --c-text-2: #c4c4cc;      /* 11.9:1 on --c-surface */
  --c-text-muted: #8d8d97;  /* 5.9:1 on --c-surface  */
  --c-focus: #fff;

  /* The spark palette: the only accents. Used for charge, sparks, and fallbacks. */
  --c-spark-1: #ff3d7f;
  --c-spark-2: #ffb000;
  --c-spark-3: #2de2e6;
  --c-spark-4: #8a6bff;

  /* Ambience. The void's one light is cold; the collage's sky is a deep violet night the colour pours into. */
  --c-light: 170 180 196;   /* rgb triplet, used with alpha */
  --c-sky: #120a2c;

  /* Type: one family (system mono reads as "a file"), four sizes. */
  --font: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
  --fs-1: 0.875rem;  /* 14px: the file name, captions */
  --fs-2: 1rem;      /* 16px: body, buttons          */
  --fs-3: 1.25rem;   /* 20px: card titles             */
  --fs-4: 1.75rem;   /* 28px: large card titles       */
  --lh: 1.4;
  --ls-file: 0.04em;

  /* Space: 4px base. */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;

  /* Shape. */
  --radius: 6px;
  --radius-card: 16px; /* cards are soft-bodied things floating in fluid, so they're rounder */
  --border: 1px;
  --focus-ring: 2px solid var(--c-focus);
  --focus-offset: 4px;
  --target: 44px;

  /* Elevation (used only for hovered cards and the window). */
  --shadow-1: 0 8px 24px rgb(0 0 0 / 0.5);
  --shadow-2: 0 24px 80px rgb(0 0 0 / 0.7);

  /* Layers. */
  --z-sky: 0;      /* aurora, then the ambience canvas, both behind the stage */
  --z-stage: 1;    /* the void and the collage */
  --z-grid: 1;
  --z-bar: 3;
  --z-fx: 4;

  /* Motion. */
  --t-fast: 160ms;
  --t-mid: 320ms;
  --t-slow: 900ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.18, 1.35, 0.4, 1);

  /* Live state written by script: 0 (calm) to 1 (bursting). */
  --charge: 0;
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--c-void); color: var(--c-text); font: var(--fs-2)/var(--lh) var(--font); }
/* The void isn't flat black: a faint lift at the centre falls off to nothing in every direction. */
body { background: radial-gradient(ellipse 90% 70% at 50% 46%, #07080c, var(--c-void) 72%) fixed; }
body { margin: 0; min-height: 100dvh; overflow-x: hidden; }
body[data-state="void"], body[data-state="bursting"] { overflow: hidden; }
button { font: inherit; color: inherit; }
:focus-visible { outline: var(--focus-ring); outline-offset: var(--focus-offset); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.noscript { position: fixed; inset: auto 0 var(--s-6); text-align: center; color: var(--c-text-muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--target); padding: 0 var(--s-4);
  border: var(--border) solid var(--c-border); border-radius: var(--radius);
  background: var(--c-surface-raised); color: var(--c-text);
  font-size: var(--fs-1); text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.btn:hover { border-color: var(--c-text-muted); }
.btn:active { background: var(--c-surface); }
.btn--primary { background: var(--c-text); color: var(--c-void); border-color: var(--c-text); }

/* ==========================================================================
   The void and the file
   ========================================================================== */
/* The atmosphere layers (src/ambience.js). Both ignore the pointer. */
.ambience { position: fixed; inset: 0; width: 100%; height: 100%; z-index: var(--z-sky); pointer-events: none; }
/* The fluid is computed on a coarse grid and stretched to the screen; the smooth upscale softens its edges. */
/* The collage's sky: the aurora wash with the fluid over it. Colour floods out of the file and drains
   back into it through a radial mask whose edge is a wide feather, so there's no hard circle, only a
   glow that spreads. --reveal is the radius where the sky is fully opaque; the feather runs past it. */
@property --reveal { syntax: '<length>'; inherits: false; initial-value: 0px; }
.sky {
  position: fixed; inset: 0; z-index: var(--z-sky); overflow: hidden; pointer-events: none;
  --feather: 45vmax;
}
.sky[hidden] { display: none; }
.sky.is-revealing {
  mask-image: radial-gradient(circle at var(--ox) var(--oy),
    #000 var(--reveal), rgb(0 0 0 / 0.5) calc(var(--reveal) + var(--feather) * 0.4), transparent calc(var(--reveal) + var(--feather)));
}
.fluid { position: absolute; left: 0; top: 0; }
.aurora {
  position: absolute; inset: -60px; /* room to shift for parallax without showing an edge */
  overflow: hidden; background: var(--c-sky);
}
/* Five soft blooms of the spark colours: a still wash of colour. The fluid in front of it is what moves. */
.aurora i {
  position: absolute; width: 75vmax; height: 75vmax; border-radius: 50%;
  background: radial-gradient(closest-side, var(--bloom), transparent);
  opacity: 0.45;
}
.aurora i:nth-child(1) { --bloom: var(--c-spark-1); left: -22vmax; top: -28vmax; }
.aurora i:nth-child(2) { --bloom: var(--c-spark-3);  right: -26vmax; top: -18vmax; }
.aurora i:nth-child(3) { --bloom: var(--c-spark-4); left: -18vmax; bottom: -32vmax; }
.aurora i:nth-child(4) { --bloom: var(--c-spark-2); right: -24vmax; bottom: -30vmax; opacity: 0.38; }
.aurora i:nth-child(5) { --bloom: var(--c-spark-1); left: 20vmax; top: 18vmax; opacity: 0.22; }

.void {
  position: fixed; inset: 0; z-index: var(--z-stage); display: grid; place-items: center;
  touch-action: none; /* a swipe across the file keeps reporting moves instead of scrolling */
}
body:not([data-state="void"]) .void { pointer-events: none; }

/* One cold light from somewhere far above, falling on the file and a floor you can't otherwise see.
   It flickers now and then, like it's failing; charge makes it burn brighter. */
.void__light {
  position: absolute; inset: 0; pointer-events: none;
  filter: blur(16px);
  opacity: calc(0.8 + var(--charge) * 0.5);
}
.void__light::before, .void__light::after { content: ""; position: absolute; animation: flicker 13s linear infinite; }
.void__light::before { /* the beam */
  inset: -12vh 0 calc(48vh - 12px);
  clip-path: polygon(calc(50% - 28px) 0, calc(50% + 28px) 0, calc(50% + 30vmin) 100%, calc(50% - 30vmin) 100%);
  background: linear-gradient(rgb(var(--c-light) / 0.04), rgb(var(--c-light) / 0.2));
}
.void__light::after { /* where it lands */
  left: 50%; top: calc(50% + 12px); width: 90vmin; height: 14vmin; translate: -50% -50%;
  background: radial-gradient(closest-side, rgb(var(--c-light) / 0.26), transparent);
}
@keyframes flicker {
  0%, 37%, 39.5%, 41%, 78%, 79.5%, 100% { opacity: 1; }
  38% { opacity: 0.45; } 40% { opacity: 0.7; } 40.5% { opacity: 0.35; } 79% { opacity: 0.75; }
}
body[data-state="collage"] .void { visibility: hidden; }

.core {
  /* The text is small, the target is not (WCAG 2.5.8, Fitts). */
  position: relative;
  min-width: var(--target); min-height: var(--target);
  padding: var(--s-3) var(--s-4);
  border: 0; background: none; cursor: pointer;
  font-size: var(--fs-1); letter-spacing: calc(var(--ls-file) + var(--charge) * 0.18em);
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
.core__label {
  display: inline-block;
  /* The only sign there's a floor at all (Chromium and Safari; elsewhere it's simply not there). */
  -webkit-box-reflect: below 1px linear-gradient(transparent 35%, rgb(0 0 0 / 0.22));
  /* Charge drives color fringing: a chromatic split that widens and warms. */
  text-shadow:
    calc(var(--charge) * -2.5px) 0 calc(var(--charge) * 1px) rgb(255 61 127 / calc(var(--charge) * 1.2)),
    calc(var(--charge) *  2.5px) 0 calc(var(--charge) * 1px) rgb(45 226 230 / calc(var(--charge) * 1.2)),
    0 0 calc(var(--charge) * 18px) rgb(255 176 0 / calc(var(--charge) * 0.9));
}
.core__label .ch { display: inline-block; will-change: transform; }

/* Idle breathing: after a while alone, the file quietly signals it's alive. */
body[data-state="void"] .core[data-idle] .core__label { animation: breathe 4.8s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.55; } }

/* Each hover sends out a ring. */
.ring {
  position: absolute; left: 50%; top: 50%;
  border-radius: 50%;
  border: 1px solid var(--ring, var(--c-text));
  pointer-events: none;
}

/* ==========================================================================
   Burst effects
   ========================================================================== */
.fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: var(--z-fx); }

/* ==========================================================================
   Collage: a stage the size of the screen (taller only if the projects
   can't fit). Cards are positioned by the physics in main.js.
   ========================================================================== */
.collage {
  position: relative; z-index: var(--z-stage); height: var(--stage-h, 100dvh); overflow: hidden;
  isolation: isolate;  /* the cards' climbing z-index stays inside the stage */
  cursor: zoom-out;    /* empty space folds the collage back into the file */
}
.collage[hidden] { display: none; }
.collage__grid { list-style: none; margin: 0; padding: 0; position: absolute; inset: 0; }

/* Back to the void, for keyboards: hidden until focused, like a skip link. Escape works too. */
.collage__back { position: fixed; top: var(--s-4); left: var(--s-4); z-index: var(--z-bar); }
.collage__back:not(:focus-visible) {
  width: 1px; height: 1px; min-height: 0; padding: 0; overflow: hidden; clip-path: inset(50%); border: 0;
}
/* Said once, briefly, after the first burst. */
.collage__hint {
  position: fixed; left: 50%; bottom: var(--s-5); z-index: var(--z-bar);
  translate: -50% 0; margin: 0; padding: var(--s-2) var(--s-3);
  border-radius: var(--radius); background: rgb(0 0 0 / 0.8);
  font-size: var(--fs-1); color: var(--c-text-2); white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity var(--t-slow) var(--ease-out);
}
.collage__hint.is-shown { opacity: 1; }

/* Three independent transform channels, so effects never fight:
     .tile         physics: position and spin (inline transform, every frame)
     .card         burst flight (Web Animations), hover and grab lift (scale)
     .card__frame  3D tilt toward the cursor                                  */
.tile {
  position: absolute; left: 0; top: 0; z-index: var(--z-grid);
  will-change: transform;
  touch-action: none; /* a finger on a card drags it instead of scrolling */
  cursor: auto;
}
.card {
  /* --hue comes from the tile. */
  --accent: hsl(var(--hue) 90% 62%);
  position: absolute; inset: 0;
  display: block; color: var(--c-text); text-decoration: none;
  border-radius: var(--radius-card);
  transition: scale var(--t-mid) var(--ease-spring);
  perspective: 900px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  container: card / size; /* the caption adapts to the card's size, not the screen's */
}
.card:hover, .card:focus-visible { scale: 1.04; }
.tile[data-drag] .card { scale: 1.06; cursor: grabbing; }
.card:focus-visible { outline-offset: 6px; } /* keyboard only: a plain white ring, no border otherwise */

.card__frame {
  position: absolute; inset: 0; overflow: hidden;
  border-radius: var(--radius-card);
  background: var(--c-surface);
  /* Hover tilt toward the cursor, plus the camera's angle (--cx, --cy on .collage) for parallax. */
  transform: rotateX(calc(var(--ty, 0deg) - var(--cy, 0) * 5deg)) rotateY(calc(var(--tx, 0deg) + var(--cx, 0) * 5deg));
  transition: transform var(--t-mid) var(--ease-out), box-shadow var(--t-mid) var(--ease-out);
  box-shadow: 0 12px 32px rgb(8 0 28 / 0.45); /* lifts the card off the colour behind it */
}
/* No borders: a raised card just floats higher, with a deeper, softer shadow. */
.card:hover .card__frame, .card:focus-visible .card__frame, .tile[data-drag] .card__frame {
  box-shadow: 0 24px 56px rgb(8 0 28 / 0.55);
  transition-duration: 60ms, var(--t-mid);
}
/* The mini preview: the top of the real page. Hover slowly scrolls it, like a glance at the live site. */
.card__art {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  object-fit: cover; object-position: 50% 0;
  background: hsl(var(--hue) 30% 9%);
  transition: object-position 1.2s var(--ease-out);
  pointer-events: none;
}
.card:hover .card__art { object-position: 50% 100%; transition: object-position 9s linear; }
.card__cap {
  position: absolute; inset: auto 0 0 0;
  display: grid; gap: var(--s-1);
  padding: var(--s-5) var(--s-3) var(--s-3);
  background: linear-gradient(transparent, rgb(0 0 0 / 0.88) 45%); /* legibility over any screenshot */
}
.card__title { font-size: var(--fs-2); line-height: 1.15; }
.card__kind { font-size: var(--fs-1); color: var(--c-text-2); }
.card__kind::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: var(--s-2); border-radius: 50%; background: var(--accent); }
.card__blurb {
  font-size: var(--fs-1); color: var(--c-text-2);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
/* Type steps up with the card. */
@container card (min-width: 260px) {
  .card__cap { padding: var(--s-6) var(--s-4) var(--s-3); }
  .card__title { font-size: var(--fs-3); }
}
@container card (min-width: 520px) and (min-height: 320px) { .card__title { font-size: var(--fs-4); } }
/* Short cards: the description slides in on hover or focus. Too narrow to read it: none at all. */
@container card (max-height: 219px) {
  .card__blurb { max-height: 0; opacity: 0; transition: max-height var(--t-mid) var(--ease-out), opacity var(--t-mid); }
  .card:is(:hover, :focus-visible) .card__blurb { max-height: 5lh; opacity: 1; }
}
@container card (max-width: 199px) { .card__blurb { display: none; } }
@media (hover: none) {
  @container card (max-height: 219px) { .card__blurb { display: none; } } /* touch: the window has room for it */
}

/* ==========================================================================
   Viewer (in-page browser)
   ========================================================================== */
.viewer {
  width: min(1200px, 100vw - var(--s-6)); height: min(860px, 100dvh - var(--s-6));
  max-width: none; max-height: none; padding: 0;
  border: var(--border) solid var(--c-border); border-radius: var(--radius);
  background: var(--c-surface); color: var(--c-text);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.viewer[open] { display: grid; grid-template-rows: auto 1fr; }
.viewer::backdrop { background: rgb(0 0 0 / 0.72); backdrop-filter: blur(6px); }
.viewer__bar {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4);
  border-bottom: var(--border) solid var(--c-border);
}
.viewer__title { margin: 0; font-size: var(--fs-2); font-weight: 600; white-space: nowrap; }
.viewer__title::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: var(--s-2); border-radius: 50%; background: var(--accent); }
.viewer__url {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: var(--s-2) var(--s-3); border-radius: var(--radius);
  background: var(--c-void); color: var(--c-text-muted); font-size: var(--fs-1);
}
.viewer__tag { margin-left: var(--s-2); color: var(--c-text-2); }
.viewer__body { position: relative; overflow: hidden; background: var(--c-surface); }
/* The card's preview stands in while the snapshot loads, then the live page fades in on top of it.
   Both are the same page at the same width, so the swap is seamless. */
.viewer__poster { position: absolute; inset: 0 0 auto; width: 100%; height: auto; display: block; }
.viewer__frame {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0;
  opacity: 0; transition: opacity var(--t-mid) var(--ease-out);
}
.viewer__frame.is-ready { opacity: 1; }

@media (max-width: 640px) {
  .viewer { width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
  .viewer__url { display: none; }
  .viewer__title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .viewer__bar .btn { padding: 0 var(--s-3); }
}

/* ==========================================================================
   Reduced motion: keep every state, drop the movement.
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card__frame { transform: none; transition: none; }
  .card__art, .card:hover .card__art { transition: none; object-position: 50% 0; }
  .viewer__frame { transition: none; }
  .void__light::before, .void__light::after { animation: none; }
  .core[data-idle] .core__label { animation: none !important; }
  .core { letter-spacing: var(--ls-file); }
}
