/* ═══════════════════════════════════════════════════════════════════════════
   BROKEN SPEAKERS // DECAYED BUILD
   A copy of the game UI left out in the rain. Loads after styles.css and
   ps1-interface.css and rots everything on top.

   All theme rot lives under body.rotten. Starting the game runs a staged
   repair: damage layers fade out first (body.repairing), then .rotten is
   removed and the clean original UI transitions back in.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── 1. Palette tokens ──────────────────────────────────────────────────── */
:root {
  --d-bg: #060705;
  --d-panel: #0a0d07;
  --d-green-dead: #46602e;
  --d-rust: #a05a22;
  --d-rust-dark: #57300f;
  --d-amber: #c8992a;
  --d-red: #b03426;
  --d-line: #2c3d1e;
  --d-tape: rgba(178, 170, 150, 0.16);
  --d-noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.06 0 0 0 0 0.05 0 0 0 0 0.02 0 0 0 0.55 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* rot the ps1 tokens in place — everything downstream decays with them */
body.rotten {
  --ps1-ink: #050604;
  --ps1-face: #0b0f08;
  --ps1-edge: #3d4a26;
  --ps1-text: #b6c694;
  --ps1-muted: #6d7c4e;
  --ps1-green: #7fae54;
  --ps1-cyan: #86a06a;
  --ps1-amber: #c8992a;
}

body.rotten {
  background:
    radial-gradient(ellipse 60% 40% at 12% 88%, rgba(87, 48, 15, 0.22), transparent 70%),
    radial-gradient(ellipse 40% 55% at 92% 12%, rgba(87, 48, 15, 0.14), transparent 70%),
    radial-gradient(ellipse 30% 25% at 70% 80%, rgba(40, 60, 20, 0.12), transparent 70%),
    var(--d-bg);
  color: var(--ps1-text);
  cursor: progress;
}

body.rotten ::selection {
  background: rgba(160, 90, 34, 0.55);
  color: #f2e8c8;
}

/* ─── 2. Repair: everything settles back down, slowly ──────────────────────
   Transitions live on body.repairing (the staged-repair window) only, so the
   live app keeps snappy interactions the rest of the time. */
body.repairing,
body.repairing *,
body.repairing *::before,
body.repairing *::after {
  transition:
    color 1.4s ease,
    background-color 1.4s ease,
    background-image 1.4s ease,
    border-color 1.4s ease,
    text-shadow 1.4s ease,
    box-shadow 1.4s ease,
    transform 1.4s ease,
    opacity 1.4s ease,
    clip-path 1.4s ease;
}

/* ─── 3. CRT overlay: scanlines, vignette, the rolling band of dead air ───── */
.crt-overlay {
  position: fixed;
  inset: 0;
  z-index: 95;
  pointer-events: none;
  transition: opacity 1.6s ease;
  background:
    repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 58%, rgba(0, 0, 0, 0.55) 100%);
}

.crt-overlay::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 22vh;
  top: -25vh;
  background: linear-gradient(180deg,
      transparent,
      rgba(150, 220, 120, 0.045) 42%,
      rgba(150, 220, 120, 0.07) 50%,
      rgba(150, 220, 120, 0.045) 58%,
      transparent);
  animation: crt-roll 7.3s linear infinite;
}

.crt-overlay::after {
  /* faint horizontal hold jitter line */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  top: 31%;
  background: rgba(200, 255, 170, 0.06);
  animation: crt-hold 11s steps(1) infinite;
}

@keyframes crt-roll {
  to {
    transform: translateY(130vh);
  }
}

@keyframes crt-hold {
  0%, 88% {
    top: 31%;
    opacity: 0.5;
  }
  89% {
    top: 64%;
    opacity: 1;
  }
  91% {
    top: 12%;
    opacity: 0.8;
  }
  93%, 100% {
    top: 78%;
    opacity: 0;
  }
}

/* ─── 4. Static noise + crack layer ──────────────────────────────────────── */
#decayNoise {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 90;
  pointer-events: none;
  opacity: 0.075;
  mix-blend-mode: screen;
  image-rendering: pixelated;
  transition: opacity 1.6s ease;
}

