/* ==========================================================================
   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;

  /* 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;
  --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-grid: 1;
  --z-card-hot: 2;
  --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);

  /* Layout. */
  --cell: clamp(150px, 17vw, 230px);
  --row: clamp(130px, 13vw, 170px);

  /* 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); }
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
   ========================================================================== */
.void { position: fixed; inset: 0; display: grid; place-items: center; }
body:not([data-state="void"]) .void { pointer-events: none; }
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;
}
.core__label {
  display: inline-block;
  /* 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
   ========================================================================== */
.collage { position: relative; min-height: 100dvh; padding: var(--s-8) var(--s-5) var(--s-8); }
.collage[hidden] { display: none; }
.collage__bar {
  position: fixed; top: 0; left: 0; z-index: var(--z-bar);
  display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2);
  border-bottom-right-radius: var(--radius);
  background: rgb(0 0 0 / 0.72); backdrop-filter: blur(8px); /* stays legible over cards scrolling beneath */
}
.collage__title { margin: 0; font-size: var(--fs-1); font-weight: 400; color: var(--c-text-muted); }
.core--home { opacity: 0; transition: opacity var(--t-mid); }
body[data-state="collage"] .core--home { opacity: 1; }

.collage__grid {
  list-style: none; margin: 0 auto; padding: 0; max-width: 1400px;
  display: grid; gap: var(--s-5);
  grid-template-columns: repeat(auto-fill, minmax(var(--cell), 1fr));
  grid-auto-rows: var(--row);
  grid-auto-flow: dense;
}
.tile { position: relative; z-index: var(--z-grid); }
.tile[data-size="w"] { grid-column: span 2; }
.tile[data-size="t"] { grid-row: span 2; }
.tile[data-size="l"] { grid-column: span 2; grid-row: span 2; }
.tile:has(.card:hover), .tile:has(.card:focus-visible) { z-index: var(--z-card-hot); }

/* Three independent transform channels, so effects never fight:
     .tile         the burst flight (Web Animations)
     .card         drift (transform), cursor repel (translate), hover lift (scale)
     .card__frame  3D tilt toward the cursor                                    */
.card {
  --hue: 0;
  --accent: hsl(var(--hue) 90% 62%);
  position: absolute; inset: 0;
  display: block; color: var(--c-text); text-decoration: none;
  border-radius: var(--radius);
  translate: var(--px, 0px) var(--py, 0px);
  transform: translate(var(--ox), var(--oy)) rotate(var(--rot));
  animation: drift var(--dur) ease-in-out var(--phase) infinite alternate;
  transition: scale var(--t-mid) var(--ease-spring);
  perspective: 900px;
}
@keyframes drift {
  from { transform: translate(var(--ox), var(--oy)) rotate(var(--rot)); }
  to   { transform: translate(calc(var(--ox) + var(--dx)), calc(var(--oy) + var(--dy))) rotate(calc(var(--rot) * -0.4)); }
}
.card:hover, .card:focus-visible { scale: 1.06; animation-play-state: paused; }
.card:focus-visible { outline-color: var(--accent); }

.card__frame {
  position: absolute; inset: 0; overflow: hidden;
  border-radius: var(--radius);
  background: var(--c-surface);
  border: var(--border) solid var(--c-border);
  transform: rotateX(var(--ty, 0deg)) rotateY(var(--tx, 0deg));
  transition: transform var(--t-mid) var(--ease-out), border-color var(--t-fast), box-shadow var(--t-mid);
}
.card:hover .card__frame, .card:focus-visible .card__frame {
  border-color: var(--accent);
  box-shadow: var(--shadow-1), 0 0 0 1px var(--accent), 0 0 32px hsl(var(--hue) 90% 55% / 0.35);
  transition-duration: 60ms, var(--t-fast), 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);
}
.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-6) var(--s-4) var(--s-3);
  background: linear-gradient(transparent, rgb(0 0 0 / 0.88) 45%); /* legibility over any screenshot */
}
.card__title { font-size: var(--fs-3); line-height: 1.15; }
.tile[data-size="l"] .card__title { font-size: var(--fs-4); }
.card__kind { font-size: var(--fs-1); color: var(--c-text-2); }
/* The description: always shown on big tiles; on small ones it slides in on hover or focus. */
.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;
}
.tile[data-size="s"] .card__blurb { max-height: 0; opacity: 0; transition: max-height var(--t-mid) var(--ease-out), opacity var(--t-mid); }
.tile[data-size="s"] .card:is(:hover, :focus-visible) .card__blurb { max-height: 5lh; opacity: 1; }
@media (hover: none) { .tile[data-size="s"] .card__blurb { display: none; } } /* touch: the window has room for it */
.card__kind::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: var(--s-2); border-radius: 50%; background: var(--accent); }

/* Phones: two even columns, no 2-column spans that would squeeze. */
@media (max-width: 480px) {
  :root { --cell: 140px; --row: 150px; }
  .collage { padding-inline: var(--s-4); }
  .collage__grid { grid-template-columns: repeat(2, 1fr); gap: var(--s-4); }
  .card__title, .tile[data-size="l"] .card__title { font-size: var(--fs-2); }
  .card__cap { padding: var(--s-5) var(--s-3) var(--s-3); }
  .tile[data-size="s"] .card__blurb, .tile[data-size="t"] .card__blurb { display: none; }
  .card__blurb { -webkit-line-clamp: 2; }
}

/* ==========================================================================
   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 { animation: none; transition: none; translate: none; }
  .card__frame { transform: none; transition: border-color var(--t-fast); }
  .card__art, .card:hover .card__art { transition: none; object-position: 50% 0; }
  .viewer__frame { transition: none; }
  .core[data-idle] .core__label { animation: none !important; }
  .core { letter-spacing: var(--ls-file); }
}
