*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #080514;
  --panel: #110b26;
  --panel-alt: #1b123b;
  --border: #332266;
  --text: #f2f4ff;
  --muted: #b0b6d9;
  --cyan: #00f0ff;
  --magenta: #ff2a85;
  --amber: #ffe066;
  --emerald: #00ff9f;
  --danger: #ff3b5c;
  --font-ui: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Code", "Consolas", ui-monospace, monospace;
}

html {
  scrollbar-gutter: stable;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

body {
  background: radial-gradient(circle at 50% 0%, #240c4c 0%, var(--bg) 70%);
}

.hidden {
  display: none !important;
}

.hide-cursor,
.hide-cursor * {
  cursor: none !important;
}

/* ================= APP SHELL ================= */
.app-shell {
  height: 100dvh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 6px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ================= TOP BAR ================= */
.top-bar {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 5px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-seal {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(135deg, #2a0c54 0%, #110824 58%, #701046 100%);
  border: 1px solid var(--cyan);
  color: var(--cyan);
  font-weight: 800;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
}

.brand-title {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--text);
  white-space: nowrap;
}

.version-badge {
  flex: 0 0 auto;
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 240, 255, 0.14);
  border: 1px solid rgba(0, 240, 255, 0.45);
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  text-decoration: none;
}

a.version-badge:hover {
  background: rgba(0, 240, 255, 0.24);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.top-btn,
.top-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 9px;
  border-radius: 6px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.top-btn:hover,
.top-link:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

.top-btn.is-active {
  border-color: rgba(0, 240, 255, 0.6);
  color: var(--cyan);
  background: rgba(0, 240, 255, 0.12);
}

.top-btn:focus-visible,
.top-link:focus-visible,
.version-badge:focus-visible,
.corner-mute-btn:focus-visible,
.gear-toggle-btn:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.btn-danger:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* ================= STAGE & CANVAS FRAME ================= */
.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-frame {
  position: relative;
  width: 100%;
  height: 100%;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05020e;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
}

.canvas-frame:fullscreen {
  border: none;
  border-radius: 0;
  background: #03010a;
}

#game-canvas {
  display: block;
  width: min(100cqw, calc(100cqh * 16 / 9));
  height: min(100cqh, calc(100cqw * 9 / 16));
}

/* Subtle Corner Mute Button */
.corner-mute-btn {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 6;
  padding: 5px 10px;
  border-radius: 6px;
  background: rgba(8, 5, 22, 0.8);
  border: 1px solid rgba(0, 240, 255, 0.5);
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.corner-mute-btn:hover {
  background: rgba(16, 10, 42, 0.95);
  border-color: var(--amber);
  color: var(--amber);
}

.corner-mute-btn.is-muted {
  border-color: rgba(255, 59, 92, 0.7);
  color: #ff8099;
}

/* Bottom-Left Now Playing Music Toast (adapted from /cbuc/) */
.music-toast {
  position: absolute;
  bottom: 48px;
  left: 12px;
  z-index: 7;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: min(440px, calc(100% - 28px));
  padding: 7px 12px;
  border-radius: 9px;
  background: rgba(10, 5, 28, 0.92);
  border: 1px solid rgba(0, 240, 255, 0.55);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.56), 0 0 14px rgba(255, 42, 133, 0.18);
  color: var(--text);
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.music-toast.is-visible {
  opacity: 0.96;
  transform: translateY(0);
}

.music-toast-icon {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: rgba(255, 42, 133, 0.18);
  border: 1px solid rgba(255, 42, 133, 0.55);
  color: var(--magenta);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 0.95rem;
  font-weight: 800;
}

.music-toast-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.music-toast-primary {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  min-width: 0;
  font-size: 0.8rem;
  line-height: 1.2;
}

.music-toast-brand {
  color: var(--cyan);
  font-weight: 800;
  letter-spacing: 0.06em;
  white-space: nowrap;
  flex: 0 0 auto;
}

.music-toast-sep {
  color: var(--muted);
  flex: 0 0 auto;
}

.music-toast-track {
  color: #ffffff;
  font-weight: 700;
  white-space: nowrap;
  flex: 0 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}

.music-toast-num {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 240, 255, 0.14);
  border: 1px solid rgba(0, 240, 255, 0.38);
  color: var(--cyan);
}

.music-toast-num:empty {
  display: none;
}

.music-toast-sub {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ================= OVERLAYS ================= */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vh, 22px);
  background: radial-gradient(circle at 50% 35%, rgba(16, 7, 38, 0.62) 0%, rgba(5, 2, 16, 0.84) 100%);
  backdrop-filter: blur(4px);
}

.overlay-title.is-fullscreen-menu {
  padding: clamp(14px, 2.5vh, 28px) clamp(18px, 3vw, 40px);
  background: radial-gradient(ellipse at 50% 16%, #2a1158 0%, #110828 54%, #060312 100%);
  backdrop-filter: none;
}

.title-screen {
  width: 100%;
  height: 100%;
  max-width: 1120px;
  max-height: 100%;
  margin: 0 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: clamp(10px, 1.8vh, 20px);
  padding: clamp(4px, 1vh, 12px) 2px;
  text-align: center;
}

.title-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.modal-card {
  width: min(500px, 94%);
  max-height: 100%;
  overflow-y: auto;
  padding: clamp(14px, 2.4vh, 26px) clamp(16px, 2.6vw, 30px);
  border-radius: 14px;
  background: rgba(12, 7, 30, 0.94);
  border: 1px solid rgba(0, 240, 255, 0.48);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.65), 0 0 28px rgba(255, 42, 133, 0.18);
  text-align: center;
}

.end-card {
  width: min(640px, 95%);
}

.menu-top-row,
.end-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--magenta);
  text-transform: uppercase;
}