.crack-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 92;
  pointer-events: none;
  opacity: 0.65;
  transition: opacity 2s ease 0.4s;
}

.dead-pixel {
  position: fixed;
  z-index: 93;
  width: 3px;
  height: 3px;
  pointer-events: none;
  transition: opacity 1.2s ease;
}

.dead-pixel.black {
  background: #000;
}

.dead-pixel.stuck {
  background: #9fff6a;
  box-shadow: 0 0 4px rgba(140, 255, 100, 0.8);
}

.dead-pixel.bleeding {
  background: #c8992a;
  animation: px-blink 1.7s steps(1) infinite;
}

@keyframes px-blink {
  0%, 60% {
    opacity: 1;
  }
  61%, 100% {
    opacity: 0;
  }
}

/* damage layers fade away during and after repair */
body.repairing #decayNoise,
body.repairing .crt-overlay,
body.repairing .crack-layer,
body.repairing .dead-pixel,
body:not(.rotten) #decayNoise,
body:not(.rotten) .crt-overlay,
body:not(.rotten) .crack-layer,
body:not(.rotten) .dead-pixel {
  opacity: 0 !important;
}

/* ─── 5. Whole-screen glitch events (triggered by JS) ────────────────────── */
body.glitch-burst .app-shell {
  animation: screen-tear 0.24s steps(2, end);
}

@keyframes screen-tear {
  0% {
    transform: translate(0, 0);
    filter: none;
  }
  20% {
    transform: translate(-5px, 2px) skewX(0.8deg);
    filter: hue-rotate(45deg) saturate(2.4);
  }
  40% {
    transform: translate(4px, -3px) skewX(-0.6deg);
    filter: invert(0.07) contrast(1.4);
  }
  60% {
    transform: translate(-2px, 1px);
    filter: hue-rotate(-60deg) brightness(1.3);
  }
  80% {
    transform: translate(1px, -1px);
    filter: saturate(0.2);
  }
  100% {
    transform: none;
    filter: none;
  }
}

body.power-sag .app-shell {
  filter: brightness(0.45) contrast(1.25) sepia(0.3);
  transition: filter 50ms;
}

/* ─── 6. Home page: the marquee of a place nobody maintains ──────────────── */
body.rotten .home-page {
  background:
    var(--d-noise),
    radial-gradient(ellipse 70% 50% at 50% 38%, rgba(60, 90, 40, 0.14), transparent 65%),
    radial-gradient(ellipse 45% 35% at 85% 90%, rgba(87, 48, 15, 0.25), transparent 70%),
    radial-gradient(circle 180px at 16% 22%, rgba(0, 0, 0, 0.55), transparent 75%),
    #04050300;
  background-color: #040503;
}

body.rotten .home-page::before {
  /* water-stained ceiling tiles of the internet */
  background:
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(70, 96, 46, 0.13) 3px 4px),
    radial-gradient(ellipse 34% 20% at 24% 14%, rgba(96, 66, 20, 0.2), transparent 70%),
    radial-gradient(ellipse 22% 30% at 78% 62%, rgba(96, 66, 20, 0.14), transparent 70%);
  opacity: 1;
}

body.rotten .home-edition {
  color: var(--d-amber);
  animation: flicker-soft 5.5s infinite;
}

body.rotten .home-title {
  position: relative;
  color: #a9c47e;
  text-shadow:
    3px 3px 0 #17301a,
    0 0 18px rgba(127, 174, 84, 0.35);
  animation: title-flicker 7s infinite;
}

/* RGB-split ghost slices over the title */
body.rotten .home-title::before,
body.rotten .home-title::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  mix-blend-mode: screen;
}

body.rotten .home-title::before {
  color: rgba(176, 52, 38, 0.55);
  transform: translate(-3px, 1px);
  clip-path: inset(0 0 58% 0);
  animation: slice-a 3.7s steps(1) infinite;
}

body.rotten .home-title::after {
  color: rgba(60, 140, 190, 0.45);
  transform: translate(3px, -1px);
  clip-path: inset(52% 0 0 0);
  animation: slice-b 2.9s steps(1) infinite;
}

