:root {
  color-scheme: dark;
  font-family: "Lucida Console", "Courier New", monospace;
  background: #010403;
  color: #83ffad;
  --screen: #020806;
  --panel: rgb(2 12 8 / 94%);
  --phosphor: #39ff88;
  --phosphor-bright: #c5ffd8;
  --phosphor-dim: #16834a;
  --phosphor-dark: #07351f;
  --amber: #ffc857;
}

* {
  box-sizing: border-box;
}

#app {
  display: contents;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

body {
  display: grid;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: clamp(10px, 2.5vh, 28px);
  overflow: hidden;
  place-items: center;
  background:
    radial-gradient(circle at 50% 42%, rgb(12 77 44 / 35%), transparent 48%),
    repeating-linear-gradient(90deg, rgb(57 255 136 / 2.5%) 0 1px, transparent 1px 72px),
    #010403;
}

body::before,
body::after {
  position: fixed;
  z-index: 10;
  inset: 0;
  pointer-events: none;
  content: "";
}

body::before {
  background: repeating-linear-gradient(
    0deg,
    rgb(0 0 0 / 12%) 0,
    rgb(0 0 0 / 12%) 1px,
    transparent 1px,
    transparent 4px
  );
}

body::after {
  background: radial-gradient(ellipse at center, transparent 52%, rgb(0 0 0 / 68%) 115%);
}

.game-shell {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: min(100%, 960px);
  height: 100%;
  gap: clamp(8px, 1.8vh, 16px);
  isolation: isolate;
}

.game-footer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px 24px;
  align-items: center;
  min-width: 0;
  padding: 8px 10px;
  border-block: 1px solid var(--phosphor-dark);
  background: rgb(1 9 6 / 78%);
  box-shadow: inset 0 0 24px rgb(57 255 136 / 3.5%);
}

.score {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--amber);
  font-size: clamp(24px, 4vw, 36px);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 0 10px rgb(255 200 87 / 60%);
}

.score::before {
  align-self: center;
  color: var(--phosphor-dim);
  content: "SCORE";
  font-size: 9px;
  letter-spacing: 0.12em;
  text-shadow: none;
  writing-mode: vertical-rl;
}

.score-divider {
  color: var(--phosphor-dim);
}

.game-stage {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  container-type: size;
  place-items: center;
}

.game-stage::after {
  position: absolute;
  z-index: 2;
  width: min(100cqw, calc(100cqh * 16 / 9));
  aspect-ratio: 16 / 9;
  pointer-events: none;
  content: "";
  background:
    repeating-linear-gradient(0deg, transparent 0 3px, rgb(0 0 0 / 13%) 3px 4px),
    linear-gradient(90deg, rgb(255 0 0 / 1.8%), transparent 20%, rgb(0 102 255 / 1.8%));
  box-shadow: inset 0 0 42px rgb(0 0 0 / 42%);
  contain: strict;
  transform: translateZ(0);
  animation: crt-flicker 6s steps(2, end) infinite;
}

canvas {
  display: block;
  width: min(100cqw, calc(100cqh * 16 / 9));
  height: auto;
  aspect-ratio: 16 / 9;
  border: 2px solid var(--phosphor-dim);
  border-radius: 0;
  background: var(--screen);
  box-shadow:
    0 0 0 1px #00190d,
    0 0 24px rgb(57 255 136 / 22%),
    0 20px 70px rgb(0 0 0 / 72%);
  image-rendering: pixelated;
}

.lobby {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  display: grid;
  width: min(520px, calc(100% - 40px));
  padding: clamp(22px, 4vw, 38px);
  border: 2px solid var(--phosphor);
  border-radius: 0;
  background: var(--panel);
  box-shadow:
    8px 8px 0 #001c0e,
    0 0 34px rgb(57 255 136 / 20%),
    inset 0 0 42px rgb(57 255 136 / 4.5%);
  text-align: left;
  transform: translate(-50%, -50%);
}

