/* ==========================================================================
   Lector PDF con diccionario — hoja de estilos
   Tokens en :root (claro) y en [data-theme="dark"]. El tema "auto" lo resuelve
   settings.js estampando data-theme según prefers-color-scheme.
   ========================================================================== */

:root {
  --font-ui: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-read: Georgia, "Times New Roman", serif;
  --read-size: 18px;
  --read-lh: 1.6;
  --read-measure: 70ch;
  --read-align: left;

  --bg: #eef1f5;
  --bg-elev: #ffffff;
  --bg-sunken: #e2e6ec;
  --fg: #1a1f2b;
  --fg-muted: #5b6474;
  --fg-faint: #8b93a3;
  --line: #d7dce4;
  --line-strong: #b9c1cd;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --accent-soft: #dbe7ff;
  --danger: #dc2626;
  --highlight: rgba(250, 204, 21, .55);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, .12), 0 2px 4px rgba(16, 24, 40, .08);
  --shadow-lg: 0 20px 40px rgba(16, 24, 40, .18), 0 6px 12px rgba(16, 24, 40, .1);
  --page-shadow: 0 1px 3px rgba(0,0,0,.18), 0 8px 24px rgba(0,0,0,.12);
  --radius: 10px;
  --radius-sm: 7px;
  --toolbar-h: 56px;
  --pdf-filter: none;
}

[data-theme="dark"] {
  --bg: #12151c;
  --bg-elev: #1b1f28;
  --bg-sunken: #0d1015;
  --fg: #e6e9ef;
  --fg-muted: #a3abbb;
  --fg-faint: #6f788a;
  --line: #2a303c;
  --line-strong: #3a4250;
  --accent: #6d9cff;
  --accent-fg: #0b1220;
  --accent-soft: #1f2d4d;
  --danger: #f87171;
  --highlight: rgba(250, 204, 21, .38);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,.5);
  --shadow-lg: 0 20px 40px rgba(0,0,0,.6);
  --page-shadow: 0 1px 3px rgba(0,0,0,.6), 0 8px 24px rgba(0,0,0,.5);
}
[data-theme="dark"][data-invert-pdf="1"] { --pdf-filter: invert(.92) hue-rotate(180deg); }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 var(--font-ui);
  color: var(--fg);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3 { margin: 0; font-weight: 600; }
[hidden] { display: none !important; }

/* --------------------------------------------------------------------------
   Toolbar
   -------------------------------------------------------------------------- */
.toolbar {
  position: relative; z-index: 20;
  height: var(--toolbar-h);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 12px; padding: 0 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.toolbar__group { display: flex; align-items: center; gap: 6px; min-width: 0; }
.toolbar__right { justify-content: flex-end; }
.toolbar__sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.toolbar__brand { gap: 10px; }
.brand__logo {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent);
  position: relative; flex: none;
}
.brand__logo::after {
  content: ""; position: absolute; left: 8px; top: 6px; width: 12px; height: 15px;
  background: #fff; border-radius: 2px 6px 6px 2px;
}
.brand__name { font-weight: 700; font-size: 15px; letter-spacing: -.01em; margin-right: 6px; }
.brand__name span { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; cursor: pointer;
  color: var(--fg); white-space: nowrap; user-select: none;
  transition: background .12s, border-color .12s, color .12s, transform .06s;
}
.btn:hover { background: var(--bg-sunken); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: .4; cursor: default; }
.btn--icon { width: 34px; padding: 0; justify-content: center; position: relative; }
.btn--sm { height: 28px; width: 28px; }
.btn--sm svg { width: 16px; height: 16px; }
.btn--text { color: var(--fg-muted); font-weight: 500; }
.btn--text:hover { color: var(--fg); }
.btn--danger { color: var(--danger); }
.btn--primary { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn--primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn--lg { height: 42px; padding: 0 22px; font-size: 15px; }
.badge {
  position: absolute; top: 3px; right: 3px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--accent); color: var(--accent-fg);
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

.page-indicator { display: inline-flex; align-items: center; gap: 6px; color: var(--fg-muted); }
.page-indicator input {
  width: 52px; height: 30px; text-align: center; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
  -moz-appearance: textfield;
}
.page-indicator input::-webkit-inner-spin-button { appearance: none; }
.page-indicator input:focus { outline: 2px solid var(--accent); border-color: transparent; }
#zoom-label { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: 8px; background: var(--bg-sunken);
}
.segmented__btn {
  height: 28px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent;
  color: var(--fg-muted); cursor: pointer; font-weight: 500;
}
.segmented__btn:hover { color: var(--fg); }
.segmented__btn.is-active { background: var(--bg-elev); color: var(--fg); box-shadow: var(--shadow-sm); }
.segmented--full { display: flex; }
.segmented--full .segmented__btn { flex: 1; }

