/* LearnTrack — Bold Vibrant theme with auto dark/light */
:root {
  --bg: #fff7ed;
  --bg-soft: #ffedd5;
  --surface: #ffffff;
  --surface-2: #fff1f2;
  --border: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  --brand: #ec4899;
  --brand-2: #f97316;
  --brand-3: #fbbf24;
  --grad-brand: linear-gradient(135deg, #ec4899 0%, #f97316 50%, #fbbf24 100%);
  --grad-streak: linear-gradient(135deg, #f97316 0%, #ef4444 100%);
  --grad-success: linear-gradient(135deg, #84cc16 0%, #10b981 100%);
  --grad-cool: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --grad-card: linear-gradient(135deg, rgba(236,72,153,0.12) 0%, rgba(249,115,22,0.12) 100%);

  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;

  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow: 0 8px 28px rgba(236, 72, 153, 0.18);
  --shadow-lg: 0 24px 64px rgba(236, 72, 153, 0.28);

  --radius: 20px;
  --radius-lg: 28px;
  --radius-pill: 999px;

  --nav-height: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
/* Auto mode: only apply dark when system prefers dark AND user hasn't picked an explicit theme */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0a0f;
    --bg-soft: #11111a;
    --surface: #16161f;
    --surface-2: #1d1d28;
    --border: rgba(255, 255, 255, 0.07);
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --text-subtle: #64748b;
    --grad-card: linear-gradient(135deg, rgba(236,72,153,0.18) 0%, rgba(249,115,22,0.12) 100%);
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.7);
  }
}
/* Explicit light override beats the media query */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #fff7ed;
  --bg-soft: #ffedd5;
  --surface: #ffffff;
  --surface-2: #fff1f2;
  --border: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --grad-card: linear-gradient(135deg, rgba(236,72,153,0.12) 0%, rgba(249,115,22,0.12) 100%);
  --shadow: 0 8px 28px rgba(236, 72, 153, 0.18);
  --shadow-lg: 0 24px 64px rgba(236, 72, 153, 0.28);
}
/* Explicit dark override (works even if system is light) */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0f; --bg-soft: #11111a; --surface: #16161f; --surface-2: #1d1d28;
  --border: rgba(255,255,255,0.07); --text: #f8fafc; --text-muted: #94a3b8; --text-subtle: #64748b;
  --grad-card: linear-gradient(135deg, rgba(236,72,153,0.18) 0%, rgba(249,115,22,0.12) 100%);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.5); --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  overscroll-behavior-y: contain;
}
.mono { font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }

/* ============= LAYOUT ============= */
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 24px);
  max-width: 640px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}
.page { padding: 20px 18px 8px; animation: pageIn 0.32s cubic-bezier(.2,.7,.3,1.2); }
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px 18px;
}
.topbar h1 { font-size: 28px; font-weight: 800; margin: 0; letter-spacing: -0.02em; }
.greeting { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-bottom: 2px; }

/* ============= BOTTOM NAV ============= */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--border);
  padding: 10px 8px calc(10px + var(--safe-bottom));
  display: flex; justify-content: space-around; align-items: center;
  z-index: 100;
}
.bottom-nav .nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 8px; border-radius: 16px; cursor: pointer; transition: all 0.2s;
  color: var(--text-muted); background: transparent; border: 0;
}
.bottom-nav .nav-item.active { color: var(--brand); }
.bottom-nav .nav-item.active .nav-icon { background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; transform: scale(1.1); }
.bottom-nav .nav-icon { font-size: 22px; transition: transform 0.2s; }
.bottom-nav .nav-label { font-size: 10px; font-weight: 600; letter-spacing: 0.02em; }

/* ============= CARDS ============= */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}
.card.hero {
  background: var(--grad-brand);
  color: white;
  border: 0;
  box-shadow: var(--shadow-lg);
  padding: 22px;
}
.card.hero::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at top right, rgba(255,255,255,0.25), transparent 60%);
  pointer-events: none;
}

/* ============= STREAK BADGE ============= */
.streak-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--grad-streak); color: white;
  padding: 8px 14px; border-radius: var(--radius-pill);
  font-weight: 800; font-size: 14px;
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.35);
  animation: pulse 2.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}
.streak-badge .flame { font-size: 16px; }

/* ============= PROGRESS RING ============= */
.ring {
  --size: 80px;
  --thickness: 8px;
  --progress: 0;
  width: var(--size); height: var(--size);
  position: relative;
}
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { fill: none; stroke: var(--border); stroke-width: var(--thickness); }
.ring .fill {
  fill: none; stroke: url(#ringGrad);
  stroke-width: var(--thickness); stroke-linecap: round;
  transition: stroke-dasharray 0.8s cubic-bezier(.2,.7,.3,1);
}
.ring .center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 0;
}
.ring .center .pct { font-weight: 800; font-size: 18px; letter-spacing: -0.02em; }
.ring .center .label { font-size: 9px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }

/* ============= COURSE CARDS ============= */
.course-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px; margin-top: 8px;
}
.course-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s; position: relative; overflow: hidden;
  text-align: left;
}
.course-card:active { transform: scale(0.97); }
.course-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: var(--course-color, var(--grad-brand));
}
.course-card .icon-circle {
  width: 44px; height: 44px; border-radius: 14px;
  background: var(--course-color, var(--grad-brand));
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; box-shadow: 0 6px 16px rgba(236,72,153,0.25);
}
.course-card .title { font-weight: 700; font-size: 15px; margin: 12px 0 4px; line-height: 1.3; }
.course-card .meta { font-size: 12px; color: var(--text-muted); }
.course-card .progress-bar {
  height: 6px; background: var(--border); border-radius: 3px;
  margin-top: 12px; overflow: hidden;
}
.course-card .progress-bar .fill {
  height: 100%; background: var(--course-color, var(--grad-brand));
  border-radius: 3px; transition: width 1s cubic-bezier(.2,.7,.3,1);
}
.course-card .progress-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--text-muted); margin-top: 6px; font-weight: 600;
}

/* ============= BUTTONS ============= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 22px; border-radius: var(--radius-pill);
  font-weight: 700; font-size: 15px; border: 0; cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  text-decoration: none;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--grad-brand); color: white; box-shadow: 0 8px 24px rgba(236,72,153,0.35); }
.btn.primary:hover { box-shadow: 0 12px 32px rgba(236,72,153,0.45); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: white; }
.btn.ghost { background: transparent; color: var(--text-muted); }
.btn.block { width: 100%; }
.btn.lg { padding: 16px 28px; font-size: 16px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============= SESSION ROW ============= */
.session-list { list-style: none; padding: 0; margin: 0; }
.session-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; margin-bottom: 8px;
  transition: transform 0.2s, background 0.2s;
}
.session-row.completed { opacity: 0.6; }
.session-row .check {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--border); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; background: transparent;
}
.session-row .check.done {
  background: var(--grad-success); border-color: transparent; color: white;
  box-shadow: 0 4px 12px rgba(16,185,129,0.35);
}
.session-row .info { flex: 1; min-width: 0; }
.session-row .info .title { font-weight: 600; font-size: 14px; }
.session-row .info .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.session-row.completed .title { text-decoration: line-through; }
.session-row .hours { font-weight: 700; font-size: 13px; color: var(--brand); }
.session-row .play-btn {
  flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%;
  background: var(--grad-brand); color: white; border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
  box-shadow: 0 4px 12px rgba(236,72,153,0.35);
}

/* ============= TIMER SCREEN ============= */
.timer-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 32px 18px;
}
.timer-ring { width: 280px; height: 280px; margin: 24px auto; }
.timer-ring .time {
  font-family: 'JetBrains Mono', monospace; font-size: 48px; font-weight: 700;
  letter-spacing: -0.02em;
}
.timer-actions {
  display: flex; gap: 12px; margin-top: 32px; flex-wrap: wrap; justify-content: center;
}

/* ============= FLOATING TIMER PILL ============= */
.timer-pill {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%; transform: translateX(-50%);
  background: var(--grad-brand); color: white;
  padding: 12px 20px; border-radius: var(--radius-pill);
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 12px 32px rgba(236,72,153,0.45);
  z-index: 90; cursor: pointer; font-weight: 700;
  animation: floatIn 0.4s cubic-bezier(.2,.7,.3,1.2);
  max-width: calc(100% - 36px);
}
@keyframes floatIn {
  from { transform: translate(-50%, 24px); opacity: 0; }
  to   { transform: translate(-50%, 0);    opacity: 1; }
}
.timer-pill .dot {
  width: 8px; height: 8px; border-radius: 50%; background: white;
  animation: blink 1.5s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }

/* ============= FORMS ============= */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.field input, .field textarea, .field select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 14px; background: var(--surface-2); color: var(--text);
  transition: border-color 0.2s; font-size: 15px;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(236,72,153,0.12);
}
.field textarea { min-height: 80px; resize: vertical; }

