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

/* ─── Shared Accents (Casual Palette) ─── */
:root {
  --font: 'Nunito', system-ui, sans-serif;
  --font-display: 'Fredoka', system-ui, sans-serif;

  --accent-teal: #48c9b0;
  --accent-teal-shadow: #1abc9c;
  --accent-coral: #ff6b6b;
  --accent-coral-shadow: #ee5253;
  --accent-yellow: #feca57;
  --accent-yellow-shadow: #ff9f43;
  --accent-purple: #9b59b6;
  --accent-purple-shadow: #8e44ad;
}

/* ─── Dark Theme (default) ─── */
:root,
[data-theme="dark"] {
  --bg: #2c2c34;
  --surface: #3b3b46;
  --surface-2: #4a4a58;
  --border: rgba(255, 255, 255, 0.1);
  --border-hover: rgba(255, 255, 255, 0.15);
  --text: #ffffff;
  --text-muted: #a3a3b5;
  --text-dim: #707080;

  --card-bg: #3b3b46;
  --card-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);

  --btn-secondary-bg: #4a4a58;
  --btn-secondary-shadow: #33333d;

  --toggle-bg: #4a4a58;
  --toggle-active: var(--accent-teal);
  --select-bg: #3b3b46;
  --success: var(--accent-teal);

  /* 3D scene */
  /* 3D scene - Dark Theme */
  --scene-bg: #1e1e24;       /* Matches --bg */
  --board-color: #2c2c34;    /* Matches --surface */
  --board-edge: #1e1e24;     
  --hole-color: #121216;     /* Noticeably deep dark cutout */
  --hole-ring: #4a4a5a;      /* Distinct lighter ring to frame it */
}

/* ─── Light Theme ─── */
[data-theme="light"] {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #e9ecef;
  --border: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.12);
  --text: #2d3436;
  --text-muted: #636e72;
  --text-dim: #b2bec3;

  --card-bg: #ffffff;
  --card-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);

  --btn-secondary-bg: #dfe6e9;
  --btn-secondary-shadow: #b2bec3;

  --toggle-bg: #dfe6e9;
  --toggle-active: var(--accent-teal);
  --select-bg: #f4f5f8;
  --success: var(--accent-teal);

  /* 3D scene - Light Theme */
  --scene-bg: #f4f5f8;       /* Matches --bg */
  --board-color: #ffffff;    /* Matches --card-bg */
  --board-edge: #dfe6e9;
  --hole-color: #cbd5e1;     /* Distinctly darker slate grey cutout */
  --hole-ring: #94a3b8;      /* Even darker slate for clear ring framing */
}

.font-display {
  font-family: var(--font-display);
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ─── Canvas ─── */
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#game-canvas:active {
  cursor: grabbing;
}

/* ─── HUD ─── */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px;
  pointer-events: none;
  z-index: 10;
}

#hud>* {
  pointer-events: auto;
}

.hud-pill {
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: 0.05em;
  color: #fff;
  background: var(--accent-coral);
  padding: 8px 24px;
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--accent-coral-shadow), 0 8px 16px rgba(0, 0, 0, 0.2);
  user-select: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
  transform: translateY(0);
}

.hud-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn-icon:active {
  transform: translateY(4px);
  box-shadow: 0 0px 0 var(--border), 0 4px 8px rgba(0, 0, 0, 0.2) !important;
}

/* ─── HUD Specific Buttons ─── */
.btn-icon-pill {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, filter 0.2s;
  outline: none;
}

.btn-icon-pill svg {
  width: 24px;
  height: 24px;
}

.btn-icon-pill:hover {
  filter: brightness(1.05);
}

.btn-icon-pill:active {
  transform: translateY(6px);
}

