/* Biblioteca: reading styles for a low-vision reader.
   Light text on a dark background only (betterview themes), Atkinson Hyperlegible
   (bundled, SIL Open Font License: fonts/OFL.txt), one column, and every size in
   rem/em so the A−/A+ buttons (--scale) and browser zoom enlarge everything. */

@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-400-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-ext-400-normal.woff2) format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: italic; font-weight: 400; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-400-italic.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: italic; font-weight: 400; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-ext-400-italic.woff2) format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 700; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-700-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: normal; font-weight: 700; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-ext-700-normal.woff2) format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: italic; font-weight: 700; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-700-italic.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Atkinson Hyperlegible"; font-style: italic; font-weight: 700; font-display: swap;
  src: url(fonts/atkinson-hyperlegible-latin-ext-700-italic.woff2) format("woff2");
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

/* ------------------------------------------------------------------ themes
   "soft" is betterview's default: light grey on dark grey, the least glare.
   The theme button cycles soft → black → yellow → sepia. */
:root, :root[data-theme="soft"] {
  --scale: 1.3;   /* default: two steps above 1 (28.6 px) */
  --bg: #1e1e1e;
  --fg: #e6e6e6;
  --muted: #b8b8b8;
  --rule: #4a4a4a;
  --panel: #2a2a2a;
  --tip: #333333;
  --link: #9cc8ff;
  --accent: #8fc1ff;
  --on-accent: #111111;
  --gloss: #7fb6ff;
  --gloss-bg: rgba(127, 182, 255, 0.18);
  --focus: #ffb000;
  color-scheme: dark;
}
:root[data-theme="black"] {
  --bg: #000000; --fg: #ffffff; --muted: #cccccc; --rule: #5a5a5a; --panel: #161616; --tip: #262626;
  --link: #9cc8ff; --accent: #9cc8ff; --on-accent: #000000; --gloss: #86bcff; --gloss-bg: rgba(134, 188, 255, 0.22);
}
:root[data-theme="yellow"] {
  --bg: #000000; --fg: #ffe14d; --muted: #e3c94a; --rule: #6b5d1c; --panel: #161616; --tip: #262626;
  --link: #ffffff; --accent: #ffe14d; --on-accent: #000000; --gloss: #ffffff; --gloss-bg: rgba(255, 255, 255, 0.18);
}
:root[data-theme="sepia"] {
  --bg: #1f1a14; --fg: #f0e0c0; --muted: #cdbc9a; --rule: #54483a; --panel: #2d261d; --tip: #3a3126;
  --link: #f0c060; --accent: #f0c060; --on-accent: #1f1a14; --gloss: #f0b850; --gloss-bg: rgba(240, 184, 80, 0.2);
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html {
  font-size: calc(137.5% * var(--scale));   /* 22 px × scale at the browser default */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: "Atkinson Hyperlegible", Verdana, "Segoe UI", system-ui, sans-serif;
  line-height: 1.65;
  word-spacing: 0.04em;
  overflow-wrap: break-word;
}
a { color: var(--link); text-underline-offset: 0.18em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2 { line-height: 1.25; }
h1 { font-size: 1.6em; margin: 0.2em 0 0.3em; }
h2 { font-size: 1.25em; }

/* ------------------------------------------------------------------ bars
   The top bar and the page buttons keep a steady size (about 20 px) while
   A−/A+ change the book text; they grow a little at the largest sizes. */
.topbar, .pager {
  font-size: calc(0.9rem / var(--scale) * clamp(1.3, var(--scale), 1.6) / 1.3);
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}
.topbar-in { display: flex; align-items: center; gap: 1em; padding: 0.3em clamp(16px, 3.5vw, 64px); }
.library .topbar-in, .book .topbar-in { max-width: 40rem; margin: 0 auto; padding-left: 1rem; padding-right: 1rem; }
.topbar .home { flex: 0 0 auto; font-weight: 700; white-space: nowrap; padding: 0.4em 0; }
.library .topbar .home { color: var(--fg); }
.topbar .where {
  flex: 1 1 auto; min-width: 0; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .where a { color: var(--muted); }
.tools { display: flex; gap: 0.4em; flex: 0 0 auto; margin-left: auto; }
.tools button {
  min-width: 2.6em; min-height: 2.4em; padding: 0 0.6em;
  font: inherit; font-weight: 700; color: var(--fg); background: var(--panel);
  border: 1px solid var(--rule); border-radius: 0.4em; cursor: pointer;
}
.tools button:hover { border-color: var(--fg); }
.tools button:disabled { opacity: 0.4; cursor: default; }
.progress { height: 0.3em; background: var(--panel); }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); }

/* ------------------------------------------------------------------ reading
   With JavaScript (class "js" on <html>, set by prefs.js) a chapter is shown
   one screen at a time: #flow is laid out in columns one window wide and as
   tall as the space between the bars, and reader.js shifts it sideways to
   turn the page. Nothing scrolls; the page buttons are always on screen.
   Without JavaScript the chapter is an ordinary scrolling page. */
.flow { padding: 0.6em clamp(16px, 3.5vw, 64px) 0.4em; }
.flow p { margin: 0 0 0.8em; orphans: 2; widows: 2; }
.flow h2.chapter {
  text-align: center; font-size: 1.35em; letter-spacing: 0.04em;
  margin: 0.2em 0 0.9em; break-after: avoid;
}
.flow p.end { text-align: center; color: var(--muted); font-style: italic; margin-top: 1.5em; }

.js body.reading {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; min-height: 0;
  overflow: hidden;
}
.js body.reading .topbar { position: relative; flex: 0 0 auto; }
.js .view { flex: 1 1 auto; min-height: 0; position: relative; overflow: hidden; }
.js .flow {
  height: 100%;
  column-count: 1;               /* reader.js sets the exact column width and gap in px */
  column-gap: calc(2 * clamp(16px, 3.5vw, 64px));
  column-fill: auto;
  overflow: visible;
}

/* page buttons, always at the bottom of the window */
.pager {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75em;
  padding: 0.5em clamp(16px, 3.5vw, 64px) 0.6em;
  border-top: 1px solid var(--rule);
  background: var(--bg);
}
.js body.reading .pager { flex: 0 0 auto; }
.pager .pos { color: var(--muted); text-align: center; text-decoration: none; padding: 0.5em 0.25em; }
.pager .pos:hover { text-decoration: underline; }
.pager .btn { min-width: 8.5em; min-height: 2.8em; gap: 0.45em; }
.pager .btn.end .arr { display: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 2.6em; padding: 0.3em 1.1em;
  font: inherit; font-weight: 700; line-height: 1.3; text-decoration: none; white-space: nowrap;
  color: var(--fg); background: var(--panel);
  border: 2px solid var(--rule); border-radius: 0.5em; cursor: pointer;
  user-select: none;
}
.btn:hover { border-color: var(--fg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { border-color: var(--fg); }
.btn.ghost { visibility: hidden; }
.btn.big { font-size: 1.05em; padding: 0.45em 1.4em; }

/* a gloss: dotted underline; the Spanish shows in #tip on hover or tap.
   A repeat on the same page ("dup", set by reader.js) is plain text. */
.g {
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--gloss);
  text-decoration-thickness: 0.12em;
  text-underline-offset: 0.24em;
  text-decoration-skip-ink: none;
  cursor: help;
  border-radius: 0.15em;
}
.g:hover, .g.on { background: var(--gloss-bg); }
.g.dup { text-decoration: none; cursor: auto; }
.g.dup:hover { background: none; }

/* the pop-up: same text size as the book */
#tip {
  position: fixed; z-index: 50; top: 0; left: 0;
  max-width: min(24em, calc(100vw - 1.5rem));
  padding: 0.4em 0.75em 0.45em;
  font-size: 1rem; line-height: 1.45;
  background: var(--tip); color: var(--fg);
  border: 2px solid var(--gloss); border-radius: 0.45em;
  box-shadow: 0 0.3em 1.2em rgba(0, 0, 0, 0.65);
  pointer-events: none;
}
#tip[hidden] { display: none; }
#tip .es { display: block; font-weight: 700; }
#tip .n { display: block; color: var(--muted); margin-top: 0.1em; }

p.hint {
  border-left: 4px solid var(--gloss); background: var(--panel);
  padding: 0.5em 0.9em; margin: 0 0 1.2em;
  font-size: calc(0.85rem / var(--scale) * clamp(1.3, var(--scale), 1.6) / 1.3);  /* like the bars */
  line-height: 1.5;
}

/* ------------------------------------------------------------------ library and book pages */
main.shelf { max-width: 40rem; margin: 0 auto; padding: 1.2em 1rem 3em; }
ul.books { list-style: none; margin: 0; padding: 0; }
.book-card, .book-head { display: flex; gap: 1.2em; align-items: flex-start; }
.book-card { padding: 1.2em 0; border-bottom: 1px solid var(--rule); }
.book-card h2 { margin: 0 0 0.15em; font-size: 1.3em; }
.book-card h2 a { color: var(--fg); text-decoration: none; }
.book-card h2 a:hover { text-decoration: underline; }
.book-card .info, .book-head > div { flex: 1 1 auto; min-width: 0; }
img.cover {
  flex: 0 0 auto; width: 6.5em; height: auto; border-radius: 0.25em;
  box-shadow: 0 0 0 1px var(--rule);
}
.book-head img.cover { width: 8em; }
.by { color: var(--muted); margin: 0 0 0.6em; }
.badge {
  display: inline-block; margin: 0 0 0.6em; padding: 0.1em 0.6em;
  border: 1px solid var(--accent); border-radius: 0.4em; color: var(--accent); font-size: 0.85em;
}
.status { margin: 0 0 0.35em; }
.meter { height: 0.5rem; background: var(--panel); border-radius: 0.25rem; overflow: hidden; margin: 0 0 1em; max-width: 20em; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); }
.book-card .btn { margin: 0 0.4em 0.4em 0; }
ol.toc { list-style: none; margin: 0 0 1.6em; padding: 0; }
ol.toc li { border-bottom: 1px solid var(--rule); }
ol.toc a { display: flex; justify-content: space-between; gap: 1em; padding: 0.55em 0.2em; font-weight: 700; text-decoration: none; }
ol.toc a:hover span:first-child { text-decoration: underline; }
ol.toc .pg { color: var(--muted); font-weight: 400; white-space: nowrap; }
form.goto { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6em; margin: 0 0 2em; }
form.goto input {
  width: 6em; min-height: 2.6em; padding: 0.2em 0.5em;
  font: inherit; color: var(--fg); background: var(--panel);
  border: 2px solid var(--rule); border-radius: 0.5em;
}
.credit, .logout { color: var(--muted); font-size: 0.85em; }
.logout a { color: var(--muted); }

