/* The FITO Ledger : palette dérivée de la couverture (carmin, bordeaux, noir encre, ivoire, or vieilli) */
:root {
  --bg: #FAF5EF;
  --surface: #FFFFFF;
  --text: #2B1010;
  --muted: #7A5C5C;
  --primary: #8C1A1A;
  --primary-soft: #A82626;
  --accent: #C9A44C;
  --border: #E8D9D0;
  --reader-bg: #FAF5EF;
  --reader-text: #2B1010;
}
html[data-theme="sombre"] {
  --bg: #140808;
  --surface: #221010;
  --text: #F5EDE4;
  --muted: #B39A9A;
  --primary: #A82626;
  --primary-soft: #C03333;
  --accent: #D9B45E;
  --border: #3A1D1D;
  --reader-bg: #140808;
  --reader-text: #F5EDE4;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  min-height: 100vh;
}
.hidden { display: none !important; }
h1, h2, h3 { color: var(--text); }
.meta { color: var(--muted); font-size: 0.92rem; }
.error { color: var(--primary); }

/* Boutons */
.btn {
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--primary); color: #F5EDE4; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-soft); }
.btn-gold { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-link { background: none; border: none; color: var(--accent); text-decoration: underline; }
.btn-block { width: 100%; }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-tab { flex: 1; border-radius: 0; }
.btn-tab.active { background: var(--primary); color: #F5EDE4; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }

/* Notices */
.notice { border-radius: 10px; padding: 0.7rem 0.9rem; font-size: 0.92rem; }
.notice-gold { border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }

/* Progression */
.progress-wrap { margin: 0.75rem 0; }
.progress-bar { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }

/* Écrans et overlays */
.screen { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 1rem; }
.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: #1A0505;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
#trailer-overlay { background: #000; }
#trailer-video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.trailer-actions {
  position: absolute; bottom: 1.2rem; left: 0; right: 0;
  display: flex; gap: 0.75rem; justify-content: center;
}
.overlay-skip { position: absolute; bottom: 1.2rem; right: 1.2rem; color: #F5EDE4; border-color: #C9A44C; }

/* Connexion */
.auth-card {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  margin-top: 2rem;
  text-align: center;
}
.auth-logo { width: 120px; height: 120px; object-fit: cover; border-radius: 14px; }
.auth-card h1 { margin: 0.6rem 0 0.2rem; color: var(--primary); }
.subtitle { margin: 0; color: var(--muted); }
.auth-note { font-size: 0.9rem; color: var(--muted); }
.auth-tabs { display: flex; margin: 1rem 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
#auth-form { text-align: left; display: grid; gap: 0.8rem; }
#auth-form label { display: grid; gap: 0.3rem; font-size: 0.9rem; }
#auth-form input, #toc-search, .order-form input, .reader-tools select {
  font-family: inherit; font-size: 1rem; padding: 0.6rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); width: 100%;
}

/* Barre du haut et onglets */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 0.6rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.9rem;
}
.topbar-logo { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; }
.topbar-title { font-weight: bold; color: var(--primary); flex: 1; }
#main { max-width: 880px; margin: 0 auto; padding: 1rem 1rem 5.5rem; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  flex: 1; background: none; border: none; padding: 0.8rem 0.3rem;
  font-family: inherit; font-size: 0.85rem; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab.active { color: var(--primary); font-weight: bold; box-shadow: inset 0 2px 0 var(--accent); }

/* Bibliothèque */
.library-hero { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.cover-button { background: none; border: none; padding: 0; cursor: pointer; }
.cover-button img {
  width: 200px; max-width: 55vw; border-radius: 6px;
  box-shadow: 0 12px 30px rgba(26, 5, 5, 0.35);
}
.library-info { flex: 1; min-width: 260px; }
.library-info h2 { margin-top: 0; color: var(--primary); }
.author { color: var(--accent); font-style: italic; margin-top: -0.5rem; }

/* Listes de chapitres */
.chapter-list, .order-list { list-style: none; margin: 0; padding: 0; }
.chapter-list li, .order-list li {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.65rem 0.4rem; border-bottom: 1px solid var(--border);
}
.chapter-list li button.chapter-open {
  flex: 1; text-align: left; background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 1rem; color: var(--text); padding: 0;
}
.chapter-list li.locked { color: var(--muted); }
.badge { font-size: 0.72rem; border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; padding: 0.1rem 0.5rem; white-space: nowrap; }
.badge-lock { border-color: var(--muted); color: var(--muted); }
.read-dot { color: var(--accent); }

/* Annexes et boutique */
.annexe-card, .shop-box, .product-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.annexe-card h3, .product-card h3 { margin-top: 0; color: var(--primary); }
.synopsis { font-style: italic; line-height: 1.55; }
.reading-order { color: var(--accent); font-weight: bold; }
.price { font-size: 1.15rem; font-weight: bold; color: var(--primary); }
.product-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin: 1rem 0; }
.order-form { display: grid; gap: 0.5rem; margin-top: 0.6rem; }
.status { font-size: 0.82rem; }
.status-pending { color: var(--accent); }
.status-validated { color: #2E7D32; }
.status-rejected { color: var(--primary); }

/* Recensement */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.8rem; margin-bottom: 1rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem; text-align: center; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: bold; color: var(--primary); display: block; }
table.accounts { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.accounts th, table.accounts td { border-bottom: 1px solid var(--border); padding: 0.45rem; text-align: left; }

/* Lecteur */
#reader { flex-direction: column; align-items: stretch; padding: 0; background: var(--reader-bg); color: var(--reader-text); }
#reader[data-readtheme="papier"] { --reader-bg: #F0E6D8; --reader-text: #3A1D1D; }
#reader[data-readtheme="sombre"] { --reader-bg: #140808; --reader-text: #F5EDE4; }
#reader[data-readtheme="clair"] { --reader-bg: #FAF5EF; --reader-text: #2B1010; }
.reader-top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  background: var(--reader-bg); border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.8rem;
}
.reader-book { flex: 1; font-weight: bold; color: var(--primary); }
.reader-tools { display: flex; gap: 0.4rem; align-items: center; }
.reader-tools select { width: auto; }
.reader-progress { border-radius: 0; }
.reader-content {
  max-width: 720px; width: 100%; margin: 0 auto;
  padding: 1.2rem 1.1rem 2rem; line-height: 1.75; font-size: 1.08rem;
}
.reader-content h2 { color: var(--primary); text-align: center; margin-bottom: 1.4rem; }
.reader-content p { margin: 0 0 1em; text-align: justify; }
.reader-content p:first-of-type::first-letter {
  font-size: 2.6em; line-height: 1; color: var(--accent);
  float: left; padding-right: 0.12em; font-weight: bold;
}
.sep { text-align: center !important; color: var(--accent); letter-spacing: 0.4em; margin: 1.4em 0 !important; }
.locked-note { text-align: center; color: var(--muted); }
.reader-nav {
  position: sticky; bottom: 0; display: flex; justify-content: space-between; gap: 1rem;
  background: var(--reader-bg); border-top: 1px solid var(--border); padding: 0.7rem 0.9rem;
}

