/* ==========================================================================
   NEON SURVIVOR — assets/styles.css
   Phase 1 shell: menu, dialogs, settings, credits, animated neon background.
   Mobile-first, 320–1920, safe-area aware, no horizontal overflow.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
  --bg-0: #03060c;
  --bg-1: #060c16;
  --bg-2: #0a1424;
  --panel: rgba(8, 17, 30, 0.74);
  --panel-solid: #081120;
  --line: rgba(120, 200, 235, 0.16);
  --line-strong: rgba(120, 220, 255, 0.32);
  --text: #e9f5ff;
  --text-soft: #b4c9da;
  --muted: #8aa2b6;
  --cyan: #22e6ff;
  --cyan-deep: #0fb4e0;
  --magenta: #ff3ea5;
  --amber: #ffb84d;
  --violet: #7a5cff;
  --danger: #ff5d7a;
  --ok: #4dffb8;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Consolas, "Liberation Mono", monospace;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 28px;

  --shadow-glow: 0 0 0 1px rgba(34, 230, 255, 0.12), 0 20px 60px -22px rgba(0, 12, 24, 0.9);
  --shadow-cyan: 0 0 24px -6px rgba(34, 230, 255, 0.55);
  --shadow-magenta: 0 0 26px -6px rgba(255, 62, 165, 0.5);

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur: 160ms;
}

/* Colorblind-friendly palette (applied via body class) */
body.colorblind {
  --cyan: #58c8ff;
  --cyan-deep: #2f9fe0;
  --magenta: #ffa028;
  --amber: #ffe066;
  --violet: #9c8bff;
  --line: rgba(150, 210, 240, 0.22);
}

/* --------------------------------------------------------------------------
   2. Reset / base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
  background: var(--bg-0);
  scrollbar-color: rgba(34, 230, 255, 0.35) transparent;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    radial-gradient(1200px 720px at 50% -10%, rgba(18, 80, 110, 0.35), transparent 68%),
    radial-gradient(900px 600px at 92% 110%, rgba(90, 30, 90, 0.22), transparent 70%),
    var(--bg-0);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.dialog-open {
  overflow: hidden;
}

img,
svg,
canvas {
  display: block;
  max-width: 100%;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

h1, h2, h3, h4, p, ul, dl, dd, dt {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

[hidden] {
  display: none !important;
}

::selection {
  background: rgba(34, 230, 255, 0.3);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
  border-radius: 6px;
}

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

.skip-link {
  position: fixed;
  left: 12px;
  top: -100px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--cyan);
  color: #021018;
  font-weight: 700;
  text-decoration: none;
  transition: top var(--dur) var(--ease);
}

.skip-link:focus {
  top: calc(12px + env(safe-area-inset-top, 0px));
}

/* --------------------------------------------------------------------------
   3. Background canvas + overlays
   -------------------------------------------------------------------------- */
#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
  background: var(--bg-0);
}

.fx-scanlines,
.fx-grain {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.fx-scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.024) 0,
    rgba(255, 255, 255, 0.024) 1px,
    transparent 1px,
    transparent 3px
  );
  opacity: 0.55;
  mix-blend-mode: soft-light;
}

.fx-grain {
  opacity: 0.05;
  background-image:
    radial-gradient(circle at 20% 30%, #fff 0, transparent 1px),
    radial-gradient(circle at 70% 60%, #fff 0, transparent 1px);
  background-size: 3px 3px, 5px 5px;
  mix-blend-mode: overlay;
}

/* --------------------------------------------------------------------------
   4. App shell + top bar
   -------------------------------------------------------------------------- */
.app {
  position: relative;
  z-index: 3;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding:
    calc(12px + env(safe-area-inset-top, 0px))
    calc(16px + env(safe-area-inset-right, 0px))
    12px
    calc(16px + env(safe-area-inset-left, 0px));
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

.brand-mini {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.85;
  user-select: none;
}

.brand-mini-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.62);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease),
    background var(--dur) var(--ease), transform var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}

.chip:hover {
  border-color: var(--line-strong);
  color: var(--text);
  background: rgba(14, 30, 50, 0.8);
  box-shadow: var(--shadow-cyan);
}

.chip:active {
  transform: scale(0.96);
}

.chip-icon {
  display: inline-flex;
  color: var(--cyan);
}

.chip-label {
  white-space: nowrap;
}

#btn-audio[aria-pressed="false"] {
  color: var(--muted);
}

#btn-audio[aria-pressed="false"] .chip-icon {
  color: var(--muted);
}

#btn-audio[aria-pressed="false"] .spk-wave,
#btn-audio[aria-pressed="false"] .spk-wave2 {
  opacity: 0.2;
}

#btn-audio[aria-pressed="false"] .spk-slash {
  opacity: 1;
}

.spk-slash {
  opacity: 0;
  stroke: var(--danger);
  transition: opacity var(--dur) var(--ease);
}

/* --------------------------------------------------------------------------
   5. Screens + menu
   -------------------------------------------------------------------------- */
.screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(84px + env(safe-area-inset-top, 0px))
    calc(16px + env(safe-area-inset-right, 0px))
    calc(28px + env(safe-area-inset-bottom, 0px))
    calc(16px + env(safe-area-inset-left, 0px));
  animation: screen-in 420ms var(--ease) both;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.menu-card {
  position: relative;
  width: min(560px, 100%);
  padding: clamp(24px, 5vw, 44px) clamp(20px, 5vw, 44px) clamp(22px, 4vw, 34px);
  border-radius: var(--radius-xl);
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(11, 23, 40, 0.82), rgba(5, 11, 20, 0.9));
  box-shadow: var(--shadow-glow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  backdrop-filter: blur(14px) saturate(120%);
  text-align: center;
  overflow: hidden;
}

.menu-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 12%;
  right: 12%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--cyan), var(--magenta), transparent);
  opacity: 0.85;
}

.menu-card::after {
  content: "";
  position: absolute;
  inset: -60% -20% auto;
  height: 220px;
  background: radial-gradient(60% 100% at 50% 0%, rgba(34, 230, 255, 0.16), transparent 70%);
  pointer-events: none;
}

.logo-eyebrow {
  position: relative;
  font-family: var(--font-mono);
  font-size: clamp(10px, 2.4vw, 12px);
  letter-spacing: 0.52em;
  text-transform: uppercase;
  color: var(--cyan);
  text-indent: 0.52em;
  opacity: 0.9;
  margin-bottom: 10px;
}

