/* Dark Theme (Default) */
:root {
  --bg: #0b1021;
  --bg-alt: #111731;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-strong: rgba(255, 255, 255, 0.08);
  --text: #f5f7ff;
  --muted: #a0aac8;
  --accent: #6ef1c5;
  --accent-2: #ffc466;
  --danger: #ff6b6b;
  --border: rgba(255, 255, 255, 0.08);
  --font: "Space Grotesk", "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --input-bg: var(--bg);
}

/* Light Theme */
[data-theme="light"] {
  --bg: #f8f9fc;
  --bg-alt: #ffffff;
  --panel: rgba(0, 0, 0, 0.03);
  --panel-strong: rgba(0, 0, 0, 0.06);
  --text: #1a1f36;
  --muted: #5c6582;
  --accent: #10b981;
  --accent-2: #f59e0b;
  --danger: #ef4444;
  --border: rgba(0, 0, 0, 0.1);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --input-bg: #ffffff;
}

[data-theme="light"] body {
  background: radial-gradient(120% 120% at 20% 20%, rgba(16, 185, 129, 0.06), transparent 40%),
    radial-gradient(100% 100% at 80% 10%, rgba(245, 158, 11, 0.06), transparent 35%),
    var(--bg);
}

/* Light theme specific overrides */
[data-theme="light"] .badge {
  color: #ffffff;
}

[data-theme="light"] .topbar,
[data-theme="light"] .card,
[data-theme="light"] .goal-card,
[data-theme="light"] .lesson-card,
[data-theme="light"] .modal,
[data-theme="light"] .achievements-section,
[data-theme="light"] .leaderboard-section {
  box-shadow: var(--shadow);
}

[data-theme="light"] .form-group input {
  background: var(--input-bg);
}

[data-theme="light"] .option {
  background: var(--bg-alt);
}

[data-theme="light"] .option:hover {
  background: var(--panel-strong);
}

[data-theme="light"] .leaderboard-rank.gold {
  color: #ffffff;
}

[data-theme="light"] .leaderboard-rank.silver {
  color: #ffffff;
}