@keyframes slice-a {
  0%, 82% {
    clip-path: inset(0 0 99% 0);
  }
  83% {
    clip-path: inset(12% 0 55% 0);
    transform: translate(-6px, 1px);
  }
  87% {
    clip-path: inset(40% 0 30% 0);
    transform: translate(4px, -2px);
  }
  91%, 100% {
    clip-path: inset(0 0 99% 0);
  }
}

@keyframes slice-b {
  0%, 74% {
    clip-path: inset(99% 0 0 0);
  }
  75% {
    clip-path: inset(48% 0 18% 0);
    transform: translate(5px, 2px);
  }
  80% {
    clip-path: inset(66% 0 4% 0);
    transform: translate(-4px, 0);
  }
  85%, 100% {
    clip-path: inset(99% 0 0 0);
  }
}

@keyframes title-flicker {
  0%, 100% {
    opacity: 1;
  }
  54% {
    opacity: 1;
  }
  55% {
    opacity: 0.35;
  }
  56% {
    opacity: 1;
  }
  71% {
    opacity: 0.72;
  }
  72% {
    opacity: 1;
  }
}

@keyframes flicker-soft {
  0%, 100% {
    opacity: 1;
  }
  83% {
    opacity: 1;
  }
  84% {
    opacity: 0.3;
  }
  85% {
    opacity: 1;
  }
  88% {
    opacity: 0.55;
  }
  89% {
    opacity: 1;
  }
}

body.rotten .home-tagline {
  color: var(--ps1-muted);
}

body.rotten .home-session {
  color: #8a6a3a;
}

body.rotten .session-light {
  background: var(--d-red);
  box-shadow: 0 0 8px rgba(176, 52, 38, 0.9);
  animation: px-blink 1.1s steps(1) infinite;
}

/* ─── 7. The blown speaker centerpiece ───────────────────────────────────── */
.home-artifact-area {
  display: grid;
  place-items: center;
  position: relative;
}

.wreck {
  position: relative;
  width: min(760px, 100%);
  height: 100%;
}

