/* English Reader. Paper-and-ink palette, serif for the book, sans for controls. */
:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --ink: #1f1b16;
  --muted: #6f675c;
  --line: #e0d6c3;
  --accent: #8a3b12;
  --accent-ink: #fffdf8;
  --mark: rgba(201, 138, 28, 0.26);
  --mark-line: #b8791a;
  --danger: #a12a1f;
  --shadow: 0 10px 34px rgba(60, 40, 10, 0.16);
  --reader-size: 19px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --surface: #211e17;
    --ink: #e9e2d3;
    --muted: #a2988a;
    --line: #373126;
    --accent: #e0a36b;
    --accent-ink: #1a140c;
    --mark: rgba(224, 163, 107, 0.2);
    --mark-line: #c98d55;
    --danger: #ef8a7c;
    --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  overflow-wrap: break-word;
}
h1, h2, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.boot { padding: 30vh 16px 0; text-align: center; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- controls ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: 600 15px/1.2 var(--sans); text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); border-color: var(--line); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn-small { min-height: 34px; padding: 5px 12px; font-size: 14px; }
.busy { opacity: 0.55; pointer-events: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--ink); background: var(--mark); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.txt { font: 700 15px/1 var(--sans); }
input[type="email"], input.code-input, input[type="password"], input[type="search"] {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: 16px/1.3 var(--sans);
}
.notice { padding: 10px 12px; border-radius: 10px; background: var(--mark); font-size: 15px; }
.notice-error { background: transparent; border: 1px solid var(--danger); color: var(--danger); }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex; align-items: center; gap: 8px;
  max-width: 860px; min-height: 56px; margin: 0 auto; padding: 6px 12px;
}
.topbar-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.brand { font: 700 18px/1.2 var(--serif); letter-spacing: 0.01em; }

/* ---- pages ---- */
.page { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; display: grid; gap: 18px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page h1 { font: 700 30px/1.15 var(--serif); }
.empty { padding: 28px 18px; border: 1px dashed var(--line); border-radius: 14px; display: grid; gap: 8px; color: var(--muted); }
.version { font-size: 13px; text-align: center; }
.file-btn { position: relative; }

/* ---- sign in ---- */
.auth { max-width: 420px; margin: 0 auto; padding: 12vh 20px 48px; display: grid; gap: 16px; }
.auth .brand { color: var(--accent); }
.auth h1 { font: 700 32px/1.15 var(--serif); text-wrap: balance; }
.lede { color: var(--muted); }
.inline-icon { display: inline-flex; vertical-align: -0.2em; color: var(--accent, currentColor); }
.inline-icon svg { width: 1.15em; height: 1.15em; }
.auth-form { display: grid; gap: 12px; margin-top: 8px; }
.auth-form label { display: grid; gap: 4px; font-size: 14px; font-weight: 600; color: var(--muted); }

/* ---- library ---- */
.books { display: grid; gap: 10px; }
.book {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px 6px 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
}
.book-link { flex: 1; min-width: 0; display: grid; gap: 3px; padding: 12px 8px 12px 18px; text-decoration: none; }
.book-title { font: 700 20px/1.25 var(--serif); }
.book-author { color: var(--muted); }
.book-meta { font-size: 14px; color: var(--muted); }
.progress { height: 3px; margin-top: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); }

/* ---- reader ---- */
.reader-titles { flex: 1; min-width: 0; display: grid; line-height: 1.25; }
.reader-book { font: 700 15px/1.25 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-chapter { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader { max-width: 700px; margin: 0 auto; padding: 28px 20px 96px; }
.text { font: var(--reader-size)/1.65 var(--serif); min-height: 50vh; }
.text.loading { opacity: 0.4; }
.text .blk { scroll-margin-top: 68px; }
.text p { margin: 0 0 0.9em; hyphens: auto; }
.text h2 { margin: 1.4em 0 0.7em; font: 700 1.3em/1.25 var(--serif); text-wrap: balance; }
.text h2:first-child { margin-top: 0; }
.w { cursor: pointer; border-radius: 3px; -webkit-tap-highlight-color: transparent; }
@media (hover: hover) { .w:hover { background: var(--mark); } }
.w-learning { background: var(--mark); box-shadow: inset 0 -1.5px 0 var(--mark-line); }
.w.w-active, .w.w-active:hover { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.w.w-sent { background: var(--mark); }
.w.w-speak { background: var(--accent); color: var(--accent-ink); box-shadow: none; transition: background 0.08s; }
.chapter-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--line); }

/* ---- translation card ---- */
.card {
  position: fixed; z-index: 20; width: 360px; max-width: calc(100vw - 24px);
  padding: 14px 16px 14px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow);
  display: grid; gap: 6px;
}
.card.sheet {
  left: 0; right: 0; bottom: 0; top: auto; width: auto; max-width: none;
  border-radius: 18px 18px 0 0; border-width: 1px 0 0;
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 70vh; overflow-y: auto;
}
.card-close { position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; }
.card-head { display: flex; align-items: center; gap: 4px; padding-right: 36px; }
.card-word { font: italic 600 17px/1.3 var(--serif); color: var(--muted); }
.card-translation { font: 700 24px/1.2 var(--sans); }
.card-lemma { font-size: 14px; color: var(--muted); }
.card-note { font-size: 15px; padding-left: 10px; border-left: 3px solid var(--mark-line); }
.card-other { font-size: 14.5px; }
.card-wait { color: var(--muted); padding: 6px 0 10px; }
.card-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; min-height: 34px; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 13.5px; }
.card-foot .muted { margin-right: auto; white-space: nowrap; }
.card-foot .btn { white-space: nowrap; }
.card-foot:empty { display: none; }

