/* ===========================
   Design System — Study Trainer M3
   «The Cognitive Sanctuary»
   =========================== */

:root {
  /* ─── 1. Global Primitives ─────────────────────────────── */

  /* Neutral scale */
  --color-neutral-950: #121212;
  --color-neutral-900: #161616;
  --color-neutral-850: #1A1A1A;
  --color-neutral-800: #1E1E1E;
  --color-neutral-750: #242424;

  /* Accent palette */
  --color-blue-300:   #adc6ff;
  --color-blue-500:   #4d8eff;
  --color-mint-300:   #44e2cd;
  --color-amber-300:  #ffb95f;
  --color-red-400:    #FF4B4B;

  /* Text primitives */
  --color-text-primary:  #E0E0E0;
  --color-text-heading:  #F5F5F5;
  --color-text-muted:    #9CA3AF;
  --color-text-dim:      #6B7280;

  /* Primary transparency ladder */
  --primary-8:  rgba(173,198,255,0.08);
  --primary-15: rgba(173,198,255,0.15);
  --primary-30: rgba(173,198,255,0.30);

  /* Spacing scale */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;

  /* Type scale */
  --text-xs:      0.75rem;
  --text-sm:      0.8125rem;
  --text-base:    0.9375rem;
  --text-md:      1rem;
  --text-lg:      1.25rem;
  --text-xl:      1.5rem;
  --text-2xl:     2rem;
  --text-display: 3.5rem;

  /* ─── 2. Semantic Tokens ───────────────────────────────── */

  /* Surfaces — neutral tonal hierarchy */
  --bg:               var(--color-neutral-950);
  --surface-low:      var(--color-neutral-900);
  --surface:          var(--color-neutral-850);
  --surface-high:     var(--color-neutral-800);
  --surface-highest:  var(--color-neutral-750);

  /* Accent */
  --primary:           var(--color-blue-300);
  --primary-container: var(--color-blue-500);
  --secondary:         var(--color-mint-300);
  --tertiary:          var(--color-amber-300);
  --error:             var(--color-red-400);

  /* Text */
  --on-surface:         var(--color-text-primary);
  --on-surface-heading: var(--color-text-heading);
  --on-surface-muted:   var(--color-text-muted);
  --on-surface-dim:     var(--color-text-dim);

  /* Borders */
  --border-subtle:  rgba(255,255,255,0.05);
  --border-card:    rgba(255,255,255,0.08);

  /* ─── 3. Component Tokens ──────────────────────────────── */

  /* Geometry */
  --radius:    12px;
  --radius-sm: 8px;
  --radius-xs: 4px;

  /* Transitions */
  --t:      0.2s ease;
  --t-slow: 0.35s ease;

  /* Layout */
  --sidebar-w:       220px;
  --sidebar-w-open:  220px;
  --top-bar-h:       70px;

  /* Legacy aliases (for backward compat with inline styles) */
  --text:       var(--on-surface);
  --text-muted: var(--on-surface-muted);
  --text-dim:   var(--on-surface-dim);
  --bg-card:    var(--surface);
  --bg-card-2:  var(--surface-high);
  --bg-input:   var(--surface-low);
  --border:     var(--border-card);
  --green:      var(--secondary);
  --green-dark: #2dc4b1;
  --green-bg:   rgba(68,226,205,0.12);
  --blue:       var(--primary);
  --blue-dark:  var(--primary-container);
  --blue-bg:    rgba(173,198,255,0.12);
  --gold:       var(--tertiary);
  --gold-dark:  #d49a47;
  --gold-bg:    rgba(255,185,95,0.12);
  --red:        var(--error);
  --red-dark:   #d93e3e;
  --red-bg:     rgba(255,75,75,0.12);
  --purple:     #adc6ff;
  --purple-dark: #7aa3f0;
  --purple-bg:  rgba(173,198,255,0.12);
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-padding-top: var(--top-bar-h, 70px); }

body {
  font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--on-surface);
  line-height: 1.7;
  min-height: 100vh;
}

/* ===========================
   Skip Link (WCAG 2.1 AA)
   =========================== */
.skip-link {
  position: absolute;
  top: -100%;
  left: 8px;
  z-index: 9999;
  padding: 8px 16px;
  background: var(--primary);
  color: #121212;
  border-radius: 0 0 8px 8px;
  font-weight: 700;
  font-size: 0.875rem;
  text-decoration: none;
  transition: top 0.15s;
}
.skip-link:focus { top: 0; }

/* ===========================
   Typography
   =========================== */
h1 { font-size: clamp(1.5rem, 1rem + 2vw, 2rem); font-weight: 800; line-height: 1.2; letter-spacing: -0.02em; color: var(--on-surface-heading); }
h2 { font-size: clamp(1.25rem, 0.875rem + 1.5vw, 1.5rem); font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; color: var(--on-surface-heading); }
h3 { font-size: var(--text-lg);  font-weight: 700; color: var(--on-surface-heading); }
h4 { font-size: var(--text-md);  font-weight: 700; color: var(--on-surface-heading); }
p  { font-size: var(--text-md); }

.label-text {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
}

/* ===========================
   Sidebar Navigation
   =========================== */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border-subtle);
  z-index: 300;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-top {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 0 8px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-bottom {
  padding: 8px 0 16px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 52px;
  min-height: 52px;
  color: var(--on-surface-muted);
  text-decoration: none;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  width: 100%;
  text-align: left;
  transition: background var(--t), color var(--t);
  position: relative;
}

.sidebar-item:hover {
  background: var(--surface-high);
  color: var(--on-surface);
}

.sidebar-item.active {
  background: var(--surface-high);
  color: var(--primary);
  border-left: 3px solid var(--primary);
  padding-left: 17px;
}

.sidebar-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.sidebar-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.sidebar-label {
  overflow: hidden;
  opacity: 1;
  white-space: nowrap;
}

/* ── Sidebar brand ─── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 12px;
  font-size: 0.9375rem;
  font-weight: 800;
  color: var(--on-surface);
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
  cursor: pointer;
  transition: opacity var(--t);
}
.sidebar-brand:hover { opacity: 0.8; }
.sidebar-brand-icon { font-size: 1.25rem; flex-shrink: 0; }

/* ── Sidebar user card ─── */
.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 10px 4px;
  padding: 10px 12px;
  background: var(--surface-high);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: #121212;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: var(--text-base);
  flex-shrink: 0;
}
.sidebar-user-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}
#sidebar-username {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
}
#sidebar-level {
  font-size: 0.6875rem;
  color: var(--tertiary);
  font-weight: 500;
  font-family: 'Inter', system-ui, sans-serif;
  white-space: nowrap;
  opacity: 1;
}

/* ── Sidebar stats bar (streak + XP, shown below user card on all pages) ─── */
.sidebar-stats {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-4) 18px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-3);
}
.sidebar-stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--on-surface-muted);
}
.sidebar-stat-item b { color: var(--on-surface); }

/* Language toggle in sidebar */
.sidebar-lang {
  display: flex;
  gap: 4px;
  padding: 8px 14px;
  overflow: hidden;
}

.sidebar-lang-btn {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-card);
  background: transparent;
  color: var(--on-surface-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
}

.sidebar-lang-btn.active {
  background: var(--primary-container);
  color: #121212;
  border-color: var(--primary-container);
}

.sidebar-lang-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ===========================
   Mobile Bottom Navigation
   =========================== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  z-index: 300;
  background: rgba(18,18,18,0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.bottom-nav-inner {
  display: flex;
  height: 100%;
  align-items: stretch;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--on-surface-dim);
  text-decoration: none;
  font-size: 0.6875rem;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 500;
  padding: 6px 4px;
  min-height: 44px;
  transition: color var(--t);
}

.bottom-nav-item.active,
.bottom-nav-item:hover { color: var(--secondary); }

.bottom-nav-icon { font-size: 1.25rem; }

/* ── Sidebar toggle button ─── */
.sidebar-toggle {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--on-surface-muted);
  font-size: 1.25rem;
  cursor: pointer;
  z-index: 301;
  transition: background var(--t), border-color var(--t);
}
.sidebar-toggle:hover {
  background: var(--surface-high);
  border-color: var(--border-card);
}
.sidebar-toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* ── Sidebar collapsed state ─── */
.sidebar--collapsed {
  transform: translateX(-100%);
}
.sidebar {
  transition: transform 0.25s ease;
}

/* ── Floating hamburger when sidebar collapsed (desktop) ─── */
.sidebar-floater {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--on-surface-muted);
  font-size: 1.25rem;
  cursor: pointer;
  z-index: 301;
  transition: background var(--t), border-color var(--t);
}
.sidebar-floater:hover {
  background: var(--surface-high);
  border-color: var(--border-card);
}
.sidebar-floater:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* ── Desktop: margin shift when sidebar collapsed ─── */
body.body--sidebar-collapsed > .top-bar,
body.body--sidebar-collapsed > main,
body.body--sidebar-collapsed > .page-content,
body.body--sidebar-collapsed > .screen,
body.body--sidebar-collapsed > .main-content {
  margin-left: 0 !important;
  transition: margin-left 0.25s ease;
}

/* ── Mobile landscape: sidebar as overlay ─── */
.sidebar-backdrop {
  display: none;
}
@media (max-width: 768px) and (orientation: landscape) {
  .sidebar {
    display: flex;
    transform: translateX(-100%);
  }
  .sidebar.sidebar--overlay-open {
    transform: translateX(0);
  }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 299;
  }
  .sidebar-floater {
    display: flex;
  }
  .bottom-nav { display: none; }
}

/* ── Mobile portrait: no sidebar, no toggle ─── */
@media (max-width: 768px) and (orientation: portrait) {
  .sidebar    { display: none !important; }
  .sidebar-floater { display: none !important; }
  .sidebar-toggle { display: none !important; }
  .bottom-nav { display: flex; }
}

/* ── Desktop: show sidebar normally ─── */
@media (min-width: 769px) {
  .sidebar-floater { display: none; }
  body.body--sidebar-collapsed .sidebar-floater { display: flex; }
}

/* ── Reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
  body.body--sidebar-collapsed > .top-bar,
  body.body--sidebar-collapsed > main,
  body.body--sidebar-collapsed > .page-content,
  body.body--sidebar-collapsed > .screen,
  body.body--sidebar-collapsed > .main-content { transition: none; }
  .sidebar-backdrop { backdrop-filter: none; -webkit-backdrop-filter: none; }
}

/* ── Bottom nav overflow menu ─── */
.bottom-nav-mehr {
  border: none;
  background: transparent;
  cursor: pointer;
}
.bottom-nav-overflow {
  position: fixed;
  bottom: 60px;
  right: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
  z-index: 301;
  min-width: 180px;
  animation: overflow-in 0.15s ease;
}
.bottom-nav-overflow ul {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
}
.bottom-nav-overflow-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  height: 44px;
  color: var(--on-surface-muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background var(--t), color var(--t);
}
.bottom-nav-overflow-item:hover,
.bottom-nav-overflow-item.active {
  background: var(--surface-high);
  color: var(--primary);
}
.bottom-nav-overflow-item:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
@keyframes overflow-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .bottom-nav-overflow { animation: none; }
}

/* ===========================
   Top Navigation Bar
   =========================== */
.top-bar {
  background: var(--surface);
  padding: 0.75rem 0;
  position: sticky;
  top: 0;
  z-index: 200;
}

.top-bar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.top-bar-left { display: flex; align-items: center; gap: 0.75rem; }

/* Back button — kept for compatibility, styled as ghost */
.back-btn {
  background: transparent;
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  color: var(--on-surface-muted);
  padding: 0.4rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  transition: all var(--t);
}
.back-btn:hover { color: var(--primary); border-color: var(--primary-30); }
.back-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }

.top-bar-title {
  font-size: 0.9375rem;
  font-weight: 800;
  color: var(--on-surface);
}

/* XP / Streak bar */
.top-bar-stats {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 700;
  font-size: 0.875rem;
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--tertiary);
}

.stat-pill .icon { font-size: 1.1rem; }

/* XP Tooltip */
.xp-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--primary);
  cursor: pointer;
  user-select: none;
  font-family: 'Inter', system-ui, sans-serif;
}
.xp-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface-high);
  border-radius: var(--radius);
  padding: .6rem .85rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--on-surface-muted);
  white-space: nowrap;
  z-index: 200;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
  line-height: 1.85;
  pointer-events: none;
}
.xp-wrap:hover .xp-tooltip,
.xp-wrap.open .xp-tooltip { display: block; }
.xp-wrap:focus-visible { outline: 2px solid var(--primary); border-radius: var(--radius-xs); outline-offset: 3px; }

/* ===========================
   Language Toggle (in top-bar, legacy)
   =========================== */