/* Animation d'ouverture du livre (CSS 3D, version simplifiée) */
.book3d-scene { perspective: 1400px; }
.book3d {
  position: relative; width: 240px; height: 340px;
  transform-style: preserve-3d;
  animation: book-in 1.1s ease both;
}
@keyframes book-in {
  from { transform: rotateY(-38deg) rotateX(6deg) translateY(16px); opacity: 0; }
  to { transform: rotateY(-14deg) rotateX(4deg) translateY(0); opacity: 1; }
}
.book3d-back, .book3d-pages, .book3d-page, .book3d-cover {
  position: absolute; inset: 0; border-radius: 4px 10px 10px 4px;
}
.book3d-back { background: #4A0D0D; transform: translateZ(-14px); }
.book3d-pages { background: repeating-linear-gradient(to right, #F5EDE4 0 3px, #E8D9D0 3px 4px); transform: translateZ(-6px); }
.book3d-page {
  background: #F5EDE4;
  background-image: repeating-linear-gradient(#F5EDE4 0 26px, #E8D9D0 26px 27px);
  transform-origin: left center;
  border: 1px solid #E8D9D0;
}
.book3d-page.flip1 { transform: translateZ(3px); animation: page-turn 1.3s ease 2.1s both; }
.book3d-page.flip2 { transform: translateZ(2px); animation: page-turn 1.3s ease 3.1s both; }
.book3d-cover {
  background: url("/assets/cover-front.png") center / cover no-repeat, #4A0D0D;
  transform-origin: left center;
  transform: translateZ(14px);
  animation: cover-open 1.1s ease 0.9s both;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}
@keyframes cover-open {
  from { transform: translateZ(14px) rotateY(0deg); }
  to { transform: translateZ(14px) rotateY(-158deg); }
}
@keyframes page-turn {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(-152deg); }
}
.book-anim-title { color: #F5EDE4; margin-top: 1.6rem; font-size: 1.1rem; text-align: center; padding: 0 1rem; }
@media (prefers-reduced-motion: reduce) {
  .book3d, .book3d-cover, .book3d-page { animation-duration: 0.01s !important; }
}

/* Visionneuse 3D */
.viewer-scene { perspective: 1500px; padding: 2rem; }
.viewer-book {
  position: relative; width: 250px; height: 380px;
  transform-style: preserve-3d;
  transition: transform 0.25s ease;
  cursor: grab;
}
.viewer-book .face {
  position: absolute; background-size: cover; background-position: center;
  border: 1px solid #3A1D1D;
}
.face-front  { width: 250px; height: 380px; transform: translateZ(15px); background-image: url("/assets/cover-front.png"); }
.face-back   { width: 250px; height: 380px; transform: rotateY(180deg) translateZ(15px); background-image: url("/assets/cover-back.png"); }
.face-spine  { width: 30px; height: 380px; left: -15px; transform: rotateY(-90deg); background-image: url("/assets/cover-spine.png"); }
.face-pages  { width: 30px; height: 380px; right: -15px; transform: rotateY(90deg); background: repeating-linear-gradient(to right, #F5EDE4 0 3px, #D9C9B8 3px 4px); }
.face-top    { width: 250px; height: 30px; top: -15px; transform: rotateX(90deg); background: repeating-linear-gradient(to bottom, #F5EDE4 0 3px, #D9C9B8 3px 4px); }
.face-bottom { width: 250px; height: 30px; bottom: -15px; transform: rotateX(-90deg); background: #E8D9D0; }
.viewer-controls { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; padding: 0 1rem; }
.viewer-controls .btn { color: #F5EDE4; border-color: #C9A44C; }
.viewer-hint { color: #B39A9A; font-size: 0.9rem; }

@media (max-width: 560px) {
  .cover-button img { width: 150px; }
  .viewer-book { width: 200px; height: 304px; }
  .face-front, .face-back { width: 200px; height: 304px; }
  .face-spine, .face-pages { height: 304px; }
  .face-top, .face-bottom { width: 200px; }
}