.logo {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  font-weight: 900;
  font-size: clamp(42px, 12vw, 84px);
  line-height: 0.86;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.logo-neon {
  background: linear-gradient(180deg, #f4ffff 0%, var(--cyan) 52%, var(--cyan-deep) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 22px rgba(34, 230, 255, 0.4));
}

.logo-survivor {
  font-size: 0.62em;
  letter-spacing: 0.18em;
  text-indent: 0.18em;
  background: linear-gradient(100deg, var(--magenta) 0%, #ff8ac2 42%, var(--amber) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 20px rgba(255, 62, 165, 0.34));
}

.menu-subtitle {
  margin-top: 16px;
  font-size: clamp(13px, 3.4vw, 15px);
  color: var(--text-soft);
  letter-spacing: 0.02em;
}

.best-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  margin: 22px auto 4px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid rgba(255, 184, 77, 0.28);
  background: linear-gradient(180deg, rgba(60, 42, 12, 0.35), rgba(20, 16, 8, 0.4));
  color: var(--amber);
}

.best-icon {
  align-self: center;
  display: inline-flex;
  color: var(--amber);
  opacity: 0.9;
}

.best-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: rgba(255, 200, 120, 0.85);
}

.best-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff3dc;
  text-shadow: 0 0 14px rgba(255, 184, 77, 0.55);
}

.menu-nav {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.menu-nav-secondary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.menu-nav-secondary .btn {
  padding-left: 12px;
  padding-right: 12px;
  font-size: 13px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.menu-hint {
  margin-top: 22px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
  opacity: 0.85;
}

/* --------------------------------------------------------------------------
   6. Buttons
   -------------------------------------------------------------------------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 50px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(20, 38, 60, 0.7), rgba(9, 18, 32, 0.82));
  color: var(--text);
  font-size: clamp(13px, 3.4vw, 15px);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  line-height: 1.2;
  overflow: hidden;
  isolation: isolate;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease), background var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

.btn > span,
.btn > svg {
  position: relative;
  z-index: 1;
}

.btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 20%, rgba(255, 255, 255, 0.12) 45%, transparent 70%);
  transform: translateX(-130%);
  transition: transform 420ms var(--ease);
  z-index: 0;
}

.btn:hover::before {
  transform: translateX(130%);
}

.btn:hover {
  border-color: var(--line-strong);
  box-shadow: 0 10px 26px -16px rgba(34, 230, 255, 0.9);
}

.btn:active {
  transform: scale(0.975);
}

.btn--primary {
  min-height: 62px;
  border: 1px solid rgba(120, 240, 255, 0.5);
  background: linear-gradient(100deg, #1fe0ff 0%, #34c3ff 46%, #7a5cff 100%);
  color: #03121c;
  font-size: clamp(16px, 4.4vw, 19px);
  font-weight: 900;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  box-shadow: 0 0 0 1px rgba(3, 18, 28, 0.2), 0 18px 44px -16px rgba(34, 230, 255, 0.75);
}

.btn--primary .btn-icon {
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.4));
}

.btn--primary:hover {
  box-shadow: 0 0 0 1px rgba(3, 18, 28, 0.2), 0 24px 54px -14px rgba(34, 230, 255, 0.95);
  border-color: #b9f6ff;
}

.btn--ghost {
  background: transparent;
}

.btn--sm {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 12px;
  letter-spacing: 0.06em;
}

.btn--danger {
  border-color: rgba(255, 93, 122, 0.42);
  background: linear-gradient(180deg, rgba(60, 18, 30, 0.6), rgba(26, 8, 14, 0.7));
  color: #ffc2cd;
}

.btn--danger:hover {
  border-color: var(--danger);
  box-shadow: 0 10px 26px -14px rgba(255, 93, 122, 0.9);
}

.btn--danger.armed {
  background: linear-gradient(100deg, #ff4d6d, #ff8a5c);
  color: #2a050c;
  border-color: #ffd0d8;
  animation: armed-pulse 900ms ease-in-out infinite;
}

@keyframes armed-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 93, 122, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(255, 93, 122, 0); }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(10, 22, 38, 0.7);
  color: var(--text-soft);
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    background var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.icon-btn:hover {
  color: #fff;
  border-color: var(--line-strong);
  background: rgba(20, 40, 64, 0.9);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* --------------------------------------------------------------------------
   7. Dialogs
   -------------------------------------------------------------------------- */
.dialog {
  width: min(680px, calc(100vw - 24px));
  max-height: min(95dvh, 1000px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(11, 24, 42, 0.97), rgba(5, 11, 20, 0.98));
  color: var(--text);
  box-shadow:
    0 0 0 1px rgba(34, 230, 255, 0.08),
    0 40px 120px -30px rgba(0, 0, 0, 0.95),
    0 0 80px -30px rgba(34, 230, 255, 0.5);
  overflow: hidden;
}

.dialog[open] {
  animation: dialog-in 220ms var(--ease) both;
}

.dialog::backdrop {
  background: rgba(2, 6, 12, 0.62);
  -webkit-backdrop-filter: blur(9px) saturate(115%);
  backdrop-filter: blur(9px) saturate(115%);
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

.dialog-inner {
  display: flex;
  flex-direction: column;
  max-height: inherit;
  min-height: 0;
}

.dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(18px, 4vw, 28px) 12px;
  background: linear-gradient(180deg, rgba(9, 20, 36, 0.98), rgba(9, 20, 36, 0.86));
  border-bottom: 1px solid var(--line);
}

.dialog-title {
  font-size: clamp(19px, 4.6vw, 24px);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: linear-gradient(100deg, #ffffff, var(--cyan) 70%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.dialog-body {
  padding: clamp(16px, 3.6vw, 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1 1 auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(34, 230, 255, 0.35) transparent;
}

.dialog-body::-webkit-scrollbar {
  width: 10px;
}

.dialog-body::-webkit-scrollbar-thumb {
  background: rgba(34, 230, 255, 0.28);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.lead {
  color: var(--text-soft);
  font-size: 15px;
  line-height: 1.65;
}

.dialog-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.dialog-section:first-of-type {
  margin-top: 10px;
}

.section-title {
  margin-bottom: 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--cyan);
}

.dialog-section p {
  color: var(--text-soft);
  font-size: 14.5px;
  line-height: 1.65;
}

/* How-to: controls */
.control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.control-card {
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(12, 26, 44, 0.55);
}

.control-card h4 {
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text);
}

.control-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.control-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
  color: var(--text-soft);
}

.keys {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}

kbd {
  display: inline-block;
  min-width: 26px;
  padding: 3px 7px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  background: rgba(6, 14, 26, 0.9);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
  text-align: center;
}

/* How-to: enemies */
.enemy-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

@media (max-width: 520px) {
  .enemy-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 370px) {
  .enemy-grid {
    grid-template-columns: 1fr;
  }
}

.enemy-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(12, 26, 44, 0.5);
}

.enemy-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.enemy-text strong {
  font-size: 13.5px;
  letter-spacing: 0.04em;
  color: var(--text);
}

.enemy-text span {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.35;
}

.shape {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  background: var(--cyan);
  filter: drop-shadow(0 0 7px rgba(34, 230, 255, 0.7));
}

.shape--grunt {
  background: var(--cyan);
  clip-path: polygon(50% 4%, 100% 96%, 0% 96%);
}

.shape--runner {
  background: var(--magenta);
  clip-path: polygon(50% 0%, 62% 40%, 50% 100%, 38% 40%);
  filter: drop-shadow(0 0 7px rgba(255, 62, 165, 0.7));
}

.shape--brute {
  background: var(--amber);
  clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0% 50%);
  filter: drop-shadow(0 0 7px rgba(255, 184, 77, 0.7));
}

