/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100dvh;
  overscroll-behavior: none;
}
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; }
input[type="text"], input[type="number"], input[type="password"] { font-size: 16px; }

/* === Animations === */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }
@keyframes bounce { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes starPop { 0% { transform: scale(0); opacity: 0; } 50% { transform: scale(1.3); } 100% { transform: scale(1); opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

.animate-fade-in { animation: fadeIn 0.3s ease-out; }
.animate-slide-up { animation: slideUp 0.4s ease-out backwards; }
.animate-scale-in { animation: scaleIn 0.3s ease-out; }
.animate-bounce { animation: bounce 0.4s ease-in-out; }
.animate-shake { animation: shake 0.4s ease-in-out; }

/* === Header / Nav === */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--color-bg-card); border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-card);
}
.logo { font-size: 1.5rem; font-weight: 700; color: var(--color-primary); text-decoration: none; }
.nav { display: flex; align-items: center; gap: 1rem; }
.nav-link {
  padding: 0.5rem 1rem; border-radius: 8px; text-decoration: none;
  font-weight: 500; transition: background 0.2s, color 0.2s;
}
.nav-link:hover { background: var(--color-bg-input); }
.nav-link.active { background: var(--color-primary); color: var(--color-text-on-primary); }
.sound-toggle { font-size: 1.25rem; padding: 0.5rem; border-radius: 8px; transition: background 0.2s; }
.sound-toggle:hover { background: var(--color-bg-input); }
.logout-button {
  padding: 0.5rem 1rem; border-radius: 8px; text-decoration: none;
  color: var(--color-text-light); font-weight: 500; transition: background 0.2s, color 0.2s;
}
.logout-button:hover { background: var(--color-wrong-light); color: var(--color-wrong); }

/* === Main content === */
.main { flex: 1; padding: 1.5rem; max-width: 900px; width: 100%; margin: 0 auto; }

/* === Buttons === */
.btn {
  display: inline-block; padding: 0.875rem 1.5rem; border-radius: 10px;
  font-size: 1.1rem; font-weight: 600; text-align: center; text-decoration: none;
  transition: background 0.2s, transform 0.1s; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: var(--color-primary); color: var(--color-text-on-primary);
  box-shadow: var(--shadow-button);
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary {
  background: var(--color-bg-card); color: var(--color-text);
  border: 2px solid var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg-input); }
.btn-block { display: block; width: 100%; }

/* === Cards === */
.card {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  padding: 1.5rem 1rem; background: var(--color-bg-card); border-radius: 14px;
  box-shadow: var(--shadow-card); text-decoration: none; color: var(--color-text);
  transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.card:active { transform: translateY(-1px); }
.card-emoji { font-size: 2.5rem; }
.card-label { font-size: 1.15rem; font-weight: 600; text-align: center; }

/* === Typography === */
.greeting { font-size: 1.75rem; font-weight: 700; color: var(--color-primary); margin-bottom: 0.5rem; }
.subtitle { font-size: 1.1rem; font-weight: 400; color: var(--color-text-light); margin-bottom: 1.5rem; }
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--color-primary); margin-bottom: 1.5rem; }
.empty-message { color: var(--color-text-light); text-align: center; padding: 2rem; }

/* === Grade grid === */
.grade-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }

/* === Lesson grid === */
.lesson-section { margin-bottom: 2rem; }
.section-title {
  font-size: 1.1rem; font-weight: 600; color: var(--color-text-light);
  margin-bottom: 0.75rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--color-border);
}
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.75rem; }
.difficulty { font-size: 0.75rem; color: var(--color-text-light); letter-spacing: 2px; }
.difficulty[data-level="easy"] { color: var(--color-correct); }
.difficulty[data-level="medium"] { color: var(--color-accent-dark); }
.difficulty[data-level="hard"] { color: var(--color-wrong); }

/* === Mode grid === */
.lesson-header { text-align: center; margin-bottom: 2rem; }
.lesson-icon { font-size: 3.5rem; display: block; margin-bottom: 0.75rem; }
.lesson-description { color: var(--color-text-light); font-size: 1.05rem; }
.modes-title { font-size: 1.1rem; font-weight: 600; text-align: center; margin-bottom: 1rem; }
.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.mode-desc { font-size: 0.85rem; color: var(--color-text-light); text-align: center; line-height: 1.4; }

