:root {
  --bg: #f3f6fb;
  --bg-soft: #eaf0f8;
  --card: rgba(255,255,255,.92);
  --card-solid: #ffffff;
  --text: #172033;
  --muted: #6b7589;
  --line: #dfe5ef;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eaf1ff;
  --success: #0f9f6e;
  --danger: #b42318;
  --shadow: 0 24px 70px rgba(30, 50, 85, .11);
  --radius-xl: 26px;
  --radius-lg: 18px;
  --radius-md: 13px;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --bg-soft: #101a2d;
  --card: rgba(18,28,47,.94);
  --card-solid: #121c2f;
  --text: #edf3ff;
  --muted: #9aa8c0;
  --line: #26344c;
  --primary: #5b8cff;
  --primary-dark: #78a0ff;
  --primary-soft: #17284d;
  --success: #37c893;
  --danger: #ff847a;
  --shadow: 0 24px 70px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(circle at 20% -5%, rgba(37,99,235,.13), transparent 35%),
    radial-gradient(circle at 100% 15%, rgba(14,165,233,.10), transparent 28%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}
.brand-logo { display: block; width: 150px; height: auto; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); display: grid; place-items: center; cursor: pointer;
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
}
.icon-btn:hover { transform: translateY(-1px); border-color: #b8c3d6; }
.icon-btn.small { width: 34px; height: 34px; border-radius: 10px; font-size: 24px; line-height: 1; }

.main-content { width: min(900px, calc(100% - 34px)); margin: 28px auto 50px; flex: 1; }
.hero { text-align: center; margin: 14px auto 30px; max-width: 720px; }
.eyebrow { margin: 0 0 12px; color: var(--primary); font-size: .76rem; font-weight: 800; letter-spacing: .14em; }
.hero h1 { margin: 0; font-size: clamp(2rem, 5vw, 3.55rem); line-height: 1.04; letter-spacing: -.045em; font-weight: 800; }
.hero-copy { margin: 18px auto 0; color: var(--muted); line-height: 1.6; font-size: 1.05rem; max-width: 640px; }

.reader-card, .preview-card {
  background: var(--card); border: 1px solid rgba(160,176,200,.28); box-shadow: var(--shadow);
  border-radius: var(--radius-xl); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.reader-card { padding: 24px; }
.source-tabs {
  background: var(--bg-soft); padding: 5px; border-radius: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 20px;
}
.source-tab { border: 0; background: transparent; color: var(--muted); border-radius: 10px; padding: 11px 16px; cursor: pointer; font-weight: 700; transition: .18s ease; }
.source-tab.active { background: var(--card-solid); color: var(--text); box-shadow: 0 4px 14px rgba(41,57,84,.08); }
.source-panel { display: none; }
.source-panel.active { display: block; }
textarea {
  width: 100%; min-height: 270px; resize: vertical; border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--card-solid); color: var(--text); padding: 18px; line-height: 1.65; outline: 0;
  transition: border-color .18s, box-shadow .18s;
}
textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37,99,235,.1); }
textarea::placeholder { color: #9aa5b8; }
.text-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 9px; color: var(--muted); font-size: .85rem; }
.text-button { border: 0; padding: 5px 0; background: transparent; color: var(--primary); font-weight: 700; cursor: pointer; }
.text-button:hover { text-decoration: underline; }

.drop-zone {
  width: 100%; min-height: 270px; border: 1.5px dashed #b9c6d9; border-radius: var(--radius-lg); background: var(--card-solid);
  color: var(--text); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; padding: 28px;
  transition: border-color .18s, background .18s, transform .18s;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--primary); background: var(--primary-soft); transform: translateY(-1px); }
.drop-zone > span:last-child { color: var(--muted); font-size: .92rem; }
.drop-icon { width: 62px; height: 62px; display: grid; place-items: center; border-radius: 18px; background: var(--primary-soft); color: var(--primary); margin-bottom: 6px; }
.file-info { margin-top: 14px; display: flex; align-items: center; gap: 12px; padding: 13px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--card-solid); }
.file-badge { min-width: 46px; height: 46px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); font-weight: 800; font-size: .72rem; display: grid; place-items: center; }
.file-details { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.file-details strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-details span { color: var(--muted); font-size: .84rem; }

.settings-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 18px; margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--line); }
.field-group { min-width: 0; }
.field-group label { display: block; font-size: .84rem; font-weight: 750; margin-bottom: 8px; }
.select-wrap select { width: 100%; height: 46px; border: 1px solid var(--line); border-radius: 12px; background: var(--card-solid); color: var(--text); padding: 0 40px 0 13px; outline: 0; }
.field-label-row { display: flex; justify-content: space-between; align-items: center; }
.field-label-row span { font-size: .83rem; font-weight: 750; color: var(--primary); }
input[type="range"] { width: 100%; accent-color: var(--primary); margin: 9px 0 0; }

