/* Minha Biblioteca v2 — mobile-first, ~360px. Dark default, light via [data-theme="light"]. */
:root{
  --bg:#0f172a; --surface:#1e293b; --surface-2:#273449; --text:#f1f5f9; --muted:#94a3b8;
  --border:#334155; --accent:#2dd4bf; --accent-ink:#042f2e; --danger:#f87171; --warn:#fbbf24;
  --star:#fbbf24; --radius:12px; --tap:44px;
  color-scheme:dark;
}
[data-theme="light"]{
  --bg:#f1f5f9; --surface:#ffffff; --surface-2:#e2e8f0; --text:#0f172a; --muted:#64748b;
  --border:#cbd5e1; --accent:#0f766e; --accent-ink:#ffffff; --danger:#dc2626; --warn:#b45309;
  color-scheme:light;
}
*{box-sizing:border-box; margin:0; padding:0}
html{-webkit-text-size-adjust:100%}
body{
  background:var(--bg); color:var(--text);
  font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;
  font-size:16px; line-height:1.45; min-height:100dvh;
}
button{font:inherit; color:inherit; background:none; border:none; cursor:pointer; min-height:var(--tap)}
input,select,textarea{font:inherit; color:var(--text); background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:10px 12px; width:100%}
input:focus-visible,select:focus-visible,textarea:focus-visible,button:focus-visible{outline:2px solid var(--accent); outline-offset:2px}
.hidden{display:none !important}
.view{max-width:480px; margin:0 auto; padding:0 12px 96px}

/* Header */
.app-header{display:flex; align-items:center; justify-content:space-between; padding:14px 0 8px}
.brand{display:flex; align-items:center; gap:8px}
.brand-mark{font-size:26px; color:var(--accent)}
.app-header h1{font-size:20px}
.header-actions{display:flex; gap:4px}
.icon-btn{min-width:var(--tap); min-height:var(--tap); border-radius:50%; display:inline-flex; align-items:center; justify-content:center; font-size:20px; padding:0 6px}
.icon-btn:hover{background:var(--surface-2)}

/* Banners */
.banner{background:var(--surface); border:1px solid var(--accent); border-radius:var(--radius); padding:10px 12px; margin:8px 0; font-size:14px}
.banner.warn{border-color:var(--warn)}
.banner button{color:var(--accent); font-weight:700; min-height:32px; padding:0 4px}

/* Stats card */
.stats-card{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:12px; margin:8px 0 14px}
.stats-row{display:flex; justify-content:space-between; gap:8px}
.stat{display:flex; flex-direction:column; align-items:center; text-align:center; flex:1}
.stat-num{font-size:18px; font-weight:800}
.stat-label{font-size:11px; color:var(--muted)}
.goal-bar{height:8px; background:var(--surface-2); border-radius:99px; margin-top:10px; overflow:hidden}
.goal-fill{height:100%; background:var(--accent); border-radius:99px; transition:width .3s}
.goal-pace{font-size:12px; color:var(--muted); margin-top:6px; text-align:center}

/* Continue row */
.continue-section h2, .settings-body h3{font-size:16px; margin:14px 0 8px}
.continue-row{display:flex; gap:10px; overflow-x:auto; padding-bottom:6px; scrollbar-width:thin}
.continue-card{flex:0 0 104px; text-align:left}
.continue-card img{width:104px; height:156px; object-fit:cover; border-radius:8px; background:var(--surface-2); display:block}
.continue-card .cc-title{font-size:12px; font-weight:700; margin-top:4px; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden}
.continue-card .cc-prog{font-size:11px; color:var(--muted)}

/* Search / chips / toolbar */
.search-row{display:flex; gap:8px; margin:12px 0 8px}
.search-row input{flex:1}
.chips{display:flex; gap:6px; overflow-x:auto; padding:2px 0 8px; scrollbar-width:none}
.chip{flex:0 0 auto; padding:8px 14px; border-radius:99px; background:var(--surface); border:1px solid var(--border); font-size:14px; min-height:36px}
.chip.active{background:var(--accent); color:var(--accent-ink); border-color:var(--accent); font-weight:700}
.toolbar{display:flex; align-items:center; justify-content:space-between; gap:8px; margin:4px 0 10px}
.result-count{font-size:13px; color:var(--muted)}
.sort-label{font-size:13px; color:var(--muted); display:flex; align-items:center; gap:6px}
.sort-label select{width:auto; padding:6px 8px; font-size:13px}