/* === Login === */
.login-container {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.login-card {
  background: var(--color-bg-card); border-radius: 16px; padding: 2.5rem 2rem;
  box-shadow: var(--shadow-card); width: 100%; max-width: 400px;
}
.login-title { font-size: 2rem; font-weight: 700; color: var(--color-primary); text-align: center; margin-bottom: 2rem; }
.login-form { display: flex; flex-direction: column; gap: 1.25rem; }
.form-label { display: flex; flex-direction: column; gap: 0.5rem; font-weight: 500; }
.form-input {
  padding: 0.75rem 1rem; border: 2px solid var(--color-border); border-radius: 10px;
  background: var(--color-bg-input); font: inherit; transition: border-color 0.2s;
}
.form-input:focus { outline: none; border-color: var(--color-primary); }
.form-error { color: var(--color-wrong); font-size: 0.9rem; text-align: center; }

/* === Play page === */
.play-container {
  display: flex; flex-direction: column; gap: 1.5rem;
  max-width: 500px; margin: 0 auto; padding: 1.5rem 1rem; min-height: 100dvh;
}
.play-progress { display: flex; align-items: center; gap: 0.75rem; }
.play-progress-label { font-size: 0.85rem; font-weight: 500; color: var(--color-text-light); white-space: nowrap; }
.play-score { font-size: 0.9rem; font-weight: 600; color: var(--color-correct); white-space: nowrap; }

.progress-bar-bg { flex: 1; height: 8px; background: var(--color-border); border-radius: 4px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--color-primary); border-radius: 4px; transition: width 0.3s ease-out; }

.timer { display: flex; align-items: center; gap: 0.75rem; }
.timer-bar-bg { flex: 1; height: 10px; background: var(--color-border); border-radius: 5px; overflow: hidden; }
.timer-bar-fill {
  height: 100%; background: var(--color-primary); border-radius: 5px;
  transition: width 0.1s linear; width: 100%;
}
.timer-bar-fill.low { background: var(--color-accent-dark); }
.timer-bar-fill.critical { background: var(--color-wrong); animation: pulse 0.5s infinite; }
.timer-label { font-size: 1rem; font-weight: 600; min-width: 2.5rem; text-align: right; }
.timer-label.critical { color: var(--color-wrong); }

.question-area { display: flex; flex-direction: column; align-items: center; gap: 1.5rem; animation: fadeIn 0.3s ease-out; }
.prompt { font-size: 2.25rem; font-weight: 700; text-align: center; padding: 1rem; }

/* Number pad */
.numpad { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; width: 100%; max-width: 320px; }
.numpad-display {
  width: 100%; padding: 0.75rem 1rem; background: var(--color-bg-input);
  border: 2px solid var(--color-border); border-radius: 12px;
  font-size: 2rem; font-weight: 700; text-align: center; min-height: 3.5rem;
}
.numpad-display.empty { color: var(--color-text-light); }
.numpad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; width: 100%; }
.numpad-key {
  padding: 1rem; font-size: 1.5rem; font-weight: 600;
  background: var(--color-bg-card); border: 2px solid var(--color-border); border-radius: 12px;
  box-shadow: var(--shadow-button); user-select: none;
  -webkit-tap-highlight-color: transparent; transition: background 0.1s, transform 0.1s;
}
.numpad-key:hover { background: var(--color-bg-input); border-color: var(--color-primary-light); }
.numpad-key:active { transform: scale(0.95); background: var(--color-primary-light); color: var(--color-text-on-primary); }
.numpad-submit {
  width: 100%; padding: 1rem; font-size: 1.25rem; font-weight: 700;
  background: var(--color-primary); color: var(--color-text-on-primary);
  border-radius: 12px; box-shadow: var(--shadow-button); user-select: none;
  -webkit-tap-highlight-color: transparent; transition: background 0.2s, transform 0.1s;
}
.numpad-submit:hover { background: var(--color-primary-dark); }
.numpad-submit:active { transform: scale(0.98); }
.numpad-submit:disabled { opacity: 0.4; cursor: not-allowed; }

