:root {
  --bg: #07060f;
  --glow: #7b5bff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  font-family: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 700px at 50% -10%, #1b1140 0%, transparent 60%),
    radial-gradient(900px 600px at 10% 110%, #10233f 0%, transparent 60%),
    radial-gradient(900px 600px at 90% 110%, #3a0f2e 0%, transparent 60%),
    var(--bg);
}

#stage {
  position: relative;
  line-height: 0;
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, .08),
    0 0 60px rgba(123, 91, 255, .28),
    0 30px 90px rgba(0, 0, 0, .7);
}

#game {
  display: block;
  image-rendering: -webkit-optimize-contrast;
  background: #07060f;
  cursor: default;
}

/* subtle CRT scanlines + vignette */
#scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255, 255, 255, .035) 0px,
      rgba(255, 255, 255, .035) 1px,
      transparent 1px,
      transparent 3px
    ),
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, .45) 100%);
  mix-blend-mode: overlay;
}

@media (max-width: 700px) {
  #stage { border-radius: 0; }
}

/* Positioned/sized dynamically in js/main.js to sit exactly over the drawn
   share-link box; invisible until then. Text is transparent (canvas already
   draws the visible copy) but selection/caret still work normally. */
#linkOverlay {
  position: absolute;
  display: none;
  box-sizing: border-box;
  margin: 0;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font: 700 15px 'Trebuchet MS', system-ui, sans-serif;
  text-align: center;
}
#linkOverlay::selection { background: rgba(34, 224, 224, .35); }

/* Real, focusable overlay inputs for the canvas-drawn name/code text fields
   (js/ui/textinput.js). A canvas can never raise the mobile on-screen
   keyboard by itself — only a genuine focused <input> can — so each field
   is backed by one of these, positioned exactly over its drawn box each
   frame. Text stays transparent; the canvas already draws the visible copy. */
.field-overlay {
  position: absolute;
  z-index: 4;
  box-sizing: border-box;
  margin: 0;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  text-align: center;
  font: 900 30px 'Trebuchet MS', system-ui, sans-serif;
}

/* Always-visible "back" button (js/core/backnav.js), shown on every screen
   except the title screen. Doubles as the explicit affordance for touch
   users (no Escape key) and works identically to pressing Escape. */
#backBtn {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 6;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1.5px solid rgba(255, 255, 255, .28);
  background: rgba(20, 16, 40, .55);
  color: #fff;
  font: 900 18px 'Trebuchet MS', system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  backdrop-filter: blur(2px);
  cursor: pointer;
}
#backBtn:active { background: rgba(123, 91, 255, .55); border-color: #fff; }

/* On-screen touch controls (phones/tablets with no physical keyboard).
   Hidden by default; js/core/touchpad.js toggles data-kind based on the
   active screen + game. Only relevant sub-group is shown per kind.
   `position: fixed` (viewport-relative, not canvas-relative) so controls can
   be parked in the letterboxed margin beside/above/below the play canvas —
   js/core/touchpad.js computes exact left/top/scale every frame the canvas
   can move (resize, orientation change, or a kind toggle). */
#touchpad {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  display: none;
  font-family: 'Trebuchet MS', system-ui, sans-serif;
}
#touchpad[data-kind="game"],
#touchpad[data-kind="quiz"] {
  display: block;
}
#touchpad .tp-dpad,
#touchpad .tp-actions,
#touchpad .tp-quiz {
  display: none;
}
#touchpad[data-kind="game"] .tp-dpad,
#touchpad[data-kind="game"] .tp-actions {
  display: grid;
}
#touchpad[data-kind="quiz"] .tp-quiz {
  display: flex;
}

.tp-btn {
  pointer-events: auto;
  touch-action: none;
  border: 1.5px solid rgba(255, 255, 255, .28);
  background: rgba(20, 16, 40, .55);
  color: #fff;
  font: 900 20px 'Trebuchet MS', system-ui, sans-serif;
  border-radius: 14px;
  -webkit-user-select: none;
  user-select: none;
  backdrop-filter: blur(2px);
}
.tp-btn.active,
.tp-btn:active {
  background: rgba(123, 91, 255, .55);
  border-color: #fff;
}

/* left/top/transform are all set from JS (touchpad.js `place()`) — position
   here is just a placeholder until the first layout() call. */
.tp-dpad {
  position: fixed;
  width: 150px;
  height: 150px;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 4px;
}
.tp-up { grid-area: 1 / 2 / 2 / 3; }
.tp-left { grid-area: 2 / 1 / 3 / 2; }
.tp-right { grid-area: 2 / 3 / 3 / 4; }
.tp-down { grid-area: 3 / 2 / 4 / 3; }

.tp-actions {
  position: fixed;
  width: 140px;
  height: 140px;
}
.tp-actions .tp-btn {
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-size: 22px;
}
.tp-a { right: 0; bottom: 32px; }
.tp-b { right: 57px; bottom: 0; }

.tp-quiz {
  position: fixed;
  transform: translateX(-50%);
  gap: 12px;
}
.tp-quiz .tp-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  font-size: 22px;
}

.tp-pause {
  position: fixed;
  width: 40px;
  height: 40px;
  font-size: 16px;
  border-radius: 10px;
}
#touchpad[data-kind="game"] .tp-pause,
#touchpad[data-kind="quiz"] .tp-pause {
  display: block;
  pointer-events: auto;
}