.lobby::before {
  margin: calc(clamp(22px, 4vw, 38px) * -1) calc(clamp(22px, 4vw, 38px) * -1) 22px;
  padding: 7px 10px;
  background: var(--phosphor);
  color: #001608;
  content: "C:\\PONG\\RUN.EXE  [ACTIVE]";
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.lobby[hidden],
.instructions [hidden] {
  display: none;
}

.lobby-kicker,
.lobby-copy,
.lobby h1 {
  margin: 0;
}

.lobby-kicker {
  color: var(--amber);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  text-shadow: 0 0 8px rgb(255 200 87 / 45%);
}

.lobby h1 {
  margin-top: 7px;
  color: var(--phosphor-bright);
  font-size: clamp(36px, 7vw, 64px);
  line-height: 1;
  letter-spacing: -0.08em;
  text-shadow:
    3px 0 0 var(--phosphor-dark),
    0 0 16px rgb(57 255 136 / 55%);
}

.lobby-copy {
  margin-top: 14px;
  color: var(--phosphor);
  font-size: 13px;
}

.lobby-copy::after {
  content: "_";
  animation: cursor-blink 0.8s steps(2, end) infinite;
}

.lobby-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 26px;
}

.theme-selector {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--phosphor-dark);
}

.theme-selector-label {
  display: block;
  margin-bottom: 8px;
  color: var(--phosphor-dim);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.theme-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

button {
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid var(--phosphor-dim);
  border-radius: 0;
  background: #010705;
  color: var(--phosphor-bright);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.035em;
  text-align: left;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: inset 0 0 16px rgb(57 255 136 / 3.5%);
}

button::before {
  color: var(--amber);
  content: "> ";
}

button:hover,
button:focus-visible {
  border-color: var(--phosphor-bright);
  background: var(--phosphor);
  color: #001608;
  outline: 1px solid var(--phosphor);
  outline-offset: 3px;
  box-shadow: 0 0 18px rgb(57 255 136 / 38%);
}

button:hover::before,
button:focus-visible::before {
  color: #001608;
}

.theme-options button {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 9px;
  text-align: center;
}

.theme-options button::before {
  content: "";
}

.theme-options button[aria-pressed="true"] {
  border-color: var(--phosphor);
  background: #002713;
  color: var(--phosphor-bright);
  box-shadow: inset 0 0 16px rgb(57 255 136 / 10%);
}

.theme-options button[aria-pressed="true"]::before {
  color: var(--phosphor);
  content: "● ";
}

.instructions {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px 18px;
  align-items: center;
  color: #68c98a;
  font-size: 10px;
  line-height: 1.4;
  text-transform: uppercase;
}

.control-group {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 16px;
  align-items: center;
}

.utility-controls {
  justify-content: flex-end;
}

.mode-label {
  color: var(--amber);
  font-weight: 700;
  text-shadow: 0 0 8px rgb(255 200 87 / 35%);
}

.mode-label::before {
  content: "MODE: ";
  color: var(--phosphor-dim);
}

kbd {
  display: inline-grid;
  min-width: 25px;
  min-height: 25px;
  margin-right: 3px;
  padding: 2px 6px;
  place-items: center;
  border: 1px solid var(--phosphor-dim);
  border-radius: 0;
  background: #00180c;
  color: var(--phosphor-bright);
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  box-shadow: 2px 2px 0 #000;
}

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

@keyframes crt-flicker {
  0%,
  96%,
  100% {
    opacity: 1;
  }

  97% {
    opacity: 0.96;
  }
}

@media (max-width: 600px) {
  body {
    padding: 10px;
  }

  .game-footer {
    grid-template-columns: auto;
  }

  .instructions {
    grid-template-columns: 1fr;
  }

  .utility-controls {
    justify-content: flex-start;
  }

  .lobby-actions {
    grid-template-columns: 1fr;
  }

  .theme-options {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-height: 560px) {
  body {
    padding-block: 7px;
  }

  .game-footer {
    padding-block: 5px;
  }

  .score {
    font-size: 22px;
  }

  .instructions {
    gap: 5px 12px;
    font-size: 9px;
  }

  .control-group {
    gap: 4px 10px;
  }

  kbd {
    min-width: 19px;
    min-height: 19px;
    padding: 1px 4px;
    font-size: 8px;
  }

  .lobby {
    width: min(500px, calc(100% - 18px));
    padding: 14px;
  }

  .lobby::before {
    margin: -14px -14px 12px;
    padding-block: 5px;
    font-size: 9px;
  }

  .lobby h1 {
    font-size: 34px;
  }

  .lobby-copy {
    margin-top: 5px;
    font-size: 10px;
  }

  .lobby-actions {
    margin-top: 11px;
  }

  .theme-selector {
    margin-top: 8px;
    padding-top: 7px;
  }

  button {
    min-height: 35px;
    padding: 6px 9px;
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-stage::after,
  .lobby-copy::after {
    animation: none;
  }
}