/* ─── Modals & Overlays ─── */
.hidden {
  display: none !important;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 30, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 50;
  padding: 24px;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  border-radius: 28px;
  padding: 32px 24px;
  box-shadow: var(--card-shadow);
  text-align: center;
  animation: modal-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modal-pop {
  0% {
    transform: scale(0.85);
    opacity: 0;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ─── Main Menu ─── */
.menu-logo {
  margin-bottom: 32px;
}

.menu-icon {
  margin-bottom: 12px;
}

.menu-logo h1 {
  font-size: 2.6rem;
  color: var(--text);
  line-height: 1.1;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.menu-logo p {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ─── 3D Pill Buttons ─── */
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.btn {
  width: 100%;
  padding: 16px 0;
  border: none;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: 0.03em;
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, filter 0.2s;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  position: relative;
  outline: none;
}

.btn:hover {
  filter: brightness(1.05);
}

.btn:active {
  transform: translateY(6px);
}

/* Color Variants */
.btn-teal {
  background: var(--accent-teal);
  box-shadow: 0 6px 0 var(--accent-teal-shadow);
}

.btn-teal:active {
  box-shadow: 0 0px 0 var(--accent-teal-shadow);
}

.btn-coral {
  background: var(--accent-coral);
  box-shadow: 0 6px 0 var(--accent-coral-shadow);
}

.btn-coral:active {
  box-shadow: 0 0px 0 var(--accent-coral-shadow);
}

.btn-yellow {
  background: var(--accent-yellow);
  box-shadow: 0 6px 0 var(--accent-yellow-shadow);
}

.btn-yellow:active {
  box-shadow: 0 0px 0 var(--accent-yellow-shadow);
}

.btn-purple {
  background: var(--accent-purple);
  box-shadow: 0 6px 0 var(--accent-purple-shadow);
}

.btn-purple:active {
  box-shadow: 0 0px 0 var(--accent-purple-shadow);
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--text);
  box-shadow: 0 6px 0 var(--btn-secondary-shadow);
  text-shadow: none;
}

.btn-secondary:active {
  box-shadow: 0 0px 0 var(--btn-secondary-shadow);
}

.btn-secondary:active {
  box-shadow: 0 0px 0 var(--btn-secondary-shadow);
}

/* ─── Overlay Panels (General) ─── */
.overlay-panel {
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.panel-header h2 {
  font-size: 1.8rem;
  color: var(--text);
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--btn-secondary-bg);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-icon:hover {
  background: var(--btn-secondary-hover);
}

/* ─── Level Grid ─── */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  overflow-y: auto;
  padding-bottom: 12px;
}

.level-cell {
  aspect-ratio: 1;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.1rem;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 4px 0 var(--border);
  transition: transform 0.1s, box-shadow 0.1s;
}

.level-cell.completed {
  background: var(--accent-teal);
  color: #fff;
  box-shadow: 0 4px 0 var(--accent-teal-shadow);
}

.level-cell.current {
  background: var(--accent-yellow);
  color: #fff;
  box-shadow: 0 4px 0 var(--accent-yellow-shadow);
  transform: scale(1.1);
}

.level-cell.locked {
  background: var(--btn-secondary-bg);
  color: var(--text-dim);
  box-shadow: 0 4px 0 var(--btn-secondary-shadow);
  cursor: not-allowed;
  opacity: 0.6;
}

.level-cell:not(.locked):active {
  transform: translateY(4px);
  box-shadow: 0 0px 0 transparent;
}

.level-cell.current:active {
  transform: scale(1.1) translateY(4px);
}

/* ─── Settings ─── */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.setting-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Toggle Switch */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  border-radius: 24px;
  background: var(--toggle-bg);
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  left: 3px;
  bottom: 3px;
  background: white;
  transition: transform 0.2s;
}

.toggle input:checked+.toggle-slider {
  background: var(--toggle-active);
}

.toggle input:checked+.toggle-slider::before {
  transform: translateX(20px);
}

/* Theme Select */
.theme-select {
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--select-bg);
  color: var(--text);
  border: 1px solid var(--border);
  font-family: var(--font);
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
}

.theme-select:focus {
  border-color: var(--toggle-active);
}

/* ─── Win / Loading ─── */
#loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 200;
}

#fail-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
}

#fail-card {
  text-align: center;
  color: #fff;
  font-family: var(--font-display);
}

#fail-emoji {
  font-size: 4rem;
  margin-bottom: 0.5rem;
}

#fail-title {
  font-size: 2rem;
}

#fail-sub {
  font-family: var(--font);
  font-size: 1rem;
  color: #ffaaaa;
  margin-top: 0.3rem;
}

#win-emoji svg {
  margin-bottom: 12px;
}

#win-title {
  font-size: 2.2rem;
  color: var(--text);
  margin-bottom: 8px;
}

#win-sub {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
}

#loading-text {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 0.4;
  }

  50% {
    opacity: 1;
  }
}

/* ─── Responsive ─── */
@media (max-width: 480px) {
  .menu-container {
    padding: 16px;
  }

  .menu-logo h1 {
    font-size: 1.8rem;
  }

  .levels-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .overlay-panel {
    padding: 16px;
  }
}