:root {
  --bg: #0f1110;
  --ink: #efeedd;
  --ink-dim: #a9a89a;
  --paper: #f3f0e6;
  --paper-ink: #1b1c1a;
  --paper-dim: #5d5e57;
  --pixel: "Press Start 2P", monospace;
  --hand: "Handjet", "Courier New", monospace;
  --sans: "Noto Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--hand);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.visually-hidden, .plain-list {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Header ---------- */
.meta {
  position: fixed;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 16px;
  font-size: 23px;
  font-weight: 300;
  line-height: 1.25;
  letter-spacing: 0.02em;
  color: var(--ink);
  pointer-events: none;
  z-index: 10;
}
.meta p { margin: 0; }
.meta__is { color: var(--ink-dim); }
.meta__roles { position: absolute; top: 43px; left: 16px; color: var(--ink-dim); }
.meta__roles span { display: block; }
.meta__visitor { text-align: right; color: var(--ink-dim); }
.meta__line { display: block; }

/* ---------- Stage ---------- */
.stage {
  position: fixed;
  inset: 0;
  outline: none;
}
.stage canvas { display: block; width: 100%; height: 100%; touch-action: manipulation; }
.stage.is-pointer { cursor: pointer; }

.gate-arrow {
  position: fixed;
  left: 0; top: 0;
  width: 56px; height: 56px;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 5;
  animation: nudge 0.9s steps(2) infinite;
}
@keyframes nudge { 50% { translate: 10px 0; } }

.tap-hint {
  position: fixed;
  left: 50%; bottom: 28px;
  translate: -50% 0;
  margin: 0;
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 0.05em;
  color: var(--ink);
  text-align: center;
  width: max-content;
  max-width: calc(100vw - 32px);
  line-height: 1.8;
  animation: blink 1.2s steps(2) infinite;
  z-index: 5;
  pointer-events: none;
}
@keyframes blink { 50% { opacity: 0.25; } }

.preloader {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  font-family: var(--pixel);
  font-size: 12px;
  z-index: 20;
  background: var(--bg);
  transition: opacity 0.4s;
}
.preloader.is-done { opacity: 0; pointer-events: none; }
.dots span { animation: blink 0.9s steps(2) infinite; }
.dots span:nth-child(2) { animation-delay: 0.3s; }
.dots span:nth-child(3) { animation-delay: 0.6s; }

/* ---------- Key hints ---------- */
.keyhint {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  font-size: 19px;
  color: var(--ink-dim);
  opacity: 0;
  transition: opacity 0.6s 0.8s;
}
.keyhint.is-on { opacity: 1; }
.keyhint__group {
  position: absolute;
  top: 50%;
  translate: 0 -55%;
}
.keyhint__group--move { left: max(32px, calc(25vw - 210px)); }
.keyhint__group--buttons { right: max(32px, calc(25vw - 250px)); }
.keyhint__title {
  font-family: var(--pixel);
  font-size: 11px;
  color: var(--ink-dim);
  margin: 0 0 22px;
  letter-spacing: 0.05em;
}
.keyhint kbd {
  display: inline-grid;
  place-items: center;
  min-width: 32px; height: 30px;
  padding: 0 8px;
  border: 1px solid #77766c;
  font-family: var(--hand);
  font-size: 19px;
  color: var(--ink);
  background: rgba(15,17,16,0.85);
}
.keyhint__pads { display: grid; gap: 14px; }
.keyhint__pad {
  display: grid;
  grid-template-columns: repeat(3, 32px);
  grid-template-rows: repeat(2, 30px);
  gap: 5px 3px;
}
.keyhint__pad .up { grid-column: 2; grid-row: 1; }
.keyhint__pad .left { grid-column: 1; grid-row: 2; }
.keyhint__pad .down { grid-column: 2; grid-row: 2; }
.keyhint__pad .right { grid-column: 3; grid-row: 2; }
.keyhint__pad kbd { min-width: 0; padding: 0; }
.keyhint__rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.keyhint__rows li { display: flex; align-items: center; gap: 8px; }
.keyhint__btn {
  font-family: var(--pixel);
  font-size: 11px;
  color: var(--ink);
  width: 26px;
}
.keyhint__btn.sm { font-size: 7px; width: 52px; }
.keyhint__rows li:nth-child(n+3) { margin-left: -26px; }
.or { color: var(--ink-dim); }
.keyhint__note {
  margin: 20px 0 0;
  line-height: 1.15;
  background: rgba(15,17,16,0.85);
  padding: 2px 0;
}

@media (max-width: 1100px), (max-height: 560px) {
  .keyhint { display: none; }
}

/* ---------- Mute ---------- */
.toggles {
  position: fixed;
  right: 16px; bottom: 16px;
  z-index: 30;
}
.toggle {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  background: #181a19;
  color: var(--ink);
  border: 1px solid #2c2e2c;
  cursor: pointer;
}
.toggle:hover { background: #232523; }
.toggle:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.toggle .cross { display: none; }
.toggle[aria-pressed="true"] .waves { display: none; }
.toggle[aria-pressed="true"] .cross { display: inline; }

/* ---------- Page overlay (case studies, posts, about) ---------- */
.frame {
  position: fixed;
  inset: 0;
  z-index: 40;
  overflow-y: auto;
  background: var(--bg);
  animation: frame-in 0.35s steps(5);
}
.frame[hidden] { display: none; }
@keyframes frame-in { from { clip-path: inset(50% 0 50% 0); } to { clip-path: inset(0 0 0 0); } }

.back {
  position: fixed;
  top: 32px; left: 32px;
  z-index: 2;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 12px;
  font-family: var(--pixel);
  font-size: 12px;
  color: #111;
  background: #fbfaf4;
  border: 3px solid #111;
  box-shadow: 0 0 0 3px #fbfaf4, 0 0 0 4px #777;
  cursor: pointer;
}
.back:hover { background: #fff; }
.back:focus-visible { outline: 3px solid #e43; outline-offset: 5px; }

.hero {
  position: relative;
  padding: 68px 80px 48px;
}
.hero__media {
  position: relative;
  max-width: 1280px;
  margin: 0 auto;
  aspect-ratio: 2 / 1;
  overflow: hidden;
  background: #222;
}
.hero__media img, .hero__media canvas {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  image-rendering: pixelated;
}
.hero__media::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(10,12,30,0.85), rgba(10,12,30,0) 55%);
}
.hero__text {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 0 48px 36px;
  z-index: 1;
}
.hero__title {
  font-family: var(--hand);
  font-weight: 800;
  font-size: clamp(40px, 6vw, 72px);
  line-height: 1;
  margin: 0 0 14px;
  color: #fff;
  text-shadow: 3px 3px 0 rgba(0,0,0,0.5);
  letter-spacing: 0.01em;
}
.hero__sub {
  font-family: var(--sans);
  font-size: clamp(16px, 1.6vw, 21px);
  margin: 0;
  color: #f2f2f2;
}

.dither {
  height: 26px;
  background:
    repeating-conic-gradient(var(--paper) 0 25%, transparent 0 50%) 0 0 / 4px 4px,
    var(--bg);
  -webkit-mask: linear-gradient(to bottom, transparent, #000);
          mask: linear-gradient(to bottom, transparent, #000);
  background-color: var(--bg);
}
.dither-wrap { background: var(--bg); }

.paper {
  background: var(--paper);
  color: var(--paper-ink);
  font-family: var(--sans);
  padding: 48px 24px 96px;
  min-height: 60vh;
}
.paper__inner { max-width: 680px; margin: 0 auto; }
.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 10px 32px;
  margin: 0 0 48px;
  font-size: 16px;
}
.facts dt {
  font-family: var(--pixel);
  font-size: 9px;
  padding-top: 5px;
  color: var(--paper-dim);
  letter-spacing: 0.05em;
}
.facts dd { margin: 0; }
.paper p { font-size: 18px; line-height: 1.65; margin: 0 0 1.2em; }
.paper h2 {
  font-family: var(--pixel);
  font-size: 14px;
  line-height: 1.6;
  margin: 2.4em 0 1em;
}
.links { list-style: none; padding: 0; margin: 32px 0 0; display: flex; flex-wrap: wrap; gap: 12px; }
.links a {
  display: inline-block;
  font-family: var(--pixel);
  font-size: 10px;
  padding: 10px 12px;
  border: 2px solid var(--paper-ink);
  text-decoration: none;
}
.links a:hover { background: var(--paper-ink); color: var(--paper); }
.next {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 2px dashed #c9c5b6;
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  font-family: var(--pixel); font-size: 10px; line-height: 1.8;
}
.next a { text-decoration: none; }
.next a:hover { text-decoration: underline; }
.paper .page-footer {
  margin-top: 48px;
  font-size: 14px;
  color: var(--paper-dim);
}
.paper .post-date { font-family: var(--pixel); font-size: 10px; color: var(--paper-dim); margin: 0 0 32px; }
.post-list { list-style: none; padding: 0; margin: 0; }
.post-list li { margin: 0 0 18px; }
.post-list a { font-size: 20px; }

/* ---------- Fallback when WebGL is unavailable ---------- */
html.no-gl body { overflow: auto; }
html.no-gl .stage, html.no-gl .preloader, html.no-gl .keyhint, html.no-gl .toggles,
html.no-gl .gate-arrow, html.no-gl .tap-hint { display: none !important; }
html.no-gl .plain-list {
  position: static !important;
  width: auto; height: auto; clip: auto; clip-path: none; white-space: normal;
  max-width: 680px;
  margin: 0 auto;
  padding: 150px 16px 64px;
  font-family: var(--sans);
  font-size: 18px;
}
html.no-gl .plain-list h2 { font-family: var(--pixel); font-size: 14px; margin-top: 40px; }
html.no-gl .plain-list li { margin-bottom: 14px; }
html.no-gl .plain-list li p { margin: 2px 0 0; color: var(--ink-dim); }

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  .meta { font-size: 18px; padding: 12px 16px; }
  .meta__roles { top: 34px; }
  .back { top: 16px; left: 16px; font-size: 10px; }
  .tap-hint { bottom: 92px; }
  .hero { padding: 72px 0 0; }
  .hero__media { aspect-ratio: 4 / 3; }
  .hero__text { padding: 0 16px 16px; }
  .facts { gap: 8px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
