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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Arial Rounded MT Bold', Arial, sans-serif;
  background: #000;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  z-index: 10;
}

.screen.active {
  display: flex;
}

#start-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  pointer-events: auto;
}

#start-logo {
  text-align: center;
  margin-bottom: 40px;
  animation: logoBounce 2s ease-in-out infinite;
}

#start-logo h1 {
  font-size: clamp(48px, 10vw, 96px);
  font-weight: 900;
  color: #ff4466;
  text-shadow:
    0 4px 0 #cc2244,
    0 8px 0 #991133,
    0 12px 20px rgba(0,0,0,0.4);
  letter-spacing: 4px;
  line-height: 1.1;
}

@keyframes logoBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.game-btn {
  padding: 16px 48px;
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 800;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  color: #fff;
  background: #4488ff;
  box-shadow: 0 6px 0 #2266cc, 0 8px 16px rgba(0,0,0,0.3);
  transition: transform 0.1s, box-shadow 0.1s;
  text-transform: uppercase;
  letter-spacing: 2px;
  min-width: 160px;
  min-height: 56px;
}

.game-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #2266cc, 0 12px 20px rgba(0,0,0,0.3);
}

.game-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #2266cc, 0 4px 8px rgba(0,0,0,0.3);
}

.primary-btn {
  background: #ff6644;
  box-shadow: 0 6px 0 #cc4422, 0 8px 16px rgba(0,0,0,0.3);
}

.primary-btn:hover {
  box-shadow: 0 8px 0 #cc4422, 0 12px 20px rgba(0,0,0,0.3);
}

.primary-btn:active {
  box-shadow: 0 2px 0 #cc4422, 0 4px 8px rgba(0,0,0,0.3);
}

.icon-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 12px;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
  backdrop-filter: blur(4px);
}

.icon-btn:hover {
  background: rgba(255,255,255,0.35);
}

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

.icon-btn.small {
  width: 40px;
  height: 40px;
  font-size: 16px;
  border-radius: 10px;
}

#map-screen {
  flex-direction: column;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
}

#map-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  gap: 16px;
}

#map-header h2 {
  color: #fff;
  font-size: clamp(20px, 4vw, 32px);
  font-weight: 800;
  flex: 1;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

#total-stars-display {
  color: #ffd700;
  font-size: clamp(14px, 2.5vw, 20px);
  font-weight: 700;
  white-space: nowrap;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

#map-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 16px 24px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
  align-content: center;
}

.map-card {
  background: rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 20px;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
  border: 2px solid rgba(255,255,255,0.15);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.map-card:hover:not(.locked) {
  transform: translateY(-4px);
  background: rgba(255,255,255,0.18);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.map-card:active:not(.locked) {
  transform: translateY(0);
}

.map-card.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.map-card .map-number {
  font-size: 14px;
  color: rgba(255,255,255,0.6);
  font-weight: 700;
  margin-bottom: 4px;
}

.map-card .map-name {
  font-size: clamp(16px, 2.5vw, 22px);
  color: #fff;
  font-weight: 800;
  margin-bottom: 8px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.map-card .map-preview {
  width: 100%;
  height: 80px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.map-card .map-score {
  font-size: 14px;
  color: rgba(255,255,255,0.7);
  font-weight: 600;
  margin-bottom: 6px;
}

.map-card .map-stars {
  font-size: 22px;
  letter-spacing: 4px;
}

.map-card .lock-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 40px;
  opacity: 0.6;
}

.star-filled { color: #ffd700; }
.star-empty { color: rgba(255,255,255,0.25); }

#game-screen {
  pointer-events: none;
}

#game-screen.active {
  display: block;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 16px;
  pointer-events: auto;
  z-index: 20;
}

#hud-left {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,0.45);
  padding: 6px 12px;
  border-radius: 12px;
  backdrop-filter: blur(4px);
}

#hud-map-name {
  color: #fff;
  font-size: clamp(12px, 2vw, 16px);
  font-weight: 700;
  white-space: nowrap;
}

