/* --- DESIGN SYSTEM & RESET --- */
:root {
  --font-title: 'Fredoka', 'Outfit', sans-serif;
  --font-body: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Color Palette */
  --bg-gradient-start: #080718;
  --bg-gradient-end: #120e2a;
  --color-primary: #ff7597;
  --color-primary-hover: #ff5680;
  --color-secondary: #8b93ff;
  --color-secondary-hover: #6d77ff;
  --color-accent: #ffd35c;
  --color-text-dark: #f1f5f9;
  --color-text-light: #ffffff;
  --color-glass-bg: rgba(20, 16, 45, 0.75);
  --color-glass-border: rgba(255, 255, 255, 0.15);
  --color-card-shadow: rgba(0, 0, 0, 0.4);
  
  --border-radius-lg: 24px;
  --border-radius-md: 16px;
  --border-radius-sm: 8px;
  
  --transition-smooth: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --transition-fast: all 0.1s ease-out;
}

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

body {
  font-family: var(--font-body);
  background: radial-gradient(circle, #1a143b 0%, #080718 100%);
  color: var(--color-text-dark);
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* --- GAME CONTAINER --- */
#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 480px;
  max-height: 850px;
  background: linear-gradient(to bottom, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@media (min-width: 481px) {
  #game-container {
    border-radius: var(--border-radius-lg);
    border: 6px solid #ffffff;
    height: 95vh;
  }
}

/* --- SOUND TOGGLE --- */
#sound-toggle-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 100;
  background: var(--color-glass-bg);
  border: 1px solid var(--color-glass-border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--color-card-shadow);
  transition: var(--transition-smooth);
}

#sound-toggle-btn:hover {
  transform: scale(1.1);
  background: #ffffff;
}

#sound-toggle-btn.muted .icon {
  filter: grayscale(1) opacity(0.5);
}

/* --- SCREENS --- */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 40px 24px 30px 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease-in-out, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform: scale(0.95);
  z-index: 10;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

/* --- BUTTONS --- */
.btn {
  border: none;
  outline: none;
  font-family: var(--font-title);
  font-weight: 700;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  transition: var(--transition-smooth);
  text-decoration: none;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-light);
  box-shadow: 0 8px 0 #d94d70, 0 12px 20px rgba(255, 117, 151, 0.4);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 10px 0 #d94d70, 0 15px 25px rgba(255, 117, 151, 0.4);
}

.btn-primary:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 #d94d70, 0 4px 10px rgba(255, 117, 151, 0.4);
}

.btn-secondary {
  background: var(--color-secondary);
  color: var(--color-text-light);
  box-shadow: 0 8px 0 #6d77ff, 0 12px 20px rgba(139, 147, 255, 0.4);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.btn-secondary:hover {
  background: var(--color-secondary-hover);
  transform: translateY(-2px);
  box-shadow: 0 10px 0 #6d77ff, 0 15px 25px rgba(139, 147, 255, 0.4);
}

.btn-secondary:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 #6d77ff, 0 4px 10px rgba(139, 147, 255, 0.4);
}

.btn-outline {
  background: var(--color-glass-bg);
  border: 2px solid var(--color-secondary);
  color: var(--color-secondary);
  box-shadow: 0 6px 0 var(--color-secondary), 0 8px 15px rgba(139, 147, 255, 0.2);
}

.btn-outline:hover {
  background: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 8px 0 var(--color-secondary), 0 12px 20px rgba(139, 147, 255, 0.2);
}

.btn-outline:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--color-secondary), 0 4px 8px rgba(139, 147, 255, 0.2);
}

.btn-lg {
  padding: 16px 32px;
  font-size: 20px;
}

.btn-full {
  width: 100%;
  padding: 14px 20px;
  font-size: 18px;
}

.icon-btn {
  border: none;
  background: none;
  cursor: pointer;
  outline: none;
}

