:root {
  --primary: #FF8C42;
  --primary-dark: #E67A30;
  --success: #4CAF50;
  --success-dark: #3d9140;
  --bg: #FFF8F0;
  --card-bg: #FFFFFF;
  --text: #2C3E50;
  --text-light: #7F8C8D;
  --shadow: 0 4px 15px rgba(0,0,0,0.1);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 500px;
  margin: 0 auto;
  overflow-x: hidden;
}

/* ── Vues ── */
.view { display: none; flex-direction: column; min-height: 100vh; }
.view.active { display: flex; }

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  background: var(--card-bg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 10;
}
header h1 { font-size: 1.5rem; font-weight: 800; color: var(--primary); flex: 1; }
header h2 { font-size: 1.1rem; font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Boutons ── */
.btn-back {
  background: none; border: none; font-size: 1.4rem;
  cursor: pointer; padding: 4px 6px; color: var(--text); line-height: 1;
}
.btn-primary {
  background: var(--primary); color: white; border: none;
  border-radius: var(--radius); padding: 14px 22px;
  font-family: 'Nunito', sans-serif; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: transform 0.1s, background 0.15s;
}
.btn-primary:active { transform: scale(0.97); background: var(--primary-dark); }
.btn-secondary {
  background: none; border: 2px solid #ccc; color: var(--text-light);
  border-radius: var(--radius); padding: 12px 22px;
  font-family: 'Nunito', sans-serif; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.btn-success {
  background: var(--success); color: white; border: none;
  border-radius: var(--radius); padding: 14px 22px;
  font-family: 'Nunito', sans-serif; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: transform 0.1s, background 0.15s;
}
.btn-success:active { transform: scale(0.97); background: var(--success-dark); }
.btn-large { width: 100%; font-size: 1.05rem; padding: 16px; }
.btn-round {
  width: 42px; height: 42px; border-radius: 50%;
  padding: 0; font-size: 1.5rem; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── Bibliothèque ── */
.book-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 14px; padding: 18px; flex: 1;
}
.book-card {
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; cursor: pointer;
  transition: transform 0.15s;
}
.book-card:active { transform: scale(0.96); }
.book-card img {
  width: 100%; aspect-ratio: 3/4; object-fit: cover;
  background: #e8e8e8; display: block;
}
.book-card-info { padding: 10px 12px; }
.book-card-title { font-weight: 700; font-size: 0.88rem; line-height: 1.3; }
.book-card-pages { font-size: 0.75rem; color: var(--text-light); margin-top: 3px; }
.book-card-delete {
  position: absolute; top: 6px; right: 6px;
  background: rgba(0,0,0,0.45); color: white; border: none;
  border-radius: 50%; width: 28px; height: 28px; font-size: 0.75rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.book-card-wrap { position: relative; }

.empty-state {
  grid-column: 1/-1; text-align: center;
  padding: 60px 20px; color: var(--text-light);
}
.empty-state .emoji { font-size: 3.5rem; margin-bottom: 14px; }
.empty-state p { font-size: 1.05rem; font-weight: 600; }
.empty-state .hint { font-size: 0.9rem; margin-top: 8px; font-weight: 400; }

/* ── Options ajout livre ── */
.add-options { display: flex; flex-direction: column; gap: 12px; padding: 20px 18px; flex: 1; }
.add-title { font-size: 0.95rem; color: var(--text-light); font-weight: 600; margin-bottom: 4px; }
.add-option-btn {
  display: flex; align-items: center; gap: 14px;
  background: var(--card-bg); border: 2px solid #eee; border-radius: var(--radius);
  padding: 16px 18px; cursor: pointer; text-align: left; width: 100%;
  font-family: 'Nunito', sans-serif; transition: border-color 0.15s, transform 0.1s;
}
.add-option-btn:active { transform: scale(0.98); border-color: var(--primary); }
.add-option-btn.highlight { border-color: var(--primary); background: #fff5ee; }
.add-option-icon { font-size: 1.6rem; flex-shrink: 0; }
.add-option-label { font-size: 1rem; font-weight: 700; color: var(--text); }
.camera-section { display: flex; flex-direction: column; }

/* ── Caméra ── */
.camera-container { position: relative; background: #111; overflow: hidden; flex-shrink: 0; }
.camera-container video { width: 100%; max-height: 52vh; object-fit: cover; display: block; }
.camera-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.scan-frame {
  width: 68%; aspect-ratio: 3/4;
  border: 3px solid rgba(255,255,255,0.85); border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.45);
}
.camera-error {
  position: absolute; inset: 0; background: #1a1a1a;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: #aaa; text-align: center; padding: 20px;
}
.camera-error p:first-child { font-size: 2.5rem; }
.camera-error p { font-size: 0.95rem; font-weight: 600; }
.camera-error .hint { font-size: 0.82rem; font-weight: 400; color: #888; }
.camera-hint {
  color: white; font-size: 0.88rem; font-weight: 600;
  background: rgba(0,0,0,0.55); padding: 6px 14px; border-radius: 20px;
}

/* ── Contenu vue ── */
.view-content { flex: 1; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.actions { display: flex; flex-direction: column; gap: 10px; padding: 0 18px 24px; }

/* ── Confirmer livre ── */
.book-confirm { align-items: center; padding: 24px 18px; text-align: center; gap: 10px; }
.book-confirm img { width: 150px; border-radius: 10px; box-shadow: var(--shadow); object-fit: cover; }
.book-confirm h3 { font-size: 1.15rem; font-weight: 800; margin-top: 6px; }
.book-confirm p { color: var(--text-light); font-size: 0.95rem; }
.isbn-label { font-size: 0.78rem !important; }

/* ── ISBN input ── */
.hidden { display: none !important; }
#isbn-input-container { display: flex; flex-direction: column; gap: 10px; padding: 0 18px; }
#isbn-input {
  padding: 14px 16px; border: 2px solid #ddd; border-radius: var(--radius);
  font-family: 'Nunito', sans-serif; font-size: 1rem; outline: none; width: 100%;
}
#isbn-input:focus { border-color: var(--primary); }

/* ── Miniatures pages ── */
.page-thumbnails-wrap { padding: 0 18px; min-height: 78px; }
.page-thumbnails { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.page-thumb {
  width: 50px; height: 66px; border-radius: 6px; object-fit: cover;
  border: 2px solid var(--primary); flex-shrink: 0; cursor: pointer;
}

/* ── Badge ── */
.badge {
  background: var(--primary); color: white;
  padding: 4px 12px; border-radius: 20px; font-size: 0.82rem; font-weight: 700;
  white-space: nowrap; flex-shrink: 0;
}

/* ── Lecture ── */
.read-title-header { font-size: 1rem !important; }
.read-content { padding: 14px; gap: 12px; }
.page-display {
  border-radius: var(--radius); overflow: hidden;
  background: #e8e8e8; flex: 1; min-height: 42vh; display: flex; align-items: center;
}
.page-display img { width: 100%; display: block; border-radius: var(--radius); object-fit: contain; }
.read-controls {
  display: flex; align-items: center; justify-content: center; gap: 20px; padding: 8px 0;
}
.btn-nav {
  background: var(--card-bg); border: 2px solid #ddd; border-radius: 50%;
  width: 50px; height: 50px; font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.btn-nav:disabled { opacity: 0.3; cursor: default; }
.btn-play {
  background: var(--primary); color: white; border: none; border-radius: 50%;
  width: 68px; height: 68px; font-size: 1.6rem; cursor: pointer;
  box-shadow: 0 4px 14px rgba(255,140,66,0.45);
  transition: transform 0.1s; display: flex; align-items: center; justify-content: center;
}
.btn-play:active { transform: scale(0.94); }
.btn-play.playing { background: #e55; box-shadow: 0 4px 14px rgba(229,85,85,0.4); }
.read-meta { text-align: center; color: var(--text-light); font-size: 0.88rem; }

/* ── Loading ── */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.62);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; z-index: 100;
}
.loading-spinner {
  width: 50px; height: 50px;
  border: 4px solid rgba(255,255,255,0.3); border-top-color: white;
  border-radius: 50%; animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { color: white; font-size: 1rem; font-weight: 600; }

/* ── Bouton icône ── */
.btn-icon {
  background: none; border: none; font-size: 1.3rem;
  cursor: pointer; padding: 4px; line-height: 1;
}

/* ── Réglages ── */
.settings-content { overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 20px; }
.settings-section { display: flex; flex-direction: column; gap: 8px; }
.settings-label { font-size: 0.95rem; font-weight: 800; color: var(--text); }
.settings-hint { font-size: 0.82rem; color: var(--text-light); }
.settings-input-row { display: flex; gap: 8px; }
.settings-input-row input {
  flex: 1; padding: 12px 14px; border: 2px solid #ddd; border-radius: var(--radius);
  font-family: 'Nunito', sans-serif; font-size: 0.9rem; outline: none;
}
.settings-input-row input:focus { border-color: var(--primary); }
.settings-status { font-size: 0.82rem; font-weight: 600; min-height: 18px; }
.settings-status.ok { color: var(--success); }
.settings-status.err { color: #e55; }

/* ── Effets voix ── */
.effects-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.effect-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px 6px; border: 2px solid #eee; border-radius: 12px;
  background: var(--card-bg); cursor: pointer; font-family: 'Nunito', sans-serif;
  transition: border-color 0.15s, background 0.15s; font-size: 1.6rem;
}
.effect-btn span { font-size: 0.75rem; font-weight: 700; color: var(--text); }
.effect-btn.selected { border-color: var(--primary); background: #fff5ee; }
.effect-btn:active { transform: scale(0.95); }

.voice-search {
  padding: 10px 14px; border: 2px solid #ddd; border-radius: var(--radius);
  font-family: 'Nunito', sans-serif; font-size: 0.9rem; outline: none; width: 100%;
}
.voice-search:focus { border-color: var(--primary); }
.voices-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.voice-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 2px solid #eee; border-radius: 10px; cursor: pointer;
  transition: border-color 0.15s;
}
.voice-item:hover { border-color: var(--primary); }
.voice-item.selected { border-color: var(--primary); background: #fff5ee; }
.voice-item input[type=radio] { display: none; }
.voice-name { font-size: 0.9rem; font-weight: 700; }
.voice-meta { font-size: 0.75rem; color: var(--text-light); }
.accent-badge {
  display: inline-block; font-size: 0.68rem; font-weight: 600;
  background: #eee; color: #666; border-radius: 6px;
  padding: 1px 6px; margin-left: 4px; vertical-align: middle;
}
.accent-badge.fr { background: #ddf0ff; color: #1a6fb5; }
.voice-preview {
  margin-left: auto; background: none; border: 1px solid #ccc;
  border-radius: 20px; padding: 4px 10px; font-size: 0.78rem; cursor: pointer;
  font-family: 'Nunito', sans-serif; flex-shrink: 0;
}

/* ── Modale ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--card-bg); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 500px; max-height: 70vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; padding: 16px 18px;
  border-bottom: 1px solid #eee;
}
.modal-header h3 { flex: 1; font-size: 1.05rem; font-weight: 700; }
.server-pdf-list { overflow-y: auto; padding: 12px 0; }
.server-pdf-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; cursor: pointer; border-bottom: 1px solid #f5f5f5;
  transition: background 0.15s;
}
.server-pdf-item:active { background: #f9f9f9; }
.server-pdf-icon { font-size: 1.5rem; flex-shrink: 0; }
.server-pdf-name { font-size: 0.92rem; font-weight: 600; line-height: 1.3; }
.server-pdf-size { font-size: 0.78rem; color: var(--text-light); margin-top: 2px; }
.loading-hint { text-align: center; padding: 24px; color: var(--text-light); }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #2C3E50; color: white; padding: 12px 22px;
  border-radius: 24px; font-size: 0.9rem; font-weight: 600;
  z-index: 99; white-space: nowrap; pointer-events: none;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }
