:root {
  --bg-dark: #0a0f1d;
  --bg-panel: rgba(15, 23, 42, 0.75);
  --bg-panel-light: rgba(30, 41, 59, 0.85);
  --border-glow: rgba(0, 216, 214, 0.4);
  --primary: #00d8d6;
  --primary-glow: rgba(0, 216, 214, 0.6);
  --success: #0be881;
  --warning: #ffa801;
  --danger: #ff5e57;
  --accent: #8854d0;
  --text-light: #f8fafc;
  --text-dim: #94a3b8;
}

body {
  margin: 0;
  padding: 0;
  background-color: #030712;
  color: var(--text-light);
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

/* Master Container */
#app {
  position: relative;
  width: 1024px;
  height: 768px;
  background-color: var(--bg-dark);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8), 
              0 0 40px rgba(0, 216, 214, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
}

/* Game Canvas container */
#game-container {
  width: 1024px;
  height: 768px;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

/* React Overlay Container */
.react-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 1024px;
  height: 768px;
  z-index: 10;
  pointer-events: none; /* Let clicks pass through when HUD is transparent */
  display: flex;
  flex-direction: column;
}

.interactive-panel {
  pointer-events: auto; /* Enable clicks on this specific panel */
}

/* Glassmorphism Panel base */
.glass-panel {
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
  color: var(--text-light);
}

/* Screens (Menu, Character Select, etc.) */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, rgba(17, 24, 39, 0.95) 0%, rgba(3, 7, 18, 0.99) 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 20;
  animation: fadeIn 0.4s ease-out;
  padding: 40px;
  box-sizing: border-box;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(1.02); }
  to { opacity: 1; transform: scale(1); }
}

/* Title Styling */
.title-container {
  text-align: center;
  margin-bottom: 40px;
}

.game-title {
  font-size: 4.5rem;
  font-weight: 800;
  margin: 0;
  background: linear-gradient(135deg, #00ffff 0%, #a855f7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-transform: uppercase;
  letter-spacing: 4px;
  filter: drop-shadow(0 0 15px rgba(0, 216, 214, 0.3));
  animation: titlePulse 3s ease-in-out infinite alternate;
}

.game-subtitle {
  font-size: 1.2rem;
  color: var(--text-dim);
  margin-top: 10px;
  letter-spacing: 6px;
  text-transform: uppercase;
}

@keyframes titlePulse {
  0% { filter: drop-shadow(0 0 8px rgba(0, 216, 214, 0.2)); }
  100% { filter: drop-shadow(0 0 25px rgba(168, 85, 247, 0.5)); }
}

/* Custom Premium Buttons */
.btn {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.9) 100%);
  color: var(--text-light);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 14px 28px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 0 20px rgba(0, 216, 214, 0.3);
  color: #ffffff;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(135deg, #00d8d6 0%, #00bcba 100%);
  color: #0b1329;
  border: none;
  font-weight: 800;
  box-shadow: 0 4px 15px rgba(0, 216, 214, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #00ffff 0%, #00e5e3 100%);
  box-shadow: 0 6px 25px rgba(0, 216, 214, 0.5);
  color: #0b1329;
}

.btn-accent {
  background: linear-gradient(135deg, #8854d0 0%, #7033ac 100%);
  border: none;
}

.btn-accent:hover {
  border-color: #a855f7;
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.4);
}

.btn-danger {
  background: linear-gradient(135deg, #ff5e57 0%, #e0443d 100%);
  border: none;
}

.btn-danger:hover {
  box-shadow: 0 0 20px rgba(255, 94, 87, 0.4);
}

.btn-disabled, .btn:disabled {
  background: rgba(30, 41, 59, 0.4) !important;
  color: var(--text-dim) !important;
  border: 1px solid rgba(255, 255, 255, 0.05) !important;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* Level Selection Grid */
.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  width: 85%;
  margin-bottom: 30px;
}

.level-card {
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.level-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: var(--primary);
  opacity: 0.7;
}

.level-card.level-2::before { background: var(--accent); }
.level-card.level-3::before { background: var(--warning); }

.level-card:hover {
  transform: translateY(-5px);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
}

.level-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 25px rgba(0, 216, 214, 0.25);
}

