/* ====== RESET & VARIABLES ====== */
:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;

  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --hover: #f1f5f9;

  --sidebar-width: 280px;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.1);

  /* Fluid typography */
  --fs-base: clamp(0.95rem, 0.92rem + 0.15vw, 1rem);
  --fs-h1: clamp(1.5rem, 1.2rem + 1.5vw, 2.25rem);
  --fs-h2: clamp(1.3rem, 1.1rem + 0.9vw, 1.75rem);
  --fs-h3: clamp(1.1rem, 1rem + 0.4vw, 1.25rem);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 1rem;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: var(--fs-base);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ====== SIDEBAR ====== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.sidebar-header-text h1 {
  font-size: 1.4rem;
  color: var(--primary);
  margin-bottom: 0.2rem;
}

.sidebar-header-text .subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  font-size: 1.75rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.sidebar-close:hover { background: var(--hover); }

.nav { flex: 1; padding: 1rem 0.75rem; }
.nav-group { margin-bottom: 1.5rem; }

.nav-group h3 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 0.75rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 0.65rem 0.75rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.9rem;
  transition: all 0.15s;
  min-height: 44px;
}

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

.nav-link.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}

.nav-link.highlight {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  font-weight: 500;
}

.nav-link.highlight:hover { opacity: 0.9; color: white; }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.status-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot.ok { background: var(--success); }
.status-dot.error { background: var(--danger); }
.status-dot.pending { background: var(--warning); animation: pulse 1.5s infinite; }

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

/* ====== Backdrop ====== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s;
}

.sidebar-backdrop.show { display: block; opacity: 1; }

/* ====== Top bar móvil ====== */
.mobile-bar {
  display: none;
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  z-index: 50;
  align-items: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-sm);
}

.menu-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 44px;
  height: 44px;
  font-size: 1.4rem;
  cursor: pointer;
  flex-shrink: 0;
}

.mobile-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  flex: 1;
  text-align: center;
  margin-right: 44px;
}

/* ====== MAIN ====== */
.main {
  margin-left: var(--sidebar-width);
  padding: 2rem 3rem;
}

/* ====== HERO ====== */
.hero {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: white;
  padding: 2.5rem 2rem;
  border-radius: var(--radius);
  margin-bottom: 2rem;
  box-shadow: var(--shadow-lg);
}

.hero h1 { font-size: var(--fs-h1); margin-bottom: 0.5rem; line-height: 1.2; }

.hero-subtitle {
  font-size: clamp(0.95rem, 0.9rem + 0.3vw, 1.1rem);
  opacity: 0.95;
  margin-bottom: 1.75rem;
}

.hero-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 0.75rem;
}

.hero-card {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  padding: 1.1rem;
  color: white;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  transition: all 0.2s;
  min-height: 80px;
}

.hero-card:hover, .hero-card:active { background: rgba(255, 255, 255, 0.25); transform: translateY(-2px); }
.hero-card .emoji { font-size: 1.6rem; margin-bottom: 0.25rem; }
.hero-card strong { font-size: 0.95rem; }
.hero-card small { opacity: 0.85; font-size: 0.8rem; }

/* ====== SECTIONS ====== */
.section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: clamp(1.25rem, 1rem + 1vw, 2rem);
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  scroll-margin-top: 1rem;
}

.section.featured { border-color: var(--primary); border-width: 2px; }

.section h2 { font-size: var(--fs-h2); margin-bottom: 0.85rem; line-height: 1.25; }
.section h3 { font-size: var(--fs-h3); margin: 1.5rem 0 0.65rem; line-height: 1.3; }
.section h4 { font-size: 1rem; margin-bottom: 0.5rem; }
.section p { margin-bottom: 0.75rem; }
.section ul, .section ol { margin-left: 1.4rem; margin-bottom: 1rem; }
.section li { margin-bottom: 0.35rem; }