.shape--spitter {
  background: var(--violet);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  filter: drop-shadow(0 0 7px rgba(122, 92, 255, 0.75));
}

.shape--elite {
  background: radial-gradient(circle, rgba(5, 12, 22, 0.96) 34%, var(--magenta) 37%, var(--magenta) 58%, rgba(5, 12, 22, 0.15) 61%);
  clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
  filter: drop-shadow(0 0 8px rgba(255, 62, 165, 0.8));
}

.shape--boss {
  background: conic-gradient(from 0deg, var(--cyan), var(--magenta), var(--amber), var(--cyan));
  clip-path: polygon(50% 0%, 90% 20%, 100% 62%, 72% 100%, 28% 100%, 0% 62%, 10% 20%);
  filter: drop-shadow(0 0 9px rgba(34, 230, 255, 0.75));
}

/* --------------------------------------------------------------------------
   8. Settings controls
   -------------------------------------------------------------------------- */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 11px 0;
  border-bottom: 1px dashed rgba(120, 200, 235, 0.12);
}

.setting-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.setting-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.setting-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.setting-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.setting-control {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 1 260px;
}

/* Range slider */
.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  background: transparent;
  cursor: pointer;
}

.range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(34, 230, 255, 0.7), rgba(122, 92, 255, 0.55));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.range::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(34, 230, 255, 0.7), rgba(122, 92, 255, 0.55));
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  background: #eafcff;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 12px rgba(34, 230, 255, 0.8);
  transition: transform var(--dur) var(--ease);
}

.range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #eafcff;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 12px rgba(34, 230, 255, 0.8);
}

.range:hover::-webkit-slider-thumb,
.range:focus-visible::-webkit-slider-thumb {
  transform: scale(1.15);
}

.range:focus-visible {
  outline-offset: 6px;
}

.range-out {
  min-width: 40px;
  font-family: var(--font-mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--cyan);
}

/* Segmented control */
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(5, 13, 24, 0.7);
}

.seg-btn {
  min-height: 38px;
  padding: 8px 16px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.seg-btn:hover {
  color: var(--text);
  background: rgba(34, 230, 255, 0.08);
}

.seg-btn[aria-pressed="true"] {
  color: #03121c;
  background: linear-gradient(100deg, #28e1ff, #6f9dff);
  box-shadow: 0 4px 14px -6px rgba(34, 230, 255, 0.85);
}

.seg-btn:active {
  transform: scale(0.97);
}

/* Switch */
.switch {
  position: relative;
  flex: 0 0 auto;
  width: 54px;
  height: 30px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(4, 10, 20, 0.85);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #7d93a6;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}

.switch[aria-checked="true"] {
  background: rgba(34, 230, 255, 0.18);
  border-color: var(--cyan);
}

.switch[aria-checked="true"]::after {
  transform: translateX(24px);
  background: var(--cyan);
  box-shadow: 0 0 12px rgba(34, 230, 255, 0.85);
}

/* Data / delete */
.dialog-section--data .setting-row {
  border-bottom: 0;
  padding-bottom: 0;
}

.best-inline {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--amber);
}

.delete-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

/* Credits */
.credits-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.credits-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 16px;
  border: 1px solid var(--line-strong);
  background: radial-gradient(circle at 30% 20%, rgba(34, 230, 255, 0.3), rgba(8, 18, 32, 0.9));
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--cyan);
  box-shadow: var(--shadow-cyan);
}

.credits-name {
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #fff;
}

.credits-tagline {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.credits-list {
  margin-top: 8px;
}

.credits-row {
  display: grid;
  grid-template-columns: minmax(110px, 170px) 1fr;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px dashed rgba(120, 200, 235, 0.12);
}

.credits-row:last-child {
  border-bottom: 0;
}

.credits-row dt {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cyan);
}

.credits-row dd {
  font-size: 14px;
  color: var(--text-soft);
  line-height: 1.55;
}

/* --------------------------------------------------------------------------
   9. Toast + noscript
   -------------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(8, 20, 34, 0.96);
  color: var(--text);
  font-size: 13.5px;
  text-align: center;
  box-shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.9), var(--shadow-cyan);
  opacity: 0;
  transform: translate(-50%, 14px);
  pointer-events: none;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg-0);
  color: var(--text);
  text-align: center;
}

/* Gameplay layer shells (reserved for phase 2/3) */
.game-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
}

/* --------------------------------------------------------------------------
   10. Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 520px) {
  .topbar {
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
  }

  .brand-mini {
    display: none;
  }

  .menu-nav-secondary {
    grid-template-columns: 1fr;
  }

  .menu-card {
    border-radius: var(--radius-lg);
  }

  .menu-hint {
    font-size: 10px;
  }

  .setting-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .setting-control {
    flex-basis: auto;
  }

  .setting-row .switch {
    align-self: flex-start;
  }

  .delete-actions {
    justify-content: flex-start;
  }

  .credits-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .dialog-head {
    padding-top: calc(18px + env(safe-area-inset-top, 0px) * 0.35);
  }
}

@media (max-width: 360px) {
  .btn {
    padding: 11px 14px;
    letter-spacing: 0.05em;
  }

  .btn--primary {
    font-size: 16px;
    letter-spacing: 0.16em;
    text-indent: 0.16em;
  }

  .seg-btn {
    padding: 8px 12px;
    font-size: 12px;
  }
}

@media (min-width: 900px) {
  .menu-card {
    padding: 46px 48px 36px;
  }

  .menu-nav-secondary {
    gap: 12px;
  }
}

@media (max-height: 620px) and (orientation: landscape) {
  .screen {
    align-items: flex-start;
    padding-top: calc(64px + env(safe-area-inset-top, 0px));
    padding-bottom: 18px;
  }

  .logo {
    font-size: clamp(34px, 7vw, 56px);
  }

  .best-chip {
    margin-top: 12px;
  }

  .menu-nav {
    margin-top: 16px;
  }

  .menu-card {
    padding-top: 22px;
    padding-bottom: 18px;
  }
}

/* --------------------------------------------------------------------------
   11. Reduced motion / QA
   -------------------------------------------------------------------------- */
body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

body.qa-mode *,
body.qa-mode *::before,
body.qa-mode *::after {
  animation: none !important;
  transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .btn::before {
    display: none;
  }
}

/* High-contrast focus for colorblind users */
body.colorblind :focus-visible {
  outline-width: 3px;
  outline-color: #9fe8ff;
}

/* ==========================================================================
   PHASE 2A — Gameplay HUD, overlays, upgrade cards, touch controls
   ========================================================================== */