.lang-toggle {
  display: flex;
  background: var(--surface-high);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.lang-btn {
  padding: var(--space-2) 14px;
  border-radius: 999px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--on-surface-muted);
  cursor: pointer;
  transition: background var(--t), color var(--t);
  white-space: nowrap;
}

.lang-btn.active {
  background: var(--primary-container);
  color: #121212;
}

.lang-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 999px; }

/* ===========================
   Layout
   =========================== */
.container { max-width: 860px; margin: 0 auto; padding: 0 1.25rem; }
.page-content { padding: 2rem 0 4rem; }

/* Push main content to the right of sidebar */
@media (min-width: 769px) {
  body > .top-bar,
  body > main,
  body > .page-content,
  body > .screen {
    margin-left: var(--sidebar-w);
    transition: margin-left 0.25s ease;
  }
  /* .container has class-level specificity (0,1,0) > element (0,0,1),
     so its margin: 0 auto overrides margin-left above — fix with higher specificity */
  body > main.container,
  body > main.page-content {
    margin-left: var(--sidebar-w);
    margin-right: 0;
  }
  /* Double-class specificity (0,2,0) beats .container (0,1,0) — definitive fix */
  .container.page-content {
    margin-left: var(--sidebar-w);
    margin-right: 0;
  }
}

/* ===========================
   Glassmorphism utility
   =========================== */
.glass {
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  background: rgba(26,26,26,0.85);
}

/* ===========================
   Progress Rail
   =========================== */
.progress-rail {
  height: 4px;
  background: var(--surface-high);
  border-radius: 999px;
  overflow: hidden;
}

.progress-rail-fill {
  height: 100%;
  background: var(--secondary);
  border-radius: 999px;
  transition: width 0.6s ease-out;
}

/* ===========================
   Buttons — Cognitive Sanctuary
   =========================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.75rem;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--text-md);
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--t), box-shadow var(--t), background var(--t);
  text-decoration: none;
  line-height: 1;
  -webkit-user-select: none;
  user-select: none;
}

.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

.btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Primary — gradient azure CTA */
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  color: #121212;
  font-weight: 800;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(77,142,255,0.35); }
.btn-primary:active:not(:disabled) { transform: translateY(0); box-shadow: 0 2px 8px rgba(77,142,255,0.25); }

/* Green — mint secondary (Cognitive Sanctuary) */
.btn-green {
  background: var(--secondary);
  color: #121212;
  font-weight: 800;
}
.btn-green:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(68,226,205,0.35); }
.btn-green:active:not(:disabled) { transform: translateY(0); box-shadow: 0 2px 8px rgba(68,226,205,0.25); }

/* Blue — azure primary */
.btn-blue {
  background: var(--primary);
  color: #121212;
  font-weight: 800;
}
.btn-blue:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(173,198,255,0.35); }
.btn-blue:active:not(:disabled) { transform: translateY(0); box-shadow: 0 2px 8px rgba(173,198,255,0.25); }

/* Ghost / Secondary */
.btn-ghost,
.btn-secondary {
  background: var(--surface-high);
  color: var(--on-surface);
  border: 1px solid var(--border-card);
}
.btn-ghost:hover:not(:disabled),
.btn-secondary:hover:not(:disabled) { background: var(--surface-highest); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.btn-ghost:active:not(:disabled),
.btn-secondary:active:not(:disabled) { transform: translateY(0); }

/* Red */
.btn-red {
  background: var(--error);
  color: #fff;
  font-weight: 800;
}
.btn-red:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(255,75,75,0.35); }
.btn-red:active:not(:disabled) { transform: translateY(0); }

/* Gold / Tertiary */
.btn-gold {
  background: var(--tertiary);
  color: #121212;
  font-weight: 800;
}
.btn-gold:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(255,185,95,0.35); }
.btn-gold:active:not(:disabled) { transform: translateY(0); }

.btn-lg   { padding: 1rem 2.5rem; font-size: 1.125rem; }
.btn-sm   { padding: 0.5rem 1rem; font-size: 0.875rem; border-radius: var(--radius-sm); }
.btn-full { width: 100%; }

/* Loading state (UI-18.19) */
.btn-loading {
  pointer-events: none;
  position: relative;
  color: transparent !important;
}
.btn-loading::after {
  content: '';
  position: absolute;
  width: 1.125em;
  height: 1.125em;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btnSpin 0.6s linear infinite;
}
@keyframes btnSpin {
  to { transform: rotate(360deg); }
}

/* ===========================
   Cards
   =========================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: border-color var(--t), box-shadow var(--t), transform var(--t);
}

.card:hover {
  border-color: var(--primary-30);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  transform: translateY(-2px);
}

.card-highlighted {
  background: var(--primary-8);
}

/* ===========================
   Dashboard Grid (Home page)
   =========================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: var(--space-5);
  margin-top: 1rem;
}

/* Compact padding for dashboard tiles only */
.dashboard-grid .bento-tile { padding: 14px 16px; }
/* Smaller stat number in dashboard (91 days etc.) */
.dashboard-grid .bento-tile-value { font-size: 1.625rem; margin: 4px 0 2px; }
.dashboard-grid .bento-tile-icon  { font-size: 1.25rem; }

/* Hero card spans left column */
.hero-card {
  grid-column: 1;
  grid-row: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.hero-card-body {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  height: 100%;
}
.hero-text { flex: 1; }
.hero-greeting {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--on-surface-muted);
  margin-bottom: 4px;
}
.hero-username {
  font-size: 1.875rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 8px;
  color: var(--on-surface);
}
.hero-sub {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.8125rem;
  color: var(--on-surface-muted);
  margin-bottom: 1rem;
  line-height: 1.5;
}
.hero-illus {
  font-size: 3rem;
  line-height: 1;
  opacity: 0.25;
  flex-shrink: 0;
  align-self: center;
}

/* Stats column (right) */
.stats-col {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* Combined streak+XP card */
.stat-split-card {
  display: flex;
  gap: 0;
}
.stat-half {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-half + .stat-half {
  border-left: 1px solid var(--border-subtle);
  padding-left: var(--space-4);
  margin-left: 0;
}
.stat-half-icon { font-size: 1.25rem; line-height: 1; margin-bottom: 6px; }
.stat-half-val  { font-size: 1.875rem; font-weight: 800; line-height: 1; }
.stat-half-lbl  { font-family: 'Inter', sans-serif; font-size: 0.6875rem; color: var(--on-surface-muted); margin-top: 2px; }

/* Level card */
.level-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--on-surface-muted);
}
.level-num-badge {
  font-size: 1.125rem;
  font-weight: 800;
  color: var(--secondary);
}
.xp-sub-text {
  font-family: 'Inter', sans-serif;
  font-size: 0.6875rem;
  color: var(--on-surface-dim);
  margin-top: 6px;
}

