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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #1a1208;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: manipulation;
}

/* Global banner */
.global-banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  text-align: center;
  padding: env(safe-area-inset-top, 8px) 12px 6px;
  background: linear-gradient(180deg, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0) 100%);
  pointer-events: none;
}

.global-label {
  display: block;
  font-size: clamp(9px, 2.5vw, 12px);
  letter-spacing: 0.08em;
  color: #c8a882;
  text-transform: uppercase;
}

.global-count {
  display: block;
  font-size: clamp(16px, 4.5vw, 24px);
  font-weight: 800;
  color: #ffd700;
  text-shadow: 0 0 12px rgba(255, 215, 0, 0.5);
  font-variant-numeric: tabular-nums;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
  background: rgba(10, 8, 5, 0.82);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
  transform: scale(0.97);
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.overlay.panel {
  justify-content: flex-start;
  padding-top: calc(env(safe-area-inset-top, 16px) + 24px);
  overflow-y: auto;
}

.hidden {
  display: none !important;
}

/* Title */
.game-title {
  font-size: clamp(28px, 8vw, 52px);
  font-weight: 900;
  text-align: center;
  color: #ffd700;
  text-shadow: 3px 3px 0 #8b4513, 0 0 30px rgba(255, 200, 0, 0.4);
  line-height: 1.1;
  animation: titleWobble 3s ease-in-out infinite;
  margin-bottom: 8px;
}

@keyframes titleWobble {
  0%, 100% { transform: rotate(-1deg) scale(1); }
  50% { transform: rotate(1deg) scale(1.02); }
}

.game-subtitle {
  color: #c8a882;
  font-size: clamp(14px, 3.5vw, 18px);
  margin-bottom: 32px;
}

/* Buttons */
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(280px, 80vw);
}

.btn {
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 700;
  border: 2px solid #8b6914;
  border-radius: 12px;
  background: linear-gradient(180deg, #5c4033 0%, #3d2817 100%);
  color: #f5e6c8;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  touch-action: manipulation;
}

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

.btn-primary {
  background: linear-gradient(180deg, #d4a017 0%, #b8860b 100%);
  color: #1a1208;
  border-color: #ffd700;
  box-shadow: 0 4px 16px rgba(255, 215, 0, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(255, 215, 0, 0.5);
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
}

/* HUD */
.hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 52px);
  left: 0;
  right: 0;
  z-index: 15;
  padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
}

.hud:not(.hidden) {
  display: block;
}

.hud-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.hud-stat {
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,215,0,0.3);
  border-radius: 8px;
  padding: 4px 12px;
  text-align: center;
  min-width: 70px;
}

.hud-stat .label {
  display: block;
  font-size: 10px;
  color: #c8a882;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hud-stat span:last-child {
  font-size: 18px;
  font-weight: 800;
  color: #ffd700;
  font-variant-numeric: tabular-nums;
}

.hud-controls {
  position: absolute;
  top: 0;
  right: 12px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

/* Panels */
h2 {
  color: #ffd700;
  font-size: clamp(20px, 5vw, 28px);
  margin-bottom: 20px;
  text-align: center;
}

.settings-group {
  width: min(320px, 90vw);
  margin-bottom: 16px;
}

.settings-group label {
  display: block;
  color: #c8a882;
  margin-bottom: 6px;
  font-size: 14px;
}

.settings-group input[type="range"] {
  width: 100%;
  accent-color: #ffd700;
}

.toggle-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: min(360px, 90vw);
  margin-bottom: 20px;
}

.stat-card {
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}

.stat-card .stat-label {
  font-size: 11px;
  color: #c8a882;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-size: 22px;
  font-weight: 800;
  color: #ffd700;
}

/* FPS */
.fps-counter {
  position: absolute;
  bottom: env(safe-area-inset-bottom, 8px);
  left: 8px;
  z-index: 30;
  background: rgba(0,0,0,0.6);
  color: #0f0;
  font-family: monospace;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
}

.fps-counter:not(.hidden) {
  display: block;
}

/* Mobile & small screens */
@media (max-width: 640px), (max-height: 500px) {
  .global-banner {
    padding: env(safe-area-inset-top, 6px) 8px 4px;
  }

  .global-label {
    font-size: clamp(8px, 2.2vw, 10px);
    letter-spacing: 0.04em;
    line-height: 1.3;
  }

  .global-count {
    font-size: clamp(18px, 5vw, 22px);
  }

  .hud {
    top: calc(env(safe-area-inset-top, 0px) + 46px);
  }

  .hud-row {
    gap: 6px;
    padding-right: 0;
  }

  .hud-stat {
    min-width: 0;
    flex: 1;
    max-width: 120px;
    padding: 6px 10px;
  }

  .hud-stat .label {
    font-size: 9px;
  }

  .hud-stat span:last-child {
    font-size: 16px;
  }

  .hud-controls {
    position: fixed;
    top: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    right: max(12px, env(safe-area-inset-right));
    z-index: 25;
  }

  .btn-icon {
    width: 48px;
    height: 48px;
    font-size: 18px;
    border-width: 2px;
    background: rgba(0, 0, 0, 0.65);
  }

  .game-title {
    font-size: clamp(24px, 9vw, 40px);
    margin-bottom: 6px;
  }

  .game-subtitle {
    font-size: clamp(13px, 3.5vw, 16px);
    margin-bottom: 24px;
    padding: 0 16px;
    text-align: center;
  }

  .menu-buttons {
    width: min(300px, 88vw);
    gap: 10px;
  }

  .btn {
    padding: 16px 20px;
    min-height: 48px;
    font-size: 15px;
  }

  .overlay {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .overlay.panel {
    padding-top: calc(env(safe-area-inset-top, 12px) + 16px);
  }

  .stats-grid {
    grid-template-columns: 1fr;
    width: min(320px, 92vw);
  }

  .stat-card .stat-value {
    font-size: 20px;
  }
}

@media (max-width: 380px) {
  .global-label {
    font-size: 7px;
  }

  .hud-stat span:last-child {
    font-size: 15px;
  }
}