/* --------------------------------------------------------------------------
   12. HUD
   -------------------------------------------------------------------------- */
.in-game .topbar {
  display: none;
}

.in-game .screen--menu {
  display: none;
}

.game-hud {
  z-index: 12;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding:
    calc(14px + env(safe-area-inset-top, 0px))
    calc(18px + env(safe-area-inset-right, 0px))
    calc(16px + env(safe-area-inset-bottom, 0px))
    calc(18px + env(safe-area-inset-left, 0px));
  pointer-events: none;
  user-select: none;
}

.game-hud::before,
.game-hud::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 132px;
  pointer-events: none;
}

.game-hud::before {
  top: 0;
  background: linear-gradient(180deg, rgba(2, 6, 12, 0.58), rgba(2, 6, 12, 0));
}

.game-hud::after {
  bottom: 0;
  background: linear-gradient(0deg, rgba(2, 6, 12, 0.62), rgba(2, 6, 12, 0));
}

.hud-label,
.hud-hp-text,
.hud-stat strong,
.hud-timer,
.hud-timer-label,
.hud-wave,
.hud-xp-text,
.hud-level strong,
.dash-label,
.boss-bar-label {
  text-shadow: 0 1px 5px rgba(2, 6, 12, 0.95), 0 0 12px rgba(2, 6, 12, 0.7);
}

.hud-top,
.hud-bottom {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
}

.hud-bottom {
  align-items: flex-end;
}

.hud-left {
  width: min(300px, 32vw);
  min-width: 140px;
}

.hud-hp-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 5px;
}

.hud-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-hp-text {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-soft);
}

.bar {
  position: relative;
  height: 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(3, 9, 18, 0.78);
  overflow: hidden;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.5);
}

.bar-fill,
.bar-lag {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(1);
  border-radius: 999px;
  will-change: transform;
}

.bar--hp .bar-lag {
  background: rgba(255, 93, 122, 0.42);
  transition: transform 180ms linear;
}

.bar--hp .bar-fill {
  background: linear-gradient(90deg, #ff3ea5 0%, #ff7b6b 60%, #ffb84d 100%);
  box-shadow: 0 0 12px rgba(255, 62, 165, 0.55);
}

.bar--xp {
  height: 9px;
}

.bar--xp .bar-fill {
  background: linear-gradient(90deg, var(--cyan) 0%, #6f9dff 60%, var(--violet) 100%);
  box-shadow: 0 0 12px rgba(34, 230, 255, 0.55);
}

.hud-shield {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(122, 92, 255, 0.5);
  background: rgba(50, 30, 110, 0.3);
  font-family: var(--font-mono);
  font-size: 11px;
  color: #cfc4ff;
}

.shield-pip {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  transform: rotate(45deg);
  background: var(--violet);
  box-shadow: 0 0 8px rgba(122, 92, 255, 0.9);
}

.hud-center {
  text-align: center;
  flex: 1;
  padding-top: 2px;
}

.hud-timer {
  font-family: var(--font-mono);
  font-size: clamp(22px, 2.4vw, 32px);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: #f2fbff;
  text-shadow: 0 0 18px rgba(34, 230, 255, 0.5);
}

.hud-timer-label {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.24em;
  color: var(--cyan);
  opacity: 0.85;
}

.hud-wave {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.hud-wave strong {
  color: var(--text-soft);
  font-size: 11px;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 18px;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.hud-stat strong {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.hud-pause {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(8, 18, 32, 0.72);
  color: var(--text);
  pointer-events: auto;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}

.hud-pause:hover {
  border-color: var(--cyan);
  background: rgba(16, 34, 56, 0.9);
}

.hud-pause:active {
  transform: scale(0.94);
}

/* Boss bar */
.boss-bar {
  position: absolute;
  top: calc(78px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: min(540px, 74vw);
  text-align: center;
}

.boss-bar-label {
  display: block;
  margin-bottom: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.34em;
  color: var(--magenta);
  text-shadow: 0 0 12px rgba(255, 62, 165, 0.6);
}

.boss-bar-track {
  position: relative;
  display: block;
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 62, 165, 0.4);
  background: rgba(3, 9, 18, 0.85);
  overflow: hidden;
}

.boss-bar-track span {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--magenta), var(--amber));
  box-shadow: 0 0 14px rgba(255, 62, 165, 0.65);
  transition: transform 120ms linear;
}

/* HUD bottom */
.hud-xp-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(330px, 40vw);
  min-width: 150px;
}

.hud-level {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: rgba(8, 18, 32, 0.7);
}

.hud-level strong {
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--cyan);
}

.hud-xp-wrap .bar {
  flex: 1;
}

.hud-xp-text {
  font-family: var(--font-mono);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.hud-combo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 184, 77, 0.4);
  background: rgba(40, 26, 8, 0.42);
  animation: combo-pop 180ms var(--ease);
}

.hud-combo[hidden] {
  display: none !important;
}

.combo-mult {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--amber);
  text-shadow: 0 0 14px rgba(255, 184, 77, 0.6);
}

.combo-count {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: rgba(255, 210, 150, 0.8);
}

@keyframes combo-pop {
  from { transform: scale(0.86); opacity: 0.4; }
  to { transform: none; opacity: 1; }
}

.hud-dash {
  flex: 0 0 auto;
}

.dash-ring {
  --p: 1;
  position: relative;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: conic-gradient(var(--cyan) calc(var(--p) * 360deg), rgba(120, 200, 235, 0.16) 0);
  filter: drop-shadow(0 0 10px rgba(34, 230, 255, 0.28));
}

.dash-ring::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #0a1728, #050b16 70%);
  border: 1px solid var(--line);
}

.dash-label {
  position: relative;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text-soft);
}

.dash-ring.is-ready .dash-label {
  color: var(--cyan);
}

/* --------------------------------------------------------------------------
   13. Overlays (level-up / pause / results)
   -------------------------------------------------------------------------- */
.overlay-layer {
  z-index: 30;
  display: grid;
  place-items: center;
  padding:
    calc(20px + env(safe-area-inset-top, 0px))
    calc(16px + env(safe-area-inset-right, 0px))
    calc(20px + env(safe-area-inset-bottom, 0px))
    calc(16px + env(safe-area-inset-left, 0px));
  background:
    radial-gradient(70% 60% at 50% 30%, rgba(10, 30, 50, 0.5), transparent 75%),
    rgba(2, 6, 12, 0.66);
  -webkit-backdrop-filter: blur(5px) saturate(115%);
  backdrop-filter: blur(5px) saturate(115%);
  overflow-y: auto;
  animation: overlay-fade 200ms var(--ease) both;
}