/* Module progress card (full width) */
.modules-card {
  grid-column: 1 / -1;
}
.modules-card-hdr {
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--on-surface-muted);
  margin-bottom: 14px;
}

/* Quick tiles (full-width 3-col row) */
.quick-tiles-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-5);
}

.bento-tile {
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  padding: var(--space-5);
  transition: border-color var(--t), box-shadow var(--t), transform var(--t);
}
.bento-tile:hover { border-color: var(--primary-30); box-shadow: 0 8px 24px rgba(0,0,0,0.3); transform: translateY(-2px); }

/* Quick-access tiles */
.bento-quick {
  text-decoration: none;
  color: var(--on-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 100px;
  text-align: center;
}
.bento-quick:hover { border-color: var(--primary-30); }
.bento-quick-icon  { font-size: 1.75rem; }
.bento-quick-title { font-size: 0.875rem; font-weight: 700; }

/* Legacy bento-grid (other pages if needed) */
.bento-grid {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: repeat(3, 1fr);
  margin-top: 2rem;
}
@media (max-width: 900px) { .bento-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .bento-grid { grid-template-columns: 1fr; } }
.bento-modules { grid-column: span 2; }

.bento-tile-value {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--tertiary);
  line-height: 1;
  margin: 8px 0 4px;
}

.bento-xp .bento-tile-value { color: var(--primary); }
.bento-level .bento-tile-value { color: var(--secondary); }

.bento-tile-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.bento-tile-label {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.8125rem;
  color: var(--on-surface-muted);
}

.bento-tile-sub {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.75rem;
  color: var(--on-surface-dim);
  margin-top: 4px;
}

/* ===========================
   Module progress cards (home, фича E)
   =========================== */
.module-progress-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 20px;
  text-decoration: none;
  color: var(--on-surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: background var(--t);
  cursor: pointer;
}

.module-progress-card:hover { border-color: var(--primary-30); box-shadow: 0 8px 24px rgba(0,0,0,0.3); }

.module-progress-card .mod-icon { font-size: 1.5rem; }
.module-progress-card .mod-name { font-size: 0.9375rem; font-weight: 700; }
.module-progress-card .mod-pct {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.8125rem;
  color: var(--on-surface-muted);
}

/* ===========================
   Progress / Session header
   =========================== */
.session-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.session-progress {
  flex: 1;
  background: var(--surface-high);
  border-radius: 999px;
  height: 4px;
  overflow: hidden;
}

.session-progress-fill {
  height: 100%;
  background: var(--secondary);
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
}

.session-count {
  font-weight: 700;
  font-size: 0.875rem;
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--on-surface-muted);
  white-space: nowrap;
  min-width: 3.5rem;
  text-align: right;
}

/* Hearts */
.hearts { display: flex; gap: 0.2rem; align-items: center; }
.heart  { font-size: 1.125rem; transition: transform 0.3s; }
.heart.lost { filter: grayscale(1) opacity(0.25); }
.heart-shake { animation: heartShake 0.5s; }

@keyframes heartShake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-4px) rotate(-10deg); }
  50%     { transform: translateX(4px) rotate(10deg); }
  80%     { transform: translateX(-2px); }
}

/* ===========================
   Flashcard
   =========================== */
.flashcard-scene {
  perspective: 1200px;
  margin: 2rem auto;
  max-width: 560px;
  height: 240px;
  cursor: pointer;
}

.flashcard-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4,0,0.2,1);
}

.flashcard-scene:active .flashcard-inner {
  transform: scale(0.97);
  transition: transform 0.1s ease;
}

.flashcard-scene.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-scene.flipped:active .flashcard-inner {
  transform: rotateY(180deg) scale(0.97);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  background: var(--surface);
}

.flashcard-face.front {
  background: linear-gradient(135deg, var(--surface) 0%, var(--primary-8) 100%);
  border: 1px solid var(--border-card);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.flashcard-face.back {
  transform: rotateY(180deg);
  background: linear-gradient(135deg, var(--surface) 0%, rgba(68,226,205,0.08) 100%);
  border: 1px solid var(--border-card);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.flashcard-lang {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--on-surface-muted);
  font-family: 'Inter', system-ui, sans-serif;
  margin-bottom: 0.75rem;
}

.flashcard-term {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--on-surface);
  line-height: 1.2;
}

.flashcard-hint {
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--on-surface-muted);
  font-style: italic;
  background: var(--surface-high);
  border-radius: var(--radius-xs);
  padding: 0.3rem 0.75rem;
}

.flashcard-tap-hint {
  position: absolute;
  bottom: 1rem;
  font-size: 0.75rem;
  color: var(--on-surface-dim);
  font-weight: 600;
  font-family: 'Inter', system-ui, sans-serif;
}

/* Card action bar */
.card-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
}

/* ===========================
   Quiz / Exam Answer Options
   =========================== */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.options-grid--rf {
  grid-template-columns: 1fr 1fr;
}

.rf-badge {
  font-size: var(--text-xs, 0.75rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

.option-btn {
  background: var(--surface-high);
  border: none;
  border-radius: var(--radius);
  padding: 1rem 1.125rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--on-surface);
  cursor: pointer;
  text-align: left;
  transition: background var(--t), color var(--t), border-left var(--t);
  line-height: 1.4;
  position: relative;
  border-left: 3px solid transparent;
}

.option-btn:hover:not(:disabled) {
  background: var(--surface-highest);
}

.option-btn.selected {
  background: rgba(77,142,255,0.15);
  border-left-color: var(--primary);
  color: var(--primary);
}

.option-btn.correct {
  background: rgba(68,226,205,0.15);
  border-left-color: var(--secondary);
  color: var(--secondary);
}

.option-btn.wrong {
  background: rgba(255,75,75,0.15);
  border-left-color: var(--error);
  color: var(--error);
}

.option-btn:disabled { cursor: default; }

.option-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.option-btn::before {
  content: attr(data-label);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 4px;
  background: var(--surface-highest);
  font-size: 0.75rem;
  font-weight: 700;
  font-family: 'Inter', system-ui, sans-serif;
  margin-right: 0.625rem;
  flex-shrink: 0;
  float: left;
  margin-top: 0.1rem;
}

.option-btn.correct::before { background: rgba(68,226,205,0.2); color: var(--secondary); }
.option-btn.wrong::before   { background: rgba(255,75,75,0.2);  color: var(--error); }

/* ===========================
   Exam — Task Navigator (фича A)
   =========================== */
.exam-layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 24px;
  align-items: start;
}

