@font-face {
  font-family: 'Lilita One';
  src: url('../assets/fonts/LilitaOne-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #07060f;
  --glow: #7b5bff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

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

button {
  font-family: inherit;
}

#nameContinueBtn {
  position: absolute;
  z-index: 5;
  display: none;
  margin: 0;
  border: 1.5px solid rgba(255, 255, 255, .65);
  border-radius: 14px;
  background: linear-gradient(180deg, #7ff3f3, #22e0e0 55%, #12a9b0);
  color: #0b1830;
  font: 900 20px 'Trebuchet MS', system-ui, sans-serif;
  letter-spacing: 1.5px;
  box-shadow: inset 0 1px rgba(255, 255, 255, .5), 0 0 26px rgba(34, 224, 224, .38);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .15s ease, box-shadow .15s ease;
}

#nameContinueBtn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: inset 0 1px rgba(255, 255, 255, .55), 0 0 36px rgba(34, 224, 224, .6);
}

#nameContinueBtn:disabled {
  border-color: rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .08);
  color: #8f88bd;
  box-shadow: none;
  cursor: default;
}

#nameContinueBtn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

#networkBlockedDialog, #relayVerificationDialog {
  width: min(440px, calc(100vw - 32px));
  padding: 26px 24px 22px;
  border: 1px solid rgba(255, 77, 109, .72);
  border-radius: 18px;
  background: linear-gradient(180deg, #201331, #0d0918);
  color: #fff;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .72), 0 0 30px rgba(255, 77, 109, .2);
}

#networkBlockedDialog::backdrop, #relayVerificationDialog::backdrop {
  background: rgba(3, 2, 9, .82);
  backdrop-filter: blur(4px);
}

#networkBlockedDialog h2, #relayVerificationDialog h2 {
  margin: 10px 0 12px;
  color: #ff6b82;
  font-size: clamp(20px, 6vw, 28px);
  line-height: 1.15;
}

#networkBlockedDialog p, #relayVerificationDialog p {
  margin: 0 auto 22px;
  color: #d4cfee;
  font-size: 16px;
  line-height: 1.5;
}

#networkBlockedDialog button, #relayVerificationDialog button {
  min-width: 120px;
  min-height: 48px;
  border: 1px solid #fff;
  border-radius: 12px;
  background: #7b5bff;
  color: #fff;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}

#networkBlockedDialog .network-diagnostics {
  margin: -4px auto 18px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

#networkBlockedDialog #networkDiagnosticCopy {
  margin-right: 8px;
  background: #312749;
}

.network-dialog-icon {
  width: 46px;
  height: 46px;
  margin: 0 auto;
  border: 2px solid #ff6b82;
  border-radius: 50%;
  color: #ff6b82;
  font-size: 30px;
  font-weight: 900;
  line-height: 42px;
}

#relayVerificationDialog { max-height: calc(100dvh - 24px); overflow: auto; }
#relayVerificationDialog > div { display: flex; justify-content: center; margin-bottom: 16px; }
#relayVerificationDialog button { display: block; width: 100%; margin-top: 10px; }
#relayVerificationDialog button[hidden] { display: none; }
#relayVerificationDialog p:last-child { margin: 16px 0 0; font-size: 13px; }

body {
  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;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  line-height: 0;
  overflow: hidden;
  background: var(--bg);
}

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

#game {
  display: block;
  image-rendering: auto;
  background: #07060f;
  cursor: default;
  touch-action: none;
}

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

#stage[data-game="artillery"][data-screen="play"] #scanlines {
  background: radial-gradient(ellipse at center, transparent 66%, rgba(6, 13, 28, .19) 100%);
  mix-blend-mode: normal;
}

#orientationHint {
  display: none;
}

#home {
  --home-accent: #ff4d6d;
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  padding: max(64px, calc(var(--safe-top) + 56px)) max(12px, calc(var(--safe-right) + 8px)) max(8px, calc(var(--safe-bottom) + 8px)) max(12px, calc(var(--safe-left) + 8px));
  color: #fff;
  line-height: 1.4;
  background:
    radial-gradient(ellipse at 50% 8%, rgba(93, 51, 168, .32), transparent 52%),
    radial-gradient(ellipse at 12% 92%, rgba(34, 224, 224, .1), transparent 45%),
    rgba(7, 6, 15, .9);
  overscroll-behavior: contain;
  touch-action: manipulation;
}