@keyframes overlay-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-panel {
  position: relative;
  width: min(760px, 100%);
  padding: clamp(22px, 4vw, 38px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line-strong);
  background:
    linear-gradient(180deg, rgba(11, 24, 42, 0.96), rgba(5, 11, 20, 0.98));
  box-shadow:
    0 40px 120px -30px rgba(0, 0, 0, 0.95),
    0 0 80px -30px rgba(34, 230, 255, 0.42);
  text-align: center;
  overflow: hidden;
}

.overlay-panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 15%;
  right: 15%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--cyan), var(--magenta), transparent);
}

.overlay-panel--levelup {
  width: min(900px, 100%);
}

.overlay-kicker {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  color: var(--magenta);
  text-transform: uppercase;
}

.overlay-kicker--win {
  color: var(--amber);
}

.overlay-title {
  margin-top: 8px;
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.05;
  text-transform: uppercase;
  background: linear-gradient(100deg, #ffffff, var(--cyan) 65%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay-title--danger {
  background: linear-gradient(100deg, #ffffff, var(--magenta) 60%, var(--amber) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay-title--win {
  background: linear-gradient(100deg, #ffffff, var(--amber) 50%, var(--cyan) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay-sub {
  margin-top: 10px;
  font-size: 13.5px;
  color: var(--muted);
}

.overlay-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 24px;
}

.overlay-actions .btn--ghost {
  border-color: var(--line);
}

/* Upgrade cards */
.upgrade-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.upgrade-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 16px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(16, 32, 52, 0.72), rgba(7, 15, 27, 0.88));
  color: var(--text);
  text-align: left;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
  overflow: hidden;
}

.upgrade-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(80% 60% at 50% 0%, rgba(34, 230, 255, 0.14), transparent 70%);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
  pointer-events: none;
}

.upgrade-card:hover,
.upgrade-card:focus-visible {
  transform: translateY(-3px);
  border-color: var(--cyan);
  box-shadow: 0 16px 36px -20px rgba(34, 230, 255, 0.9);
}

.upgrade-card:hover::before,
.upgrade-card:focus-visible::before {
  opacity: 1;
}

.upgrade-card:active {
  transform: translateY(-1px) scale(0.99);
}

.upgrade-card[hidden] {
  display: none !important;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-rarity {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cyan);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(34, 230, 255, 0.35);
  background: rgba(34, 230, 255, 0.08);
}

.upgrade-card[data-rarity="rare"] .card-rarity {
  color: var(--violet);
  border-color: rgba(122, 92, 255, 0.45);
  background: rgba(122, 92, 255, 0.12);
}

.upgrade-card[data-rarity="epic"] .card-rarity {
  color: var(--amber);
  border-color: rgba(255, 184, 77, 0.45);
  background: rgba(255, 184, 77, 0.12);
}

.card-key {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: rgba(3, 9, 18, 0.8);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-soft);
}

.card-icon {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin: 2px 0 2px;
  border-radius: 13px;
  border: 1px solid var(--line-strong);
  background: radial-gradient(circle at 30% 25%, rgba(34, 230, 255, 0.28), rgba(8, 18, 32, 0.9));
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--cyan);
  box-shadow: inset 0 0 18px rgba(34, 230, 255, 0.12);
}

.upgrade-card[data-rarity="rare"] .card-icon {
  background: radial-gradient(circle at 30% 25%, rgba(122, 92, 255, 0.32), rgba(8, 18, 32, 0.9));
  color: #c9c0ff;
}

.upgrade-card[data-rarity="epic"] .card-icon {
  background: radial-gradient(circle at 30% 25%, rgba(255, 184, 77, 0.32), rgba(8, 18, 32, 0.9));
  color: #ffe0a8;
}

.card-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #f2fbff;
}

.card-desc {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
  min-height: 36px;
}

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding-top: 6px;
  border-top: 1px dashed rgba(120, 200, 235, 0.14);
}

.card-level {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-soft);
}

/* Result stats */
.result-record {
  display: inline-block;
  margin-top: 12px;
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 184, 77, 0.5);
  background: rgba(60, 42, 12, 0.35);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.24em;
  color: var(--amber);
  animation: record-pulse 1200ms ease-in-out infinite;
}

@keyframes record-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 184, 77, 0.35); }
  50% { box-shadow: 0 0 0 7px rgba(255, 184, 77, 0); }
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 22px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(5, 13, 24, 0.55);
}

.result-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 2px;
}

.result-stat span {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
}