@media (max-width: 1279px) {
  .exam-layout { grid-template-columns: 1fr; }
  .exam-right-sidebar { display: none; }
}

.exam-right-sidebar {
  position: sticky;
  top: 80px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
}

.task-navigator {
  display: grid;
  grid-template-columns: repeat(6, 44px);
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.task-cell {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-xs);
  background: var(--surface-high);
  color: var(--on-surface-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: 'Inter', system-ui, sans-serif;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t), color var(--t);
}

.task-cell.answered  { background: rgba(68,226,205,0.25); color: var(--secondary); }
.task-cell.current   { background: var(--primary-container); color: #121212; font-weight: 800; }
.task-cell.flagged   { background: rgba(255,185,95,0.3); color: var(--tertiary); }
.task-cell:hover:not(.current) { background: var(--surface-highest); }
.task-cell:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.focus-anchor {
  background: var(--surface-high);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 0.8125rem;
  color: var(--on-surface-muted);
  line-height: 1.5;
}

.focus-anchor-title {
  font-size: 0.75rem;
  font-weight: 700;
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--primary);
  margin-bottom: 4px;
}

/* Breadcrumb */
.breadcrumb {
  font-size: 0.875rem;
  color: var(--on-surface-muted);
  font-family: 'Inter', system-ui, sans-serif;
  margin-bottom: 1rem;
}

/* ===========================
   Glossary — 2-column grid + badges
   =========================== */
.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 1rem;
}

@media (max-width: 640px) {
  .glossary-grid { grid-template-columns: 1fr; }
}

.glossary-card {
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  padding: var(--space-5);
  position: relative;
  transition: border-color var(--t), box-shadow var(--t), transform var(--t);
}

.glossary-card:hover { border-color: var(--primary-30); box-shadow: 0 8px 24px rgba(0,0,0,0.3); transform: translateY(-2px); }

.glossary-term { font-size: 1.0625rem; font-weight: 700; margin-bottom: 6px; }
.glossary-def  { font-size: 0.875rem; color: var(--on-surface-muted); line-height: 1.5; margin-bottom: 12px; }
.glossary-tag  {
  display: inline-block;
  background: var(--surface-high);
  border-radius: var(--radius-xs);
  padding: 2px 8px;
  font-size: 0.75rem;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 500;
  color: var(--on-surface-muted);
  margin-bottom: 8px;
}

/* Star button (фича D) */
.star-btn {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.125rem;
  color: var(--on-surface-dim);
  transition: color var(--t), transform var(--t);
  padding: var(--space-3);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.star-btn:hover { color: var(--tertiary); transform: scale(1.15); }
.star-btn.starred { color: var(--tertiary); }
.star-btn:focus-visible { outline: 2px solid var(--primary); border-radius: 4px; outline-offset: 2px; }

/* Confidence badge (фича C) */
.confidence-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) 14px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 500;
  border: none;
  cursor: pointer;
  background: var(--surface-high);
  color: var(--on-surface-dim);
  transition: background var(--t), color var(--t), transform 0.1s;
}

.confidence-badge:hover { background: var(--surface-highest); }
.confidence-badge:active { transform: scale(0.95); }
.confidence-badge:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.confidence-badge.learning  { background: var(--primary-15); color: var(--primary); }
.confidence-badge.review    { background: rgba(255,185,95,0.12);  color: var(--tertiary); }
.confidence-badge.confident { background: rgba(68,226,205,0.12);  color: var(--secondary); }

/* Mastery counter (фича B) */
.mastery-counter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.9375rem;
  color: var(--on-surface-muted);
  margin-bottom: 1rem;
}

.mastery-counter .mastery-pct {
  font-weight: 700;
  color: var(--secondary);
}

.mastery-counter.low .mastery-pct { color: var(--tertiary); }

/* ===========================
   Count selector pills
   =========================== */
.count-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

.count-pill {
  padding: 0.5rem 1.125rem;
  background: var(--surface-high);
  border: 1px solid var(--border-card);
  border-radius: 999px;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--on-surface-muted);
  cursor: pointer;
  transition: all var(--t);
}

.count-pill:hover { background: var(--surface-highest); color: var(--on-surface); }

.count-pill.active {
  background: var(--primary-container);
  border-color: var(--primary-container);
  color: #121212;
}

.count-pill:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 999px; }

/* ===========================
   Feedback banner
   =========================== */
.feedback-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.25rem 1.5rem;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4,0,0.2,1);
  z-index: 150;
}

.feedback-banner.visible { transform: translateY(0); }

.feedback-banner.correct-fb {
  background: rgba(68,226,205,0.1);
  border-top: 2px solid var(--secondary);
  backdrop-filter: blur(10px);
}

.feedback-banner.wrong-fb {
  background: rgba(255,75,75,0.1);
  border-top: 2px solid var(--error);
  backdrop-filter: blur(10px);
}

.feedback-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.feedback-icon { font-size: 1.75rem; flex-shrink: 0; }
.feedback-text { flex: 1; min-width: 0; }

.feedback-title {
  font-size: 1.125rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
}

.feedback-banner.correct-fb .feedback-title { color: var(--secondary); }
.feedback-banner.wrong-fb   .feedback-title { color: var(--error); }

.feedback-explanation {
  font-size: 0.875rem;
  color: var(--on-surface-muted);
  line-height: 1.5;
}

/* Mobile — feedback above bottom nav */
@media (max-width: 768px) {
  .feedback-banner { bottom: 56px; }
}

/* ===========================
   Animations
   =========================== */
@keyframes popIn {
  0%   { transform: scale(0.6); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes correctPulse {
  0%   { box-shadow: 0 0 0 0   rgba(68,226,205,0.5); }
  70%  { box-shadow: 0 0 0 14px rgba(68,226,205,0); }
  100% { box-shadow: 0 0 0 0   rgba(68,226,205,0); }
}

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

.animate-pop     { animation: popIn       0.4s cubic-bezier(0.4,0,0.2,1); }
.animate-slide   { animation: slideUp     0.3s var(--t); }
.animate-correct { animation: correctPulse 0.6s; }
.animate-wrong   { animation: wrongShake   0.4s; }

/* ===========================
   Exercises
   =========================== */
.exercise-formula {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  background: var(--primary-8);
  border-left: 4px solid var(--primary-30);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.875rem 1rem;
  font-size: var(--text-base);
  color: var(--primary);
  font-weight: 600;
  margin: 1rem 0;
  word-break: break-word;
}

/* Lightbulb hint */
.hint-wrap { margin: 0.75rem 0; }

.hint-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255,185,95,0.1);
  border: 1px solid rgba(255,185,95,0.3);
  border-radius: 999px;
  padding: 0.3rem 0.875rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--tertiary);
  cursor: pointer;
  transition: all var(--t);
}
.hint-btn:hover { background: rgba(255,185,95,0.18); }
.hint-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 999px; }