/* Multiple choice / comparison */
.options-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; width: 100%; max-width: 320px; }
.option-btn {
  padding: 1.25rem; font-size: 1.5rem; font-weight: 600;
  background: var(--color-bg-card); border: 2px solid var(--color-border); border-radius: 12px;
  box-shadow: var(--shadow-button); user-select: none;
  -webkit-tap-highlight-color: transparent; transition: background 0.15s, transform 0.1s;
}
.option-btn:hover { border-color: var(--color-primary-light); background: var(--color-bg-input); }
.option-btn:active { transform: scale(0.95); background: var(--color-primary-light); color: var(--color-text-on-primary); }

.comparison-buttons { display: flex; gap: 1rem; justify-content: center; }
.comparison-btn {
  width: 5rem; height: 5rem; font-size: 2.5rem; font-weight: 700;
  background: var(--color-bg-card); border: 2px solid var(--color-border); border-radius: 50%;
  box-shadow: var(--shadow-button); user-select: none;
  -webkit-tap-highlight-color: transparent; transition: background 0.15s, transform 0.1s;
}
.comparison-btn:hover { border-color: var(--color-primary-light); background: var(--color-bg-input); }
.comparison-btn:active { transform: scale(0.92); background: var(--color-primary-light); color: var(--color-text-on-primary); }

.hint { color: var(--color-text-light); font-size: 0.95rem; text-align: center; padding: 0.75rem; background: var(--color-bg-input); border-radius: 8px; max-width: 320px; }

/* Feedback */
.feedback-overlay {
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
  padding: 1.5rem; border-radius: 16px; animation: scaleIn 0.3s ease-out;
}
.feedback-overlay[hidden] { display: none; }
.feedback-overlay.correct { background: var(--color-correct-light); }
.feedback-overlay.wrong { background: var(--color-wrong-light); }
.feedback-emoji { font-size: 3rem; font-weight: 700; }
.feedback-text { font-size: 1.25rem; font-weight: 600; }
.feedback-answer { font-size: 1rem; color: var(--color-text-light); }
.correct .feedback-emoji, .correct .feedback-text { color: var(--color-correct); }
.wrong .feedback-emoji, .wrong .feedback-text { color: var(--color-wrong); }

/* === Results === */
.result-container { display: flex; flex-direction: column; align-items: center; gap: 2rem; padding: 2rem 0; }
.stars-area { display: flex; gap: 0.5rem; justify-content: center; }
.star { font-size: 3rem; animation: starPop 0.5s ease-out backwards; }
.star-filled { color: var(--color-accent); text-shadow: 0 2px 8px rgba(255, 217, 61, 0.4); }
.star-empty { color: var(--color-border); }
.result-stats { display: flex; gap: 2rem; flex-wrap: wrap; justify-content: center; }
.result-stat {
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem;
  padding: 1rem 1.5rem; background: var(--color-bg-card); border-radius: 12px; box-shadow: var(--shadow-card);
}
.result-value { font-size: 1.75rem; font-weight: 700; color: var(--color-primary); }
.result-label { font-size: 0.85rem; color: var(--color-text-light); }
.result-actions { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; max-width: 300px; }

/* === Progress page === */
.progress-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.progress-card { align-items: stretch; }
.progress-lesson-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.75rem; }
.progress-stats { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; font-size: 0.85rem; color: var(--color-text-light); }
.progress-percent { font-size: 0.85rem; font-weight: 500; color: var(--color-text-light); margin-top: 0.5rem; }
.trend[data-trend="improving"] { color: var(--color-correct); font-weight: 500; }
.trend[data-trend="stable"] { color: var(--color-text-light); }
.trend[data-trend="declining"] { color: var(--color-wrong); font-weight: 500; }

/* === Responsive === */
@media (max-width: 600px) {
  .header { padding: 0.5rem 1rem; }
  .main { padding: 1rem; }
  .nav-link { padding: 0.5rem 0.75rem; font-size: 0.9rem; }
  .prompt { font-size: 1.75rem; }
}
