:root {
  color-scheme: dark;
  --arcade-bg: #020506;
  --arcade-panel: #070d0f;
  --arcade-panel-2: #0b1417;
  --arcade-ink: #e8f8f5;
  --arcade-muted: #78918f;
  --arcade-line: rgba(119, 222, 214, 0.28);
  --arcade-line-hard: rgba(145, 245, 235, 0.62);
  --arcade-primary: #8ff5e9;
  --arcade-secondary: #ffcf72;
  --arcade-danger: #ff7f93;
  --arcade-shadow: #000;
  --arcade-font: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--arcade-bg);
}

body.observatory-arcade,
body.gate-arcade {
  color: var(--arcade-ink);
  font-family: var(--arcade-font);
  background:
    linear-gradient(rgba(143, 245, 233, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(143, 245, 233, 0.025) 1px, transparent 1px),
    #020506;
  background-size: 32px 32px;
}

button,
a { -webkit-tap-highlight-color: transparent; }

button { font: inherit; }

.arcade-shell {
  position: fixed;
  inset: 0;
  isolation: isolate;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.65rem;
  padding:
    max(0.75rem, env(safe-area-inset-top))
    max(0.75rem, env(safe-area-inset-right))
    max(0.65rem, env(safe-area-inset-bottom))
    max(0.75rem, env(safe-area-inset-left));
}

.arcade-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent 0 49.9%, rgba(143, 245, 233, 0.035) 50%, transparent 50.1%),
    linear-gradient(0deg, transparent 0 49.9%, rgba(143, 245, 233, 0.025) 50%, transparent 50.1%);
}

.arcade-header,
.arcade-footer {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--arcade-line);
  background: rgba(4, 10, 12, 0.94);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.34);
}

.arcade-header { border-top-color: var(--arcade-line-hard); }

.arcade-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.arcade-title-wrap { min-width: 0; }

.arcade-title {
  margin: 0;
  overflow: hidden;
  color: var(--arcade-ink);
  font: 800 clamp(1rem, 2.4vw, 1.45rem)/1 var(--arcade-font);
  letter-spacing: 0.12em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.arcade-subtitle {
  margin: 0.32rem 0 0;
  overflow: hidden;
  color: var(--arcade-muted);
  font-size: 0.63rem;
  letter-spacing: 0.14em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.arcade-exit,
.arcade-action {
  min-height: 2.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0.55rem 0.72rem;
  border: 1px solid var(--arcade-line-hard);
  color: var(--arcade-primary);
  background: #071012;
  font: 800 0.65rem/1 var(--arcade-font);
  letter-spacing: 0.12em;
  text-decoration: none;
  text-transform: uppercase;
}

.arcade-exit:hover,
.arcade-exit:focus-visible,
.arcade-action:hover,
.arcade-action:focus-visible {
  color: #001311;
  background: var(--arcade-primary);
  outline: none;
}

.arcade-stats {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  gap: 0.45rem;
}

.arcade-chip {
  min-width: 5.4rem;
  display: grid;
  gap: 0.16rem;
  padding: 0.44rem 0.55rem;
  border-left: 2px solid var(--arcade-primary);
  background: rgba(143, 245, 233, 0.055);
}

.arcade-chip span {
  color: var(--arcade-muted);
  font-size: 0.53rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.arcade-chip strong {
  color: var(--arcade-primary);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
}

.arcade-screen-frame {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--arcade-line-hard);
  background: #000;
  box-shadow:
    inset 0 0 0 3px #03090a,
    inset 0 0 0 4px rgba(143, 245, 233, 0.13),
    0 16px 36px rgba(0, 0, 0, 0.52);
}

.arcade-screen-frame::before,
.arcade-screen-frame::after {
  content: "";
  position: absolute;
  z-index: 18;
  width: 2rem;
  height: 2rem;
  pointer-events: none;
}

.arcade-screen-frame::before {
  top: 0.6rem;
  left: 0.6rem;
  border-top: 2px solid var(--arcade-secondary);
  border-left: 2px solid var(--arcade-secondary);
}

.arcade-screen-frame::after {
  right: 0.6rem;
  bottom: 0.6rem;
  border-right: 2px solid var(--arcade-secondary);
  border-bottom: 2px solid var(--arcade-secondary);
}

.screen-scanlines {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  opacity: 0.18;
  background: repeating-linear-gradient(to bottom, transparent 0 3px, rgba(129, 255, 236, 0.14) 4px);
  mix-blend-mode: screen;
}

.screen-grid {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0.16;
  background:
    linear-gradient(rgba(143, 245, 233, 0.14) 1px, transparent 1px),
    linear-gradient(90deg, rgba(143, 245, 233, 0.14) 1px, transparent 1px);
  background-size: 12.5% 12.5%;
  mask-image: linear-gradient(to bottom, transparent, #000 18%, #000 82%, transparent);
}

.arcade-footer {
  min-height: 2.6rem;
  padding-block: 0.45rem;
  color: var(--arcade-muted);
  font-size: 0.58rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.arcade-footer strong { color: var(--arcade-secondary); }

.arcade-legend {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  white-space: nowrap;
}

.arcade-legend span { display: inline-flex; align-items: center; gap: 0.32rem; }

.arcade-key {
  min-width: 1.35rem;
  min-height: 1.35rem;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--arcade-line-hard);
  color: var(--arcade-primary);
  background: #071012;
  font-weight: 800;
}

/* Observatory */

.observatory-screen #view {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #000;
}

.observatory-screen canvas {
  display: block;
  width: 100%;
  height: 100%;
  filter: contrast(1.1) saturate(0.9);
}

#scope {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
}

#reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(34vmin, 17rem);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(143, 245, 233, 0.26);
}

