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

:root {
  --bg: #e8f4f8;
  --text: #333;
  --overlay-bg: rgba(255, 255, 255, 0.92);
  --btn-bg: #4CAF50;
  --btn-hover: #43a047;
  --btn-text: #fff;
  --btn-secondary-bg: #607d8b;
  --btn-secondary-hover: #546e7a;
  --shadow: rgba(0, 0, 0, 0.15);
  --score-text: #fff;
  --score-shadow: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --text: #e0e0e0;
  --overlay-bg: rgba(26, 26, 46, 0.94);
  --btn-bg: #66bb6a;
  --btn-hover: #4CAF50;
  --btn-text: #1a1a2e;
  --btn-secondary-bg: #78909c;
  --btn-secondary-hover: #607d8b;
  --shadow: rgba(0, 0, 0, 0.4);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#game-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

#game-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

/* Top bar */
.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  z-index: 10;
  pointer-events: none;
}

.top-bar > * {
  pointer-events: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--overlay-bg);
  color: var(--text);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow);
  transition: transform 0.15s;
}

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

/* Overlays */
.overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: var(--overlay-bg);
  z-index: 20;
  gap: 16px;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay h1 {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 4px;
}

.overlay h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
}

.overlay p {
  font-size: 16px;
  opacity: 0.7;
}

.overlay .score-display {
  font-size: 48px;
  font-weight: 900;
  color: var(--btn-bg);
}

.overlay .best-score {
  font-size: 18px;
  opacity: 0.8;
}

.new-best {
  font-size: 20px;
  color: #ff9800;
  font-weight: 700;
  animation: pulse 0.8s ease infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.1); }
}

.btn {
  min-width: 160px;
  padding: 14px 28px;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  box-shadow: 0 4px 12px var(--shadow);
}

.btn:active {
  transform: scale(0.95);
}

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

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

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: #fff;
}

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

.btn-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.hint {
  font-size: 14px;
  opacity: 0.5;
  margin-top: 8px;
}

/* In-game score */
#live-score {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 48px;
  font-weight: 900;
  color: var(--score-text);
  text-shadow: 2px 2px 4px var(--score-shadow), -1px -1px 2px var(--score-shadow);
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

#live-score.visible {
  opacity: 1;
}