.search {
  display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; width: 220px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg);
  color: var(--fg-faint);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { flex: none; width: 16px; height: 16px; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: 0; color: var(--fg); }
.search input::-webkit-search-cancel-button { appearance: none; }

/* --------------------------------------------------------------------------
   Workspace / viewer
   -------------------------------------------------------------------------- */
.workspace { position: relative; height: calc(100% - var(--toolbar-h)); display: flex; }
/* overflow-anchor: none → el visor compensa él mismo los cambios de altura (viewer.js), sin que el navegador lo duplique */
.viewer { flex: 1; min-width: 0; overflow: auto; position: relative; outline: 0; scroll-behavior: auto; overflow-anchor: none; }

.empty { min-height: 100%; display: grid; place-items: center; padding: 40px 20px; }
.empty__card {
  max-width: 520px; text-align: center; padding: 44px 40px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-md);
}
.empty__icon {
  width: 72px; height: 88px; margin: 0 auto 22px; border-radius: 6px 14px 14px 6px;
  background: linear-gradient(160deg, var(--accent), #7c3aed); position: relative; box-shadow: var(--shadow-md);
}
.empty__icon::before, .empty__icon::after {
  content: ""; position: absolute; left: 16px; height: 6px; border-radius: 3px; background: rgba(255,255,255,.85);
}
.empty__icon::before { top: 26px; width: 40px; }
.empty__icon::after { top: 42px; width: 28px; }
.empty h1 { font-size: 22px; letter-spacing: -.01em; margin-bottom: 10px; }
.empty p { color: var(--fg-muted); margin: 0 0 22px; font-size: 15px; }
.empty__hint { font-size: 13px !important; color: var(--fg-faint) !important; margin: 14px 0 0 !important; }
.empty__meta { font-size: 12px !important; color: var(--fg-faint) !important; margin: 18px 0 0 !important; }

.pages { padding: 24px 24px 80px; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.page {
  position: relative; background: #fff; box-shadow: var(--page-shadow); flex: none;
  filter: var(--pdf-filter);
}
.page canvas { display: block; width: 100%; height: 100%; }
.page__num {
  position: absolute; left: 50%; bottom: -20px; transform: translateX(-50%);
  font-size: 11px; color: var(--fg-faint); filter: none;
}
.page--loading::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 26px; height: 26px;
  border: 3px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Capa de texto de pdf.js: texto transparente y posicionado sobre el canvas */
.textLayer {
  position: absolute; inset: 0; overflow: hidden; line-height: 1;
  text-align: initial; text-size-adjust: none; forced-color-adjust: none;
  transform-origin: 0 0; z-index: 2; cursor: text;
}
.textLayer span, .textLayer br { color: transparent; position: absolute; white-space: pre; transform-origin: 0 0; }
.textLayer ::selection { background: rgba(37, 99, 235, .3); }
.textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: -1; cursor: default; user-select: none; }

/* Vista Texto (reflujo) */
.reflow {
  width: min(100%, var(--read-measure)); margin: 0 auto; padding: 8px 0;
  font-family: var(--font-read); font-size: var(--read-size); line-height: var(--read-lh);
  text-align: var(--read-align); hyphens: auto; color: var(--fg);
}
.reflow__page {
  padding: 34px 40px; margin-bottom: 26px; background: var(--bg-elev);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-sm);
}
.reflow__page p { margin: 0 0 1em; }
.reflow__page h3 { font-size: 1.25em; margin: 1.2em 0 .6em; line-height: 1.3; }
.reflow__page h3:first-child { margin-top: 0; }
.reflow__marker { font-family: var(--font-ui); font-size: 12px; color: var(--fg-faint); margin-bottom: 14px; }
.reflow__empty { color: var(--fg-faint); font-style: italic; }
.reflow ::selection { background: var(--accent-soft); }
::highlight(pdfr-word) { background: var(--highlight); color: inherit; }

/* --------------------------------------------------------------------------
   Drawers (vocabulario y ajustes)
   -------------------------------------------------------------------------- */
.drawer {
  width: 340px; flex: none; display: flex; flex-direction: column;
  background: var(--bg-elev); border-left: 1px solid var(--line); box-shadow: var(--shadow-md);
  animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
.drawer__head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: 52px; padding: 0 10px 0 18px; border-bottom: 1px solid var(--line);
}
.drawer__head h2 { font-size: 15px; }
.drawer__actions { display: flex; gap: 2px; align-items: center; }
.drawer__body { flex: 1; overflow: auto; padding: 16px 18px 30px; }
.drawer__empty { color: var(--fg-faint); font-size: 13px; }

