:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --danger: #dc2626;
  --bar: #1f2937;
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --panel: #111827;
    --ink: #f3f4f6;
    --muted: #9ca3af;
    --line: #1f2937;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Botões ---------- */
.btn {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--muted);
}
.btn.big { width: 100%; min-height: 56px; font-size: 1.1rem; }

/* ---------- Biblioteca ---------- */
#library {
  height: 100%;
  overflow: auto;
  max-width: 760px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 32px) calc(var(--safe-l) + 16px);
}

.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.lib-head h1 { margin: 0; font-size: 1.5rem; }

.privacy { color: var(--muted); font-size: .9rem; margin: 10px 2px 22px; }
.sec { font-size: 1rem; color: var(--muted); font-weight: 600; margin: 0 2px 10px; }

.banner {
  background: #fef3c7;
  color: #78350f;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: .95rem;
}

.docs { list-style: none; margin: 0; padding: 0; }
.doc {
  display: flex;
  align-items: stretch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.doc-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: 0;
  padding: 14px 16px;
}
.doc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-info { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.doc-del {
  background: none;
  border: 0;
  padding: 0 16px;
  color: var(--danger);
  min-width: 64px;
}
.empty { color: var(--muted); padding: 8px 2px; }

/* ---------- Leitor ---------- */
#reader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #4b5563;
}

.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(var(--safe-t) + 6px) calc(var(--safe-r) + 8px) 6px calc(var(--safe-l) + 8px);
  background: var(--bar);
  color: #f9fafb;
  overflow-x: auto;
}

.tb {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: #374151;
  color: #fff;
  white-space: nowrap;
}
.tb:disabled { opacity: .4; }
.tb.on { background: var(--brand); }

.pg {
  flex: none;
  width: 58px;
  min-height: 44px;
  text-align: center;
  border: 0;
  border-radius: 10px;
  font: inherit;
  background: #f9fafb;
  color: #111827;
}
.tot { flex: none; min-width: 3.2em; text-align: center; color: #e5e7eb; font-size: .95rem; }
.spacer { flex: 1; min-width: 0; }

#scroller {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#pages { position: relative; }

.page {
  position: absolute;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
  overflow: hidden;
}
.page canvas { display: block; width: 100%; height: 100%; }

.links { position: absolute; inset: 0; }
.lk {
  position: absolute;
  display: block;
  -webkit-tap-highlight-color: rgba(37, 99, 235, .25);
}
.lk:active { background: rgba(37, 99, 235, .22); }
.show-links .lk {
  outline: 2px solid rgba(37, 99, 235, .9);
  background: rgba(37, 99, 235, .12);
}

#loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(17, 24, 39, .88);
  color: #fff;
  z-index: 5;
}
.loading-box { text-align: center; padding: 20px; }
.loading-box progress { width: min(260px, 70vw); }

/* ---------- Janela e aviso ---------- */
#modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .55);
}
.sheet {
  width: 100%;
  max-width: 460px;
  max-height: 85vh;
  overflow: auto;
  padding: 20px;
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
}
.sheet h2 { margin: 0 0 10px; font-size: 1.15rem; }
.sheet p { margin: 0 0 10px; }
.sheet .small { color: var(--muted); font-size: .9rem; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 24px);
  transform: translateX(-50%);
  z-index: 60;
  max-width: 90vw;
  padding: 10px 16px;
  border-radius: 12px;
  background: #111827;
  color: #fff;
  text-align: center;
}

@media (max-width: 640px) {
  .tb .lbl { display: none; }
}
