/* Estudio de lectura asistida para dislexia, TDAH y fatiga visual */
:root,
[data-theme="dark"] {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg-page: #0b0f17;
  --bg-surface: #131b2e;
  --bg-surface-2: #192338;
  --bg-input: #0f1626;
  --border-color: #26334d;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --ok: #10b981;
  --ok-soft: rgba(16, 185, 129, 0.14);
  --shadow-card: 0 12px 32px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg-page: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-surface-2: #f8fafc;
  --bg-input: #ffffff;
  --border-color: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #475569;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --accent-soft: rgba(2, 132, 199, 0.1);
  --ok: #059669;
  --ok-soft: rgba(5, 150, 105, 0.1);
  --shadow-card: 0 8px 24px rgba(15, 23, 42, 0.08);
  color-scheme: light;
}

[data-theme="dark"] .app-header { background: #131b2e !important; border-bottom: 1px solid #1e293b !important; }
[data-theme="dark"] .brand-title { color: #f8fafc !important; }
[data-theme="light"] .app-header { background: #ffffff !important; border-bottom: 1px solid #cbd5e1 !important; }
[data-theme="light"] .brand-title { color: #0f172a !important; }

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

body {
  font-family: var(--font-main);
  background: var(--bg-page);
  color: var(--text-main);
  margin: 0;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6, .brand-title, .section-title, .hero-title { font-family: var(--font-heading); }
.mono, code { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.tool-layout { max-width: 1200px; width: 100%; margin: 1.5rem auto 3rem; padding: 0 1rem; flex: 1 0 auto; }
.tool-with-sidebar { display: flex; gap: 2rem; align-items: flex-start; width: 100%; }
.tool-main-content { flex: 1 1 0%; min-width: 0; width: 100%; }

.card-main {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.35rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 1.35rem;
}

.section-head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.badge-pill {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  margin-bottom: 0.5rem;
}
.hero-title { margin: 0 0 0.35rem; font-size: 1.28rem; line-height: 1.25; }
.hero-desc { margin: 0; font-size: 0.89rem; color: var(--text-muted); line-height: 1.55; max-width: 72ch; }
.section-title { margin: 0 0 0.75rem; font-size: 1.08rem; font-weight: 700; }

.input-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.form-group { min-width: 0; margin-bottom: 0.65rem; }
.form-label { display: block; font-size: 0.76rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.28rem; }

.form-textarea,
.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.9rem;
}

.form-textarea { resize: vertical; line-height: 1.55; }

.form-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 40px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}

[data-theme="dark"] .form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}
[data-theme="light"] .form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

.form-select option,
.form-select optgroup { background-color: var(--bg-surface); color: var(--text-main); }

.text-stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}
.control-block {
  padding: 0.95rem;
  border-radius: 12px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
}
.control-block-title { margin: 0 0 0.75rem; font-size: 0.94rem; font-weight: 700; }

.range-row { margin-bottom: 0.65rem; }
.range-row input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.82rem;
  font-weight: 500;
  margin-bottom: 0.55rem;
  cursor: pointer;
}
.toggle-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }

.tint-swatches { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.swatch-btn {
  min-height: 36px;
  padding: 0.28rem 0.6rem;
  border-radius: 8px;
  border: 2px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}
.swatch-btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.tts-btn-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.5rem; }
.tts-status { margin: 0.55rem 0 0; font-size: 0.76rem; color: var(--text-muted); }

.btn-primary,
.btn-secondary,
.btn-chip,
.tab-btn {
  min-height: 40px;
  padding: 0.45rem 0.9rem;
  border-radius: 10px;
  font-size: 0.83rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--border-color);
  background: var(--bg-surface-2);
  color: var(--text-main);
  text-decoration: none;
}
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #ffffff; }
.btn-secondary:hover,
.btn-chip:hover { border-color: var(--accent); color: var(--accent); }
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: #ffffff; }

.reader-shell.fullscreen-focus {
  position: fixed;
  inset: 0;
  z-index: 9999;
  margin: 0;
  border-radius: 0;
  overflow-y: auto;
  padding: 1.25rem;
}