#home[hidden] { display: none; }
.home-content {
  width: min(100%, 155dvh, 3000px);
  height: 100%;
  min-height: 0;
  margin: auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: clamp(6px, 1.4dvh, 24px);
}
.home-header { position: relative; width: fit-content; max-width: 100%; margin: 0 auto; text-align: center; }
#homeTitle {
  margin: 0;
  font: 400 clamp(28px, 5.8dvh, 120px)/.86 'Lilita One', sans-serif;
  letter-spacing: 4px;
  filter: drop-shadow(0 5px #24124b) drop-shadow(0 0 20px rgba(123, 91, 255, .25));
}
#homeTitle span { display: block; }
#homeTitle span:first-child {
  background: linear-gradient(#fff, #c9b8ff);
  color: #ddd0ff;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
#homeTitle span:last-child {
  margin-top: 4px;
  background: linear-gradient(#fff09a, #ffb627 55%, #ff5f3c);
  color: #ffb627;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.home-beta {
  position: absolute;
  top: 40%;
  right: -36px;
  padding: 4px 9px;
  border: 2px solid #fff;
  border-radius: 7px;
  background: #ff4d6d;
  font: 400 13px 'Lilita One', sans-serif;
  letter-spacing: 1px;
  transform: rotate(-12deg);
}
.home-header > p { margin: 8px 0 0; font-weight: 900; font-size: clamp(12px, 1.8dvh, 28px); }
.home-header .home-intro { margin-top: 4px; color: #c5bfe6; font-size: clamp(11px, 1.2dvh, 20px); font-weight: 400; }
#homeGames { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: clamp(4px, 1vw, 20px); min-height: 0; }
.home-game {
  position: relative;
  min-width: 0;
  min-height: 44px;
  padding: clamp(4px, .8dvh, 14px) 4px;
  border: 1px solid #443359;
  border-radius: 16px;
  background: linear-gradient(155deg, #241738, #100d20);
  color: #c9c2ea;
  cursor: pointer;
  transition: border-color .18s, transform .18s, box-shadow .18s;
}
.home-game[aria-selected="true"] {
  border-color: var(--game-accent);
  color: #fff;
  transform: translateY(-4px);
  box-shadow: 0 0 18px color-mix(in srgb, var(--game-accent) 20%, transparent);
}
.home-game:hover { border-color: var(--game-accent); }
.home-game img { display: block; width: min(100%, clamp(30px, 7.5dvh, 190px)); height: auto; margin: auto; }
.home-game-name { display: block; font: 400 clamp(11px, 1.8dvh, 34px)/1.1 'Lilita One', sans-serif; overflow-wrap: anywhere; }
.home-game-number { position: absolute; top: 6px; left: 7px; color: var(--game-accent); font-size: 10px; font-weight: 900; }
#homeDescription {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 0;
  align-items: center;
  gap: clamp(10px, 2vw, 40px);
  padding: clamp(10px, 1.4dvh, 28px);
  border: 1px solid var(--home-accent);
  border-radius: 22px;
  background: linear-gradient(135deg, #20162e, #100c20 70%);
  box-shadow: 0 12px 48px #0005;
}
#homeDescription::before {
  content: '';
  position: absolute;
  top: -9px;
  left: calc(var(--notch-position, 10%) - 9px);
  width: 16px;
  height: 16px;
  border-left: 1px solid var(--home-accent);
  border-top: 1px solid var(--home-accent);
  background: #20162e;
  transform: rotate(45deg);
}
.home-preview {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid #ffffff28;
  border-radius: 14px;
  background: #090817;
}
#homePreview { display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain; background: #090817; }
.home-preview-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  font-size: clamp(11px, 1.4dvh, 24px);
  line-height: 1.2;
  border-top: 1px solid #ffffff1a;
}
#homePreviewHook { color: #fff; font-size: clamp(11px, 1.4dvh, 24px); font-weight: 900; }
#homePreviewToggle {
  flex-shrink: 0;
  min-width: 60px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #ffffff40;
  border-radius: 9px;
  background: #292039;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
#homePreviewCaption { margin: 2px 0 0; color: #aca4c9; font-size: clamp(9px, 1.1dvh, 18px); }
.home-details { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: clamp(6px, 1.2dvh, 22px); }
.home-detail-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
#homeGenre { margin: 0; color: var(--home-accent); font-size: clamp(10px, 1.3dvh, 22px); font-weight: 900; letter-spacing: 1px; }
#homeBadge { padding: 4px 8px; border-radius: 20px; background: #ffc53124; color: #ffc531; font-size: 10px; font-weight: 900; }
#homeBadge[hidden] { display: none; }
#homeGameTitle { margin: 0; font: 400 clamp(22px, 4dvh, 86px)/1.05 'Lilita One', sans-serif; overflow-wrap: anywhere; }
#homeTagline { margin: 0; color: #eee8ff; font-size: clamp(13px, 1.8dvh, 34px); font-weight: 700; }
.home-actions { display: grid; grid-template-columns: auto auto minmax(0, 1fr); align-items: stretch; gap: 8px; }
#homeRules { min-height: 44px; padding: 8px 12px; border: 1px solid #ffffff40; border-radius: 10px; background: #292039; color: #eee8ff; font-size: clamp(12px, 1.5dvh, 26px); cursor: pointer; }
#homeFacts { display: flex; flex-wrap: wrap; gap: 4px; }
#homeFacts span { padding: 5px 7px; border-radius: 8px; background: #ffffff0b; color: #dcd5f5; font-size: clamp(9px, 1.1dvh, 19px); font-weight: 900; }
#homePlay {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #ffffff80;
  border-radius: 12px;
  background: var(--home-accent);
  color: #0f0920;
  box-shadow: inset 0 1px #ffffff66, 0 4px 0 #0004;
  font: 400 clamp(14px, 2.2dvh, 42px) 'Lilita One', sans-serif;
  letter-spacing: .3px;
  cursor: pointer;
}
#homePlay:hover { filter: brightness(1.12); }
#home button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.home-footer { text-align: center; color: #958bad; font-size: clamp(10px, 1.1dvh, 20px); }
.home-footer p { margin: 0; }
.home-footer p:last-child { margin-top: 3px; font-size: clamp(9px, 1dvh, 18px); letter-spacing: .5px; }
.home-footer span { margin-left: 8px; }

