:root {
  --primary-color: #ff2e63;
  --primary-shadow: #b21f45;
  --secondary-color: #00fff5;
  --accent-yellow: #ffe66d;
  --bg-gradient-start: #16213e;
  --bg-gradient-end: #0f3460;
  --card-bg: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.15);
  --text-main: #ffffff;
  --text-muted: #a0a0a0;
  --btn-correct: #00c853;
  --btn-correct-shadow: #009624;
  --btn-wrong: #d50000;
  --btn-wrong-shadow: #9b0000;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: #1a1a2e;
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

/* Portrait Container */
.game-container {
  width: 100%;
  max-width: 420px;
  height: 100vh;
  max-height: 880px;
  background: linear-gradient(180deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

@media (min-height: 800px) and (min-width: 420px) {
  .game-container {
    border-radius: var(--radius-lg);
    height: 92vh;
  }
}

/* Top Header Bar */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  z-index: 10;
}

.header-left {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-btn, .pill-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  padding: 6px 12px;
  color: var(--text-main);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.2s;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  padding: 0;
  font-size: 18px;
}

.icon-btn:active, .pill-btn:active {
  transform: scale(0.92);
}

.high-score-badge {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 230, 109, 0.3);
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 800;
  font-size: 14px;
  color: var(--accent-yellow);
}

/* Screens */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 18px 20px 18px;
  justify-content: space-between;
  overflow-y: auto;
}

.screen.hidden {
  display: none !important;
}

/* Header Content & Title */
.header-content {
  text-align: center;
  margin-top: 4px;
}

.floating-title {
  font-size: 36px;
  font-weight: 900;
  color: var(--primary-color);
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.4);
  letter-spacing: 1px;
  animation: floatTitle 3s ease-in-out infinite alternate;
}

@keyframes floatTitle {
  0% { transform: translateY(0); }
  100% { transform: translateY(-6px); }
}

.subtitle {
  font-size: 15px;
  color: var(--secondary-color);
  margin-top: 2px;
  font-weight: 700;
}

/* Level Selection Cards */
.level-selection {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0;
}

.section-label {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.level-cards-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.level-card {
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.level-card.active {
  background: rgba(0, 255, 245, 0.12);
  border-color: var(--secondary-color);
  transform: scale(1.01);
}

.level-card.locked {
  opacity: 0.75;
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.08);
}

.level-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.level-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.level-card-title {
  font-size: 16px;
  font-weight: 800;
  color: #ffffff;
}

.lock-badge {
  background: rgba(255, 46, 99, 0.2);
  border: 1px solid var(--primary-color);
  color: #ff8fa3;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 8px;
}

.level-card-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.level-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.card-stars {
  font-size: 12px;
  letter-spacing: 1px;
}

.card-best-score {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent-yellow);
}

/* HUD */
.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}

.hud-card {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.hud-label {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.hud-value {
  font-size: 16px;
  font-weight: 900;
  color: #ffffff;
}

.highlight-text {
  color: var(--accent-yellow);
}

.hearts-container {
  font-size: 14px;
  letter-spacing: 1px;
}

.hud-secondary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.progress-tracker {
  font-size: 13px;
  font-weight: 800;
  color: var(--secondary-color);
  background: rgba(0, 255, 245, 0.1);
  padding: 4px 10px;
  border-radius: 12px;
}

.icon-btn-small {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 14px;
  cursor: pointer;
  color: #fff;
}

/* Timer Bar */
.timer-bar-bg {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
}

.timer-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--secondary-color);
  transition: width 0.1s linear, background-color 0.3s ease;
}

/* Question Area */
.question-box {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 2px solid var(--card-border);
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 130px;
  margin-bottom: 16px;
}

.speed-badge {
  position: absolute;
  top: 10px;
  left: 12px;
  background: var(--accent-yellow);
  color: #0f3460;
  font-size: 10px;
  font-weight: 900;
  padding: 3px 8px;
  border-radius: 8px;
  animation: pulse 0.8s infinite alternate;
}

.feedback-msg {
  position: absolute;
  top: 10px;
  font-size: 15px;
  font-weight: 900;
  height: 20px;
}

.feedback-msg.correct { color: #00e676; }
.feedback-msg.wrong { color: #ff5252; }

.question-text {
  font-size: 46px;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: 2px;
}

/* Answer Buttons Grid */
.answers-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.answer-btn {
  background: #252a44;
  border: 3px solid #3d456b;
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 26px;
  font-weight: 900;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 6px 0 #181b2c;
  transition: transform 0.05s, background-color 0.2s, border-color 0.2s;
}

.answer-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #181b2c;
}

.answer-btn.btn-correct {
  background: var(--btn-correct) !important;
  border-color: #b9f6ca !important;
  box-shadow: 0 6px 0 var(--btn-correct-shadow) !important;
  color: #ffffff !important;
  animation: pop 0.3s ease;
}

.answer-btn.btn-wrong {
  background: var(--btn-wrong) !important;
  border-color: #ff8a80 !important;
  box-shadow: 0 6px 0 var(--btn-wrong-shadow) !important;
  color: #ffffff !important;
  animation: shake 0.4s ease;
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* Primary / Secondary Buttons */
.primary-btn {
  background: var(--primary-color);
  border: none;
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 20px;
  font-weight: 900;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--primary-shadow);
  width: 100%;
  transition: transform 0.1s, background 0.2s;
}

.primary-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--primary-shadow);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 16px;
  font-weight: 800;
  color: #ffffff;
  cursor: pointer;
  width: 100%;
}

.secondary-btn:active {
  background: rgba(255, 255, 255, 0.2);
}

.secondary-btn.danger {
  background: rgba(213, 0, 0, 0.2);
  border-color: #ff5252;
}

.tertiary-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 800;
  padding: 10px;
  cursor: pointer;
}

/* Results Screen */
#results-screen {
  position: relative;
}

#confetti-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.results-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 2px solid var(--card-border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  z-index: 2;
}

.results-title {
  font-size: 28px;
  font-weight: 900;
  color: var(--primary-color);
  text-align: center;
}

.stars-row {
  display: flex;
  gap: 12px;
  margin: 10px 0;
}

.star-icon {
  font-size: 42px;
  transition: transform 0.3s ease;
}

.star-icon.dimmed {
  filter: grayscale(1) opacity(0.3);
}

.star-icon.active {
  animation: starPop 0.5s ease forward;
}

@keyframes starPop {
  0% { transform: scale(0.5); }
  70% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  margin: 10px 0;
}

.stat-box {
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: var(--radius-sm);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
}

.stat-value {
  font-size: 22px;
  font-weight: 900;
  color: var(--accent-yellow);
}

.results-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

/* Modals */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  z-index: 100;
}

.modal-overlay.hidden {
  display: none !important;
}

.modal-card {
  background: #16213e;
  border: 2px solid var(--secondary-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}

.modal-card.mini {
  max-width: 280px;
  padding: 20px;
}

.modal-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.lock-icon-lg {
  font-size: 36px;
}

.modal-header h3 {
  font-size: 20px;
  font-weight: 900;
  color: var(--accent-yellow);
}

.features-list {
  list-style: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: #e0e0e0;
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pulse-anim {
  animation: pulse 1.2s infinite alternate;
}

@keyframes pulse {
  0% { transform: scale(0.98); }
  100% { transform: scale(1.02); }
}