/* CSS variables for visual details */
:root {
  --bg-color: #0b0f19;
  --panel-bg: rgba(18, 25, 41, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: rgba(255, 255, 255, 0.2);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent-cyan: #3cd4c8;
  --accent-orange: #ff763b;
  --accent-blue: #3b82f6;
  --accent-red: #ef4444;
  --accent-green: #10b981;
  --accent-yellow: #f59e0b;
  --glow-shadow: 0 0 15px rgba(60, 212, 200, 0.4);
  --card-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body {
  background-color: #04060a;
  color: var(--text-primary);
  font-family: var(--font-family);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* The vertical mobile game container */
#game-container {
  width: 100%;
  max-width: 480px;
  height: 100%;
  max-height: 900px;
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(at 50% 0%, rgba(60, 212, 200, 0.08) 0px, transparent 50%),
    radial-gradient(at 0% 100%, rgba(255, 118, 59, 0.05) 0px, transparent 50%),
    radial-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 0);
  background-size: 100% 100%, 100% 100%, 20px 20px;
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
  position: relative;
}

/* Top HUD Layout */
.hud-top {
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

.hud-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.level-indicator {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 30%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.progress-container {
  width: 150px;
  height: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 7px;
  position: relative;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-blue));
  border-radius: 6px;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 8px rgba(60, 212, 200, 0.5);
}

.progress-text {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  font-size: 9px;
  font-weight: 800;
  text-align: center;
  line-height: 12px;
  color: var(--text-primary);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.hud-right {
  display: flex;
  align-items: center;
}

.lives-container {
  display: flex;
  gap: 8px;
}

.heart {
  font-size: 1.4rem;
  filter: grayscale(100%) opacity(20%);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), filter 0.2s ease;
}

.heart.active {
  filter: grayscale(0%) opacity(100%) drop-shadow(0 0 4px rgba(239, 68, 68, 0.5));
  animation: pulse-heart 1.2s infinite ease-in-out alternate;
}

@keyframes pulse-heart {
  0% { transform: scale(1); }
  100% { transform: scale(1.08); }
}

/* Game Viewport and Canvas centering */
.game-viewport {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  padding: 10px;
}

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

/* Bottom HUD Layout */
.hud-bottom {
  padding: 24px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  z-index: 10;
}

/* Actions styling */
.action-btn {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 16px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  outline: none;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-active);
  transform: translateY(-2px);
}

.action-btn:active {
  transform: translateY(0) scale(0.96);
}

#btn-settings {
  width: 52px;
  height: 52px;
}

#btn-settings svg {
  color: var(--text-secondary);
  transition: transform 0.4s ease;
}

#btn-settings:hover svg {
  color: var(--text-primary);
  transform: rotate(45deg);
}

.text-btn {
  flex: 1;
  height: 52px;
  font-size: 0.95rem;
  font-weight: 600;
  gap: 8px;
  padding: 0 20px;
}

.btn-icon {
  font-size: 1.15rem;
}

/* Modals overlays & Dialogs design */
.game-modal {
  border: none;
  background: transparent;
  width: 100%;
  height: 100%;
  display: none; /* Controlled by display or showModal */
  justify-content: center;
  align-items: center;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 100;
  padding: 24px;
}

.game-modal[open] {
  display: flex;
}

.game-modal::backdrop {
  background: rgba(2, 4, 8, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-content {
  width: 100%;
  max-width: 380px;
  background: rgba(14, 22, 38, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 32px;
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  animation: modal-enter 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modal-enter {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-glow-bg {
  position: absolute;
  width: 250px;
  height: 250px;
  background: radial-gradient(circle, rgba(60, 212, 200, 0.25) 0%, transparent 70%);
  top: -80px;
  filter: blur(20px);
  pointer-events: none;
}

.modal-glow-bg.fail-glow {
  background: radial-gradient(circle, rgba(239, 68, 68, 0.25) 0%, transparent 70%);
}

.modal-content h2 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 12px;
  z-index: 2;
  letter-spacing: -0.02em;
}

#win-title {
  background: linear-gradient(135deg, #ffffff 40%, var(--accent-cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

#fail-title {
  background: linear-gradient(135deg, #ffffff 40%, var(--accent-red) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-content p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 28px;
  z-index: 2;
}

/* Stars for complete */
.stars-container {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  z-index: 2;
}

.star {
  font-size: 2.2rem;
  color: rgba(255, 255, 255, 0.1);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.star.active {
  color: var(--accent-yellow);
  text-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
  transform: scale(1.1);
  animation: star-spin 0.6s ease-out;
}

@keyframes star-spin {
  0% { transform: scale(0) rotate(-45deg); }
  70% { transform: scale(1.2) rotate(10deg); }
  100% { transform: scale(1.1) rotate(0); }
}

/* Buttons inside modals */
.modal-btn {
  width: 100%;
  height: 54px;
  border-radius: 18px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  transition: all 0.2s ease;
  outline: none;
  z-index: 2;
  position: relative;
}

.modal-btn:last-child {
  margin-bottom: 0;
}

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

.primary-btn {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  color: #0b0f19;
  font-weight: 800;
  box-shadow: 0 4px 15px rgba(60, 212, 200, 0.3);
}

.primary-btn:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 20px rgba(60, 212, 200, 0.5);
}

.accent-btn {
  background: linear-gradient(135deg, #ff7e36, #ef4444);
  color: #ffffff;
  font-weight: 800;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.accent-btn:hover {
  filter: brightness(1.1);
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.5);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-active);
}

/* Settings modal special style */
.settings-content {
  padding: 30px 24px;
}

.settings-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 24px;
}

.settings-group label {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.toggle-buttons {
  display: flex;
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 4px;
}

.toggle-btn {
  flex: 1;
  height: 38px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
}

.toggle-btn.active {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.wide-btn {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-weight: 600;
  cursor: pointer;
}

.wide-btn.active {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

/* Level Grid in Settings */
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 4px;
}

.level-grid::-webkit-scrollbar {
  width: 4px;
}

.level-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

.level-btn {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s ease;
}

.level-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-active);
  color: var(--text-primary);
}

.level-btn.completed {
  background: rgba(60, 212, 200, 0.08);
  border-color: rgba(60, 212, 200, 0.3);
  color: var(--accent-cyan);
}

.level-btn.active {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
  color: #0b0f19;
  font-weight: 800;
  box-shadow: 0 0 10px rgba(60, 212, 200, 0.3);
}

/* Simulated ad spinner */
.ad-loader-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: ad-spin 0.8s linear infinite;
  display: inline-block;
}

@keyframes ad-spin {
  to { transform: rotate(360deg); }
}

/* Custom visual pulse effect (used visually when hint triggers) */
@keyframes pulse-glowing {
  0% { filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.3)); }
  50% { filter: drop-shadow(0 0 12px rgba(255, 255, 255, 0.9)); }
  100% { filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.3)); }
}

/* Media Queries for Desktop centering scaling */
@media (min-width: 480px) {
  #game-container {
    height: 95vh;
    border-radius: 36px;
  }
}
