/* tinyfragments.com. Kanagawa Lotus (light, darkened for WCAG AA) and
   Kanagawa Wave (dark). scripts/test_contrast.py holds the text tokens to
   4.5:1. Everything that moves is pure CSS: the site has no JavaScript, and
   its CSP blocks inline styles, so every effect lives in this file. All
   motion stops under prefers-reduced-motion. */

:root {
  --bg: #F2ECBC;
  --surface: #E8E1B6;
  --fg: #43436C;
  --muted: #5A5960;
  --accent: #3B5687;
  --accent2: #4F6436;
  --border: #D5CEA3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1F1F28;
    --surface: #2A2A37;
    --fg: #DCD7BA;
    --muted: #9A978A;
    --accent: #7E9CD8;
    --accent2: #98BB6C;
    --border: #363646;
  }
}

/* Decorative colours: gradients, glows, node lights. Never body text. */
:root {
  --c1: #4D699B;  --c2: #B35B79;  --c3: #77713F;  --c4: #597B75;
  --glow: rgba(77, 105, 155, .28);
  --glass: rgba(255, 255, 255, .38);
  --term-bg: #16161D;
  --term-fg: #DCD7BA;
  --grain: .07;
}
@media (prefers-color-scheme: dark) {
  :root {
    --c1: #7E9CD8;  --c2: #D27E99;  --c3: #E6C384;  --c4: #7AA89F;
    --glow: rgba(126, 156, 216, .35);
    --glass: rgba(42, 42, 55, .55);
    --grain: .09;
  }
}

@property --angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1.0625rem/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: clip;
  position: relative;
  min-height: 100vh;
}

/* ---- the sky: drifting aurora + film grain ------------------------------ */

body::before {
  content: "";
  position: fixed;
  inset: -20vmax;
  z-index: -2;
  background:
    radial-gradient(40vmax 30vmax at 15% 20%, color-mix(in srgb, var(--c1) 35%, transparent), transparent 70%),
    radial-gradient(35vmax 28vmax at 85% 15%, color-mix(in srgb, var(--c2) 28%, transparent), transparent 70%),
    radial-gradient(45vmax 30vmax at 70% 85%, color-mix(in srgb, var(--c4) 28%, transparent), transparent 70%),
    radial-gradient(30vmax 25vmax at 20% 90%, color-mix(in srgb, var(--c3) 22%, transparent), transparent 70%);
  filter: blur(30px);
  animation: aurora 28s ease-in-out infinite alternate;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: url("/noise.svg");
  opacity: var(--grain);
  mix-blend-mode: overlay;
}
@keyframes aurora {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
  50%  { transform: translate3d(4vmax, -3vmax, 0) rotate(8deg) scale(1.08); }
  100% { transform: translate3d(-3vmax, 2vmax, 0) rotate(-6deg) scale(1.02); }
}

header.site, main, footer.site {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---- header / footer --------------------------------------------------- */

header.site {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  max-width: none;
  padding: 1rem max(16px, calc((100vw - 40rem) / 2 + 16px));
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

.brand {
  color: var(--fg);
  font-weight: 800;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
  text-decoration: none;
}
.brand span {
  background: linear-gradient(90deg, var(--c1), var(--c2), var(--c1));
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 6s linear infinite;
}

header.site nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }
header.site nav a { color: var(--muted); text-decoration: none; }
header.site nav a:hover { color: var(--accent); }

footer.site {
  margin-top: 5rem;
  padding-top: 1.5rem;
  padding-bottom: 2.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9375rem;
}
footer.site p { margin: 0.25rem 0; }
.fine { font-size: 0.875rem; }

.cta {
  margin: 0 0 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--fg);
}

/* ---- type -------------------------------------------------------------- */

h1, h2, h3 { line-height: 1.2; margin: 2rem 0 0.75rem; letter-spacing: -0.02em; }
h1 { font-size: clamp(2rem, 7vw, 3rem); margin-top: 0.5rem; font-weight: 800; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }

p, li { overflow-wrap: anywhere; }

a { color: var(--accent); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

::selection { background: color-mix(in srgb, var(--c2) 40%, transparent); }

code, pre {
  font-family: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}
code { background: var(--surface); padding: 0.1em 0.3em; border-radius: 4px; }
pre {
  background: var(--surface);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  overflow-x: auto;
  line-height: 1.45;
}
pre code { background: none; padding: 0; }

table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 1rem 0;
}
th, td { padding: 0.4rem 0.75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; }

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