@media (orientation: portrait) {
  #homeDescription { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 10px; }
  .home-details { gap: 7px; }
  .home-header .home-intro, .home-footer span { display: none; }
}

@media (max-width: 700px) {
  .home-beta { right: -20px; top: 35%; padding: 3px 6px; font-size: 10px; }
  .home-game { border-radius: 10px; }
  .home-game-number { top: 4px; left: 4px; font-size: 9px; }
  #homeDescription { border-radius: 16px; }
  #homeRules { padding: 6px 8px; }
  #homePreviewToggle { min-width: 44px; max-width: 64px; padding: 4px; font-size: 10px; }
  #homeGameTitle { font-size: clamp(22px, 3.5dvh, 30px); }
  #homeTagline { font-size: 13px; }
  #homeBadge { font-size: 9px; padding: 3px 6px; }
}

@media (max-height: 700px) and (orientation: portrait) {
  .home-content { gap: 6px; }
  #homeTitle { font-size: clamp(24px, 5dvh, 32px); letter-spacing: 2px; }
  #homeTitle span { display: inline; }
  #homeTitle span:last-child { margin-left: 6px; }
  .home-header > p, .home-beta { display: none; }
  .home-game img { width: min(100%, 32px); }
  .home-game-name { font-size: 10px; }
  #homeDescription { padding: 8px; gap: 6px; }
  .home-details { gap: 5px; }
  #homeFacts span { padding: 3px 5px; font-size: 9px; line-height: 1.2; }
  #homeBadge { padding: 2px 5px; }
  #homePlay { padding: 4px; }
  .home-footer p:first-child { font-size: 9px; }
  .home-footer p:last-child { font-size: 8px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .home-content { grid-template-columns: clamp(112px, 16vw, 150px) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; gap: 6px 10px; width: 100%; }
  .home-header { grid-column: 1; grid-row: 1; }
  #homeTitle { font-size: 24px; letter-spacing: 2px; }
  .home-header > p, .home-beta { display: none; }
  #homeGames { grid-column: 1; grid-row: 2; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(44px, 1fr)); gap: 4px; }
  .home-game { padding: 3px; border-radius: 8px; }
  .home-game img { width: 30px; }
  .home-game-name { font-size: 10px; }
  .home-game-number { top: 3px; left: 3px; font-size: 8px; }
  #homeDescription { grid-column: 2; grid-row: 1 / 3; padding: 8px; gap: 8px; border-radius: 14px; }
  .home-details { gap: 5px; }
  #homeGameTitle { font-size: 22px; }
  #homeGenre { font-size: 9px; }
  #homeTagline { font-size: 12px; }
  #homeBadge { font-size: 8px; padding: 3px; }
  #homeFacts span { font-size: 8px; padding: 4px; }
  .home-actions { gap: 4px; }
  #homeRules { font-size: 11px; padding: 4px; }
  #homePlay { font-size: 12px; padding: 4px; }
  .home-preview-top { gap: 4px; padding: 4px; }
  #homePreviewHook { font-size: 10px; }
  #homePreviewCaption { font-size: 8px; }
  #homePreviewToggle { min-width: 44px; font-size: 10px; padding: 4px; }
  .home-footer { grid-column: 1 / -1; grid-row: 3; }
  .home-footer span { display: none; }
  .home-footer p:last-child { font-size: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .home-game { transition: none; }
}

#homeRulesDialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom));
  padding: 20px;
  border: 1px solid #9c7fff;
  border-radius: 18px;
  background: #171127;
  color: #fff;
}
#homeRulesDialog::backdrop { background: #030209db; backdrop-filter: blur(5px); }
.home-rules-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#homeRulesTitle { margin: 0; font-size: 23px; }
#homeRulesClose { flex-shrink: 0; width: 44px; height: 44px; border: 1px solid #77709f; border-radius: 10px; background: #292039; color: #fff; font-size: 26px; cursor: pointer; }
#homeGameDescription { margin: 12px 0 0; color: #d5cdec; font-size: 14px; line-height: 1.5; }
#homeRulesDialog button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

@media (orientation: portrait) {
  #stage {
    background:
      radial-gradient(ellipse at 20% 82%, rgba(34, 224, 224, .12), transparent 42%),
      radial-gradient(ellipse at 82% 86%, rgba(255, 77, 109, .13), transparent 42%),
      linear-gradient(180deg, #0d0920, #07060f 58%, #10091b);
  }

  #stage::before {
    content: '';
    position: absolute;
    z-index: 0;
    left: max(10px, var(--safe-left));
    right: max(10px, var(--safe-right));
    top: calc(var(--safe-top) + var(--canvas-height, 244px) + 18px);
    bottom: max(10px, var(--safe-bottom));
    display: none;
    border: 1px solid rgba(123, 91, 255, .2);
    border-radius: 26px;
    background: linear-gradient(180deg, rgba(24, 17, 51, .5), rgba(11, 9, 25, .72));
    box-shadow: inset 0 1px rgba(255, 255, 255, .04);
  }

  #stage[data-screen="play"]:not([data-portrait-full="true"])::before {
    display: block;
  }

  #stage[data-screen="play"]:not([data-portrait-full="true"]) #orientationHint {
    display: block;
    position: absolute;
    z-index: 3;
    top: calc(var(--safe-top) + var(--canvas-height, 244px) + 12px);
    left: max(18px, var(--safe-left));
    right: max(18px, var(--safe-right));
    margin: 0;
    color: #e8e2ff;
    font-size: 14px;
    font-weight: 900;
    line-height: 1.4;
    text-align: center;
    pointer-events: none;
  }

  #game {
    position: absolute;
    z-index: 1;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    border-radius: 12px;
    box-shadow: 0 10px 34px rgba(0, 0, 0, .48);
  }

  #stage[data-portrait-full="true"] #game {
    left: 0;
    top: 0;
    transform: none;
    border-radius: 0;
    box-shadow: none;
  }

  #stage[data-screen="play"]:not([data-portrait-full="true"]) #game {
    top: max(6px, var(--safe-top));
    transform: translateX(-50%);
    border-radius: 0 0 12px 12px;
  }

  #stage #triviaCategorySelect {
    padding-right: 24px;
    padding-left: 8px;
    border-radius: 7px;
  }

  #scanlines {
    z-index: 2;
    border-radius: inherit;
  }
}

