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

:root {
  --bg: #070b16;
  --cream: #e8eef8;
  --muted: rgba(232, 238, 248, 0.55);
  --purple: #a78bfa;
  --gold: #fbbf24;
  --cyan: #3df0ff;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 70% 45% at 50% -5%, rgba(124, 58, 237, 0.22), transparent 55%),
    radial-gradient(ellipse 50% 40% at 90% 80%, rgba(61, 240, 255, 0.08), transparent 50%),
    var(--bg);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: max(0.45rem, env(safe-area-inset-top)) 0.85rem 0.3rem;
  flex-shrink: 0;
  z-index: 5;
}

.home-link {
  color: #7dd3fc;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.06em;
}

.logo {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.logo span {
  color: var(--purple);
}

.version {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  opacity: 0.45;
  color: #86efac;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.65rem;
  justify-content: center;
  padding: 0.15rem 0.65rem 0.35rem;
  flex-shrink: 0;
  z-index: 5;
}

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

.stat {
  min-width: 3.6rem;
  padding: 0.28rem 0.55rem;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
}

.stat .label {
  display: block;
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.5;
  margin-bottom: 0.08rem;
}

.stat strong {
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

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

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.5rem;
}

#game {
  width: min(1100px, 100%);
  height: auto;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 0.75rem;
  border: 1px solid rgba(167, 139, 250, 0.25);
  background: #0c1224;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* Virtual stick */
.joy-pad {
  position: absolute;
  left: max(0.75rem, env(safe-area-inset-left));
  bottom: max(0.85rem, env(safe-area-inset-bottom));
  width: 7.25rem;
  height: 7.25rem;
  border-radius: 50%;
  background: rgba(8, 16, 28, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.35);
  touch-action: none;
  z-index: 8;
  display: grid;
  place-items: center;
  opacity: 0.72;
}

.joy-pad[hidden] {
  display: none !important;
}

.joy-pad:active {
  opacity: 0.92;
}

.joy-knob {
  width: 2.85rem;
  height: 2.85rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c4b5fd, #7c3aed 65%, #5b21b6);
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  transform: translate(0, 0);
  will-change: transform;
}

.boost-btn {
  position: absolute;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(1.1rem, env(safe-area-inset-bottom));
  z-index: 8;
  width: 4.6rem;
  height: 4.6rem;
  border-radius: 50%;
  border: 2px solid rgba(251, 191, 36, 0.55);
  background: radial-gradient(circle at 35% 30%, #fde68a, #f59e0b 70%, #b45309);
  color: #1c1917;
  font: inherit;
  font-weight: 900;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
}

.boost-btn[hidden] {
  display: none !important;
}

.boost-btn[aria-pressed="true"] {
  transform: scale(0.94);
  filter: brightness(1.12);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.55);
}

.hint {
  flex-shrink: 0;
  text-align: center;
  font-size: 0.68rem;
  opacity: 0.4;
  padding: 0.25rem 0.75rem max(0.45rem, env(safe-area-inset-bottom));
}

/* Overlays */
.overlay {
  position: fixed;
  inset: var(--rg-bar) 0 0 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(5, 8, 16, 0.72);
  backdrop-filter: blur(5px);
}

.overlay[hidden] {
  display: none !important;
}

.panel {
  width: min(26rem, 100%);
  padding: 1.35rem 1.2rem 1.25rem;
  border-radius: 1rem;
  border: 1px solid rgba(167, 139, 250, 0.35);
  background: linear-gradient(165deg, #161b2e, #0c101c);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.panel.small {
  width: min(16rem, 100%);
  padding: 1.2rem;
}

.eyebrow {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #7dd3fc;
  opacity: 0.85;
  margin-bottom: 0.35rem;
}

.panel h1,
.panel h2 {
  font-size: 1.55rem;
  font-weight: 800;
  color: #e9d5ff;
  margin-bottom: 0.4rem;
}

.subtitle {
  font-size: 0.88rem;
  line-height: 1.45;
  opacity: 0.7;
  margin-bottom: 1rem;
}

.final-score {
  font-size: 1.05rem;
  margin-bottom: 0.65rem;
  color: #fde68a;
  font-weight: 700;
}

.final-score[hidden] {
  display: none !important;
}

/* Leaderboard */
.leaderboard {
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.55rem 0.55rem;
  border-radius: 0.65rem;
  border: 1px solid rgba(167, 139, 250, 0.28);
  background: rgba(0, 0, 0, 0.28);
  text-align: center;
}

.leaderboard[hidden] {
  display: none !important;
}

.leaderboard h3 {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #c4b5fd;
  margin-bottom: 0.15rem;
}

.lb-sub {
  font-size: 0.65rem;
  opacity: 0.5;
  margin-bottom: 0.45rem;
}

.lb-table-wrap {
  overflow-x: auto;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.lb-table th {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.5;
  font-weight: 650;
  padding: 0.2rem 0.25rem 0.35rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.lb-table td {
  padding: 0.32rem 0.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: rgba(232, 238, 248, 0.88);
}

.lb-table tbody tr:last-child td {
  border-bottom: none;
}

.lb-table tr.is-current td {
  color: #fde68a;
  font-weight: 750;
  background: rgba(251, 191, 36, 0.08);
}

.lb-table tr.is-best td:first-child {
  color: #fbbf24;
}

.lb-empty {
  font-size: 0.75rem;
  opacity: 0.45;
  padding: 0.45rem 0.25rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.btn {
  min-width: 6.5rem;
  padding: 0.55rem 0.9rem;
  border-radius: 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
  color: inherit;
  font: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn.primary {
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
  border-color: transparent;
  color: #fff;
}

.btn.ghost {
  background: transparent;
}

.hint-keys {
  font-size: 0.72rem;
  opacity: 0.5;
  margin-bottom: 0.75rem;
}

kbd {
  display: inline-block;
  min-width: 1.15rem;
  padding: 0.06rem 0.28rem;
  border-radius: 0.25rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.68rem;
  font-weight: 700;
  text-align: center;
}

.feature-list {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem 0.55rem;
  font-size: 0.75rem;
  opacity: 0.7;
  text-align: left;
}

@media (max-width: 640px) {
  .top-bar {
    padding: max(0.3rem, env(safe-area-inset-top)) 0.5rem 0.2rem;
  }

  .logo {
    font-size: 0.8rem;
  }

  .hud {
    gap: 0.28rem;
    padding: 0.1rem 0.35rem 0.25rem;
  }

  .stat {
    min-width: 3rem;
    padding: 0.2rem 0.4rem;
  }

  .stat strong {
    font-size: 0.88rem;
  }

  .stage {
    padding: 0 0.25rem;
  }

  #game {
    width: 100%;
    max-height: calc(calc(100dvh - var(--rg-bar)) - 9.5rem);
    border-radius: 0.5rem;
  }

  .hint {
    display: none;
  }

  .joy-pad {
    display: grid;
    width: 7.6rem;
    height: 7.6rem;
    opacity: 0.82;
  }

  .boost-btn {
    display: grid;
    place-items: center;
  }

  .feature-list {
    grid-template-columns: 1fr;
  }
}

/* Desktop: stick optional / subtle when fine pointer */
@media (hover: hover) and (pointer: fine) {
  .joy-pad:not([hidden]) {
    opacity: 0.35;
  }

  .joy-pad:hover,
  .joy-pad:active {
    opacity: 0.75;
  }

  .boost-btn:not([hidden]) {
    opacity: 0.55;
  }

  .boost-btn:hover {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .joy-knob,
  .boost-btn {
    transition: none;
  }
}