.lead {
  font-size: clamp(0.95rem, 0.9rem + 0.2vw, 1.05rem);
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

/* ====== INFO BOXES ====== */
.info-box {
  border-left: 4px solid;
  padding: 0.85rem 1rem;
  margin: 1rem 0;
  border-radius: 0 8px 8px 0;
}

.info-box h4 { margin-bottom: 0.4rem; font-size: 0.95rem; }
.info-box.tip { background: #eff6ff; border-color: var(--info); }
.info-box.warning { background: #fffbeb; border-color: var(--warning); }
.info-box.info { background: #f0f9ff; border-color: #0ea5e9; }

/* ====== TABLES ====== */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.verbs-table, .modal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.verbs-table th, .modal-table th {
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 0.7rem 0.6rem;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--primary);
  position: sticky;
  top: 0;
  z-index: 1;
}

.verbs-table td, .modal-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.verbs-table tr:hover, .modal-table tr:hover { background: var(--hover); }

/* ====== GRIDS ====== */
.pattern-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(480px, 100%), 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.tense-grid, .prep-grid, .connector-grid,
.collocation-grid, .mediation-grid, .writing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.pattern-card, .tense-card, .prep-card, .connector-card,
.collocation-card, .mediation-card, .writing-card, .conditional-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem;
}

.pattern-card h4, .tense-card h4, .prep-card h4,
.connector-card h4, .collocation-card h4, .mediation-card h4,
.writing-card h4 { color: var(--primary); margin-bottom: 0.5rem; }

.pattern-mnemonic, .markers, .usage {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
  font-style: italic;
}

.tense-card .example, .conditional-card .example {
  background: var(--primary-light);
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  margin: 0.5rem 0;
}

.conditional-card { margin-bottom: 0.85rem; }

.conditional-card .formula {
  background: var(--text);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 0.85rem;
  display: inline-block;
  margin: 0.5rem 0;
  word-break: break-word;
}

.conditional-card .alt { font-size: 0.9rem; color: var(--text-muted); margin-top: 0.5rem; }

.alt-list {
  background: var(--bg);
  padding: 0.85rem 0.85rem 0.85rem 2.25rem !important;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* ====== PHRASES ====== */
.phrases-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  gap: 0.85rem;
  margin: 1rem 0;
}

.phrase-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem;
}

.phrase-block h4 { color: var(--primary); font-size: 0.9rem; margin-bottom: 0.4rem; }
.phrase-block ul { list-style: none; margin: 0; font-size: 0.88rem; }
.phrase-block li { padding: 0.3rem 0; border-bottom: 1px dashed var(--border); }
.phrase-block li:last-child { border-bottom: none; }

.strategy-list {
  background: var(--primary-light);
  padding: 0.85rem 0.85rem 0.85rem 2.25rem !important;
  border-radius: 8px;
}

.strategy-list li { margin-bottom: 0.5rem; }

/* ====== BOXES ====== */
.example-box, .template-box {
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin: 0.85rem 0;
}

.source-text {
  background: #fef3c7;
  padding: 0.7rem;
  border-radius: 6px;
  border-left: 3px solid var(--warning);
  margin: 0.65rem 0;
  font-size: 0.88rem;
}

.model-answer {
  background: #ecfdf5;
  padding: 0.85rem;
  border-radius: 6px;
  border-left: 3px solid var(--success);
  font-size: 0.88rem;
  margin-top: 0.5rem;
  white-space: pre-line;
}

.template-box p { margin-bottom: 0.5rem; font-size: 0.88rem; }

/* ====== BUTTONS ====== */
.btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.7rem 1.2rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  min-height: 44px;
}

.btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--primary); }

.btn-practice {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: white;
  border: none;
  padding: 0.8rem 1.4rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  margin-top: 1rem;
  box-shadow: var(--shadow);
  transition: all 0.2s;
  width: 100%;
  min-height: 48px;
}

@media (min-width: 600px) { .btn-practice { width: auto; } }

.btn-practice:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.btn-practice.featured {
  background: linear-gradient(135deg, var(--accent), #d97706);
  font-size: 1rem;
  padding: 0.9rem 1.6rem;
}

/* ====== AI TRAINER ====== */
.ai-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 0.85rem;
  background: var(--bg);
  padding: 1.1rem;
  border-radius: var(--radius);
  margin: 1rem 0 1.25rem;
  border: 1px solid var(--border);
}

.control-group { display: flex; flex-direction: column; gap: 0.4rem; }
.control-group label { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); }
.provider-badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.9rem; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 0.9rem; font-weight: 600; color: var(--text);
}

select, input[type="text"], textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s;
  min-height: 44px;
}

select:focus, input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

textarea {
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
  line-height: 1.5;
}

.ai-mode { margin-top: 1rem; }

.ai-mode label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin: 0.75rem 0 0.4rem;
  color: var(--text);
}

.ai-mode.hidden { display: none; }

/* ====== INLINE PRACTICE PANEL ====== */
.inline-practice {
  margin-top: 1.5rem;
  border-top: 2px solid var(--primary-light);
  padding-top: 1.25rem;
  animation: slideDown 0.25s ease;
}

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

