/* ===== Forest 2048 - Global Styles ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #f0f7ee;
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

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

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  outline: none;
  cursor: default;
}

#game-canvas:focus {
  outline: none;
}

.hidden { display: none !important; }

/* Prevent overlays from stealing focus */
#ui-overlay,
#menu-overlay,
#select-overlay,
#win-overlay,
#lose-overlay,
#codex-overlay {
  outline: none;
}

button:focus {
  outline: none;
}

/* ===== UI Overlay ===== */
#ui-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 10;
}

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

/* Score Panel */
#score-panel {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.95);
  border-radius: 18px;
  padding: 10px 36px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(74,154,72,0.15);
  border: 2px solid rgba(74,154,72,0.2);
}

.score-label {
  font-size: 14px;
  color: #6aad5a;
  letter-spacing: 3px;
  font-weight: 600;
}

#score-value {
  font-size: 38px;
  font-weight: 800;
  color: #3a8a2a;
}

/* Global mute button - always visible */
.global-mute {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 30;
}

/* Control Buttons */
#game-controls {
  position: absolute;
  top: 20px;
  right: 76px;
  display: flex;
  gap: 10px;
}

.ctrl-btn {
  width: 46px;
  height: 46px;
  border: 2px solid rgba(74,154,72,0.2);
  border-radius: 14px;
  background: rgba(255,255,255,0.95);
  color: #4a9a3a;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(0,0,0,0.06);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ctrl-btn:hover {
  background: #fff;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(74,154,72,0.2);
}

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

/* ===== Menu Overlay ===== */
#menu-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  background: rgba(240,247,238,0.9);
}

.menu-content {
  text-align: center;
  padding: 48px 36px;
  max-width: 400px;
  width: 92%;
  background: rgba(255,255,255,0.95);
  border-radius: 28px;
  box-shadow: 0 12px 48px rgba(74,154,72,0.15);
  border: 2px solid rgba(74,154,72,0.15);
}

.game-title {
  font-size: 40px;
  font-weight: 900;
  color: #3a8a2a;
  margin-bottom: 32px;
  letter-spacing: 6px;
  text-shadow: 0 2px 8px rgba(74,154,72,0.2);
}

#menu-info {
  background: linear-gradient(135deg, #e8f5e4, #f0f7ee);
  border-radius: 20px;
  padding: 22px 28px;
  margin-bottom: 28px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.04);
  border: 1px solid rgba(74,154,72,0.15);
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(74,154,72,0.1);
}

.info-row:last-child { border-bottom: none; }

.info-label {
  font-size: 15px;
  color: #5a9a4a;
  font-weight: 500;
}

.info-row span:last-child {
  font-size: 20px;
  font-weight: 800;
  color: #2a7a1a;
}

/* Buttons */
.primary-btn, .secondary-btn {
  border: none;
  border-radius: 18px;
  padding: 16px 42px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 2px;
}

.primary-btn {
  background: linear-gradient(135deg, #5cc45a, #3aaa38);
  color: #fff;
  box-shadow: 0 6px 24px rgba(58,170,56,0.35);
}

.primary-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 32px rgba(58,170,56,0.45);
}

.primary-btn:active { transform: translateY(0) scale(0.97); }

.secondary-btn {
  background: rgba(255,255,255,0.95);
  color: #4a9a3a;
  box-shadow: 0 3px 12px rgba(0,0,0,0.06);
  border: 2px solid rgba(74,154,72,0.2);
}

.secondary-btn:hover {
  background: #fff;
  transform: translateY(-2px);
}

.secondary-btn:active { transform: scale(0.97); }

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

/* ===== Species Select ===== */
#select-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(240,247,238,0.97);
  z-index: 20;
}

.select-content {
  text-align: center;
  padding: 36px 24px;
  max-width: 460px;
  width: 95%;
}

.select-title {
  font-size: 30px;
  color: #3a8a2a;
  margin-bottom: 28px;
  font-weight: 800;
}