.player { margin-top: 25px; background: var(--bg-soft); border-radius: var(--radius-lg); padding: 18px; }
.progress-row { display: flex; justify-content: space-between; gap: 15px; color: var(--muted); font-size: .83rem; margin-bottom: 10px; }
.progress-track { height: 5px; background: rgba(130,145,170,.22); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: var(--primary); border-radius: inherit; transition: width .25s linear; }
.controls { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 18px; }
.control-btn { border: 0; cursor: pointer; display: grid; place-items: center; transition: transform .16s ease, box-shadow .16s ease, opacity .16s; }
.control-btn:hover { transform: translateY(-1px); }
.control-btn.secondary { width: 46px; height: 46px; border-radius: 50%; color: var(--text); background: var(--card-solid); border: 1px solid var(--line); }
.control-btn.play { width: 64px; height: 64px; border-radius: 50%; color: white; background: var(--primary); box-shadow: 0 12px 27px rgba(37,99,235,.28); }
.control-btn.play:hover { background: var(--primary-dark); box-shadow: 0 14px 31px rgba(37,99,235,.34); }
.control-btn:disabled { cursor: not-allowed; opacity: .42; transform: none; }
.hidden { display: none !important; }

.message-box { margin-top: 15px; border-radius: 12px; padding: 11px 13px; font-size: .88rem; line-height: 1.45; background: var(--primary-soft); color: var(--text); }
.message-box.error { background: rgba(180,35,24,.1); color: var(--danger); }
.message-box.success { background: rgba(15,159,110,.1); color: var(--success); }

.preview-card { margin-top: 18px; padding: 20px; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 13px; }
.preview-head h2 { margin: 0; font-size: 1rem; }
.preview-text { max-height: 300px; overflow: auto; white-space: pre-wrap; line-height: 1.65; color: var(--muted); font-size: .93rem; background: var(--bg-soft); padding: 16px; border-radius: 13px; }
.preview-text .current { background: rgba(37,99,235,.16); color: var(--text); border-radius: 4px; }

footer { display: flex; gap: 8px; justify-content: center; align-items: center; color: var(--muted); font-size: .78rem; padding: 0 20px 28px; }
.footer-dot { opacity: .5; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 680px) {
  .topbar { height: 68px; padding: 0 18px; }
  .brand-logo { width: 135px; }
  .main-content { width: min(100% - 22px, 900px); margin-top: 16px; }
  .hero { margin-bottom: 22px; padding: 0 8px; }
  .hero h1 { font-size: clamp(2rem, 11vw, 2.75rem); }
  .hero-copy { font-size: .96rem; }
  .reader-card { padding: 15px; border-radius: 21px; }
  textarea, .drop-zone { min-height: 240px; }
  .settings-grid { grid-template-columns: 1fr; gap: 18px; }
  .player { padding: 15px; }
  .preview-card { padding: 15px; border-radius: 21px; }
  .preview-text { max-height: 250px; }
}

/* Selector de tema */
.theme-switch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--card);
}
.theme-option {
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  font-size: .82rem;
  font-weight: 750;
  cursor: pointer;
  transition: background .18s ease, color .18s ease, box-shadow .18s ease;
}
.theme-option.active {
  background: var(--card-solid);
  color: var(--text);
  box-shadow: 0 3px 10px rgba(30,50,85,.10);
}

/* Zona interactiva de lectura */
.preview-head > div { min-width: 0; }
.preview-help {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: .83rem;
  line-height: 1.45;
}
.selection-info {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin-bottom: 10px;
  padding: 5px 9px;
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: .78rem;
  font-weight: 750;
}
.interactive-reader {
  max-height: 430px;
  color: var(--text);
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
  scroll-behavior: smooth;
}
.read-word {
  border-radius: 3px;
  cursor: pointer;
  transition: background .08s ease, color .08s ease, text-decoration-color .08s ease;
}
.read-word:hover {
  background: rgba(37,99,235,.09);
}
.read-word.read-start {
  text-decoration-line: underline;
  text-decoration-thickness: 2px;
  text-decoration-color: var(--primary);
  text-underline-offset: 4px;
}
.read-word.speaking-word {
  background: var(--primary);
  color: #fff;
  text-decoration-line: underline;
  text-decoration-thickness: 2px;
  text-decoration-color: currentColor;
  text-underline-offset: 3px;
}
.interactive-reader::selection,
.interactive-reader *::selection {
  background: rgba(37,99,235,.28);
}

@media (max-width: 680px) {
  .theme-option { padding: 7px 9px; font-size: .76rem; }
  .preview-head { align-items: flex-start; }
  .interactive-reader { max-height: 360px; font-size: .96rem; }
}
