@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --bg: #0B0E12;
  --bg-elevated: #12161C;
  --bg-panel: #161B22;
  --border: rgba(231, 228, 220, 0.09);
  --text: #E7E4DC;
  --text-dim: #8A8F98;
  --amber: #D98E4A;
  --cyan: #4FB3BF;
  --rose: #A45A6B;
  --green: #6B8F71;
  --serif: 'Fraunces', serif;
  --sans: 'Inter', sans-serif;
  --mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  height: 100%;
}

a { color: inherit; text-decoration: none; }

::selection { background: var(--amber); color: var(--bg); }

/* ---------- Page d'accueil ---------- */

.site-header {
  padding: 3rem 1.5rem 1rem;
  max-width: 760px;
  margin: 0 auto;
}

.site-label {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  display: block;
  margin-bottom: 1.25rem;
}

.site-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.2rem, 6vw, 3.2rem);
  line-height: 1.1;
  margin: 0 0 0.75rem;
}

.site-intro {
  color: var(--text-dim);
  font-size: 1.05rem;
  line-height: 1.6;
  max-width: 46ch;
}

.library-grid {
  max-width: 760px;
  margin: 2.5rem auto 5rem;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.5rem;
}

.book-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  background: var(--bg-elevated);
  transition: border-color 0.2s ease;
}

.book-card:hover { border-color: var(--card-accent, var(--amber)); }

.book-cover {
  aspect-ratio: 2 / 3;
  width: 100%;
  display: flex;
  align-items: flex-end;
  padding: 1rem;
  background: linear-gradient(160deg, var(--bg-elevated) 0%, color-mix(in srgb, var(--card-accent, var(--amber)) 18%, var(--bg-elevated)) 100%);
  background-size: cover;
  background-position: center;
}

.book-cover-initial {
  font-family: var(--serif);
  font-size: 2.4rem;
  color: var(--card-accent, var(--amber));
  opacity: 0.85;
}

.book-info { padding: 0.9rem 1rem 1.1rem; }

.book-format {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.1rem 0.35rem;
  margin: 0 0.35rem 0.5rem 0;
}

.book-subject {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--card-accent, var(--amber));
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.15rem 0.4rem;
  margin-bottom: 0.5rem;
}

.book-title {
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.3;
  margin: 0 0 0.2rem;
}

.book-author {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  display: block;
  margin-bottom: 0.5rem;
}

.book-blurb {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0;
}

.empty-state {
  max-width: 760px;
  margin: 2.5rem auto 5rem;
  padding: 2rem 1.5rem;
  border: 1px dashed var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.6;
}

.empty-state code {
  font-family: var(--mono);
  color: var(--cyan);
  font-size: 0.85em;
}

/* ---------- Lecteur ---------- */

body.reader-body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.reader-topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.reader-back {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.reader-back:hover { color: var(--cyan); }

.reader-meta { flex: 1; min-width: 0; }
.reader-meta-title {
  font-family: var(--serif);
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-meta-author {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.reader-btn {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  line-height: 1;
}
.reader-btn:hover { color: var(--text); border-color: var(--cyan); }
.reader-btn.active { color: var(--cyan); border-color: var(--cyan); }

.reader-progress {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  min-width: 4.5rem;
  text-align: right;
}

.reader-body-area {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

#toc-panel {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 1.25rem;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
}
#toc-panel.open { transform: translateX(0); }

.toc-heading {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  margin: 0 0 1rem;
}

#toc-list { list-style: none; margin: 0; padding: 0; }
#toc-list li a {
  display: block;
  padding: 0.5rem 0;
  font-size: 0.88rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
#toc-list li a:hover { color: var(--cyan); }

#viewer-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
  background: var(--reader-bg, var(--bg));
}

#viewer { width: 100%; height: 100%; }

.page-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 15%;
  min-width: 44px;
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: 3;
  display: flex;
  align-items: center;
}
.page-nav.prev { left: 0; justify-content: flex-start; padding-left: 8px; }
.page-nav.next { right: 0; justify-content: flex-end; padding-right: 8px; }

.page-nav-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-dim);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  opacity: 0.85;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.page-nav:hover .page-nav-icon,
.page-nav:focus-visible .page-nav-icon,
.page-nav:active .page-nav-icon {
  opacity: 1;
  color: var(--cyan);
  border-color: var(--cyan);
}

@media (max-width: 640px) {
  .page-nav-icon { width: 34px; height: 34px; font-size: 1.3rem; }
  .page-nav { width: 20%; }
}

.progress-bar {
  height: 2px;
  background: var(--border);
  flex-shrink: 0;
}
.progress-bar-fill {
  height: 100%;
  background: var(--cyan);
  width: 0%;
  transition: width 0.2s ease;
}

.reader-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Thème clair de lecture (contenu de l'epub uniquement, l'interface reste sombre) */
body.theme-light #viewer-wrap { --reader-bg: #F4F1EA; }

@media (max-width: 640px) {
  #toc-panel { width: 85%; }
  .reader-meta-author { display: none; }
  .reader-meta { display: none; }
  .reader-controls { overflow-x: auto; }
  .reader-btn { white-space: nowrap; }
}
