* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: linear-gradient(150deg, #142b3b, #264c54 55%, #413956);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f1f5f9;
  overflow-x: hidden;
}
body:has(#startScreen.active) {
  align-items: flex-start;
  background:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(150deg, #122e32, #225058 55%, #493c48);
  background-size: 32px 32px, 32px 32px, auto;
}
#app:has(#startScreen.active) { padding-top: 30px; }
#app { width: 100%; max-width: 640px; padding: 20px; position: relative; }
.screen { display: none; text-align: center; position: relative; }
.screen.active { display: block; animation: fadeIn 0.4s ease; }
.hidden { display: none !important; }

.sound-btn {
  position: absolute; top: 0; right: 0;
  background: rgba(255,255,255,0.1);
  border: none; border-radius: 50%;
  width: 42px; height: 42px; font-size: 1.2rem;
  cursor: pointer; color: #fff;
  transition: transform 0.15s ease, background 0.2s ease;
  z-index: 5;
}
.sound-btn:hover { transform: scale(1.1); background: rgba(255,255,255,0.2); }
.sound-btn.muted { opacity: 0.5; }

#startScreen { max-width: 440px; margin: 0 auto; padding: 16px 0 22px; text-align: left; }
#startScreen h1 { margin: 0 48px 24px 0; font-family: 'Trebuchet MS', sans-serif; font-size: 1.8rem; color: #fff9e9; }
#startScreen .sound-btn { top: 12px; background: #17434a; border: 1px solid rgba(148,227,221,.3); }
#startScreen .mode-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; padding: 5px; margin: 0 0 16px; border-radius: 12px; background: rgba(255,255,255,.09); }
#startScreen .mode-tab { min-width: 0; min-height: 44px; padding: 9px 6px; border: 0; border-radius: 8px; font-size: .83rem; line-height: 1.2; }
#startScreen .mode-tab.active { background: #e0faf4; color: #193744; box-shadow: 0 2px 10px rgba(6,31,33,.18); }
#startScreen .instructions { margin: 0 0 24px; color: #cbd5e1; }
.difficulty-picker > span { display: block; margin-bottom: 10px; font-size: .88rem; font-weight: 700; color: #e1eaf0; }
.difficulty-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 10px; background: rgba(255,255,255,.09); }
.difficulty-choice { min-width: 0; min-height: 44px; border: 0; border-radius: 7px; background: transparent; color: #e1eaf0; font: inherit; font-weight: 700; cursor: pointer; }
.difficulty-choice.active { background: #ffae8a; color: #302c32; box-shadow: 0 2px 10px rgba(6,31,33,.18); }
.difficulty-choice:focus-visible, #playBtn:focus-visible, .settings-panel summary:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
#playBtn { display: block; width: 100%; min-height: 52px; margin-top: 18px; border: 0; border-radius: 10px; background: #facc15; color: #22213f; font: inherit; font-size: 1.1rem; font-weight: 800; cursor: pointer; box-shadow: 0 8px 20px rgba(20,24,22,.2); }
#playBtn:hover { background: #ffe066; }
#startScreen #progressBtn { display: block; margin: 12px auto 0; padding: 10px; border: 0; background: transparent; box-shadow: none; color: #d5e3ed; font-size: .88rem; }

h1 { font-size: 2rem; margin-bottom: 4px; }
.subtitle { opacity: 0.8; margin-bottom: 12px; }
.instructions { margin-bottom: 20px; font-size: 0.95rem; opacity: 0.85; }

.mode-tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; flex-wrap: wrap; }
.mode-tab {
  padding: 10px 18px; border-radius: 20px; border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.05); color: #cbd5e1; cursor: pointer;
  font-weight: 600; font-size: 0.9rem; transition: all 0.2s ease;
}
.mode-tab.active { background: #6366f1; border-color: #6366f1; color: #fff; }

.level-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }
.lvl-btn {
  padding: 14px 26px; font-size: 1.1rem; border: none; border-radius: 10px;
  cursor: pointer; color: #fff; font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.lvl-btn:hover { transform: translateY(-3px) scale(1.03); box-shadow: 0 6px 16px rgba(0,0,0,0.3); }
.lvl-btn:active { transform: scale(0.96); }
.lvl-btn.easy { background: #16a34a; }
.lvl-btn.medium { background: #d97706; }
.lvl-btn.hard { background: #dc2626; }

.secondary-btn {
  padding: 10px 20px; font-size: 0.95rem; background: rgba(255,255,255,0.1);
  color: #fff; border: 1px solid rgba(255,255,255,0.25); border-radius: 10px;
  cursor: pointer; margin-top: 6px; transition: background 0.2s ease;
}
.secondary-btn:hover { background: rgba(255,255,255,0.2); }
.secondary-btn.danger { border-color: #f87171; color: #f87171; }
.secondary-btn.danger:hover { background: rgba(248,113,113,0.15); }

.progress-bar-wrapper {
  width: 100%; height: 8px; background: rgba(255,255,255,0.1);
  border-radius: 6px; overflow: hidden; margin-top: 46px; margin-bottom: 8px;
}
#progressBar, #sustainedProgressBar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #4ade80, #facc15);
  border-radius: 6px; transition: width 0.4s ease;
}

.hud {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  background: rgba(255,255,255,0.08); padding: 10px 14px; border-radius: 10px;
  margin-bottom: 14px; font-size: 0.9rem;
}
.hud-item span { font-weight: 700; color: #facc15; transition: color 0.2s ease; }
#timeWrapper.time-low span { color: #f87171; animation: pulseText 0.6s infinite; }

#targetBanner {
  background: rgba(250,204,21,0.15); border: 2px dashed #facc15; border-radius: 10px;
  padding: 10px; margin-bottom: 14px; font-size: 1.05rem; font-weight: 600;
  animation: bannerSlide 0.35s ease;
}

#grid { display: grid; gap: 8px; justify-content: center; max-width: 100%; margin: 0 auto; }
.cell {
  width: 100%; aspect-ratio: 1/1; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; background: rgba(255,255,255,0.06); cursor: pointer; user-select: none;
  transition: transform 0.08s ease, background 0.2s ease; animation: popIn 0.3s ease backwards;
}
.cell:hover { transform: scale(1.06); background: rgba(255,255,255,0.12); }
.cell.correct-hit { animation: correctPulse 0.4s ease; }
.cell.wrong-hit { animation: shake 0.35s ease; }

#feedback, #sustainedFeedback {
  min-height: 24px; margin-top: 12px; font-weight: 700; font-size: 1rem;
}
#feedback.correct, #sustainedFeedback.correct { color: #4ade80; animation: fadeInUp 0.3s ease; }
#feedback.wrong, #sustainedFeedback.wrong { color: #f87171; animation: fadeInUp 0.3s ease; }

#sustainedRule {
  background: rgba(99,102,241,0.15); border: 2px dashed #818cf8; border-radius: 10px;
  padding: 10px; margin-bottom: 18px; font-size: 1.05rem; font-weight: 600;
}
#sustainedStage {
  height: 220px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.04); border-radius: 14px; margin-bottom: 18px;
}
#sustainedShapeWrap { width: 90px; height: 90px; display: flex; align-items: center; justify-content: center; }
#sustainedShapeWrap.animate-in { animation: popIn 0.25s ease; }

#tapTargetBtn {
  padding: 18px 40px; font-size: 1.15rem; font-weight: 700; color: #fff;
  background: #6366f1; border: none; border-radius: 14px; cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease; width: 100%; max-width: 320px;
}
#tapTargetBtn:hover { background: #4f46e5; }
#tapTargetBtn:active { transform: scale(0.96); }

