/* ============================================================
   FLUX — Fragment Shader Observatory
   pure black / white / #FF3B30 / 1px #333 / JetBrains Mono
   ============================================================ */

:root {
  --bg: #000;
  --fg: #fff;
  --line: #333;
  --dim: #777;
  --faint: #999;
  --accent: #FF3B30;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  scrollbar-color: var(--line) var(--bg);
  /* keep the gutter when the inspector locks scroll, so the FLIP
     start rect matches exactly where the tile sits on screen */
  scrollbar-gutter: stable;
}

body {
  font-size: 12px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

body.modal-open { overflow: hidden; }

/* Lenis smooth scroll (UI layer) */
html.lenis, html.lenis body { height: auto; }
.lenis.lenis-smooth { scroll-behavior: auto !important; }
.lenis.lenis-stopped { overflow: hidden; }

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

button {
  font-family: var(--mono);
  background: #000;
  color: var(--fg);
  border: 1px solid var(--line);
  font-size: 10px;
  letter-spacing: 0.14em;
  padding: 9px 16px;
  text-transform: uppercase;
  transition: border-color 0.18s, color 0.18s;
}
button:hover { border-color: var(--fg); }
button:focus-visible,
.tile:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

.tag {
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--accent);
  text-transform: uppercase;
}

/* ---------------- noscript / fallback / intro shells -------- */

.noscript, #fallback, #intro {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: min(12vw, 130px);
  z-index: 200;
}
.noscript { z-index: 300; }

.noscript h1, #fallback h1 {
  font-size: clamp(34px, 7vw, 72px);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.02em;
  margin: 14px 0 18px;
}
.noscript .body, #fallback .body {
  max-width: 58ch;
  color: var(--faint);
  font-size: 12px;
}
.fallback-list { margin-top: 34px; border-left: 1px solid var(--line); padding-left: 18px; }
.fallback-list p { font-size: 10px; letter-spacing: 0.12em; color: var(--dim); line-height: 2; }

#intro { transition: opacity 0.55s ease; }
#intro.done { opacity: 0; pointer-events: none; }

.intro-mark {
  font-size: clamp(64px, 15vw, 170px);
  font-weight: 700;
  line-height: 0.92;
  letter-spacing: -0.04em;
  margin-top: 10px;
}
.intro-sub {
  font-size: 10px;
  letter-spacing: 0.34em;
  color: var(--dim);
  margin-top: 12px;
}
#boot-log { margin-top: 36px; min-height: 176px; max-height: 44vh; overflow: hidden; }
.boot-line {
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.06em;
  line-height: 1.7;
}
.boot-line.bad { color: var(--accent); }
.intro-bar {
  width: 260px;
  height: 1px;
  background: #222;
  margin-top: 26px;
}
#intro-fill {
  display: block;
  height: 1px;
  width: 0;
  background: var(--accent);
  transition: width 0.25s ease;
}

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

.site-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.head-left { display: flex; align-items: baseline; }
.mark { font-size: 18px; font-weight: 700; letter-spacing: 0.02em; }
.mark-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--accent);
  margin-left: 7px;
  animation: blink 1.6s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0.15; } }
.head-sub {
  font-size: 10px;
  letter-spacing: 0.26em;
  color: var(--dim);
  margin-left: 20px;
  text-transform: uppercase;
}
.hud { display: flex; gap: 24px; }
.hud span {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--dim);
  white-space: nowrap;
}
.hud b { color: var(--fg); font-weight: 500; font-variant-numeric: tabular-nums; }
.hud .hud-spec b { display: inline-block; min-width: 11ch; color: var(--accent); }

/* ---------------- hero --------------------------------------- */

