:root {
  --bg-deep: #070b16;
  --bg-card: #111827;
  --bg-glass: rgba(11, 17, 32, 0.82);
  --border-subtle: rgba(148, 163, 184, 0.22);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #f59e0b;
  --accent-strong: #fbbf24;
  --danger: #ef4444;
  --story-font-scale: 1;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100dvh;
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

/* ========================================================================= */
/* DIRECTIONAL VIEW TRANSITIONS (modern-web-guidance)                        */
/* ========================================================================= */
@keyframes slide-to-left {
  to {
    transform: translateX(-100%);
  }
}

@keyframes slide-from-right {
  from {
    transform: translateX(100%);
  }
}

@keyframes slide-to-right {
  to {
    transform: translateX(100%);
  }
}

@keyframes slide-from-left {
  from {
    transform: translateX(-100%);
  }
}

::view-transition-group(root) {
  animation: 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}

html:active-view-transition-type(forward)::view-transition-old(root) {
  animation-name: slide-to-left;
}
html:active-view-transition-type(forward)::view-transition-new(root) {
  animation-name: slide-from-right;
}

html:active-view-transition-type(backward)::view-transition-old(root) {
  animation-name: slide-to-right;
}
html:active-view-transition-type(backward)::view-transition-new(root) {
  animation-name: slide-from-left;
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(root) {
    animation: none !important;
  }
}

/* ========================================================================= */
/* ÉCRAN 1 : BIBLIOTHÈQUE (https://bib.menfin.fr)                            */
/* ========================================================================= */
.library-view {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.library-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 1.5rem;
}

.library-header__domain {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--accent-strong);
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.35);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

.library-header__title {
  margin: 0.35rem 0 0.2rem;
  font-size: 1.85rem;
  letter-spacing: -0.02em;
}

.library-header__subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.library-header__controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-pill {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.88rem;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.icon-pill:hover {
  border-color: var(--accent);
}

.icon-pill--accent {
  background: rgba(245, 158, 11, 0.18);
  border-color: rgba(245, 158, 11, 0.5);
  color: #fef3c7;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.story-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 1rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
}

.story-card__cover-wrap {
  position: relative;
  aspect-ratio: 9 / 14;
  background: #050811;
  overflow: hidden;
  cursor: pointer;
}

.story-card__cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease;
}

.story-card__cover-wrap:hover .story-card__cover {
  transform: scale(1.04);
}

.story-card__genre {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  background: rgba(7, 11, 22, 0.85);
  border: 1px solid var(--border-subtle);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.story-card__badge {
  position: absolute;
  bottom: 0.75rem;
  left: 0.75rem;
  right: 0.75rem;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(251, 191, 36, 0.45);
  color: #fde68a;
  padding: 0.35rem 0.65rem;
  border-radius: 0.5rem;
  font-size: 0.76rem;
  font-weight: 600;
  text-align: center;
}

.story-card__body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.story-card__title {
  margin: 0;
  font-size: 1.2rem;
}

.story-card__subtitle {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.story-card__meta {
  margin: 0.2rem 0 0.5rem;
  font-size: 0.78rem;
  color: #cbd5e1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.story-card__actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn {
  width: 100%;
  padding: 0.68rem 0.9rem;
  border-radius: 0.65rem;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.9rem;
  text-align: center;
}

.btn--primary {
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #090d16;
}

.btn--ghost {
  background: rgba(30, 41, 59, 0.7);
  border-color: var(--border-subtle);
  color: #e2e8f0;
  font-weight: 600;
  font-size: 0.82rem;
}

/* ========================================================================= */
/* ÉCRAN 2 : LECTEUR PLEIN ÉCRAN VERTICAL (100% de l'écran)                  */
/* ========================================================================= */
.player-view {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  background: #000;
  overflow: hidden;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: min(100vw, calc(100dvh * 9 / 16));
  max-height: 100dvh;
  overflow: hidden;
  touch-action: none;
  background: #070b16;
}

@media (max-width: 640px) {
  .player-viewport {
    max-width: 100vw;
  }
}

.zoom-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-origin: center center;
  will-change: transform;
}

.frame-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

/* Retour visuel lors d'une vibration haptique */
@keyframes haptic-shake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  20% {
    transform: translate3d(-4px, 2px, 0);
  }
  40% {
    transform: translate3d(4px, -3px, 0);
  }
  60% {
    transform: translate3d(-3px, -2px, 0);
  }
  80% {
    transform: translate3d(3px, 2px, 0);
  }
}