/* 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;
  z-index: 4;
  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); }

#triviaCategorySelect {
  position: absolute;
  z-index: 5;
  display: none;
  box-sizing: border-box;
  margin: 0;
  padding: 0 38px 0 16px;
  border: 1.5px solid rgba(34, 224, 224, .65);
  border-radius: 10px;
  background: rgba(20, 16, 48, .96);
  color: #fff;
  font: 900 16px 'Trebuchet MS', system-ui, sans-serif;
  text-align: center;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(34, 224, 224, .16);
}
#triviaCategorySelect:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
#triviaCategorySelect:disabled {
  cursor: default;
  color: #c5bfe6;
  opacity: .82;
}

/* 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;
}

.field-overlay:focus {
  outline: none;
}

/* Navigation remains available to mouse, keyboard and touch users. Root
   controls are disabled; leaving a live match keeps its confirmation flow. */
#backBtn,
#closeBtn {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 6;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(200, 185, 255, .28);
  background: linear-gradient(180deg, rgba(48, 38, 92, .72), rgba(18, 14, 38, .78));
  color: #fff;
  font: 900 18px 'Trebuchet MS', system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: inset 0 1px rgba(255, 255, 255, .12), 0 6px 18px rgba(0, 0, 0, .35);
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
#backBtn:hover:not(:disabled),
#closeBtn:hover:not(:disabled),
#muteBtn:hover {
  border-color: rgba(200, 185, 255, .7);
  box-shadow: inset 0 1px rgba(255, 255, 255, .18), 0 0 18px rgba(123, 91, 255, .45), 0 8px 20px rgba(0, 0, 0, .4);
}
#closeBtn {
  left: auto;
  right: max(12px, env(safe-area-inset-right));
  font-size: 28px;
}
#backBtn:active,
#closeBtn:active { background: rgba(123, 91, 255, .55); border-color: #fff; }
#backBtn:disabled,
#closeBtn:disabled { opacity: .3; cursor: default; }

