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

:root {
  --bg: #FFF8F0;
  --bg-alt: #F0E8DC;
  --text: #2D2A26;
  --text-muted: #8A847A;
  --wall: #3D3A36;
  --wall-light: #5A5650;
  --accent: #FF6B4A;
  --accent-glow: #FFAA33;
  --tile-shadow: rgba(0,0,0,0.15);
  --overlay-bg: rgba(30,28,24,0.82);
  --card-bg: #FFFDF8;
  --floor1: #F5EDE2;
  --floor2: #EDE5D8;
  --hud-bg: rgba(255,248,240,0.92);
}

.dark-mode {
  --bg: #1A1D2E;
  --bg-alt: #232740;
  --text: #E8E4DC;
  --text-muted: #7A7A8A;
  --wall: #0E1020;
  --wall-light: #2A2E48;
  --accent: #FF7B5A;
  --accent-glow: #FFB844;
  --tile-shadow: rgba(0,0,0,0.35);
  --overlay-bg: rgba(10,12,24,0.88);
  --card-bg: #232740;
  --floor1: #1E2136;
  --floor2: #22253C;
  --hud-bg: rgba(26,29,46,0.92);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Baloo 2', 'Nunito', sans-serif;
  color: var(--text);
  transition: background 0.3s, color 0.3s;
}

#game-container {
  position: relative;
  width: 100%;
  height: calc(100% - 28px);
  display: flex;
  align-items: center;
  justify-content: center;
}

#canvas {
  display: block;
  touch-action: none;
}

#ui-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

#ui-overlay > * {
  pointer-events: auto;
}

#game-footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  padding: 4px 0;
  background: var(--bg-alt);
  z-index: 100;
  height: 28px;
}

#game-footer a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  font-family: 'Fira Code', monospace;
}

#game-footer a:hover {
  color: var(--accent);
}

.overlay-screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--overlay-bg);
  z-index: 50;
  animation: fadeIn 0.25s ease;
}

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

@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes bounceIn {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.06); }
  70% { transform: scale(0.96); }
  100% { transform: scale(1); opacity: 1; }
}

.overlay-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  animation: popIn 0.35s ease;
  max-height: 85vh;
  overflow-y: auto;
}

.overlay-card h1 {
  font-size: 2.2em;
  font-weight: 800;
  margin-bottom: 8px;
  line-height: 1.1;
}

.overlay-card h2 {
  font-size: 1.6em;
  font-weight: 800;
  margin-bottom: 8px;
}

.overlay-card p {
  color: var(--text-muted);
  margin-bottom: 16px;
  font-size: 0.95em;
  line-height: 1.5;
}

.btn {
  display: inline-block;
  padding: 14px 32px;
  border: none;
  border-radius: 14px;
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.15em;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  margin: 6px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-alt);
  color: var(--text);
}

.btn-small {
  padding: 8px 18px;
  font-size: 0.9em;
  border-radius: 10px;
}

.title-gradient {
  background: linear-gradient(135deg, #FF6B4A, #FFAA33, #4AEAFF, #7B6BFF);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.star-rating {
  font-size: 1.8em;
  letter-spacing: 4px;
  margin: 8px 0;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.level-cell {
  aspect-ratio: 1;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.2em;
  cursor: pointer;
  transition: transform 0.15s;
  border: 2px solid transparent;
  position: relative;
}

.level-cell:hover:not(.locked) {
  transform: scale(1.08);
}

.level-cell.completed {
  background: #E8F5E9;
  color: #2E7D32;
  border-color: #A5D6A7;
}

.dark-mode .level-cell.completed {
  background: #1B3A1F;
  color: #81C784;
  border-color: #2E7D32;
}

.level-cell.unlocked {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--text);
}

.level-cell.locked {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--text);
  cursor: pointer;
}

.level-stars {
  font-size: 0.45em;
  letter-spacing: 1px;
  margin-top: 2px;
}

.level-mod-badge {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.5em;
  line-height: 1;
}

.hud-bar {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--hud-bg);
  backdrop-filter: blur(8px);
  z-index: 20;
  font-weight: 600;
  font-size: 0.85em;
  gap: 6px;
}

.hud-left, .hud-center, .hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.goal-display {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
}

.goal-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-weight: 800;
  font-size: 0.95em;
  color: #fff;
  box-shadow: 0 2px 4px var(--tile-shadow);
}

.goal-arrow {
  color: var(--text-muted);
  font-size: 0.8em;
}

.hud-btn {
  background: none;
  border: 2px solid var(--text-muted);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1em;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}

.hud-btn:hover {
  border-color: var(--accent);
  background: var(--bg-alt);
}

.tutorial-step {
  text-align: left;
  margin: 10px 0;
  padding: 10px 14px;
  background: var(--bg-alt);
  border-radius: 10px;
  font-size: 0.9em;
  line-height: 1.5;
}

.tutorial-step strong {
  color: var(--accent);
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--bg-alt);
}

.settings-row label {
  font-weight: 600;
}

.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
  background: var(--bg-alt);
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-switch.active {
  background: var(--accent);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch.active::after {
  transform: translateX(22px);
}

@media (max-width: 480px) {
  .overlay-card {
    padding: 24px 18px;
  }
  .overlay-card h1 {
    font-size: 1.7em;
  }
  .level-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }
  .hud-bar {
    font-size: 0.75em;
    padding: 6px 8px;
  }
  .goal-tile {
    width: 24px;
    height: 24px;
    font-size: 0.8em;
  }
}