/* ==========================================================================
   entrenador-velocidad-notas · styles.css?v=1
   CSS vanilla (no Tailwind CDN). Variables CSS + modo claro/oscuro.
   Paleta: violeta-cyan destacado, neutros suaves, contraste AA WCAG 2.1.
   Cache-bust: bump ?v=N al modificar.
   ========================================================================== */

/* Reset mínimo */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body, h1, h2, h3, p, ul, ol, li, figure, blockbox, dl, dd { margin: 0; }
body { min-height: 100vh; line-height: 1.55; -webkit-font-smoothing: antialiased; }
img, picture, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* Tokens (tema oscuro = default) */
:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev-2: #1f232c;
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.16);
  --fg: #e8eaed;
  --fg-muted: #9aa0a6;
  --fg-dim: #6c727a;
  --accent: #a78bfa;
  --accent-strong: #8b5cf6;
  --accent-soft: rgba(167,139,250,0.18);
  --success: #34d399;
  --warn: #fbbf24;
  --error: #f87171;
  --code-bg: #0b0d12;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.25);
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
  --container: 1100px;
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* Tema claro */
[data-theme="light"] {
  --bg: #fafafa;
  --bg-elev: #ffffff;
  --bg-elev-2: #f1f3f5;
  --border: rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.16);
  --fg: #1a1c20;
  --fg-muted: #5b6168;
  --fg-dim: #8a8f96;
  --accent: #6d28d9;
  --accent-strong: #5b21b6;
  --accent-soft: rgba(109,40,217,0.12);
  --code-bg: #1a1c20;
  --shadow: 0 4px 16px rgba(0,0,0,0.06);
}

/* Respeta prefers-color-scheme cuando data-theme="auto" */
@media (prefers-color-scheme: light) {
  [data-theme="auto"] {
    --bg: #fafafa;
    --bg-elev: #ffffff;
    --bg-elev-2: #f1f3f5;
    --border: rgba(0,0,0,0.08);
    --border-strong: rgba(0,0,0,0.16);
    --fg: #1a1c20;
    --fg-muted: #5b6168;
    --fg-dim: #8a8f96;
    --accent: #6d28d9;
    --accent-strong: #5b21b6;
    --accent-soft: rgba(109,40,217,0.12);
    --code-bg: #1a1c20;
    --shadow: 0 4px 16px rgba(0,0,0,0.06);
  }
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  transition: background var(--transition), color var(--transition);
  font-size: 16px;
}

/* Skip-link accesibilidad */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 0 0 var(--radius) 0;
  z-index: 100;
}
.skip-link:focus { left: 0; outline: 3px solid var(--accent); }

/* Visually hidden (accesibilidad) */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* Focus visible global */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Container */
.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ==========================================================================
   Header
   ========================================================================== */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.15rem;
}
.brand-mark { color: var(--accent); }
.brand-mark-sm { color: var(--fg); opacity: 0.7; }
.header-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.header-nav a {
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  color: var(--fg-muted);
  transition: background var(--transition), color var(--transition);
  font-size: 0.95rem;
}
.header-nav a:hover { background: var(--accent-soft); color: var(--fg); }

.lang-toggle, .theme-toggle {
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  background: var(--bg-elev-2);
  color: var(--fg);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background var(--transition);
  min-width: 44px;
  min-height: 36px;
}
.lang-toggle:hover, .theme-toggle:hover { background: var(--accent-soft); }

/* ==========================================================================
   Hero
   ========================================================================== */
.hero {
  padding: 3rem 0 2rem;
  text-align: center;
}
.hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
  line-height: 1.15;
}
.hero-lead {
  font-size: clamp(1rem, 2vw, 1.15rem);
  color: var(--fg-muted);
  max-width: 720px;
  margin: 0 auto 1.5rem;
  line-height: 1.6;
}
.cta {
  display: inline-block;
  padding: 0.85rem 1.5rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius);
  transition: background var(--transition), transform var(--transition);
}
.cta:hover { background: var(--accent-strong); transform: translateY(-1px); }

/* ==========================================================================
   Sections
   ========================================================================== */
section {
  padding: 2.5rem 0;
}
section h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  text-align: center;
}

/* ==========================================================================
   Level cards
   ========================================================================== */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}