#muteBtn {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(68px, calc(env(safe-area-inset-right) + 56px));
  z-index: 6;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(200, 185, 255, .28);
  background: linear-gradient(180deg, rgba(48, 38, 92, .72), rgba(18, 14, 38, .78));
  color: #fff;
  font-size: 20px;
  line-height: 1;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: inset 0 1px rgba(255, 255, 255, .12), 0 6px 18px rgba(0, 0, 0, .35);
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease;
}

#muteBtn[aria-pressed="true"] {
  color: #ff4d6d;
  border-color: rgba(255, 77, 109, .75);
}

#comingSoonBtn {
  position: absolute;
  right: max(20px, calc(var(--safe-right) + 12px));
  bottom: max(20px, calc(var(--safe-bottom) + 12px));
  z-index: 6;
  isolation: isolate;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: #c1fff5;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

#comingSoonBtn::before {
  content: '';
  position: absolute;
  inset: -1px;
  z-index: -1;
  border: 1px solid rgba(53, 230, 208, .65);
  border-radius: inherit;
  background: rgba(14, 25, 39, .95);
  box-shadow: 0 0 20px rgba(53, 230, 208, .14);
  animation: coming-soon-breathe 4s ease-in-out infinite;
  pointer-events: none;
}

#comingSoonBtn[hidden] { display: none; }
#comingSoonBtn:hover::before,
#comingSoonBtn:focus-visible::before {
  animation-play-state: paused;
  border-color: #c1fff5;
  box-shadow: 0 0 26px rgba(53, 230, 208, .4);
}
#comingSoonBtn:focus-visible,
#comingSoonDialog button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

@keyframes coming-soon-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

#comingSoonDialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom));
  overflow-y: auto;
  padding: 26px;
  border: 1px solid rgba(53, 230, 208, .45);
  border-radius: 24px;
  background: linear-gradient(145deg, #16132d, #090d1c);
  color: #fff;
  line-height: 1.5;
  box-shadow: 0 24px 90px rgba(0, 0, 0, .7);
}

#comingSoonDialog::backdrop {
  background: rgba(3, 2, 9, .82);
  backdrop-filter: blur(5px);
}