.level-num {
  font-size: 0.9rem;
  color: var(--primary);
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.level-2 .level-num { color: var(--accent); }
.level-3 .level-num { color: var(--warning); }

.level-name {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 8px 0;
}

.level-description {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.4;
}

/* Character Selection Screen */
.character-list {
  display: flex;
  gap: 25px;
  width: 90%;
  justify-content: center;
  margin-bottom: 40px;
}

.character-card {
  flex: 1;
  max-width: 260px;
  padding: 20px;
  text-align: center;
  position: relative;
  cursor: pointer;
  transition: all 0.3s ease;
}

.character-card.locked {
  opacity: 0.6;
  border-color: rgba(255, 255, 255, 0.05);
  background: rgba(10, 15, 30, 0.4);
}

.character-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 25px rgba(0, 216, 214, 0.25);
}

.character-avatar-holder {
  width: 80px;
  height: 80px;
  margin: 10px auto 20px auto;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  position: relative;
}

.character-avatar-holder::after {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border-radius: 50%;
  border: 2px dashed rgba(255,255,255,0.15);
}

.selected .character-avatar-holder::after {
  border-color: var(--primary);
  animation: rotateDashed 12s linear infinite;
}

@keyframes rotateDashed {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.character-card.rusty .character-avatar-holder {
  background: radial-gradient(circle, rgba(255, 168, 1, 0.2) 0%, rgba(255, 168, 1, 0.05) 100%);
  border: 2px solid #ffa801;
}
.character-card.penny .character-avatar-holder {
  background: radial-gradient(circle, rgba(44, 62, 80, 0.4) 0%, rgba(44, 62, 80, 0.05) 100%);
  border: 2px solid #00d8d6;
}
.character-card.barnaby .character-avatar-holder {
  background: radial-gradient(circle, rgba(93, 64, 55, 0.3) 0%, rgba(93, 64, 55, 0.05) 100%);
  border: 2px solid #8d6e63;
}

.character-name {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0 0 5px 0;
}

.character-title {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 20px;
}

.stats-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.stat-row {
  font-size: 0.8rem;
}

.stat-label-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.stat-bar-bg {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--primary);
}

.penny .stat-bar-fill { background: var(--primary); }
.rusty .stat-bar-fill { background: var(--warning); }
.barnaby .stat-bar-fill { background: var(--accent); }

