/* =========================================================
   VARIABLES & THEMES (Light, Dark, System)
   ========================================================= */

:root {
  --font-main: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Default Light Mode Variables */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-secondary: #f1f5f9;
  --bg-input: #ffffff;
  --border: #e2e8f0;
  --border-focus: #6366f1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-text: #ffffff;

  /* SRS Rating Button Colors */
  --srs-again: #ef4444;
  --srs-again-bg: #fef2f2;
  --srs-hard: #f59e0b;
  --srs-hard-bg: #fffbeb;
  --srs-good: #10b981;
  --srs-good-bg: #ecfdf5;
  --srs-easy: #0ea5e9;
  --srs-easy-bg: #f0f9ff;

  /* CEFR Level Accents */
  --cefr-a1: #10b981;
  --cefr-a2: #06b6d4;
  --cefr-b1: #3b82f6;
  --cefr-b2: #8b5cf6;
  --cefr-c1: #ec4899;
  --cefr-c2: #f43f5e;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

/* Explicit Dark Theme */
body.theme-dark {
  --bg-app: #0b0f19;
  --bg-card: #131b2e;
  --bg-card-secondary: #1e293b;
  --bg-input: #1e293b;
  --border: #2e384d;
  --border-focus: #818cf8;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #1e1b4b;
  --primary-text: #ffffff;

  --srs-again-bg: #3f1717;
  --srs-hard-bg: #382405;
  --srs-good-bg: #063726;
  --srs-easy-bg: #072a3e;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 8px -1px rgb(0 0 0 / 0.6);
  --shadow-lg: 0 12px 24px -4px rgb(0 0 0 / 0.7);
}

/* System Theme (when user chooses follow system) */
@media (prefers-color-scheme: dark) {
  body.theme-system {
    --bg-app: #0b0f19;
    --bg-card: #131b2e;
    --bg-card-secondary: #1e293b;
    --bg-input: #1e293b;
    --border: #2e384d;
    --border-focus: #818cf8;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;

    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #1e1b4b;
    --primary-text: #ffffff;

    --srs-again-bg: #3f1717;
    --srs-hard-bg: #382405;
    --srs-good-bg: #063726;
    --srs-easy-bg: #072a3e;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
    --shadow-md: 0 4px 8px -1px rgb(0 0 0 / 0.6);
    --shadow-lg: 0 12px 24px -4px rgb(0 0 0 / 0.7);
  }
}

/* =========================================================
   BASE STYLES
   ========================================================= */

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

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.25s ease, color 0.25s ease;
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
}

button {
  font-family: var(--font-main);
  cursor: pointer;
  border: none;
  outline: none;
  transition: all 0.2s ease;
}

input, select, textarea {
  font-family: var(--font-main);
  background-color: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.95rem;
  transition: border-color 0.2s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  outline: 2px solid var(--primary-light);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hidden {
  display: none !important;
}

/* =========================================================
   HEADER & NAVIGATION
   ========================================================= */

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: block;
}

.brand-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
  background-color: var(--bg-card-secondary);
  padding: 4px;
  border-radius: var(--radius-md);
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
}

.nav-btn:hover {
  color: var(--text-main);
}

.nav-btn.active {
  background-color: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

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

.level-selector-wrapper select {
  font-weight: 600;
  border-radius: var(--radius-md);
  padding: 8px 14px;
  cursor: pointer;
}

/* Theme Dropdown */
.theme-dropdown-container {
  position: relative;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background-color: var(--bg-card-secondary);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.icon-btn:hover {
  background-color: var(--border);
}

.theme-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  width: 140px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 100;
}

.theme-menu button {
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 500;
}

.theme-menu button:hover {
  background-color: var(--bg-card-secondary);
}

/* =========================================================
   BUTTONS
   ========================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 0.9rem;
  transition: transform 0.1s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--primary);
  color: var(--primary-text);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

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

.btn-outline:hover {
  background-color: var(--bg-card-secondary);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-xl {
  padding: 16px 32px;
  font-size: 1.15rem;
  border-radius: var(--radius-lg);
}

/* =========================================================
   MAIN VIEW CONTAINER
   ========================================================= */

.main-content {
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  padding: 30px 20px 60px;
  flex: 1;
}

.view-section {
  animation: fadeIn 0.3s ease;
}

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

/* =========================================================
   STUDY SECTION (SRS FLASHCARD)
   ========================================================= */

.study-session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 12px;
}

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