/* --- MAIN MENU SCREEN --- */
#menu-screen {
  justify-content: space-between;
}

.logo-container {
  text-align: center;
  margin-top: 30px;
}

.game-title {
  font-family: var(--font-title);
  font-size: 54px;
  font-weight: 800;
  line-height: 1.1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.word-cute {
  color: var(--color-accent);
  text-shadow: 0 0 10px rgba(255, 211, 92, 0.8), 0 0 20px rgba(255, 211, 92, 0.4);
  transform: rotate(-5deg) translateX(-15px);
  display: inline-block;
  animation: float-left 3s ease-in-out infinite alternate;
}

.word-stairs {
  color: var(--color-secondary);
  text-shadow: 0 0 10px rgba(139, 147, 255, 0.8), 0 0 20px rgba(139, 147, 255, 0.4);
  transform: rotate(3deg) translateX(15px);
  display: inline-block;
  animation: float-right 3s ease-in-out infinite alternate;
}

.game-subtitle {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 16px;
  color: #72637a;
  letter-spacing: 2px;
  margin-top: 10px;
  background: var(--color-glass-bg);
  padding: 4px 16px;
  border-radius: var(--border-radius-sm);
  display: inline-block;
}

/* Character Carousel */
.character-select-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.section-title {
  font-family: var(--font-title);
  font-size: 18px;
  color: var(--color-text-dark);
  margin-bottom: 12px;
}

.carousel-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: var(--color-glass-bg);
  border: 2px solid var(--color-glass-border);
  border-radius: var(--border-radius-lg);
  padding: 16px;
  box-shadow: 0 12px 30px var(--color-card-shadow);
  backdrop-filter: blur(10px);
}

.carousel-nav-btn {
  background: var(--color-glass-bg);
  border: 1px solid var(--color-glass-border);
  color: var(--color-text-dark);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  transition: var(--transition-smooth);
}

.carousel-nav-btn:hover {
  transform: scale(1.1);
  background: var(--color-accent);
  color: white;
}

.carousel-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-grow: 1;
}

#character-preview-canvas {
  filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.1));
}

#character-info {
  text-align: center;
  margin-top: 8px;
}

#character-name {
  font-family: var(--font-title);
  font-size: 18px;
  color: var(--color-text-dark);
}

#character-description {
  font-size: 13px;
  color: #72637a;
  margin-top: 4px;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  margin-bottom: 10px;
}

.game-tips {
  text-align: center;
  font-size: 13px;
  color: #72637a;
}

/* --- PLAYING SCREEN --- */
#play-screen {
  padding: 16px 0 0 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#hud {
  position: relative;
  z-index: 10;
  padding: 10px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Energy Bar */
.energy-bar-container {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-glass-bg);
  border: 1px solid var(--color-glass-border);
  padding: 6px 12px;
  border-radius: 20px;
  backdrop-filter: blur(5px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.energy-bar-icon {
  font-size: 18px;
  color: var(--color-accent);
  animation: pulse 1s ease-in-out infinite alternate;
}

.energy-bar-track {
  flex-grow: 1;
  height: 14px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 7px;
  overflow: hidden;
}

#energy-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(to right, #ff9800, #ffeb3b);
  border-radius: 7px;
  transition: width 0.1s linear, background-color 0.3s ease;
}

/* Score & Combo */
.hud-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.score-display {
  background: var(--color-glass-bg);
  border: 1px solid var(--color-glass-border);
  padding: 8px 18px;
  border-radius: var(--border-radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  backdrop-filter: blur(5px);
  box-shadow: 0 4px 12px var(--color-card-shadow);
}

.score-display .label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #72637a;
}

#live-score {
  font-family: var(--font-title);
  font-size: 32px;
  font-weight: 800;
  color: var(--color-secondary);
}

.combo-bubble {
  background: var(--color-primary);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 4px 10px rgba(255, 117, 151, 0.3);
  opacity: 0;
  transform: scale(0.7) rotate(-5deg);
  transition: var(--transition-smooth);
}

