:root {
  color-scheme: dark;
  font-family: Arial, Helvetica, sans-serif;
  background: #02040a;
  color: #fff;
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow: hidden;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
}

body {
  background: #02040a;
}

button {
  font: inherit;
}

#game-root,
#title-root,
#title-screen,
#space-background,
#tutorial-screen,
#tutorial-scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
}

#game-root {
  overflow: hidden;
  background: #02040a;
  isolation: isolate;
}

#title-screen,
#tutorial-screen {
  overflow: hidden;
  isolation: isolate;
}

/* =========================================
   TITLE SCREEN
   ========================================= */

#title-screen {
  background: transparent;
  pointer-events: none;
}

#space-background {
  z-index: 0;
  overflow: hidden;
}

#space-background canvas,
#tutorial-scene canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

#title-menu {
  pointer-events: auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  display: flex;
  flex-direction: column;
  align-items: stretch;

  width: max-content;
  max-width: calc(100vw - 40px);

  color: #fff;
  text-align: center;
  z-index: 2;
}

#game-title {
  width: max-content;
  max-width: 100%;
  align-self: center;

  margin: 0 0 20px;
  color: #fff;

  font-size: clamp(36px, 7.2vw, 84px);
  font-weight: 700;
  letter-spacing: 0.075em;
  line-height: 1;

  white-space: nowrap;
  text-shadow: 0 0 24px rgb(255 255 255 / 12%);
}

#title-buttons {
  display: flex;
  width: 100%;
  align-items: stretch;
  gap: 0;
}

#title-buttons button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  padding: 12px 8px;

  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;

  background: transparent;
  border: none;
  border-radius: 0;

  color: #fff;
  font-size: clamp(12px, 1.7vw, 17px);
  font-weight: 500;
  letter-spacing: 0.09em;
  white-space: nowrap;

  cursor: pointer;
  transition:
    background-color 180ms ease,
    color 180ms ease,
    text-shadow 180ms ease;
}

#title-buttons button:hover,
#title-buttons button:focus-visible {
  background: rgb(255 255 255 / 9%);
  color: #fff;
  text-shadow: 0 0 12px rgb(255 255 255 / 50%);
  outline: none;
}

#title-buttons button:focus-visible {
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 70%);
}

#title-buttons button:active {
  background: rgb(255 255 255 / 15%);
}

.chevron {
  flex: 0 0 auto;
  transition: transform 180ms ease;
}

#load-game-button[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

#load-game-panel {
  margin-top: 12px;
  padding: 12px;
  color: rgb(255 255 255 / 70%);
  font-size: 12px;
  letter-spacing: 0.15em;
}

#load-game-panel p {
  margin: 0;
}

#load-game-panel[hidden] {
  display: none;
}

/* =========================================
   TUTORIAL SCREEN
   ========================================= */

#tutorial-screen {
  background: #000;
  isolation: isolate;
}

#tutorial-scene {
  z-index: 0;
  overflow: hidden;
  background: #080d15;
}

#tutorial-scene canvas {
  position: absolute;
  inset: 0;
}

/*
 * This overlay covers the entire 3D scene.
 * JavaScript fades its opacity from 1 to 0.
 */

#tutorial-blackout {
  position: absolute;
  inset: 0;
  z-index: 5;

  display: block;
  opacity: 1;
  background: #000;

  pointer-events: none;
  will-change: opacity;
}

/* Minimal loading indicator, visible only during audio. */

#tutorial-loading {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translateX(-50%);

  color: rgb(255 255 255 / 40%);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.3em;

  pointer-events: none;
  transition: opacity 700ms ease;
}

#tutorial-loading.loading-hidden {
  opacity: 0;
}

/* Mobile movement joystick */

#movement-joystick {
  position: absolute;
  z-index: 4;
  left: max(24px, env(safe-area-inset-left));
  bottom: max(28px, env(safe-area-inset-bottom));

  width: 132px;
  height: 132px;

  border: 2px solid rgb(255 255 255 / 35%);
  border-radius: 50%;
  background: rgb(12 20 28 / 35%);

  display: flex;
  align-items: center;
  justify-content: center;

  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#joystick-knob {
  width: 54px;
  height: 54px;

  border: 2px solid rgb(255 255 255 / 65%);
  border-radius: 50%;
  background: rgb(220 235 240 / 45%);

  pointer-events: none;
  will-change: transform;
}

@media (hover: hover) and (pointer: fine) {
  #movement-joystick {
    display: none;
  }
}

/* =========================================
   ERROR STATE
   ========================================= */

.game-error {
  position: fixed;
  inset: 0;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;

  padding: 24px;
  background: #02040a;
  color: #fff;
  text-align: center;
}

.game-error button {
  padding: 14px 20px;
  border: 1px solid rgb(255 255 255 / 30%);
  background: transparent;
  color: #fff;
  cursor: pointer;
}

/* =========================================
   MOBILE
   ========================================= */

@media (max-width: 520px) {
  #title-menu {
    max-width: calc(100vw - 28px);
  }

  #game-title {
    font-size: clamp(28px, 8vw, 42px);
    letter-spacing: 0.055em;
    margin-bottom: 16px;
  }

  #title-buttons button {
    min-height: 44px;
    padding: 10px 4px;
    font-size: clamp(10px, 2.8vw, 13px);
    letter-spacing: 0.04em;
    gap: 4px;
  }

  .chevron {
    width: 14px;
    height: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #title-buttons button,
  .chevron {
    transition: none;
  }
}