/* ============= LOGIN SCREEN ============= */
.login-screen {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px;
  background: var(--bg);
}
.login-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 32px 24px; width: 100%; max-width: 380px;
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  position: relative; overflow: hidden;
}
.login-card::before {
  content: ''; position: absolute; top: -40px; right: -40px;
  width: 200px; height: 200px; border-radius: 50%;
  background: var(--grad-brand); opacity: 0.18; filter: blur(40px);
}
.logo {
  font-size: 32px; font-weight: 900; letter-spacing: -0.03em;
  background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ============= HEATMAP ============= */
.heatmap {
  display: grid; grid-template-columns: repeat(53, 1fr); gap: 3px;
  padding: 12px; overflow-x: auto;
}
.heatmap .cell {
  aspect-ratio: 1; border-radius: 3px; background: var(--border);
}
.heatmap .cell[data-l="1"] { background: rgba(236,72,153,0.25); }
.heatmap .cell[data-l="2"] { background: rgba(236,72,153,0.5); }
.heatmap .cell[data-l="3"] { background: rgba(236,72,153,0.75); }
.heatmap .cell[data-l="4"] { background: var(--brand); }

/* ============= TOAST ============= */
#toast-host {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: var(--radius-pill);
  font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s cubic-bezier(.2,.7,.3,1.2);
  display: flex; align-items: center; gap: 8px;
}
.toast.success { background: var(--grad-success); color: white; }
.toast.error { background: var(--danger); color: white; }
@keyframes toastIn { from { transform: translateY(-20px); opacity: 0; } }

/* ============= MODAL ============= */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px); z-index: 150;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 20px; width: 100%; max-width: 640px;
  max-height: 85vh; overflow-y: auto;
  animation: slideUp 0.32s cubic-bezier(.2,.7,.3,1.2);
  padding-bottom: calc(24px + var(--safe-bottom));
}
@keyframes slideUp { from { transform: translateY(100%); } }
.modal h2 { margin: 0 0 16px; font-size: 22px; }
.modal .grip {
  width: 40px; height: 4px; background: var(--border); border-radius: 2px;
  margin: 0 auto 18px;
}

/* ============= MODULE/SESSION DETAILS ============= */
.module-block { margin-bottom: 16px; }
.module-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; padding: 0 4px;
}
.module-header .title { font-weight: 700; font-size: 15px; }
.module-header .meta { font-size: 12px; color: var(--text-muted); font-weight: 600; }

/* ============= STATS ============= */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat-card .num { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.stat-card .lbl { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-top: 2px; }

/* ============= WEEKLY BAR CHART ============= */
.weekly-bars {
  display: flex; align-items: flex-end; gap: 6px; height: 80px; padding: 12px 4px;
}
.weekly-bars .bar {
  flex: 1; background: var(--grad-brand); border-radius: 6px 6px 2px 2px;
  min-height: 4px; transition: height 0.8s cubic-bezier(.2,.7,.3,1);
  position: relative;
}
.weekly-bars .bar .day { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--text-muted); }

/* ============= BADGES ============= */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 10px; }
.badge {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px 8px; text-align: center;
  transition: transform 0.2s;
}
.badge:hover { transform: translateY(-2px); }
.badge .emoji { font-size: 32px; }
.badge .name { font-size: 11px; font-weight: 700; margin-top: 6px; }
.badge.locked { opacity: 0.3; filter: grayscale(1); }

/* ============= EMPTY STATES ============= */
.empty {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty .emoji { font-size: 56px; margin-bottom: 12px; }
.empty .title { font-weight: 700; font-size: 17px; color: var(--text); margin-bottom: 6px; }
.empty .sub { font-size: 13px; }

/* ============= CONFETTI ============= */
#confetti-host {
  position: fixed; inset: 0; pointer-events: none; z-index: 300; overflow: hidden;
}
.confetti-piece {
  position: absolute; width: 10px; height: 10px;
  animation: confettiFall 2.2s cubic-bezier(.2,.7,.3,1) forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ============= UTILITIES ============= */
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.center { text-align: center; }
.h2 { font-size: 20px; font-weight: 800; margin: 18px 0 10px; letter-spacing: -0.02em; }
.h3 { font-size: 15px; font-weight: 700; margin: 12px 0 8px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--brand); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 32px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============= PROFILE / PUBLIC ============= */
.profile-hero {
  text-align: center; padding: 32px 18px 16px;
  background: var(--grad-cool); color: white;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.profile-hero .avatar {
  width: 96px; height: 96px; border-radius: 50%; margin: 0 auto 12px;
  background: rgba(255,255,255,0.2); display: flex; align-items: center; justify-content: center;
  font-size: 44px; font-weight: 900; border: 4px solid rgba(255,255,255,0.3);
}
.profile-hero h2 { margin: 0 0 4px; font-size: 24px; }
.profile-hero .sub { opacity: 0.9; font-size: 14px; }
.profile-stats { display: flex; justify-content: center; gap: 24px; margin-top: 18px; }
.profile-stats .stat { text-align: center; }
.profile-stats .stat .num { font-size: 22px; font-weight: 800; }
.profile-stats .stat .lbl { font-size: 11px; opacity: 0.85; text-transform: uppercase; letter-spacing: 0.05em; }