.lock-badge {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 0.7rem;
  color: var(--danger);
  border: 1px solid rgba(255, 94, 87, 0.2);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Gameplay HUD */
.hud {
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 5;
}

.hud-panel {
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 15px;
  font-weight: 600;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  background: rgba(0,0,0,0.4);
}

.hearts-container {
  display: flex;
  gap: 4px;
}

.heart {
  color: var(--danger);
  font-size: 1.4rem;
  filter: drop-shadow(0 0 5px rgba(255, 94, 87, 0.6));
  animation: heartBeat 1.2s infinite alternate;
}

@keyframes heartBeat {
  to { transform: scale(1.15); }
}

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

.hud-level-badge {
  font-size: 0.8rem;
  color: var(--primary);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.hud-score {
  font-size: 1.6rem;
  font-weight: 800;
  color: #ffffff;
}

/* Quiz Modal */
.quiz-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(3, 7, 18, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  animation: fadeIn 0.3s ease-out;
}

.quiz-card {
  width: 500px;
  padding: 35px;
  position: relative;
  text-align: center;
  animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.quiz-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 30px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 20px;
  box-shadow: 0 0 10px rgba(255,255,255,0.05);
}

.quiz-badge.math { background: rgba(255, 168, 1, 0.2); color: var(--warning); border: 1px solid rgba(255, 168, 1, 0.3); }
.quiz-badge.science { background: rgba(0, 216, 214, 0.2); color: var(--primary); border: 1px solid rgba(0, 216, 214, 0.3); }
.quiz-badge.geography { background: rgba(136, 84, 208, 0.2); color: #a855f7; border: 1px solid rgba(136, 84, 208, 0.3); }
.quiz-badge.history { background: rgba(11, 232, 129, 0.2); color: var(--success); border: 1px solid rgba(11, 232, 129, 0.3); }

.quiz-question {
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1.5;
  margin: 0 0 30px 0;
  color: #ffffff;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 25px;
}

.option-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-light);
  padding: 16px 20px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.option-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateX(4px);
}

.option-btn.selected {
  border-color: var(--primary);
  background: rgba(0, 216, 214, 0.1);
}

.option-btn.correct {
  border-color: var(--success) !important;
  background: rgba(11, 232, 129, 0.15) !important;
  color: var(--success) !important;
}

.option-btn.wrong {
  border-color: var(--danger) !important;
  background: rgba(255, 94, 87, 0.15) !important;
  color: var(--danger) !important;
}

.quiz-feedback {
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 15px;
  animation: pulseIn 0.3s ease-out;
}

.feedback-success { color: var(--success); }
.feedback-error { color: var(--danger); }

@keyframes pulseIn {
  0% { transform: scale(0.95); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Results / Victory Screen */
.victory-card {
  max-width: 550px;
  padding: 40px;
  text-align: center;
  border-color: var(--success);
  box-shadow: 0 0 40px rgba(11, 232, 129, 0.15);
}

.victory-icon {
  font-size: 4rem;
  margin-bottom: 20px;
  animation: bounceRotate 2s infinite ease-in-out;
}

@keyframes bounceRotate {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-15px) rotate(10deg); }
}

.rescued-announcement {
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  padding: 20px;
  border-radius: 12px;
  margin: 25px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
}

.rescued-icon {
  font-size: 2.5rem;
  background: radial-gradient(circle, rgba(0, 216, 214, 0.2) 0%, rgba(0,0,0,0) 70%);
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.rescued-text {
  text-align: left;
}

.rescued-name {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
}

.rescued-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.score-summary {
  font-size: 1.2rem;
  color: var(--text-dim);
  margin-bottom: 30px;
}

.score-summary strong {
  color: #ffffff;
  font-size: 1.5rem;
}

/* Game Over Card */
.gameover-card {
  max-width: 450px;
  padding: 40px;
  text-align: center;
  border-color: var(--danger);
  box-shadow: 0 0 40px rgba(255, 94, 87, 0.15);
}

.gameover-icon {
  font-size: 4rem;
  color: var(--danger);
  margin-bottom: 20px;
}

/* Pause Button / Controls instruction */
.hud-right {
  display: flex;
  gap: 10px;
}

.controls-help {
  font-size: 0.75rem;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 8px 12px;
  border-radius: 8px;
  display: flex;
  gap: 10px;
}

/* Age Select Bar styling */
.age-select-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 25px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 8px 16px;
  border-radius: 12px;
}

.age-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-weight: 700;
}

.age-options {
  display: flex;
  gap: 8px;
}

.age-btn {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-dim);
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.age-btn:hover {
  border-color: var(--primary);
  color: #ffffff;
}

.age-btn.active {
  background: var(--primary);
  color: #0b1329;
  border-color: var(--primary);
  box-shadow: 0 0 12px var(--primary-glow);
}

/* Boss Battle Overlay styles */
.boss-battle-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(3, 7, 18, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 110;
  animation: fadeIn 0.3s ease-out;
}

.boss-battle-card {
  width: 580px;
  padding: 30px;
  position: relative;
  text-align: center;
  border-color: var(--danger);
  box-shadow: 0 0 40px rgba(255, 94, 87, 0.2);
  animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.boss-battle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 15px;
}

.boss-character-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.boss-avatar-glow {
  font-size: 2.2rem;
  filter: drop-shadow(0 0 10px rgba(255, 94, 87, 0.5));
}

.boss-vs-label {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-dim);
  letter-spacing: 2px;
}

.combat-log-container {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 10px 15px;
  height: 90px;
  overflow-y: auto;
  margin-top: 20px;
  text-align: left;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.combat-log-entry {
  line-height: 1.3;
}

.combat-log-entry.player-action {
  color: var(--primary);
}

.combat-log-entry.boss-action {
  color: var(--danger);
}

.combat-log-entry.info-action {
  color: var(--success);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr) !important;
  gap: 20px;
  width: 90% !important;
  margin-bottom: 30px;
}

.level-card.level-4::before {
  background: var(--success);
}
.level-card.level-4 .level-num {
  color: var(--success);
}