.speaker-woofer {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(300px, 62vw);
  aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(-4deg);
  border-radius: 50%;
  border: 3px solid #33421f;
  background:
    radial-gradient(circle at 44% 38%, rgba(150, 190, 110, 0.1), transparent 32%),
    repeating-radial-gradient(circle at 50% 50%, rgba(90, 110, 60, 0.16) 0 2px, transparent 2px 11px),
    radial-gradient(circle at 45% 40%, #171d10, #070a05 68%);
  box-shadow:
    inset 0 0 40px rgba(0, 0, 0, 0.85),
    6px 8px 0 rgba(0, 0, 0, 0.5);
}

/* the dust cap popped clean out */
.speaker-woofer::before {
  content: "";
  position: absolute;
  left: 58%;
  top: 24%;
  width: 30%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid #4a5a2e;
  background: radial-gradient(circle at 40% 35%, #2a3418, #0b0f07 70%);
  transform: rotate(14deg);
  box-shadow: 4px 6px 0 rgba(0, 0, 0, 0.6);
}

/* the hole it left behind */
.speaker-woofer::after {
  content: "";
  position: absolute;
  left: 34%;
  top: 36%;
  width: 30%;
  aspect-ratio: 1;
  background: #000;
  clip-path: polygon(48% 0, 70% 12%, 100% 30%, 88% 62%, 96% 88%, 56% 100%, 22% 86%, 6% 52%, 18% 20%);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 1);
}

.woofer-crack {
  position: absolute;
  background: rgba(0, 0, 0, 0.85);
  box-shadow: 1px 0 0 rgba(190, 230, 160, 0.1);
  z-index: 2;
}

.woofer-crack.c1 {
  left: 50%;
  top: 6%;
  width: 2px;
  height: 34%;
  transform: rotate(24deg);
}

.woofer-crack.c2 {
  left: 18%;
  top: 52%;
  width: 2px;
  height: 40%;
  transform: rotate(-58deg);
}

.speaker-tweeter {
  position: absolute;
  right: 13%;
  top: 22%;
  width: min(110px, 22vw);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid #3d4a26;
  background:
    repeating-radial-gradient(circle at 50% 50%, rgba(90, 110, 60, 0.2) 0 1px, transparent 1px 6px),
    radial-gradient(circle at 42% 38%, #1c2312, #060804 70%);
  transform: rotate(9deg);
  box-shadow: 4px 5px 0 rgba(0, 0, 0, 0.55);
}

.speaker-tweeter::after {
  /* its cone tore straight through */
  content: "";
  position: absolute;
  left: 30%;
  top: 8%;
  width: 44%;
  height: 84%;
  background: #000;
  clip-path: polygon(52% 0, 88% 18%, 66% 46%, 96% 70%, 58% 100%, 30% 66%, 4% 40%, 26% 16%);
}

.hanging-wire {
  position: absolute;
  left: 14%;
  top: 0;
  width: 120px;
  height: 70%;
  overflow: visible;
}

.hanging-wire path {
  fill: none;
  stroke: #6a5a2e;
  stroke-width: 2.5;
}

.hanging-wire .plug {
  fill: #14180d;
  stroke: #3d4a26;
  stroke-width: 2;
}

.wreck-caption {
  position: absolute;
  left: 50%;
  bottom: -4px;
  transform: translateX(-50%) rotate(-1.2deg);
  color: var(--d-rust);
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ─── 8. Buttons: taped on, hanging by threads, mostly refusing ──────────── */
body.rotten button,
body.rotten .upload-button {
  border-style: dashed !important;
  border-color: var(--d-line) !important;
  background:
    var(--d-noise),
    rgba(8, 11, 6, 0.92) !important;
  color: #9db377;
  text-shadow: 0 0 5px rgba(127, 174, 84, 0.25);
}

body.rotten button:not(:disabled):hover,
body.rotten .upload-button:hover {
  border-color: var(--d-amber) !important;
  color: #e8dca8;
  animation: btn-zap 0.16s steps(2);
}

body.rotten button:disabled {
  color: #4a5634;
  text-decoration: line-through;
  text-decoration-color: rgba(176, 52, 38, 0.7);
  opacity: 1;
}

@keyframes btn-zap {
  50% {
    filter: invert(0.25) hue-rotate(90deg);
    transform: translate(1px, -1px);
  }
}

.home-buttons {
  position: relative;
}

.home-buttons button {
  position: relative;
  min-height: 58px;
}

body.rotten #playGameButton {
  transform: rotate(-0.7deg);
  border-style: solid !important;
  border-color: #5a6e36 !important;
}

#tutorialButton {
  transform-origin: top right;
}

body.rotten #tutorialButton {
  /* hanging by a single thread */
  transform: rotate(2.4deg);
  animation: dangle 5.2s ease-in-out infinite alternate;
  border-width: 1px 1px 3px 1px !important;
}

@keyframes dangle {
  from {
    transform: rotate(1.6deg);
  }
  to {
    transform: rotate(3.4deg);
  }
}

.thread-anchor {
  position: absolute;
  z-index: 3;
  top: -26px;
  right: 18px;
  width: 2px;
  height: 26px;
  background: linear-gradient(180deg, #8a7a44, #57300f);
  transform: rotate(-6deg);
  transform-origin: top;
  transition: opacity 1.4s ease;
}

body.rotten .thread-anchor {
  animation: thread-sway 5.2s ease-in-out infinite alternate;
}

body.repairing .thread-anchor,
body:not(.rotten) .thread-anchor {
  opacity: 0;
}

@keyframes thread-sway {
  from {
    transform: rotate(-8deg);
  }
  to {
    transform: rotate(-2deg);
  }
}

/* ─── 9. Tape, stitches, hazard strips, drips ────────────────────────────── */
.tape {
  position: absolute;
  z-index: 6;
  width: 118px;
  height: 30px;
  background:
    repeating-linear-gradient(90deg, transparent 0 7px, rgba(0, 0, 0, 0.05) 7px 8px),
    var(--d-tape);
  border-left: 1px dashed rgba(255, 255, 255, 0.14);
  border-right: 1px dashed rgba(255, 255, 255, 0.14);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

.tape::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, rgba(255, 255, 255, 0.1), transparent 45%);
}

