:root {
  --bg: #f6f6f4; --fg: #1b1b1b; --muted: #6b6b6b; --bar: #ffffff; --line: #e2e2df;
  --accent: #3f51b5; --accent-fg: #fff; --card: #fff; --hover: #eeeef3; --mark: #ffe58a;
  --accent-soft: rgba(63, 81, 181, .1); --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 18px rgba(0,0,0,.08);
  color-scheme: light;
}
:root[data-theme="sepia"] {
  --bg: #efe6d0; --fg: #4a3a2a; --muted: #7d6a55; --bar: #f4ecd8; --line: #dccfb4;
  --accent: #8a5a2b; --card: #f8f1e0; --hover: #e9dfc6; --mark: #f1d27a; --accent-soft: rgba(138, 90, 43, .12);
}
:root[data-theme="dark"] {
  --bg: #161616; --fg: #dcdcdc; --muted: #9a9a9a; --bar: #1f1f1f; --line: #333;
  --accent: #8ab4f8; --accent-fg: #101010; --card: #242424; --hover: #2c2c2c; --mark: #6b5a12;
  --accent-soft: rgba(138, 180, 248, .14); --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--fg);
}
button {
  font: inherit; color: inherit; background: transparent; border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 10px; cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--hover); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.active { outline: 2px solid var(--accent); }
