/* ==========================================================================
   STATICSTATICSTATIC — 0DC
   Industrial Brutalist / Technical Terminal System
   ========================================================================== */

/* --- TOKENS -------------------------------------------------------------- */
:root {
  --off-white: #f7f7f4;
  --black: #0a0a0a;
  --red: #e30613;
  --font-mono: "IBM Plex Mono", "Courier New", Courier, monospace;
  --font-display: "Archivo Black", "Arial Black", sans-serif;
  --shell-max: 1280px;
  --ticker-h: 2.25rem;
}

/* Light mode (print / terminal paper) */
[data-theme="light"] {
  --bg: #f7f7f4;
  --fg: #0a0a0a;
  --surface: #f7f7f4;
  --surface-invert: #0a0a0a;
  --grid-bg: #0a0a0a;
  --border-color: #0a0a0a;
  --red-dim: rgba(227, 6, 19, 0.35);
  --scanline-color: 10, 10, 10;
  --scanline-opacity: 0.04;
  --grain-opacity: 0.12;
  --stripe-mix: rgba(10, 10, 10, 0.04);
  --bus-hover-bg: #0a0a0a;
  --bus-hover-fg: #f7f7f4;
  --glitch-secondary: #0a0a0a;
}

/* Dark mode — default on first visit */
[data-theme="dark"] {
  --bg: #0a0a0a;
  --fg: #f7f7f4;
  --surface: #0a0a0a;
  --surface-invert: #f7f7f4;
  --grid-bg: #f7f7f4;
  --border-color: #f7f7f4;
  --red-dim: rgba(227, 6, 19, 0.5);
  --scanline-color: 247, 247, 244;
  --scanline-opacity: 0.05;
  --grain-opacity: 0.16;
  --stripe-mix: rgba(247, 247, 244, 0.06);
  --bus-hover-bg: #f7f7f4;
  --bus-hover-fg: #0a0a0a;
  --glitch-secondary: #f7f7f4;
}

[data-theme="light"],
[data-theme="dark"] {
  --border: 2px solid var(--border-color);
}

/* --- RESET & BASE -------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  overflow-x: hidden;
  padding-top: var(--ticker-h);
  padding-bottom: var(--ticker-h);
  transition: background 0.2s ease, color 0.2s ease;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  color: var(--red);
}

img,
iframe {
  display: block;
  max-width: 100%;
}

/* --- OVERLAY STACK ------------------------------------------------------- */
#grain-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 9000;
  pointer-events: none;
  opacity: var(--grain-opacity);
  image-rendering: pixelated;
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 8999;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(var(--scanline-color), var(--scanline-opacity)) 2px,
    rgba(var(--scanline-color), var(--scanline-opacity)) 4px
  );
}

/* --- TICKER MARQUEES ----------------------------------------------------- */
.ticker {
  position: fixed;
  left: 0;
  right: 0;
  height: var(--ticker-h);
  background: var(--black);
  color: var(--off-white);
  overflow: hidden;
  z-index: 9500;
  border-block: var(--border);
  border-color: var(--red);
}

.ticker--top {
  top: 0;
}

.ticker--bottom {
  bottom: 0;
}

.ticker__track {
  display: flex;
  width: max-content;
  height: 100%;
  align-items: center;
  animation: ticker-scroll 28s linear infinite;
  will-change: transform;
}

.ticker--bottom .ticker__track {
  animation-duration: 26s;
  animation-direction: reverse;
}

.ticker__segment {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  white-space: nowrap;
  padding-inline: 0;
}

