:root {
  color-scheme: light dark;
  --bg: #f5f5f7; --panel: #ffffff; --text: #1d1d1f; --muted: #6e6e73; --line: #d2d2d7;
  --accent: #0a66c2; --accent-text: #ffffff; --hover: #e8e8ed; --selected: #dbe7f5; --danger: #c0392b;
  --shadow: 0 1px 3px rgba(0,0,0,0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1c1c1e; --panel: #2c2c2e; --text: #f2f2f7; --muted: #9a9aa0; --line: #3a3a3c; --accent: #4ea1ff; --accent-text: #0b0b0c;
          --hover: #3a3a3c; --selected: #2e4461; --shadow: 0 1px 3px rgba(0,0,0,0.5); }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
#app { height: 100%; display: flex; flex-direction: column; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:hover { background: var(--hover); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
button.primary:hover { filter: brightness(1.1); background: var(--accent); }
button.danger { color: var(--danger); }
button.quiet { border-color: transparent; background: transparent; }
button.quiet:hover { background: var(--hover); }
button:disabled { opacity: 0.5; cursor: default; }
input[type=text], input[type=search], select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Header */
header.bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header.bar h1 { font-size: 1.1em; margin: 0 8px 0 0; font-weight: 600; }
header.bar input[type=search] { width: 260px; max-width: 100%; }

/* Library layout */
.library { display: grid; grid-template-columns: 220px 1fr; flex: 1; min-height: 0; }
.library.with-detail { grid-template-columns: 220px 1fr 340px; }
aside.sidebar { border-right: 1px solid var(--line); padding: 10px 8px; overflow: auto; background: var(--bg); }
aside.sidebar h3 { font-size: 0.75em; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 10px 4px; }
aside.sidebar .item { display: flex; justify-content: space-between; gap: 6px; width: 100%; text-align: left; border: 0; background: transparent; border-radius: 6px; padding: 6px 10px; }
aside.sidebar .item:hover { background: var(--hover); }
aside.sidebar .item.active { background: var(--selected); }
aside.sidebar .item .count { color: var(--muted); font-size: 0.85em; }
main.books { overflow: auto; padding: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
.card { background: transparent; border: 0; padding: 6px; border-radius: 10px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.card:hover { background: var(--hover); }
.card.selected { background: var(--selected); }
.cover { width: 100%; aspect-ratio: 2 / 3; background: linear-gradient(160deg, #6b7a8f, #3c4858); border-radius: 6px; box-shadow: var(--shadow); display: flex; align-items: flex-end; padding: 10px; color: #fff; font-weight: 600; overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 6px; }
.cover.placeholder span { font-size: 0.9em; text-shadow: 0 1px 2px rgba(0,0,0,0.6); }
.card .title { font-weight: 600; line-height: 1.25; }
.progressbar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.progressbar i { display: block; height: 100%; background: var(--accent); }
.formats { display: flex; gap: 4px; flex-wrap: wrap; }
.badge { font-size: 0.72em; padding: 1px 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.badge.epub { border-color: #2e8b57; color: #2e8b57; } .badge.pdf { border-color: #c0392b; color: #c0392b; }
.badge.docx { border-color: #2b579a; color: #2b579a; } .badge.html { border-color: #e67e22; color: #e67e22; } .badge.text { border-color: #7f8c8d; color: #7f8c8d; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.85em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr { cursor: pointer; }
table.list tr:hover td { background: var(--hover); }
table.list tr.selected td { background: var(--selected); }
table.list .thumb { width: 32px; height: 48px; border-radius: 3px; object-fit: cover; background: #556; display: block; }
.empty { color: var(--muted); text-align: center; padding: 60px 20px; }
.empty p { max-width: 420px; margin: 8px auto; }

/* Detail panel */
aside.detail { border-left: 1px solid var(--line); padding: 16px; overflow: auto; background: var(--panel); }
aside.detail .cover { max-width: 180px; margin: 0 auto 14px; }
aside.detail h2 { font-size: 1.15em; margin: 0 0 2px; }
aside.detail h4 { font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 0 6px; }
aside.detail .version { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
aside.detail .version .name { flex: 1; min-width: 0; }
aside.detail ul { list-style: none; margin: 0; padding: 0; }
aside.detail li { padding: 4px 0; }
aside.detail label.check { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
.bookmark { display: flex; gap: 8px; align-items: center; }
.bookmark button.open { flex: 1; text-align: left; border: 0; background: transparent; padding: 4px 0; }
.bookmark button.open:hover { text-decoration: underline; background: transparent; }

/* Sign-in */
.signin-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.signin { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); }
.signin h1 { font-size: 1.2em; margin: 0 0 4px; }
.signin p { margin: 0 0 6px; }
header.bar select[title="Account"] { max-width: 160px; }

/* Dialogs */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 0; max-width: min(760px, 95vw); width: 720px; box-shadow: 0 10px 40px rgba(0,0,0,0.3); }
dialog::backdrop { background: rgba(0,0,0,0.4); }
dialog .head { padding: 16px 20px 10px; border-bottom: 1px solid var(--line); }
dialog .head h2 { margin: 0; font-size: 1.1em; }
dialog .body { padding: 14px 20px; max-height: 60vh; overflow: auto; }
dialog .foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.review-item { padding: 10px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; }
.review-item .name { font-weight: 600; }
.review-item .explain { grid-column: 1 / -1; color: var(--muted); font-size: 0.9em; }
.review-item select { max-width: 280px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; }
.toast.error { background: var(--danger); color: #fff; }

/* Reader */
.reader { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.reader .toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.reader .toolbar .title { font-weight: 600; }
.reader .toolbar .where { color: var(--muted); font-size: 0.9em; }
.reader .stage { display: flex; flex: 1; min-height: 0; position: relative; }
.reader iframe { flex: 1; border: 0; background: var(--bg); width: 100%; height: 100%; }
.reader .drawer { width: 320px; border-right: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 10px 12px; }
.drawer h3 { font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 10px 0 6px; }
.drawer ol { list-style: none; margin: 0; padding-left: 0; }
.drawer ol ol { padding-left: 14px; }
.drawer li button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 5px 6px; border-radius: 6px; }
.drawer li button:hover { background: var(--hover); }
.drawer li button.active { background: var(--selected); }
.drawer .tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.drawer .tabs button { flex: 1; padding: 5px; }
.drawer .tabs button.active { background: var(--selected); }
.hit { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px; border-radius: 6px; border-bottom: 1px solid var(--line); }
.hit:hover { background: var(--hover); }
.hit .chapter { color: var(--muted); font-size: 0.8em; }
.hit mark { background: rgba(255, 214, 10, 0.5); color: inherit; border-radius: 2px; }
.reader .footer { display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--panel); border-top: 1px solid var(--line); font-size: 0.9em; }
.reader .footer .progressbar { flex: 1; height: 6px; cursor: pointer; }
.pages { flex: 1; overflow: auto; padding: 16px; background: var(--bg); }
.page { position: relative; width: min(100%, 900px); margin: 0 auto 16px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.35); }
.page img { width: 100%; height: 100%; display: block; }
.page .page-number { position: absolute; right: 8px; bottom: 6px; font-size: 0.75em; color: #666; background: rgba(255,255,255,0.8); padding: 1px 6px; border-radius: 4px; }
@media (prefers-color-scheme: dark) { .page img { filter: brightness(0.9); } }
.pdf-note { padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.9em; }

/* Listening bar */
.listen { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--panel); border-top: 1px solid var(--line); flex-wrap: wrap; }
.listen .now { flex: 1; min-width: 160px; }
.listen .now .what { font-weight: 600; }
.listen .sentence { color: var(--muted); font-size: 0.9em; max-height: 2.6em; overflow: hidden; }
.listen input[type=range] { width: 120px; }

@media (max-width: 900px) {
  .library, .library.with-detail { grid-template-columns: 1fr; }
  aside.sidebar { display: flex; gap: 4px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; }
  aside.sidebar h3 { display: none; }
  aside.sidebar .item { white-space: nowrap; width: auto; }
  aside.detail { border-left: 0; border-top: 1px solid var(--line); }
  .reader .drawer { position: absolute; left: 0; top: 0; bottom: 0; z-index: 5; box-shadow: var(--shadow); }
}

/* Highlights drawer */
.drawer ol.highlights li.highlight { border-left: 4px solid var(--hl, #ffd60a); border-radius: 4px; margin: 0 0 10px; padding-left: 4px; }
.drawer li.hl-yellow { --hl: #ffd60a; } .drawer li.hl-green { --hl: #34c759; } .drawer li.hl-blue { --hl: #0a84ff; }
.drawer li.hl-pink, .drawer li.hl-underline { --hl: #ff375f; }
.drawer li.hl-underline .quote { text-decoration: underline 2px var(--hl); text-underline-offset: 3px; }
.drawer li.highlight button.go { white-space: normal; }
.drawer li.highlight .quote { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.drawer li.highlight .note { margin: 4px 0 2px; font-style: italic; white-space: pre-wrap; color: var(--text); opacity: 0.85; }
.drawer li.highlight .actions { display: flex; align-items: center; gap: 4px; padding: 0 6px 2px; }
.drawer li.highlight .actions button { width: auto; display: inline-block; }
.drawer li.highlight .actions button.swatch { flex: none; width: 18px; height: 18px; min-width: 18px; padding: 0; border-radius: 50%; border: 2px solid transparent; font-size: 10px; line-height: 12px; text-align: center; }
.drawer .swatch.current { border-color: var(--text); }
.drawer .sw-yellow { background: #ffd60a; } .drawer .sw-green { background: #34c759; } .drawer .sw-blue { background: #0a84ff; } .drawer .sw-pink { background: #ff375f; }
.drawer .sw-underline { background: transparent; text-decoration: underline; color: var(--text); border-color: var(--line); }
.drawer .swatch.sw-underline.current { border-color: var(--text); }
dialog.note-editor { width: 520px; }
dialog.note-editor .quote { margin-top: 6px; font-style: italic; }
dialog.note-editor textarea { font: inherit; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); resize: vertical; }
.drawer button.export { width: 100%; margin: 0 0 10px; }

/* Dictionary card */
.define-card { position: fixed; z-index: 50; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 34px rgba(0,0,0,0.3); overflow: auto; padding: 10px 14px 12px; }
.define-card .head { position: sticky; top: -10px; background: var(--panel); padding-bottom: 4px; }
.define-card .pos { margin: 10px 0 2px; }
.define-card ol { margin: 0; padding-left: 1.3em; }
.define-card li { margin: 4px 0 6px; line-height: 1.4; }
.define-card .example { font-style: italic; opacity: 0.8; margin-top: 2px; }
.define-card .source { margin-top: 10px; text-align: right; }
.define-card .translation { white-space: pre-wrap; line-height: 1.5; margin-top: 6px; }
.define-card .languages { gap: 6px; margin: 2px 0 4px; }
.define-card .languages select { max-width: 42%; }

/* Statistics */
.stats { max-width: 900px; margin: 0 auto; padding: 18px; overflow: auto; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.stat-tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.stat-value { font-size: 1.45em; font-weight: 600; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat-chart { display: flex; align-items: flex-end; gap: 2px; height: 180px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.stat-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; min-width: 2px; }
.stat-col .bar { width: 100%; border-radius: 2px 2px 0 0; }
.stat-col .bar.reading { background: var(--accent); }
.stat-col .bar.listening { background: #ff9f0a; }
.swatch-key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 12px; }
.swatch-key.reading { background: var(--accent); margin-left: 0; } .swatch-key.listening { background: #ff9f0a; }
.stat-book { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 8px 0; }
.stat-book .progressbar { margin: 6px 0; }
.stat-finished { padding: 4px 0; gap: 10px; }

/* Reading appearance */
.appearance-panel { position: fixed; z-index: 40; top: 56px; right: 16px; width: min(330px, calc(100vw - 32px)); max-height: calc(100vh - 80px); overflow: auto;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 34px rgba(0,0,0,0.3); padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.appearance-panel .themes { display: flex; justify-content: space-between; gap: 4px; }
.appearance-panel .theme { display: flex; flex-direction: column; align-items: center; gap: 4px; border: 0; background: transparent; padding: 2px; }
.appearance-panel .theme .swatch { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 0.8em; border: 1px solid var(--line); }
.appearance-panel .theme.current .swatch { outline: 3px solid var(--accent); outline-offset: 1px; }
.appearance-panel label.row { gap: 8px; }
.stage.dark-pages .page img { filter: invert(0.9) hue-rotate(180deg); }
/* Follow-along on page images: the sentence being read aloud and its word. */
.page .speak-mark { position: absolute; pointer-events: none; border-radius: 2px; background: rgba(10, 132, 255, 0.16); }
.page .speak-mark.word { background: rgba(10, 132, 255, 0.40); }
/* Library check */
.check-row { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 6px 0; }
.check-title { font-weight: 600; }
a.button { color: inherit; text-decoration: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; }
a.button:hover { background: var(--hover); }