button:focus-visible, a:focus-visible, .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .5; cursor: default; }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
button.tb { display: inline-flex; align-items: center; gap: 6px; border-color: transparent; padding: 6px 9px; }
button.tb:hover { background: var(--hover); }
button.tb.on { background: var(--accent-soft); color: var(--accent); }
#btn-bookmark.marked { color: var(--accent); }
#btn-bookmark.marked svg path { fill: currentColor; }
.tabs { margin-bottom: 10px; }
.bm { display: flex; gap: 8px; align-items: flex-start; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.bm:hover { background: var(--hover); }
.bm .ic { flex: none; width: 16px; height: 16px; margin-top: 2px; color: var(--accent); }
.bm .ic path { fill: currentColor; }
.bm .b-body { flex: 1; min-width: 0; }
.bm .b-ch { font-weight: 600; font-size: 13px; }
.bm .b-ex { font-size: 13px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.bm .del { border-color: transparent; padding: 0 6px; opacity: .6; }
.bm .del:hover { opacity: 1; }
.dict h3 { margin: 0 0 2px; font-size: 20px; }
.dict .pos { margin: 12px 0 4px; font-style: italic; color: var(--muted); }
.dict ol { margin: 0; padding-left: 20px; }
.dict li { margin: 0 0 6px; line-height: 1.45; }
.dict .ex { display: block; color: var(--muted); font-style: italic; }
.dict .src { margin-top: 14px; font-size: 12px; }
.dict button.linkish { color: var(--accent); text-decoration: underline; padding: 0 2px; }
button.aa { font-weight: 700; font-size: 15px; min-width: 38px; justify-content: center; }
button.linkish { border-color: transparent; padding: 4px 8px; }
button.linkish:hover, button.linkish.on { background: var(--hover); color: var(--fg); }
.badge { font-size: 11px; font-weight: 600; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); text-align: center; line-height: 18px; }
button.pro::after { content: "PRO"; font-size: 9px; margin-left: 5px; padding: 1px 4px; border-radius: 3px; background: var(--accent); color: var(--accent-fg); vertical-align: middle; }
button.pro.unlocked::after { content: none; }
button.pro.trial:not(.unlocked)::after { content: "TRY"; }   /* free read-aloud minutes left today (0.3.1) */
.pro-box .trial-note { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; margin: 4px 0 10px; }
.pro-tag { font-size: 9px; padding: 1px 4px; border-radius: 3px; background: var(--accent); color: var(--accent-fg); }
input, select, textarea { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.screen { height: 100%; }

/* Library */
#library { display: flex; flex-direction: column; overflow: auto; }
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 28px; border-bottom: 1px solid var(--line); background: var(--bar); }
.lib-brand { display: flex; align-items: center; gap: 12px; }
.lib-brand h1 { font-size: 20px; margin: 0; }
.lib-brand p { margin: 2px 0 0; }
.lib-actions { display: flex; gap: 8px; }
.notice { margin: 16px 28px 0; padding: 12px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.notice p { margin: 0; flex: 1 1 300px; }
.rate-bar { padding: 8px 12px 8px 16px; gap: 8px; border-left: 3px solid var(--accent); }
.rate-bar button:not(.primary) { color: var(--muted); }
.lib-section { display: flex; align-items: center; gap: 10px; padding: 22px 28px 0; flex-wrap: wrap; }
.lib-section select { padding: 4px 8px; }
button.chip { border-radius: 999px; padding: 4px 12px; color: var(--muted); }
button.chip.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.lib-hint { grid-column: 1 / -1; margin: 8px 0; }
.card .fav { position: absolute; top: 6px; left: 6px; padding: 0 6px; border-radius: 50%; background: var(--bar); opacity: 0; color: var(--muted); font-size: 15px; line-height: 22px; }
.card:hover .fav, .card .fav.on { opacity: 1; }
.card .fav.on { color: #f2b01e; }
.card.trashed { cursor: default; }
.card.trashed .cover { opacity: .55; filter: grayscale(.6); }
.card .row { display: flex; gap: 6px; margin-top: 6px; }
.card .row button { padding: 3px 8px; font-size: 12px; }
button.danger { color: #c62828; border-color: #c6282855; }
#toast button.linkish { color: #9ec1ff; text-decoration: underline; padding: 0 4px; }
.lib-section h2 { font-size: 16px; margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px; padding: 16px 28px 28px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; position: relative; transition: transform .15s, box-shadow .15s; }
.card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
#lib-continue { margin: 22px 28px 0; }
.continue { display: flex; gap: 20px; align-items: center; padding: 16px 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); box-shadow: var(--shadow); cursor: pointer; }
.continue .cover { width: 72px; aspect-ratio: 2 / 3; flex: none; border-radius: 4px; overflow: hidden; background: var(--hover); display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.continue .cover img { width: 100%; height: 100%; object-fit: cover; }
.continue .cover .initials { font-size: 20px; font-weight: 600; color: var(--muted); }
.continue .body { flex: 1; min-width: 0; }
.continue .kicker { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
.continue .t { font-size: 18px; font-weight: 600; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue .where { font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue .bar { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 10px; max-width: 420px; }
.continue .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.continue button { flex: none; padding: 8px 18px; }
.card .cover { aspect-ratio: 2 / 3; background: var(--hover); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.card .cover img { width: 100%; height: 100%; object-fit: cover; }
.card .cover .initials { font-size: 34px; font-weight: 600; color: var(--muted); padding: 12px; text-align: center; }
.card .info { padding: 8px 10px 10px; }
.card .t { font-weight: 600; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .a { font-size: 12px; margin-top: 2px; }
.card .prog { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card .bar { flex: 1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.card .bar i { display: block; height: 100%; background: var(--accent); }
.card .prog.new { color: var(--accent); font-weight: 600; }
.card .prog.new .bar { display: none; }
.card .del { position: absolute; top: 6px; right: 6px; padding: 0 7px; border-radius: 50%; background: var(--bar); opacity: 0; }
.card:hover .del { opacity: 1; }
.empty { padding: 48px 28px; display: flex; justify-content: center; }
.drop-zone { max-width: 560px; width: 100%; text-align: center; padding: 40px 32px 32px; border: 2px dashed var(--line); border-radius: 16px; background: var(--card); }
.drop-zone .ic.big { width: 56px; height: 56px; stroke-width: 1.3; color: var(--accent); }
.drop-zone h2 { margin: 12px 0 6px; font-size: 22px; }
.drop-zone p { margin: 6px 0; }
button.big { font-size: 15px; padding: 10px 22px; margin: 10px 0 6px; }
.ways { list-style: none; padding: 0; margin: 18px 0 0; font-size: 13px; }
.ways li { padding: 3px 0; }
.drop-zone .free { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; }
.drop-zone a { color: var(--accent); }

/* Reader */
#reader { display: flex; flex-direction: column; position: relative; }
#topbar, #navbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--bar); border-bottom: 1px solid var(--line); z-index: 3; }
#navbar { border-bottom: 0; border-top: 1px solid var(--line); }
#topbar { gap: 4px; }
#topbar .title { font-weight: 600; margin-left: 4px; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#chapter-label { max-width: 24vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#book-area { flex: 1; min-height: 0; position: relative; }
foliate-view { display: block; width: 100%; height: 100%; }
#progress-wrap { flex: 1; position: relative; display: flex; align-items: center; }
#progress { flex: 1; accent-color: var(--accent); cursor: pointer; margin: 0; }
#chapter-marks { position: absolute; left: 8px; right: 8px; top: 50%; height: 0; pointer-events: none; }
#chapter-marks i { position: absolute; top: -7px; width: 2px; height: 5px; border-radius: 1px; background: var(--muted); opacity: .55; transform: translateX(-1px); }
#lightbox { position: fixed; inset: 0; z-index: 80; background: rgba(12,12,12,.96); display: flex; flex-direction: column; }
#lightbox[hidden] { display: none; }
#lightbox .lb-bar { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 10px; color: #eee; }
#lightbox .lb-bar button { color: #eee; border-color: #ffffff40; background: #ffffff14; }
#lightbox .lb-bar span { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
#lightbox .lb-stage { flex: 1; overflow: auto; display: grid; place-items: center; padding: 12px; }
#lb-img { transition: transform .15s; max-width: none; background: #fff; }
#lb-img.fit { max-width: calc(100vw - 40px); max-height: calc(100vh - 90px); }
#book-area { position: relative; }
#ruler { position: absolute; left: 0; right: 0; top: 0; bottom: 0; pointer-events: none; z-index: 2; }
#ruler.ruler-line::before { content: ""; position: absolute; left: 0; right: 0; top: var(--ruler-top, 40%); height: var(--ruler-h, 28px); background: var(--accent-soft); border-top: 2px solid var(--accent); border-bottom: 2px solid var(--accent); opacity: .7; }
#ruler.ruler-focus::before, #ruler.ruler-focus::after { content: ""; position: absolute; left: 0; right: 0; background: rgba(0,0,0,.42); }
#ruler.ruler-focus::before { top: 0; height: var(--ruler-top, 40%); }
#ruler.ruler-focus::after { top: calc(var(--ruler-top, 40%) + var(--ruler-h, 28px)); bottom: 0; }
#btn-prev, #btn-next { font-size: 18px; line-height: 1; padding: 4px 12px; border-color: transparent; }
#progress-text { min-width: 200px; text-align: right; white-space: nowrap; }

#panel {
  position: absolute; top: 45px; right: 0; bottom: 0; width: 380px; max-width: 100%;
  background: var(--bar); border-left: 1px solid var(--line); z-index: 4; display: flex; flex-direction: column;
  box-shadow: -4px 0 16px rgba(0,0,0,.08); animation: slide-in .14s ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
#panel > header { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
#panel-body { flex: 1; overflow: auto; padding: 10px 12px; }
#panel-body ol[role="tree"], #panel-body ol[role="group"] { list-style: none; margin: 0; padding: 0; }
#panel-body [role="treeitem"] { display: block; padding: 5px 8px; border-radius: 6px; text-decoration: none; color: inherit; cursor: pointer; }
#panel-body [role="treeitem"]:hover { background: var(--hover); }
#panel-body [role="treeitem"][aria-current] { background: var(--hover); font-weight: 600; color: var(--accent); }
#panel-body [role="treeitem"] svg { fill: currentColor; margin-right: 4px; transition: transform .1s; }
#panel-body [role="treeitem"][aria-expanded="false"] svg { transform: rotate(-90deg); }
#panel-body [role="treeitem"][aria-expanded="false"] + ol { display: none; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.field label { flex: 1; }
.seg { display: flex; gap: 4px; }
.seg button { padding: 4px 9px; }
.seg button.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.section-title { font-weight: 600; margin: 14px 0 6px; }
.kbd { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kbd kbd { font-family: ui-monospace, Consolas, monospace; background: var(--hover); padding: 1px 5px; border-radius: 4px; }

/* Search */
.search-box { display: flex; gap: 6px; margin-bottom: 8px; }
.search-box input { flex: 1; }
.result-group { margin: 10px 0 4px; }
.result-group .gt { font-weight: 600; margin-bottom: 4px; }
a.result { display: block; padding: 5px 8px; border-radius: 6px; color: inherit; text-decoration: none; font-size: 13px; line-height: 1.35; }
a.result:hover { background: var(--hover); }
a.result.on { background: var(--accent-soft); box-shadow: inset 3px 0 var(--accent); }
a.result mark { background: var(--mark); color: inherit; padding: 0 1px; }

/* Highlights */
.hl { padding: 9px 10px; border: 1px solid var(--line); border-left: 4px solid; border-radius: 6px; background: var(--card); margin-bottom: 8px; cursor: pointer; }
.hl:hover { background: var(--hover); }
.hl .c { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hl .edit { font-size: 11px; padding: 1px 8px; color: var(--muted); }
.hl .edit:hover { color: var(--accent); }
.hl-empty { text-align: center; padding: 28px 12px; }
.hl-empty .ic { width: 36px; height: 36px; color: var(--accent); stroke-width: 1.4; }
.hl .q { font-size: 13px; }
.hl .n { font-size: 12px; margin-top: 4px; color: var(--muted); white-space: pre-wrap; }
.hl .c { font-size: 11px; color: var(--muted); margin-top: 3px; }
#sel-toolbar, #tts-bar {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 52px; z-index: 5;
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 10px;
  background: var(--bar); border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0,0,0,.15);
}
#sel-toolbar { gap: 4px; padding: 5px 6px 5px 10px; }
#sel-toolbar.placed { transform: none; bottom: auto; animation: pop .12s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } }
#sel-toolbar .swatch { margin-right: 2px; transition: transform .1s; }
#sel-toolbar .swatch:hover { transform: scale(1.15); }
#sel-toolbar .sep { width: 1px; align-self: stretch; margin: 2px 4px; background: var(--line); }
#tts-bar { bottom: auto; top: 54px; }
#tts-bar select { padding: 4px 6px; }
#tts-status { white-space: nowrap; }
#tts-voice { max-width: 190px; }
#tts-status:empty { display: none; }

/* Aa: display settings in a small popover under the button, the page stays visible */
#display-pop {
  position: absolute; top: 48px; right: 10px; z-index: 6; width: 360px; max-height: calc(100vh - 120px); overflow: auto; padding: 14px 16px 10px;
  background: var(--bar); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18);
  animation: pop .12s ease-out;
}
#display-pop .size { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
#display-pop .size button { flex: 1; font-weight: 600; padding: 7px 0; }
#display-pop .size button.big { font-size: 19px; }
#display-pop .size span { min-width: 56px; text-align: center; font-variant-numeric: tabular-nums; }
.themes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 8px; }
.themes button { padding: 7px 0; border-width: 2px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.themes button.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.field.col { flex-direction: column; align-items: stretch; gap: 6px; }
.range { display: inline-flex; align-items: center; gap: 8px; }
.range input { width: 130px; accent-color: var(--accent); }
.range output { min-width: 34px; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
#book-area { transition: filter .15s; }
#display-pop .field:last-child { border-bottom: 0; }
#display-pop .seg button { padding: 4px 8px; }
.swatch { width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 2px solid var(--line); }
.swatch[data-color="yellow"] { background: #ffd54f; }
.swatch[data-color="green"] { background: #81c784; }
.swatch[data-color="blue"] { background: #64b5f6; }
.swatch[data-color="pink"] { background: #f48fb1; }
.editor textarea { width: 100%; min-height: 80px; margin: 6px 0; }
.editor .q { font-style: italic; background: var(--card); padding: 8px; border-radius: 6px; }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* Stats */
.stat { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.stat b { font-variant-numeric: tabular-nums; }
.days { margin-top: 10px; }
.days div { display: grid; grid-template-columns: 90px 1fr 50px; gap: 8px; align-items: center; font-size: 12px; padding: 2px 0; }
.days i { display: block; height: 8px; background: var(--accent); border-radius: 4px; }

/* Pro */
.pro-box h2 { margin: 6px 0; }
.pro-box ul { list-style: none; padding: 0; margin: 12px 0 16px; }
.pro-box li { position: relative; padding: 5px 0 5px 28px; }
.pro-box li::before { content: "✓"; position: absolute; left: 0; top: 4px; width: 19px; height: 19px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; text-align: center; line-height: 19px; }
.pro-box .offer { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: var(--card); }
.pro-box .offer .muted { font-size: 12px; margin: 8px 0 0; }
#btn-get-pro { width: 100%; padding: 10px; font-size: 15px; font-weight: 600; }
.pro-box details.license { margin-top: 16px; }
.pro-box details.license summary { cursor: pointer; }
.pro-box details.license[open] summary { margin-bottom: 8px; }
.pro-box .fine { font-size: 12px; }
.pro-box .price { font-size: 24px; font-weight: 700; margin: 0 0 10px; }
.pro-box .license-error { color: #c62828; margin: 8px 0 0; min-height: 1em; }
.pro-box .license-error:empty { display: none; }
.pro-box .license-label { font-weight: 600; }

#drop-overlay { position: fixed; inset: 0; background: rgba(63,81,181,.25); z-index: 50; display: flex; align-items: center; justify-content: center; border: 4px dashed var(--accent); }
#drop-overlay div { background: var(--bar); padding: 18px 26px; border-radius: 10px; font-size: 18px; }
@media (max-width: 960px) {
  #topbar button.tb span { display: none; }
  #chapter-label { display: none; }
  #topbar .title { max-width: 45vw; }
}
/* narrow windows and phones (the web version opened from Drive on a phone, a half-width window) */
@media (max-width: 640px) {
  .lib-head { flex-wrap: wrap; gap: 12px; padding: 14px 16px; }
  .lib-brand { flex: 1 1 100%; }
  .lib-brand img { width: 30px; height: 30px; }
  .lib-actions { flex-wrap: wrap; }
  .notice, #lib-continue { margin-left: 16px; margin-right: 16px; }
  .lib-section { padding-left: 16px; padding-right: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; padding: 14px 16px 24px; }
}
#toast { position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 60; max-width: 80vw; }
[hidden] { display: none !important; }

/* web version (web/shim.js sets html.web): things only the extension can do */
.web .ext-only { display: none !important; }
.notice a.btn-link { align-self: center; margin: 0 6px; font-weight: 600; }