[data-theme="light"] .leaderboard-rank.bronze {
  color: #ffffff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(120% 120% at 20% 20%, rgba(110, 241, 197, 0.08), transparent 40%),
    radial-gradient(100% 100% at 80% 10%, rgba(255, 196, 102, 0.08), transparent 35%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  backdrop-filter: blur(10px);
}

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

.badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b1021;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

h1 {
  font-size: 22px;
  margin: 2px 0 0;
}

h2 {
  margin: 6px 0;
  font-size: 26px;
}

h3 {
  margin: 0;
  font-size: 20px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 12px;
  align-items: center;
}

.metric {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel-strong);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.metric .icon {
  font-size: 18px;
}

.label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.value {
  margin: 0;
  font-weight: 600;
}

.hero {
  margin: 24px 0;
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 24px;
  align-items: center;
  padding: 24px;
  background: linear-gradient(135deg, rgba(110, 241, 197, 0.1), rgba(255, 196, 102, 0.06));
  border: 1px solid var(--border);
  border-radius: 16px;
}

.sub {
  color: var(--muted);
  margin: 8px 0 16px;
}

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

button {
  border: none;
  cursor: pointer;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: 12px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.2s ease;
}

button:active {
  transform: translateY(1px);
}

.primary {
  background: linear-gradient(135deg, var(--accent), #78ffd5);
  color: #0b1021;
  box-shadow: 0 10px 30px rgba(110, 241, 197, 0.35);
}

.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.goal-card {
  background: var(--panel);
  padding: 18px;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.progress {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: inherit;
  transition: width 0.25s ease;
}

.goal-text {
  margin: 0;
  color: var(--muted);
}

.lessons {
  margin: 32px 0 20px;
}

.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.lesson-card {
  position: relative;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease;
}

.lesson-card:hover {
  transform: translateY(-4px);
  border-color: rgba(110, 241, 197, 0.5);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(110, 241, 197, 0.1);
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
}

.xp {
  color: var(--accent-2);
}

.player {
  margin-top: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  min-height: 240px;
  transition: border-color 0.15s ease;
}

.card h4 {
  margin-top: 0;
}

.prompt {
  font-size: 18px;
  margin: 0 0 12px;
}

.option-list {
  display: grid;
  gap: 10px;
}

.option {
  padding: 12px;
  border-radius: 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.option:hover {
  border-color: rgba(110, 241, 197, 0.6);
  transform: translateY(-1px);
}

.option.selected {
  border-color: var(--accent);
  background: rgba(110, 241, 197, 0.1);
}

.status {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(110, 241, 197, 0.1);
  border: 1px solid rgba(110, 241, 197, 0.5);
}

.status.error {
  background: rgba(255, 107, 107, 0.1);
  border-color: rgba(255, 107, 107, 0.6);
}

.fill-input {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 16px;
}

.free-input {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 15px;
  min-height: 120px;
  resize: vertical;
}

.matching-grid {
  display: grid;
  gap: 10px;
}

.match-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 10px;
  align-items: center;
}

select {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.chip {
  padding: 10px 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.chip:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.chip.used {
  opacity: 0.4;
  cursor: default;
}

.order-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.order-step {
  padding: 10px;
  border-radius: 10px;
  background: rgba(110, 241, 197, 0.08);
  border: 1px dashed rgba(110, 241, 197, 0.5);
}

.footer-actions {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.small {
  font-size: 13px;
  color: var(--muted);
}

.grade-details {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed rgba(110, 241, 197, 0.4);
  background: rgba(110, 241, 197, 0.04);
}

.grade-details ul {
  margin: 6px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

/* Toggle Buttons (Theme & Sound) */
.theme-toggle,
.sound-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 18px;
}

.theme-toggle:hover,
.sound-toggle:hover {
  background: var(--panel-strong);
  border-color: var(--accent);
  transform: scale(1.05);
}

.theme-toggle:active,
.sound-toggle:active {
  transform: scale(0.95);
}

/* Theme toggle animation */
.theme-icon {
  transition: transform 0.3s ease;
}

.theme-toggle:hover .theme-icon {
  transform: rotate(20deg);
}

/* User Auth Section */
.user-auth {
  display: flex;
  align-items: center;
}

.auth-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: linear-gradient(135deg, rgba(110, 241, 197, 0.2), rgba(255, 196, 102, 0.2));
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.auth-btn:hover {
  background: linear-gradient(135deg, rgba(110, 241, 197, 0.3), rgba(255, 196, 102, 0.3));
  border-color: var(--accent);
}

.auth-icon {
  font-size: 18px;
}

.auth-text {
  font-size: 14px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #0b1021;
  font-size: 14px;
}

.user-name {
  font-weight: 600;
  font-size: 14px;
}

.user-email {
  font-size: 12px;
  color: var(--muted);
}

.logout-btn {
  padding: 6px 12px;
  font-size: 12px;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: var(--danger);
  border-radius: 8px;
}

.logout-btn:hover {
  background: rgba(255, 107, 107, 0.2);
}

/* Login Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  max-width: 400px;
  width: 100%;
  position: relative;
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 20px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--panel-strong);
  color: var(--text);
}

.modal-header {
  text-align: center;
  margin-bottom: 24px;
}

.modal-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.modal-header h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.modal-header p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.form-group input {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  transition: border-color 0.2s ease;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-error {
  padding: 12px;
  border-radius: 10px;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: var(--danger);
  font-size: 14px;
  text-align: center;
}

.auth-submit {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  margin-top: 8px;
}

.auth-footer {
  margin-top: 20px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

.auth-footer a {
  color: var(--accent);
  text-decoration: none;
}

.auth-footer a:hover {
  text-decoration: underline;
}

/* Notification Toggle Button */
.notification-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.2s ease;
  position: relative;
}

.notification-toggle:hover {
  background: var(--panel-strong);
  transform: scale(1.05);
}

.notification-icon {
  font-size: 18px;
}

.notification-toggle.has-notifications::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

/* Notification Modal */
.notification-modal {
  max-width: 440px;
}

.notification-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.notification-section {
  padding: 16px;
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.notification-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.notification-section-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.notification-header > div {
  flex: 1;
}

.notification-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.notification-desc {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 26px;
  transition: all 0.3s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 2px;
  bottom: 2px;
  background: var(--muted);
  border-radius: 50%;
  transition: all 0.3s ease;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
  background: white;
}

/* Push Status */
.notification-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 13px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.notification-status.enabled .status-indicator {
  background: var(--accent);
  animation: pulse 2s infinite;
}

.notification-status.denied .status-indicator {
  background: var(--danger);
}

.notification-status.denied .status-text {
  color: var(--danger);
}

/* Notification Types */
.notification-types h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.checkbox-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.checkbox-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.checkbox-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
}

.checkbox-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.checkbox-title {
  font-size: 14px;
  font-weight: 500;
}

.checkbox-desc {
  font-size: 12px;
  color: var(--muted);
}

.notification-save {
  width: 100%;
  padding: 14px;
  font-size: 16px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Achievements Section */
.achievements-section {
  margin: 32px 0;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.achievement-card {
  padding: 16px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-align: center;
  transition: all 0.2s ease;
}

.achievement-card.unlocked {
  border-color: var(--accent);
  background: rgba(110, 241, 197, 0.05);
}

.achievement-card.locked {
  opacity: 0.5;
  filter: grayscale(0.8);
}

.achievement-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.achievement-info h4,
.achievement-name {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 4px;
}

.achievement-info p,
.achievement-desc {
  font-size: 11px;
  color: var(--muted);
  margin: 0;
}

.achievement-check {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #0b1021;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.achievement-card {
  position: relative;
}

.achievement-date {
  font-size: 10px;
  color: var(--accent);
  margin-top: 6px;
}

/* Leaderboard Section */
.leaderboard-section {
  margin: 32px 0;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.leaderboard-tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}

.tab-btn {
  padding: 10px 20px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tab-btn.active {
  background: linear-gradient(135deg, rgba(110, 241, 197, 0.2), rgba(255, 196, 102, 0.1));
  border-color: var(--accent);
  color: var(--text);
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: all 0.2s ease;
}

.leaderboard-item:hover {
  border-color: rgba(110, 241, 197, 0.3);
}

.leaderboard-item.current-user {
  border-color: var(--accent);
  background: rgba(110, 241, 197, 0.05);
}

.leaderboard-item.top-3 {
  border-color: var(--accent-2);
  background: rgba(255, 196, 102, 0.05);
}

.rank,
.leaderboard-rank {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--panel);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
}

.rank.gold,
.leaderboard-rank.gold {
  background: linear-gradient(135deg, #ffd700, #ffb347);
  color: #0b1021;
}

.rank.silver,
.leaderboard-rank.silver {
  background: linear-gradient(135deg, #c0c0c0, #a8a8a8);
  color: #0b1021;
}

.rank.bronze,
.leaderboard-rank.bronze {
  background: linear-gradient(135deg, #cd7f32, #b87333);
  color: #0b1021;
}

.leaderboard-user {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.leaderboard-user .user-name {
  font-weight: 600;
  font-size: 14px;
}

.leaderboard-user .user-streak {
  font-size: 12px;
  color: var(--muted);
}

.leaderboard-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #0b1021;
  font-size: 16px;
}

.leaderboard-name {
  font-weight: 600;
}

.leaderboard-stats {
  display: flex;
  gap: 16px;
  align-items: center;
}

.leaderboard-xp {
  font-weight: 700;
  color: var(--accent);
}

.leaderboard-streak {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--accent-2);
  font-size: 14px;
}

.leaderboard-empty,
.leaderboard-loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

.leaderboard-empty .sub {
  font-size: 13px;
  margin-top: 8px;
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(110, 241, 197, 0.1);
  border: 1px solid rgba(110, 241, 197, 0.3);
  border-radius: 20px;
  font-size: 11px;
  color: var(--accent);
  margin-left: 8px;
}

@media (max-width: 900px) {
  .topbar,
  .hero {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .metrics {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    width: 100%;
  }

  .user-auth {
    grid-column: 1 / -1;
    justify-content: center;
    margin-top: 8px;
  }

  .cta {
    flex-wrap: wrap;
  }

  .leaderboard-stats {
    flex-direction: column;
    gap: 4px;
    align-items: flex-end;
  }

  .achievements-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
}