.session-badge {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  background-color: var(--primary-light);
  color: var(--primary);
}

.session-progress-counts {
  display: flex;
  gap: 8px;
}

.count-badge {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
}

.count-due {
  background-color: #fee2e2;
  color: #dc2626;
}

.count-new {
  background-color: #e0f2fe;
  color: #0284c7;
}

.count-learned {
  background-color: #dcfce7;
  color: #16a34a;
}

.session-progress-bar-container {
  width: 100%;
  height: 6px;
  background-color: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 28px;
}

.session-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

/* Flashcard Container */
.flashcard-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.flashcard {
  width: 100%;
  max-width: 720px;
  min-height: 380px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
}

.tag-level {
  font-weight: 800;
  font-size: 0.8rem;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  color: white;
  background-color: var(--primary);
}

.tag-category {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background-color: var(--bg-card-secondary);
  color: var(--text-muted);
}

.tag-type {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text-dim);
  text-transform: uppercase;
}

.card-question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-question-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0;
}

.btn-speak {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background-color: var(--bg-card-secondary);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-speak:hover {
  color: var(--primary);
  border-color: var(--primary);
  background-color: var(--primary-light);
  transform: translateY(-1px);
}

.btn-speak-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  margin-left: 6px;
  vertical-align: middle;
  transition: all 0.15s ease;
}

.btn-speak-mini:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.card-prompt {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
  line-height: 1.25;
}

.divider {
  height: 1px;
  background-color: var(--border);
  margin: 28px 0;
}

/* =========================================================
   MULTIPLE CHOICE OPTIONS GRID
   ========================================================= */

.multiple-choice-container {
  margin-top: 24px;
  width: 100%;
}

.choice-instruction {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.choice-options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 600px) {
  .choice-options-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.choice-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  background-color: var(--bg-card-secondary);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  transition: all 0.15s ease;
  cursor: pointer;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background-color: var(--primary-light);
  color: var(--primary);
  transform: translateY(-1px);
}

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

.choice-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-app);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.choice-text {
  flex: 1;
}

