/* style.css : mise en page de l'interface (S#1-01 ; polices et texte du livre : S#1-03).

   Deux vues, choisies par le lecteur (main.js, attribut data-view sur <body>) :
     - page   : fenêtre au ratio d'une page (8:9) ; le canevas y est recadré
                sur la page affichée ;
     - spread : fenêtre en 16:9, la double page entière, avec les boutons de zoom.
   La forme de la fenêtre (--win-ratio) change en douceur (0,4 s).

   Couleurs : thème par défaut ci-dessous (priorité basse). Le thème adaptatif
   remplace ces variables depuis theme.js, page par page.
   Règle de contraste : --muted ne s'emploie que sur --bg ; sur --surface
   (le Menu), le texte est toujours en --ink.

   Polices : les deux polices du livre (titres, texte des pages) sont des
   fichiers locaux, déclarés ici avec les noms de famille de config.ui.fonts.
   Chacune n'a qu'une graisse : elle est déclarée « normal » (le fichier de
   Berlin Sans FB Demi se dit lui-même gras), et aucun style ne demande de
   gras, pour que le navigateur n'en simule pas. L'interface utilise la
   police du système. */
@font-face {
  font-family: "Berlin Sans FB Demi";
  src: url("fonts/BerlinSansFB-Demi.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: "Futura Book";
  src: url("fonts/Futura-Book.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: block;
}
:root {
  --bg: #17282f;          /* nuit */
  --surface: #314546;     /* pin */
  --ink: #f8e1b8;         /* crème */
  --muted: #8299a1;       /* brume */
  --line: #4e606a;        /* ardoise */
  --accent: #f4c283;      /* abricot */
  --accent-ink: #17282f;  /* nuit */
  --win-ratio: 1.778;     /* largeur / hauteur de la fenêtre, posé par main.js */
  --font-display: "Berlin Sans FB Demi", Georgia, serif;   /* titres (police du livre) */
  --font-body: system-ui, sans-serif;                        /* interface : police du système */
  --font-mono: ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- structure : une colonne à la hauteur de l'écran ---------- */

.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  /* marges de sécurité (encoche, barre d'accueil) */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- en-tête : localisation, titre, onglet Menu ---------- */

.top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  padding: 8px 56px;            /* laisse la place à la localisation et à l'onglet */
}
.moment-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: normal;          /* une seule graisse : pas de gras simulé */
  font-size: clamp(22px, 6vw, 34px);
  line-height: 1.1;
  text-align: center;
  text-wrap: balance;
}
.lang {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  left: calc(env(safe-area-inset-left) + 4px);
  min-width: 44px; min-height: 44px;
  padding: 0;
  background: none;
  border: 0;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0.08em;
  color: var(--accent);
  transform: rotate(-45deg);   /* en diagonale, comme sur le wireframe */
  cursor: pointer;
}
.menu-tab {
  position: absolute;
  z-index: 3;
  top: calc(env(safe-area-inset-top) + 10px);
  right: env(safe-area-inset-right);
  width: 40px;
  min-height: 132px;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 10px 0 0 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.menu-tab > span:last-child { writing-mode: vertical-rl; }   /* le mot « Menu » se lit de haut en bas */

/* ---------- scène : la fenêtre s'ajuste à la zone en gardant son ratio ---------- */

.stage-zone {
  flex: 1 1 0;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
}
.window {
  position: relative;
  width: min(100cqw, 100cqh * var(--win-ratio));
  height: min(100cqh, 100cqw / var(--win-ratio));
  overflow: hidden;
  background: #040817;
}
.stage { position: absolute; inset: 0; touch-action: pan-y; }   /* glissement horizontal laissé à la page : swipe (S#2-04) */
/* Le canevas garde le ratio de la scène et la hauteur de la fenêtre : en
   vue page, ses bords gauche et droit débordent et sont coupés. */
.stage canvas {
  position: absolute;
  top: 0;
  left: 50%;
  height: 100%;
  width: auto;
  aspect-ratio: 16 / 9;
  transform: translateX(-50%);
  display: block;
}
body[data-view="spread"] .stage.is-zoomed { cursor: grab; touch-action: none; }
body[data-view="spread"] .stage.is-dragging { cursor: grabbing; }
.stage-msg {
  position: absolute; inset: 0;
  margin: 0; padding: 20px;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  color: #f8e1b8;
}

.page-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  min-height: 44px;
  padding: 8px 12px;
  background: rgba(23, 40, 47, 0.72);   /* nuit translucide : lisible sur n'importe quel fond */
  color: #f8e1b8;
  border: 0;
  font-weight: 600;
  cursor: pointer;
}
.page-prev { left: 0; border-radius: 0 10px 10px 0; }
.page-next { right: 0; border-radius: 10px 0 0 10px; }
.page-btn:disabled { opacity: 0.35; cursor: default; }

/* Zoom (vue double page seulement) : en haut, sur la jonction des pages, pour
   ne pas recouvrir le texte posé en bas des pages (S#1-04). */
.zoom {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  display: none;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(23, 40, 47, 0.72);
  color: #f8e1b8;
}
body[data-view="spread"] .zoom { display: flex; }

/* ---------- icônes : fichiers SVG utilisés comme masques, teintés par la couleur du texte ---------- */

.icon {
  display: inline-block;
  width: 22px; height: 22px;
  background-color: currentColor;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
}
.icon-play { -webkit-mask-image: url(../img/web/icons/play.svg); mask-image: url(../img/web/icons/play.svg); }
.icon-pause { -webkit-mask-image: url(../img/web/icons/pause.svg); mask-image: url(../img/web/icons/pause.svg); }
.icon-menu { -webkit-mask-image: url(../img/web/icons/menu.svg); mask-image: url(../img/web/icons/menu.svg); }
.icon-close { -webkit-mask-image: url(../img/web/icons/close.svg); mask-image: url(../img/web/icons/close.svg); }
.icon-sound-on { -webkit-mask-image: url(../img/web/icons/sound-on.svg); mask-image: url(../img/web/icons/sound-on.svg); }
.icon-sound-off { -webkit-mask-image: url(../img/web/icons/sound-off.svg); mask-image: url(../img/web/icons/sound-off.svg); }
.icon-zoom-in { -webkit-mask-image: url(../img/web/icons/zoom-in.svg); mask-image: url(../img/web/icons/zoom-in.svg); }
.icon-zoom-out { -webkit-mask-image: url(../img/web/icons/zoom-out.svg); mask-image: url(../img/web/icons/zoom-out.svg); }
.icon-zoom-fit { -webkit-mask-image: url(../img/web/icons/zoom-fit.svg); mask-image: url(../img/web/icons/zoom-fit.svg); }

.icon-btn {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn:disabled { opacity: 0.35; cursor: default; }

/* ---------- progression : lecture/pause, curseur, temps ---------- */
/* S#2-01 : le lecteur tourne les pages lui-même ; sans « ?debug » dans
   l'adresse, il ne reste que le bouton Lecture/Pause, centré, et depuis
   S#2-02 le numéro de page. Le curseur, ses
   repères et le temps restent pour les tests (?debug, classe .debug du body). */

.progress {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px 0 4px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.scrub { position: relative; flex: 1 1 auto; min-width: 0; height: 44px; display: flex; align-items: center; }
.scrub input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
/* Repères : fins pour les moments clés, plus marqués pour les pages. */
.ticks { position: absolute; left: 8px; right: 8px; bottom: 4px; height: 8px; pointer-events: none; }
.ticks span {
  position: absolute;
  bottom: 0;
  width: 2px; height: 5px;
  margin-left: -1px;
  background: var(--muted);
}
.ticks span.tick-page { width: 3px; height: 8px; margin-left: -1.5px; background: var(--accent); }
.time {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
body:not(.debug) .scrub,
body:not(.debug) .time { display: none; }
body:not(.debug) .progress { justify-content: center; padding-right: 4px; }
/* Journal de la console à l'écran, sous ?debug (débogage #1 de S#2-02, js/journal.js). */
.journal {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: 38vh; margin: 0; padding: 6px 8px; overflow: auto;
  background: rgba(0, 0, 0, 0.82); color: #f8e1b8;
  font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
}
/* Numéro de page (S#2-02) : à la place de la timeline, à côté du bouton Lecture/Pause, toujours visible. */
.page-num {
  flex: 0 0 auto;
  min-width: 9ch;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--ink);
  white-space: nowrap;
}

/* La zone de texte du moment a disparu (S#1-03) : le texte du livre est dans
   la page, dans le canevas. La zone de la scène prend tout l'espace entre
   l'en-tête et la progression ; la fenêtre y est centrée, et la progression
   reste collée en bas de l'écran. */
body[data-view="spread"] .top { min-height: 48px; padding-top: 4px; padding-bottom: 4px; }
body[data-view="spread"] .moment-title { font-size: clamp(20px, 3.4vh, 30px); }
body[data-view="spread"] .menu-tab { min-height: 110px; }

/* ---------- Menu (dialog natif : Échap et piège du focus fournis par le navigateur) ---------- */

.menu {
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  margin: auto 0 auto auto;       /* collé au bord droit, du côté de l'onglet, centré en hauteur */
  padding: 16px 18px 14px;
  background: var(--surface);
  color: var(--ink);              /* jamais --muted ici : contraste insuffisant sur --surface */
  border: 1px solid var(--line);
  border-radius: 14px 0 0 14px;
  overflow-y: auto;
}
.menu::backdrop { background: rgba(4, 8, 23, 0.6); }
.menu-head { display: flex; align-items: center; justify-content: space-between; }
.menu h2 { margin: 0; font-family: var(--font-display); font-weight: normal; font-size: 26px; }
.menu h3 {
  margin: 18px 0 8px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.moments { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.moment {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
}
.moment-n, .moment-time { font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.moment-t { flex: 1 1 auto; font-weight: 500; }
.moment.is-current { border-color: var(--accent); background: rgba(0, 0, 0, 0.18); }
.moment.is-current .moment-n { color: var(--accent); }

.btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: none;
  border: 1px solid var(--ink);
  border-radius: 10px;
  font-weight: 500;
  cursor: pointer;
}
.btn[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.view-switch { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn:disabled { opacity: 0.5; cursor: default; }
.hint { margin: 0 0 10px; font-size: 14px; }
.status { margin: 8px 0 0; min-height: 1.5em; font-size: 14px; }
.version { margin: 18px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-family: var(--font-mono); font-size: 12px; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .icon-btn, .page-btn, .moment { transition: opacity 0.15s; }
  /* Changement de vue du lecteur : la fenêtre change de forme en 0,4 s (ui.viewEase). */
  /* (pas au chargement : main.js ajoute .is-ready une fois la première forme posée) */
  .app.is-ready .window { transition: width 0.4s ease-in-out, height 0.4s ease-in-out; }
}