/* ------------------------------------------------------------------ login */
main.login { max-width: 22rem; margin: 0 auto; padding: 3em 1rem; }
main.login label { display: block; font-weight: 700; margin: 1em 0 0.3em; }
main.login input {
  width: 100%; min-height: 2.6em; padding: 0.3em 0.6em;
  font: inherit; color: var(--fg); background: var(--panel);
  border: 2px solid var(--rule); border-radius: 0.5em;
}
main.login button { margin-top: 1.4em; width: 100%; }
main.login .err { color: #ffb4a8; font-weight: 700; }

/* narrow windows */
@media (max-width: 34em) {
  .book-card, .book-head { flex-direction: column; }
  .topbar-in { gap: 0.6em; }
  .tools button { min-width: 2.3em; padding: 0 0.4em; }
  .pager .btn { min-width: 3.2em; padding: 0.3em 0.8em; }
  .pager .btn .lbl { display: none; }          /* arrows only on phones */
  .pager .btn.end .lbl { display: inline; }
  .pager .pos { font-size: 0.9em; white-space: nowrap; }
}
@media print {
  .js body.reading { display: block; height: auto; overflow: visible; }
  .js .flow { columns: auto; height: auto; transform: none !important; }
  .topbar, .pager, #tip { display: none; }
}