#reticle::before,
#reticle::after {
  content: "";
  position: absolute;
  background: rgba(143, 245, 233, 0.34);
}

#reticle::before {
  left: 50%;
  top: -32%;
  bottom: -32%;
  width: 1px;
}

#reticle::after {
  top: 50%;
  left: -32%;
  right: -32%;
  height: 1px;
}

.tick { position: absolute; background: var(--arcade-secondary); }
.tick.t { top: -1px; left: 50%; width: 2px; height: 0.8rem; transform: translateX(-50%); }
.tick.b { bottom: -1px; left: 50%; width: 2px; height: 0.8rem; transform: translateX(-50%); }
.tick.l { top: 50%; left: -1px; width: 0.8rem; height: 2px; transform: translateY(-50%); }
.tick.r { top: 50%; right: -1px; width: 0.8rem; height: 2px; transform: translateY(-50%); }

#hud {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  z-index: 20;
  max-width: calc(100% - 2rem);
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--arcade-line);
  color: var(--arcade-primary);
  background: rgba(0, 7, 8, 0.9);
  font: 0.65rem/1.45 var(--arcade-font);
  white-space: pre-wrap;
}

#loading {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  color: var(--arcade-primary);
  background: #000;
  font: 800 0.68rem/1 var(--arcade-font);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  pointer-events: none;
}

.observatory-target {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  z-index: 16;
  width: min(30rem, calc(100% - 9rem));
  transform: translateX(-50%);
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--arcade-line);
  color: var(--arcade-muted);
  background: rgba(0, 7, 8, 0.86);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
  pointer-events: none;
}

.observatory-target strong { color: var(--arcade-primary); }

html[data-embed="1"] .arcade-header,
html[data-embed="1"] .arcade-footer,
html[data-embed="1"] #scope,
html[data-embed="1"] .observatory-target { display: none; }

html[data-embed="1"] .arcade-shell { padding: 0; }
html[data-embed="1"] .arcade-screen-frame { border: 0; box-shadow: none; }

/* Gate */

.gate-screen { min-height: 0; }

#gateStarfield {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #000;
}

#gateStarfield canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.gate-interface {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.55rem;
  padding: clamp(1rem, 2.8vw, 2rem);
}

.gate-screen-label {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--arcade-muted);
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.gate-screen-label strong { color: var(--arcade-secondary); }

.gate-grid {
  position: relative;
  place-self: center;
  width: min(68vmin, 36rem);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
}