.hint-content { margin-top: 0.5rem; }

.given-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  margin: 1rem 0;
}

.given-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.given-table td:first-child {
  color: var(--on-surface-muted);
  font-weight: 700;
  width: 55%;
}

.given-table td:last-child {
  font-weight: 800;
  color: var(--primary);
  font-family: 'JetBrains Mono', monospace;
}

.answer-row {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  margin: 1.25rem 0;
}

.answer-input {
  flex: 1;
  background: var(--surface-low);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  padding: 0.875rem 1.25rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--on-surface);
  transition: border-color var(--t), box-shadow var(--t);
  text-align: center;
  -moz-appearance: textfield;
}

.answer-input::-webkit-inner-spin-button,
.answer-input::-webkit-outer-spin-button { -webkit-appearance: none; }

.answer-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-8);
}
.answer-input.correct-input { border-color: var(--secondary); background: rgba(68,226,205,0.06); color: var(--secondary); }
.answer-input.wrong-input   { border-color: var(--error);     background: rgba(255,75,75,0.06);  color: var(--error); }

.answer-unit {
  display: flex;
  align-items: center;
  padding: 0 1rem;
  background: var(--surface-high);
  border-radius: var(--radius);
  font-weight: 800;
  color: var(--on-surface-muted);
  font-size: 1.125rem;
  white-space: nowrap;
}

.steps-list {
  list-style: none;
  counter-reset: steps;
  margin-top: 0.75rem;
}

.steps-list li {
  counter-increment: steps;
  display: flex;
  gap: 0.75rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-base);
  line-height: 1.5;
  animation: slideUp 0.3s ease both;
}

.steps-list li:last-child { border-bottom: none; }

/* Staggered delay (UI-18.20) */
.steps-list li:nth-child(1) { animation-delay: 0ms; }
.steps-list li:nth-child(2) { animation-delay: 100ms; }
.steps-list li:nth-child(3) { animation-delay: 200ms; }
.steps-list li:nth-child(4) { animation-delay: 300ms; }
.steps-list li:nth-child(5) { animation-delay: 400ms; }
.steps-list li:nth-child(n+6) { animation-delay: 500ms; }

.steps-list li::before {
  content: counter(steps);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 1.75rem;
  height: 1.75rem;
  background: var(--primary-15);
  border-radius: 50%;
  font-size: var(--text-xs);
  font-weight: 800;
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--primary);
  flex-shrink: 0;
  margin-top: 0.1rem;
}

/* ===========================
   Alert banners
   =========================== */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.4;
  animation: slideUp 0.3s ease;
}

.alert-success { background: rgba(68,226,205,0.1);  color: var(--secondary); }
.alert-danger  { background: rgba(255,75,75,0.1);   color: var(--error); }
.alert-info    { background: rgba(173,198,255,0.1); color: var(--primary); }

/* ===========================
   Topic / Filter Chips
   =========================== */
.topic-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

.topic-chip {
  display: inline-flex;
  align-items: center;
  padding: var(--space-2) var(--space-4);
  background: var(--surface-high);
  border: none;
  border-radius: 999px;
  color: var(--primary);
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all var(--t);
  white-space: nowrap;
}

.topic-chip:hover { background: var(--surface-highest); color: var(--on-surface); }
@supports (background: color-mix(in srgb, red 20%, blue)) {
  .topic-chip:hover { background: color-mix(in srgb, var(--primary) 20%, var(--surface-high)); }
}

.topic-chip.active {
  background: var(--primary);
  color: var(--bg);
  font-weight: 600;
}

.topic-chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 999px; }

/* ===========================
   Home page — module cards (legacy, kept for compat)
   =========================== */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-top: 2rem;
}

.module-card {
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  text-decoration: none;
  color: var(--on-surface);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: border-color var(--t), box-shadow var(--t), transform var(--t);
  cursor: pointer;
}

.module-card:hover { border-color: var(--primary-30); box-shadow: 0 8px 24px rgba(0,0,0,0.3); transform: translateY(-2px); }
.module-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }

.module-icon  { font-size: 2.5rem; line-height: 1; }
.module-title { font-size: 1.25rem; font-weight: 800; }

.module-desc {
  font-size: 0.875rem;
  color: var(--on-surface-muted);
  line-height: 1.5;
}

.module-stats {
  display: flex;
  gap: 1rem;
  margin-top: auto;
  padding-top: 0.75rem;
}

.module-stat { font-size: 0.8125rem; font-weight: 600; color: var(--on-surface-muted); font-family: 'Inter', system-ui, sans-serif; }
.module-stat strong { color: var(--on-surface); margin-right: 0.25rem; }

/* ===========================
   Level cards (exercises)
   =========================== */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.level-card {
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  cursor: pointer;
  text-align: center;
  transition: border-color var(--t), box-shadow var(--t), transform var(--t);
}

.level-card:hover { border-color: var(--primary-30); box-shadow: 0 8px 24px rgba(0,0,0,0.3); transform: translateY(-2px); }
.level-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }

.level-card.easy:hover   { background: rgba(68,226,205,0.08); }
.level-card.medium:hover { background: rgba(255,185,95,0.08); }
.level-card.hard:hover   { background: rgba(255,75,75,0.08); }

.level-card .level-icon  { font-size: 2.5rem; margin-bottom: 0.5rem; }
.level-card .level-name  { font-size: 1.125rem; font-weight: 800; margin-bottom: 0.25rem; }
.level-card .level-desc  { font-size: 0.8125rem; color: var(--on-surface-muted); line-height: 1.4; }
.level-card .level-count { font-size: 0.75rem; font-weight: 700; font-family: 'Inter', system-ui, sans-serif; margin-top: 0.5rem; }
.level-card.easy   .level-count { color: var(--secondary); }
.level-card.medium .level-count { color: var(--tertiary); }
.level-card.hard   .level-count { color: var(--error); }