.player-view.haptic-pulse .player-viewport {
  animation: haptic-shake 0.28s ease-in-out;
}

/* ========================================================================= */
/* CALQUE CARTOUCHE & PHYLACTÈRE (Multilingue + Taille dynamique)            */
/* ========================================================================= */
.overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.story-overlay {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: calc(0.75rem * var(--story-font-scale)) calc(1rem * var(--story-font-scale));
  font-size: calc(1rem * var(--story-font-scale));
  line-height: 1.38;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.65);
  transition: font-size 0.15s ease, padding 0.15s ease;
}

/* Cartouche narratif (rectangulaire, bordure ambrée) */
.story-overlay--cartouche {
  background: rgba(15, 23, 42, 0.92);
  border: 2px solid #f59e0b;
  border-left-width: 6px;
  border-radius: 0.45rem;
  color: #fef3c7;
}

/* Phylactère / Bulle de dialogue */
.story-overlay--phylactere {
  background: #ffffff;
  color: #0f172a;
  border: 3px solid #0f172a;
  border-radius: 1.25rem;
}

.story-overlay__speaker {
  font-size: calc(0.74rem * var(--story-font-scale));
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #b45309;
  margin-bottom: 0.2rem;
}

.story-overlay__text {
  margin: 0;
  font-weight: 600;
}

.story-overlay__tail {
  position: absolute;
  bottom: -14px;
  left: calc(50% + var(--tail-offset-x, 0px));
  width: 0;
  height: 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-top: 15px solid #ffffff;
  filter: drop-shadow(0 3px 0 #0f172a);
}

/* ========================================================================= */
/* CALQUE D'EFFET VISUEL SIMPLE (ex: « PAN ! » jaune et rouge)               */
/* ========================================================================= */
.effect-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

@keyframes pan-burst-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.25) rotate(-14deg);
  }
  22% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.18) rotate(6deg);
  }
  40% {
    transform: translate(-50%, -50%) scale(0.95) rotate(-4deg);
  }
  65% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.06) rotate(2deg);
  }
  100% {
    opacity: 0.92;
    transform: translate(-50%, -50%) scale(1) rotate(-2deg);
  }
}

.story-effect {
  position: absolute;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  animation: pan-burst-pop var(--fx-duration, 1000ms) cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

.pan-burst-svg {
  width: clamp(190px, 52vw, 280px);
  height: auto;
  filter: drop-shadow(0 8px 20px rgba(220, 38, 38, 0.75));
}

.pan-burst-text {
  position: absolute;
  font-weight: 900;
  font-size: calc(2.15rem * var(--story-font-scale));
  color: #dc2626;
  text-shadow:
    -2px -2px 0 #fef08a,
    2px -2px 0 #fef08a,
    -2px 2px 0 #fef08a,
    2px 2px 0 #090d16;
  letter-spacing: 0.04em;
  transform: rotate(-6deg);
}

.simple-fx-badge {
  background: rgba(250, 204, 21, 0.94);
  color: #7f1d1d;
  border: 3px solid #dc2626;
  padding: 0.35rem 0.85rem;
  border-radius: 0.6rem;
  font-weight: 900;
  font-size: calc(1.3rem * var(--story-font-scale));
  letter-spacing: 0.06em;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
}

/* ========================================================================= */
/* HUD ET ZONES DE L'ÉCRAN                                                   */
/* ========================================================================= */
.progress-track {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.16);
  z-index: 12;
}

.progress-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  transform-origin: left center;
  transform: scaleX(0);
}

.player-hud {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: min(100vw, calc(100dvh * 9 / 16));
  z-index: 10;
  padding: 0.6rem 0.75rem;
  transition: opacity 0.22s ease;
}

@media (max-width: 640px) {
  .player-hud {
    max-width: 100vw;
  }
}

.player-view:not(.hud-visible) .player-hud {
  opacity: 0;
  pointer-events: none;
}

.player-hud--top {
  top: 4px;
  background: linear-gradient(to bottom, rgba(7, 11, 22, 0.86), transparent);
}

.player-hud--bottom {
  bottom: 0;
  background: linear-gradient(to top, rgba(7, 11, 22, 0.9), transparent);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.player-hud__top-bar,
.player-hud__bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
}

.hud-titles {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 0;
}

