/* Shiori 栞 — escuro, calmo, só o conteúdo. Espaços: 4 8 12 16 24 32 48 */
:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1e252e;
  --line: #262e39;
  --text: #ece8e1;
  --muted: #8d96a3;
  --faint: #7f8998;
  --accent: #e2a66e;
  --radius: 10px;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Hiragino Sans", "Segoe UI", system-ui, sans-serif;
  --serif: ui-serif, "New York", "Hiragino Mincho ProN", Georgia, serif;
  --ease: cubic-bezier(.22, .8, .24, 1);
  --sa-t: env(safe-area-inset-top); --sa-b: env(safe-area-inset-bottom);
  --sa-l: env(safe-area-inset-left); --sa-r: env(safe-area-inset-right);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
body { min-height: 100dvh; -webkit-user-select: none; user-select: none; }
body.reading { overflow: hidden; position: fixed; inset: 0; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.muted { color: var(--muted); font-size: 15px; }
.faint { color: var(--faint); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 24px;
  border-radius: 999px; background: var(--surface-2); font-weight: 600; font-size: 17px;
  transition: transform 160ms var(--ease), background 160ms;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #1b1309; }
.icon {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 999px; flex: none;
  transition: background 160ms;
}
.icon:active { background: rgba(255,255,255,.08); }
.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.link { color: var(--faint); font-size: 13px; padding: 8px 0; }
.link:active { color: var(--muted); }

/* ---------- primeira abertura ---------- */
.empty {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: calc(48px + var(--sa-t)) 32px calc(48px + var(--sa-b)); text-align: center;
  background: radial-gradient(120% 70% at 50% 0%, #17202b 0%, var(--bg) 60%);
}
.empty-mark { width: 88px; height: 120px; border-radius: 8px; background: var(--surface); position: relative; margin-bottom: 16px;
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 24px 48px -16px rgba(0,0,0,.6); }
.ribbon { position: absolute; top: -6px; right: 18px; width: 14px; height: 64px; background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%); }
.empty-title { font: 500 34px/1.1 var(--serif); margin: 0; letter-spacing: .01em; }
.empty-title span { color: var(--muted); font-size: 26px; margin-left: 4px; }
.empty .muted { font-size: 16px; margin: 0 0 24px; }

/* ---------- biblioteca ---------- */
.library { padding: calc(16px + var(--sa-t)) calc(48px + var(--sa-r)) calc(32px + var(--sa-b)) calc(48px + var(--sa-l)); max-width: 1400px; margin: 0 auto; }
.lib-head { display: flex; align-items: center; gap: 12px; height: 64px; margin-bottom: 24px; }
.lib-head #lib-back { margin-left: -12px; }
.lib-title { font: 600 28px/1.1 var(--sans); margin: 0; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-title.brand { font: 500 30px/1.1 var(--serif); letter-spacing: .01em; }
.lib-head #lib-size { flex: 1; padding-top: 6px; }
.lib-head #lib-import { margin-left: auto; margin-right: -10px; background: var(--surface); }

.continue {
  display: flex; gap: 24px; align-items: center; width: 100%; text-align: left; padding: 16px; margin-bottom: 48px;
  border-radius: 16px; background: linear-gradient(180deg, var(--surface) 0%, #131820 100%);
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset; transition: transform 180ms var(--ease);
}
.continue:active { transform: scale(.985); }
.continue-cover { width: 96px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 6px; box-shadow: 0 12px 24px -10px rgba(0,0,0,.7); }
.continue-info { display: flex; flex-direction: column; gap: 4px; flex: 1; max-width: 420px; }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: .04em; }
.continue-title { font-size: 22px; font-weight: 600; }
.continue .bar { margin-top: 12px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 40px 28px; }
.tile { display: flex; flex-direction: column; gap: 4px; text-align: left; min-width: 0; }
.frame { position: relative; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden; background: var(--surface); margin-bottom: 8px;
  box-shadow: 0 18px 32px -18px rgba(0,0,0,.8); transition: transform 180ms var(--ease); }
.tile:active .frame { transform: scale(.97); }
.cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; border-radius: 0; background: rgba(0,0,0,.55); }
.tile-title { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bar { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; position: relative; }
.bar::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--p, 0%); background: var(--accent); border-radius: inherit; }
.bar.big { height: 6px; margin: 16px 0 12px; }

.lib-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 64px; }