.choice-btn.correct {
  background-color: #ecfdf5 !important;
  border-color: #10b981 !important;
  color: #065f46 !important;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

body.theme-dark .choice-btn.correct {
  background-color: #063726 !important;
  color: #6ee7b7 !important;
}

@media (prefers-color-scheme: dark) {
  body.theme-system .choice-btn.correct {
    background-color: #063726 !important;
    color: #6ee7b7 !important;
  }
}

.choice-btn.correct .choice-letter {
  background-color: #10b981;
  color: white;
  border-color: #10b981;
}

.choice-btn.wrong {
  background-color: #fef2f2 !important;
  border-color: #ef4444 !important;
  color: #991b1b !important;
}

body.theme-dark .choice-btn.wrong {
  background-color: #3f1717 !important;
  color: #fca5a5 !important;
}

@media (prefers-color-scheme: dark) {
  body.theme-system .choice-btn.wrong {
    background-color: #3f1717 !important;
    color: #fca5a5 !important;
  }
}

.choice-btn.wrong .choice-letter {
  background-color: #ef4444;
  color: white;
  border-color: #ef4444;
}

.card-back {
  animation: fadeIn 0.25s ease;
}

.answer-section.compact-result {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.result-pill {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background-color: var(--primary-light);
  color: var(--primary);
}

.result-pill.correct {
  background-color: #ecfdf5;
  color: #047857;
}

body.theme-dark .result-pill.correct {
  background-color: #063726;
  color: #6ee7b7;
}

.result-pill.wrong {
  background-color: #fef2f2;
  color: #b91c1c;
}

body.theme-dark .result-pill.wrong {
  background-color: #3f1717;
  color: #fca5a5;
}

.card-answer-text {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.context-box {
  background-color: var(--bg-card-secondary);
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 12px 16px;
  margin-bottom: 12px;
}

.context-english {
  font-size: 1.05rem;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--text-main);
}

.context-portuguese {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-top: 6px;
  padding-left: 28px;
  font-style: italic;
}

.explanation-box {
  background-color: var(--bg-app);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  border: 1px dashed var(--border);
  font-size: 0.92rem;
  color: var(--text-muted);
}

.explanation-box strong {
  color: var(--text-main);
  display: block;
  margin-bottom: 4px;
}

/* Flashcard Controls (Reveal & Ratings) */
.flashcard-controls {
  width: 100%;
  max-width: 720px;
}

.controls-panel {
  display: flex;
  justify-content: center;
  gap: 14px;
  width: 100%;
}

.btn-reveal {
  width: 100%;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: white;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.btn-reveal:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.45);
}

.btn-rating {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 10px;
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  gap: 4px;
}

.rating-name {
  font-size: 0.95rem;
  font-weight: 700;
}

.rating-interval {
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0.85;
}

kbd {
  font-family: var(--font-mono);
  background-color: rgba(0, 0, 0, 0.12);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.72rem;
  font-weight: 600;
}

.theme-dark kbd,
@media (prefers-color-scheme: dark) {
  body.theme-system kbd {
    background-color: rgba(255, 255, 255, 0.15);
  }
}

.btn-again {
  background-color: var(--srs-again-bg);
  border-color: var(--srs-again);
  color: var(--srs-again);
}

.btn-again:hover {
  background-color: var(--srs-again);
  color: white;
}

.btn-hard {
  background-color: var(--srs-hard-bg);
  border-color: var(--srs-hard);
  color: var(--srs-hard);
}

.btn-hard:hover {
  background-color: var(--srs-hard);
  color: white;
}

.btn-good {
  background-color: var(--srs-good-bg);
  border-color: var(--srs-good);
  color: var(--srs-good);
}

.btn-good:hover {
  background-color: var(--srs-good);
  color: white;
}

.btn-easy {
  background-color: var(--srs-easy-bg);
  border-color: var(--srs-easy);
  color: var(--srs-easy);
}

.btn-easy:hover {
  background-color: var(--srs-easy);
  color: white;
}

.btn-rating.recommended {
  box-shadow: 0 0 0 3px var(--primary), 0 4px 12px rgba(99, 102, 241, 0.4);
  transform: translateY(-2px);
  position: relative;
}

.btn-rating.recommended::after {
  content: 'Sugerido';
  position: absolute;
  top: -8px;
  right: 6px;
  background-color: var(--primary);
  color: white;
  font-size: 0.62rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.srs-auto-hint {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 10px;
}

.srs-auto-hint kbd {
  margin: 0 2px;
}

/* Session Finished State */
.session-finished {
  text-align: center;
  padding: 60px 20px;
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 600px;
}

.trophy-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
}

.session-finished h2 {
  font-size: 1.6rem;
  margin-bottom: 8px;
}

.session-finished p {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.finished-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

/* =========================================================
   QUESTIONS EXPLORER & MANAGEMENT SECTION
   ========================================================= */

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
}

.section-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

.header-action-buttons {
  display: flex;
  gap: 10px;
}

.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.filter-bar input {
  flex: 1;
  min-width: 240px;
}

.total-counter {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
}

.questions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.question-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.question-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.q-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.q-prompt {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 6px 0;
}

.q-answer {
  font-size: 0.95rem;
  color: var(--primary);
  font-weight: 600;
}

.q-context {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  border-left: 2px solid var(--border);
  padding-left: 8px;
}

.q-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 4px;
}

