:root {
  --ink: #181229;
  --panel: rgba(24, 18, 41, 0.62);
  --panel-border: rgba(255, 255, 255, 0.14);
  --cream: #FDF6EC;
  --coral: #FF7E5F;
  --amber: #FFD580;
  --pink: #FF4FA3;
  --muted: #C9C0DD;
  --shadow: 0 20px 60px rgba(10, 6, 25, 0.55);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  height: 100dvh;
  width: 100vw;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  background: #0d0a1a;
  font-family: 'Sora', sans-serif;
  color: var(--cream);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
}

#stage {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100dvh;
  touch-action: manipulation;
}

/* Game area holds the canvas, HUD, and every overlay. It always leaves
   room below itself for the footer because the footer is a normal flex
   sibling, not something absolutely positioned on top of the canvas. */
#gameArea {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  container-type: size;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.display {
  font-family: 'Space Grotesk', sans-serif;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: max(16px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 5;
}

.score-chip {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: clamp(16px, 8cqw, 34px);
  color: var(--cream);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

.best-chip {
  font-size: clamp(8px, 3cqw, 12px);
  font-weight: 600;
  color: var(--amber);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 2px;
  opacity: 0.9;
}

.icon-row {
  display: flex;
  gap: 8px;
  pointer-events: all;
}

.icon-btn {
  width: clamp(28px, 10cqw, 42px);
  height: clamp(28px, 10cqw, 42px);
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--cream);
  transition: transform .15s ease;
}

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

.icon-btn svg {
  width: 50%;
  height: 50%;
}

.streak {
  position: absolute;
  top: 74px;
  left: 18px;
  font-size: clamp(8px, 3cqw, 12px);
  font-weight: 600;
  letter-spacing: 0.8px;
  color: var(--pink);
  text-transform: uppercase;
  opacity: 0;
  transition: opacity .3s ease;
  pointer-events: none;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.streak.show {
  opacity: 1;
}

.level-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -60%);
  text-align: center;
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  transition: opacity .4s ease, transform .4s ease;
}

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

.level-banner .eyebrow2 {
  font-size: clamp(8px, 2.8cqw, 11px);
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--amber);
  font-weight: 700;
}

.level-banner .name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(16px, 9cqw, 40px);
  font-weight: 700;
  color: var(--cream);
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

/* power-up HUD */
#powerHud {
  position: absolute;
  top: 78px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
  pointer-events: none;
  align-items: flex-end;
}

.power-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 4px 8px 4px 4px;
  font-size: clamp(8px, 2.8cqw, 11px);
  font-weight: 600;
  backdrop-filter: blur(10px);
}

.power-badge .dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: clamp(10px, 3vh, 24px) max(14px, env(safe-area-inset-right)) clamp(10px, 3vh, 24px) max(14px, env(safe-area-inset-left));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay.hidden {
  display: none;
}

.panel {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: clamp(14px, 5cqw, 24px);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  padding: clamp(14px, 4.5vh, 28px) clamp(14px, 5cqw, 26px);
  text-align: center;
  animation: rise .5s cubic-bezier(.2, .8, .2, 1);
  max-height: 100%;
  overflow-y: auto;
  margin: auto;
  position: relative;
}

/* ---------- Account & Auth Modal Styling ---------- */
.account-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 8px 14px;
  margin: 12px 0 16px;
  font-size: 13px;
}

.account-info {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.account-icon {
  font-size: 15px;
}

.account-text {
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.account-text strong {
  color: #fff;
}

.account-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.account-btn:hover {
  background: var(--amber);
  color: #000;
  border-color: var(--amber);
}

.auth-panel {
  text-align: left;
}

.auth-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 4px;
  margin: 14px 0 18px;
}

.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.auth-tab.active {
  background: var(--amber);
  color: #000;
}

.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}

.form-input {
  width: 100%;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 10px 12px;
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-input:focus {
  border-color: var(--coral);
}

.auth-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  margin-bottom: 12px;
}

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 16px 0;
  color: var(--muted);
  font-size: 11px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.auth-divider span {
  padding: 0 10px;
}

.google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  border: none;
  border-radius: 12px;
  padding: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.google-btn:hover {
  background: #ffffff;
  transform: translateY(-1px);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.eyebrow {
  font-size: clamp(8px, 2.8cqw, 11px);
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--coral);
  margin-bottom: 6px;
}

.title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(18px, 8cqw, 32px);
  font-weight: 700;
  line-height: 1.05;
  background: linear-gradient(120deg, var(--amber), var(--coral) 55%, var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 6px;
}

.subtitle {
  font-size: clamp(10px, 3.2cqw, 13px);
  color: var(--muted);
  line-height: 1.4;
  margin-bottom: 12px;
}