.inline-practice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.inline-practice-header h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--primary);
}

.inline-practice-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.inline-practice-controls select {
  min-height: 36px;
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  width: auto;
}

.btn-close-practice {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  min-height: 36px;
  font-family: inherit;
  transition: all 0.15s;
}

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

.btn-practice.active {
  background: linear-gradient(135deg, #059669, #10b981);
}

/* ====== EXERCISES & RESULTS ====== */
#exerciseContainer, #writingResult, #mediationResult, #modalContent { margin-top: 1.25rem; }

.exercise-item {
  background: var(--bg);
  padding: 0.9rem 1rem;
  border-radius: 10px;
  margin-bottom: 0.85rem;
  border: 1px solid var(--border);
}

.exercise-item .question { font-weight: 500; margin-bottom: 0.5rem; }
.exercise-item .hint { font-size: 0.85rem; color: var(--text-muted); font-style: italic; margin-bottom: 0.5rem; }
.exercise-item input { margin-bottom: 0.5rem; }

.exercise-item .feedback {
  margin-top: 0.65rem;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  font-size: 0.88rem;
}

.exercise-item .feedback.correct { background: #ecfdf5; border-left: 3px solid var(--success); }
.exercise-item .feedback.incorrect { background: #fef2f2; border-left: 3px solid var(--danger); }
.exercise-item .feedback strong { display: block; margin-bottom: 0.25rem; }
.exercise-item .tip-feedback { margin-top: 0.5rem; font-size: 0.85rem; color: var(--text-muted); font-style: italic; }

.score-badge {
  display: inline-block;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
}

.score-badge.high { background: #d1fae5; color: #065f46; }
.score-badge.mid  { background: #fef3c7; color: #92400e; }
.score-badge.low  { background: #fee2e2; color: #991b1b; }

.result-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1rem;
}

.result-card h4 { color: var(--primary); margin: 1rem 0 0.5rem; font-size: 1rem; }
.result-card h4:first-child { margin-top: 0; }

.error-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin: 0.5rem 0;
  font-size: 0.88rem;
}

.error-row .original { color: var(--danger); text-decoration: line-through; }
.error-row .corrected { color: var(--success); font-weight: 500; }
.error-row .explanation { color: var(--text-muted); font-style: italic; font-size: 0.83rem; margin-top: 0.25rem; }

.improved-text {
  background: #ecfdf5;
  padding: 0.9rem;
  border-radius: 8px;
  border-left: 3px solid var(--success);
  white-space: pre-wrap;
  line-height: 1.7;
}

/* ====== MODAL ====== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 700px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

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

/* ====== LOADING ====== */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.loader::before {
  content: '';
  width: 20px;
  height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-message {
  background: #fef2f2;
  color: var(--danger);
  padding: 0.85rem;
  border-radius: 8px;
  border-left: 3px solid var(--danger);
  margin: 0.85rem 0;
  font-size: 0.88rem;
}

/* ====== TOOLTIP / DICTIONARY ====== */
.en {
  cursor: help;
  border-bottom: 1px dotted rgba(79, 70, 229, 0.4);
  text-decoration: none;
  color: inherit;
  transition: background 0.15s;
  border-radius: 2px;
  padding: 0 1px;
}

.en:hover, .en.touched {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-bottom-color: var(--primary);
}

.tooltip {
  position: fixed;
  z-index: 9999;
  background: #1e293b;
  color: white;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  font-size: 0.85rem;
  max-width: min(320px, calc(100vw - 24px));
  min-width: 200px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.1);
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.15s, transform 0.15s;
}

.tooltip.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
.tooltip.touched { pointer-events: auto; }

.tooltip-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.tooltip-word { font-weight: 600; font-size: 1rem; color: #a5b4fc; }
.tooltip-phonetic { font-size: 0.8rem; color: #cbd5e1; font-family: 'SF Mono', Monaco, Consolas, monospace; }

.tooltip-translation {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.6rem;
  background: rgba(165, 180, 252, 0.15);
  border-radius: 6px;
  border-left: 3px solid #a5b4fc;
}

.tooltip-flag {
  font-size: 1rem;
  flex-shrink: 0;
}

.tooltip-translation-text {
  font-size: 0.95rem;
  color: white;
  font-weight: 500;
  line-height: 1.4;
}

.tooltip-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  font-weight: 600;
  margin: 0.5rem 0 0.4rem;
  padding-top: 0.5rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

.tooltip-section-label:first-child {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.tooltip-meaning { margin-bottom: 0.5rem; }
.tooltip-meaning:last-child { margin-bottom: 0; }

.tooltip-pos {
  display: inline-block;
  background: rgba(165, 180, 252, 0.2);
  color: #c7d2fe;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.03em;
  margin-bottom: 0.25rem;
}

.tooltip-definition { color: white; font-size: 0.85rem; }
.tooltip-example { color: #94a3b8; font-style: italic; font-size: 0.8rem; margin-top: 0.25rem; }
.tooltip-loading, .tooltip-empty { color: #cbd5e1; font-style: italic; text-align: center; font-size: 0.85rem; }

.tooltip-close {
  display: none;
  background: none;
  border: none;
  color: #cbd5e1;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

/* ====== FOOTER ====== */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ====== RESPONSIVE BREAKPOINTS ====== */

@media (max-width: 1024px) { .main { padding: 1.75rem 1.5rem; } }

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: min(300px, 85vw);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .mobile-bar { display: flex; }
  .main { margin-left: 0; padding: 1rem; }
  .hero { padding: 1.75rem 1.25rem; margin-bottom: 1.25rem; }
  .section { margin-bottom: 1rem; }

  .modal-content {
    padding: 1.25rem;
    max-height: 90vh;
    max-height: 90dvh;
  }

  .tooltip { max-width: calc(100vw - 24px); }
  .tooltip-close { display: block; }
}

@media (max-width: 480px) {
  .hero { padding: 1.5rem 1rem; }
  .section { padding: 1.1rem 0.9rem; }
  .info-box { padding: 0.75rem 0.85rem; }
  .ai-controls { padding: 0.85rem; }

  .pattern-card, .tense-card, .prep-card, .connector-card,
  .collocation-card, .mediation-card, .writing-card, .conditional-card {
    padding: 0.85rem;
  }
}

/* Touch devices */
@media (hover: none) {
  .nav-link:hover { background: transparent; color: var(--text); }
  .nav-link.active { background: var(--primary-light); color: var(--primary); }
  .en:hover { background: transparent; color: inherit; }
  .en.touched { background: var(--primary-light); color: var(--primary-dark); }
}

/* Print */
@media print {
  .sidebar, .mobile-bar, .btn-practice, .footer, .menu-toggle, .tooltip { display: none; }
  .main { margin-left: 0; padding: 1rem; max-width: 100%; }
  .section { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
  .en { border-bottom: none; }
}

/* ====== AUTH ====== */
.auth-panel {
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.auth-panel.hidden { display: none; }

.auth-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.auth-avatar {
  font-size: 1.5rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.auth-email {
  font-size: 0.8rem;
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  width: 100%;
  font-family: inherit;
  transition: all 0.15s;
  min-height: 36px;
}

.btn-logout:hover { background: #fef2f2; color: var(--danger); border-color: var(--danger); }

.auth-login-prompt { padding: 0.5rem 0; border-top: 1px solid var(--border); margin-bottom: 0.75rem; }
.btn-login { width: 100%; margin-bottom: 0.25rem; }
.auth-hint { font-size: 0.75rem; color: var(--text-muted); text-align: center; }

/* ====== LOGIN MODAL ====== */
.login-modal-inner {
  text-align: center;
  padding: 1rem 0;
}

.login-modal-inner h2 { margin-bottom: 0.25rem; }
.login-modal-inner .lead { margin-bottom: 1.5rem; }

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 360px;
  margin: 0 auto;
}

.login-form input[type="email"] {
  font-size: 1rem;
  text-align: center;
}

.btn-send-otp {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: white;
  border: none;
  padding: 0.85rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  min-height: 48px;
  transition: all 0.2s;
}

.btn-send-otp:hover { transform: translateY(-1px); opacity: 0.95; }
.btn-send-otp:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.login-success-msg {
  background: #ecfdf5;
  border: 1px solid var(--success);
  border-radius: 10px;
  padding: 1.25rem;
  color: #065f46;
}

.login-success-msg h3 { margin-bottom: 0.5rem; }

/* ====== PROGRESS DASHBOARD ====== */
.progress-login-prompt { text-align: center; padding: 2rem; }

.progress-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.progress-module-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.progress-module-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.progress-module-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.progress-module-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.trend-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
}

.trend-improving { background: #d1fae5; color: #065f46; }
.trend-declining { background: #fee2e2; color: #991b1b; }
.trend-stable    { background: #fef3c7; color: #92400e; }
.trend-new       { background: #e0e7ff; color: #3730a3; }

.progress-bar-wrap {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  margin: 0.5rem 0;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--primary), #7c3aed);
  transition: width 0.6s ease;
}

.progress-bar-fill.good { background: linear-gradient(90deg, #10b981, #059669); }
.progress-bar-fill.mid  { background: linear-gradient(90deg, #f59e0b, #d97706); }
.progress-bar-fill.low  { background: linear-gradient(90deg, #ef4444, #dc2626); }

.progress-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

/* Timeline chart */
.timeline-section { margin-top: 1.5rem; }

.timeline-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 80px;
  padding: 0.5rem 0;
  overflow-x: auto;
}

.timeline-bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  width: 28px;
}

.timeline-bar {
  width: 20px;
  border-radius: 4px 4px 0 0;
  background: var(--primary);
  min-height: 4px;
  transition: height 0.4s;
  cursor: pointer;
  position: relative;
}

.timeline-bar:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: white;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 100;
}

.timeline-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 28px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Weak areas panel */
.weak-areas-panel {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 10px;
  padding: 1rem;
  margin-top: 1rem;
}

.weak-areas-panel h4 {
  color: #9a3412;
  margin-bottom: 0.5rem;
}

.weak-area-tag {
  display: inline-block;
  background: #fed7aa;
  color: #9a3412;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  margin: 0.2rem;
  font-weight: 500;
}

/* Advice panel (inside inline practice) */
.advice-panel {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 1.1rem;
  margin-top: 1rem;
  animation: slideDown 0.2s ease;
}

.advice-panel h4 { color: #1e40af; margin-bottom: 0.5rem; }

.advice-example {
  background: white;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  margin: 0.4rem 0;
  font-size: 0.88rem;
}

.advice-example .wrong { color: var(--danger); text-decoration: line-through; }
.advice-example .correct { color: var(--success); font-weight: 500; }

/* Session summary */
.session-summary {
  background: var(--bg);
  border: 2px solid var(--primary-light);
  border-radius: 10px;
  padding: 1.1rem;
  margin-top: 1rem;
  text-align: center;
}

.session-score-big {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
  margin: 0.5rem 0;
}

.session-score-big.high { color: var(--success); }
.session-score-big.mid  { color: var(--warning); }
.session-score-big.low  { color: var(--danger); }

/* ── Auth Gate ─────────────────────────────────────────────── */
.auth-gate {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 40%, #4c1d95 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 1rem;
}

.auth-gate.hidden { display: none; }
.app-shell-hidden { display: none; }
.app-shell-visible { display: contents; }

.auth-gate-card {
  background: rgba(255,255,255,0.97);
  border-radius: 24px;
  padding: 3rem 2.5rem 2rem;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 32px 64px rgba(0,0,0,0.35), 0 0 0 1px rgba(255,255,255,0.1);
  position: relative;
  overflow: hidden;
}

.auth-gate-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, #4f46e5, #7c3aed, #ec4899);
}

.auth-gate-logo {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin: 0 auto 1.25rem;
  box-shadow: 0 8px 24px rgba(79,70,229,0.35);
}

.auth-gate-card h1 {
  color: #1e293b;
  font-size: 1.75rem;
  margin: 0 0 0.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-gate-subtitle {
  color: #64748b;
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
}

.auth-gate-tagline {
  color: #4f46e5;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 2rem;
}

.auth-step { transition: all 0.2s; }
.auth-step.hidden { display: none; }

.auth-gate-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 0.5rem;
  text-align: left;
}

.auth-gate-card input[type="email"],
.auth-gate-card input[type="text"] {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  margin-bottom: 0.75rem;
  background: #f8fafc;
  color: #1e293b;
}

.auth-gate-card input:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
  background: white;
}

.otp-input {
  font-size: 2rem !important;
  font-weight: 700 !important;
  letter-spacing: 0.3em !important;
  text-align: center !important;
  font-family: 'SF Mono', Monaco, Consolas, monospace !important;
  padding: 1rem !important;
  color: #4f46e5 !important;
}

.btn-send-otp {
  width: 100%;
  padding: 0.9rem;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  min-height: 52px;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(79,70,229,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-send-otp:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(79,70,229,0.4); }
.btn-send-otp:active { transform: translateY(0); }
.btn-send-otp:disabled { opacity: 0.65; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-back-link {
  background: none;
  border: none;
  color: #64748b;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  margin-top: 0.75rem;
  text-decoration: underline;
  display: block;
  width: 100%;
}

.btn-back-link:hover { color: #4f46e5; }

.auth-email-display {
  background: #f1f5f9;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  color: #1e293b;
  font-weight: 500;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.auth-gate-msg {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  min-height: 1.5rem;
}

.auth-gate-msg.error   { color: #dc2626; }
.auth-gate-msg.success { color: #059669; }

.auth-gate-features {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #f1f5f9;
}

.auth-feature {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.auth-feature-icon { font-size: 1.25rem; }

.auth-feature-label {
  font-size: 0.7rem;
  color: #94a3b8;
  font-weight: 500;
}

.auth-gate-legal {
  font-size: 0.72rem;
  color: #cbd5e1;
  margin-top: 1rem;
}

.auth-gate-bg-circles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.auth-gate-bg-circles::before,
.auth-gate-bg-circles::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.04);
}

.auth-gate-bg-circles::before {
  width: 400px; height: 400px;
  top: -100px; right: -100px;
}

.auth-gate-bg-circles::after {
  width: 300px; height: 300px;
  bottom: -80px; left: -80px;
}

@media (max-width: 480px) {
  .auth-gate-card { padding: 2.5rem 1.5rem 1.5rem; border-radius: 20px; }
  .auth-gate-card h1 { font-size: 1.5rem; }
  .auth-gate-features { gap: 1rem; }
}

/* ====== AI USAGE WIDGET (plan básico) ====== */
.ai-usage-widget {
  position: fixed;
  top: 0.75rem;
  right: 1rem;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.85rem 0.3rem 0.6rem;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.ai-usage-widget.limit-reached {
  border-color: #fca5a5;
  background: #fef2f2;
  color: #991b1b;
}
.ai-usage-pips { display: flex; gap: 3px; }
.ai-usage-pip {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--border);
  transition: background 0.2s;
}
.ai-usage-pip.used { background: var(--primary); }
.ai-usage-pip.used.limit-reached { background: #ef4444; }
.ai-usage-reset {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 0.25rem;
}
/* En móvil va dentro de la mobile-bar */
@media (max-width: 900px) {
  .ai-usage-widget { display: none !important; }
  .ai-usage-badge {
    font-size: 0.75rem; font-weight: 600;
    display: flex; align-items: center; gap: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.2rem 0.6rem;
    margin-left: auto;
  }
}
@media (min-width: 901px) {
  .ai-usage-badge { display: none !important; }
}

/* ====== PLAN LOCK OVERLAY ====== */
.plan-lock-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(6px);
  border-radius: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.plan-lock-box {
  text-align: center;
  padding: 2rem 1.5rem;
}
.plan-lock-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.plan-lock-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.4rem;
}
.plan-lock-sub {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 0 0 1.2rem;
  line-height: 1.5;
}
.plan-lock-btn {
  display: inline-block;
  background: var(--primary);
  color: white;
  padding: 0.55rem 1.25rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: background 0.15s;
}
.plan-lock-btn:hover { background: var(--primary-dark); }
.nav-locked { opacity: 0.45; pointer-events: none; }
.nav-locked::after { content: ' 🔒'; font-size: 0.7rem; }

/* ====== TOAST NOTIFICATIONS ====== */
#toast-center,
#toast-bl {
  position: fixed;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  pointer-events: none;
}
#toast-center {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  align-items: center;
}
#toast-bl {
  bottom: 1.5rem;
  left: 1.5rem;
  align-items: flex-start;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  font-size: 0.92rem;
  font-weight: 500;
  max-width: 360px;
  animation: toastIn 0.25s ease;
  backdrop-filter: blur(8px);
}
.toast.removing { animation: toastOut 0.2s ease forwards; }
.toast-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }
.toast-success { background: #f0fdf4; color: #166534; border: 1px solid #86efac; }
.toast-info    { background: #eff6ff; color: #1e40af; border: 1px solid #93c5fd; }
.toast-warn    { background: #fffbeb; color: #92400e; border: 1px solid #fcd34d; }
.toast-icon    { font-size: 1.1rem; flex-shrink: 0; }
.toast-close {
  margin-left: auto; background: none; border: none;
  cursor: pointer; opacity: 0.5; font-size: 1rem; padding: 0 0 0 0.5rem;
  color: inherit; line-height: 1;
}
.toast-close:hover { opacity: 1; }
@keyframes toastIn  { from { opacity:0; transform: translateY(8px) scale(0.97); } to { opacity:1; transform: none; } }
@keyframes toastOut { to   { opacity:0; transform: translateY(-6px) scale(0.96); } }