.phrase-button {
  position: fixed; z-index: 15; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  min-height: 44px; padding: 10px 20px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font: 600 15px/1.2 var(--sans);
  box-shadow: var(--shadow); cursor: pointer;
}
.toast {
  position: fixed; z-index: 30; left: 50%; bottom: 80px; transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--ink); color: var(--bg); font-size: 15px; box-shadow: var(--shadow);
}

/* ---- narration ---- */
.player {
  position: fixed; z-index: 16; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 4px 6px;
  max-width: calc(100vw - 16px);
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); box-shadow: var(--shadow);
}
.player .icon-btn { width: 40px; height: 40px; border-radius: 999px; }
.player .player-toggle { color: var(--accent-ink); background: var(--accent); }
.player .player-toggle:hover { color: var(--accent-ink); background: var(--accent); filter: brightness(1.08); }
.player-chip {
  min-height: 34px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--ink); font: 600 13.5px/1.2 var(--sans); cursor: pointer; white-space: nowrap;
  max-width: 120px; overflow: hidden; text-overflow: ellipsis;
}
.player-chip:hover { border-color: var(--muted); }
body.narrating .reader { padding-bottom: 120px; }
body.narrating .phrase-button { bottom: calc(76px + env(safe-area-inset-bottom)); }
.is-loading svg { animation: pulse 0.9s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .is-loading svg { animation: none; opacity: 0.5; } }
.card-play { color: var(--accent); }
.voices { display: grid; gap: 2px; margin-top: 8px; }
.voice-row { display: flex; align-items: center; gap: 4px; border-radius: 10px; }
.voice-row.current { background: var(--mark); }
.voice-pick {
  flex: 1; display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 10px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--ink);
  font: 16px/1.3 var(--sans); text-align: left; cursor: pointer;
}
.voice-pick:hover { background: var(--mark); }
.voice-name { font-weight: 700; }
.voice-pick .muted { font-size: 13.5px; }
.field { display: flex; align-items: center; gap: 10px; margin: 4px 0 6px; }
.field .select { flex: 1; min-width: 0; width: 100%; }
.select {
  flex: 1; min-height: 40px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: 15px/1.3 var(--sans);
}
.small { font-size: 13.5px; margin-top: 6px; }

