:root {
  --bg: #111318;
  --surface: #1b1e26;
  --surface-2: #252935;
  --text: #eef0f5;
  --muted: #9aa1b2;
  --accent: #e8483b;
  --accent-2: #f5b82e;
  --danger: #ff6b6b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.view { min-height: 100dvh; }
.content { padding: 16px; padding-bottom: calc(24px + var(--safe-bottom)); max-width: 720px; margin: 0 auto; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; }

input[type=email], input[type=password], input[type=text], input[type=search], input[type=file] {
  width: 100%; padding: 12px 14px; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid transparent; border-radius: 10px; outline: none;
}
input:focus-visible { border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.btn {
  min-height: 46px; padding: 0 18px; font: inherit; font-weight: 600; color: var(--text);
  background: var(--surface-2); border: 0; border-radius: 10px; cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger-outline { background: transparent; color: var(--danger); border: 1px solid currentColor; margin-top: 16px; width: 100%; }
.btn:disabled { opacity: .5; }
.btn:active { transform: scale(.98); }

.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; flex: none;
  background: transparent; border: 0; border-radius: 50%; color: inherit; cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { background: var(--surface-2); }

.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: .9rem; }

/* Connexion */
#view-login { display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { text-align: center; margin-bottom: 8px; }
.logo { width: 72px; height: 72px; margin: 0 auto; }

/* Bibliothèque */
.search { margin: 4px 0 14px; }
.book-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.book {
  display: flex; align-items: center; gap: 14px; padding: 12px; width: 100%;
  background: var(--surface); border: 0; border-radius: var(--radius); color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.book:active { background: var(--surface-2); }
.book-icon {
  width: 46px; height: 62px; flex: none; border-radius: 6px; display: grid; place-items: center;
  background: linear-gradient(160deg, var(--accent), #8f1f17); color: #fff; font-weight: 700; font-size: .75rem;
}
.book-info { flex: 1; min-width: 0; }
.book-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-meta { display: block; font-size: .85rem; color: var(--muted); margin-top: 4px; }
.bar { display: block; height: 4px; background: var(--surface-2); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent-2); }

.continue {
  display: block; width: 100%; padding: 16px; margin-bottom: 14px; border: 0; border-radius: var(--radius);
  background: linear-gradient(135deg, #3a1d1b, var(--surface)); color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.continue small { color: var(--accent-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: .75rem; }
.continue strong { display: block; font-size: 1.1rem; margin: 4px 0 2px; }

/* Admin */
.admin-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.admin-list li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--surface-2); }
.admin-list li > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-list .small { font-size: .8rem; color: var(--muted); }
.link-btn { background: none; border: 0; color: var(--muted); font: inherit; font-size: .9rem; padding: 8px; cursor: pointer; }
.link-btn.danger { color: var(--danger); }
progress { width: 100%; accent-color: var(--accent); }

/* Lecteur */
.reader { position: fixed; inset: 0; background: #000; overflow: hidden; touch-action: pan-y pinch-zoom; }
.stage { position: absolute; inset: 0; overflow: auto; display: flex; justify-content: center; -webkit-overflow-scrolling: touch; }
.stage.fit-page { align-items: center; overflow: hidden; }
.stage canvas { display: block; flex: none; }
.reader-ui { position: absolute; inset: 0; pointer-events: none; transition: opacity .2s; }
.reader-ui.hidden { opacity: 0; }
.reader-ui.hidden * { pointer-events: none !important; }
.reader-top, .reader-bottom, .settings { pointer-events: auto; }
.reader-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 4px;
  padding: calc(6px + var(--safe-top)) 6px 6px; background: linear-gradient(#000d, #0000);
}
.reader-top h1 { flex: 1; font-size: 1rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.settings { position: absolute; top: calc(60px + var(--safe-top)); right: 10px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.chip { background: var(--surface); color: var(--text); border: 0; border-radius: 999px; padding: 10px 16px; font: inherit; font-size: .9rem; cursor: pointer; }
.reader-bottom {
  position: absolute; bottom: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px;
  padding: 14px 16px calc(14px + var(--safe-bottom)); background: linear-gradient(#0000, #000d);
}
.reader-bottom input { flex: 1; accent-color: var(--accent); height: 32px; }
.reader.rtl .reader-bottom input { direction: rtl; }
#page-label { font-variant-numeric: tabular-nums; font-size: .9rem; min-width: 70px; text-align: right; }
.loader {
  position: absolute; top: 50%; left: 50%; width: 36px; height: 36px; margin: -18px;
  border: 3px solid #fff3; border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); z-index: 50;
  background: var(--surface-2); padding: 12px 18px; border-radius: 10px; max-width: calc(100% - 32px); box-shadow: 0 6px 24px #0008;
}

@media (min-width: 720px) {
  .book-list { display: grid; grid-template-columns: 1fr 1fr; }
}