#comboPopup, #milestonePopup {
  position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%);
  font-size: 2rem; font-weight: 800; color: #facc15; pointer-events: none;
  opacity: 0; text-align: center; z-index: 10;
}
#comboPopup.show, #milestonePopup.show { animation: comboFly 0.9s ease forwards; }
#milestonePopup { color: #4ade80; font-size: 1.6rem; }

.stats { display: flex; gap: 14px; justify-content: center; margin: 22px 0; flex-wrap: wrap; }
.stat-box {
  background: rgba(255,255,255,0.08); padding: 16px 20px; border-radius: 12px;
  min-width: 100px; animation: popIn 0.4s ease backwards;
}
.stat-box span { display: block; font-size: 1.6rem; font-weight: 700; color: #facc15; }
.stat-box label { font-size: 0.8rem; opacity: 0.8; }

.stars { font-size: 2.4rem; margin-bottom: 6px; }
.stars span { display: inline-block; opacity: 0.25; transition: opacity 0.3s ease, transform 0.3s ease; }
.stars span.lit { opacity: 1; animation: starPop 0.5s ease; }

#attentionVerdict { margin-bottom: 20px; font-size: 1.05rem; animation: fadeInUp 0.4s ease; }

#restartBtn {
  padding: 14px 30px; font-size: 1.05rem; background: #6366f1; color: #fff;
  border: none; border-radius: 10px; cursor: pointer; font-weight: 600;
  transition: transform 0.15s ease, background 0.2s ease; margin-right: 8px;
}
#restartBtn:hover { background: #4f46e5; transform: translateY(-2px); }
#restartBtn:active { transform: scale(0.96); }