.result-stat strong {
  font-family: var(--font-mono);
  font-size: clamp(15px, 2vw, 20px);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.result-stat--best strong {
  color: var(--amber);
  text-shadow: 0 0 12px rgba(255, 184, 77, 0.5);
}

/* --------------------------------------------------------------------------
   14. Touch controls (functional basic — mobile padding in phase 2B)
   -------------------------------------------------------------------------- */
.touch-controls {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 14;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  padding:
    0
    calc(22px + env(safe-area-inset-right, 0px))
    calc(22px + env(safe-area-inset-bottom, 0px))
    calc(22px + env(safe-area-inset-left, 0px));
  pointer-events: none;
}

.touch-controls[hidden] {
  display: none !important;
}

.joystick {
  position: relative;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 1px solid rgba(34, 230, 255, 0.3);
  background: radial-gradient(circle, rgba(34, 230, 255, 0.08), rgba(4, 10, 20, 0.42) 70%);
  pointer-events: auto;
  touch-action: none;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  border: 1px solid rgba(34, 230, 255, 0.55);
  background: radial-gradient(circle at 35% 30%, rgba(34, 230, 255, 0.6), rgba(10, 30, 50, 0.9));
  box-shadow: 0 0 18px rgba(34, 230, 255, 0.35);
  pointer-events: none;
}

.touch-dash {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 1px solid rgba(255, 62, 165, 0.55);
  background: radial-gradient(circle at 35% 30%, rgba(255, 62, 165, 0.4), rgba(30, 8, 22, 0.85));
  color: #ffd7ea;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  pointer-events: auto;
  touch-action: none;
}

.touch-dash:active {
  transform: scale(0.95);
}

@media (pointer: coarse) {
  .touch-controls:not([hidden]) {
    display: flex;
  }

  .hud-bottom {
    padding-bottom: 122px;
  }

  .hud-dash {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   15. HUD responsive
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
  .game-hud {
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
  }

  .hud-left {
    width: 40vw;
    min-width: 120px;
  }

  .hud-right {
    gap: 12px;
  }

  .hud-stat strong {
    font-size: 15px;
  }

  .hud-timer {
    font-size: 22px;
  }

  .hud-wave {
    font-size: 9px;
  }

  .hud-xp-wrap {
    width: 48vw;
    min-width: 120px;
  }

  .dash-ring {
    width: 56px;
    height: 56px;
  }

  .upgrade-cards {
    grid-template-columns: 1fr;
    max-height: 56dvh;
    overflow-y: auto;
    padding: 2px;
  }

  .upgrade-card {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
  }

  .card-top {
    order: 0;
    width: 100%;
  }

  .card-icon {
    order: 1;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
  }

  .card-name {
    order: 2;
    flex: 1;
  }

  .card-desc {
    order: 3;
    flex-basis: 100%;
    min-height: 0;
  }

  .card-foot {
    order: 4;
    width: 100%;
  }

  .result-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .result-stat--best {
    grid-column: 1 / -1;
  }

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

@media (max-width: 380px) {
  .hud-stat:first-child {
    display: none;
  }

  .boss-bar {
    width: 82vw;
  }

  .combo-mult {
    font-size: 17px;
  }
}

@media (max-height: 520px) {
  .overlay-layer {
    align-items: start;
  }

  .overlay-panel {
    padding: 18px;
  }

  .overlay-title {
    font-size: 24px;
  }

  .overlay-sub {
    display: none;
  }

  .result-stats {
    margin-top: 12px;
    padding: 10px;
  }

  .overlay-actions {
    margin-top: 14px;
  }
}

/* ==========================================================================
   PHASE 2B — HUD polish, audio-era juice visuals, mobile controls, a11y
   ========================================================================== */

/* --------------------------------------------------------------------------
   16. HUD refinement
   -------------------------------------------------------------------------- */
@keyframes hud-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.game-hud {
  animation: hud-in 280ms var(--ease) both;
}

.hud-top {
  gap: clamp(6px, 1.4vw, 18px);
}

.hud-left {
  width: min(300px, 31vw);
  min-width: 118px;
}

.hud-center {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
  max-width: 46vw;
  padding-top: 0;
}

.hud-timer-label {
  order: 0;
  margin: 0 0 1px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 8.5px;
  letter-spacing: 0.16em;
  color: var(--cyan);
  opacity: 0.92;
}

.hud-timer {
  order: 1;
  font-size: clamp(26px, 2.7vw, 36px);
  line-height: 0.98;
}

.hud-wave {
  order: 2;
  margin-top: 2px;
  font-size: 9px;
  letter-spacing: 0.16em;
}

.hud-wave strong {
  font-size: 10px;
}

.hud-right {
  gap: clamp(7px, 1.2vw, 16px);
  flex: 0 0 auto;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(8, 18, 32, 0.82), rgba(4, 11, 21, 0.72));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  min-width: 44px;
}

.hud-stat-label {
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1.2;
}

.hud-stat-value {
  font-family: var(--font-mono);
  font-size: clamp(15px, 1.4vw, 19px);
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.hud-stat-divider {
  width: 1px;
  height: 22px;
  background: var(--line);
  flex: 0 0 auto;
}

.hud-pause {
  width: 44px;
  height: 44px;
  margin-left: 2px;
}

.hud-label,
.hud-hp-text,
.hud-stat-label,
.hud-stat-value,
.hud-timer,
.hud-timer-label,
.hud-wave,
.hud-xp-text,
.hud-xp-label,
.hud-level strong,
.hud-level-label,
.dash-label,
.boss-bar-label {
  text-shadow: 0 1px 5px rgba(2, 6, 12, 0.95), 0 0 12px rgba(2, 6, 12, 0.72);
}

/* XP + level — compact card */
.hud-xp-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(360px, 34vw);
  min-width: 190px;
  padding: 7px 11px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(8, 18, 32, 0.82), rgba(4, 11, 21, 0.72));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.hud-level {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: rgba(4, 11, 21, 0.8);
  flex: 0 0 auto;
}

.hud-level-label {
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.hud-level strong {
  font-family: var(--font-mono);
  font-size: 18px;
  line-height: 1;
  color: var(--cyan);
}

.hud-xp-mid {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hud-xp-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}

.hud-xp-label {
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.hud-xp-text {
  font-size: 9.5px;
  color: var(--text-soft);
}

.bar--xp {
  height: 7px;
}

/* Combo floats above the bottom bar, never over DASH */
.hud-bottom {
  position: relative;
  align-items: flex-end;
  gap: 12px;
}

.hud-combo {
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 2;
  transform: translateX(-50%);
  animation: combo-pop-2 200ms var(--ease);
}

.hud-combo.is-pop {
  animation: combo-pop-2 180ms var(--ease);
}

@keyframes combo-pop-2 {
  from { opacity: 0.35; transform: translateX(-50%) scale(0.84); }
  to { opacity: 1; transform: translateX(-50%) scale(1); }
}

/* --------------------------------------------------------------------------
   17. Player readability, low HP, boss warning
   -------------------------------------------------------------------------- */
.low-hp {
  position: fixed;
  inset: 0;
  z-index: 11;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 52%, rgba(255, 30, 70, 0.26) 100%);
  box-shadow: inset 0 0 120px rgba(255, 30, 70, 0.24);
  transition: opacity 350ms var(--ease);
}

.low-hp.is-low {
  opacity: 0.58;
  animation: low-hp-beat 1.15s ease-in-out infinite;
}

@keyframes low-hp-beat {
  0%, 100% { opacity: 0.48; }
  42% { opacity: 0.9; }
  55% { opacity: 0.62; }
}

body.reduce-motion .low-hp.is-low,
body.qa-mode .low-hp.is-low {
  animation: none;
  opacity: 0.5;
}

.boss-alert {
  position: fixed;
  top: 19%;
  left: 50%;
  z-index: 24;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 30px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 62, 165, 0.55);
  background: rgba(24, 6, 16, 0.78);
  box-shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.9), 0 0 40px -14px rgba(255, 62, 165, 0.7);
  opacity: 0;
  transform: translate(-50%, -10px) scale(0.96);
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
  pointer-events: none;
  text-align: center;
}

.boss-alert.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.boss-alert-line {
  width: 110px;
  height: 2px;
  margin-bottom: 3px;
  background: linear-gradient(90deg, transparent, var(--magenta), transparent);
  box-shadow: 0 0 12px rgba(255, 62, 165, 0.8);
}

.boss-alert strong {
  font-family: var(--font-sans);
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 900;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  color: var(--magenta);
  text-shadow: 0 0 22px rgba(255, 62, 165, 0.7);
}

.boss-alert-sub {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.28em;
  color: rgba(255, 200, 220, 0.85);
}

/* --------------------------------------------------------------------------
   18. Overlays — cheaper blur, richer panels & cards
   -------------------------------------------------------------------------- */
.overlay-layer {
  background:
    radial-gradient(70% 60% at 50% 30%, rgba(10, 30, 50, 0.45), transparent 75%),
    rgba(2, 6, 12, 0.82);
  -webkit-backdrop-filter: blur(2px) saturate(110%);
  backdrop-filter: blur(2px) saturate(110%);
}

.overlay-panel {
  box-shadow:
    0 40px 110px -34px rgba(0, 0, 0, 0.95),
    0 0 70px -34px rgba(34, 230, 255, 0.45);
}

.upgrade-card {
  animation: card-in 300ms var(--ease) both;
}

.upgrade-card:nth-child(2) { animation-delay: 55ms; }
.upgrade-card:nth-child(3) { animation-delay: 110ms; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.upgrade-card[data-rarity="rare"] {
  border-color: rgba(122, 92, 255, 0.46);
}

.upgrade-card[data-rarity="epic"] {
  border-color: rgba(255, 184, 77, 0.52);
  box-shadow: inset 0 0 34px rgba(255, 184, 77, 0.055);
}

.upgrade-card.is-picked {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px rgba(255, 184, 77, 0.45), 0 18px 40px -18px rgba(255, 184, 77, 0.7);
  transform: translateY(-3px) scale(1.01);
}

.card-icon {
  font-size: 0;
}

.card-icon svg {
  width: 26px;
  height: 26px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --------------------------------------------------------------------------
   19. Touch controls — complete & non-overlapping
   -------------------------------------------------------------------------- */
.touch-controls {
  z-index: 20;
  gap: 14px;
  padding:
    0
    calc(22px + env(safe-area-inset-right, 0px))
    calc(22px + env(safe-area-inset-bottom, 0px))
    calc(22px + env(safe-area-inset-left, 0px));
}

body.touch-mode .touch-controls:not([hidden]) {
  display: flex;
}

.joystick {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: 1px solid rgba(34, 230, 255, 0.4);
  background: radial-gradient(circle at 50% 45%, rgba(34, 230, 255, 0.1), rgba(3, 9, 18, 0.5) 72%);
  box-shadow: inset 0 0 34px rgba(34, 230, 255, 0.08), 0 0 22px rgba(34, 230, 255, 0.12);
}

.joystick-ring {
  position: absolute;
  inset: 11px;
  border-radius: 50%;
  border: 1px dashed rgba(34, 230, 255, 0.24);
  pointer-events: none;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  border: 1px solid rgba(34, 230, 255, 0.7);
  background: radial-gradient(circle at 35% 30%, rgba(120, 245, 255, 0.75), rgba(8, 28, 46, 0.95));
  box-shadow: 0 0 18px rgba(34, 230, 255, 0.45);
  pointer-events: none;
}

.touch-dash {
  --p: 1;
  position: relative;
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: conic-gradient(var(--cyan) calc(var(--p) * 360deg), rgba(120, 200, 235, 0.2) 0);
  color: #eafcff;
  box-shadow: 0 0 22px rgba(34, 230, 255, 0.22);
  touch-action: none;
  transition: transform 120ms var(--ease), filter 120ms var(--ease);
}

.touch-dash::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 1px solid rgba(34, 230, 255, 0.55);
  background: radial-gradient(circle at 35% 30%, rgba(34, 230, 255, 0.42), rgba(5, 14, 26, 0.95) 72%);
}

.touch-dash-label {
  position: relative;
  z-index: 1;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.touch-dash.is-ready {
  filter: drop-shadow(0 0 12px rgba(34, 230, 255, 0.75));
}

.touch-dash:active {
  transform: scale(0.95);
}

body.touch-mode .hud-dash {
  display: none;
}

body.touch-mode .hud-bottom {
  padding-bottom: 150px;
}

body.touch-mode .hud-combo {
  bottom: 200px;
}

/* --------------------------------------------------------------------------
   20. HUD responsive refinements
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
  .hud-top {
    gap: 6px;
  }

  .hud-left {
    width: 35vw;
    min-width: 104px;
  }

  .hud-stats {
    gap: 6px;
    padding: 4px 7px;
    border-radius: 10px;
  }

  .hud-stat {
    min-width: 34px;
  }

  .hud-stat-label {
    font-size: 7.5px;
    letter-spacing: 0.06em;
  }

  .hud-stat-value {
    font-size: 14px;
  }

  .hud-stat-divider {
    height: 16px;
  }

  .hud-pause {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }

  .hud-timer {
    font-size: 22px;
  }

  .hud-timer-label {
    font-size: 7.5px;
    letter-spacing: 0.08em;
  }

  .hud-wave {
    font-size: 8px;
  }

  .hud-xp-wrap {
    width: 50vw;
    min-width: 168px;
    padding: 6px 9px;
  }

  .hud-level strong {
    font-size: 16px;
  }

  .hud-combo {
    bottom: 70px;
    padding: 3px 10px;
  }

  .combo-mult {
    font-size: 16px;
  }

  .combo-count {
    font-size: 8.5px;
  }
}

@media (max-width: 400px) {
  .hud-left {
    width: 33vw;
    min-width: 100px;
  }

  .hud-stats {
    gap: 4px;
    padding: 4px 6px;
  }

  .hud-stat {
    min-width: 30px;
  }

  .hud-stat-label {
    font-size: 7.2px;
    letter-spacing: 0.03em;
  }

  .hud-stat-value {
    font-size: 13px;
  }

  .hud-pause {
    width: 36px;
    height: 36px;
  }

  .hud-timer {
    font-size: 20px;
  }

  .hud-timer-label {
    font-size: 7.2px;
    letter-spacing: 0.03em;
  }

  .hud-xp-wrap {
    min-width: 164px;
  }
}

@media (max-width: 340px) {
  .hud-stat:first-child,
  .hud-stat-divider {
    display: none;
  }

  .hud-left {
    min-width: 92px;
    width: 31vw;
  }

  .hud-xp-wrap {
    min-width: 158px;
  }
}

@media (max-height: 520px) {
  body.touch-mode .hud-bottom {
    padding-bottom: 124px;
  }

  body.touch-mode .joystick {
    width: 104px;
    height: 104px;
  }

  body.touch-mode .joystick-knob {
    width: 48px;
    height: 48px;
    margin: -24px 0 0 -24px;
  }

  body.touch-mode .touch-dash {
    width: 74px;
    height: 74px;
  }

  body.touch-mode .hud-combo {
    bottom: 146px;
  }
}

body.reduce-motion .boss-alert,
body.qa-mode .boss-alert {
  transition: none;
}

body.reduce-motion .upgrade-card,
body.qa-mode .upgrade-card,
body.reduce-motion .hud-combo,
body.qa-mode .hud-combo {
  animation: none !important;
}

/* ==========================================================================
   FIX ROUND 1 — QA P1/P2/P3
   ========================================================================== */

/* 0) Remove expensive full-screen compositing on animated canvas */
.fx-grain {
  display: none !important;
}

.fx-scanlines {
  mix-blend-mode: normal;
  opacity: 0.32;
}

.chip,
.menu-card {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.chip {
  background: rgba(8, 18, 32, 0.86);
}

.menu-card {
  background: linear-gradient(180deg, rgba(11, 23, 40, 0.95), rgba(5, 11, 20, 0.97));
}

/* 1) P1 — level-up scrollable + compact at low heights */
.overlay-layer {
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(34, 230, 255, 0.4) transparent;
}

.overlay-panel--levelup {
  overflow: visible;
}

.overlay-layer::-webkit-scrollbar {
  width: 8px;
}

.overlay-layer::-webkit-scrollbar-thumb {
  background: rgba(34, 230, 255, 0.35);
  border-radius: 999px;
}

@media (max-width: 720px) {
  .upgrade-cards {
    max-height: none;
    overflow: visible;
  }
}

@media (max-height: 720px) {
  .overlay-layer {
    place-items: start center;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .overlay-panel {
    margin: 0 auto;
  }

  #levelup .overlay-panel {
    padding: 14px 12px 12px;
    border-radius: 18px;
  }

  #levelup .overlay-kicker {
    font-size: 9px;
    letter-spacing: 0.3em;
  }

  #levelup .overlay-title {
    margin-top: 5px;
    font-size: clamp(18px, 5.2vw, 24px);
    line-height: 1.08;
    letter-spacing: 0.02em;
  }

  #levelup .overlay-sub {
    margin-top: 6px;
    font-size: 11.5px;
    line-height: 1.35;
  }

  #levelup .upgrade-cards {
    grid-template-columns: 1fr;
    gap: 7px;
    margin-top: 10px;
    max-height: none;
    overflow: visible;
  }

  #levelup .upgrade-card {
    padding: 9px 11px;
    gap: 5px 9px;
    border-radius: 12px;
  }

  #levelup .card-top {
    width: 100%;
  }

  #levelup .card-icon {
    width: 34px;
    height: 34px;
    margin: 0;
    border-radius: 10px;
  }

  #levelup .card-icon svg {
    width: 21px;
    height: 21px;
  }

  #levelup .card-name {
    font-size: 13.5px;
  }

  #levelup .card-desc {
    min-height: 0;
    font-size: 11.5px;
    line-height: 1.32;
  }

  #levelup .card-foot {
    padding-top: 4px;
  }

  #levelup .card-level {
    font-size: 9px;
  }
}