.coming-soon-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.coming-soon-eyebrow { margin: 0 0 4px; color: #35e6d0; font-size: 11px; font-weight: 900; letter-spacing: 2px; }
#comingSoonTitle { margin: 0; font-size: 30px; }
#comingSoonClose {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 1px solid #77709f;
  border-radius: 12px;
  background: #211a38;
  color: #fff;
  font-size: 28px;
  cursor: pointer;
}
#comingSoonIntro { margin: 18px 0 22px; color: #bdb6db; font-size: 15px; }
.upcoming-game { padding: 22px; border: 1px solid #584278; border-radius: 18px; background: rgba(123, 91, 255, .1); }
.upcoming-game + .upcoming-game { margin-top: 16px; }
.upcoming-status { display: inline-block; color: #d8c7ff; font-size: 10px; font-weight: 900; letter-spacing: 1.5px; }
.upcoming-game h3 { margin: 12px 0 8px; color: #f4edff; font-size: 23px; }
.upcoming-game p { margin: 0; font-size: 15px; }
.upcoming-game .upcoming-details { margin-top: 12px; color: #bdb6db; font-size: 13px; }
.coming-soon-footer { margin: 20px 0 0; color: #9990bd; font-size: 12px; text-align: center; }

@media (orientation: portrait) {
  #comingSoonBtn {
    top: max(12px, var(--safe-top));
    right: max(124px, calc(var(--safe-right) + 112px));
    bottom: auto;
    padding: 0 12px;
    font-size: 12px;
  }
  #comingSoonDialog {
    margin: auto 8px max(8px, var(--safe-bottom));
    width: calc(100vw - 16px);
    padding: 24px 20px;
    border-radius: 24px 24px 16px 16px;
  }
}

@media (orientation: portrait) and (max-height: 740px) {
  #comingSoonBtn {
    top: auto;
    right: max(16px, calc(var(--safe-right) + 12px));
    bottom: max(16px, calc(var(--safe-bottom) + 12px));
  }
}

#stage[data-screen="title"] #comingSoonBtn {
  top: max(12px, var(--safe-top));
  right: max(124px, calc(var(--safe-right) + 112px));
  bottom: auto;
}

#backBtn:focus-visible,
#closeBtn:focus-visible,
#muteBtn:focus-visible,
.tp-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* 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"],
#touchpad[data-kind="pause"],
#touchpad[data-kind="tank"] {
  display: block;
}
#touchpad .tp-joystick,
#touchpad .tp-actions,
#touchpad .tp-quiz {
  display: none;
}
#touchpad[data-kind="game"] .tp-joystick,
#touchpad[data-kind="game"] .tp-actions {
  display: block;
}
#touchpad[data-kind="tank"] .tp-joystick {
  display: block;
}
#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;
}

/* Draggable analog-style joystick. The outer ring stays fixed while the knob
   follows the thumb and snaps back to center on release. */
.tp-joystick {
  position: fixed;
  width: 150px;
  height: 150px;
  pointer-events: auto;
  touch-action: none;
  border: 2px solid rgba(255, 255, 255, .34);
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(123, 91, 255, .18) 0 38%, transparent 39%),
    rgba(20, 16, 40, .48);
  box-shadow:
    inset 0 0 28px rgba(123, 91, 255, .18),
    0 8px 24px rgba(0, 0, 0, .28);
  -webkit-user-select: none;
  user-select: none;
  backdrop-filter: blur(2px);
}

.tp-stick-guide {
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 50%;
}
.tp-stick-guide::before,
.tp-stick-guide::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, .15);
}
.tp-stick-guide::before {
  left: 50%;
  top: 4px;
  bottom: 4px;
  width: 1px;
}
.tp-stick-guide::after {
  top: 50%;
  left: 4px;
  right: 4px;
  height: 1px;
}

.tp-stick-knob {
  position: absolute;
  left: 46px;
  top: 46px;
  width: 58px;
  height: 58px;
  border: 2px solid rgba(255, 255, 255, .72);
  border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, #b6a9ff, #6948e8 72%);
  box-shadow: 0 5px 18px rgba(0, 0, 0, .38), 0 0 20px rgba(123, 91, 255, .42);
  transition: transform 70ms ease-out;
  will-change: transform;
}
.tp-joystick.active .tp-stick-knob {
  transition: none;
  box-shadow: 0 5px 18px rgba(0, 0, 0, .42), 0 0 26px rgba(155, 253, 75, .52);
}

#touchpad[data-directions="lr"] .tp-stick-guide::before {
  display: none;
}

.tp-actions {
  position: fixed;
  width: 140px;
  height: 140px;
}
.tp-actions .tp-btn {
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  padding: 0 4px;
  font-size: 14px;
}
.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: 48px;
  height: 48px;
  font-size: 16px;
  border-radius: 10px;
}
#touchpad[data-kind="game"] .tp-pause,
#touchpad[data-kind="quiz"] .tp-pause,
#touchpad[data-kind="pause"] .tp-pause,
#touchpad[data-kind="tank"] .tp-pause {
  display: block;
  pointer-events: auto;
}

#touchpad[data-top-action="none"] .tp-pause {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  #comingSoonBtn::before { animation: none; }
  #backBtn, #closeBtn, #muteBtn, #nameContinueBtn { transition: none; }
  #scanlines {
    background: radial-gradient(ellipse at center, transparent 62%, rgba(0, 0, 0, .34) 100%);
    mix-blend-mode: normal;
  }
}

@media (prefers-contrast: more) {
  #scanlines { display: none; }
  .tp-btn,
  #backBtn,
  #closeBtn,
  #muteBtn {
    border-width: 2px;
    background: rgba(7, 6, 15, .9);
  }
}