.hud-story-title {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-location {
  font-size: 0.72rem;
  color: #fde68a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-actions {
  display: flex;
  gap: 0.35rem;
}

.hud-btn,
.zone-pill,
.zoom-btn {
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 0.38rem 0.65rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}

.hud-btn--accent {
  border-color: rgba(245, 158, 11, 0.6);
  color: #fde68a;
}

.zone-pill:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.part-zones-bar {
  margin-top: 0.45rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.streak-badge,
.sensory-pill {
  background: rgba(245, 158, 11, 0.22);
  border: 1px solid rgba(251, 191, 36, 0.65);
  color: #fef08a;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-transport {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.hud-frame-counter {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
  padding: 0 0.25rem;
}

.zoom-hint {
  align-self: center;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #bae6fd;
  font-size: 0.72rem;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
}

.zoom-bar {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
}

/* Carte visuelle des zones de l'écran */
.zones-guide-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: rgba(7, 11, 22, 0.76);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4.5rem 0.75rem 5.5rem;
  text-align: center;
  font-weight: 700;
}

.zones-guide__row {
  display: flex;
  gap: 0.5rem;
}

.zones-guide__row > span {
  flex: 1;
  border: 2px dashed rgba(251, 191, 36, 0.75);
  background: rgba(15, 23, 42, 0.75);
  border-radius: 0.75rem;
  padding: 0.75rem 0.4rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 0.82rem;
  color: #fef3c7;
}

.zones-guide__row--middle {
  flex: 1;
  margin: 0.5rem 0;
}

/* ========================================================================= */
/* DIALOGUE NATIF DES 4 RÉGLAGES (animate-to-from-top-layer)                 */
/* ========================================================================= */
.settings-dialog {
  width: min(92vw, 400px);
  border: 1px solid var(--border-subtle);
  border-radius: 1.15rem;
  background: #0f172a;
  color: var(--text-main);
  padding: 0;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.75);

  opacity: 0;
  transform: scale(0.92);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease,
    overlay 0.22s ease allow-discrete,
    display 0.22s ease allow-discrete;
}

.settings-dialog::backdrop {
  background-color: transparent;
  backdrop-filter: blur(3px);
  transition:
    background-color 0.22s ease,
    overlay 0.22s ease allow-discrete,
    display 0.22s ease allow-discrete;
}

:is(dialog.settings-dialog[open]):where(:not([data-closing])) {
  opacity: 1;
  transform: scale(1);

  @starting-style {
    opacity: 0;
    transform: scale(0.92);
  }

  &::backdrop {
    background-color: rgba(2, 6, 23, 0.72);

    @starting-style {
      background-color: transparent;
    }
  }
}

.settings-dialog__inner {
  padding: 1.15rem;
}

.settings-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border-subtle);
}

.settings-dialog__header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 1.05rem;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.setting-item--column {
  flex-direction: column;
  align-items: stretch;
}

.setting-item__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.setting-item__label {
  font-weight: 700;
  font-size: 0.94rem;
  display: block;
}

.setting-item__hint {
  color: var(--text-muted);
  font-size: 0.76rem;
}

.setting-item__value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent-strong);
}

.segmented-control {
  display: inline-flex;
  background: #1e293b;
  border-radius: 0.6rem;
  padding: 0.2rem;
}

.segmented-control__option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control__option span {
  display: block;
  padding: 0.35rem 0.75rem;
  border-radius: 0.45rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.segmented-control__option input:checked + span {
  background: var(--accent);
  color: #090d16;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch__slider {
  position: absolute;
  inset: 0;
  background-color: #334155;
  border-radius: 999px;
  transition: 0.2s;
  cursor: pointer;
}

.switch__slider::before {
  content: "";
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .switch__slider {
  background-color: var(--accent);
}

.switch input:checked + .switch__slider::before {
  transform: translateX(22px);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.text-size-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
}

.size-btn {
  background: #1e293b;
  border: 1px solid var(--border-subtle);
  border-radius: 0.5rem;
  padding: 0.45rem 0.3rem;
  font-weight: 700;
  font-size: 0.84rem;
}

.size-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #090d16;
  border-color: var(--accent);
}

/* ========================================================================= */
/* TOASTS DE NOTIFICATION                                                    */
/* ========================================================================= */
.toast-container {
  position: fixed;
  top: 4.2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  pointer-events: none;
  width: min(92vw, 380px);
}

.toast-message {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--accent);
  color: #fef3c7;
  padding: 0.6rem 0.9rem;
  border-radius: 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.6);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast-message.is-leaving {
  opacity: 0;
  transform: translateY(-8px);
}