.difficulty-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: 'Inter', system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}

.difficulty-badge.easy   { color: var(--secondary); background: rgba(68,226,205,0.1); }
.difficulty-badge.medium { color: var(--tertiary);  background: rgba(255,185,95,0.1); }
.difficulty-badge.hard   { color: var(--error);     background: rgba(255,75,75,0.1); }

/* ===========================
   Score / Result screen
   =========================== */
.result-screen {
  text-align: center;
  padding: 3rem 1rem;
  animation: slideUp 0.4s ease;
}

.result-emoji {
  font-size: 5rem;
  display: block;
  margin-bottom: 1rem;
  animation: popIn 0.5s cubic-bezier(0.4,0,0.2,1);
}

.result-score {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--secondary);
  margin: 0.5rem 0;
  animation: popIn 0.5s 0.1s cubic-bezier(0.4,0,0.2,1) both;
}

.xp-gained {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255,185,95,0.1);
  border-radius: 999px;
  padding: 0.4rem 1.25rem;
  font-size: 1.125rem;
  font-weight: 800;
  color: var(--tertiary);
  margin: 1rem 0;
  animation: popIn 0.5s 0.2s both;
}

/* ===========================
   Streak banner
   =========================== */
.streak-banner {
  background: rgba(255,185,95,0.07);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  animation: slideUp 0.3s ease;
}

.streak-banner .streak-fire { font-size: 2rem; }
.streak-banner .streak-text { font-weight: 800; color: var(--tertiary); }
.streak-banner .streak-sub  { font-size: 0.8125rem; color: var(--on-surface-muted); }

/* ===========================
   Welcome overlay
   =========================== */
.welcome-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18,18,18,0.85);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fadeIn 0.3s ease;
  backdrop-filter: blur(8px);
}

.welcome-box {
  background: rgba(26,26,26,0.9);
  backdrop-filter: blur(16px);
  border-radius: 20px;
  padding: 2rem 2rem 1.75rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  animation: popIn 0.4s cubic-bezier(0.4,0,0.2,1);
}

.welcome-video-wrap {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 auto 1.25rem;
  border: 3px solid var(--secondary);
}

.welcome-video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.welcome-box h2 {
  font-size: 1.5rem;
  color: var(--on-surface);
  margin-bottom: 0.5rem;
}

.welcome-box p {
  color: var(--on-surface-muted);
  font-size: 0.9375rem;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

/* ===========================
   Utilities
   =========================== */
.flex           { display: flex; }
.flex-center    { display: flex; align-items: center; justify-content: center; }
.items-center   { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1  { gap: 0.5rem; }
.gap-2  { gap: 1rem; }
.gap-3  { gap: 1.5rem; }
.mt-1   { margin-top: 0.5rem; }
.mt-2   { margin-top: 1rem; }
.mt-3   { margin-top: 1.5rem; }
.mt-4   { margin-top: 2rem; }
.mb-1   { margin-bottom: 0.5rem; }
.mb-2   { margin-bottom: 1rem; }
.mb-3   { margin-bottom: 1.5rem; }
.text-center { text-align: center; }
.text-muted  { color: var(--on-surface-muted); }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ===========================
   Responsive
   =========================== */
@media (max-width: 400px) {
  .options-grid--rf { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .options-grid    { grid-template-columns: 1fr; }
  .options-grid--rf { grid-template-columns: 1fr 1fr; }
  .module-grid     { grid-template-columns: 1fr; }
  .flashcard-scene { height: 200px; }
  .flashcard-term  { font-size: 1.375rem; }
  .answer-row      { flex-direction: column; }
  .answer-unit     { justify-content: center; }
  .feedback-inner  { flex-direction: column; align-items: flex-start; }
  .top-bar-stats   { gap: 0.5rem; }
  .welcome-video-wrap { width: 130px; height: 130px; }
}

/* Mobile: main content padding for bottom nav */
@media (max-width: 768px) {
  .page-content { padding-bottom: 5rem; }
}

/* ===========================
   Progress fill (shared)
   =========================== */
.progress-fill {
  height: 100%;
  background: var(--secondary);
  border-radius: 999px;
  transition: width 0.6s ease-out;
}

/* ── Back button (shared across pages) ─── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--on-surface-muted);
  text-decoration: none;
  transition: color var(--t);
}
.back-btn:hover { color: var(--primary); }

/* ===========================
   Main content + page layout
   =========================== */
.main-content {
  padding-top: 1.5rem;
  overflow-x: hidden;
}

@media (max-width: 768px) {
  .main-content { padding-bottom: 5rem; }
}

.page-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ===========================
   Dashboard responsive
   =========================== */
@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .hero-card  { grid-column: 1; grid-row: auto; }
  .stats-col  { grid-column: 1; grid-row: auto; flex-direction: row; flex-wrap: wrap; }
  .stats-col > .bento-tile { flex: 1; min-width: 140px; }
  .quick-tiles-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  .quick-tiles-row { grid-template-columns: repeat(2, 1fr); }
  .hero-illus { display: none; }
}

/* ===========================
   Module progress rows (home, фича E)
   =========================== */
.module-progress-row {
  margin-bottom: 12px;
}

.module-progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 0.875rem;
  font-weight: 600;
}

.module-progress-sub {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.75rem;
  color: var(--on-surface-dim);
}

/* ===========================
   Learning Path (home, DEV-15.10)
   =========================== */
.learning-path-card { grid-column: 1 / -1; }
.learning-path-hdr {
  font: 700 0.6875rem/1 'Inter', sans-serif;
  letter-spacing: .08em;
  color: var(--on-surface-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
}
.lp-info-tip {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary-8);
  border: 1.5px solid var(--border-card);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  font-family: 'Inter', sans-serif;
  color: var(--primary);
  cursor: help;
  padding: 0;
  transition: background var(--t), border-color var(--t), color var(--t);
}
.lp-info-tip:hover,
.lp-info-tip:focus {
  background: var(--primary-15);
  border-color: var(--primary);
  outline: none;
}
.lp-tip-content {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 260px;
  background: var(--surface-high);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--on-surface-muted);
  line-height: 1.6;
  white-space: pre-line;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.lp-info-tip:hover .lp-tip-content,
.lp-info-tip:focus .lp-tip-content {
  opacity: 1;
  transform: translateY(0);
}
.lp-list { display: flex; flex-direction: column; }
.lp-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 5px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.lp-row:last-child { border-bottom: none; }
.lp-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.lp-dot--todo     { background: var(--tertiary); }
.lp-dot--progress { background: var(--primary); }
.lp-dot--done     { background: var(--secondary); }
.lp-name { flex: 1; font-size: 0.8125rem; color: var(--on-surface); }
.lp-pct  { font: 600 0.8125rem/1 'Inter', sans-serif; color: var(--on-surface-muted); min-width: 34px; text-align: right; }

/* ===========================
   Auth overlay — Cognitive Sanctuary
   =========================== */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  padding: 0 2rem 2rem;
  width: 100%;
  max-width: 380px;
  margin: 1rem;
  box-shadow: 0 24px 60px rgba(0,0,0,0.55), 0 0 0 1px var(--border-subtle);
  overflow: hidden;
}
.auth-card::before {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  margin: 0 -2rem 2rem;
}