.reader-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-color);
}
.reader-tabs,
.reader-toolbar-right,
.ruler-nudge { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; }

.reader-stage {
  position: relative;
  border-radius: 14px;
  border: 1px solid var(--border-color);
  padding: 2rem 1.5rem;
  min-height: 280px;
  overflow: hidden;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.reader-stage:focus { outline: 2px solid var(--accent); }

/* Láminas Irlen */
.reader-stage.tint-auto { background: var(--bg-input); color: var(--text-main); }
.reader-stage.tint-cream { background: #fdf6e3; color: #1e293b; }
.reader-stage.tint-blue { background: #e0f2fe; color: #0f172a; }
.reader-stage.tint-mint { background: #dcfce7; color: #0f172a; }
.reader-stage.tint-peach { background: #ffedd5; color: #1e293b; }
.reader-stage.tint-yellow { background: #fef9c3; color: #1e293b; }
.reader-stage.tint-slate { background: #0f172a; color: #f8fafc; }

.reader-content {
  margin: 0 auto;
  max-width: 65ch;
  position: relative;
  z-index: 1;
}
.reader-content p { margin: 0 0 1.2em; }
.reader-content p:last-child { margin-bottom: 0; }

.bionic-fix { font-weight: 800; }
.bionic-tail { opacity: var(--tail-opacity, 0.75); }
.syllable-dot { opacity: 0.48; font-weight: 400; padding: 0 0.02em; }
.tts-word { border-radius: 4px; transition: background-color 0.08s ease; }
.tts-word.tts-active {
  background: rgba(56, 189, 248, 0.32);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.45);
}

/* Regla focal horizontal */
.focus-ruler-overlay {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  flex-direction: column;
}
.focus-ruler-overlay.active { display: flex; }
.ruler-shade-top {
  height: var(--ruler-top, 90px);
  background: rgba(2, 6, 23, 0.62);
  backdrop-filter: blur(1px);
  transition: height 0.05s linear;
}
.ruler-window {
  height: var(--ruler-height, 58px);
  border-top: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  background: transparent;
}
.ruler-shade-bottom {
  flex: 1 1 auto;
  background: rgba(2, 6, 23, 0.62);
  backdrop-filter: blur(1px);
}

/* Troceador de pasos TDAH */
.steps-progress-row { display: flex; flex-direction: column; gap: 0.45rem; margin-bottom: 1rem; }
.steps-summary { font-size: 0.85rem; font-weight: 700; color: var(--accent); }
.steps-progress-track { height: 10px; border-radius: 999px; background: var(--bg-surface-2); border: 1px solid var(--border-color); overflow: hidden; }
.steps-progress-fill { height: 100%; background: var(--ok); transition: width 0.25s ease; }

.microsteps-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.microstep-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface-2);
  transition: opacity 0.2s ease, border-color 0.2s ease;
}
.microstep-item.done { opacity: 0.6; border-color: var(--ok); }
.microstep-item input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--ok); margin-top: 2px; flex-shrink: 0; cursor: pointer; }
.microstep-num { font-family: var(--font-mono); font-size: 0.76rem; font-weight: 700; padding: 0.15rem 0.45rem; border-radius: 6px; background: var(--accent-soft); color: var(--accent); flex-shrink: 0; }
.microstep-text { font-size: 0.94rem; line-height: 1.5; }
.microstep-item.done .microstep-text { text-decoration: line-through; }

.faq-list { display: flex; flex-direction: column; gap: 0.6rem; }
.faq-item { border: 1px solid var(--border-color); border-radius: 12px; padding: 0.75rem 0.95rem; background: var(--bg-surface-2); }
.faq-question { cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.faq-answer { margin: 0.55rem 0 0; font-size: 0.84rem; color: var(--text-muted); line-height: 1.55; }

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

@media (max-width: 640px) {
  .input-actions,
  .reader-tabs,
  .reader-toolbar-right { width: 100%; }
  .input-actions > *,
  .reader-tabs > *,
  .reader-toolbar-right > button { flex: 1 1 auto; }
  .tts-btn-row button { width: 100%; }
  .reader-stage { padding: 1.25rem 1rem; }
}
