/* Ossature : application, barre du haut, zone de contenu, fil d'Ariane, toast. */

#app { display: none; height: 100vh; height: 100dvh; overflow: hidden; }
#app.visible { display: flex; }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

#topbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; min-height: 60px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right));
}
.topbar-btn {
  flex: none; background: transparent; border: 1px solid transparent; border-radius: 11px; width: 40px; height: 40px;
  font-size: 17px; cursor: pointer; color: var(--text); display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .1s;
}
.topbar-btn:hover { background: var(--panel-2); }
.topbar-btn:active { transform: scale(.92); }

/* Bouton libellé de la barre du haut (« Guide de l'étudiant »). */
.topbar-nav {
  flex: none; display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 13px;
  background: transparent; border: 1px solid var(--border); border-radius: 11px; cursor: pointer;
  color: var(--text); font: inherit; font-size: 13.5px; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.topbar-nav:hover { background: var(--panel-2); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.topbar-nav:active { transform: scale(.96); }
.topbar-nav .tn-emoji { font-size: 16px; line-height: 1; }
.topbar-spacer { flex: 1 1 auto; }

/* Témoin de synchronisation : vert = à jour, ambre = mise à jour en cours,
   rouge = hors ligne. Cliquer force une resynchronisation complète. */
#sync-btn { position: relative; }
#sync-btn .sync-dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent);
  transition: background .25s, box-shadow .25s;
}
#sync-btn[data-state="syncing"] .sync-dot { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); animation: syncPulse 1.1s ease-in-out infinite; }
#sync-btn[data-state="offline"] .sync-dot { background: var(--red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 22%, transparent); }
@keyframes syncPulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

#breadcrumb { flex: 0 1 auto; min-width: 0; font-size: 13.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#breadcrumb .crumb-sep { margin: 0 6px; color: var(--text-faint); }
#breadcrumb .crumb-current { color: var(--text); font-weight: 600; }
/* Bouton « texte » : fil d'Ariane, titres de séance dans les sommaires. */
.crumb-link, .crumb-home {
  background: none; border: none; padding: 0; margin: 0; cursor: pointer; font: inherit;
  color: var(--accent); font-weight: 600; flex: none; text-align: left;
}
.crumb-link:hover, .crumb-home:hover { text-decoration: underline; }

/* Pas de `scroll-behavior: smooth` ici : tous les déplacements du site sont
   programmés (lien vers un bloc, résultat de recherche). L'animation partait
   sur plusieurs milliers de pixels et se faisait interrompre par le repeint
   suivant — le lecteur restait alors en haut du cours. Le repère visuel est
   donné par le flash du bloc d'arrivée. */
#content { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; }
.content-inner { max-width: 1180px; margin: 0 auto; padding: clamp(14px, 2.5vw, 30px) clamp(14px, 3.2vw, 44px) 96px; }
/* Lecture (cours, guide, sommaires) : colonne « document » centrée, à mesure
   confortable (~75 caractères par ligne). L'accueil garde sa pleine largeur. */
#app.reading .content-inner { max-width: 860px; }

.cours-header { margin-bottom: clamp(18px, 3vw, 28px); border-bottom: 1px solid var(--hairline); padding-bottom: clamp(14px, 2.2vw, 20px); }
.cours-header .cours-path { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.cours-header h1 { font-family: var(--serif); font-size: clamp(28px, 4vw, 42px); margin: 0; letter-spacing: -.015em; line-height: 1.14; font-weight: 600; }

.cover-banner {
  position: relative; margin: 0 0 clamp(22px, 3vw, 32px); height: clamp(140px, 20vw, 230px); overflow: hidden;
  border-radius: var(--r-lg); background: var(--panel-2);
}
.cover-banner img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-banner .cover-veil { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(20, 18, 15, .06) 0%, rgba(20, 18, 15, .42) 66%, rgba(20, 18, 15, .7) 100%); }
.cover-banner .cover-label {
  position: absolute; left: clamp(18px, 3vw, 28px); bottom: 16px; right: 16px; color: #fff; font-weight: 700;
  font-size: clamp(15px, 2vw, 19px); text-shadow: 0 1px 10px rgba(0, 0, 0, .5); display: flex; align-items: center; gap: 9px;
}
.cover-banner .cover-label .emoji { font-size: 1.2em; }

/* ============ ÉTAT VIDE ============ */
.empty-state { text-align: center; padding: 80px 20px; color: var(--text-dim); }
.empty-state .icon { font-size: 46px; margin-bottom: 12px; }
.empty-state h2 { font-family: var(--serif); color: var(--text); font-size: 22px; margin: 0 0 6px; font-weight: 600; }

/* ============ TOAST ============ */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(90px);
  background: var(--btn); color: var(--btn-text); padding: 13px 20px; border-radius: var(--r); font-size: 14px;
  z-index: 990; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow-lg); opacity: 0;
  transition: opacity .3s, transform .3s var(--ease); max-width: min(560px, calc(100vw - 32px));
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast button { background: var(--accent); border: none; color: var(--accent-contrast); padding: 7px 14px; border-radius: 9px; cursor: pointer; font-size: 13px; font-weight: 600; flex: none; }

/* ============ POPOVER D'APERÇU ============ */
#preview-popover {
  position: fixed; z-index: 950; display: none; width: 336px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-lg); overflow: hidden; animation: fadeSlide .18s var(--ease);
}
#preview-popover .pp-img { width: 100%; height: 130px; object-fit: cover; display: block; background: var(--panel-2); }
#preview-popover .pp-body { padding: 13px 16px 15px; }
#preview-popover .pp-path { font-size: 11.5px; color: var(--text-dim); margin-bottom: 4px; }
#preview-popover .pp-title { font-weight: 700; font-size: 15px; margin-bottom: 5px; }
#preview-popover .pp-excerpt { font-size: 13px; color: var(--text-dim); line-height: 1.5; }

/* ============ RECHERCHE ============ */
#search-overlay { position: fixed; inset: 0; z-index: 800; display: none; background: rgba(20, 18, 15, .4); padding: 9vh 16px 0; }
#search-overlay.visible { display: block; }
.search-panel {
  max-width: 640px; margin: 0 auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); overflow: hidden; display: flex; flex-direction: column; max-height: 74vh;
}
.search-input-wrap { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--hairline); }
.search-input-wrap .icon { font-size: 17px; color: var(--text-dim); }
#search-input { flex: 1; border: none; outline: none; font-size: 17px; background: none; color: var(--text); }
#search-results { overflow-y: auto; padding: 7px; }
.search-result { display: block; width: 100%; text-align: left; background: none; border: none; cursor: pointer; padding: 12px 14px; border-radius: var(--r-sm); transition: background .12s; }
.search-result:hover { background: var(--panel-2); }
.search-result.sr-soon { opacity: .55; cursor: default; }
.search-result .sr-path { font-size: 12px; color: var(--text-dim); margin-bottom: 2px; }
.search-result .sr-title { font-weight: 600; font-size: 15px; color: var(--text); }
.search-result .sr-excerpt { font-size: 13px; color: var(--text-dim); margin-top: 3px; line-height: 1.5; }
.search-result mark { background: #fdeea1; color: #201f1c; padding: 0 2px; border-radius: 3px; }
.search-hint { text-align: center; color: var(--text-dim); font-size: 14px; padding: 26px 10px; }