.vocab-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.vocab-item {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg);
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: start;
}
.vocab-item__word { font-weight: 600; cursor: pointer; }
.vocab-item__word:hover { color: var(--accent); }
.vocab-item__trans { grid-column: 1; color: var(--fg-muted); font-size: 13px; }
.vocab-item__meta { grid-column: 1; color: var(--fg-faint); font-size: 11px; }
.vocab-item__del { grid-column: 2; grid-row: 1 / span 3; }

.settings h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-faint);
  margin: 22px 0 10px;
}
.settings h3:first-child { margin-top: 0; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field--row { flex-direction: row; align-items: center; justify-content: space-between; gap: 14px; cursor: pointer; }
.field__label { font-size: 13px; display: flex; justify-content: space-between; align-items: baseline; }
.field--row .field__label { flex-direction: column; align-items: flex-start; gap: 2px; }
.field__label small { color: var(--fg-faint); font-size: 11px; }
.field__label b { font-weight: 500; color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.field__value { margin: 0; font-size: 12px; color: var(--fg-muted); }
.select {
  height: 34px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg); color: var(--fg);
}
.range { width: 100%; accent-color: var(--accent); }
.switch {
  appearance: none; width: 40px; height: 22px; border-radius: 11px; background: var(--line-strong);
  position: relative; cursor: pointer; flex: none; transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
.shortcuts { list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--fg-muted); }
.shortcuts li { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px; border-radius: 5px; text-align: center;
  border: 1px solid var(--line-strong); border-bottom-width: 2px; background: var(--bg);
  font: 11px/1.6 var(--font-ui); color: var(--fg);
}

/* --------------------------------------------------------------------------
   Popup de traducción
   -------------------------------------------------------------------------- */
.popup {
  position: fixed; z-index: 50; width: 320px; max-width: calc(100vw - 16px);
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-lg); animation: pop .14s ease-out;
  font-family: var(--font-ui);
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.popup__arrow {
  position: absolute; width: 12px; height: 12px; background: var(--bg-elev);
  border-left: 1px solid var(--line); border-top: 1px solid var(--line);
  transform: rotate(45deg); top: -7px; left: 24px;
}
.popup--above .popup__arrow { top: auto; bottom: -7px; transform: rotate(225deg); }
.popup__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 12px 10px 6px 16px; }
.popup__word h3 { font-size: 19px; letter-spacing: -.01em; line-height: 1.2; word-break: break-word; }
.popup__lemma { font-size: 12px; color: var(--fg-faint); }
.popup__actions { display: flex; gap: 2px; flex: none; }
.popup__body { padding: 0 16px 8px; max-height: 320px; overflow: auto; }
.popup__foot { padding: 6px 16px 10px; font-size: 11px; color: var(--fg-faint); border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.popup__foot:empty { display: none; }

.sense { margin: 8px 0; padding-left: 8px; border-left: 2px solid var(--line); }
.sense__pos {
  display: inline-block; margin-bottom: 4px; padding: 1px 7px; border-radius: 4px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  background: var(--accent-soft); color: var(--accent);
}
.sense__trans { font-size: 15px; font-weight: 600; line-height: 1.35; }
.sense__trans span + span::before { content: ", "; font-weight: 400; color: var(--fg-faint); }
.sense__def { margin: 2px 0 0; font-size: 12px; color: var(--fg-muted); line-height: 1.4; }
.popup__none { color: var(--fg-muted); font-size: 13px; padding: 6px 0 10px; }
.popup__loading { display: flex; align-items: center; gap: 8px; color: var(--fg-faint); font-size: 12px; padding: 8px 0; }
.popup__loading::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
.popup__online { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); }
.popup__online-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-faint); margin-bottom: 4px; }
.popup__phrase { font-size: 14px; line-height: 1.45; }
.popup__link { color: var(--accent); text-decoration: none; }
.popup__link:hover { text-decoration: underline; }

/* --------------------------------------------------------------------------
   Toast, dropzone
   -------------------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 60;
  padding: 10px 16px; border-radius: 10px; background: var(--fg); color: var(--bg);
  font-size: 13px; box-shadow: var(--shadow-lg); animation: pop .15s ease-out; max-width: 80vw;
}
.dropzone {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent); backdrop-filter: blur(2px);
  border: 3px dashed var(--accent); pointer-events: none;
}
.dropzone p { padding: 14px 24px; border-radius: 12px; background: var(--bg-elev); font-weight: 600; box-shadow: var(--shadow-md); }

@media (max-width: 980px) {
  .toolbar { grid-template-columns: auto 1fr auto; }
  .brand__name, #btn-open span { display: none; }
  .search { width: 150px; }
  .drawer { position: absolute; right: 0; top: 0; bottom: 0; z-index: 30; }
}