.species-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.species-card {
  background: rgba(255,255,255,0.98);
  border-radius: 22px;
  padding: 22px 14px;
  cursor: pointer;
  transition: all 0.25s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  border: 2px solid rgba(74,154,72,0.12);
}

.species-card:hover:not(.locked) {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 32px rgba(74,154,72,0.2);
  border-color: rgba(74,154,72,0.3);
}

.species-card:active:not(.locked) {
  transform: scale(0.97);
}

.species-card.locked {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.species-card-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.species-card-name {
  font-size: 16px;
  font-weight: 700;
  color: #2a7a1a;
}

.species-card-status {
  font-size: 12px;
  color: #7ab86a;
  margin-top: 5px;
}

/* ===== Win/Lose Overlays ===== */
#win-overlay, #lose-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
}

#win-overlay { background: rgba(74,194,72,0.95); }
#lose-overlay { background: rgba(120,140,120,0.95); }

.result-content {
  text-align: center;
  padding: 48px 32px;
  max-width: 380px;
  width: 92%;
  background: rgba(255,255,255,0.95);
  border-radius: 28px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.15);
}

.result-title {
  font-size: 36px;
  font-weight: 900;
  margin-bottom: 24px;
}

.win-title { color: #2a8a1a; }
.lose-title { color: #5a6a5a; }

#win-creature-display {
  width: 140px;
  height: 140px;
  margin: 0 auto 24px;
}

#unlock-notification {
  background: linear-gradient(135deg, #e8f5e4, #d0ecd0);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 20px;
  border: 2px solid rgba(74,154,72,0.2);
}

.unlock-text {
  font-size: 14px;
  color: #4a9a3a;
  margin-bottom: 6px;
  font-weight: 600;
}

#unlock-species-name {
  font-size: 22px;
  font-weight: 800;
  color: #2a7a1a;
}

.result-score {
  font-size: 20px;
  color: #3a6a2a;
  margin-bottom: 12px;
  font-weight: 600;
}

.result-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  margin-top: 24px;
}

/* ===== Codex ===== */
#codex-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(240,247,238,0.97);
  z-index: 20;
  overflow-y: auto;
}

.codex-content {
  text-align: center;
  padding: 60px 20px 36px;
  max-width: 720px;
  width: 95%;
  overflow-y: auto;
  max-height: 100vh;
}

.codex-title {
  font-size: 30px;
  color: #3a8a2a;
  margin-bottom: 28px;
  font-weight: 800;
}

#codex-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 28px;
}

.codex-species {
  background: rgba(255,255,255,0.98);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  border: 2px solid rgba(74,154,72,0.12);
}

.codex-species.locked {
  opacity: 0.4;
  filter: grayscale(0.5);
}

.codex-species-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.codex-species-icon {
  font-size: 36px;
}

.codex-species-name {
  font-size: 20px;
  font-weight: 800;
  color: #2a7a1a;
}

.codex-evolution {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 10px 0;
}

.codex-evo-cell {
  width: 104px;
  height: 104px;
  border-radius: 20px;
  background: #e8f5e4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #4a9a3a;
  position: relative;
  border: 1px solid rgba(74,154,72,0.15);
}

.codex-evo-cell.unlocked {
  background: #d0ecd0;
  border-color: rgba(74,154,72,0.3);
}

.codex-evo-level {
  position: absolute;
  bottom: 4px;
  right: 6px;
  font-size: 12px;
  color: #7ab86a;
  font-weight: 700;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .game-title { font-size: 32px; letter-spacing: 4px; }
  .species-grid { gap: 12px; }
  .species-card { padding: 18px 10px; }
  .species-card-icon { font-size: 40px; }
  #score-value { font-size: 30px; }
  .primary-btn, .secondary-btn { padding: 14px 32px; font-size: 16px; }
  .menu-content { padding: 36px 24px; }
}

@media (max-width: 360px) {
  .game-title { font-size: 26px; }
  .species-card-icon { font-size: 34px; }
}
