:root {
  /* Classic Atari brand */
  --fuji-red: #e01e2b;
  --fuji-red-deep: #b0141f;
  --black: #0a0a0a;
  --ink: #111111;
  --paper: #f2f0ea;
  --silver: #c8c8c8;
  --wood-light: #8b5a2b;
  --wood-mid: #5c3317;
  --wood-dark: #2a160c;
  --wood-grain: #3d2314;
  /* Jr / 5200 rainbow */
  --rb-1: #e31c23;
  --rb-2: #f7941d;
  --rb-3: #f7c948;
  --rb-4: #39b54a;
  --rb-5: #00aeef;
  --rb-6: #2e3192;
  --crt: #050505;
  --hud: #f2f0ea;
  --muted: #9a9088;
  --shadow: rgba(0, 0, 0, 0.65);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--black);
  color: var(--hud);
  font-family: "Silkscreen", monospace;
  overflow: hidden;
}

body {
  min-height: 100dvh;
}

.crt {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  min-height: 100dvh;
  height: 100dvh;
  background:
    linear-gradient(180deg, #1a0a0a 0%, var(--black) 40%, #0c0806 100%);
  isolation: isolate;
}

.scanlines,
.vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 40;
}

.scanlines {
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0, 0, 0, 0.22) 2px,
    rgba(0, 0, 0, 0.22) 4px
  );
  mix-blend-mode: multiply;
  opacity: 0.5;
  animation: flicker 7s steps(2) infinite;
}

.vignette {
  background: radial-gradient(ellipse at center, transparent 42%, rgba(0, 0, 0, 0.72) 100%);
}

@keyframes flicker {
  0%,
  97%,
  100% {
    opacity: 0.5;
  }
  98% {
    opacity: 0.3;
  }
  99% {
    opacity: 0.65;
  }
}

/* Fuji rainbow bar */
.rainbow {
  height: 6px;
  width: 100%;
  background: linear-gradient(
    90deg,
    var(--rb-1) 0%,
    var(--rb-1) 16.66%,
    var(--rb-2) 16.66%,
    var(--rb-2) 33.33%,
    var(--rb-3) 33.33%,
    var(--rb-3) 50%,
    var(--rb-4) 50%,
    var(--rb-4) 66.66%,
    var(--rb-5) 66.66%,
    var(--rb-5) 83.33%,
    var(--rb-6) 83.33%,
    var(--rb-6) 100%
  );
  z-index: 6;
}

/* HUD — console faceplate */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  z-index: 5;
  background:
    linear-gradient(180deg, #2a2a2a 0%, #141414 55%, #0c0c0c 100%);
  border-bottom: 1px solid #333;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.hud-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.fuji {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--fuji-red);
  filter: drop-shadow(0 0 6px rgba(224, 30, 43, 0.45));
}

.hud-logo {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.75rem, 2.2vw, 1.05rem);
  letter-spacing: 0.12em;
  color: var(--fuji-red);
  text-shadow: 2px 2px 0 #000;
}

.hud-chip {
  font-family: "Press Start 2P", monospace;
  font-size: 0.45rem;
  color: var(--paper);
  background: var(--ink);
  border: 1px solid var(--silver);
  padding: 0.3rem 0.45rem;
  letter-spacing: 0.15em;
}

.hud-stats {
  display: none;
  gap: 1.25rem;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--rb-3);
}

.hud-stats b {
  color: var(--paper);
  font-weight: 700;
}

@media (min-width: 720px) {
  .hud-stats {
    display: flex;
  }
}

.hud-music {
  font-family: "Press Start 2P", monospace;
  font-size: 0.42rem;
  line-height: 1.4;
  color: #fff;
  background: var(--fuji-red);
  border: 0;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  box-shadow: 3px 3px 0 #000;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.hud-music[aria-pressed="true"] {
  background: #333;
  color: var(--muted);
}

.hud-music:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #000;
}

