:root {
  --bg-deep: #0d1326;
  --glass: rgba(15, 22, 44, 0.62);
  --glass-border: rgba(255, 255, 255, 0.16);
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --gold: #ffd54f;
  --cyan: #5ce1e6;
  --coral: #ff5e78;
  --accent-grad: linear-gradient(135deg, #ffd54f 0%, #ff9f43 100%);
  --font-ui: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.stage {
  position: relative;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* Top HUD */
.hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-center {
  flex: 1;
  justify-content: center;
  min-width: 0;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.24);
}

.stat-pill .label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.stat-pill .value {
  font-size: clamp(0.95rem, 1.8vw, 1.15rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.mult-pill {
  font-weight: 800;
  font-size: 0.92rem;
  color: var(--gold);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.mult-pill[data-mult="3"],
.mult-pill[data-mult="4"] {
  border-color: rgba(92, 225, 230, 0.55);
  color: var(--cyan);
}

.mult-pill[data-mult="5"] {
  border-color: rgba(255, 213, 79, 0.8);
  color: #fff3b0;
  box-shadow: 0 0 18px rgba(255, 213, 79, 0.35);
}

.goal-pill {
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.goal-lvl {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 213, 79, 0.18);
  color: var(--gold);
}

.goal-text {
  font-size: clamp(0.78rem, 1.5vw, 0.9rem);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-btn {
  pointer-events: auto;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-main);
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: transform 0.12s ease, background 0.15s ease;
}

.hud-btn:hover {
  background: rgba(30, 41, 78, 0.82);
}

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

/* Bottom Dash Bar */
.dash-bar-wrap {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  pointer-events: none;
}

.dash-pill {
  pointer-events: auto;
  position: relative;
  overflow: hidden;
  min-width: min(260px, 72dvw);
  height: 34px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  cursor: pointer;
  backdrop-filter: blur(10px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.dash-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  background: linear-gradient(90deg, rgba(92, 225, 230, 0.36), rgba(255, 213, 79, 0.48));
  transform-origin: left center;
  transform: scaleX(1);
  transition: transform 0.08s linear;
}

.dash-pill.ready {
  border-color: rgba(255, 213, 79, 0.72);
  box-shadow: 0 0 22px rgba(255, 213, 79, 0.28);
}

.dash-label {
  position: relative;
  z-index: 1;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 12, 26, 0.56);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 20;
}

.overlay.hidden {
  display: none;
}

.card {
  width: min(440px, 92dvw);
  padding: clamp(22px, 4vw, 32px);
  border-radius: 24px;
  background: rgba(16, 23, 46, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.compact-card {
  width: min(360px, 90dvw);
}

.brand-badge {
  display: inline-block;
  padding: 4px 12px;
  margin-bottom: 10px;
  border-radius: 999px;
  background: rgba(255, 213, 79, 0.16);
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.new-best {
  display: inline-block;
  padding: 5px 14px;
  margin-bottom: 10px;
  border-radius: 999px;
  background: rgba(255, 213, 79, 0.22);
  border: 1px solid rgba(255, 213, 79, 0.55);
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.new-best.hidden {
  display: none;
}

.card h1 {
  margin: 0 0 8px;
  font-size: clamp(2.1rem, 5.5vw, 2.9rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 10%, #ffd54f 65%, #5ce1e6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.card h2 {
  margin: 0 0 10px;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
}

.subtitle {
  margin: 0 0 18px;
  font-size: clamp(0.9rem, 2vw, 1rem);
  line-height: 1.48;
  color: var(--text-muted);
}

.controls-list {
  margin: 0 0 18px;
  padding: 12px 14px;
  list-style: none;
  text-align: left;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: clamp(0.82rem, 1.8vw, 0.9rem);
  line-height: 1.65;
  color: #e2e8f0;
}

.controls-list strong {
  color: var(--gold);
}

.best-banner {
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.best-banner strong {
  color: var(--gold);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 20px;
}

.summary-box {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.summary-box.wide {
  grid-column: 1 / -1;
}

.summary-box .label {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.summary-box strong {
  font-size: 1.15rem;
  font-weight: 800;
}

.btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.primary-btn,
.secondary-btn {
  border: 0;
  border-radius: 999px;
  padding: 13px 26px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.primary-btn {
  width: 100%;
  color: #161b2e;
  background: var(--accent-grad);
  box-shadow: 0 10px 26px rgba(255, 180, 67, 0.32);
}

.btn-row .primary-btn,
.btn-row .secondary-btn {
  width: auto;
  flex: 1;
}

.secondary-btn {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.primary-btn:hover,
.secondary-btn:hover {
  filter: brightness(1.06);
}

.primary-btn:active,
.secondary-btn:active {
  transform: scale(0.97);
}

button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .hud {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .hud-center {
    order: 3;
    flex-basis: 100%;
  }

  .hud-pill {
    padding: 6px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