.combo-bubble.show {
  opacity: 1;
  transform: scale(1) rotate(-5deg);
}

/* Controller Controls */
.game-controls {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 0 20px 30px 20px;
}

.control-btn {
  border: none;
  outline: none;
  border-radius: var(--border-radius-lg);
  padding: 16px 16px 20px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-title);
  transition: var(--transition-fast);
}

.control-btn.climb {
  background: var(--color-secondary);
  color: white;
  box-shadow: 0 10px 0 #5c64d4, 0 12px 24px rgba(139, 147, 255, 0.4);
}

.control-btn.climb:active {
  transform: translateY(6px);
  box-shadow: 0 4px 0 #5c64d4, 0 6px 12px rgba(139, 147, 255, 0.4);
}

.control-btn.turn {
  background: var(--color-primary);
  color: white;
  box-shadow: 0 10px 0 #d94d70, 0 12px 24px rgba(255, 117, 151, 0.4);
}

.control-btn.turn:active {
  transform: translateY(6px);
  box-shadow: 0 4px 0 #d94d70, 0 6px 12px rgba(255, 117, 151, 0.4);
}

.keycap {
  background: #ffffff;
  color: var(--color-text-dark);
  font-family: var(--font-title);
  font-size: 32px;
  font-weight: 800;
  width: 60px;
  height: 60px;
  border-radius: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 5px 0 #ccd4e0, 0 8px 12px rgba(0, 0, 0, 0.15);
  border: 2px solid #ffffff;
  margin-bottom: 10px;
  transition: var(--transition-fast);
}

.control-btn:active .keycap {
  transform: translateY(2px);
  box-shadow: 0 3px 0 #ccd4e0, 0 4px 6px rgba(0, 0, 0, 0.15);
}

.control-label-group {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.control-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.control-desc {
  font-family: var(--font-body);
  font-size: 11px;
  opacity: 0.8;
  margin-top: 2px;
}

/* --- GAMEOVER SCREEN --- */
#gameover-screen {
  background: rgba(253, 213, 232, 0.5);
  backdrop-filter: blur(10px);
  justify-content: center;
  align-items: center;
}

.gameover-box {
  width: 100%;
  background: #191535;
  border-radius: var(--border-radius-lg);
  padding: 24px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
  border: 4px solid var(--color-glass-border);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gameover-title {
  font-family: var(--font-title);
  font-size: 38px;
  font-weight: 800;
  color: var(--color-primary);
  margin-bottom: 16px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.05);
  animation: bounce 1.2s infinite;
}

.gameover-score-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  margin-bottom: 20px;
}

.final-score-box, .best-score-box {
  background: #0f0b24;
  padding: 12px;
  border-radius: var(--border-radius-md);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 2px dashed rgba(139, 147, 255, 0.3);
}

.final-score-box .label, .best-score-box .label {
  font-size: 11px;
  font-weight: 700;
  color: #72637a;
}

.final-score-box span:last-child {
  font-family: var(--font-title);
  font-size: 28px;
  font-weight: 800;
  color: var(--color-primary);
}

.best-score-box span:last-child {
  font-family: var(--font-title);
  font-size: 28px;
  font-weight: 800;
  color: var(--color-secondary);
}

/* Leaderboard Section */
.leaderboard-section {
  width: 100%;
  background: #0f0b24;
  border-radius: var(--border-radius-md);
  padding: 16px;
  margin-bottom: 20px;
  max-height: 250px;
  overflow-y: auto;
  border: 1px solid rgba(139, 147, 255, 0.2);
}