/* Stage — woodgrain console bezel, canvas fills remaining space */
.stage-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 10px;
  min-height: 0;
  height: 100%;
  background:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 2px,
      rgba(0, 0, 0, 0.07) 2px,
      rgba(0, 0, 0, 0.07) 3px
    ),
    linear-gradient(
      180deg,
      var(--wood-light) 0%,
      var(--wood-mid) 35%,
      var(--wood-dark) 100%
    );
  box-shadow: inset 0 12px 24px rgba(0, 0, 0, 0.35);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--crt);
  border: 8px solid #1a1a1a;
  outline: 2px solid #0a0a0a;
  box-shadow:
    0 0 0 1px #444,
    inset 0 0 40px rgba(224, 30, 43, 0.05);
  touch-action: none;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
  text-align: center;
  max-width: calc(100% - 2rem);
}

.hint p {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.38rem, 1.3vw, 0.5rem);
  line-height: 1.7;
  color: var(--paper);
  background: rgba(0, 0, 0, 0.7);
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--fuji-red);
}

.hint.fade {
  opacity: 0;
  transition: opacity 0.6s ease;
}

/* Touch D-pad — joystick vibe */
.dpad {
  display: none;
  position: absolute;
  right: 0.75rem;
  bottom: 3.5rem;
  z-index: 7;
  width: 148px;
  height: 148px;
}

.dpad button {
  position: absolute;
  width: 44px;
  height: 44px;
  border: 2px solid #000;
  background: var(--fuji-red);
  color: #fff;
  font-size: 0.9rem;
  font-family: inherit;
  box-shadow: 2px 2px 0 #000;
  touch-action: manipulation;
  user-select: none;
}

.dpad button:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 #000;
}

.dpad [data-dir="left"] {
  left: 0;
  top: 52px;
}
.dpad [data-dir="right"] {
  right: 0;
  top: 52px;
}
.dpad [data-dir="up"] {
  left: 52px;
  top: 0;
}
.dpad [data-dir="down"] {
  left: 52px;
  bottom: 0;
}
.dpad .act {
  right: -4px;
  bottom: -4px;
  border-radius: 50%;
  background: var(--rb-3);
  color: #111;
  width: 48px;
  height: 48px;
  font-family: "Press Start 2P", monospace;
  font-size: 0.7rem;
}

@media (hover: none), (max-width: 820px) {
  .dpad {
    display: block;
  }
  .hint {
    bottom: 0.35rem;
  }
}

/* Ticker */
.ticker {
  overflow: hidden;
  background: var(--ink);
  padding: 0.45rem 0;
  z-index: 5;
}

.ticker-track {
  display: inline-block;
  white-space: nowrap;
  font-family: "Press Start 2P", monospace;
  font-size: 0.42rem;
  letter-spacing: 0.14em;
  color: var(--paper);
  animation: marquee 28s linear infinite;
  padding-left: 100%;
}

@keyframes marquee {
  to {
    transform: translateX(-100%);
  }
}

/* Boot */
.boot {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--black);
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

.boot::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 38%, rgba(224, 30, 43, 0.22), transparent 48%);
  pointer-events: none;
}

.boot.off {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  display: none;
}

.boot-inner {
  position: relative;
  text-align: center;
  padding: 1.5rem;
}

.boot-fuji {
  width: 72px;
  height: 72px;
  margin: 0 auto 1.25rem;
  color: var(--fuji-red);
  animation: boot-in 0.7s steps(4) both;
}

.boot-logo {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  font-size: clamp(1.5rem, 7vw, 3rem);
  color: var(--fuji-red);
  letter-spacing: 0.14em;
  text-shadow: 4px 4px 0 #000;
  animation: boot-in 0.8s steps(4) both;
}

.boot-sub {
  margin: 1rem 0 0.35rem;
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.5rem, 1.8vw, 0.7rem);
  color: var(--paper);
  letter-spacing: 0.35em;
}

.boot-rainbow {
  width: min(280px, 70vw);
  height: 5px;
  margin: 1rem auto 1.75rem;
  background: linear-gradient(
    90deg,
    var(--rb-1),
    var(--rb-2),
    var(--rb-3),
    var(--rb-4),
    var(--rb-5),
    var(--rb-6)
  );
}