.tape.tl {
  left: -22px;
  top: -12px;
  transform: rotate(-38deg);
}

.tape.tr {
  right: -22px;
  top: -14px;
  transform: rotate(41deg);
}

.tape.bl {
  left: -20px;
  bottom: 26px;
  transform: rotate(48deg);
}

.tape.mid {
  left: 50%;
  top: -14px;
  transform: translateX(-50%) rotate(2deg);
}

.tape-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(230, 220, 190, 0.5);
  font-size: 9px;
  letter-spacing: 2px;
  transform: rotate(-4deg);
}

.hazard {
  position: absolute;
  z-index: 7;
  padding: 5px 16px;
  background: repeating-linear-gradient(45deg, rgba(200, 153, 42, 0.75) 0 12px, rgba(20, 16, 8, 0.9) 12px 24px);
  color: #0c0a05;
  background-clip: padding-box;
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 2px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.6);
  clip-path: polygon(2% 8%, 98% 0, 100% 88%, 1% 100%);
}

.stitch {
  position: absolute;
  z-index: 5;
  border-top: 2px dashed rgba(90, 110, 55, 0.55);
  pointer-events: none;
}

.drip {
  position: absolute;
  z-index: 5;
  top: 100%;
  width: 3px;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(180deg, var(--d-rust-dark), rgba(87, 48, 15, 0));
  pointer-events: none;
}

.drip.green {
  background: linear-gradient(180deg, #3d5a24, rgba(61, 90, 36, 0));
}

/* ─── 10. Panels: cracked apart, held on out of spite ────────────────────── */
body.rotten .music-panel,
body.rotten .tutorial-panel {
  position: relative;
  transform: rotate(-0.35deg);
  border-style: dashed !important;
  border-color: #4a5a2e !important;
  background:
    var(--d-noise),
    radial-gradient(ellipse 50% 30% at 88% 6%, rgba(87, 48, 15, 0.28), transparent 65%),
    radial-gradient(ellipse 35% 40% at 6% 92%, rgba(87, 48, 15, 0.2), transparent 70%),
    radial-gradient(ellipse 26% 18% at 40% 55%, rgba(0, 0, 0, 0.5), transparent 70%),
    #090c06 !important;
  box-shadow:
    8px 10px 0 rgba(0, 0, 0, 0.65),
    inset 0 0 80px rgba(0, 0, 0, 0.6) !important;
  clip-path: polygon(0 0, 99.2% 0.4%, 100% 3%, 100% 97.6%, 99% 100%, 1.2% 99.4%, 0 96.8%);
}

/* the seam that gave up */
body.rotten .music-panel::after,
body.rotten .tutorial-panel::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 41%;
  height: 3px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.9) 0 14%, transparent 14% 16%,
      rgba(0, 0, 0, 0.9) 16% 47%, transparent 47% 49%,
      rgba(0, 0, 0, 0.9) 49% 78%, transparent 78% 80%,
      rgba(0, 0, 0, 0.9) 80% 100%);
  box-shadow: 0 1px 0 rgba(190, 230, 160, 0.08), 0 2px 4px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 8;
}

body.rotten .panel-header h1 {
  color: #a9c47e;
}

body.rotten .eyebrow {
  color: #8a6a3a;
}

body.rotten .icon-button:hover {
  border-color: var(--d-red) !important;
  color: var(--d-red) !important;
}

/* ─── 11. The PS1 viewport: no signal for months ─────────────────────────── */
body.rotten .selected-record.ps1-mode {
  position: relative;
  border-style: dashed !important;
  border-color: #3d4a26 !important;
}

body.rotten .ps1-canvas {
  background:
    repeating-linear-gradient(180deg, rgba(120, 150, 90, 0.05) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.4) 0 2px, transparent 2px 5px),
    radial-gradient(ellipse at center, #0a0e07, #020302 80%);
}