/* Stage overlays and the shared gameplay joystick. */
#title-screen { z-index: 8; }
#prelude-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  background: #000;
  color: #fff;
  pointer-events: none;
}
#prelude-title {
  color: #fff;
  font-size: clamp(24px, 5vw, 48px);
  font-weight: 500;
  letter-spacing: 0.28em;
  text-align: center;
  padding-left: 0.28em;
}
#movement-joystick {
  position: fixed;
  z-index: 30;
  left: max(24px, env(safe-area-inset-left));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 132px;
  height: 132px;
  border: 2px solid rgb(255 255 255 / 35%);
  border-radius: 50%;
  background: rgb(12 20 28 / 35%);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#joystick-knob {
  width: 54px;
  height: 54px;
  border: 2px solid rgb(255 255 255 / 65%);
  border-radius: 50%;
  background: rgb(220 235 240 / 45%);
  pointer-events: none;
  will-change: transform;
}


/* Teamstick: quadrant character selectors with a central Rustbucket selector. */
#teamstick {
  position: fixed;
  z-index: 31;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 148px;
  height: 148px;
  border: 2px solid rgb(255 255 255 / 38%);
  border-radius: 50%;
  background: rgb(12 20 28 / 42%);
  touch-action: manipulation;
  user-select: none;
}
.teamstick-option,
.teamstick-vehicle {
  position: absolute;
  display: grid;
  place-items: center;
  padding: 0;
  color: #fff;
  border: 1px solid rgb(255 255 255 / 58%);
  border-radius: 50%;
  background: rgb(32 48 62 / 88%);
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.teamstick-option {
  width: 43px;
  height: 43px;
  font-size: 15px;
}
.teamstick-ben { left: 20px; top: 20px; }
.teamstick-gwen { right: 20px; top: 20px; }
.teamstick-kevin { right: 20px; bottom: 20px; }
.teamstick-rook { left: 20px; bottom: 20px; }
.teamstick-vehicle {
  width: 38px;
  height: 38px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 19px;
  background: rgb(150 91 42 / 95%);
}
.teamstick-option.selected,
.teamstick-vehicle.selected {
  background: #d18a3b;
  color: #111;
  border-color: #fff;
  box-shadow: 0 0 12px rgb(255 190 105 / 75%);
}


/* Full-screen control; browser entry requires a direct user gesture. */
#fullscreen-toggle {
  position: fixed;
  z-index: 100;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 35%);
  border-radius: 10px;
  color: #fff;
  background: rgb(8 15 24 / 72%);
  font-size: 27px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
#fullscreen-toggle:active { background: rgb(70 100 130 / 90%); }

#tutorial-step-label {
  position: fixed; z-index: 40; left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%); width: min(760px, calc(100vw - 32px));
  padding: 12px 18px; color: #fff; background: rgb(0 0 0 / 72%);
  border: 1px solid rgb(255 255 255 / 35%); text-align: center;
  text-transform: uppercase; letter-spacing: .08em;
  font-size: clamp(11px, 2.1vw, 15px); line-height: 1.5;
  pointer-events: none;
}
.tutorial-step-number { font-weight: 800; margin-bottom: 4px; }
.tutorial-step-content { font-weight: 600; }
#fullscreen-toggle { display: none !important; }
@media (hover: hover) and (pointer: fine) {
  #movement-joystick, #teamstick { display: none !important; }
}

/* Revised tutorial prompt and four-segment team selector. */
#tutorial-step-label {
  z-index: 35;
  bottom: max(176px, calc(env(safe-area-inset-bottom) + 176px));
  width: min(680px, calc(100vw - 32px));
  padding: 4px 8px;
  color: rgb(255 255 255 / 94%);
  background: transparent;
  border: 0;
  font-size: clamp(9px, 1.45vw, 12px);
  line-height: 1.35;
  text-shadow: 0 1px 4px #000;
}
.tutorial-step-number { display: none; }
@media (hover: hover) and (pointer: fine) {
  #tutorial-step-label { bottom: max(28px, env(safe-area-inset-bottom)); }
}
#teamstick { background: rgb(12 20 28 / 24%); }
.teamstick-option {
  width: 72px;
  height: 72px;
  border-radius: 0;
  font-size: 17px;
}
.teamstick-ben {
  left: 0; top: 0;
  clip-path: polygon(0 0,100% 0,100% 34%,76% 34%,76% 76%,34% 76%,34% 100%,0 100%);
}
.teamstick-gwen {
  right: 0; top: 0;
  clip-path: polygon(0 0,100% 0,100% 100%,66% 100%,66% 76%,24% 76%,24% 34%,0 34%);
}
.teamstick-kevin {
  right: 0; bottom: 0;
  clip-path: polygon(100% 100%,0 100%,0 66%,24% 66%,24% 24%,66% 24%,66% 0,100% 0);
}
.teamstick-rook {
  left: 0; bottom: 0;
  clip-path: polygon(0 100%,0 0,34% 0,34% 24%,76% 24%,76% 66%,100% 66%,100% 100%);
}
.teamstick-vehicle {
  border: 1px solid rgb(255 255 255 / 70%);
  border-radius: 50%;
}
html, body { min-height: 100%; min-height: 100dvh; }

/* Curved quarter-ring hit areas; only the vehicle selector remains circular. */
.teamstick-ben {
  clip-path: path("M 0 72 A 72 72 0 0 1 72 0 L 72 36 A 36 36 0 0 0 36 72 Z");
}
.teamstick-gwen {
  clip-path: path("M 0 0 A 72 72 0 0 1 72 72 L 36 72 A 36 36 0 0 0 0 36 Z");
}
.teamstick-kevin {
  clip-path: path("M 72 0 A 72 72 0 0 1 0 72 L 0 36 A 36 36 0 0 0 36 0 Z");
}
.teamstick-rook {
  clip-path: path("M 72 72 A 72 72 0 0 1 0 0 L 36 0 A 36 36 0 0 0 72 36 Z");
}

html, body { height: 100dvh; }
#omniverse { height: 100dvh; }