.boot-blink {
  margin: 0 0 1.25rem;
  font-family: "Press Start 2P", monospace;
  font-size: 0.6rem;
  color: var(--rb-3);
  animation: blink 1s steps(1) infinite;
}

.boot-btn {
  font-family: "Press Start 2P", monospace;
  font-size: 0.7rem;
  padding: 0.9rem 1.4rem;
  border: 0;
  background: var(--fuji-red);
  color: #fff;
  cursor: pointer;
  box-shadow: 4px 4px 0 #000;
  letter-spacing: 0.08em;
}

.boot-btn:hover {
  background: var(--fuji-red-deep);
}

.boot-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #000;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes boot-in {
  from {
    letter-spacing: 0.4em;
    opacity: 0;
  }
  to {
    letter-spacing: 0.14em;
    opacity: 1;
  }
}

/* Panels — cartridge / aluminum plate */
.panel {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.78);
}

.panel.hidden {
  display: none;
}

.panel-frame {
  width: min(560px, 100%);
  max-height: min(85dvh, 720px);
  overflow: auto;
  background: linear-gradient(180deg, #1c1c1c 0%, #0e0e0e 100%);
  border: 4px solid var(--fuji-red);
  box-shadow:
    6px 6px 0 #000,
    0 0 0 1px #000;
  animation: panel-pop 0.2s steps(3);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 4px solid transparent;
  border-image: linear-gradient(
      90deg,
      var(--rb-1),
      var(--rb-2),
      var(--rb-3),
      var(--rb-4),
      var(--rb-5),
      var(--rb-6)
    )
    1;
  background: #141414;
}

.panel-head h2 {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.5rem, 2vw, 0.7rem);
  color: var(--paper);
  line-height: 1.5;
}

.panel-close {
  font-family: "Press Start 2P", monospace;
  font-size: 0.7rem;
  width: 2rem;
  height: 2rem;
  border: 2px solid #000;
  background: var(--fuji-red);
  color: #fff;
  cursor: pointer;
  box-shadow: 2px 2px 0 #000;
}

.panel-body {
  padding: 1rem 1.1rem 1.25rem;
  font-size: 0.95rem;
  line-height: 1.55;
}

.panel-body p {
  margin: 0 0 0.85rem;
}

.panel-body .lead {
  color: var(--fuji-red);
}

.panel-body .muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.panel-links {
  display: grid;
  gap: 0.55rem;
  margin: 1rem 0;
}

.panel-links a,
.chip-link {
  display: block;
  text-decoration: none;
  font-family: "Press Start 2P", monospace;
  font-size: 0.48rem;
  line-height: 1.6;
  padding: 0.75rem 0.85rem;
  color: #fff;
  background: var(--fuji-red);
  border: 2px solid #000;
  box-shadow: 3px 3px 0 #000;
  transition: transform 0.08s ease;
}

.panel-links a:nth-child(2) {
  background: var(--rb-6);
}
.panel-links a:nth-child(3) {
  background: var(--wood-mid);
}
.panel-links a:nth-child(4) {
  background: var(--rb-2);
  color: #111;
}
.panel-links a:nth-child(5) {
  background: var(--rb-4);
  color: #111;
}

.panel-links a:hover,
.chip-link:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 #000;
}

.embed {
  margin: 0.75rem 0 0;
  border: 3px solid #000;
  background: #000;
  overflow: hidden;
}

.embed iframe {
  display: block;
  width: 100%;
  border: 0;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.75rem 0 1rem;
}

.tag {
  font-family: "Press Start 2P", monospace;
  font-size: 0.38rem;
  padding: 0.4rem 0.5rem;
  border: 2px solid var(--fuji-red);
  color: var(--fuji-red);
}

@keyframes panel-pop {
  from {
    transform: scale(0.92);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scanlines,
  .ticker-track,
  .boot-blink,
  .boot-logo,
  .boot-fuji,
  .panel-frame {
    animation: none;
  }
}
