:root {
  --bg: #01042d;
  --panel: #1a1a2e;
  --ink: #eee;
  --accent: #7799ff;   /* Changed to blue-silver */
  --accent-hover: #99bbff; /* Brighter blue-silver for hover */
  --accent-2: #001994; /* deep blue (letter outline) */
  --accent-glow: rgba(119, 153, 255, 0.4); /* Blue glow */
  --navy: #002754;
  --danger: #ff4d4d;
  --success: #4dff88;
  --title-purple: #3f0090;
  
  /* Rocket metallic colors */
  --rocket-silver: #c0c5cc;
  --rocket-blue: #7799ff;
  --rocket-glow: rgba(119, 153, 255, 0.5);
  
  /* Difficulty colors */
  --diff-beginner: #4dff88;
  --diff-intermediate: #ffeb3b;
  --diff-advanced: #ff6b6b;
  
  /* Keep pink for title contrast */
  --title-pink: #f8abeb;
  --title-pink-glow: rgba(248, 171, 235, 0.4);
}

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

html, body { height: 100%; }

body {
  margin: 0;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: transparent;
  color: var(--ink);
  font-family: "Rubik", ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  text-align: center;
  overscroll-behavior: contain;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* OUTERMOST starfield */
#bgStars {
  position: fixed;
  inset: 0;
  z-index: -1;
  width: 100vw;
  height: 100vh;
  display: block;
  pointer-events: none;
}

/* Back button - using blue accent now */
.top-left-back-button {
  position: fixed;
  top: 16px;
  left: 16px;
  padding: 10px 14px;
  background: color-mix(in oklab, var(--accent) 18%, transparent);
  color: var(--accent);
  text-decoration: none;
  border-radius: 10px;
  backdrop-filter: blur(6px);
  transition: all .2s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: calc(15px * 1.09);
  border: 1px solid color-mix(in oklab, var(--accent-2) 50%, transparent);
  box-shadow:
    0 18px 42px rgba(0,0,0,.55),
    0 6px 18px rgba(0, 25, 148, .25);
  will-change: transform, background;
}

.top-left-back-button:hover {
  transform: translateY(-2px) scale(1.02);
  background: color-mix(in oklab, var(--accent) 30%, transparent);
  box-shadow:
    0 20px 48px rgba(0,0,0,.60),
    0 8px 20px rgba(0, 25, 148, .30),
    0 0 20px var(--accent-glow);
}

/* Title - keeping pink for contrast */
.titlebar {
  width: min(92vw, 800px);
  margin: 24px auto clamp(120px, 24vh, 200px);
  padding: 0;
  animation: titleGlow 3s ease-in-out infinite alternate;
}

@keyframes titleGlow {
  0% { filter: brightness(1) saturate(1); }
  100% { filter: brightness(1.1) saturate(1.15); }
}

h1 {
  margin: 0;
  font-size: clamp(37px, 7.5vw, 64px);
  font-weight: 700;
  font-style: italic;
  letter-spacing: .08em;
  text-transform: uppercase;
  background: linear-gradient(135deg,
              #ffe6f8 0%, var(--title-pink) 45%, #ffbdea 65%, #ffe6f8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1.2px var(--accent-2);
  text-shadow:
    0 10px 22px rgba(0,0,0,.55),
    0 4px 12px rgba(0, 25, 148, .25),
    0 0 10px rgba(0, 25, 148, .45),
    0 0 8px var(--title-pink-glow);
  animation: titlePulse 4s ease-in-out infinite;
}

@keyframes titlePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

/* Container for board */
#game-container {
  position: relative;
  width: min(92vw, 640px);
  margin: 0 auto 24px;
}

/* Floating board - blue/silver border now */
.screen-shell {
  position: relative;
  border-radius: 0;
  padding: 0;
  background: none;
  box-shadow: none;
}