.hero {
  padding: clamp(48px, 9vh, 100px) 20px clamp(40px, 7vh, 80px);
}
.hero h1 {
  font-size: clamp(26px, 4.6vw, 60px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 16px 0 20px;
}
.hero-body {
  max-width: 62ch;
  color: #aaa;
  font-size: 13px;
}
.hero-meta {
  margin-top: 22px;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: #666;
  text-transform: uppercase;
}

/* ---------------- grid / tiles ------------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.tile {
  position: relative;
  background: #000;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  display: block;
}
html.has-cursor .tile { cursor: none; }

.tile canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.tile-row {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  pointer-events: none;
  z-index: 2;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.tile-top { top: 0; }
.tile-bot { bottom: 0; }

.t-index { color: var(--accent); font-weight: 700; }
.t-tech, .t-name, .t-status b { mix-blend-mode: difference; }
.t-tech { color: #bbb; font-size: 9px; }
.t-name { color: #fff; font-weight: 700; font-size: 12px; letter-spacing: 0.18em; }
.t-status { display: flex; align-items: center; gap: 7px; color: #ccc; }
.t-status i {
  width: 5px;
  height: 5px;
  background: var(--accent);
  animation: blink 1.4s steps(2, start) infinite;
}
.tile:hover .t-status b { color: var(--accent); mix-blend-mode: normal; }

/* corner brackets on hover / focus */
.tile::before, .tile::after {
  content: '';
  position: absolute;
  width: 15px;
  height: 15px;
  border: 0 solid var(--accent);
  opacity: 0;
  transition: opacity 0.18s;
  z-index: 3;
  pointer-events: none;
}
.tile::before { top: 7px; left: 7px; border-top-width: 1px; border-left-width: 1px; }
.tile::after { bottom: 7px; right: 7px; border-bottom-width: 1px; border-right-width: 1px; }
.tile:hover::before, .tile:hover::after,
.tile:focus-visible::before, .tile:focus-visible::after { opacity: 1; }

/* staggered reveal — CSS path (fallback when GSAP is absent) */
body.booting .tile { opacity: 0; transform: translateY(14px); }
body.revealed .tile {
  opacity: 1;
  transform: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
  transition-delay: calc(var(--i, 0) * 45ms);
}
/* when GSAP owns the reveal, the CSS path stands down */
body.gsap .tile {
  opacity: 1;
  transform: none;
  transition: none;
  transition-delay: 0s;
}

/* 008 FLOW — painting must beat scrolling on touch */
.tile--flow { touch-action: none; }

/* compile-error state */
.tile--error canvas { opacity: 0.4; }
.tile-fault {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  background: rgba(20, 0, 0, 0.82);
  border: 1px solid var(--accent);
}
.tile-fault b { font-size: 38px; font-weight: 700; color: var(--accent); letter-spacing: 0.05em; }
.tile-fault span { font-size: 9px; letter-spacing: 0.2em; color: #b98a86; }

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

.foot-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.foot-grid > div {
  padding: 30px 20px 34px;
  border-left: 1px solid var(--line);
}
.foot-grid > div:first-child { border-left: none; }
.foot-grid h3 {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.24em;
  color: var(--dim);
  margin-bottom: 12px;
}
.foot-grid p { color: var(--faint); font-size: 11px; line-height: 1.75; max-width: 44ch; }

.foot-bar {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 24px;
  border-top: 1px solid var(--line);
  padding: 14px 20px;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: #666;
  text-transform: uppercase;
}
.foot-motion { display: flex; align-items: center; gap: 14px; }
#motion-btn { padding: 5px 12px; }

/* ---------------- fullscreen inspector ----------------------- */

#modal {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
}
#modal canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.modal-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px;
  z-index: 5;
  gap: 12px;
  flex-wrap: wrap;
}
.modal-id {
  display: flex;
  align-items: baseline;
  gap: 14px;
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid var(--line);
  padding: 10px 16px;
}
.m-index { color: var(--accent); font-weight: 700; font-size: 12px; letter-spacing: 0.1em; }
.m-name { font-size: 20px; font-weight: 700; letter-spacing: 0.06em; }
.m-tech { font-size: 9px; letter-spacing: 0.2em; color: var(--dim); text-transform: uppercase; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions button { background: rgba(0, 0, 0, 0.78); }
#btn-source[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.modal-info {
  position: absolute;
  left: 20px;
  bottom: 20px;
  z-index: 5;
  max-width: min(520px, calc(100vw - 40px));
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid var(--line);
  padding: 16px 18px;
}
.modal-info p { color: #bbb; font-size: 11px; line-height: 1.75; }

.modal-fault {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
}
#modal.modal-error .modal-fault { display: flex; }
.modal-fault b { font-size: 56px; font-weight: 700; color: var(--accent); }
.modal-fault span { font-size: 10px; letter-spacing: 0.2em; color: #b98a86; }

/* source panel */
#source-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(620px, 100%);
  background: rgba(0, 0, 0, 0.93);
  border-left: 1px solid var(--line);
  transform: translateX(101%);
  transition: transform 0.32s cubic-bezier(0.25, 0.9, 0.3, 1);
  z-index: 6;
  display: flex;
  flex-direction: column;
}
#modal.show-source #source-panel { transform: none; }
.source-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--dim);
  text-transform: uppercase;
}
.source-tools { display: flex; align-items: center; gap: 14px; }
#btn-copy { padding: 5px 12px; font-size: 9px; }
#btn-copy:active { border-color: var(--accent); color: var(--accent); }

