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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: #1a1a2e;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

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

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

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

/* --- Buttons --- */
.btn {
  background: linear-gradient(135deg, #4caf50, #2e7d32);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 32px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  pointer-events: auto;
  touch-action: manipulation;
}

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

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

.btn:focus-visible {
  outline: 3px solid #ffd700;
  outline-offset: 3px;
}

.btn-large {
  padding: 16px 48px;
  font-size: 1.4rem;
  border-radius: 16px;
}

.btn-small {
  padding: 8px 20px;
  font-size: 0.85rem;
}

.btn-pause {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.btn-start {
  background: linear-gradient(135deg, #ff9800, #f44336);
  font-size: 1.6rem;
  padding: 18px 56px;
  border-radius: 50px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.btn-start:hover {
  animation: none;
}

.btn-back, .btn-reset, .btn-sound-toggle {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-sound-toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Title Screen --- */
.title-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
  text-align: center;
  padding: 20px;
}

.title-logo {
  animation: fadeInDown 0.8s ease-out;
}

.main-title {
  font-size: clamp(2.5rem, 8vw, 5rem);
  font-weight: 900;
  background: linear-gradient(135deg, #ffd700, #ff9800, #f44336, #4caf50);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: gradientShift 4s ease-in-out infinite;
  text-shadow: none;
  line-height: 1.1;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.subtitle {
  font-size: clamp(0.9rem, 2.5vw, 1.3rem);
  color: rgba(255, 255, 255, 0.8);
  letter-spacing: 2px;
  margin-top: 8px;
}

.title-footer {
  position: absolute;
  bottom: 20px;
  display: flex;
  gap: 10px;
}

/* --- Level Select --- */
.level-select-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 20px;
  max-width: 900px;
  width: 100%;
}

.section-title {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  font-weight: 800;
  color: #ffd700;
  margin-bottom: 8px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 800px;
}

.level-card {
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  transition: transform 0.2s, border-color 0.2s;
  min-height: 200px;
}

.level-card:hover {
  transform: translateY(-3px);
  border-color: #ffd700;
}

.level-card.locked {
  opacity: 0.5;
  pointer-events: none;
}

.level-card.locked:hover {
  transform: none;
  border-color: rgba(255, 255, 255, 0.15);
}

.level-card-header {
  text-align: center;
}

.level-card-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.level-desc {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
}

.level-locked-text {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 4px;
}

.level-card-stats {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.level-stars {
  display: flex;
  gap: 4px;
}

.star {
  font-size: 1.5rem;
  transition: transform 0.3s, color 0.3s;
}

.star-filled {
  color: #ffd700;
}

.star-empty {
  color: rgba(255, 255, 255, 0.2);
}

.star-animate {
  animation: starPop 0.4s ease-out;
}

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

.level-best {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
}

.level-card-locked-icon {
  font-size: 2rem;
  opacity: 0.4;
}

.btn-play-level {
  width: 100%;
  padding: 10px;
  font-size: 0.9rem;
}

.ls-footer {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 10px;
}

/* --- HUD --- */
#hud-screen {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}

#hud-screen > * {
  pointer-events: auto;
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.hud-score {
  font-size: 1.8rem;
  font-weight: 800;
  color: #ffd700;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.hud-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.hud-timer {
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.hud-timer.timer-warning {
  color: #ff4444;
  animation: blink 0.5s linear infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.hud-combo {
  font-size: 1.4rem;
  font-weight: 800;
  color: #ff9800;
  text-shadow: 0 2px 8px rgba(255, 152, 0, 0.5);
  animation: comboIn 0.3s ease-out;
}

@keyframes comboIn {
  0% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

.hud-lives {
  display: flex;
  gap: 4px;
  font-size: 1.4rem;
}

.life-icon {
  color: #ff1744;
  text-shadow: 0 1px 4px rgba(255, 23, 68, 0.5);
}

.life-empty {
  color: rgba(255, 255, 255, 0.2);
}

/* --- Pause Screen --- */
.pause-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(15px);
  padding: 40px 50px;
  border-radius: 20px;
  border: 2px solid rgba(255, 255, 255, 0.1);
}

/* --- Results Screen --- */
.results-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(15px);
  padding: 30px 36px;
  border-radius: 20px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  max-width: 400px;
  width: 90%;
}

.stars-container {
  display: flex;
  gap: 8px;
  font-size: 2.5rem;
  margin: 8px 0;
}

.results-stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 1rem;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-row span:first-child {
  color: rgba(255, 255, 255, 0.6);
}

.stat-row span:last-child {
  font-weight: 700;
  color: #ffd700;
}

.results-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 8px;
}

.results-buttons .btn {
  width: 100%;
}

/* --- Game Over Screen --- */
.gameover-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(15px);
  padding: 40px;
  border-radius: 24px;
  border: 3px solid #ffd700;
  text-align: center;
  max-width: 500px;
  width: 90%;
}

.gameover-title {
  font-size: clamp(2rem, 7vw, 4rem);
  font-weight: 900;
  background: linear-gradient(135deg, #ffd700, #ff6f00);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: gradientShift 3s ease-in-out infinite;
}

.gameover-sub {
  font-size: clamp(1rem, 3vw, 1.5rem);
  color: rgba(255, 255, 255, 0.8);
  font-style: italic;
}

.gameover-stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gameover-stats .stat-row span:last-child {
  font-size: 1.3rem;
}

.gameover-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.gameover-buttons .btn {
  width: 100%;
}

/* --- Animations --- */
@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Responsive --- */
@media (max-width: 600px) {
  .btn {
    padding: 10px 24px;
    font-size: 1rem;
  }

  .btn-large {
    padding: 14px 36px;
    font-size: 1.2rem;
  }

  .level-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .level-card {
    padding: 14px 10px;
    min-height: 150px;
  }

  .level-card-header h3 {
    font-size: 0.95rem;
  }

  .results-content,
  .pause-content,
  .gameover-content {
    padding: 20px;
  }

  .hud-score {
    font-size: 1.4rem;
  }

  .hud-timer {
    font-size: 1.1rem;
  }
}

@media (max-width: 380px) {
  .level-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .btn-start {
    padding: 14px 36px;
    font-size: 1.3rem;
  }
}

/* --- Landscape adjustments --- */
@media (orientation: landscape) and (max-height: 500px) {
  .level-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .level-card {
    min-height: auto;
    padding: 10px 8px;
  }

  .title-content {
    gap: 15px;
  }

  .main-title {
    font-size: clamp(2rem, 6vw, 3.5rem);
  }
}
