:root {
  --bg: #0f172a; /* slate-900 */
  --panel: #111827; /* gray-900 */
  --text: #e5e7eb; /* gray-200 */
  --accent: #22c55e; /* green-500 */
  --accent-2: #10b981; /* emerald-500 */
  --danger: #ef4444; /* red-500 */
  --grid: rgba(255, 255, 255, 0.06);
}
* {
  box-sizing: border-box;
}
[data-theme="classic"] {
  --bg: #0b1b0f;
  --panel: #0f2615;
  --text: #e7ffe7;
  --accent: #34d399;
  --accent-2: #22c55e;
  --grid: rgba(255, 255, 255, 0.07);
}
[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #0b1020;
  --text: #e5e7eb;
  --accent: #60a5fa;
  --accent-2: #38bdf8;
  --grid: rgba(255, 255, 255, 0.06);
}
[data-theme="neon"] {
  --bg: #020617;
  --panel: #0a0a0a;
  --text: #e5e7eb;
  --accent: #a78bfa;
  --accent-2: #22d3ee;
  --grid: rgba(167, 139, 250, 0.12);
}
[data-theme="retro"] {
  --bg: #1a1610;
  --panel: #221e19;
  --text: #f8f4e1;
  --accent: #ffb703;
  --accent-2: #fb8500;
  --grid: rgba(251, 133, 0, 0.18);
}

html,
body {
  height: 100%;
  overflow: hidden;
}
body {
  margin: 0;
  font: 500 16px/1.4 system-ui, -apple-system, Segoe UI, Roboto,
    "Helvetica Neue", Arial;
  color: var(--text);
  background: radial-gradient(
      1200px 800px at 10% -10%,
      rgba(255, 255, 255, 0.06),
      transparent
    ),
    var(--bg);
}
canvas,
.mobile-keys {
  touch-action: none;
}
.wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 18px;
}
canvas {
  outline: none;
}
.hud-2,
.hud-stats {
  user-select: none;
  -webkit-user-select: none;
  caret-color: transparent;
}
/* And REPLACE it with these three rules: */
.game-card {
  width: 100%;
  max-width: 700px;
}
.game-card[data-size="small"] {
  max-width: 65vmin;
}
.game-card[data-size="large"] {
  max-width: 95vmin;
}
.game-card {
  position: relative;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.04),
    rgba(255, 255, 255, 0.01)
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
}
.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1/1;
  background: var(--panel);
}
canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.hud {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(0, 0, 0, 0.15);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.hud-2 {
  display: flex;
  justify-content: space-between; /* This will separate the title and stats */
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(0, 0, 0, 0.15);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.game-title {
  padding: 5px;
  margin: 0;
  font-size: 1.5em;
  font-weight: 800;
  text-align: center;
  flex-grow: 1; /* Allows the title to take up the middle space */
}
.hud-stats {
  display: flex;
  gap: 10px;
}

.hud-2,
h1 {
  padding: 5px;
  margin: 0;
}
.badge {
  background: rgba(0, 0, 0, 0.35);
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.4px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.65));
  z-index: 3;
  text-align: center;
  padding: 18px;
}
.overlay.hidden {
  display: none;
}
.title {
  font-size: clamp(22px, 2.6vw, 32px);
  font-weight: 800;
  letter-spacing: 0.4px;
}
.subtitle {
  opacity: 0.8;
}
.button {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #041006;
  border: 0;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(16, 185, 129, 0.35);
  cursor: pointer;
}
.button.secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  box-shadow: none;
  outline: 1px solid rgba(255, 255, 255, 0.14);
}