.stat-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}

.stat {
  text-align: center;
}

.stat .num {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(14px, 6cqw, 24px);
  font-weight: 700;
  color: var(--cream);
}

.stat .label {
  font-size: clamp(7px, 2.4cqw, 9.5px);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2px;
}

.section-label {
  font-size: clamp(8px, 2.6cqw, 10.5px);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  margin: 10px 0 6px;
  font-weight: 600;
}

.diff-row {
  display: flex;
  gap: 6px;
}

.diff-btn {
  flex: 1;
  padding: clamp(4px, 2.2cqw, 9px) 2px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--cream);
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(8px, 2.8cqw, 11.5px);
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
  position: relative;
}

.diff-btn.active {
  background: linear-gradient(120deg, var(--coral), var(--pink));
  border-color: transparent;
}

.diff-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.diff-btn .lock {
  font-size: 9px;
  display: block;
  margin-top: 2px;
}

.skin-row {
  display: flex;
  gap: clamp(4px, 1.8cqw, 8px);
  overflow-x: auto;
  padding: 2px;
  justify-content: center;
  flex-wrap: wrap;
}

.skin-swatch {
  width: clamp(24px, 11cqw, 44px);
  height: clamp(24px, 11cqw, 44px);
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: transform .15s ease, border-color .15s ease;
}

.skin-swatch.active {
  border-color: var(--cream);
  transform: scale(1.08);
}

.skin-swatch.locked {
  opacity: 0.35;
  cursor: not-allowed;
}

.skin-swatch .lockicon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.primary-btn {
  width: 100%;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: clamp(11px, 4cqw, 16px);
  padding: clamp(8px, 3.5cqw, 14px) 20px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(120deg, var(--coral), var(--pink));
  color: var(--cream);
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(255, 79, 163, 0.25);
  transition: transform .15s ease;
  letter-spacing: 0.3px;
  margin-top: 10px;
}

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

.secondary-btn {
  width: 100%;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: clamp(10px, 3.5cqw, 14px);
  padding: clamp(6px, 3cqw, 12px) 20px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--cream);
  cursor: pointer;
  margin-top: 6px;
  transition: transform .15s ease;
}

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

.hint {
  margin-top: 10px;
  font-size: clamp(8px, 3cqw, 12px);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.kbd {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 9px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--cream);
}

.medal {
  width: clamp(40px, 18cqw, 76px);
  height: clamp(40px, 18cqw, 76px);
  border-radius: 50%;
  margin: 4px auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 7cqw, 30px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 2px 6px rgba(255, 255, 255, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.medal-label {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: clamp(10px, 3.2cqw, 13px);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

footer.credit {
  flex-shrink: 0;
  width: 100%;
  padding: 8px env(safe-area-inset-right) max(8px, env(safe-area-inset-bottom)) env(safe-area-inset-left);
  display: flex;
  justify-content: center;
  z-index: 9;
  pointer-events: none;
}

footer.credit .credit-badge {
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(15, 15, 25, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: clamp(9px, 2.5cqw, 12px);
  font-weight: 600;
  color: white;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

footer.credit .credit-badge .spark {
  color: var(--amber);
  font-size: 12px;
}

footer.credit .credit-badge .name {
  background: linear-gradient(120deg, var(--amber), var(--coral) 55%, var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 700;
}

/* ---------- Responsive Desktop & Landscape Layout ---------- */
@media (min-width: 768px) and (min-aspect-ratio: 1.1/1) {
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #0a0714;
    min-height: 100dvh;
    width: 100vw;
    overflow: hidden;
  }

  #stage {
    width: min(1200px, 92vw, calc((90dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 16 / 9));
    height: auto;
    aspect-ratio: 16 / 9;
    max-height: calc(90dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.1);
    border: 4px solid #181229;
  }
}

/* Mobile portrait layout: Score/HUD sits over the canvas, the canvas fills
   the remaining game area, and the footer is a fixed-height flex row below
   it — so it can never be scrolled off or hidden behind the canvas. */
@media (max-width: 768px) and (orientation: portrait) {
  footer.credit {
    padding-top: 6px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  footer.credit .credit-badge {
    padding: 5px 14px;
  }

  .icon-btn {
    min-width: 34px;
    min-height: 34px;
  }

  .primary-btn,
  .secondary-btn,
  .account-btn {
    min-height: 40px;
  }

  .skin-swatch {
    min-width: 30px;
    min-height: 30px;
  }
}

/* Compact landscape adjustments for mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .panel {
    padding: 10px 16px;
    max-height: 90dvh;
  }
  .subtitle {
    display: none;
  }
  .stat-row {
    margin-bottom: 6px;
  }
  .section-label {
    margin: 4px 0 2px;
  }
}