#progressChart { max-width: 100%; background: rgba(255,255,255,0.04); border-radius: 12px; margin: 12px 0; }
#historyTableWrap { max-height: 220px; overflow-y: auto; margin-bottom: 16px; }
table.history-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.history-table th, table.history-table td {
  padding: 6px 8px; border-bottom: 1px solid rgba(255,255,255,0.1); text-align: center;
}
table.history-table th { color: #facc15; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: scale(1); } }
@keyframes bannerSlide { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes correctPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); box-shadow: 0 0 18px 4px rgba(74,222,128,0.6); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}
@keyframes pulseText { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes comboFly {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.6); }
  30% { opacity: 1; transform: translate(-50%, -55%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1.3); }
}
@keyframes starPop {
  0% { transform: scale(0.3) rotate(-20deg); }
  60% { transform: scale(1.3) rotate(10deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.adaptive-note {
  font-size: 0.8rem; opacity: 0.7; margin-top: 4px; margin-bottom: 14px; font-style: italic;
}

#difficultyPopup {
  position: fixed; top: 30%; left: 50%; transform: translate(-50%, -50%);
  font-size: 1.5rem; font-weight: 800; pointer-events: none;
  opacity: 0; text-align: center; z-index: 10;
}
#difficultyPopup.show-up { animation: comboFly 1s ease forwards; color: #f87171; }
#difficultyPopup.show-down { animation: comboFly 1s ease forwards; color: #60a5fa; }

/* Custom Settings Panel */
.settings-panel {
  background: rgba(255, 255, 255, 0.1);
  padding: 15px;
  border-radius: 8px;
  margin: 15px 0;
}
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

/* Side-by-Side Layout */
.game-layout-split {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}
.game-sidebar {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 15px;
  min-width: 150px;
}
.game-main {
  flex: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

@media (max-width: 600px) {
  #app { padding: 12px; }
  .game-layout-split { flex-direction: column; align-items: stretch; gap: 10px; }
  .game-sidebar { width: 100%; min-width: 0; }
  .game-main { width: 100%; }
  .game-sidebar .hud { margin-bottom: 0; }
}

/* Drifting Animation */
.drift {
  animation: float 4s ease-in-out infinite;
}
@keyframes float {
  0% { transform: translateY(0px) translateX(0px); }
  50% { transform: translateY(-8px) translateX(5px); }
  100% { transform: translateY(0px) translateX(0px); }
}

/* Particle Effects */
.particle {
  position: absolute;
  pointer-events: none;
  animation: popOut 0.6s cubic-bezier(0, .9, .9, 1) forwards;
}
@keyframes popOut {
  to { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

/* --- ENHANCED MISSION SETTINGS PANEL --- */
.settings-panel {
  margin: 10px auto 0;
  text-align: left;
}

.settings-panel summary {
  padding: 10px 0;
  color: #d5e3ed;
  font-size: .88rem;
  cursor: pointer;
}

.settings-grid {
  padding: 14px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 10px;
  background: rgba(255,255,255,.05);
}

.settings-grid label {
  display: grid;
  grid-template-columns: 90px minmax(0,1fr);
  align-items: center;
  gap: 8px;
  font-size: .88rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: #e2e8f0;
}
.settings-grid label:last-child { margin-bottom: 0; }

/* Custom Game-like Dropdowns */
.settings-grid select {
  background: #1e1b4b; /* Deep purple background */
  color: white;
  border: 2px solid #6366f1; /* Indigo border */
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  outline: none;
  width: 100%;
  transition: all 0.2s;
}

.settings-grid select:hover {
  border-color: #facc15;
}

/* Custom Checkbox Size */
.settings-grid input[type="checkbox"] {
  width: 24px;
  height: 24px;
  cursor: pointer;
  accent-color: #6366f1;
  justify-self: end;
}

/* --- ENHANCED PROGRESS TABLE --- */
.history-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  overflow: hidden;
}

.history-table th {
  background: rgba(255, 255, 255, 0.1);
  color: #facc15;
  padding: 14px 10px;
  text-align: center;
  font-size: 1.1rem;
}

.history-table td {
  padding: 12px 10px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: #f8fafc;
}

/* Fix for the tiny Back button on the Progress Screen */
#backFromProgress {
  background: #475569;
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  margin-right: 15px;
}
#backFromProgress:hover {
  background: #64748b;
}

#mascotArea {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-bottom: 8px;
}

#medhaaLogo {
  width: 52px;
  height: 64px;
  object-fit: contain;
  transition: transform 0.2s ease;
}