.leaderboard-title {
  text-align: center;
  font-family: var(--font-title);
  font-size: 16px;
  color: var(--color-text-dark);
  margin-bottom: 12px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.leaderboard-table th {
  font-family: var(--font-title);
  font-weight: 700;
  color: #a78bfa;
  text-align: center;
  padding-bottom: 6px;
  border-bottom: 2px solid #1e1b4b;
}

.leaderboard-table td {
  padding: 8px 4px;
  text-align: center;
  border-bottom: 1px solid #110e2e;
}

.leaderboard-table tr:last-child td {
  border-bottom: none;
}

.leaderboard-table tr.rank-1 { background-color: rgba(255, 211, 92, 0.15); font-weight: bold; }
.leaderboard-table tr.rank-2 { background-color: rgba(192, 192, 192, 0.15); font-weight: bold; }
.leaderboard-table tr.rank-3 { background-color: rgba(205, 127, 50, 0.15); font-weight: bold; }

.medal {
  font-size: 16px;
}

.gameover-actions {
  display: flex;
  width: 100%;
  gap: 12px;
}

.gameover-actions button {
  flex-grow: 1;
}

/* Spinner */
.spinner-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
  color: #72637a;
  font-size: 12px;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(139, 147, 255, 0.1);
  border-top-color: var(--color-secondary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 8px;
}

.error-container {
  text-align: center;
  padding: 10px 0;
  color: #d94d70;
  font-size: 13px;
}

.error-container button {
  margin-top: 8px;
}

.hidden {
  display: none !important;
}

/* --- MODAL --- */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(58, 50, 64, 0.4);
  backdrop-filter: blur(6px);
  z-index: 50;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease-out;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  width: 100%;
  max-width: 360px;
  background: #191535;
  border-radius: var(--border-radius-lg);
  padding: 28px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  border: 4px solid var(--color-glass-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transform: translateY(20px) scale(0.95);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.active .modal-box {
  transform: translateY(0) scale(1);
}

.modal-badge {
  background: var(--color-accent);
  color: var(--color-text-dark);
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 14px;
  padding: 6px 16px;
  border-radius: 20px;
  box-shadow: 0 4px 10px rgba(255, 211, 92, 0.3);
  margin-bottom: 16px;
  animation: bounce 1.5s infinite;
}

.modal-title {
  font-family: var(--font-title);
  font-size: 26px;
  font-weight: 800;
  color: var(--color-secondary);
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 14px;
  color: #72637a;
  line-height: 1.5;
  margin-bottom: 20px;
}

.modal-desc strong {
  color: var(--color-primary);
}

.name-input-group {
  width: 100%;
  position: relative;
  margin-bottom: 8px;
}

#player-name-input {
  width: 100%;
  border: 2px solid #312e81;
  background: #0f0b24;
  border-radius: var(--border-radius-md);
  padding: 14px 44px 14px 16px;
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 18px;
  color: white;
  outline: none;
  transition: var(--transition-smooth);
}

#player-name-input:focus {
  border-color: var(--color-secondary);
  background: #110e2e;
  box-shadow: 0 0 0 4px rgba(139, 147, 255, 0.2);
}

.char-count {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: #b3acc0;
  font-family: var(--font-body);
}

.modal-error {
  color: var(--color-primary);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* --- ANIMATIONS --- */
@keyframes float-left {
  0% { transform: rotate(-5deg) translateY(0); }
  100% { transform: rotate(-7deg) translateY(-8px); }
}

@keyframes float-right {
  0% { transform: rotate(3deg) translateY(0); }
  100% { transform: rotate(5deg) translateY(-8px); }
}

@keyframes pulse {
  0% { transform: scale(1); }
  100% { transform: scale(1.15); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

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

.pulse {
  animation: pulse-button 2s infinite;
}

@keyframes pulse-button {
  0% { box-shadow: 0 8px 0 #d94d70, 0 12px 20px rgba(255, 117, 151, 0.4); }
  50% { box-shadow: 0 8px 0 #d94d70, 0 12px 30px rgba(255, 117, 151, 0.7); }
  100% { box-shadow: 0 8px 0 #d94d70, 0 12px 20px rgba(255, 117, 151, 0.4); }
}