.btn-del {
  background: transparent;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.btn-del:hover {
  background-color: #fee2e2;
  color: #dc2626;
}

/* =========================================================
   STATISTICS & PROGRESS SECTION
   ========================================================= */

.stats-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.metric-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.metric-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.metric-purple { background-color: #f3e8ff; color: #9333ea; }
.metric-green { background-color: #dcfce7; color: #16a34a; }
.metric-blue { background-color: #e0f2fe; color: #0284c7; }
.metric-amber { background-color: #fef3c7; color: #d97706; }

.metric-value {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.metric-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.card-panel {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.panel-title {
  font-size: 1.15rem;
  margin-bottom: 20px;
}

.cefr-progress-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.cefr-level-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cefr-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cefr-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.95rem;
}

.cefr-badge {
  color: white;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
}

.cefr-counts {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.cefr-bar-bg {
  width: 100%;
  height: 10px;
  background-color: var(--bg-card-secondary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.cefr-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.5s ease;
}

/* =========================================================
   MODALS
   ========================================================= */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-box {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  padding: 28px;
}

.modal-lg {
  max-width: 650px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
}

.close-btn {
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  padding: 4px;
}

.close-btn:hover {
  color: var(--text-main);
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--primary);
  border-color: var(--primary);
}

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

.form-group label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-row {
  display: flex;
  gap: 12px;
}

.col-6 {
  flex: 1;
}

.alert-error {
  background-color: #fee2e2;
  border: 1px solid #f87171;
  color: #b91c1c;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 16px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.import-help {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

#import-json-textarea {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: var(--text-main);
  color: var(--bg-card);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.92rem;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  animation: slideUp 0.25s ease;
}

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

/* =========================================================
   MOBILE BOTTOM NAVIGATION (Hidden on Desktop)
   ========================================================= */

.mobile-bottom-nav {
  display: none;
}

/* =========================================================
   RESPONSIVE DESIGN (TABLETS & SMARTPHONES)
   ========================================================= */

@media (max-width: 768px) {
  /* Header Mobile Layout */
  .app-header {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .header-container {
    padding: 8px 10px;
    gap: 6px;
    width: 100%;
    max-width: 100%;
  }

  .nav-links {
    display: none !important; /* Managed by mobile-bottom-nav */
  }

  .brand {
    gap: 6px;
    min-width: 0;
    flex-shrink: 1;
    overflow: hidden;
  }

  .brand-tag {
    display: none;
  }

  .brand-title {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-icon {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
  }

  .header-actions {
    gap: 4px;
    flex-shrink: 0;
  }

  .level-selector-wrapper select {
    padding: 5px 6px;
    font-size: 0.76rem;
    max-width: 76px;
    text-overflow: ellipsis;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
  }

  #user-nav-area {
    flex-shrink: 0;
  }

  #user-nav-area .btn {
    padding: 5px 8px;
    font-size: 0.76rem;
    white-space: nowrap;
  }

  #user-nav-area span {
    font-size: 0.75rem;
    max-width: 65px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Main Content Area */
  .main-content {
    padding: 16px 12px 95px; /* Ample bottom room for bottom nav */
  }

  /* Study Section */
  .study-session-header {
    margin-bottom: 10px;
    gap: 8px;
  }

  .session-badge {
    font-size: 0.75rem;
    padding: 3px 8px;
  }

  .session-info h2 {
    font-size: 1.15rem;
  }

  .session-progress-counts {
    gap: 4px;
    flex-wrap: wrap;
  }

  .count-badge {
    font-size: 0.72rem;
    padding: 2px 7px;
  }

  /* Flashcard / Quiz Arena */
  .flashcard {
    padding: 20px 16px;
    min-height: auto;
    border-radius: var(--radius-md);
  }

  .card-meta {
    margin-bottom: 16px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .tag-level, .tag-category, .tag-type {
    font-size: 0.72rem;
  }

  .card-question-label {
    font-size: 0.75rem;
    margin-bottom: 6px;
  }

  .card-prompt {
    font-size: clamp(1.2rem, 5vw, 1.7rem);
    line-height: 1.35;
  }

  .choice-options-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .choice-btn {
    padding: 12px 14px;
    font-size: 0.92rem;
    min-height: 48px;
    border-radius: var(--radius-sm);
  }

  .choice-letter {
    width: 26px;
    height: 26px;
    font-size: 0.78rem;
  }

  .divider {
    margin: 18px 0;
  }

  .card-answer {
    font-size: 1.25rem;
  }

  .context-box {
    padding: 10px 12px;
    margin-bottom: 12px;
  }

  .context-english {
    font-size: 0.9rem;
  }

  .context-portuguese {
    font-size: 0.82rem;
    padding-left: 20px;
  }

  .explanation-box {
    padding: 10px 12px;
    font-size: 0.84rem;
  }

  /* Flashcard Action Buttons (Mobile 2x2 Grid) */
  #rating-buttons-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  .btn-rating {
    min-width: 0;
    padding: 10px 8px;
    border-radius: var(--radius-sm);
  }

  .rating-name {
    font-size: 0.88rem;
  }

  .rating-interval {
    font-size: 0.75rem;
  }

  .btn-reveal {
    padding: 12px 16px;
    font-size: 0.95rem;
  }

  /* Questions Explorer on Mobile */
  .section-header-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .header-action-buttons {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .header-action-buttons .btn {
    flex: 1;
    font-size: 0.85rem;
    padding: 8px 10px;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .filter-bar input,
  .filter-bar select {
    width: 100%;
    font-size: 16px; /* Prevents auto-zoom in mobile safari */
  }

  .questions-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Stats Dashboard on Mobile */
  .stats-overview-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 18px;
  }

  .metric-card {
    padding: 14px 12px;
    gap: 10px;
  }

  .metric-icon {
    width: 38px;
    height: 38px;
    font-size: 1.15rem;
  }

  .metric-value {
    font-size: 1.25rem;
  }

  .metric-label {
    font-size: 0.72rem;
  }

  .card-panel {
    padding: 16px 14px;
  }

  /* Modals on Mobile */
  .modal-backdrop {
    padding: 10px;
    align-items: flex-end; /* Mobile bottom sheet style on tiny screens or centered */
  }

  .modal-box {
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px 16px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .form-row {
    flex-direction: column;
    gap: 8px;
  }

  input, select, textarea {
    font-size: 16px; /* Crucial for iOS: prevents screen zooming when typing */
  }

  /* Mobile Bottom Navigation Bar */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background-color: var(--bg-card);
    border-top: 1px solid var(--border);
    align-items: center;
    justify-content: space-around;
    z-index: 99;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
  }

  .mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    flex: 1;
    height: 100%;
  }

  .mobile-nav-btn svg {
    transition: transform 0.15s ease, color 0.15s ease;
  }

  .mobile-nav-btn.active {
    color: var(--primary);
  }

  .mobile-nav-btn.active svg {
    transform: translateY(-1px);
    stroke: var(--primary);
  }

  /* Toast position on mobile (positioned at the top to avoid covering action buttons) */
  .toast {
    bottom: auto;
    top: calc(56px + 12px);
    right: 14px;
    left: 14px;
    text-align: center;
  }
}

/* Extra small devices (<= 380px) */
@media (max-width: 380px) {
  .header-container {
    padding: 6px 8px;
    gap: 4px;
  }
  .brand {
    gap: 4px;
  }
  .brand-icon {
    width: 26px;
    height: 26px;
  }
  .brand-title {
    font-size: 0.88rem;
  }
  .header-actions {
    gap: 3px;
  }
  .level-selector-wrapper select {
    max-width: 62px;
    font-size: 0.72rem;
    padding: 4px 4px;
  }
  .icon-btn {
    width: 28px;
    height: 28px;
  }
  #user-nav-area .btn {
    padding: 4px 6px;
    font-size: 0.72rem;
  }
  #user-nav-area span {
    max-width: 50px;
    font-size: 0.7rem;
  }
  .card-prompt {
    font-size: 1.15rem;
  }
  .mobile-nav-btn {
    padding: 4px 6px;
    font-size: 0.68rem;
  }
}