.gate-filaments {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.gate-filaments canvas {
  width: 100%;
  height: 100%;
}

.gate-node {
  --node-size: clamp(2.85rem, 7vmin, 4.25rem);
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 4;
  width: var(--node-size);
  height: var(--node-size);
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  padding: 0;
  border: 1px solid rgba(143, 245, 233, 0.24);
  color: rgba(216, 235, 234, 0.25);
  background: rgba(2, 8, 10, 0.88);
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

.gate-node:hover,
.gate-node:focus-visible {
  color: var(--arcade-ink);
  border-color: var(--arcade-primary);
  transform: translate(-50%, -50%) scale(1.08);
  outline: none;
}

.gate-node.collected {
  color: var(--arcade-primary);
  border-color: var(--arcade-primary);
  background: rgba(7, 30, 30, 0.96);
  box-shadow: inset 0 0 0 2px rgba(143, 245, 233, 0.11), 0 0 18px rgba(143, 245, 233, 0.2);
}

.gate-node-index {
  position: absolute;
  right: 0.22rem;
  bottom: 0.16rem;
  color: var(--arcade-muted);
  font-size: 0.48rem;
  letter-spacing: 0;
}

.four-point-star {
  width: 62%;
  aspect-ratio: 1;
  display: block;
  background: currentColor;
  clip-path: polygon(50% 0, 59% 40%, 100% 50%, 59% 60%, 50% 100%, 41% 60%, 0 50%, 41% 40%);
}

.gate-node.twinkle .four-point-star { animation: gateTwinkle 2.7s steps(4, end) infinite; }

@keyframes gateTwinkle {
  0%, 100% { transform: scale(0.92); opacity: 0.82; }
  50% { transform: scale(1.08); opacity: 1; }
}

.gate-portal-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 8;
  width: clamp(7rem, 22vmin, 11rem);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
}

.gate-portal-wrap[hidden] { display: none; }

.gate-portal {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border: 2px solid var(--arcade-primary);
  border-radius: 50%;
  color: var(--arcade-ink);
  background:
    repeating-conic-gradient(from 0deg, rgba(143, 245, 233, 0.34) 0 8deg, transparent 8deg 18deg),
    #02090a;
  box-shadow: inset 0 0 0 8px #000, 0 0 24px rgba(143, 245, 233, 0.34);
  cursor: pointer;
  animation: portalSpin 9s linear infinite;
}

.gate-portal span {
  padding: 0.35rem 0.45rem;
  color: var(--arcade-primary);
  background: #000;
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

@keyframes portalSpin { to { transform: rotate(360deg); } }

.gate-console {
  width: min(42rem, 100%);
  justify-self: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem 1rem;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--arcade-line);
  background: rgba(2, 9, 10, 0.92);
}

.gate-hint {
  min-width: 0;
  color: var(--arcade-muted);
  font-size: clamp(0.62rem, 1.3vw, 0.72rem);
  line-height: 1.5;
}

.gate-hint strong {
  display: block;
  margin-bottom: 0.18rem;
  color: var(--arcade-primary);
  letter-spacing: 0.11em;
}

.gate-meter {
  min-width: 8.5rem;
  display: grid;
  grid-template-columns: minmax(5rem, 9rem) auto;
  gap: 0.55rem;
  align-items: center;
}

.gate-meter-track {
  height: 0.42rem;
  overflow: hidden;
  border: 1px solid var(--arcade-line);
  background: #020607;
}

.gate-meter-fill {
  width: 0;
  height: 100%;
  background: var(--arcade-primary);
  transition: width 420ms steps(7, end);
}

.gate-meter-count {
  color: var(--arcade-secondary);
  font-size: 0.68rem;
  font-weight: 900;
  white-space: nowrap;
}

.glitch-active { animation: arcadeGlitch 120ms steps(2, end) infinite; }

@keyframes arcadeGlitch {
  0% { transform: translate(0); filter: none; }
  33% { transform: translate(-2px, 1px); filter: hue-rotate(22deg); }
  66% { transform: translate(2px, -1px); filter: hue-rotate(-18deg); }
}

/* Dedicated 1999 arcade treatment */

html[data-mode="1999"] {
  --arcade-bg: #000066;
  --arcade-panel: #000;
  --arcade-panel-2: #000022;
  --arcade-ink: #fff;
  --arcade-muted: #00ffff;
  --arcade-line: #ff00ff;
  --arcade-line-hard: #ffff00;
  --arcade-primary: #00ffff;
  --arcade-secondary: #ffff00;
  --arcade-danger: #ff00ff;
}

html[data-mode="1999"][data-1999-palette="cyberspace_night"] {
  --arcade-bg: #000;
  --arcade-primary: #00ff66;
  --arcade-secondary: #00ffff;
  --arcade-line: #00ff66;
  --arcade-line-hard: #00ffff;
}

html[data-mode="1999"][data-1999-palette="purple_planet"] {
  --arcade-bg: #21004f;
  --arcade-primary: #ff9cff;
  --arcade-secondary: #9fffff;
  --arcade-line: #ff00ff;
  --arcade-line-hard: #9fffff;
}

html[data-mode="1999"][data-1999-palette="under_construction"] {
  --arcade-bg: #000;
  --arcade-primary: #ffff00;
  --arcade-secondary: #ff6600;
  --arcade-line: #ffff00;
  --arcade-line-hard: #ff6600;
}

html[data-mode="1999"],
html[data-mode="1999"] body,
html[data-mode="1999"] button,
html[data-mode="1999"] a {
  font-family: "Comic Sans MS", "Comic Sans", cursive !important;
}

html[data-mode="1999"] body.observatory-arcade,
html[data-mode="1999"] body.gate-arcade {
  background-color: var(--arcade-bg);
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.08) 25%, transparent 25% 75%, rgba(255, 255, 255, 0.08) 75%),
    linear-gradient(45deg, rgba(255, 255, 255, 0.08) 25%, transparent 25% 75%, rgba(255, 255, 255, 0.08) 75%);
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
}