/* source view v2: the typing caret */
.type-caret {
  display: inline-block;
  width: 7px;
  height: 12px;
  margin-left: 1px;
  vertical-align: -2px;
  background: var(--accent);
  animation: blink 0.9s steps(2, start) infinite;
}
#source-pre {
  flex: 1;
  overflow: auto;
  padding: 20px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.62;
  color: #c8c8c8;
  tab-size: 2;
}

/* tiny GLSL highlighter palette */
.g-cmt { color: #4d4d4d; }
.g-num { color: #8f8f8f; }
.g-kw  { color: #fff; font-weight: 500; }
.g-fn  { color: #b5b5b5; }
.g-pre { color: #6e6e6e; }
.g-uni { color: var(--accent); }

/* ---------------- custom cursor ------------------------------ */

html.has-cursor body { cursor: none; }
html.has-cursor a,
html.has-cursor button { cursor: none; }

#cursor {
  position: fixed;
  left: 0;
  top: 0;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  pointer-events: none;
  z-index: 1000;
  mix-blend-mode: difference;
  opacity: 0;
  transition: opacity 0.2s;
  display: none;
}
html.has-cursor #cursor { display: block; }
#cursor::before, #cursor::after {
  content: '';
  position: absolute;
  background: #fff;
  transition: top 0.15s, left 0.15s, width 0.15s, height 0.15s;
}
#cursor::before { left: 50%; top: 0; width: 1px; height: 100%; }
#cursor::after { top: 50%; left: 0; height: 1px; width: 100%; }
#cursor i {
  position: absolute;
  inset: 9px;
  border: 1px solid #fff;
  opacity: 0;
  transition: opacity 0.15s, inset 0.18s;
}
#cursor.is-active::before { top: 30%; height: 40%; }
#cursor.is-active::after { left: 30%; width: 40%; }
#cursor.is-active i { opacity: 1; inset: 2px; }

/* ---------------- responsive --------------------------------- */

@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .head-sub { display: none; }
  .foot-grid { grid-template-columns: 1fr; }
  .foot-grid > div { border-left: none; border-top: 1px solid var(--line); }
  .foot-grid > div:first-child { border-top: none; }
}
@media (max-width: 900px) {
  .hud { gap: 16px; }
  .hud .hud-t { display: none; }
}
@media (max-width: 680px) {
  .grid { grid-template-columns: 1fr; }
  .hud .hud-dpr, .hud .hud-q { display: none; }
  .hud .hud-spec b { min-width: 0; }
  .modal-info { right: 20px; }
  .noscript, #fallback, #intro { padding: 32px 24px; }
}

/* ---------------- reduced motion ------------------------------ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