.no-signal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #7fae54;
  font-size: clamp(18px, 4vw, 34px);
  letter-spacing: 8px;
  text-shadow: 0 0 14px rgba(127, 174, 84, 0.5), 3px 0 0 rgba(176, 52, 38, 0.4), -3px 0 0 rgba(60, 140, 190, 0.3);
  animation: nosig 3.4s steps(1) infinite;
  pointer-events: none;
}

.no-signal small {
  display: block;
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--d-rust);
}

@keyframes nosig {
  0%, 100% {
    opacity: 0.9;
    transform: translate(0, 0);
  }
  47% {
    opacity: 0.9;
  }
  48% {
    opacity: 0.2;
    transform: translate(-8px, 2px) skewX(6deg);
  }
  50% {
    opacity: 0.85;
    transform: translate(4px, -1px);
  }
  52% {
    transform: translate(0, 0);
  }
  78% {
    opacity: 0.55;
  }
}

body.rotten .ps1-floor-indicator {
  color: var(--d-amber);
}

body.rotten .ps1-track-info {
  color: #6d7c4e;
}

/* ─── 12. Model settings: the lab notes of an abandoned experiment ─────────── */
body.rotten .model-select-row select {
  border-style: dashed !important;
  background:
    var(--d-noise),
    #05070300 !important;
  background-color: #050703 !important;
}

body.rotten .model-select-row select option {
  background: #0a0d07;
  color: #9db377;
}

body.rotten .model-select-row select option.corrupt {
  color: var(--d-red);
}

body.rotten #searchInput {
  border-style: dashed !important;
  background:
    var(--d-noise),
    #05070300 !important;
  background-color: #050703 !important;
}

body.rotten #searchInput::placeholder {
  color: #55623c;
  animation: flicker-soft 6s infinite;
}

body.rotten #transformerStatus {
  color: var(--d-red);
  animation: flicker-soft 4.4s infinite;
}

body.rotten .model-chip {
  border-style: dotted !important;
  color: #55623c;
}

body.rotten .model-chip.dead {
  text-decoration: line-through;
  color: #4a5634;
}

body.rotten .model-chip.err {
  color: var(--d-red);
}

/* ─── 13. HUD: numbers you can't fully trust ─────────────────────────────── */
body.rotten .hud {
  border-style: dashed !important;
  border-color: #3d4a26 !important;
  background:
    var(--d-noise),
    rgba(4, 6, 3, 0.92) !important;
}

body.rotten .top-hud {
  transform: rotate(0.25deg);
}

body.rotten .bottom-hud {
  transform: rotate(-0.2deg);
}

body.rotten #hudTrack {
  color: #9db377;
}

body.rotten #hudHp {
  color: #c8b04a !important;
  animation: hp-flicker 3.2s steps(1) infinite;
}

@keyframes hp-flicker {
  0%, 100% {
    opacity: 1;
  }
  41% {
    opacity: 1;
  }
  42% {
    opacity: 0.15;
  }
  44% {
    opacity: 1;
  }
  70% {
    color: var(--d-red);
  }
  72% {
    color: #c8b04a;
  }
}

body.rotten #hudScore {
  color: var(--d-amber);
}

body.rotten #progressFill {
  background:
    repeating-linear-gradient(90deg,
      #7fae54 0 16px,
      transparent 16px 21px,
      #7fae54 21px 24px,
      transparent 24px 38px) !important;
  animation: bar-jitter 1.4s steps(2) infinite;
}

@keyframes bar-jitter {
  0%, 100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(-1px);
  }
}

body.rotten .time-readout {
  color: #55623c;
}

/* ─── 14. The loading screen that never finishes ───────────────────────────── */
body.rotten .loader {
  position: relative;
  transform: rotate(-0.6deg);
  border-style: dashed !important;
  border-color: #4a5a2e !important;
  background:
    var(--d-noise),
    #0a0d07 !important;
}

body.rotten .loader-heading {
  color: #a9c47e;
}

body.rotten #loadingText {
  color: #8a9a66;
  white-space: pre-wrap;
}