html[data-mode="1999"] .arcade-shell {
  width: min(68rem, 100%);
  margin-inline: auto;
}

html[data-mode="1999"] .arcade-header,
html[data-mode="1999"] .arcade-footer,
html[data-mode="1999"] .gate-console {
  border: 3px ridge var(--arcade-line-hard);
  background: #000;
  box-shadow: 5px 5px 0 #000;
}

html[data-mode="1999"] .arcade-title {
  color: var(--arcade-secondary);
  text-shadow: 2px 2px 0 #ff00ff;
}

html[data-mode="1999"] .arcade-subtitle,
html[data-mode="1999"] .arcade-footer { color: var(--arcade-primary); }

html[data-mode="1999"] .arcade-screen-frame {
  border: 5px ridge var(--arcade-line-hard);
  box-shadow: 8px 8px 0 #000;
}

html[data-mode="1999"] .arcade-screen-frame::before,
html[data-mode="1999"] .arcade-screen-frame::after { border-color: #ff00ff; }

html[data-mode="1999"] .screen-scanlines {
  opacity: 0.34;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 255, 255, 0.18) 3px 4px);
}

html[data-mode="1999"] .observatory-screen canvas,
html[data-mode="1999"] #gateStarfield canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

html[data-mode="1999"] .arcade-chip,
html[data-mode="1999"] .arcade-exit,
html[data-mode="1999"] .arcade-key,
html[data-mode="1999"] .gate-node {
  border: 2px outset var(--arcade-line-hard);
  border-radius: 0;
}

html[data-mode="1999"] .gate-node.collected {
  color: var(--arcade-secondary);
  background: #000080;
  box-shadow: 3px 3px 0 #000;
}

html[data-mode="1999"] .gate-meter-fill { background: repeating-linear-gradient(90deg, var(--arcade-primary) 0 8px, var(--arcade-secondary) 8px 16px); }

@media (max-width: 720px) {
  .arcade-shell { gap: 0.42rem; padding: max(0.45rem, env(safe-area-inset-top)) max(0.45rem, env(safe-area-inset-right)) max(0.42rem, env(safe-area-inset-bottom)) max(0.45rem, env(safe-area-inset-left)); }
  .arcade-header { padding: 0.42rem 0.48rem; }
  .arcade-brand { gap: 0.45rem; }
  .arcade-exit { min-height: 2.35rem; padding-inline: 0.58rem; }
  .arcade-title { font-size: 0.93rem; letter-spacing: 0.08em; }
  .arcade-subtitle { font-size: 0.54rem; letter-spacing: 0.08em; }
  .arcade-chip { min-width: 4.25rem; padding: 0.34rem 0.42rem; }
  .arcade-chip:nth-child(n+3) { display: none; }
  .arcade-chip strong { font-size: 0.64rem; }
  .arcade-footer { justify-content: center; text-align: center; }
  .arcade-footer > span:last-child { display: none; }
  .arcade-legend { gap: 0.48rem; white-space: normal; }
  .arcade-key { min-width: 1.15rem; min-height: 1.15rem; }
  #reticle { width: min(44vmin, 11rem); }
  .observatory-target { left: 0.65rem; right: 0.65rem; bottom: 0.65rem; width: auto; transform: none; }
  #hud { display: none !important; }
  .gate-interface { padding: 0.75rem; gap: 0.35rem; }
  .gate-screen-label { padding-inline: 0.25rem; }
  .gate-grid { width: min(88vw, 52svh, 31rem); }
  .gate-node { --node-size: clamp(2.7rem, 12vw, 3.55rem); }
  .gate-console { padding: 0.55rem 0.62rem; gap: 0.5rem; }
  .gate-hint { font-size: 0.59rem; }
  .gate-meter { min-width: 6.7rem; grid-template-columns: minmax(3.8rem, 1fr) auto; }
}

@media (max-width: 460px) {
  .arcade-chip:nth-child(n+2) { display: none; }
  .arcade-exit { font-size: 0.58rem; }
  .gate-console { grid-template-columns: 1fr; }
  .gate-meter { width: 100%; grid-template-columns: 1fr auto; }
  .gate-screen-label span:last-child { display: none; }
}

@media (max-height: 650px) {
  .arcade-shell { gap: 0.32rem; padding-block: max(0.32rem, env(safe-area-inset-top)) max(0.32rem, env(safe-area-inset-bottom)); }
  .arcade-header,
  .arcade-footer { min-height: 0; }
  .arcade-footer { display: none; }
  .arcade-subtitle { display: none; }
  .gate-interface { padding-block: 0.55rem; }
  .gate-grid { width: min(76vw, 61svh, 31rem); }
}

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