.ticker__item {
  padding-inline: 2.5rem;
  font-size: 0.6875rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ticker__item::before {
  content: "▸ ";
  color: var(--red);
}

.ticker__item--alert {
  color: var(--red);
}

@keyframes ticker-scroll {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

/* --- SHELL --------------------------------------------------------------- */
.shell {
  width: min(100% - 2rem, var(--shell-max));
  margin-inline: auto;
  padding-block: 1.5rem 2rem;
}

/* --- MASTHEAD ------------------------------------------------------------ */
.masthead {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: var(--border);
}

.masthead__sig {
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.masthead__sig span {
  color: var(--red);
}

.masthead__clock {
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
}

.masthead__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 1rem 1.5rem;
}

.masthead__clock-label {
  font-size: 0.625rem;
  color: var(--red);
  margin-right: 0.5rem;
}

/* --- THEME TOGGLE -------------------------------------------------------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.65rem;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg);
  background: transparent;
  border: var(--border);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  background: var(--red);
  color: var(--off-white);
  border-color: var(--red);
  outline: none;
}

.theme-toggle__prefix {
  opacity: 0.55;
}

.theme-toggle__prefix::after {
  content: " :: ";
  color: var(--red);
  opacity: 1;
}

.theme-toggle__state {
  font-weight: 500;
}

/* --- MATRIX GRID --------------------------------------------------------- */
.matrix {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0;
  border: var(--border);
  background: var(--grid-bg);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.matrix > * {
  background: var(--surface);
  border: var(--border);
  margin: -1px 0 0 -1px;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* HERO */
.cell--hero {
  grid-column: 1 / -1;
  padding: clamp(1.25rem, 3vw, 2rem) clamp(1.25rem, 4vw, 3rem) clamp(1.5rem, 4vw, 2.25rem);
  min-height: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  position: relative;
  overflow: visible;
}

.hero__title {
  font-family: var(--font-display);
  font-size: clamp(2.75rem, 9vw, 6.5rem);
  line-height: 0.9;
  letter-spacing: -0.04em;
  text-transform: uppercase;
  position: relative;
  display: inline-block;
  transform-origin: left center;
}

.hero__glitch,
.hero__glitch-main {
  font: inherit;
  letter-spacing: inherit;
  line-height: inherit;
  text-transform: inherit;
}

.hero__glitch {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  user-select: none;
}

.hero__glitch--red {
  color: var(--red);
  z-index: 1;
  opacity: 0;
  animation: hero-glitch-red 2.4s steps(2, end) infinite;
}

.hero__glitch--ghost {
  color: var(--glitch-secondary);
  z-index: 2;
  opacity: 0;
  animation: hero-glitch-ghost 2.4s steps(2, end) infinite;
}

.hero__glitch-main {
  position: relative;
  z-index: 3;
  color: var(--fg);
  animation: hero-glitch-main 2.4s steps(2, end) infinite;
}

.hero__title.is-burst .hero__glitch--red {
  opacity: 0.85;
  transform: translate(6px, -2px);
  clip-path: inset(5% 0 55% 0);
}

.hero__title.is-burst .hero__glitch--ghost {
  opacity: 0.7;
  transform: translate(-5px, 2px);
  clip-path: inset(48% 0 8% 0);
}

.hero__title.is-burst .hero__glitch-main {
  transform: translate(-2px, 1px) skewX(-0.6deg);
  text-shadow:
    3px 0 var(--red),
    -3px 0 var(--glitch-secondary);
}

.hero__subtitle {
  margin-top: clamp(1.25rem, 3vw, 2rem);
  font-size: clamp(0.75rem, 2.2vw, 0.9375rem);
  letter-spacing: 0.14em;
  text-transform: lowercase;
  max-width: 36ch;
  line-height: 1.6;
  position: relative;
  z-index: 2;
  padding-bottom: 0.5rem;
}

.hero__meta {
  margin-top: 1rem;
  font-size: 0.625rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--red);
}

@keyframes hero-glitch-main {
  0%,
  72%,
  100% {
    transform: none;
    text-shadow: none;
  }
  74% {
    transform: translate(-3px, 0) skewX(-1deg);
    text-shadow: 4px 0 var(--red), -4px 0 var(--glitch-secondary);
  }
  76% {
    transform: translate(2px, -1px);
    text-shadow: -3px 0 var(--red);
  }
  78% {
    transform: translate(-1px, 2px);
    text-shadow: 2px 0 var(--red), 0 0 8px var(--red-dim);
  }
  80% {
    transform: none;
    text-shadow: none;
  }
  88% {
    transform: translate(3px, 0) skewX(0.8deg);
    text-shadow: -4px 0 var(--red), 3px 0 var(--glitch-secondary);
  }
  90% {
    transform: translate(-2px, 1px);
    text-shadow: 3px 0 var(--red);
  }
  92% {
    transform: none;
    text-shadow: none;
  }
}

@keyframes hero-glitch-red {
  0%,
  72%,
  100% {
    opacity: 0;
    transform: translate(0, 0);
    clip-path: inset(0 0 100% 0);
  }
  74% {
    opacity: 0.9;
    transform: translate(7px, -2px);
    clip-path: inset(6% 0 58% 0);
  }
  76% {
    opacity: 0.75;
    transform: translate(-5px, 3px);
    clip-path: inset(40% 0 28% 0);
  }
  78% {
    opacity: 0.85;
    transform: translate(4px, 1px);
    clip-path: inset(65% 0 5% 0);
  }
  80% {
    opacity: 0;
    transform: translate(0, 0);
    clip-path: inset(0 0 100% 0);
  }
  88% {
    opacity: 0.8;
    transform: translate(-6px, 0);
    clip-path: inset(20% 0 45% 0);
  }
  90% {
    opacity: 0;
  }
}

@keyframes hero-glitch-ghost {
  0%,
  72%,
  100% {
    opacity: 0;
    transform: translate(0, 0);
    clip-path: inset(0 0 100% 0);
  }
  75% {
    opacity: 0.65;
    transform: translate(-7px, 2px);
    clip-path: inset(15% 0 50% 0);
  }
  77% {
    opacity: 0.6;
    transform: translate(5px, -2px);
    clip-path: inset(52% 0 15% 0);
  }
  79% {
    opacity: 0.7;
    transform: translate(-4px, -1px);
    clip-path: inset(72% 0 4% 0);
  }
  81% {
    opacity: 0;
  }
  89% {
    opacity: 0.65;
    transform: translate(6px, 2px);
    clip-path: inset(30% 0 38% 0);
  }
  91% {
    opacity: 0;
  }
}

/* HANDLE */
.cell--handle {
  grid-column: span 6;
  padding: clamp(1.5rem, 4vw, 2.5rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.handle__id {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 5vw, 3rem);
  letter-spacing: 0.02em;
  cursor: default;
  display: inline-block;
  transition: color 0.15s;
}

.handle__id:hover,
.handle__id.is-glitching {
  color: var(--red);
}

.handle__meta {
  margin-top: 1rem;
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.handle__project {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: var(--border);
  font-size: 0.625rem;
  letter-spacing: 0.1em;
}

.handle__project strong {
  display: block;
  font-size: 0.75rem;
  margin-bottom: 0.25rem;
}

/* STATEMENT */
.cell--statement {
  grid-column: span 6;
  padding: clamp(1.5rem, 4vw, 2.5rem);
}

.statement__label {
  font-size: 0.625rem;
  letter-spacing: 0.2em;
  color: var(--red);
  margin-bottom: 1rem;
}

.statement__body {
  font-size: clamp(0.75rem, 1.8vw, 0.8125rem);
  line-height: 1.75;
  max-width: 52ch;
}

.statement__body p + p {
  margin-top: 1rem;
}

/* AUDIO BUFFER */
.cell--audio {
  grid-column: span 8;
  display: grid;
  grid-template-columns: 3rem 1fr;
  min-height: 22rem;
}

.audio__rail {
  background: var(--red);
  color: var(--off-white);
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: 0.15em;
  border-right: var(--border);
}

.audio__embed {
  padding: 1rem;
  display: flex;
  align-items: stretch;
  min-height: 22rem;
}

.audio__embed iframe {
  width: 100%;
  height: 100%;
  min-height: 20rem;
  border: var(--border);
  background: var(--surface-invert);
}

.audio__placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: var(--border);
  background: repeating-linear-gradient(
    -45deg,
    var(--surface),
    var(--surface) 8px,
    var(--stripe-mix) 8px,
    var(--stripe-mix) 16px
  );
  font-size: 0.625rem;
  letter-spacing: 0.15em;
  text-align: center;
  padding: 1rem;
}

/* EXTERNAL BUS */
.cell--bus {
  grid-column: span 4;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.bus__header {
  padding: 0.75rem 1rem;
  background: var(--surface-invert);
  color: var(--surface);
  font-size: 0.625rem;
  letter-spacing: 0.2em;
  border-bottom: var(--border);
}

.bus__list {
  list-style: none;
  flex: 1;
}

.bus__list li {
  border-bottom: var(--border);
}

.bus__list li:last-child {
  border-bottom: none;
}

.bus__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  font-size: 0.6875rem;
  letter-spacing: 0.06em;
  transition: background 0.12s, color 0.12s;
}

.bus__link::after {
  content: "→";
  color: var(--red);
  font-size: 1rem;
}

.bus__link:hover {
  background: var(--bus-hover-bg);
  color: var(--bus-hover-fg);
}

.bus__link:hover::after {
  color: var(--bus-hover-fg);
}

/* FOOTER */
.site-footer {
  margin-top: 2rem;
  padding: 1.25rem;
  text-align: center;
  font-size: 0.625rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  border-top: var(--border);
}

/* --- RESPONSIVE ---------------------------------------------------------- */
@media (max-width: 900px) {
  .cell--handle,
  .cell--statement {
    grid-column: 1 / -1;
  }

  .cell--audio {
    grid-column: 1 / -1;
  }

  .cell--bus {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 0.75rem;
  }

  .shell {
    width: min(100% - 1rem, var(--shell-max));
    padding-block: 1rem 1.5rem;
  }

  .cell--hero {
    padding: 1.5rem 1rem 3rem;
    min-height: auto;
  }

  .hero__title {
    font-size: clamp(2.25rem, 14vw, 3.75rem);
    line-height: 0.92;
  }

  .hero__subtitle {
    margin-top: 1.5rem;
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    max-width: 100%;
    padding-right: 0.25rem;
  }

  .masthead__sig {
    font-size: 0.5625rem;
  }

  .cell--audio {
    grid-template-columns: 2.25rem 1fr;
  }

  .audio__rail {
    font-size: 0.875rem;
  }

  .ticker__item {
    padding-inline: 1.5rem;
    font-size: 0.5625rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ticker__track {
    animation: none;
  }

  .hero__title.is-burst .hero__glitch-main,
  .hero__title.is-burst .hero__glitch--red,
  .hero__title.is-burst .hero__glitch--ghost {
    transform: none;
    text-shadow: none;
    opacity: 0;
    clip-path: none;
  }

  .hero__glitch-main,
  .hero__glitch--red,
  .hero__glitch--ghost {
    animation: none;
  }
}
