:root {
  --bg-color: #08090c;
  --panel-bg: rgba(17, 20, 28, 0.65);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --accent-neon-green: #10b981;
  --accent-neon-blue: #06b6d4;
  --accent-neon-red: #ef4444;
  --accent-neon-pink: #f43f5e;
  --accent-neon-yellow: #f59e0b;
  --accent-neon-purple: #a855f7;
  --shadow-neon: 0 0 15px rgba(6, 182, 212, 0.4);
  --font-family: 'Outfit', 'Noto Sans KR', -apple-system, sans-serif;
}

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

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  position: relative;
}

/* Star Backdrop Simulation */
.stars-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 40px),
    radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 30px),
    radial-gradient(white, rgba(255,255,255,.1) 2px, transparent 40px);
  background-size: 550px 550px, 350px 350px, 250px 250px;
  background-position: 0 0, 40px 60px, 130px 270px;
  opacity: 0.18;
  z-index: -1;
  pointer-events: none;
}

.game-shell {
  width: 100%;
  max-width: 1240px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Header & Controls */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 0.8rem;
}

.brand h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4, #10b981);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand .badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  background: var(--accent-neon-pink);
  color: white;
  -webkit-text-fill-color: white;
  font-weight: 600;
  text-shadow: 0 0 5px rgba(244, 63, 94, 0.6);
}

.controls-panel {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: white;
}

.btn-secondary {
  background: rgba(31, 41, 55, 0.6);
  border-color: rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  background: rgba(55, 65, 81, 0.8);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0369a1, #0891b2);
  box-shadow: 0 6px 16px rgba(6, 182, 212, 0.4);
  transform: translateY(-1px);
}

/* Top HUD Bar */
.topbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 0.8rem 1.2rem;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.hud-item:last-child {
  border-right: none;
}

.hud-item .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.hud-item strong {
  font-size: 1.4rem;
  font-weight: 700;
}

.neon-text {
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.6), 0 0 15px var(--accent-neon-blue);
}

.neon-text-blue {
  color: #a5f3fc;
  text-shadow: 0 0 10px rgba(6, 182, 212, 0.8);
}

.neon-text-green {
  color: #a7f3d0;
  text-shadow: 0 0 10px rgba(16, 185, 129, 0.8);
}

/* Heart Life Icons */
.lives-container {
  display: flex;
  gap: 0.25rem;
  font-size: 1.1rem;
}

.lives-text {
  font-size: 1.1rem !important;
  color: var(--accent-neon-pink);
  display: none; /* fallback if screens are tiny */
}

/* Main Layout */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.2rem;
}

/* Play Area & Responsive Canvas */
.play-area {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
}

.status-bar {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--accent-neon-yellow);
  font-weight: 600;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.status-message {
  animation: pulseNeon 2s infinite alternate;
}

@keyframes pulseNeon {
  from { text-shadow: 0 0 5px rgba(245, 158, 11, 0.2); }
  to { text-shadow: 0 0 12px rgba(245, 158, 11, 0.8), 0 0 20px rgba(245, 158, 11, 0.4); }
}

.canvas-container {
  position: relative;
  width: 100%;
  background: #0b0d13;
  border: 2px solid rgba(6, 182, 212, 0.25);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(6, 182, 212, 0.05);
  overflow: hidden;
  aspect-ratio: 900 / 620;
}

#game {
  width: 100%;
  height: 100%;
  max-width: 100%;
  display: block;
}

/* Game Over / Pause Overlays */
.overlay-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(6, 7, 10, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.overlay-screen.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

.glassmorphism {
  background: rgba(17, 24, 39, 0.7);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), inset 0 1px 1px rgba(255, 255, 255, 0.1);
}

.overlay-content {
  padding: 2.5rem;
  border-radius: 16px;
  text-align: center;
  max-width: 480px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 1px solid rgba(6, 182, 212, 0.3);
}

@keyframes scaleIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.overlay-content h2 {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 1px;
}

.overlay-content p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Highscore Input inside Modal */
.name-input-area {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-top: 0.5rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.congrats-text {
  color: var(--accent-neon-yellow) !important;
  font-weight: 700;
  animation: bounce 1s infinite alternate;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-3px); }
}

.input-group {
  display: flex;
  gap: 0.5rem;
}

#playerName {
  flex: 1;
  background: rgba(17, 24, 39, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  color: white;
  font-family: var(--font-family);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

#playerName:focus {
  border-color: var(--accent-neon-blue);
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.3);
}

.overlay-actions {
  display: flex;
  justify-content: center;
  gap: 0.8rem;
  margin-top: 0.5rem;
}

.controls-guide-bar {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar: Leaderboard */
.sidebar-ranking {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.ranking-card {
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 620px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
}

.ranking-header {
  padding: 1.2rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ranking-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

.dreamlo-badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  background: rgba(6, 182, 212, 0.1);
  color: var(--accent-neon-blue);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: 4px;
  font-weight: 600;
}

.ranking-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem;
}

.ranking-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ranking-list li {
  padding: 0.7rem 0.8rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  font-size: 0.85rem;
  transition: background 0.2s;
  display: flex;
  align-items: center;
}

.ranking-list li:hover {
  background: rgba(255, 255, 255, 0.05);
}

.ranking-entry {
  display: flex;
  justify-content: space-between;
  width: 100%;
  align-items: center;
}

.ranking-entry-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.ranking-rank {
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--text-secondary);
  width: 1.2rem;
  text-align: center;
}

/* Rank Medals */
.ranking-list li:nth-child(1) .ranking-rank { color: #ffd700; font-size: 1.1rem; }
.ranking-list li:nth-child(2) .ranking-rank { color: #c0c0c0; font-size: 1.05rem; }
.ranking-list li:nth-child(3) .ranking-rank { color: #cd7f32; font-size: 1rem; }

.ranking-list li:nth-child(1) { border-color: rgba(253, 224, 71, 0.25); background: rgba(253, 224, 71, 0.03); }
.ranking-list li:nth-child(2) { border-color: rgba(209, 213, 219, 0.2); background: rgba(209, 213, 219, 0.02); }
.ranking-list li:nth-child(3) { border-color: rgba(180, 83, 9, 0.15); background: rgba(180, 83, 9, 0.01); }

.ranking-name {
  font-weight: 600;
  color: #fff;
}

.ranking-details {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
}

.ranking-score {
  font-weight: 700;
  color: var(--accent-neon-blue);
}

.ranking-level {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.ranking-footer {
  padding: 0.8rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(0, 0, 0, 0.15);
}

.ranking-state {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
}

/* Footer Section */
.game-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--panel-border);
  padding-top: 1rem;
  margin-top: 0.5rem;
}

.hidden {
  display: none !important;
}

/* Mobile Responsiveness */
@media (max-width: 992px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
  
  .ranking-card {
    max-height: 400px;
  }
}

@media (max-width: 600px) {
  .topbar {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }
  .hud-item {
    border-right: none;
    padding: 0.4rem 0;
  }
  .hud-item:nth-child(even) {
    border-left: 1px solid rgba(255, 255, 255, 0.05);
  }
  .lives-container {
    display: none;
  }
  .lives-text {
    display: inline;
  }
  .game-header {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  .controls-panel {
    justify-content: center;
  }
  .controls-guide-bar {
    font-size: 0.7rem;
  }
}
