/* Nebula.io — arena game styles.
   Self-contained (no third-party requests). Visual identity follows the
   Galaxy Brand & Design Guide v1.1 and the GAL-60 portal spec tokens. */

:root {
  --ink: #0B2647;
  --ink-deep: #061428;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-strong: rgba(9, 26, 51, 0.82);
  --line: rgba(255, 255, 255, 0.14);
  --text: #FFFFFF;
  --text-muted: #C9D6EA;
  --text-faint: #9FB2CC;
  --emerald: #10B981;
  --indigo: #4C6EF5;
  --violet: #7C3AED;
  --cyan: #22D3EE;
  --warn: #FFB020;          /* deny / "not enough mass" feedback (brand warn) */
  --focus: #10B981;
  --radius: 14px;
  --radius-sm: 10px;
  --pill: 999px;
  --shadow: 0 18px 44px rgba(4, 12, 26, 0.5);
  --font: Manrope, "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink-deep);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
}

body { -webkit-font-smoothing: antialiased; }

/* ------------------------------------------------------------------ stage */
#stage { position: fixed; inset: 0; overflow: hidden; }

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  background: var(--ink-deep);
  cursor: crosshair;
}

/* -------------------------------------------------------------------- HUD */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: 14px;
}

.hud-panel {
  position: absolute;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

/* top-left: score / mass / rank */
.stats {
  top: 14px;
  left: 14px;
  padding: 12px 16px;
  min-width: 168px;
}
.stat { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.stat + .stat { margin-top: 6px; }
.stat .k { color: var(--text-faint); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .v.accent { color: var(--emerald); }

/* top-right: leaderboard */
.board {
  top: 14px;
  right: 14px;
  width: 208px;
  padding: 12px 14px;
}
.board h2 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 700;
}
.board ol { list-style: none; margin: 0; padding: 0; }
.board li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  color: var(--text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.board li .rank { width: 16px; color: var(--text-faint); }
.board li .swatch { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.board li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li .ms { color: var(--text-faint); }
.board li.me { color: var(--text); font-weight: 700; }
.board li.me .nm { color: var(--emerald); }

/* bottom-left: minimap */
.minimap-wrap {
  bottom: 14px;
  left: 14px;
  padding: 8px;
  line-height: 0;
}
#minimap { display: block; width: 148px; height: 148px; border-radius: 10px; }

/* bottom-right: sound / help */
.controls-corner {
  bottom: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
  padding: 8px;
  pointer-events: auto;
}

.icon-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.icon-btn:hover { border-color: rgba(255, 255, 255, 0.3); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn[aria-pressed="false"] .on { display: none; }
.icon-btn[aria-pressed="true"] .off { display: none; }

/* transient hint + toast */
#hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 20px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--pill);
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
  opacity: 0;
  transition: opacity 240ms ease;
  max-width: min(92vw, 520px);
}
#hint.show { opacity: 1; }

#toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  padding: 10px 18px;
  border-radius: var(--pill);
  background: rgba(9, 26, 51, 0.9);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  opacity: 0;
  transition: opacity 200ms ease, transform 200ms ease;
}
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* dash readiness chip */
.dash-chip {
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.dash-chip .cd-ring {
  --p: 1;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: conic-gradient(var(--emerald) calc(var(--p) * 360deg), rgba(255, 255, 255, 0.14) 0);
}
.dash-chip .cd-label { font-variant-numeric: tabular-nums; min-width: 34px; text-align: center; }
.dash-chip .cd-key { color: var(--text-faint); }
.dash-chip[data-state="ready"] { color: var(--text); }
.dash-chip[data-state="ready"] .cd-label { color: var(--emerald); }
.dash-chip[data-state="cooling"] { opacity: 0.8; }

/* transient command feedback (not enough mass / dash on cooldown) */
#cmdHint {
  position: absolute;
  left: 50%;
  top: 62%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: var(--pill);
  background: rgba(9, 26, 51, 0.9);
  border: 1px solid var(--warn);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 180ms ease;
  max-width: min(90vw, 420px);
  text-align: center;
}
#cmdHint.show { opacity: 1; }

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

/* ------------------------------------------------------------------ touch */
#touch { position: absolute; inset: 0; pointer-events: none; display: none; }
body.touch #touch { display: block; }
.tbtn {
  position: absolute;
  bottom: 22px;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(9, 26, 51, 0.72);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  pointer-events: auto;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.tbtn:active { background: rgba(16, 185, 129, 0.28); }
.touch-actions {
  position: absolute;
  right: 14px;
  bottom: 78px;
  display: flex;
  gap: 10px;
  pointer-events: auto;
}
.touch-actions .tbtn { position: relative; bottom: auto; right: auto; }
/* Dash is the primary action. It gets its own emerald treatment so it never
   reads as a third identical grey circle next to Split/Eject. */
.touch-actions #btnDash {
  background: rgba(16, 185, 129, 0.24);
  border: 2px solid rgba(16, 185, 129, 0.8);
  color: #D1FAE5;
  font-weight: 800;
  letter-spacing: 0.08em;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.16);
}
.touch-actions #btnDash:active {
  background: rgba(16, 185, 129, 0.48);
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.55);
}
#stick {
  position: absolute;
  left: 24px;
  bottom: 22px;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(9, 26, 51, 0.5);
  pointer-events: auto;
}
#stickKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(76, 110, 245, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.4);
}