#hud-center {
  background: rgba(0,0,0,0.45);
  padding: 8px 20px;
  border-radius: 12px;
  text-align: center;
  backdrop-filter: blur(4px);
}

#hud-score-label {
  color: rgba(255,255,255,0.6);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
}

#hud-score-val {
  color: #fff;
  font-size: clamp(20px, 4vw, 32px);
  font-weight: 900;
  transition: transform 0.15s;
}

#hud-score-val.bump {
  transform: scale(1.2);
}

#hud-right {
  background: rgba(0,0,0,0.45);
  padding: 8px 14px;
  border-radius: 12px;
  text-align: center;
  backdrop-filter: blur(4px);
}

#hud-pigs-label {
  color: rgba(255,255,255,0.6);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
}

#hud-pigs-icons {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  justify-content: center;
}

.pig-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ff8899;
  border: 2px solid #ff4466;
  transition: opacity 0.3s, transform 0.3s;
}

.pig-icon.used {
  opacity: 0.25;
  transform: scale(0.7);
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(4px);
}

.overlay.active {
  display: flex;
}

.overlay-panel {
  background: linear-gradient(135deg, #2a3a5c, #1a2540);
  border-radius: 24px;
  padding: 32px 40px;
  text-align: center;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  border: 2px solid rgba(255,255,255,0.1);
  animation: panelIn 0.3s ease-out;
}

@keyframes panelIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.overlay-title {
  font-size: clamp(24px, 5vw, 40px);
  font-weight: 900;
  color: #fff;
  margin-bottom: 20px;
  text-shadow: 0 3px 6px rgba(0,0,0,0.4);
}

.gameover-title {
  font-size: clamp(36px, 8vw, 64px);
  color: #ff4466;
  text-shadow: 0 4px 0 #cc2244, 0 8px 20px rgba(0,0,0,0.5);
}

.stars-row {
  font-size: clamp(32px, 6vw, 48px);
  letter-spacing: 8px;
  margin-bottom: 16px;
}

.stars-row .star-anim {
  display: inline-block;
  opacity: 0;
  transform: scale(0);
  animation: starPop 0.4s ease-out forwards;
}

.stars-row .star-anim:nth-child(1) { animation-delay: 0.2s; }
.stars-row .star-anim:nth-child(2) { animation-delay: 0.5s; }
.stars-row .star-anim:nth-child(3) { animation-delay: 0.8s; }

@keyframes starPop {
  0% { opacity: 0; transform: scale(0) rotate(-30deg); }
  60% { opacity: 1; transform: scale(1.3) rotate(10deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

.overlay-score {
  color: #fff;
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 700;
  margin-bottom: 8px;
}

.overlay-best {
  color: rgba(255,255,255,0.5);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.overlay-bonus {
  color: #88ff88;
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
  min-height: 24px;
}

.overlay-info {
  color: rgba(255,255,255,0.7);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.overlay-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.overlay-buttons .game-btn {
  padding: 12px 28px;
  font-size: clamp(14px, 2.5vw, 18px);
  min-width: 120px;
}

.stars-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 20px 0;
}

.stars-grid .star-group {
  font-size: 20px;
  letter-spacing: 2px;
}

.gameover-panel {
  max-width: 500px;
}

#rotate-hint {
  display: none;
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: rgba(255,255,255,0.7);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 12px;
  z-index: 100;
  text-align: center;
}

@media (max-width: 600px) {
  #map-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px 16px;
  }

  .overlay-panel {
    padding: 24px 20px;
  }

  .overlay-buttons .game-btn {
    min-width: 100px;
    padding: 10px 20px;
  }

  #hud {
    padding: 8px 10px;
  }

  #hud-map-name {
    display: none;
  }
}

@media (orientation: portrait) and (max-width: 768px) {
  #rotate-hint {
    display: block;
  }
}