/* Grid / list */
.grid{display:grid; grid-template-columns:repeat(3,1fr); gap:12px 8px}
.grid.list-view{grid-template-columns:1fr; gap:8px}
.book-card{text-align:left; border-radius:10px; position:relative}
.book-card img{width:100%; aspect-ratio:2/3; object-fit:cover; border-radius:8px; background:var(--surface-2); display:block}
.book-card .bc-title{font-size:12px; font-weight:700; margin-top:4px; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden}
.book-card .bc-author{font-size:11px; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.progress-track{height:5px; background:var(--surface-2); border-radius:99px; margin-top:5px; overflow:hidden}
.progress-fill{height:100%; background:var(--accent)}
.progress-track.big{height:8px}
.bc-pct{font-size:11px; color:var(--muted)}
.bc-fav{position:absolute; top:4px; right:4px; background:rgba(0,0,0,.55); color:#fff; border-radius:50%; width:32px; height:32px; min-height:32px; font-size:16px; display:flex; align-items:center; justify-content:center}
.bc-badge{position:absolute; top:4px; left:4px; background:var(--warn); color:#111; font-size:10px; font-weight:800; padding:2px 6px; border-radius:99px}
/* list mode */
.grid.list-view .book-card{display:flex; gap:10px; align-items:flex-start; background:var(--surface); border:1px solid var(--border); padding:8px}
.grid.list-view .book-card img{width:56px; flex:0 0 56px}
.grid.list-view .bc-info{flex:1; min-width:0}
.grid.list-view .bc-title{font-size:14px; margin-top:2px}
.grid.list-view .bc-author{font-size:12px}
.grid.list-view .bc-fav{position:static; background:none; color:var(--danger); width:44px; height:44px; flex:0 0 44px}
.empty-state{text-align:center; color:var(--muted); padding:32px 16px; line-height:1.6}

.add-btn{width:100%; background:var(--accent); color:var(--accent-ink); font-weight:800; font-size:17px; padding:14px; border-radius:var(--radius); margin:18px 0 8px}
.drive-hint{font-size:13px; color:var(--muted); text-align:center; padding:0 8px}
.import-progress{margin-top:10px; font-size:13px}
.import-progress .ip-row{padding:6px 0; border-bottom:1px solid var(--border)}

/* Detail */
.sub-header{display:flex; align-items:center; gap:8px; padding:12px 0}
.sub-header h2{flex:1; font-size:18px; text-align:center}
.detail-body{text-align:center; padding-bottom:24px}
.detail-cover{width:170px; aspect-ratio:2/3; object-fit:cover; border-radius:10px; background:var(--surface-2)}
.detail-body h2{font-size:20px; margin-top:12px}
.detail-author{color:var(--muted); margin:4px 0 10px}
.status-chip{display:inline-block; padding:4px 12px; border-radius:99px; background:var(--surface-2); font-size:13px; font-weight:700}
.stars{display:flex; justify-content:center; gap:4px; margin:12px 0 4px}
.stars button{font-size:30px; color:var(--muted); min-width:44px; min-height:44px; padding:0}
.stars button.on{color:var(--star)}
.detail-progress{font-size:14px; margin:10px 0 4px}
.detail-meta{font-size:13px; color:var(--muted); margin:12px 0}
.detail-actions{display:flex; gap:8px; justify-content:center; flex-wrap:wrap; margin:12px 0}
.primary-btn{background:var(--accent); color:var(--accent-ink); font-weight:800; padding:12px 20px; border-radius:var(--radius)}
.secondary-btn{background:var(--surface); border:1px solid var(--border); padding:10px 16px; border-radius:var(--radius); font-weight:600}
.secondary-btn.wide{width:100%; margin:6px 0}
.text-btn{color:var(--accent); font-size:14px; padding:8px 6px; min-height:36px}
.text-btn.danger{color:var(--danger)}
.notes-list{text-align:left; margin-top:16px}
.note-item{background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:10px 12px; margin-bottom:8px}
.note-item .ni-page{font-size:12px; color:var(--accent); font-weight:700}
.note-item .ni-quote{font-style:italic; color:var(--muted); font-size:13px; margin:4px 0}
.note-item .ni-text{font-size:14px}
.note-item .ni-del{float:right; color:var(--danger); font-size:13px; min-height:32px; padding:0 6px}

/* Reader */
#view-reader{max-width:100%; padding:0; height:100dvh; display:flex; flex-direction:column; overflow:hidden}
#view-reader.hidden{display:none !important}
.reader-topbar{display:flex; align-items:center; gap:4px; padding:6px 8px; background:var(--bg); border-bottom:1px solid var(--border); transition:opacity .3s, transform .3s; z-index:5}
.reader-topbar.chrome-hidden{opacity:0; transform:translateY(-100%); pointer-events:none}
/* Modo imersivo: some tudo, fica só a página do livro */
#view-reader.immersive .reader-topbar{opacity:0; transform:translateY(-100%); pointer-events:none}
#view-reader.immersive .reader-bottombar{opacity:0; transform:translateY(100%); pointer-events:none}
#view-reader.immersive .half-indicator, #view-reader.immersive .reader-progress-line{opacity:0; pointer-events:none}
#view-reader.immersive .page-num{opacity:0}
.half-indicator, .reader-progress-line, .page-num{transition:opacity .3s}
.reader-title{flex:1; font-size:14px; font-weight:700; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; text-align:center}
.reader-menu{position:absolute; top:56px; right:8px; left:8px; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:12px; z-index:20; box-shadow:0 8px 24px rgba(0,0,0,.4)}
.menu-row{display:flex; align-items:center; justify-content:space-between; gap:8px; padding:8px 0; font-size:14px}
.seg{display:flex; border:1px solid var(--border); border-radius:99px; overflow:hidden}
.seg-btn{padding:8px 10px; font-size:13px; min-height:36px}
.seg-btn.active{background:var(--accent); color:var(--accent-ink); font-weight:700}
.zoom-row{display:flex; align-items:center; gap:8px}
.goto-row{display:flex; gap:6px; align-items:center}
.goto-row input{width:84px; padding:8px}
.toc-panel{position:absolute; top:56px; left:8px; right:8px; max-height:60dvh; overflow:auto; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:12px; z-index:20}
.toc-panel h3{margin-bottom:8px}
.toc-panel button{display:block; width:100%; text-align:left; padding:10px 6px; border-bottom:1px solid var(--border); font-size:14px}
.reader-scroll{flex:1; overflow-y:auto; overflow-x:hidden; -webkit-overflow-scrolling:touch; position:relative; overscroll-behavior:contain}
.pages{display:flex; flex-direction:column; align-items:center; gap:10px; padding:12px 0 90px}
.page-wrap{width:100%; max-width:480px; position:relative; overflow:hidden}
.page-wrap canvas{width:100%; max-width:100%; height:auto; display:block; background:#fff; box-shadow:0 2px 10px rgba(0,0,0,.35)}
.page-num{font-size:11px; color:var(--muted); text-align:center; padding:4px 0 8px}
/* Virada de página (efeito livro): a página que chega gira como folha */
@keyframes flipNext{from{transform:perspective(1400px) rotateY(-28deg) translateX(14px); opacity:.55} to{transform:perspective(1400px) rotateY(0) translateX(0); opacity:1}}
@keyframes flipPrev{from{transform:perspective(1400px) rotateY(28deg) translateX(-14px); opacity:.55} to{transform:perspective(1400px) rotateY(0) translateX(0); opacity:1}}
.page-wrap.flip-next{animation:flipNext .38s ease-out; transform-origin:left center}
.page-wrap.flip-prev{animation:flipPrev .38s ease-out; transform-origin:right center}
.text-mode.flip-next{animation:flipNext .38s ease-out; transform-origin:left center}
.text-mode.flip-prev{animation:flipPrev .38s ease-out; transform-origin:right center}
@media (prefers-reduced-motion:reduce){.page-wrap.flip-next,.page-wrap.flip-prev,.text-mode.flip-next,.text-mode.flip-prev{animation:none}}
.text-mode{padding:16px 20px 90px; font-size:19px; line-height:1.7; max-width:480px; margin:0 auto}
.text-mode p{margin-bottom:1em}
.text-mode h2{font-size:20px; margin:18px 0 8px}
.half-indicator{position:fixed; right:12px; bottom:120px; background:var(--surface); border:1px solid var(--border); border-radius:99px; padding:6px 12px; font-size:13px; font-weight:700; z-index:6}
.reader-bottombar{background:var(--bg); border-top:1px solid var(--border); padding:8px 12px calc(10px + env(safe-area-inset-bottom)); transition:opacity .3s, transform .3s; z-index:5}
.reader-bottombar.chrome-hidden{opacity:0; transform:translateY(100%); pointer-events:none}
.reader-nav{display:flex; align-items:center; justify-content:space-between; gap:8px}
.nav-btn{padding:8px 10px; font-size:14px; font-weight:700; color:var(--accent); min-width:80px}
.page-label{font-size:14px; font-weight:700; text-align:center}
.slider-row{position:relative; margin-top:6px}
.slider-row input[type=range]{width:100%; padding:0; accent-color:var(--accent); height:32px}
.slider-bubble{position:absolute; top:-30px; transform:translateX(-50%); background:var(--accent); color:var(--accent-ink); font-size:12px; font-weight:800; padding:3px 8px; border-radius:99px; pointer-events:none}
.reader-progress-line{position:fixed; left:0; right:0; bottom:0; height:4px; background:var(--surface-2); z-index:7}
.reader-progress-line div{height:100%; background:var(--accent); width:0%}
.reader-loading{text-align:center; color:var(--muted); padding:40px 16px}
.drive-fallback{padding:16px; text-align:center}
.drive-fallback iframe{width:100%; height:60dvh; border:1px solid var(--border); border-radius:10px; background:#fff}

/* Settings / stats */
.settings-body{padding-bottom:24px}
.settings-body h3{font-size:16px; margin:20px 0 8px}
.field{display:block; font-size:14px; margin:10px 0}
.field input,.field select,.field textarea{margin-top:6px}
.switch-row{display:flex; align-items:center; justify-content:space-between}
.switch-row input{width:auto; min-height:28px; min-width:28px}
.hint{font-size:13px; color:var(--muted); line-height:1.5}
.backup-preview{background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:12px; margin:10px 0; font-size:14px}
.version{text-align:center; color:var(--muted); font-size:12px; margin-top:24px}
.stats-grid{display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-top:12px}
.stat-box{background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:14px; text-align:center}
.monthly-bars{display:flex; align-items:flex-end; gap:4px; height:110px; padding:8px 0}
.mb-bar{flex:1; display:flex; flex-direction:column; align-items:center; justify-content:flex-end; height:100%}
.mb-bar .mb-fill{width:100%; max-width:22px; background:var(--accent); border-radius:4px 4px 0 0; min-height:2px}
.mb-bar .mb-label{font-size:10px; color:var(--muted); margin-top:4px}
.mb-bar .mb-val{font-size:10px; font-weight:700}

/* Sheet */
.sheet-backdrop{position:fixed; inset:0; background:rgba(0,0,0,.6); z-index:50; display:flex; align-items:flex-end; justify-content:center}
.sheet{background:var(--bg); border:1px solid var(--border); border-radius:16px 16px 0 0; width:100%; max-width:480px; padding:18px 16px calc(18px + env(safe-area-inset-bottom))}
.sheet h3{font-size:17px; margin-bottom:6px}
.sheet-actions{display:flex; gap:10px; justify-content:flex-end; margin-top:12px}

/* Toast */
.toast{position:fixed; left:12px; right:12px; bottom:24px; z-index:100; background:var(--surface); border:1px solid var(--accent); color:var(--text); border-radius:var(--radius); padding:12px 14px; font-size:14px; text-align:center; box-shadow:0 8px 24px rgba(0,0,0,.45); max-width:480px; margin:0 auto}
@media (min-width:481px){ .view{padding-bottom:120px} }