.best-pill,
.new-best-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
}

.best-pill {
  background: rgba(255, 224, 102, 0.14);
  border: 1px solid rgba(255, 224, 102, 0.5);
  color: var(--amber);
}

.new-best-pill {
  background: rgba(0, 255, 159, 0.18);
  border: 1px solid var(--emerald);
  color: var(--emerald);
}

.title-logo {
  margin: 2px 0 4px;
  font-size: clamp(2.1rem, 5.2vh, 3.6rem);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.14em;
  line-height: 1.04;
  background: linear-gradient(180deg, #ffffff 0%, #7ef6ff 42%, #ff2a85 78%, #ffe066 100%);
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(255, 42, 133, 0.45));
}

.title-tagline {
  margin: 0 auto;
  max-width: 620px;
  font-size: clamp(0.82rem, 1.65vh, 0.96rem);
  line-height: 1.42;
  color: var(--muted);
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(10px, 1.5vw, 18px);
  text-align: left;
  align-items: stretch;
}

.menu-panel {
  padding: clamp(11px, 1.8vh, 16px) clamp(13px, 1.5vw, 18px);
  border-radius: 10px;
  background: rgba(20, 12, 46, 0.86);
  border: 1px solid rgba(0, 240, 255, 0.32);
  display: flex;
  flex-direction: column;
}

.pyramid-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 7px;
  font-size: 0.79rem;
  color: var(--text);
}

.pyramid-list li {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pyr-tag {
  font-family: var(--font-mono);
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.pyr-day {
  color: var(--amber);
}

.pyr-left {
  color: var(--cyan);
}

.pyr-right {
  color: #ff6aa9;
}

.pyr-sid {
  color: var(--emerald);
}

.panel-heading {
  margin: 0 0 8px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan);
}

.controls-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text);
}

.controls-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.key-group {
  display: inline-flex;
  gap: 4px;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: #1a1338;
  border: 1px solid #4d3b8a;
  color: #f4f7ff;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.35;
}

.gear-toggle-btn {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(14, 9, 36, 0.95);
  border: 1px solid rgba(255, 42, 133, 0.65);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.gear-toggle-btn:hover {
  border-color: var(--cyan);
}

.gear-toggle-btn.is-on {
  border-color: var(--cyan);
  background: rgba(0, 240, 255, 0.14);
}

.gear-toggle-label {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--muted);
}

.gear-toggle-state {
  font-family: var(--font-mono);
  font-size: 0.86rem;
  font-weight: 800;
  color: var(--amber);
}