#loadingText .err {
  color: var(--d-red);
}

body.rotten #loaderFill {
  background: repeating-linear-gradient(90deg, #7fae54 0 8px, #17240e 8px 11px);
  transition: width 0.4s steps(4);
}

.loader-stuck-note {
  margin-top: 12px;
  color: var(--d-red);
  font-size: 11px;
  letter-spacing: 1px;
  animation: px-blink 1.3s steps(1) infinite;
}

/* ─── 15. Game stage: a frozen wreck behind the HUD ────────────────────────── */
body.rotten .game-stage {
  background:
    var(--d-noise),
    radial-gradient(ellipse 70% 60% at 50% 45%, rgba(40, 60, 26, 0.1), transparent 70%),
    #030402 !important;
}

body.rotten #gameCanvas {
  background:
    repeating-linear-gradient(0deg, rgba(90, 120, 60, 0.04) 0 1px, transparent 1px 46px),
    repeating-linear-gradient(90deg, rgba(90, 120, 60, 0.04) 0 1px, transparent 1px 46px),
    radial-gradient(circle 3px at 22% 31%, #000 0 3px, transparent 4px),
    radial-gradient(circle 2px at 71% 58%, #000 0 2px, transparent 3px),
    radial-gradient(circle 2px at 44% 77%, #000 0 2px, transparent 3px),
    radial-gradient(circle 4px at 63% 18%, #000 0 4px, transparent 5px);
}

.ghost-entity {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  transition: opacity 1.6s ease;
}

.ghost-player {
  left: 47%;
  top: 68%;
  width: 14px;
  height: 14px;
  background: rgba(134, 160, 106, 0.5);
  box-shadow: 0 0 10px rgba(134, 160, 106, 0.4);
  animation: ghost-breathe 2.6s ease-in-out infinite;
}

.ghost-enemy {
  left: 52%;
  top: 22%;
  width: 34px;
  height: 34px;
  background: rgba(176, 52, 38, 0.35);
  border: 1px dashed rgba(176, 52, 38, 0.5);
  transform: rotate(45deg);
  animation: ghost-breathe 4.1s ease-in-out infinite reverse;
}

.ghost-bullet {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(200, 153, 42, 0.4);
}

.ghost-bullet.b1 {
  left: 40%;
  top: 38%;
}

.ghost-bullet.b2 {
  left: 61%;
  top: 47%;
}

.ghost-bullet.b3 {
  left: 33%;
  top: 55%;
  background: rgba(134, 160, 106, 0.3);
}

.ghost-bullet.b4 {
  left: 66%;
  top: 30%;
  background: rgba(134, 160, 106, 0.3);
}

@keyframes ghost-breathe {
  0%, 100% {
    opacity: 0.75;
  }
  50% {
    opacity: 0.25;
  }
}

.stage-crack {
  position: absolute;
  z-index: 3;
  background: rgba(0, 0, 0, 0.8);
  box-shadow: 1px 1px 0 rgba(190, 230, 160, 0.08);
  pointer-events: none;
  transition: opacity 1.6s ease;
}

.stage-crack.k1 {
  left: 12%;
  top: 0;
  width: 2px;
  height: 26%;
  transform: rotate(18deg);
}

.stage-crack.k2 {
  right: 20%;
  bottom: 0;
  width: 2px;
  height: 34%;
  transform: rotate(-24deg);
}

/* ghosts and stage cracks dissolve during repair */
body.repairing .ghost-entity,
body.repairing .stage-crack,
body:not(.rotten) .ghost-entity,
body:not(.rotten) .stage-crack {
  opacity: 0 !important;
  animation: none !important;
}

/* ─── 16. Status ticker: the machine talking to itself ─────────────────────── */
.status-ticker {
  position: fixed;
  z-index: 94;
  top: 0;
  left: 0;
  right: 0;
  height: 22px;
  overflow: hidden;
  background: rgba(12, 8, 2, 0.92);
  border-bottom: 1px dashed rgba(160, 90, 34, 0.4);
  pointer-events: none;
  transition: transform 1.4s ease, opacity 1.4s ease;
}

.status-ticker span {
  position: absolute;
  top: 3px;
  left: 100%;
  white-space: nowrap;
  color: var(--d-rust);
  font-size: 11px;
  letter-spacing: 2px;
  animation: ticker-run 38s linear infinite;
}

@keyframes ticker-run {
  to {
    transform: translateX(calc(-100vw - 100%));
  }
}

body.repairing .status-ticker,
body:not(.rotten) .status-ticker {
  transform: translateY(-110%);
  opacity: 0;
}

/* ─── 17. View switching (our own, since the real brain is gone) ───────────── */
body.view-game .home-page {
  display: none;
}

body.view-game .game-stage {
  display: block;
}

.shake-hard {
  animation: shake-hard 0.4s steps(3) !important;
}

@keyframes shake-hard {
  0% {
    transform: translate(0, 0) rotate(0);
  }
  25% {
    transform: translate(-4px, 2px) rotate(-1deg);
  }
  50% {
    transform: translate(3px, -2px) rotate(1deg);
  }
  75% {
    transform: translate(-2px, 1px) rotate(-0.5deg);
  }
  100% {
    transform: translate(0, 0);
  }
}

/* ─── 17b. "The real view" toggle (live site, bottom right) ──────────────── */
.real-view-toggle {
  position: fixed;
  z-index: 96;
  right: 18px;
  bottom: 96px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 0;
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: lowercase;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  backdrop-filter: none;
}

body.rotten .real-view-toggle {
  border: 1px solid var(--d-rust) !important;
  background: rgba(12, 8, 3, 0.9) !important;
  color: var(--d-amber);
  text-shadow: 0 0 6px rgba(200, 153, 42, 0.4);
  animation: flicker-soft 5.2s infinite;
}

body:not(.rotten) .real-view-toggle {
  border: 1px solid var(--ps1-edge);
  background: rgba(6, 14, 12, 0.88);
  color: var(--ps1-cyan);
  text-shadow: none;
}

.real-view-toggle:hover {
  transform: none !important;
}

body.rotten .real-view-toggle:hover {
  border-color: #e8dca8 !important;
  color: #f2e8c8;
}

body:not(.rotten) .real-view-toggle:hover {
  border-color: var(--ps1-cyan);
  color: #d9f6ff;
  box-shadow: 0 0 12px rgba(116, 205, 221, 0.25);
}

.real-view-toggle {
  transition: opacity 0.6s ease, transform 0.6s ease;
}

/* in-game: present but quiet — dims to a whisper, wakes on hover */
body .real-view-toggle.rv-dimmed {
  opacity: 0.32;
  transform: scale(0.86);
  transform-origin: bottom right;
  animation: none;
}

body .real-view-toggle.rv-dimmed .rv-dot {
  animation: none;
}

.real-view-toggle.rv-dimmed:hover,
.real-view-toggle.rv-dimmed:focus-visible {
  opacity: 1;
  transform: scale(1);
}

/* when the game's UI button hides the HUD, the real-view toggle goes too */
body:has(.game-stage.ui-hidden) .real-view-toggle {
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

.real-view-toggle .rv-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 7px;
  border-radius: 50%;
  vertical-align: 1px;
}

body.rotten .real-view-toggle .rv-dot {
  background: var(--d-red);
  box-shadow: 0 0 6px rgba(176, 52, 38, 0.9);
  animation: px-blink 1.4s steps(1) infinite;
}

body:not(.rotten) .real-view-toggle .rv-dot {
  background: var(--ps1-green);
  box-shadow: 0 0 6px rgba(102, 231, 184, 0.7);
}

@media (max-width: 820px) {
  .real-view-toggle {
    right: 10px;
    bottom: 78px;
    padding: 0 10px;
    font-size: 10px;
  }
}

/* scrollbars, rotted */
body.rotten ::-webkit-scrollbar-track {
  background: #040503;
}

body.rotten ::-webkit-scrollbar-thumb {
  background: #2c3d1e;
  border: 1px dashed #16200e;
}

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