* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: linear-gradient(135deg, #1e1b4b, #312e81);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f1f5f9;
  overflow-x: hidden;
}
#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; }

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; 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; }