.gear-toggle-btn.is-on .gear-toggle-state {
  color: var(--cyan);
}

.gear-hint {
  margin: 8px 0 0;
  font-size: 0.75rem;
  line-height: 1.38;
  color: var(--muted);
}

.gear-hint strong {
  color: var(--text);
}

.menu-actions,
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.btn-primary {
  background: linear-gradient(135deg, #ff2a85 0%, #b5179e 55%, #00a8e8 100%);
  border: 1px solid #ff99d6;
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(255, 42, 133, 0.36);
}

.btn-primary:hover {
  transform: translateY(-1px);
  border-color: var(--amber);
}

.btn-primary kbd {
  background: rgba(8, 5, 22, 0.45);
  border-color: rgba(255, 255, 255, 0.45);
}

.btn-keys {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  letter-spacing: 0.01em;
}

.btn-keys kbd {
  padding: 1px 4px;
  font-size: 0.68em;
}

.btn-keys .kbd-sep {
  opacity: 0.72;
  font-size: 0.75em;
  font-weight: 700;
}

.btn-primary:has(.btn-keys) {
  gap: 6px;
  padding-inline: 14px;
}

.btn-secondary {
  background: var(--panel-alt);
  border: 1px solid rgba(0, 240, 255, 0.5);
  color: var(--cyan);
}

.btn-secondary:hover {
  background: rgba(0, 240, 255, 0.14);
}

.btn-danger {
  background: rgba(255, 59, 92, 0.16);
  border: 1px solid rgba(255, 59, 92, 0.65);
  color: #ff99ac;
}

.btn-danger:hover {
  background: rgba(255, 59, 92, 0.28);
  color: #ffffff;
}

.modal-title {
  margin: 6px 0;
  font-size: clamp(1.5rem, 3.6vh, 2.2rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #ffffff;
}

.end-goal .end-title {
  color: var(--amber);
}

.end-timeover .end-title {
  color: var(--magenta);
}

.modal-sub {
  margin: 0 auto 14px;
  max-width: 520px;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stat-box {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(22, 13, 48, 0.86);
  border: 1px solid var(--border);
  text-align: left;
}

.stat-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.stat-val {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--cyan);
}

.stat-stage {
  font-family: var(--font-ui);
  font-size: 0.96rem;
  color: var(--text);
}

.stat-gold {
  color: var(--amber);
}

.route-summary {
  margin-bottom: 16px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(18, 10, 42, 0.72);
  border: 1px solid rgba(0, 240, 255, 0.28);
  text-align: left;
}

.route-label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--magenta);
}

.route-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.route-chip {
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(0, 240, 255, 0.12);
  border: 1px solid rgba(0, 240, 255, 0.35);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 600;
}

.route-arrow {
  color: var(--amber);
  font-size: 0.75rem;
  font-weight: 700;
}

/* ================= BOTTOM LEGEND BAR ================= */
.controls-legend {
  flex: 0 0 auto;
  padding: 5px 12px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.legend-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.legend-sep {
  opacity: 0.45;
}

/* Compact adjustments for 4K @ 300% (1280x585) */
@media (max-height: 620px) {
  .app-shell {
    padding: 4px 10px 5px;
    gap: 4px;
  }

  .top-bar {
    min-height: 36px;
    padding: 4px 10px;
  }

  .controls-legend {
    padding: 3px 10px;
    font-size: 0.7rem;
  }

  .overlay-title.is-fullscreen-menu {
    padding: 8px 18px;
  }

  .title-screen {
    gap: 6px;
    padding: 2px;
  }

  .title-logo {
    font-size: 2rem;
  }

  .title-tagline {
    font-size: 0.78rem;
  }

  .menu-panel {
    padding: 8px 11px;
  }

  .controls-list,
  .pyramid-list {
    gap: 4px;
    font-size: 0.74rem;
  }

  .btn-primary,
  .btn-secondary,
  .btn-danger {
    padding: 7px 16px;
    font-size: 0.82rem;
  }
}

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

@media (max-width: 720px) {
  .menu-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }
}