@media (max-height: 620px) {
  #levelup .overlay-sub {
    display: none;
  }
}

/* 2) P2 — menu compact for short viewports (568/600/640/660) */
@media (max-height: 660px) {
  .screen {
    align-items: center;
    padding-top: calc(58px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .menu-card {
    padding: 14px 16px 12px;
    border-radius: 20px;
  }

  .logo-eyebrow {
    margin-bottom: 3px;
    font-size: 8px;
    letter-spacing: 0.32em;
  }

  .logo {
    font-size: clamp(30px, 9vw, 40px);
    line-height: 0.84;
  }

  .logo-survivor {
    font-size: 0.62em;
    letter-spacing: 0.12em;
    text-indent: 0.12em;
  }

  .menu-subtitle {
    margin-top: 6px;
    font-size: 11px;
    line-height: 1.35;
  }

  .best-chip {
    margin: 8px auto 2px;
    padding: 4px 12px;
    gap: 7px;
  }

  .best-label {
    font-size: 9px;
    letter-spacing: 0.16em;
  }

  .best-value {
    font-size: 15px;
  }

  .menu-nav {
    margin-top: 10px;
    gap: 7px;
  }

  .menu-nav-secondary {
    gap: 6px;
  }

  .btn {
    min-height: 40px;
    padding: 7px 12px;
    font-size: 11.5px;
  }

  .btn--primary {
    min-height: 44px;
    font-size: 14px;
    letter-spacing: 0.18em;
  }

  .menu-hint {
    margin-top: 8px;
    font-size: 8.5px;
    line-height: 1.3;
    letter-spacing: 0.02em;
  }

  .topbar {
    padding-top: calc(7px + env(safe-area-inset-top, 0px));
    padding-bottom: 5px;
  }

  .chip {
    min-height: 34px;
    padding: 5px 10px;
    font-size: 11.5px;
    gap: 6px;
  }

  .brand-mini {
    display: none;
  }
}

/* 3) P2 — readable mobile HUD labels */
@media (max-width: 430px), (max-height: 520px) {
  .hud-label,
  .hud-timer-label,
  .hud-stat-label,
  .hud-xp-label,
  .hud-level-label,
  .hud-xp-text,
  .hud-wave,
  .combo-count {
    font-size: 10px;
    letter-spacing: 0.02em;
    line-height: 1.25;
  }

  .hud-timer {
    font-size: 20px;
  }

  .hud-stat {
    min-width: 36px;
  }

  .hud-stat-value {
    font-size: 14px;
  }

  .hud-stats {
    gap: 5px;
    padding: 4px 7px;
  }

  .hud-stat-divider {
    height: 18px;
  }

  .hud-wave strong {
    font-size: 10px;
  }

  .hud-xp-text {
    font-size: 10px;
  }

  .hud-xp-wrap {
    gap: 7px;
  }

  .hud-level strong {
    font-size: 16px;
  }

  .hud-combo .combo-mult {
    font-size: 17px;
  }
}

@media (max-width: 340px) {
  .hud-stat:first-child,
  .hud-stat-divider {
    display: none;
  }
}

/* 4) P3 — settings compact on short viewports */
@media (max-height: 660px) {
  .dialog {
    max-height: calc(100dvh - 12px);
  }

  .dialog-head {
    padding: 10px 14px 8px;
  }

  .dialog-title {
    font-size: 17px;
  }

  .dialog-body {
    padding: 10px 14px 14px;
  }

  .dialog-section {
    margin-top: 8px;
    padding-top: 6px;
  }

  .section-title {
    margin-bottom: 7px;
    font-size: 10px;
    letter-spacing: 0.18em;
  }

  .setting-row {
    padding: 6px 0;
    gap: 8px;
  }

  .setting-name {
    font-size: 12.5px;
  }

  .setting-hint {
    font-size: 10.5px;
    line-height: 1.3;
  }

  .setting-control {
    flex: 0 0 auto;
    width: min(190px, 100%);
    gap: 8px;
  }

  .range {
    height: 20px;
  }

  .range-out {
    min-width: 32px;
    font-size: 12px;
  }

  .seg-btn {
    min-height: 32px;
    padding: 5px 11px;
    font-size: 12px;
  }

  .switch {
    width: 46px;
    height: 27px;
  }

  .switch::after {
    width: 19px;
    height: 19px;
  }

  .switch[aria-checked="true"]::after {
    transform: translateX(19px);
  }

  .btn--sm {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 11px;
  }
}

/* 5) Short landscape menu: keep side-by-side secondary buttons */
@media (max-height: 520px) and (min-width: 640px) {
  .menu-nav-secondary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-height: 660px) {
  .dialog-section--data .setting-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .dialog-section--data .delete-actions {
    justify-content: flex-end;
  }
}

@media (max-height: 620px) {
  .setting-hint {
    display: none;
  }
}

/* Keep level-up 3 columns in landscape / wide short viewports */
@media (max-height: 720px) and (min-width: 721px) {
  #levelup .upgrade-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #levelup .upgrade-card {
    padding: 12px;
    gap: 6px;
  }

  #levelup .card-icon {
    width: 38px;
    height: 38px;
  }
}