/* ---------- importando (não bloqueia a tela) ---------- */
.importing {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + var(--sa-b)); z-index: 5;
  width: min(480px, 88vw); padding: 14px 20px 16px; border-radius: 16px; background: var(--surface-2);
  box-shadow: 0 16px 40px -12px rgba(0,0,0,.7); font-size: 15px; display: flex; flex-direction: column; gap: 10px;
}
.importing .bar { height: 4px; }
button:disabled { opacity: .4; pointer-events: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(32px + var(--sa-b)); z-index: 40; max-width: min(640px, 90vw);
  padding: 12px 20px; border-radius: 14px; background: var(--surface-2); color: var(--text); font-size: 15px;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none; transition: opacity 200ms, transform 200ms var(--ease);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- leitura ---------- */
.reader { position: fixed; inset: 0; z-index: 10; background: #000; overflow: hidden; }
.stage { position: absolute; inset: 0; touch-action: none; overflow: hidden; }
.stage::after { content: ""; position: absolute; inset: 0; background: #000; opacity: var(--dim, .12); pointer-events: none; }
.track { position: absolute; inset: 0; will-change: transform; }
.slot { position: absolute; inset: 0; display: grid; place-items: center; }
.slot img { width: 100%; height: 100%; object-fit: contain; display: block; transform-origin: center; pointer-events: none; -webkit-user-drag: none; }
.slot.empty img, .slot.is-end img { display: none; }
.end { display: none; flex-direction: column; align-items: center; gap: 24px; }
.slot.is-end .end { display: flex; }
.end-title { margin: 0; font: 500 26px/1.2 var(--serif); color: var(--text); }

.tools { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.tools-top, .tools-bottom {
  position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 16px; pointer-events: auto;
  background: rgba(14,17,22,.86); -webkit-backdrop-filter: blur(20px) saturate(1.2); backdrop-filter: blur(20px) saturate(1.2);
  opacity: 0; transition: opacity 200ms ease, transform 200ms var(--ease); visibility: hidden;
}
.tools-top { top: 0; padding: calc(8px + var(--sa-t)) calc(16px + var(--sa-r)) 8px calc(16px + var(--sa-l)); transform: translateY(-8px); }
.tools-bottom { bottom: 0; padding: 16px calc(32px + var(--sa-r)) calc(16px + var(--sa-b)) calc(32px + var(--sa-l)); transform: translateY(8px); }
.tools.on .tools-top, .tools.on .tools-bottom { opacity: 1; transform: none; visibility: visible; }
.tools:not(.on) .tools-top, .tools:not(.on) .tools-bottom { transition: opacity 200ms ease, transform 200ms var(--ease), visibility 0s 200ms; }
.tools.instant .tools-top, .tools.instant .tools-bottom { transition: none; }
.r-title { flex: 1; text-align: center; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-count { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; min-width: 88px; text-align: right; }

input[type=range] { flex: 1; -webkit-appearance: none; appearance: none; height: 44px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--line); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 50%; background: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.5); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--accent); }

.hint {
  position: absolute; left: 50%; bottom: calc(40px + var(--sa-b)); z-index: 3; padding: 10px 18px; border-radius: 999px;
  background: rgba(30,37,46,.9); color: var(--text); font-size: 15px; pointer-events: none;
  opacity: 0; transform: translate(-50%, 8px); transition: opacity 300ms ease, transform 300ms var(--ease);
}
.hint.on { opacity: 1; transform: translate(-50%, 0); }

.sheet { position: absolute; inset: 0; z-index: 4; background: rgba(0,0,0,.5); opacity: 0; visibility: hidden; transition: opacity 220ms, visibility 0s 220ms; }
.sheet.on { opacity: 1; visibility: visible; transition: opacity 220ms; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 72vh; overflow: auto; border-radius: 20px 20px 0 0;
  background: var(--surface); padding: 16px calc(32px + var(--sa-r)) calc(32px + var(--sa-b)) calc(32px + var(--sa-l));
  transform: translateY(24px); transition: transform 260ms var(--ease);
}
.sheet.on .sheet-panel { transform: none; }
.sheet-head { display: flex; align-items: center; gap: 24px; margin-bottom: 24px; }
.sheet-head #r-sheet-close { margin-left: auto; }
.dim-row { display: flex; align-items: center; gap: 12px; flex: 0 1 280px; color: var(--muted); }
.dim-row svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.seg { display: inline-flex; background: var(--bg); border-radius: 999px; padding: 4px; }
.seg button { min-height: 40px; padding: 0 16px; border-radius: 999px; color: var(--muted); font-size: 14px; font-weight: 600; transition: background 160ms, color 160ms; }
.seg button[aria-pressed=true] { background: var(--surface-2); color: var(--text); }
.sheet-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 24px 16px; }
.sheet-vol { display: flex; flex-direction: column; gap: 8px; color: var(--muted); font-size: 14px; }
.sheet-vol img { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 6px; background: var(--bg); }
.sheet-vol.current { color: var(--text); font-weight: 600; }
.sheet-vol.current img { outline: 2px solid var(--accent); outline-offset: 3px; }

@media (max-width: 700px) {
  .library { padding-left: calc(24px + var(--sa-l)); padding-right: calc(24px + var(--sa-r)); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 32px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .tools-top, .tools-bottom, .sheet-panel, .toast, .hint { transform: none !important; }
}