/* --------------------------------------------------------------- overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 520px at 78% -6%, rgba(76, 110, 245, 0.3), transparent 60%),
    radial-gradient(700px 420px at 8% 104%, rgba(124, 58, 237, 0.24), transparent 60%),
    rgba(6, 20, 40, 0.82);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 20;
}
.overlay[hidden] { display: none; }

.panel {
  width: min(560px, 100%);
  max-height: 92vh;
  overflow: auto;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}
.panel .spark { width: 44px; height: 44px; margin: 0 auto 14px; display: block; }
.panel h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 7vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.panel h1 .accent { color: var(--emerald); }
.panel h2 { margin: 0 0 8px; font-size: 22px; font-weight: 700; }
.panel p { margin: 0 0 14px; color: var(--text-muted); font-size: 16px; line-height: 1.55; }
.panel .tag { color: var(--text-faint); font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 12px; }

.cta-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 18px 0 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 26px;
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--emerald); color: #06281C; }
.btn-primary:hover { background: #34D399; }
.btn-ghost { border-color: var(--line); color: var(--text); background: transparent; }
.btn-ghost:hover { border-color: rgba(255, 255, 255, 0.34); }

.modes { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 4px 0 6px; }
.mode {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.mode[aria-pressed="true"] { border-color: var(--emerald); color: var(--emerald); }

.keys {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 18px 0 6px;
  text-align: left;
}
.key {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  font-size: 14px;
}
.key kbd {
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  white-space: nowrap;
}
.score-line { font-size: 34px; font-weight: 800; color: var(--emerald); margin: 4px 0 2px; }
.sub { color: var(--text-faint); font-size: 14px; }

.site-link { display: inline-block; margin-top: 14px; color: var(--text-faint); font-size: 13px; text-decoration: none; }
.site-link:hover { color: var(--text); }

/* focus visibility everywhere */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 720px) {
  .board { width: 176px; top: 10px; right: 10px; }
  .stats { top: 10px; left: 10px; padding: 10px 12px; min-width: 0; }
  .stat .v { font-size: 17px; }
  .minimap-wrap { bottom: 10px; left: 10px; }
  #minimap { width: 108px; height: 108px; }
  .controls-corner { bottom: 10px; right: 10px; }
}
@media (max-width: 460px) {
  .board { width: 150px; padding: 10px; }
  .board li { font-size: 12px; }
  .panel { padding: 22px; }
  /* Lyra item 3: at <=460px the dash chip sat on top of the stats panel.
     It now sits directly BELOW the stats block (stats is ~92px tall here),
     so .dash-chip / .stats can never overlap. */
  .dash-chip { top: 112px; left: 10px; transform: none; }
  .touch-actions { right: 10px; bottom: 70px; gap: 8px; }
  .touch-actions .tbtn { width: 58px; height: 58px; font-size: 11px; }
  /* Dash is never the smallest target: it stays one step larger than
     Split/Eject at this breakpoint too. */
  .touch-actions #btnDash { width: 64px; height: 64px; }
  #stick { left: 16px; bottom: 16px; width: 112px; height: 112px; }
  /* On a touch device the minimap would sit under the movement stick. */
  body.touch .minimap-wrap { display: none; }
}