.sidebar {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.04),
    rgba(255, 255, 255, 0.01)
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.sidebar h2 {
  margin: 6px 0 14px;
  font-size: 18px;
  letter-spacing: 0.4px;
}
.control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
}
.control label {
  opacity: 0.85;
}
.control input[type="range"] {
  width: 180px;
}
.control input[type="checkbox"] {
  transform: scale(1.2);
}
.control select,
.control input,
.control button {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 8px 10px;
}
.hint {
  opacity: 0.7;
  font-size: 13px;
}
/* -- New Settings Tabs -- */
.settings-tabs {
  display: flex;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.tab-btn {
  border: 0;
  background: transparent;
  color: var(--text);
  opacity: 0.6;
  padding: 8px 12px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  transition: all 0.2s ease-in-out;
}
.tab-btn:hover {
  opacity: 1;
}
.tab-btn.active {
  opacity: 1;
  border-bottom-color: var(--accent-2);
}
.tab-content {
  display: none; /* Hide all content panels by default */
  min-height: 250px; /* Give the content area a fixed height */
}
.tab-content.active {
  display: block; /* Show only the active one */
}

/* -- Settings Footer -- */
.settings-footer {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 14px;
  opacity: 0.8;
}
.mobile-controls {
  display: none; /* Hide mobile text by default */
}

/* Media query to show the correct control hints */
@media (max-width: 768px) {
  .desktop-controls {
    display: none; /* Hide desktop text on mobile */
  }
  .mobile-controls {
    display: block; /* Show mobile text on mobile */
  }
}
.mobile-keys {
  display: none;
}
.mobile-keys button {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 800;
  flex-grow: 1; /* Allows buttons to stretch nicely */
  max-width: 80px;
}
/* Apply mobile-specific layouts on screens 768px or less */
@media (max-width: 768px) {
  .wrap {
    /* Stack elements vertically and align them to the top */
    flex-direction: column;
    justify-content: flex-start;
  }
  .game-title {
    display: none;
  }
  .hud-2 {
    justify-content: center; /* Center the stats when the title is gone */
  }
  .badge {
    border-radius: 999px;
    font-weight: 100;
    font-size: 1rem;
    margin: 5px;
  }

  .mobile-keys {
    /* Show the keys */
    display: flex;
    gap: 10px;
    justify-content: center;
    width: 100%;
    max-width: 400px;
    margin-top: 18px; /* Add space between the game and the keys */
  }
}
.control select option {
  color: #111; /* Use a dark color for option text */
  background: #fff; /* Ensure a light background */
}
/* -- Settings Panel Modal -- */
.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

/* Re-use the sidebar styling for the panel's content box */
.settings-panel .sidebar {
  width: 100%;
  max-width: 420px;
}
.update-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.update-card {
  background: var(--panel);
  color: var(--text);
  padding: 14px 18px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.95rem;
}
.loader {
  width: 22px;
  height: 22px;
  border: 3px solid var(--text);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
/* Utility class to hide elements */
.hidden {
  display: none !important;
}
@media (max-width: 640px) {
  .mobile-keys {
    display: flex;
  }
  .hud-2,
  h1 {
    padding: 0;
    font-size: 1.25em;
  }
}
@media (max-width: 480px) {
  .badge {
    /* Remove individual badge styling to make them uniform */
    background: none;
    box-shadow: none;
    backdrop-filter: none;
    padding: 2px 4px;
    border-radius: 0;
  }
}
/* Mobile-first improvements */
@media (pointer: coarse), (max-width: 820px) {
  .game-card {
    width: 100%;
    max-width: none;
    margin: 0;
    border-radius: 18px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }
  /* Make icon buttons perfectly centered */
  .icon-btn,
  .dpad {
    display: grid;
    place-items: center;
    line-height: 1;
  }

  /* D-pad grid: Up top-center; Left mid-left; Down center; Right mid-right; Pause top-right */
  .mobile-pad {
    display: grid;
    grid-template-columns: repeat(3, minmax(64px, 1fr));
    grid-template-rows: repeat(3, minmax(64px, 1fr));
    gap: 12px;
    justify-items: stretch;
    align-items: stretch;
  }

  #btnUp {
    grid-area: 1 / 2;
  }
  #btnLeft {
    grid-area: 2 / 1;
  }
  #btnDown {
    grid-area: 2 / 2;
  } /* centered */
  #btnRight {
    grid-area: 2 / 3;
  }
  #pauseBtn {
    grid-area: 1 / 3; /* right of Up, above Right */
    place-self: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    font-size: 18px;
    opacity: 0.9;
  }

  /* Big, thumb-friendly D-pad buttons */
  .dpad {
    width: 100%;
    max-width: 96px;
    height: 100%;
    max-height: 96px;
    border-radius: 16px;
    font-size: 24px;
  }

  /* If you still have the old mobile-actions row, hide it on mobile */
  .mobile-actions {
    display: none !important;
  }
  /* Make canvas fill width and stay perfectly square */
  canvas {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 1 / 1;
    image-rendering: pixelated;
  }

  .mobile-keys {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 12px;
    margin-top: 12px;
    touch-action: none;
    user-select: none;
  }

  /* Small, tucked-away actions */
  .mobile-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }
  .icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    font-size: 18px;
    opacity: 0.9;
  }
  .overlay-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
    justify-content: center;
  }
  .icon-btn,
  .dpad {
    display: grid;
    place-items: center;
    line-height: 1;
  }
  /* Big, thumb-friendly D-pad in a T layout */
  .mobile-pad {
    display: grid;
    grid-template-columns: repeat(3, minmax(64px, 1fr));
    grid-template-rows: repeat(3, minmax(64px, 1fr));
    gap: 12px;
    justify-items: stretch;
    align-items: stretch;
  }
  .dpad {
    width: 100%;
    max-width: 96px;
    height: 100%;
    max-height: 96px;
    border-radius: 16px;
    font-size: 24px;
  }
  /* T-shaped placement: Up on top; Left/Down/Right below */
  #btnUp {
    grid-area: 1 / 2;
  }
  #btnLeft {
    grid-area: 2 / 1;
  }
  #btnDown {
    grid-area: 2 / 2;
  } /* centered */
  #btnRight {
    grid-area: 2 / 3;
  }
  #hudSpeed {
    display: none;
  }
  /* Hide desktop-only settings on mobile */
  [data-desktop-only] {
    display: none !important;
  }
}
