/* ============ Tokens (derivados do tema: --bg, --fg, --accent) ============ */
:root {
  --bg: #f6f1e7;
  --fg: #2b2620;
  --accent: #a0522d;
  --surface: color-mix(in oklab, var(--fg) 4%, var(--bg));
  --surface-2: color-mix(in oklab, var(--fg) 8%, var(--bg));
  --elev: color-mix(in oklab, var(--fg) 2%, var(--bg));
  --line: color-mix(in oklab, var(--fg) 13%, var(--bg));
  --line-strong: color-mix(in oklab, var(--fg) 24%, var(--bg));
  --muted: color-mix(in oklab, var(--fg) 58%, var(--bg));
  --accent-soft: color-mix(in oklab, var(--accent) 15%, var(--bg));
  --accent-fg: color-mix(in oklab, var(--accent) 80%, var(--fg));
  --on-accent: #fff;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 8px 24px rgb(0 0 0 / .10);
  --shadow-lg: 0 2px 6px rgb(0 0 0 / .08), 0 24px 60px rgb(0 0 0 / .22);
  --radius: 10px;
  --ui: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --serif: 'Literata', Georgia, serif;

  --hl-yellow: rgba(250, 204, 21, .42);
  --hl-green: rgba(74, 222, 128, .38);
  --hl-blue: rgba(96, 165, 250, .40);
  --hl-pink: rgba(244, 114, 182, .40);
  --hl-orange: rgba(251, 146, 60, .42);
}
:root[data-dark="1"] {
  --elev: color-mix(in oklab, var(--fg) 7%, var(--bg));
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .35);
  --shadow-lg: 0 2px 6px rgb(0 0 0 / .3), 0 24px 60px rgb(0 0 0 / .55);
  --hl-yellow: rgba(250, 204, 21, .30);
  --hl-green: rgba(74, 222, 128, .26);
  --hl-blue: rgba(96, 165, 250, .32);
  --hl-pink: rgba(244, 114, 182, .30);
  --hl-orange: rgba(251, 146, 60, .32);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--ui);
  font-size: 1rem;
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
::selection { background: color-mix(in oklab, var(--accent) 30%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--line-strong); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

.ic { display: inline-flex; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.pad { padding: 16px; }

/* ============ Controles base ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--elev);
  font-weight: 500; font-size: .92rem; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn.primary:hover { background: color-mix(in oklab, var(--accent) 88%, #000); }
.btn.danger { background: #b42318; border-color: transparent; color: #fff; }
.btn.sm { height: 32px; padding: 0 12px; font-size: .85rem; }
.btn.xs { height: 28px; padding: 0 10px; font-size: .8rem; border-radius: 7px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 9px; border: 0; background: transparent; flex: none;
  color: color-mix(in oklab, var(--fg) 82%, var(--bg));
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }
.icon-btn.active { color: var(--accent); }
.icon-btn.sm { width: 32px; height: 32px; }

.select, input[type=text], input[type=search], textarea {
  height: 38px; border-radius: 9px; border: 1px solid var(--line); background: var(--elev); padding: 0 12px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; width: 100%; }
.select:focus, input[type=text]:focus, input[type=search]:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=range] { accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }

.search-box { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--elev); color: var(--muted); flex: 1; min-width: 0; }
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box input { border: 0; background: transparent; height: 100%; padding: 0; flex: 1; min-width: 0; color: var(--fg); box-shadow: none !important; }
.search-box.big { height: 42px; margin-bottom: 8px; }

.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); gap: 2px; }
.seg button { border: 0; background: transparent; height: 32px; min-width: 36px; padding: 0 10px; border-radius: 7px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 500; }
.seg button.on { background: var(--bg); color: var(--fg); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.seg.full { display: flex; }
.seg.full button { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field input { width: 100%; }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.bar { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* ============ Toasts, menus, modais ============ */
#toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 300; pointer-events: none; }
.toast { background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .9rem; font-weight: 500; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: none; }

.popup-menu { position: fixed; z-index: 250; min-width: 220px; padding: 6px; border-radius: 12px; background: var(--elev); border: 1px solid var(--line); box-shadow: var(--shadow-lg); animation: pop .12s ease-out; }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(-4px); } }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; padding: 9px 12px; border-radius: 8px; text-align: left; font-size: .9rem; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: #c4320a; }
:root[data-dark="1"] .menu-item.danger { color: #ff8a65; }
.menu-sep { height: 1px; background: var(--line); margin: 5px 6px; }

.modal-back { position: fixed; inset: 0; z-index: 200; background: rgb(0 0 0 / .35); display: flex; align-items: center; justify-content: center; padding: 16px; opacity: 0; transition: opacity .18s; }
.modal-back.show { opacity: 1; }
.modal { background: var(--bg); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); width: min(460px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; transform: translateY(10px) scale(.98); transition: transform .2s; }
.modal.wide { width: min(640px, 100%); }
.modal-back.show .modal { transform: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 22px; }
.modal-head h2 { margin: 0; font-size: 1.1rem; font-weight: 650; }
.modal-body { padding: 8px 22px 16px; overflow: auto; }
.modal-body > p { margin: 0 0 8px; line-height: 1.55; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px 18px; flex-wrap: wrap; }

/* ============ Biblioteca ============ */
.library { position: fixed; inset: 0; display: grid; grid-template-columns: 252px 1fr; }
.lib-side { border-right: 1px solid var(--line); background: var(--surface); padding: 18px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-family: var(--serif); font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }
.side-group { display: flex; flex-direction: column; gap: 1px; }
.side-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; text-align: left; font-size: .92rem; color: color-mix(in oklab, var(--fg) 85%, var(--bg)); position: relative; }
.side-item:hover { background: var(--surface-2); }
.side-item.active { background: var(--accent-soft); color: var(--accent-fg); font-weight: 600; }
.side-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-count { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.side-more { display: none; padding: 2px; border-radius: 6px; color: var(--muted); }
.side-item:hover .side-more { display: inline-flex; }
.side-item:hover .side-more + .side-count, .side-item:hover .side-count:has(+ .side-more) { display: none; }
.side-more:hover { background: var(--line); color: var(--fg); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 4px 4px 10px; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.side-empty { font-size: .8rem; color: var(--muted); padding: 4px 10px; margin: 0; line-height: 1.5; }
.side-sep { height: 1px; background: var(--line); margin: 14px 8px; }
.side-scrim { display: none; }

.lib-main { overflow-y: auto; padding: 0 clamp(16px, 4vw, 48px) 60px; }
.lib-header { position: sticky; top: 0; z-index: 5; background: color-mix(in oklab, var(--bg) 92%, transparent); backdrop-filter: blur(12px); padding: 22px 0 14px; margin-bottom: 8px; }
.lib-title-row { display: flex; align-items: center; gap: 12px; }
.lib-titles { flex: 1; min-width: 0; }
.lib-titles h1 { margin: 0; font-family: var(--serif); font-size: 1.8rem; font-weight: 700; letter-spacing: -.015em; line-height: 1.15; }
.lib-titles p { margin: 2px 0 0; font-size: .88rem; }
.lib-tools { display: flex; gap: 10px; margin-top: 16px; align-items: center; }
.lib-tools .search-box { max-width: 420px; }
.lib-tools .select { min-width: 0; }
.menu-btn { display: none; }

.sec-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 18px 0 14px; }

.continue-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.continue-card { display: flex; gap: 16px; align-items: center; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 14px; transition: background .15s, transform .15s, box-shadow .15s; }
.continue-card:hover { background: var(--surface-2); transform: translateY(-2px); box-shadow: var(--shadow); }
.continue-cover { width: 68px; aspect-ratio: 2/3; border-radius: 5px; overflow: hidden; flex: none; box-shadow: 0 4px 12px rgb(0 0 0 / .18); background: var(--surface-2); }
.continue-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.continue-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.continue-title { font-family: var(--serif); font-weight: 700; font-size: 1.02rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 30px 24px; }
.book-card { cursor: pointer; outline: none; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.cover-wrap { position: relative; border-radius: 4px 7px 7px 4px; transition: transform .2s, box-shadow .2s; box-shadow: 0 2px 4px rgb(0 0 0 / .1), 0 10px 22px -6px rgb(0 0 0 / .28); }
.book-card:hover .cover-wrap, .book-card:focus-visible .cover-wrap { transform: translateY(-4px); box-shadow: 0 4px 8px rgb(0 0 0 / .1), 0 18px 34px -8px rgb(0 0 0 / .38); }
.cover { aspect-ratio: 2/3; border-radius: inherit; overflow: hidden; background: var(--surface-2); position: relative; }
.cover::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, rgb(0 0 0 / .14), rgb(255 255 255 / .08) 3%, transparent 7%); pointer-events: none; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-ph { padding: 14px; font-family: var(--serif); font-weight: 700; }
.fmt { position: absolute; top: 8px; left: 8px; font-size: .62rem; font-weight: 700; letter-spacing: .06em; padding: 3px 6px; border-radius: 5px; background: rgb(0 0 0 / .55); color: #fff; backdrop-filter: blur(4px); }
.fav { position: absolute; top: 7px; right: 8px; color: #fbbf24; filter: drop-shadow(0 1px 2px rgb(0 0 0 / .5)); }
.cover-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgb(0 0 0 / .35); }
.cover-bar i { display: block; height: 100%; background: var(--accent); }
.card-more { position: absolute; right: 6px; bottom: 10px; width: 32px; height: 32px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgb(0 0 0 / .55); color: #fff; opacity: 0; transition: opacity .15s; backdrop-filter: blur(4px); }
.book-card:hover .card-more, .card-more:focus-visible { opacity: 1; }
@media (hover: none) { .card-more { opacity: 1; } }
.book-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.book-title { font-weight: 600; font-size: .92rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-author { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: .75rem; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; margin-top: 3px; }
.status.new { color: var(--accent-fg); }
.status.done { color: #2f8a4d; }
:root[data-dark="1"] .status.done { color: #6fd08f; }

.book-list { display: flex; flex-direction: column; }
.book-row { display: flex; align-items: center; gap: 16px; padding: 10px 8px; border-radius: 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.book-row:hover { background: var(--surface); }
.row-cover { width: 44px; aspect-ratio: 2/3; border-radius: 3px; overflow: hidden; flex: none; box-shadow: 0 2px 6px rgb(0 0 0 / .2); background: var(--surface-2); }
.row-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row-main .book-title { display: flex; gap: 6px; align-items: center; -webkit-line-clamp: 1; color: var(--fg); }
.row-main .book-title .ic { color: #f5b301; }
.row-main .bar { max-width: 260px; margin-top: 4px; }
.row-side { display: flex; align-items: center; gap: 16px; }
.fmt-inline { font-size: .68rem; font-weight: 700; letter-spacing: .06em; padding: 3px 7px; border-radius: 5px; background: var(--surface-2); color: var(--muted); }
.row-date { min-width: 80px; text-align: right; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 70px 20px; gap: 8px; max-width: 520px; margin: 0 auto; }
.empty h2 { margin: 10px 0 0; font-family: var(--serif); font-size: 1.5rem; }
.empty p { color: var(--muted); line-height: 1.6; margin: 4px 0 14px; }
.empty-art { width: 96px; height: 96px; border-radius: 28px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.empty-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.small-empty { padding: 40px 20px; }

.import-bar { position: fixed; bottom: 20px; right: 20px; z-index: 260; width: min(380px, calc(100vw - 32px)); background: var(--elev); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 14px 16px; display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; align-items: center; }
.import-text { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.import-prog { grid-column: 1 / -1; height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.import-prog i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.drop-overlay { position: fixed; inset: 0; z-index: 400; display: grid; place-items: center; background: color-mix(in oklab, var(--bg) 70%, transparent); backdrop-filter: blur(6px); opacity: 0; pointer-events: none; transition: opacity .15s; }
.drop-overlay.show { opacity: 1; }
.drop-box { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 48px 64px; border: 2.5px dashed var(--accent); border-radius: 24px; color: var(--accent-fg); background: var(--accent-soft); font-size: 1.1rem; text-align: center; }
.drop-box span { color: var(--muted); font-size: .9rem; }

/* Detalhes do livro */
.edit-top { display: flex; gap: 20px; }
.edit-cover { width: 130px; aspect-ratio: 2/3; border-radius: 5px; overflow: hidden; flex: none; box-shadow: var(--shadow); background: var(--surface-2); }
.edit-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.edit-fields { flex: 1; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.stat { display: flex; flex-direction: column; gap: 1px; font-size: .9rem; }
.desc { font-size: .9rem; line-height: 1.6; color: color-mix(in oklab, var(--fg) 80%, var(--bg)); max-height: 140px; overflow: auto; margin: 16px 0; }
.shelf-checks { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 8px; }

/* Marcações */
.color-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; font-size: .82rem; }
.chip.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.marks-host { display: flex; flex-direction: column; gap: 26px; padding-top: 8px; max-width: 860px; }
.marks-book-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.mini-cover { width: 38px; aspect-ratio: 2/3; border-radius: 3px; overflow: hidden; flex: none; box-shadow: 0 2px 6px rgb(0 0 0 / .2); background: var(--surface-2); }
.mini-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mark-item { display: flex; gap: 14px; width: 100%; text-align: left; border: 0; background: transparent; padding: 12px; border-radius: 10px; }
.mark-item:hover { background: var(--surface); }
.mark-bar { width: 4px; border-radius: 4px; flex: none; align-self: stretch; }
.mark-bar.hl-underline { background: var(--accent) !important; }
.mark-bar.bm { background: var(--accent); }
.mark-body { flex: 1; min-width: 0; }
blockquote { margin: 0 0 6px; font-family: var(--serif); font-size: 1rem; line-height: 1.6; }
.mark-note { display: flex; gap: 6px; align-items: flex-start; margin: 4px 0 6px; font-size: .88rem; color: color-mix(in oklab, var(--fg) 80%, var(--bg)); background: var(--surface); padding: 8px 10px; border-radius: 8px; }
.mark-note .ic { margin-top: 2px; color: var(--muted); }

.hl-yellow { background-color: var(--hl-yellow); }
.hl-green { background-color: var(--hl-green); }
.hl-blue { background-color: var(--hl-blue); }
.hl-pink { background-color: var(--hl-pink); }
.hl-orange { background-color: var(--hl-orange); }
.hl-underline { background-color: transparent; }
.dot.hl-underline, .pop-color.hl-underline { background: linear-gradient(transparent 60%, var(--accent) 60% 75%, transparent 75%); border: 1.5px solid var(--line-strong); }

/* ============ Leitor ============ */
.reader { position: fixed; inset: 0; background: var(--bg); overflow: hidden; }
.r-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--muted); z-index: 50; background: var(--bg); }
.r-stage { position: absolute; inset: 0; display: flex; flex-direction: column; transition: right .25s ease; }
.r-header, .r-footer { flex: none; height: 34px; display: flex; align-items: center; justify-content: center; padding: 0 20px; font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; letter-spacing: .01em; user-select: none; }
.r-header { padding-top: 6px; display: block; text-align: center; line-height: 34px; }
.r-footer { justify-content: space-between; padding-bottom: 4px; }
.r-footer span:first-child { overflow: hidden; text-overflow: ellipsis; }
.r-engine { flex: 1; position: relative; min-height: 0; }
.r-dim { position: absolute; inset: 0; background: #000; pointer-events: none; opacity: 0; z-index: 30; }

.r-topbar, .r-bottombar {
  position: absolute; left: 0; right: 0; z-index: 40; display: flex; align-items: center; gap: 6px; padding: 0 10px;
  background: color-mix(in oklab, var(--bg) 90%, transparent); backdrop-filter: blur(14px) saturate(1.2);
  transition: transform .25s ease, opacity .25s ease;
}
.r-topbar { top: 0; height: 58px; border-bottom: 1px solid var(--line); transform: translateY(-100%); opacity: 0; }
.r-bottombar { bottom: 0; height: 60px; border-top: 1px solid var(--line); transform: translateY(100%); opacity: 0; padding: 0 12px; }
.reader.chrome-on .r-topbar, .reader.chrome-on .r-bottombar { transform: none; opacity: 1; }
.r-titles { flex: 1; min-width: 0; padding: 0 6px; }
.r-book { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-chapter { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-actions { display: flex; gap: 2px; }
.r-slider { flex: 1; min-width: 60px; }
.r-pct { font-size: .8rem; color: var(--muted); min-width: 48px; text-align: right; font-variant-numeric: tabular-nums; }
.pdf-zoom { display: flex; align-items: center; gap: 4px; padding-left: 6px; border-left: 1px solid var(--line); margin-left: 4px; }

.r-panel { position: absolute; top: 0; right: 0; bottom: 0; width: 390px; max-width: 100%; z-index: 60; background: var(--elev); border-left: 1px solid var(--line); transform: translateX(102%); visibility: hidden; transition: transform .25s ease, visibility 0s .25s; display: flex; flex-direction: column; }
.reader.panel-open .r-panel { transform: none; visibility: visible; box-shadow: var(--shadow-lg); transition: transform .25s ease; }
.r-scrim { position: absolute; inset: 0; z-index: 55; background: rgb(0 0 0 / .25); opacity: 0; pointer-events: none; transition: opacity .25s; }
.reader.panel-open .r-scrim { opacity: 1; pointer-events: auto; }
@media (min-width: 1180px) {
  .reader.panel-open .r-stage { right: 390px; }
  .reader.panel-open .r-scrim { opacity: 0; pointer-events: none; }
  .reader.panel-open .r-topbar, .reader.panel-open .r-bottombar { right: 390px; }
  .r-topbar, .r-bottombar { transition: transform .25s ease, opacity .25s ease, right .25s ease; }
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 8px 20px; flex: none; }
.panel-head h3 { margin: 0; font-size: 1.05rem; font-weight: 650; }
.panel-body { flex: 1; overflow-y: auto; padding: 4px 16px 24px; }

.toc-book { display: flex; gap: 12px; align-items: center; padding: 6px 4px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.toc { display: flex; flex-direction: column; }
.toc-item { display: flex; justify-content: space-between; gap: 10px; text-align: left; border: 0; background: transparent; padding: 9px 14px; border-radius: 8px; font-size: .9rem; line-height: 1.35; }
.toc-item:hover:not(:disabled) { background: var(--surface-2); }
.toc-item:disabled { opacity: .5; cursor: default; }
.toc-item.current { background: var(--accent-soft); color: var(--accent-fg); font-weight: 600; }

.search-status { padding: 2px 4px 8px; }
.res-head { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 6px 6px; }
.res { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; font-size: .88rem; line-height: 1.5; color: color-mix(in oklab, var(--fg) 80%, var(--bg)); }
.res:hover { background: var(--surface-2); }
.res mark { background: var(--hl-yellow); color: var(--fg); border-radius: 2px; padding: 0 1px; }

.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 10px; margin-bottom: 14px; }
.tab { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; border: 0; background: transparent; height: 34px; border-radius: 7px; font-size: .84rem; font-weight: 500; color: var(--muted); white-space: nowrap; padding: 0 6px; }
.tab.on { background: var(--bg); color: var(--fg); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }

.notes-list { display: flex; flex-direction: column; gap: 2px; }
.note-item { display: flex; gap: 10px; align-items: stretch; padding: 4px; border-radius: 10px; }
.note-item:hover { background: var(--surface); }
.note-main { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; padding: 6px 0; }
.note-main blockquote { font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.note-actions { display: flex; flex-direction: column; opacity: 0; transition: opacity .15s; }
.note-item:hover .note-actions { opacity: 1; }
@media (hover: none) { .note-actions { opacity: 1; } }
.bm-label { font-family: var(--serif); font-size: .95rem; line-height: 1.5; margin-bottom: 4px; }
.export { margin-top: 14px; align-self: flex-start; }

/* Popup de seleção */
.sel-pop { position: fixed; z-index: 120; display: flex; align-items: center; gap: 4px; padding: 6px; border-radius: 14px; background: var(--elev); border: 1px solid var(--line); box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s; flex-wrap: wrap; max-width: calc(100vw - 16px); }
.sel-pop.show { opacity: 1; transform: none; }
.pop-colors { display: flex; gap: 6px; padding: 0 4px; }
.pop-color { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; transition: transform .1s; }
.pop-color:hover { transform: scale(1.12); }
.pop-color.on { border-color: var(--fg); }
.pop-color.hl-yellow { background: rgb(250 204 21); } .pop-color.hl-green { background: rgb(74 222 128); } .pop-color.hl-blue { background: rgb(96 165 250); }
.pop-color.hl-pink { background: rgb(244 114 182); } .pop-color.hl-orange { background: rgb(251 146 60); }
.dot.hl-yellow { background: rgb(250 204 21); } .dot.hl-green { background: rgb(74 222 128); } .dot.hl-blue { background: rgb(96 165 250); } .dot.hl-pink { background: rgb(244 114 182); } .dot.hl-orange { background: rgb(251 146 60); }
.pop-sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
.pop-note { flex-basis: 100%; font-size: .85rem; padding: 6px 8px 4px; max-width: 320px; line-height: 1.5; color: color-mix(in oklab, var(--fg) 85%, var(--bg)); }
.note-pop { flex-direction: column; align-items: stretch; width: min(380px, calc(100vw - 16px)); padding: 14px; }
.note-text { font-family: var(--serif); font-size: .95rem; line-height: 1.6; max-height: 260px; overflow: auto; }
.note-foot { display: flex; justify-content: flex-end; margin-top: 10px; }

/* ---------- Texto (EPUB/TXT) ---------- */
.flow-viewport { position: absolute; inset: 0; overflow: hidden; }
.mode-scroll .flow-viewport { overflow-y: auto; overflow-x: hidden; }
.mode-paged .flow-clip { position: absolute; top: 0; bottom: 0; overflow: hidden; }
.flow-content {
  position: absolute;
  font-family: var(--r-font);
  font-size: var(--r-size);
  font-weight: var(--r-weight);
  line-height: var(--r-lh);
  letter-spacing: var(--r-ls);
  word-spacing: var(--r-ws);
  text-align: var(--r-align);
  hyphens: var(--r-hyph);
  -webkit-hyphens: var(--r-hyph);
  column-fill: auto;
  orphans: 2; widows: 2;
  overflow-wrap: break-word;
  color: var(--fg);
  will-change: transform;
}
.mode-scroll .flow-content { position: relative; margin: 0 auto; }
.flow-content p { margin: 0 0 var(--r-ps); text-indent: var(--r-indent); }
.flow-content :is(h1, h2, h3, h4, h5, h6, hr, blockquote, .x-center, .x-noindent, figure, table) + p,
.flow-content p:first-child,
.flow-content p.x-center, .flow-content p.x-right, .flow-content p.x-noindent, .flow-content p.pre { text-indent: 0; }
.flow-content :is(h1, h2, h3) { font-weight: 700; line-height: 1.25; margin: 1.4em 0 .9em; text-align: center; hyphens: none; break-after: avoid; text-indent: 0; }
.flow-content h1 { font-size: 1.6em; }
.flow-content h2 { font-size: 1.35em; }
.flow-content h3 { font-size: 1.15em; }
.flow-content :is(h4, h5, h6) { font-size: 1em; margin: 1.2em 0 .6em; break-after: avoid; text-indent: 0; }
.flow-content h2.txt-h { font-size: 1.5em; letter-spacing: .08em; margin: 1.6em 0 1.4em; font-weight: 600; }
.flow-content > :first-child { margin-top: 0; }
.flow-content p.pre { white-space: pre-wrap; text-align: left; font-variant-numeric: tabular-nums; margin: 0; }
.flow-content hr { border: 0; margin: 1.6em auto; height: 1em; text-align: center; overflow: visible; break-after: avoid; }
.flow-content hr::after { content: '❧'; opacity: .45; font-size: .9em; }
.flow-content hr.scene::after { content: '* * *'; letter-spacing: .4em; }
.flow-content img, .flow-content svg { max-width: 100%; max-height: calc(var(--page-h) - 2.2em); height: auto; display: block; margin: .8em auto; object-fit: contain; break-inside: avoid; }
.flow-content svg { width: 100%; }
.flow-content span img, .flow-content p img { display: inline-block; margin: 0; vertical-align: middle; }
.flow-content p > img:only-child { display: block; margin: .8em auto; }
.flow-content blockquote { margin: 1em 1.5em; font-style: italic; }
.flow-content a { color: var(--accent-fg); text-decoration: none; border-bottom: 1px solid color-mix(in oklab, var(--accent) 40%, transparent); }
.flow-content sup, .flow-content sub { line-height: 0; }
.flow-content a[data-noteref] { font-weight: 600; padding: 0 2px; border: 0; }
.flow-content table { border-collapse: collapse; margin: 1em auto; font-size: .9em; break-inside: avoid; }
.flow-content td, .flow-content th { border: 1px solid var(--line); padding: 4px 8px; }
.flow-content ul, .flow-content ol { padding-left: 1.6em; }
.flow-content pre, .flow-content code { font-family: Consolas, monospace; font-size: .85em; white-space: pre-wrap; }
.flow-content figure { margin: 1em 0; break-inside: avoid; }
.flow-content figcaption { font-size: .85em; text-align: center; color: var(--muted); }
.flow-content .x-center { text-align: center; text-indent: 0; }
.flow-content .x-right { text-align: right; }
.flow-content .x-italic { font-style: italic; }
.flow-content .x-bold { font-weight: 700; }
.flow-content .x-smallcaps { font-variant: small-caps; }
.flow-content .x-upper { text-transform: uppercase; }
.flow-content .x-small { font-size: .85em; }
.flow-content .x-pagebreak { display: none; }
.flow-content mark { color: inherit; border-radius: 2px; }
.flow-content mark.hl { cursor: pointer; transition: filter .15s; padding: .08em 0; }
.flow-content mark.hl:hover { filter: brightness(.94) saturate(1.2); }
.flow-content mark.hl-underline { background: transparent; text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.flow-content mark.has-note { box-shadow: inset 0 -2px 0 color-mix(in oklab, var(--accent) 70%, transparent); }
.flow-content mark.flash { background: color-mix(in oklab, var(--accent) 35%, transparent); animation: flash 2.6s ease forwards; }
@keyframes flash { 0%, 60% { background: color-mix(in oklab, var(--accent) 35%, transparent); } 100% { background: transparent; } }
.flow-sentinel { display: inline-block; width: 1px; height: 1px; }
.flow-endnav { display: none; }
.mode-scroll .flow-endnav { display: flex; justify-content: center; padding: 20px 20px 90px; }
.flow-endnav .btn { height: auto; padding: 12px 20px; white-space: normal; text-align: left; gap: 6px; }

/* ---------- PDF ---------- */
.pdf-viewport { position: absolute; inset: 0; overflow: auto; background: var(--surface-2); }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 20px 12px 80px; min-width: min-content; }
.pdf-page { position: relative; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .15), 0 6px 16px rgb(0 0 0 / .08); flex: none; }
.pdf-page canvas { display: block; }
.pdf-page.hidden-page { display: none; }
.pdf-paged .pdf-pages { flex-direction: row; justify-content: center; min-height: 100%; padding: 12px; gap: 16px; }
.pdf-paged .pdf-viewport { overflow: auto; }
[data-pdf-filter="invert"] .pdf-page { background: #111; }
[data-pdf-filter="invert"] .pdf-page canvas { filter: invert(.9) hue-rotate(180deg) contrast(.95); }
[data-pdf-filter="sepia"] .pdf-page canvas { filter: sepia(.5) brightness(.96) contrast(.95); }
[data-pdf-filter="sepia"] .pdf-page { background: #f1e5c9; }
.hl-layer { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.pdf-hl { position: absolute; mix-blend-mode: multiply; border-radius: 2px; }
[data-pdf-filter="invert"] .pdf-hl { mix-blend-mode: screen; }
.pdf-hl.hl-underline { background: transparent; border-bottom: 2px solid var(--accent); }
.textLayer { position: absolute; inset: 0; overflow: hidden; line-height: 1; text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; z-index: 2; opacity: 1; }
.textLayer span, .textLayer br { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; }
.textLayer span.markedContent { top: 0; height: 0; }
.textLayer ::selection { background: rgb(0 90 255 / .28); }
.textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: -1; cursor: default; user-select: none; }
.textLayer.selecting .endOfContent { top: 0; }
.textLayer span.flash-span { background: color-mix(in oklab, var(--accent) 40%, transparent); border-radius: 2px; transition: background 1s; }

/* ============ Configurações ============ */
.settings .settings-body { display: flex; flex-direction: column; gap: 18px; }
.ctl { display: flex; flex-direction: column; gap: 8px; }
.ctl-head { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 600; }
.ctl-head .val { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.ctl-row { display: flex; align-items: center; gap: 10px; }
.ctl-row input[type=range] { flex: 1; min-width: 0; }
.step { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--elev); font-size: 1.05rem; line-height: 1; flex: none; display: grid; place-items: center; }
.step:hover { background: var(--surface-2); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; font-size: .9rem; font-weight: 500; }
.toggle > span { display: flex; flex-direction: column; }
.toggle small { font-weight: 400; font-size: .78rem; }
.toggle input { display: none; }
.toggle i { width: 40px; height: 24px; border-radius: 999px; background: var(--line-strong); position: relative; flex: none; transition: background .2s; }
.toggle i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: transform .2s; }
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(16px); }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 10px; }
.theme-sw { position: relative; aspect-ratio: 1 / 1.05; border-radius: 12px; border: 1px solid rgb(0 0 0 / .12); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; transition: transform .12s; padding: 6px; }
.theme-sw:hover { transform: translateY(-2px); }
.theme-sw.on { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.theme-sw .aa { font-size: 1.5rem; font-weight: 600; line-height: 1; }
.theme-sw .tn { font-size: .72rem; font-weight: 500; opacity: .85; }
.theme-sw .acc { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; }
.theme-sw.add { background: transparent; border: 1.5px dashed var(--line-strong); color: var(--muted); }
.theme-edit { position: absolute; bottom: 5px; right: 5px; padding: 3px; border-radius: 6px; background: rgb(0 0 0 / .12); display: inline-flex; }
.theme-editor .color-row { display: flex; gap: 12px; margin-bottom: 10px; }
.color-field { display: flex; align-items: center; gap: 8px; flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 10px; font-size: .85rem; }
.color-field input { width: 32px; height: 32px; border: 0; padding: 0; background: none; border-radius: 6px; cursor: pointer; }
.theme-preview { margin-top: 12px; padding: 18px; border-radius: 12px; border: 1px solid var(--line); font-family: var(--serif); line-height: 1.6; }
.theme-preview p { margin: 6px 0; }
.font-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.font-opt { border: 1px solid var(--line); background: var(--elev); border-radius: 9px; padding: 9px 10px; text-align: left; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-opt:hover { background: var(--surface-2); }
.font-opt.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-fg); }
.font-extra { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.font-extra input { width: 100%; }
.font-extra .btn { align-self: flex-start; }
.set-sub { margin: 6px 0 -6px; font-size: .75rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ Responsivo ============ */
@media (max-width: 820px) {
  .library { grid-template-columns: 1fr; }
  .lib-side { position: fixed; top: 0; bottom: 0; left: 0; width: min(290px, 86vw); z-index: 90; transform: translateX(-102%); visibility: hidden; transition: transform .25s ease, visibility 0s .25s; }
  .library.side-open .lib-side { transform: none; visibility: visible; box-shadow: var(--shadow-lg); transition: transform .25s ease; }
  .side-scrim { display: block; position: fixed; inset: 0; z-index: 80; background: rgb(0 0 0 / .3); opacity: 0; pointer-events: none; transition: opacity .25s; }
  .library.side-open .side-scrim { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-flex; margin-left: -8px; }
  .lib-titles h1 { font-size: 1.45rem; }
  .side-more { display: inline-flex; }
}
@media (max-width: 600px) {
  .lib-main { padding: 0 16px 60px; }
  .lib-header { padding: 14px 0 10px; }
  .lib-tools { flex-wrap: wrap; margin-top: 12px; gap: 8px; }
  .lib-tools .search-box { flex-basis: 100%; max-width: none; }
  .lib-tools .select { flex: 1; }
  .add-btn > span:not(.ic) { display: none; }
  .add-btn { width: 40px; padding: 0; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 22px 14px; }
  .book-title { font-size: .84rem; }
  .continue-row { grid-template-columns: 1fr; }
  .continue-card { padding: 10px; }
  .row-date, .fmt-inline { display: none; }
  .edit-top { flex-direction: column; align-items: center; }
  .edit-cover { width: 110px; }
  .modal-body { padding: 8px 16px 14px; }
  .modal-foot { padding: 10px 16px 16px; }

  .r-topbar { height: 54px; padding: 0 4px; }
  .r-actions .hide-narrow { display: none; }
  .r-actions .icon-btn { width: 36px; }
  .r-bottombar { padding: 0 6px; gap: 2px; }
  .pdf-zoom .btn { display: none; }
  .r-panel { width: 100%; border-left: 0; }
  .r-header { font-size: .72rem; }
  .r-footer { padding: 0 14px 4px; }
  .theme-grid { grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); }
  .font-list { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 380px) {
  .r-book { font-size: .85rem; }
  .r-actions .icon-btn { width: 32px; }
  .book-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============ Web: login, sincronização, notas, histórico ============ */
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
.login-screen { position: fixed; inset: 0; z-index: 500; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; padding: 32px 28px 24px; border: 1px solid var(--line); border-radius: 20px; background: var(--elev); box-shadow: var(--shadow); }
.login-brand { padding: 0 0 4px; justify-content: center; font-size: 1.6rem; }
.login-sub { text-align: center; margin: 0 0 22px; }
.login-card input { width: 100%; height: 44px; font-size: 1rem; }
.login-btn { height: 46px; margin-top: 4px; font-size: 1rem; }
.login-msg { min-height: 1.2em; margin: 0 0 10px; font-size: .88rem; color: var(--muted); }
.login-msg.err { color: #c4320a; }
:root[data-dark="1"] .login-msg.err { color: #ff8a65; }
.link-btn { border: 0; background: none; color: var(--accent-fg); margin-top: 14px; font-size: .88rem; }
.link-btn:hover { text-decoration: underline; }
input[type=email], input[type=password], input[type=date] { height: 38px; border-radius: 9px; border: 1px solid var(--line); background: var(--elev); padding: 0 12px; outline: none; color: var(--fg); }
input[type=email]:focus, input[type=password]:focus, input[type=date]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.side-foot { margin-top: auto; padding: 16px 6px 2px; display: flex; flex-direction: column; gap: 10px; }
.side-user { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.side-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sync-badge { font-size: .76rem; color: var(--muted); display: flex; align-items: center; gap: 7px; padding: 0 4px; }
.sync-badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #3aa35b; flex: none; }
.sync-badge.s-saving::before { background: #e0a400; }
.sync-badge.s-offline::before { background: #9a9a9a; }

.stars { display: inline-flex; gap: 1px; vertical-align: middle; }
.star {
  --f: 0%; display: inline-block; flex: none;
  background: linear-gradient(90deg, #f5b301 var(--f), color-mix(in oklab, var(--fg) 18%, var(--bg)) var(--f));
  -webkit-mask: var(--star-mask) center / contain no-repeat;
  mask: var(--star-mask) center / contain no-repeat;
}
:root { --star-mask: url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 24 24%22%3E%3Cpath d=%22m12 2 3.1 6.3 6.9 1-5 4.9 1.2 6.8L12 17.8 5.8 21l1.2-6.8-5-4.9 6.9-1z%22/%3E%3C/svg%3E"); }
.star-wrap { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.star-input { display: inline-flex; gap: 4px; cursor: pointer; outline: none; touch-action: manipulation; }
.star-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.star-input .star { transition: transform .1s; }
.star-input .star:hover { transform: scale(1.1); }
.star-label { font-size: .88rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.meta-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.meta-line .status { margin-top: 0; }
.book-meta .meta-line { margin-top: 3px; }
.date-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rate-quick { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.rate-quick textarea { width: 100%; }
.rate-quick p { margin: 0; }
.rate-book { display: flex; gap: 12px; align-items: center; }

.sync-banner {
  position: absolute; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 70;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center;
  padding: 10px 12px 10px 16px; border-radius: 14px; background: var(--elev); border: 1px solid var(--line); box-shadow: var(--shadow-lg);
  font-size: .88rem; width: max-content; max-width: calc(100vw - 24px);
}
.sync-actions { display: flex; gap: 6px; }

.hist { display: flex; flex-direction: column; gap: 8px; max-width: 980px; }
.hist-loading { display: flex; align-items: center; gap: 12px; color: var(--muted); padding: 40px 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-top: 4px; }
.stat-card { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.stat-label { font-size: .78rem; color: var(--muted); font-weight: 600; }
.stat-value { font-family: var(--serif); font-size: 1.7rem; line-height: 1.15; font-weight: 700; letter-spacing: -.01em; }
.stat-sub { font-size: .78rem; color: var(--muted); }
.hist-sec { margin-top: 18px; }
.hist-sec .sec-title { margin-top: 8px; }
.heat-wrap { overflow-x: auto; padding-bottom: 6px; }
.heat-months, .heat-grid { display: grid; gap: 3px; min-width: 420px; }
.heat-months { font-size: .68rem; color: var(--muted); margin-bottom: 4px; }
.heat-months span { white-space: nowrap; overflow: visible; }
.heat-grid { grid-template-rows: repeat(7, auto); }
.heat { display: block; aspect-ratio: 1; border-radius: 3px; background: var(--surface-2); min-width: 10px; }
.heat.l-1 { background: transparent; }
.heat.l1 { background: color-mix(in oklab, var(--accent) 28%, var(--bg)); }
.heat.l2 { background: color-mix(in oklab, var(--accent) 50%, var(--bg)); }
.heat.l3 { background: color-mix(in oklab, var(--accent) 75%, var(--bg)); }
.heat.l4 { background: var(--accent); }
.heat-legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 8px; }
.heat-legend .heat { width: 11px; min-width: 11px; }
.year-head { display: flex; align-items: baseline; gap: 10px; margin: 14px 0 10px; font-family: var(--serif); font-size: 1.15rem; }
.done-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 18px 14px; }
.done-card { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; text-align: left; border: 0; background: transparent; padding: 0; min-width: 0; }
.done-cover { width: 100%; aspect-ratio: 2/3; border-radius: 4px; overflow: hidden; box-shadow: 0 2px 4px rgb(0 0 0 / .1), 0 8px 18px -6px rgb(0 0 0 / .3); background: var(--surface-2); transition: transform .15s; }
.done-card:hover .done-cover { transform: translateY(-3px); }
.done-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.done-title { font-size: .84rem; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rate-cta { font-size: .76rem; color: var(--accent-fg); font-weight: 600; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 4px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.day-head strong::first-letter { text-transform: uppercase; }
.sess { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 6px; border-radius: 10px; }
.sess:hover:not(:disabled) { background: var(--surface); }
.sess-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sess-main strong { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Áreas seguras (iPhone com notch, barra de gestos do Android) */
.r-topbar { padding-top: env(safe-area-inset-top); height: calc(58px + env(safe-area-inset-top)); }
.r-bottombar { padding-bottom: env(safe-area-inset-bottom); height: calc(60px + env(safe-area-inset-bottom)); }
.r-header { padding-top: max(6px, env(safe-area-inset-top)); height: calc(34px + env(safe-area-inset-top)); }
.r-footer { padding-bottom: max(4px, env(safe-area-inset-bottom)); height: calc(30px + env(safe-area-inset-bottom)); }
.lib-header { padding-top: max(22px, env(safe-area-inset-top)); }
.lib-side { padding-top: max(18px, env(safe-area-inset-top)); padding-bottom: max(18px, env(safe-area-inset-bottom)); }
.r-panel { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
@media (max-width: 600px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 12px 14px; }
  .stat-value { font-size: 1.35rem; }
  .done-row { grid-template-columns: repeat(3, 1fr); gap: 14px 10px; }
  .date-row { grid-template-columns: 1fr; gap: 0; }
  .r-topbar { height: calc(54px + env(safe-area-inset-top)); }
  .lib-header { padding-top: max(14px, env(safe-area-inset-top)); }
}