/* 320/360px-class phones: the three-button row and the movement stick cannot
   share the bottom edge. Dash moves onto its own row above Split/Eject, the
   row and the stick shrink, and the two never intersect. */
@media (max-width: 360px) {
  .touch-actions {
    right: 8px;
    bottom: 16px;
    display: grid;
    grid-template-columns: repeat(2, 54px);
    grid-template-rows: 54px 54px;
    gap: 6px;
  }
  .touch-actions .tbtn { width: 54px; height: 54px; font-size: 11px; }
  .touch-actions #btnDash {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 114px;
    justify-self: end;
  }
  #stick { left: 8px; bottom: 14px; width: 100px; height: 100px; }
  #stickKnob { width: 46px; height: 46px; margin: -23px 0 0 -23px; }
}
@media (max-width: 320px) {
  .touch-actions {
    right: 6px;
    bottom: 12px;
    grid-template-columns: repeat(2, 50px);
    grid-template-rows: 50px 50px;
    gap: 6px;
  }
  .touch-actions .tbtn { width: 50px; height: 50px; font-size: 10px; }
  .touch-actions #btnDash { width: 106px; }
  #stick { left: 6px; bottom: 10px; width: 92px; height: 92px; }
  #stickKnob { width: 42px; height: 42px; margin: -21px 0 0 -21px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, #hint, #toast, #cmdHint { transition: none; }
  .btn:hover { transform: none; }
  /* The cooldown ring was the only continuous signal in the HUD. Under reduced
     motion it becomes a FOUR-STEP discrete indicator: the conic sweep is
     removed entirely and the step (written by the game as data-step 0..4)
     is drawn with borders, so nothing animates continuously. */
  .dash-chip .cd-ring {
    background: none !important;
    border: 2px solid var(--text-muted);
    box-shadow: none;
    transition: none;
    animation: none !important;
  }
  .dash-chip .cd-ring[data-step="0"] { border-color: var(--text-muted); }
  .dash-chip .cd-ring[data-step="1"] { border-top-color: var(--emerald); }
  .dash-chip .cd-ring[data-step="2"] {
    border-top-color: var(--emerald);
    border-right-color: var(--emerald);
  }
  .dash-chip .cd-ring[data-step="3"] {
    border-top-color: var(--emerald);
    border-right-color: var(--emerald);
    border-bottom-color: var(--emerald);
  }
  .dash-chip .cd-ring[data-step="4"] { border-color: var(--emerald); }
}

@media (forced-colors: active) {
  .btn, .card, .hud-panel, .tbtn, .icon-btn { border-color: CanvasText; }
  .panel h1 .accent, .stat .v.accent { color: CanvasText; }
  /* Dash readiness chip: border-based, no background reliance. */
  .dash-chip {
    border: 1px solid CanvasText;
    background: Canvas;
    color: CanvasText;
  }
  .dash-chip .cd-label,
  .dash-chip .cd-key,
  .dash-chip[data-state="ready"] .cd-label { color: CanvasText; }
  /* Cooldown ring: a plain border ring plus discrete filled steps. No
     gradient, no background reliance, no animation. */
  .dash-chip .cd-ring {
    background: none !important;
    border: 2px solid CanvasText;
    box-shadow: none;
    transition: none;
    animation: none !important;
  }
  .dash-chip .cd-ring[data-step="1"] { border-top-color: Highlight; }
  .dash-chip .cd-ring[data-step="2"] {
    border-top-color: Highlight;
    border-right-color: Highlight;
  }
  .dash-chip .cd-ring[data-step="3"] {
    border-top-color: Highlight;
    border-right-color: Highlight;
    border-bottom-color: Highlight;
  }
  .dash-chip .cd-ring[data-step="4"] { border-color: Highlight; }
  /* Command hint pill: border + system colours, text still carries meaning. */
  #cmdHint {
    border: 1px solid CanvasText;
    background: Canvas;
    color: CanvasText;
  }
}