/* ---- dialogs ---- */
.dialog {
  width: min(480px, calc(100vw - 32px)); max-height: 80vh; padding: 20px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink);
}
.dialog::backdrop { background: rgba(20, 14, 6, 0.5); }
.dialog h2 { font: 700 21px/1.2 var(--serif); }
.dialog > p { margin-top: 8px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.toc { display: grid; gap: 2px; }
.toc-item {
  display: flex; justify-content: space-between; gap: 12px; width: 100%; padding: 10px 10px;
  border: 0; border-radius: 8px; background: transparent; color: var(--ink);
  font: 16px/1.3 var(--serif); text-align: left; cursor: pointer;
}
.toc-item .muted { flex: none; font: 13px/1.6 var(--sans); font-variant-numeric: tabular-nums; }
.toc-item:hover { background: var(--mark); }
.toc-item.current { background: var(--mark); font-weight: 700; }

/* ---- vocabulary ---- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  min-height: 38px; padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--muted); font: 600 14px/1.2 var(--sans); cursor: pointer;
}
.tab.current { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.vocab { display: grid; gap: 10px; }
.vocab-item { padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); display: grid; gap: 4px; }
.vocab-main { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 8px; }
.vocab-lemma { font: 700 20px/1.25 var(--serif); }
.vocab-main .icon-btn { width: 32px; height: 32px; }
.vocab-translation { font-weight: 600; font-size: 17px; }
.vocab-meta { font-size: 13.5px; }
.vocab-note { font-size: 14.5px; }
.vocab-sentence { font: italic 15.5px/1.5 var(--serif); color: var(--muted); }
.vocab-actions { display: flex; gap: 6px; margin-top: 6px; }

@media (max-width: 480px) {
  .page h1 { font-size: 26px; }
  .reader { padding: 22px 16px 96px; }
  .book { flex-wrap: wrap; padding: 0 0 8px; }
  .book .btn { margin-left: 10px; }
  .chapter-nav .btn { flex: 1; }
}

/* ---- adding books ---- */
.add-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.form { display: grid; gap: 12px; }
.form .dialog-head { margin-bottom: 0; }
.field-col { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.input {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: 16px/1.4 var(--sans);
}
.textarea { min-height: 200px; resize: vertical; font-family: var(--serif); }
@media (max-width: 480px) {
  .add-actions { justify-content: stretch; width: 100%; }
  .add-actions > * { flex: 1 1 auto; }
}

/* ---- sign-in by code ---- */
.code-input { font: 600 22px/1.2 var(--sans); letter-spacing: 0.3em; text-align: center; }
.auth-sent { font-size: 15px; color: var(--muted); }
.auth-sent strong { color: var(--ink); }

/* ---- Metzia ad, footer, donations ---- */
.ad {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px 10px 10px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--ink); text-decoration: none;
}
.ad:hover { border-color: var(--muted); }
.ad-logo { flex: none; width: 120px; height: auto; border-radius: 8px; }
.ad-text { display: grid; gap: 2px; font-size: 14px; line-height: 1.35; color: var(--muted); }
.ad-text strong { font-size: 16px; color: var(--ink); }
.ad-cta { margin-top: 2px; font-weight: 700; color: var(--accent); }
@media (max-width: 420px) {
  .ad { align-items: flex-start; }
  .ad-logo { width: 84px; }
}
.auth .ad { margin-top: 8px; }
.site-foot { display: grid; gap: 8px; margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.site-foot-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.site-foot-brand { font-weight: 700; color: var(--muted); text-decoration: none; }
.site-foot-brand:hover { color: var(--accent); text-decoration: underline; }
.site-foot .version { margin: 0; text-align: left; }
.link-btn { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
.link-btn:hover { color: var(--ink); }
.donate-links { display: grid; gap: 10px; margin-top: 14px; }

/* ---- language switch and Hebrew ---- */
.lang-switch { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--line, #d9d0bd); border-radius: 999px; margin-left: 12px; }
.lang-btn { border: 0; background: transparent; color: inherit; font: 600 14px/1 var(--sans, system-ui); padding: 7px 12px; border-radius: 999px; cursor: pointer; }
.lang-btn.current { background: var(--accent); color: var(--accent-ink); }
.text:lang(he) { font-family: "Frank Ruhl Libre", "David Libre", David, "Times New Roman", serif; font-size: calc(var(--reader-size) * 1.12); line-height: 1.75; text-align: right; }
.text:lang(he) p { hyphens: none; }
.card-sound { display: flex; gap: 10px; align-items: baseline; margin: 2px 0 6px; font-size: 15px; color: var(--muted); }
.card-vocalized { font: 600 20px/1.3 "Frank Ruhl Libre", David, "Times New Roman", serif; color: inherit; }
.card-root { margin: 2px 0 6px; font-size: 14px; }
.vocab-sound { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; margin: 0; font-size: 15px; }
.vocab-sound [lang="he"] { font: 600 18px/1.3 "Frank Ruhl Libre", David, "Times New Roman", serif; }
.vocab-lemma:lang(he) { font-family: "Frank Ruhl Libre", David, "Times New Roman", serif; }
@media (max-width: 560px) {
  .topbar-inner { flex-wrap: wrap; }
  .lang-switch { margin-left: 0; order: 3; }
}

/* ---- help ---- */
.help { overflow-y: auto; max-height: 60vh; }
.help h3 { font: 700 16px/1.3 var(--serif); margin: 14px 0 4px; }
.help ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.help li, .help p { font-size: 15px; line-height: 1.45; }