canvas {
  width: 100%;
  height: auto;
  background: radial-gradient(120% 120% at 50% 0%, #202040 0%, #131327 60%, #0f0f1f 100%);
  border-radius: 0;
  display: block;
  border: 2px solid var(--accent);
  box-shadow:
    inset 3px 3px 0 rgba(255,255,255,.08),
    inset -3px -3px 0 rgba(0,0,0,.55),
    inset 0 0 12px rgba(0,0,0,.35),
    0 28px 64px rgba(0,0,0,.60),
    0 6px 18px rgba(0, 25, 148, .25);
  image-rendering: crisp-edges;
}

/* Floor shadow */
.screen-shell::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -16px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(60% 100% at 50% 0%,
              rgba(0,0,0,0.50) 0%,
              rgba(0,0,0,0.18) 55%,
              rgba(0,0,0,0) 100%);
  z-index: -1;
}

/* Overlays */
#ui-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in oklab, black 35%, transparent);
  backdrop-filter: blur(3px);
  border-radius: 0;
}

.hidden { display: none !important; }

/* Enhanced Difficulty Selection */
.difficulty {
  border: none;
  padding: 0;
  margin: 16px auto;
  max-width: 420px;
}

.difficulty-label {
  display: block;
  font-size: 14px;
  opacity: 0.8;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.pill-group {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.pill {
  position: relative;
  background: linear-gradient(135deg, 
    color-mix(in oklab, var(--accent) 20%, transparent),
    color-mix(in oklab, var(--accent) 10%, transparent)
  );
  color: var(--ink);
  margin: 0;
  padding: 10px 16px;
  font-size: calc(14px * 1.09);
  border-radius: 999px;
  opacity: .75;
  border: 2px solid color-mix(in oklab, var(--accent-2) 30%, transparent);
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  min-width: 120px;
  justify-content: center;
}

.pill:hover {
  opacity: 0.9;
  transform: translateY(-2px);
  box-shadow: 
    0 6px 16px rgba(0,0,0,.35),
    0 0 20px color-mix(in oklab, var(--accent) 20%, transparent);
}

.pill-icon {
  font-size: 16px;
  display: inline-block;
}

.pill-check {
  position: absolute;
  right: 8px;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  font-size: 16px;
  color: var(--success);
  font-weight: bold;
}

/* Selected state with distinct visual feedback */
.pill.selected {
  opacity: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: var(--navy);
  border-color: var(--accent-2);
  transform: scale(1.05);
  box-shadow: 
    0 8px 20px rgba(0,0,0,.4),
    0 0 30px var(--accent-glow),
    inset 0 1px 0 rgba(255,255,255,0.3);
}

.pill.selected .pill-check {
  opacity: 1;
  transform: scale(1);
}

.pill.selected[data-diff="beginner"] {
  background: linear-gradient(135deg, var(--diff-beginner), #6dffaa);
  border-color: var(--diff-beginner);
  box-shadow: 
    0 8px 20px rgba(0,0,0,.4),
    0 0 25px rgba(77, 255, 136, 0.4);
}

.pill.selected[data-diff="intermediate"] {
  background: linear-gradient(135deg, var(--diff-intermediate), #ffd23b);
  border-color: color-mix(in oklab, var(--diff-intermediate) 80%, var(--navy));
  color: #333;
  box-shadow: 
    0 8px 20px rgba(0,0,0,.4),
    0 0 25px rgba(255, 235, 59, 0.4);
}

.pill.selected[data-diff="advanced"] {
  background: linear-gradient(135deg, var(--diff-advanced), #ff4444);
  border-color: var(--diff-advanced);
  box-shadow: 
    0 8px 20px rgba(0,0,0,.4),
    0 0 25px rgba(255, 107, 107, 0.4);
}

/* Difficulty descriptions */
.difficulty-description {
  margin-top: 12px;
  min-height: 24px;
  position: relative;
}

.difficulty-description p {
  position: absolute;
  width: 100%;
  left: 0;
  margin: 0;
  font-size: 13px;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  pointer-events: none;
  color: rgba(255, 255, 255, 0.8);
  font-style: italic;
}

.difficulty-description p.active {
  opacity: 1;
  transform: translateY(0);
}

/* Enhanced buttons with blue theme */
.play-button {
  appearance: none;
  border: 0;
  cursor: pointer;
  color: var(--navy);
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  padding: 14px 28px;
  border-radius: 12px;
  font-size: calc(18px * 1.09);
  font-weight: 700;
  transition: all .2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid color-mix(in oklab, var(--accent-2) 40%, transparent);
  box-shadow: 
    0 10px 24px rgba(0,0,0,.35),
    inset 0 1px 0 rgba(255,255,255,0.2);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.play-button:hover {
  transform: translateY(-3px) scale(1.02);
  background: linear-gradient(135deg, var(--accent-hover), #aaccff);
  box-shadow: 
    0 14px 32px rgba(0,0,0,.45),
    0 0 30px var(--rocket-glow);
}

.play-button:active {
  transform: translateY(-1px) scale(0.98);
}

.play-icon {
  font-size: 20px;
  display: inline-block;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

.secondary-button {
  appearance: none;
  border: 0;
  cursor: pointer;
  color: var(--ink);
  background: transparent;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: calc(14px * 1.09);
  font-weight: 500;
  transition: all .2s ease;
  border: 1px solid var(--accent);
  margin-top: 8px;
}

.secondary-button:hover {
  background: color-mix(in oklab, var(--accent) 20%, transparent);
  transform: translateY(-1px);
}

/* HUD enhancements with silver theme */
#hud {
  margin-top: 10px;
  font-size: calc(18px * 1.09);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  animation: hudSlideIn 0.5s ease-out;
}

@keyframes hudSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hud-left {
  display: flex;
  gap: 24px;
}

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

.hud-label {
  font-size: 12px;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hud-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--rocket-blue);
  text-shadow: 0 0 10px var(--rocket-glow);
}

.hud-right { 
  display: flex;
  gap: 8px;
}

.hud-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: calc(18px * 1.09);
  font-weight: 800;
  padding: 0;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 14px rgba(0,0,0,.28);
  background: linear-gradient(135deg, var(--rocket-silver), #e8eaed);
  color: var(--navy);
  border: 1px solid color-mix(in oklab, var(--accent-2) 40%, transparent);
  transition: all .2s ease;
}

.hud-button:hover {
  transform: scale(1.1);
  box-shadow: 
    0 8px 18px rgba(0,0,0,.35),
    0 0 15px var(--rocket-glow);
}

/* Legend styles with silver rocket */
.legend {
  list-style: none;
  padding: 0;
  margin: 8px 0 14px;
  display: grid;
  gap: 8px;
}

.legend li {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: calc(15px * 1.09);
}

.legend-label { 
  opacity: 0.95;
}

.legend-icon {
  width: 22px; 
  height: 22px;
  display: inline-block;
}

.legend-icon--rocket {
  filter: drop-shadow(0 0 8px var(--rocket-glow));
  transform: translateY(1px);
  animation: rocketFloat 3s ease-in-out infinite;
}

@keyframes rocketFloat {
  0%, 100% { transform: translateY(1px); }
  50% { transform: translateY(-2px); }
}

.legend-icon--dot { 
  filter: drop-shadow(0 0 8px rgba(112,251,253,0.65));
  animation: dotPulse 2s ease-in-out infinite;
}

@keyframes dotPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.legend-icon--diamond { 
  filter: drop-shadow(0 0 7px rgba(255,77,77,0.55));
  animation: diamondRotate 4s linear infinite;
}

@keyframes diamondRotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Enhanced Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: color-mix(in oklab, black 60%, transparent);
  display: grid;
  place-items: center;
  backdrop-filter: blur(4px);
  animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: linear-gradient(135deg, #22243a, #1a1a2e);
  color: var(--ink);
  padding: 32px;
  width: min(92vw, 520px);
  border: 2px solid var(--accent);
  border-radius: 14px;
  text-align: left;
  box-shadow: 
    0 0 24px color-mix(in oklab, var(--accent) 30%, transparent),
    0 20px 40px rgba(0,0,0,.5);
  position: relative;
  font-size: calc(16px * 1.09);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-content h2 {
  margin: 0 0 20px;
  text-align: center;
  font-size: calc(24px * 1.09);
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
}

.modal-content h3 {
  color: var(--accent);
  font-size: calc(16px * 1.09);
  margin: 16px 0 8px;
}

.help-section {
  margin: 20px 0;
  padding: 16px;
  background: color-mix(in oklab, var(--panel) 40%, transparent);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

.help-controls {
  list-style: none;
  padding: 0;
  margin: 8px 0;
}

.help-controls li {
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

kbd {
  background: color-mix(in oklab, var(--accent) 20%, var(--panel));
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--accent);
  font-family: monospace;
  font-size: 14px;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
}

.close-button {
  position: absolute;
  right: 10px;
  top: 10px;
  background: transparent;
  color: var(--accent);
  font-size: calc(28px * 1.09);
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  transition: all .2s ease;
  border-radius: 50%;
}

.close-button:hover {
  background: color-mix(in oklab, var(--accent) 20%, transparent);
  border-color: var(--accent);
  transform: rotate(90deg);
}

/* Enhanced Toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #2c2e48, var(--panel));
  border: 2px solid var(--accent);
  padding: 12px 24px;
  border-radius: 999px;
  box-shadow: 
    0 6px 16px rgba(0,0,0,.35),
    0 0 20px var(--accent-glow);
  font-weight: 700;
  font-size: calc(16px * 1.09);
  animation: toastSlideUp 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes toastSlideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(100px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Mobile controls with better visual feedback */
.controls {
  display: none;
  margin-top: 16px;
  user-select: none;
  touch-action: none;
}

.ctrl-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 6px;
}

.ctrl {
  width: 58px;
  height: 58px;
  border-radius: 12px;
  font-size: calc(22px * 1.09);
  background: linear-gradient(135deg, #2c2e48, #1a1a2e);
  border: 2px solid #3a3d60;
  box-shadow: 
    inset 0 0 10px rgba(0,0,0,.35),
    0 4px 8px rgba(0,0,0,.25);
  touch-action: none;
  color: var(--accent);
  transition: all .15s ease;
  display: grid;
  place-items: center;
}

.ctrl:active {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: var(--navy);
  border-color: var(--accent);
  transform: scale(0.95);
  box-shadow: 
    inset 0 2px 4px rgba(0,0,0,.35),
    0 0 15px var(--accent-glow);
}

.ctrl-up { grid-area: up; }
.ctrl-down { grid-area: down; }
.ctrl-left { grid-area: left; }
.ctrl-right { grid-area: right; }

.hint {
  font-size: calc(14px * 1.09);
  opacity: 0.8;
  margin-top: 16px;
  letter-spacing: 0.02em;
}

/* Game Over Screen enhancements */
.final-score {
  font-size: calc(20px * 1.09);
  margin: 20px 0;
}

.final-score strong {
  color: var(--accent);
  font-size: calc(32px * 1.09);
  display: block;
  margin-top: 8px;
  text-shadow: 0 0 20px var(--accent-glow);
  animation: scoreGlow 2s ease-in-out infinite;
}

@keyframes scoreGlow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.game-over-stats {
  margin: 20px 0;
  padding: 16px;
  background: color-mix(in oklab, var(--panel) 40%, transparent);
  border-radius: 8px;
  font-size: calc(14px * 1.09);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .controls {
    display: block;
  }
  
  .pill-group {
    flex-direction: column;
    align-items: center;
  }
  
  .pill {
    width: 160px;
  }
}

@media (hover: hover) and (pointer: fine) {
  .ctrl:hover {
    border-color: var(--accent);
    background: linear-gradient(135deg, #3a3d60, #2c2e48);
  }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .pill.selected {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
  }
  
  button {
    border-width: 2px;
  }
}

/* Dark mode already default, but ensure consistency */
@media (prefers-color-scheme: light) {
  /* Game is dark-themed by design, maintaining dark theme */
}