.level-card {
  padding: 1.5rem;
  background: var(--bg-elev);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition), background var(--transition);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 130px;
}
.level-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.level-card[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.level-card .level-icon {
  font-size: 2rem;
  margin-bottom: 0.25rem;
}
.level-card .level-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--fg);
}
.level-card .level-desc {
  font-size: 0.9rem;
  color: var(--fg-muted);
  line-height: 1.4;
}
.level-card .level-wpm {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
  margin-top: 0.25rem;
}

/* ==========================================================================
   Exercises selector
   ========================================================================== */
.exercises-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  align-items: end;
}
.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1 1 220px;
}
.control-group label {
  font-size: 0.85rem;
  color: var(--fg-muted);
  font-weight: 500;
}
.control-group input, .control-group select {
  padding: 0.6rem 0.75rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-size: 0.95rem;
}
.control-group input:focus, .control-group select:focus {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.exercises-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}
.exercise-item {
  padding: 1rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  cursor: pointer;
  min-height: 90px;
}
.exercise-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.exercise-item .ex-title {
  font-weight: 600;
  color: var(--fg);
  font-size: 0.98rem;
  line-height: 1.3;
}
.exercise-item .ex-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--fg-muted);
}
.exercise-item .ex-meta .badge {
  background: var(--bg-elev-2);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-weight: 500;
}
.exercise-item .ex-meta .badge.principiante { color: #34d399; }
.exercise-item .ex-meta .badge.intermedio { color: #fbbf24; }
.exercise-item .ex-meta .badge.avanzado { color: #f87171; }
.exercises-empty {
  text-align: center;
  color: var(--fg-muted);
  padding: 2rem 1rem;
  grid-column: 1 / -1;
}

/* ==========================================================================
   Practice view
   ========================================================================== */
.practice-view {
  display: none;
}
.practice-view.active {
  display: block;
  animation: fadeIn 200ms ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.practice-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.practice-header h2 { margin: 0; text-align: left; font-size: 1.3rem; }
.practice-header .practice-meta {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
  color: var(--fg-muted);
}

.practice-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  align-items: center;
  padding: 1rem;
  background: var(--bg-elev);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.btn-primary {
  padding: 0.85rem 1.5rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius);
  transition: background var(--transition), transform var(--transition);
  font-size: 1rem;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn-primary:hover { background: var(--accent-strong); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  padding: 0.7rem 1.2rem;
  background: var(--bg-elev-2);
  color: var(--fg);
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition);
  font-size: 0.95rem;
  min-height: 44px;
}
.btn-secondary:hover { border-color: var(--accent); background: var(--accent-soft); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-danger {
  padding: 0.7rem 1.2rem;
  background: var(--error);
  color: #fff;
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  transition: opacity var(--transition);
  font-size: 0.95rem;
  min-height: 44px;
}
.btn-danger:hover { opacity: 0.85; }

.voice-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.voice-controls label {
  color: var(--fg-muted);
  font-weight: 500;
  margin-right: 0.25rem;
}
.voice-controls select, .voice-controls input[type="range"] {
  padding: 0.4rem 0.5rem;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font-size: 0.9rem;
}
.voice-controls input[type="range"] { padding: 0; min-width: 100px; }
.voice-unsupported-banner {
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.4);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  color: var(--fg);
}
.voice-unsupported-banner strong { color: var(--warn); display: block; margin-bottom: 0.4rem; font-size: 1rem; }
.voice-unsupported-banner p { font-size: 0.92rem; color: var(--fg-muted); line-height: 1.5; }

/* Reference text (collapsible) */
.reference-text {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  display: none;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--fg-muted);
}
.reference-text.visible { display: block; }
.reference-text-label {
  font-size: 0.85rem;
  color: var(--fg-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

/* Writing textarea */
.writing-area {
  width: 100%;
  min-height: 220px;
  padding: 1rem 1.25rem;
  background: var(--bg-elev);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 1.05rem;
  line-height: 1.6;
  font-family: var(--font-mono);
  resize: vertical;
  transition: border-color var(--transition);
}
.writing-area:focus {
  outline: none;
  border-color: var(--accent);
}

/* Metrics panel */
.metrics-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 1rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.metric {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.5rem;
  text-align: center;
}
.metric .metric-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
  font-weight: 600;
}
.metric .metric-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.metric.highlight .metric-value { color: var(--accent); }
.metric.good .metric-value { color: var(--success); }
.metric.warn .metric-value { color: var(--warn); }

.progress-bar {
  height: 6px;
  background: var(--bg-elev-2);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.75rem;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 200ms ease;
}

/* ==========================================================================
   Results modal (alertdialog)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal-backdrop.visible { display: flex; }
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal h2 { text-align: left; margin-bottom: 1rem; }
.modal .results-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.modal .result-row {
  padding: 0.75rem;
  background: var(--bg-elev-2);
  border-radius: 8px;
}
.modal .result-row .row-label {
  font-size: 0.8rem;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.modal .result-row .row-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.modal .result-row .row-sub {
  font-size: 0.85rem;
  color: var(--fg-dim);
  margin-top: 0.15rem;
}
.modal .rating {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0.5rem 0 1.5rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}
.modal .modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}
.modal .modal-actions button { flex: 1 1 130px; }
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--success);
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms, transform 200ms;
  z-index: 300;
  box-shadow: var(--shadow);
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   History
   ========================================================================== */
.history-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.history-stats {
  font-size: 0.95rem;
  color: var(--fg-muted);
}
.history-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--fg-muted);
  background: var(--bg-elev);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.history-table th, .history-table td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.history-table th {
  background: var(--bg-elev-2);
  font-weight: 600;
  color: var(--fg-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.history-table tr:last-child td { border-bottom: none; }
.history-table tr:hover { background: var(--bg-elev-2); }
.history-table td.numeric { font-variant-numeric: tabular-nums; text-align: right; }
.history-table .badge-mini {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-elev-2);
}
.history-table .badge-mini.principiante { color: #34d399; }
.history-table .badge-mini.intermedio { color: #fbbf24; }
.history-table .badge-mini.avanzado { color: #f87171; }

.history-graphs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1.5rem;
}
@media (max-width: 700px) {
  .history-graphs { grid-template-columns: 1fr; }
}
.history-graph {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.history-graph h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg-muted);
  margin-bottom: 0.75rem;
  text-align: center;
}
.history-graph canvas { width: 100%; height: 160px; display: block; }

/* ==========================================================================
   SEO long-copy section
   ========================================================================== */
.seo-copy {
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
}
.seo-copy-inner {
  max-width: 800px;
  margin: 0 auto;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--fg-muted);
}
.seo-copy-inner h2 { text-align: left; font-size: 1.3rem; margin-bottom: 1rem; color: var(--fg); }
.seo-copy-inner p { margin-bottom: 1rem; }
.seo-copy-inner strong { color: var(--fg); }

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 2rem 0;
  margin-top: 2rem;
}
.footer-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.footer-line { font-size: 0.9rem; color: var(--fg-muted); }
.footer-donation { color: var(--fg); }
.footer-meta a { color: var(--accent); text-decoration: underline; }
.footer-meta a:hover { color: var(--accent-strong); }

/* ==========================================================================
   Privacy inline
   ========================================================================== */
.privacy-inline {
  font-size: 0.85rem;
  color: var(--fg-muted);
  background: var(--accent-soft);
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  margin-top: 1rem;
  border-left: 3px solid var(--accent);
  line-height: 1.5;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 700px) {
  .container { padding: 0 1rem; }
  .hero { padding: 2rem 0 1.5rem; }
  .levels-grid { grid-template-columns: 1fr; }
  .exercises-list { grid-template-columns: 1fr; }
  .modal .results-summary { grid-template-columns: 1fr; }
  .practice-controls { flex-direction: column; align-items: stretch; }
  .practice-controls .btn-primary, .practice-controls .btn-secondary { width: 100%; justify-content: center; }
  .header-nav a { font-size: 0.85rem; }
  .header-nav a span { display: none; }
  .history-table { font-size: 0.8rem; }
  .history-table th, .history-table td { padding: 0.5rem 0.4rem; }
  section { padding: 1.75rem 0; }
}

@media (max-width: 480px) {
  .metric .metric-value { font-size: 1.3rem; }
  .metrics-panel { grid-template-columns: repeat(2, 1fr); }
}

/* Scrollbar discreto */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-elev-2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