figure { margin: 1.5rem 0; }
figure img, figure video {
  display: block;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px -20px var(--glow), 0 2px 6px rgba(0, 0, 0, .12);
}
figcaption { color: var(--muted); font-size: 0.9375rem; margin-top: 0.6rem; }

/* ---- shared motion ------------------------------------------------------ */

@keyframes shimmer { to { background-position: 200% center; } }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { --angle: 360deg; } }

/* Reveal on scroll, where the browser has scroll-driven animations. */
@supports (animation-timeline: view()) {
  .card, .terminal, article.project > h2, details.built {
    animation: rise linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 40%;
  }
}

/* ---- home: hero --------------------------------------------------------- */

section.hero { padding: 3rem 0 1rem; animation: rise .9s cubic-bezier(.2, .7, .2, 1) both; }

.kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 1rem;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--glass);
  color: var(--muted);
  font-size: 0.875rem;
  backdrop-filter: blur(8px);
}
.pulse {
  flex: none;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent2);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent2) 70%, transparent);
  animation: beacon 2s infinite;
}
@keyframes beacon {
  70%  { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.headline {
  font-size: clamp(2.6rem, 11vw, 4.75rem);
  line-height: 1;
  letter-spacing: -0.045em;
  margin: 0 0 1.25rem;
}
.tagline {
  display: block;
  margin-top: 0.6rem;
  font-size: clamp(1.35rem, 5vw, 2.1rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-weight: 800;
  background: linear-gradient(100deg, var(--c1) 0%, var(--c2) 35%, var(--c3) 60%, var(--c4) 80%, var(--c1) 100%);
  background-size: 250% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 9s linear infinite;
}

.intro p { font-size: 1.125rem; color: var(--fg); }

.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.75rem; }
.btn {
  display: inline-block;
  padding: 0.75rem 1.4rem;
  border-radius: 999px;
  font-weight: 700;
  text-decoration: none;
  transition: transform .2s, box-shadow .2s, background .2s;
}
.btn.primary {
  color: var(--bg);
  background: linear-gradient(100deg, var(--c1), var(--c2));
  box-shadow: 0 10px 30px -10px var(--c2);
}
.btn.ghost { color: var(--fg); border: 1px solid var(--border); background: var(--glass); }
.btn:hover { transform: translateY(-2px); box-shadow: 0 16px 40px -12px var(--c1); text-decoration: none; }

/* ---- home: the constellation ------------------------------------------- */

.stage {
  margin: 2rem 0;
  width: min(56rem, calc(100vw - 32px));
  margin-left: 50%;
  transform: translateX(-50%);
}
.constellation { display: block; width: 100%; overflow: visible; }
.constellation .rings circle { fill: none; stroke: var(--border); stroke-width: 1.5; stroke-dasharray: 2 8; stroke-linecap: round; }
.constellation .rings circle:last-child { animation: turn 120s linear infinite; transform-origin: 400px 215px; }
@keyframes turn { to { transform: rotate(360deg); } }

.constellation .link {
  stroke: var(--c1);
  stroke-width: 1.5;
  stroke-dasharray: 3 9;
  stroke-linecap: round;
  opacity: .75;
  animation: flow 1.6s linear infinite;
}
.constellation .link:nth-of-type(3n)   { stroke: var(--c2); animation-duration: 2.2s; }
.constellation .link:nth-of-type(3n+1) { stroke: var(--c4); animation-duration: 1.9s; }
@keyframes flow { to { stroke-dashoffset: -24; } }

.constellation .dot { fill: var(--c1); }
.constellation .halo { fill: var(--c1); opacity: .25; transform-box: fill-box; transform-origin: center; animation: breathe 3s ease-in-out infinite; }
.constellation .node:nth-of-type(2n) .halo { animation-delay: -1s; }
.constellation .node:nth-of-type(3n) .halo { animation-delay: -2s; }
.constellation .agent .dot, .constellation .agent .halo { fill: var(--c4); }
.constellation .hub .dot, .constellation .hub .halo { fill: var(--c2); }
.constellation .off .dot { fill: none; stroke: var(--muted); stroke-dasharray: 2 2; }
.constellation text { fill: var(--fg); font: 600 15px ui-monospace, Menlo, Consolas, monospace; }
.constellation .off text { fill: var(--muted); font-weight: 400; }
@keyframes breathe { 50% { transform: scale(1.6); opacity: .05; } }
/* The diagram scales with the screen; keep its labels readable on a phone. */
@media (max-width: 40rem) {
  .constellation text { font-size: 22px; }
  .constellation .off { display: none; }
  /* tinysurface (n2) and tinypi0 (n7) sit at the far edges: label them underneath. */
  .constellation .n2 text, .constellation .n7 text { text-anchor: middle; }
  .constellation .n2 text { transform: translate(-14px, 32px); }
  .constellation .n7 text { transform: translate(14px, 32px); }
}

/* ---- home: the terminal ------------------------------------------------- */

.terminal {
  margin: 2.5rem 0;
  border-radius: 14px;
  overflow: hidden;
  background: var(--term-bg);
  border: 1px solid #2A2A37;
  box-shadow: 0 30px 80px -30px var(--glow), 0 0 0 1px rgba(255, 255, 255, .03) inset;
}
.term-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0.6rem 0.9rem;
  background: #1F1F28;
  border-bottom: 1px solid #2A2A37;
  color: #9A978A;
  font-size: 0.8rem;
}
.term-bar i { width: 11px; height: 11px; border-radius: 50%; background: #E46876; }
.term-bar i:nth-child(2) { background: #E6C384; }
.term-bar i:nth-child(3) { background: #98BB6C; }
.term-bar span { margin-left: auto; margin-right: auto; padding-right: 40px; }
.term {
  margin: 0;
  padding: 1rem 1.1rem 1.2rem;
  background: none;
  border-radius: 0;
  color: var(--term-fg);
  font-size: 0.85rem;
  line-height: 1.7;
}
.term b { color: #98BB6C; }
.term em { color: #7E9CD8; font-style: normal; }
.term .ok { color: #98BB6C; font-style: normal; }
.term .warn { color: #E6C384; font-style: normal; }
.t-line { opacity: 0; animation: appear .01s forwards; }
.t1 { animation-delay: .4s; } .t2 { animation-delay: 2.2s; } .t3 { animation-delay: 2.9s; }
.t4 { animation-delay: 3.4s; } .t5 { animation-delay: 3.8s; } .t6 { animation-delay: 4.4s; }
.t7 { animation-delay: 5.1s; } .t8 { animation-delay: 5.6s; }
@keyframes appear { to { opacity: 1; } }
.type {
  display: inline-block;
  vertical-align: bottom;
  overflow: hidden;
  white-space: nowrap;
  width: 0;
  animation: typing 1.3s steps(15, end) .6s forwards;
}
@keyframes typing { to { width: 15ch; } }
.cursor {
  display: inline-block;
  width: 0.6em; height: 1.1em;
  vertical-align: text-bottom;
  background: var(--term-fg);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---- home: the marquee -------------------------------------------------- */

.marquee {
  overflow: hidden;
  margin: 2rem 0;
  /* Not 100vw: that includes the scrollbar and scrolls the page sideways. */
  width: min(64rem, calc(100vw - 32px));
  margin-left: 50%;
  transform: translateX(-50%);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 15%, #000 85%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 15%, #000 85%, transparent);
}
.marquee-track { display: flex; width: max-content; animation: slide 40s linear infinite; }
.marquee span {
  padding: 0.5rem 1.4rem;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  color: transparent;
  -webkit-text-stroke: 1px var(--muted);
  white-space: nowrap;
}
.marquee span:nth-child(3n+1) { color: var(--accent); -webkit-text-stroke: 0; }
@keyframes slide { to { transform: translateX(-50%); } }

/* ---- home: cards -------------------------------------------------------- */

.section-title {
  grid-column: 1 / -1;
  font-size: clamp(1.6rem, 6vw, 2.25rem);
  margin: 1rem 0 0.25rem;
}

.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  width: min(64rem, calc(100vw - 32px));
  margin-left: 50%;
  transform: translateX(-50%);
}
@media (min-width: 40rem) {
  .cards { grid-template-columns: 1fr 1fr; }
}

.card {
  --angle: 0deg;
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  color: var(--fg);
  text-decoration: none;
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  overflow: hidden;
  transition: transform .35s cubic-bezier(.2, .7, .2, 1), box-shadow .35s;
}
/* A rotating gradient border, drawn by a masked pseudo-element. */
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 2px;
  background: conic-gradient(from var(--angle), var(--c1), var(--c2), var(--c3), var(--c4), var(--c1));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  opacity: 0;
  transition: opacity .35s;
  animation: spin 4s linear infinite;
  pointer-events: none;
}
.card:hover { transform: translateY(-6px) rotate(-0.4deg); box-shadow: 0 30px 70px -30px var(--glow); }
.card:hover::before { opacity: 1; }
.card-media { display: block; overflow: hidden; border-bottom: 1px solid var(--border); }
.card-media img { display: block; width: 100%; transition: transform .8s cubic-bezier(.2, .7, .2, 1); }
.card:hover .card-media img { transform: scale(1.06); }
.card-body { display: block; padding: 1.1rem 1.25rem 1.3rem; }
.card-num { font: 700 0.8rem ui-monospace, Menlo, monospace; color: var(--accent2); letter-spacing: .1em; text-transform: uppercase; }
.card h2 { margin: 0.25rem 0 0.35rem; font-size: 1.3rem; color: var(--fg); }
.card p { margin: 0; color: var(--muted); }
.card-go { display: inline-block; margin-top: 0.9rem; color: var(--accent); font-weight: 700; transition: transform .3s; }
.card:hover .card-go { transform: translateX(6px); }
.card.soon { border-style: dashed; background: transparent; backdrop-filter: none; justify-content: center; }
.card.soon h2 { color: var(--muted); font-size: 1.1rem; }

/* ---- project pages ----------------------------------------------------- */

article.project { padding-top: 2.5rem; }
article.project > h1 {
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
  background: linear-gradient(100deg, var(--fg) 0%, var(--fg) 45%, var(--c1) 70%, var(--c2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: rise .8s cubic-bezier(.2, .7, .2, 1) both;
}
.outcome { font-size: 1.35rem; color: var(--muted); margin-top: 0; animation: rise .8s .1s cubic-bezier(.2, .7, .2, 1) both; }

figure.hero { animation: rise .9s .2s cubic-bezier(.2, .7, .2, 1) both; }
figure.hero img { box-shadow: 0 40px 100px -30px var(--glow), 0 0 0 1px var(--border); }

/* min(): 22rem alone overrides max-width: 100% and overflows a 360 px phone. */
.hero.narrow img, .hero.narrow video { max-width: min(22rem, 100%); margin: 0 auto; }

.numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  list-style: none;
  padding: 0;
  margin: 1.75rem 0;
}
.numbers li {
  padding: 0.45rem 0.95rem;
  background: var(--glass);
  border: 1px solid color-mix(in srgb, var(--accent2) 45%, var(--border));
  border-radius: 999px;
  color: var(--accent2);
  font-weight: 700;
  box-shadow: 0 0 24px -8px var(--accent2);
}

article.project > h2 { position: relative; padding-bottom: 0.4rem; }
article.project > h2::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0;
  width: 3rem; height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--c1), var(--c2));
}

details.built {
  margin: 3rem 0 1rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--glass);
  backdrop-filter: blur(10px);
}
details.built > summary {
  cursor: pointer;
  display: inline-block;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  color: var(--bg);
  background: linear-gradient(100deg, var(--c1), var(--c2), var(--c1));
  background-size: 200% auto;
  font-weight: 700;
  list-style: none;
  animation: shimmer 6s linear infinite;
  box-shadow: 0 10px 30px -12px var(--c2);
  transition: transform .2s;
}
details.built > summary::-webkit-details-marker { display: none; }
details.built > summary::before { content: "▸ "; }
details.built[open] > summary::before { content: "▾ "; }
details.built > summary:hover { transform: translateY(-2px); }
details.built[open] > :not(summary) { animation: rise .5s cubic-bezier(.2, .7, .2, 1) both; }

.prevnext {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
}
.prevnext a {
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--glass);
  text-decoration: none;
  font-weight: 600;
}
.prevnext a[rel="next"] { margin-left: auto; }

/* ---- calm mode ---------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .type { width: 15ch; }
}