.auth-logo-wrap {
  text-align: center;
  margin-bottom: 1.75rem;
}
.auth-logo {
  font-size: 2.5rem;
  line-height: 1;
  display: block;
  margin-bottom: 0.625rem;
}
.auth-title {
  font-size: 1.375rem;
  font-weight: 800;
  color: var(--on-surface);
  letter-spacing: -0.02em;
  margin: 0 0 0.25rem;
}
.auth-subtitle {
  font-size: 0.75rem;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 400;
  color: var(--on-surface-muted);
  margin: 0;
  letter-spacing: 0.02em;
}

.auth-label {
  display: block;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--on-surface-muted);
  margin-bottom: 0.375rem;
}

.auth-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.75rem 1rem;
  margin-bottom: 1.125rem;
  background: var(--surface-low);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  color: var(--on-surface);
  font-family: inherit;
  font-size: var(--text-md);
  transition: border-color var(--t), box-shadow var(--t);
}
.auth-input::placeholder { color: var(--on-surface-muted); opacity: 0.6; }

.auth-input:focus {
  outline: none;
  border-color: var(--primary-30);
  box-shadow: 0 0 0 3px var(--primary-8);
}

.auth-error {
  color: var(--error);
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 1rem;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

/* ===========================
   Section alternation (UI-18.15)
   =========================== */
.section-alt {
  background: var(--surface);
  border-top: 1px solid var(--border-subtle);
}

/* ===========================
   Container Queries (UI-18.23)
   =========================== */
@supports (container-type: inline-size) {
  .page-container { container-type: inline-size; }

  @container (max-width: 640px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .options-grid   { grid-template-columns: 1fr; }
    .glossary-grid  { grid-template-columns: 1fr; }
    .bento-grid     { grid-template-columns: 1fr; }
  }

  @container (min-width: 641px) and (max-width: 900px) {
    .bento-grid     { grid-template-columns: repeat(2, 1fr); }
  }
}

/* ===========================
   Skeleton Screens (UI-18.24 / DEV-18.3)
   =========================== */
@keyframes skeletonPulse {
  0%   { opacity: 0.06; }
  50%  { opacity: 0.12; }
  100% { opacity: 0.06; }
}

.skeleton {
  background: var(--on-surface);
  border-radius: var(--radius-sm);
  animation: skeletonPulse 1.5s ease-in-out infinite;
}

.skeleton-text {
  height: 0.875rem;
  background: var(--on-surface);
  border-radius: var(--radius-xs);
  animation: skeletonPulse 1.5s ease-in-out infinite;
  margin-bottom: var(--space-2);
}

.skeleton-text:last-child { margin-bottom: 0; width: 60%; }

.skeleton-card {
  background: var(--surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  padding: var(--space-5);
  min-height: 120px;
}

.skeleton-card .skeleton {
  margin-bottom: var(--space-3);
}

.skeleton-card .skeleton:first-child {
  height: 1.5rem;
  width: 40%;
}

.skeleton-card .skeleton:nth-child(2) {
  height: 2.5rem;
  width: 70%;
}

.skeleton-card .skeleton:last-child {
  height: 0.875rem;
  width: 50%;
}

/* ===========================
   Reduced Motion (UI-18.1 — WCAG 2.2 / EAA)
   =========================== */
@media (prefers-reduced-motion: reduce) {
  /* Disable all decorative keyframe animations */
  .animate-pop,
  .animate-slide,
  .animate-correct,
  .animate-wrong,
  .heart-shake,
  .result-emoji,
  .result-score,
  .xp-gained,
  .streak-banner,
  .welcome-overlay,
  .welcome-box,
  .alert,
  .result-screen {
    animation: none !important;
  }

  /* Disable stagger delays on steps */
  .steps-list li {
    animation: none !important;
    animation-delay: 0ms !important;
    opacity: 1;
  }

  /* Remove transform transitions (slide, scale, shake) */
  *,
  *::before,
  *::after {
    transition-property: opacity, color, background, background-color, border-color, box-shadow !important;
    transition-duration: 0.15s !important;
  }

  /* Card/button hover: no translateY, keep shadow+border feedback */
  .card:hover,
  .bento-tile:hover,
  .glossary-card:hover,
  .module-card:hover,
  .level-card:hover,
  .btn-primary:hover:not(:disabled),
  .btn-green:hover:not(:disabled),
  .btn-blue:hover:not(:disabled),
  .btn-red:hover:not(:disabled),
  .btn-gold:hover:not(:disabled),
  .btn-ghost:hover:not(:disabled),
  .btn-secondary:hover:not(:disabled) {
    transform: none !important;
  }

  /* Flashcard: crossfade instead of rotateY */
  .flashcard-inner {
    transform-style: flat !important;
    transition: none !important;
  }

  .flashcard-face {
    backface-visibility: visible !important;
    -webkit-backface-visibility: visible !important;
    transition: opacity 0.2s ease !important;
  }

  .flashcard-face.front {
    opacity: 1;
  }

  .flashcard-face.back {
    transform: none !important;
    opacity: 0;
  }

  .flashcard-scene.flipped .flashcard-inner {
    transform: none !important;
  }

  .flashcard-scene.flipped .flashcard-face.front {
    opacity: 0;
  }

  .flashcard-scene.flipped .flashcard-face.back {
    opacity: 1;
  }

  /* No micro-scale on flashcard */
  .flashcard-scene:active .flashcard-inner,
  .flashcard-scene.flipped:active .flashcard-inner {
    transform: none !important;
  }

  /* Feedback banner: instant show */
  .feedback-banner {
    transition: none !important;
  }

  /* Skeleton pulse — keep, it's subtle and functional */

  /* Btn loading spinner — keep, it's functional feedback */
}
