/* ============================================================
   HARMONISATION DES BOUTONS
   Place commune (transition, relief au survol, bordure accent,
   focus clavier) pour que tous les boutons forment une famille.
   N'affecte que l'apparence — aucune taille ni position changée.
   ============================================================ */

/* Fonds sombres unifiés pour les boutons secondaires (flèches, fermer). */
.page-arrow,
.route-map-close {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent),
    rgba(16, 20, 26, 0.94);
}

/* Transition commune à tous les boutons. */
.chapter-select-button,
.reading-mode-switch,
.page-arrow,
.route-map-toggle,
.route-map-recenter,
.route-map-close,
.route-choice,
.reading-mode-close,
.story-panel-close,
.reading-mode-choice {
  transition: transform 150ms ease, background 150ms ease,
    border-color 150ms ease, box-shadow 150ms ease;
}

/* Survol : même léger relief + même bordure accent partout. */
@media (hover: hover) {
  .chapter-select-button:hover,
  .reading-mode-switch:hover,
  .page-arrow:hover:not(:disabled),
  .route-map-recenter:hover,
  .route-map-close:hover,
  .route-choice:hover:not(:disabled),
  .reading-mode-close:hover,
  .story-panel-close:hover {
    transform: translateY(-1px);
    border-color: rgba(226, 180, 93, 0.8);
  }

  /* Le bouton « Chemin narratif » est l'action principale : il s'éclaire
     un peu et se soulève, sans changer de bordure. */
  .route-map-toggle:hover {
    transform: translateY(-1px);
  }
}

/* Focus clavier visible et identique partout (sans casser le survol). */
.chapter-select-button:focus-visible,
.reading-mode-switch:focus-visible,
.page-arrow:focus-visible,
.route-map-toggle:focus-visible,
.route-map-recenter:focus-visible,
.route-map-close:focus-visible,
.route-choice:focus-visible,
.reading-mode-close:focus-visible,
.story-panel-close:focus-visible,
.reading-mode-choice:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

/* ============================================================
   MEDIA QUERIES RESPONSIVES (820px, 680px, reduced-motion)
   ============================================================ */
/* ============================================================
   CODEX (personnages & lieux)
   ============================================================ */
.codex-toggle {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 0.45rem;
  flex: 0 0 auto;
  min-height: 2.6rem;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.4rem 0.72rem;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent),
    rgba(16, 20, 26, 0.94);
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  box-shadow: 0 0.9rem 2rem rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 150ms ease, border-color 150ms ease;
}

.codex-toggle:focus-visible {
  border-color: rgba(226, 180, 93, 0.75);
  outline: none;
}

@media (hover: hover) {
  .codex-toggle:hover {
    border-color: rgba(226, 180, 93, 0.75);
    transform: translateY(-1px);
  }
}

.codex-toggle-icon {
  width: 1.15rem;
  height: 1.15rem;
  background: var(--accent-strong);
  -webkit-mask: var(--icon-book) center / contain no-repeat;
  mask: var(--icon-book) center / contain no-repeat;
}

.codex-modal {
  width: min(64rem, calc(100vw - 1.6rem));
  max-width: none;
  max-height: calc(100svh - 1.6rem);
  /* Ancrée en haut : quand on change d'onglet, la modale se redimensionne par le
     bas (le haut, donc les onglets, ne bouge pas). */
  margin: 0.8rem auto auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 18rem),
    var(--surface);
  box-shadow: 0 2rem 5rem rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.codex-modal::backdrop {
  background: rgba(6, 8, 11, 0.72);
  backdrop-filter: blur(3px);
}

.codex-dialog {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: calc(100svh - 1.6rem);
}

.codex-header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1rem 1.1rem 0.85rem;
  border-bottom: 1px solid var(--line);
}

.codex-title-block {
  display: grid;
  gap: 0.15rem;
  margin-right: auto;
}

.codex-title-block h2 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
}

.codex-tabs {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.22rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.32);
}

.codex-tab {
  border: 0;
  border-radius: 999px;
  padding: 0.4rem 0.95rem;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
  transition: color 150ms ease, background 150ms ease;
}

.codex-tab[aria-selected="true"] {
  color: #1c1407;
  background: var(--accent-strong);
}

@media (hover: hover) {
  .codex-tab:hover:not([aria-selected="true"]) {
    color: var(--text);
  }
}

.codex-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 2.2rem;
  aspect-ratio: 1;
  border: 1px solid rgba(226, 180, 93, 0.38);
  border-radius: 8px;
  color: var(--accent-strong);
  background: rgba(226, 180, 93, 0.08);
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
  transition: border-color 150ms ease, background 150ms ease;
}

.codex-close:focus-visible {
  border-color: rgba(226, 180, 93, 0.78);
  background: rgba(226, 180, 93, 0.14);
  outline: none;
}

@media (hover: hover) {
  .codex-close:hover {
    border-color: rgba(226, 180, 93, 0.78);
    background: rgba(226, 180, 93, 0.14);
  }
}

/* Grille auto-fill : les colonnes (1fr) remplissent la largeur de la modale,
   mais une carte seule sur sa rangée n'occupe qu'une colonne (auto-fill garde
   les pistes vides) -> elle ne s'étire pas sur toute la largeur. */
.codex-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  align-content: start;
  gap: 0.9rem;
  overflow-y: auto;
  padding: 1.1rem;
}

.codex-body[data-tab="places"] {
  grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
}

.codex-body[data-tab="objects"] {
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
}

/* Vue détail : un seul bloc pleine largeur, pas de grille. */
.codex-body[data-tab="detail"] {
  display: block;
}

/* Carte en grille (média auto + corps 1fr) : sizing fiable quand la grille
   parente étire les cartes à hauteur égale.
   Pas d'overflow:hidden ici : un conteneur de défilement a une taille minimale
   nulle, ce qui effondre la rangée de la grille parente quand elle défile. Les
   coins du média sont arrondis directement sur le média. */
.codex-card {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(13, 16, 21, 0.7);
}

/* Hauteur fixe : aspect-ratio et padding-bottom % dépendent de la largeur de
   colonne, non résolue quand la grille dimensionne ses rangées -> rangées
   écrasées. Une hauteur fixe est fiable. */
.codex-card-media {
  position: relative;
  width: 100%;
  height: 13.5rem;
  overflow: hidden;
  border-radius: 11px 11px 0 0;
  background: #0b0d10;
}

.codex-card-media-place {
  height: 10rem;
}

.codex-card-media-object {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--object-accent, var(--accent)) 24%, transparent), transparent 52%),
    rgba(0, 0, 0, 0.2);
}

.codex-card-media-object .story-object-visual {
  width: min(72%, 9rem);
  transform: scale(1.08);
}

.codex-card-media > img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 24%;
}

.codex-card-media-place > img {
  object-position: 50% 42%;
}

.codex-card-media-empty {
  background:
    radial-gradient(circle at 50% 35%, rgba(226, 180, 93, 0.16), transparent 60%),
    #11151b;
}

.codex-card-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(226, 180, 93, 0.55);
  font-size: 2.6rem;
  font-weight: 850;
}

.codex-badge {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.64rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow: 0 0.25rem 0.6rem rgba(0, 0, 0, 0.4);
}

.codex-badge-pj {
  color: #11160d;
  background: #cde08f;
}

.codex-badge-pnj {
  color: #1c1407;
  background: var(--accent-strong);
}

.codex-badge-creature {
  color: #1a0c08;
  background: #d2785f;
}

.codex-badge-object {
  color: #14110a;
  background: var(--object-accent, var(--accent-strong));
}

.codex-card-body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.8rem 0.85rem 0.9rem;
}

/* Pied de carte poussé en bas : la méta et le lien « Voir N planches »
   s'alignent au même niveau d'une carte à l'autre (cartes de hauteur égale
   grâce à la grille). */
.codex-card-foot {
  display: grid;
  gap: 0.4rem;
  margin-top: auto;
  padding-top: 0.4rem;
}

.codex-card-name {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
  line-height: 1.15;
}

.codex-card-desc {
  margin: 0;
  color: var(--muted-strong);
  font-size: 0.86rem;
  line-height: 1.4;
}

.codex-card-meta {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.15rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.codex-meta-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 1.5rem;
}

.codex-meta-where-row::before {
  content: "";
  flex: 0 0 auto;
  width: 0.95rem;
  height: 0.95rem;
  background: var(--accent-strong);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0'/%3E%3Ccircle cx='12' cy='10' r='2.6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0'/%3E%3Ccircle cx='12' cy='10' r='2.6'/%3E%3C/svg%3E") center / contain no-repeat;
}

.codex-meta-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.codex-meta-where {
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
}

.codex-meta-avatars {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.codex-meta-avatar {
  display: block;
  width: 1.5rem;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid rgba(226, 180, 93, 0.5);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.codex-meta-avatar + .codex-meta-avatar {
  margin-left: -0.45rem;
}

.codex-meta-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 28%;
}

/* --- Carte cliquable + lien « voir les planches » --- */
.codex-card-clickable {
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease;
}

.codex-card-clickable:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(226, 180, 93, 0.45);
  outline: none;
}

@media (hover: hover) {
  .codex-card-clickable:hover {
    transform: translateY(-2px);
    border-color: rgba(226, 180, 93, 0.45);
  }
}

.codex-card-link {
  margin-top: 0.55rem;
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 800;
}

/* --- Vue détail : planches où la fiche apparaît --- */
.codex-detail {
  display: grid;
  gap: 1rem;
  width: 100%;
}

.codex-back {
  justify-self: start;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.42rem 0.95rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.28);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
  transition: border-color 150ms ease, background 150ms ease;
}

.codex-back:focus-visible {
  border-color: rgba(226, 180, 93, 0.6);
  background: rgba(226, 180, 93, 0.08);
  outline: none;
}

@media (hover: hover) {
  .codex-back:hover {
    border-color: rgba(226, 180, 93, 0.6);
    background: rgba(226, 180, 93, 0.08);
  }
}

.codex-detail-head {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.codex-detail-portrait {
  flex: 0 0 auto;
  width: 7rem;
  height: 7rem;
  overflow: hidden;
  border-radius: 12px;
  background: #0b0d10;
}

.codex-detail-portrait > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 24%;
}

.codex-detail-object-media {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--object-accent, var(--accent)) 22%, transparent), transparent 58%),
    rgba(0, 0, 0, 0.22);
}

.codex-detail-object-media .story-object-visual {
  width: min(70%, 10rem);
}

.codex-detail-headbody {
  display: grid;
  gap: 0.35rem;
}

.codex-detail-name {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
}

.codex-detail-desc {
  margin: 0;
  color: var(--muted-strong);
  line-height: 1.5;
}

.codex-object-desc {
  display: grid;
  gap: 0.5rem;
}

.codex-object-desc p {
  margin: 0;
}

.codex-detail-meta {
  margin-top: 0.25rem;
  align-self: start;
}

.codex-detail-prop {
  display: block;
  justify-self: start;
  width: clamp(3.6rem, 8vw, 5.2rem);
  height: auto;
  margin-top: 0.15rem;
  filter:
    drop-shadow(0 0.7rem 0.85rem rgba(0, 0, 0, 0.5))
    drop-shadow(0 0 0.45rem rgba(226, 180, 93, 0.12));
  pointer-events: none;
  transform: rotate(var(--prop-rotate, 0deg)) scale(var(--prop-scale, 1));
  transform-origin: 50% 55%;
  user-select: none;
}

.codex-detail-section {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.codex-detail-empty {
  margin: 0;
  color: var(--muted);
}

.codex-object-meta,
.codex-object-details {
  margin-top: 0.85rem;
}

.codex-appearance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.7rem;
}

.codex-appearance {
  display: grid;
  grid-template-rows: auto auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  background: rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease;
}

.codex-appearance:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(226, 180, 93, 0.6);
  outline: none;
}

@media (hover: hover) {
  .codex-appearance:hover {
    transform: translateY(-2px);
    border-color: rgba(226, 180, 93, 0.6);
  }
}

.codex-appearance img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  object-position: 50% 8%;
}

.codex-appearance-caption {
  padding: 0.35rem 0.45rem 0.5rem;
  color: var(--muted-strong);
  font-size: 0.72rem;
  font-weight: 750;
  line-height: 1.15;
  text-align: left;
}

@media (max-width: 1024px) {
  .reader-shell {
    grid-template-columns: minmax(0, 1fr) minmax(15rem, 20rem);
  }
}

@media (max-width: 820px) {
  :root {
    --page-width: min(calc(100vw - 1.2rem), calc((100svh - 7.4rem) * 0.6667));
  }

  body {
    overflow: auto;
    min-height: 100vh;
  }

  .reader-shell {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.55rem;
    min-height: auto;
    padding: 0.52rem 0.44rem 0.72rem;
  }

  .reader-heading {
    position: relative;
    width: 100%;
    margin-bottom: 0.45rem;
  }

  .reader-chapter-jump {
    min-width: 0;
    position: static;
  }

  .chapter-select-button {
    min-width: 0;
  }

  .reader-chapter-jump .chapter-select-menu {
    left: 0;
    right: 0;
    width: auto;
  }

  .reader-controls {
    position: static;
    gap: 0.55rem;
  }

  .page-nav-card {
    display: none;
  }

  .reader-stage {
    align-items: start;
  }

  .reader-page-unit {
    position: relative;
    grid-template-areas: "page";
    grid-template-columns: minmax(0, var(--page-width));
    align-content: start;
  }

  .panel-card {
    max-width: none;
  }

  .panel-card::before,
  .panel-card::after {
    display: none;
  }

  .story-panel {
    position: absolute;
    top: clamp(0.52rem, 2.2vw, 0.78rem);
    right: clamp(0.52rem, 2.2vw, 0.78rem);
    bottom: auto;
    left: auto;
    z-index: 6;
    width: auto;
    cursor: pointer;
    transform: none;
  }

  .story-panel[data-story-expanded="true"] {
    top: auto;
    left: clamp(0.56rem, 2.4vw, 0.9rem);
    right: clamp(0.56rem, 2.4vw, 0.9rem);
    bottom: clamp(0.58rem, 2.5vw, 0.92rem);
    width: auto;
    cursor: default;
    transform: none;
  }

  .story-panel .panel-card {
    display: grid;
    place-items: center;
    width: 2.82rem;
    aspect-ratio: 1;
    gap: 0;
    max-height: none;
    overflow: hidden;
    border: 1px solid rgba(226, 180, 93, 0.22);
    border-radius: 10px;
    padding: 0;
    color: var(--text);
    background:
      radial-gradient(circle at 78% 22%, rgba(226, 180, 93, 0.2), transparent 34%),
      linear-gradient(145deg, rgba(255, 255, 255, 0.1), transparent 48%),
      rgba(12, 15, 19, 0.68);
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.22),
      0 0.55rem 1.25rem rgba(0, 0, 0, 0.26);
    backdrop-filter: blur(10px);
    -webkit-overflow-scrolling: touch;
  }

  .story-panel .panel-card::before {
    content: "";
    position: static;
    display: block;
    width: 1.58rem;
    aspect-ratio: 1;
    background: rgba(244, 240, 232, 0.82);
    -webkit-mask: var(--icon-message) center / contain no-repeat;
    mask: var(--icon-message) center / contain no-repeat;
  }

  body[data-reader-character] .story-panel:not([data-story-expanded="true"]) .panel-card {
    border-color: rgba(var(--character-accent-rgb), 0.46);
    color: var(--accent-strong);
    background:
      radial-gradient(circle at 78% 22%, rgba(var(--character-accent-rgb), 0.24), transparent 34%),
      linear-gradient(145deg, rgba(255, 255, 255, 0.1), transparent 48%),
      rgba(12, 15, 19, 0.76);
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.24),
      0 0.55rem 1.25rem rgba(0, 0, 0, 0.3),
      0 0 1rem rgba(var(--character-accent-rgb), 0.12);
  }

  body[data-reader-character] .story-panel:not([data-story-expanded="true"]) .panel-card::before {
    width: 1.86rem;
    background: var(--reader-prop-image) center / contain no-repeat;
    filter:
      drop-shadow(0 0.38rem 0.42rem rgba(0, 0, 0, 0.38))
      drop-shadow(0 0 0.22rem rgba(var(--character-accent-rgb), 0.24));
    -webkit-mask: none;
    mask: none;
    transform: rotate(var(--reader-prop-rotate, 0deg)) scale(var(--reader-prop-scale, 1));
  }

  .story-panel .panel-card::after {
    display: none;
  }

  .story-panel[data-story-expanded="true"] .panel-card {
    display: grid;
    place-items: stretch;
    width: auto;
    aspect-ratio: auto;
    gap: 0.5rem;
    max-height: min(34svh, 13.5rem);
    overflow-y: auto;
    border: 1px solid rgba(226, 180, 93, 0.26);
    border-radius: 8px;
    padding: 0.7rem 2.64rem 0.78rem 0.78rem;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 36%),
      rgba(12, 15, 19, 0.82);
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.34),
      0 0.8rem 1.8rem rgba(0, 0, 0, 0.38);
    scrollbar-color: rgba(226, 180, 93, 0.78) rgba(255, 255, 255, 0.12);
    scrollbar-width: thin;
  }

  .story-panel[data-story-expanded="true"] .panel-card::before {
    display: none;
  }

  .story-panel[data-story-expanded="true"] .panel-card::after {
    display: none;
  }

  .story-panel[data-story-expanded="true"] .story-panel-close {
    position: absolute;
    top: 0.48rem;
    right: 0.48rem;
    display: grid;
    place-items: center;
    width: 1.72rem;
    aspect-ratio: 1;
    border: 1px solid rgba(226, 180, 93, 0.32);
    border-radius: 999px;
    padding: 0;
    color: rgba(244, 240, 232, 0.86);
    background: rgba(8, 10, 13, 0.42);
    box-shadow: 0 0.34rem 0.82rem rgba(0, 0, 0, 0.22);
    font-size: 1.02rem;
    font-weight: 800;
    line-height: 1;
  }

  .story-panel[data-story-expanded="true"] .story-panel-close:focus-visible {
    border-color: rgba(226, 180, 93, 0.68);
    color: var(--text);
    outline: none;
    background: rgba(226, 180, 93, 0.16);
  }

  @media (hover: hover) {
    .story-panel[data-story-expanded="true"] .story-panel-close:hover {
      border-color: rgba(226, 180, 93, 0.68);
      color: var(--text);
      background: rgba(226, 180, 93, 0.16);
    }
  }

  .story-panel[data-story-expanded="true"] .panel-card::-webkit-scrollbar {
    width: 0.36rem;
  }

  .story-panel[data-story-expanded="true"] .panel-card::-webkit-scrollbar-track {
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
  }

  .story-panel[data-story-expanded="true"] .panel-card::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(226, 180, 93, 0.76);
  }

  .story-panel .panel-card h2 {
    display: none;
    margin: -0.1rem 0 0;
    color: var(--text);
    overflow: hidden;
    font-size: clamp(0.88rem, 2.55vw, 1.02rem);
    line-height: 1.08;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .story-panel[data-story-expanded="true"] .panel-card h2 {
    display: block;
    font-size: clamp(0.96rem, 2.7vw, 1.12rem);
    white-space: normal;
  }

  .story-panel .panel-card .eyebrow {
    display: none;
    color: var(--accent-strong);
    font-size: 0.58rem;
  }

  .story-panel[data-story-expanded="true"] .panel-card .eyebrow {
    display: block;
  }

  .story-panel .story-text {
    display: none;
    gap: 0.44rem;
  }

  .story-panel[data-story-expanded="true"] .story-text {
    display: grid;
  }

  .story-panel .story-text p {
    color: rgba(244, 240, 232, 0.86);
    font-size: clamp(0.78rem, 2.35vw, 0.92rem);
    line-height: 1.4;
  }

  .story-object-marker {
    min-width: 2.55rem;
    max-width: 4.4rem;
  }

  .story-object-modal {
    width: calc(100vw - 0.8rem);
    max-height: calc(100svh - 0.8rem);
  }

  .story-object-dialog {
    padding: 0.9rem;
  }

  .story-object-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .story-object-media {
    min-height: 11rem;
  }

  .story-object-media .story-object-visual {
    width: min(8.5rem, 36vw);
  }

  .page-click-zone {
    z-index: 5;
    width: 30%;
    cursor: pointer;
  }

  .page-click-zone::before {
    content: "";
    position: absolute;
    top: 46%;
    display: grid;
    place-items: center;
    width: clamp(2.35rem, 8vw, 2.85rem);
    aspect-ratio: 1;
    border: 1px solid rgba(246, 237, 212, 0.18);
    border-radius: 999px;
    color: rgba(244, 240, 232, 0.66);
    background: rgba(8, 10, 13, 0.22);
    box-shadow: 0 0.55rem 1.2rem rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(6px);
    font-size: 1.45rem;
    font-weight: 800;
    line-height: 1;
    opacity: 0.48;
    transform: translateY(-50%);
  }

  .page-click-zone-prev::before {
    content: "←";
    left: clamp(0.34rem, 1.8vw, 0.7rem);
  }

  .page-click-zone-next::before {
    content: "→";
    right: clamp(0.34rem, 1.8vw, 0.7rem);
  }

  .mobile-page-counter {
    position: absolute;
    top: clamp(0.5rem, 2vw, 0.74rem);
    left: 50%;
    z-index: 5;
    display: block;
    border: 1px solid rgba(246, 237, 212, 0.22);
    border-radius: 999px;
    padding: 0.36rem 0.68rem;
    color: rgba(244, 240, 232, 0.9);
    background: rgba(8, 10, 13, 0.46);
    box-shadow: 0 0.55rem 1.35rem rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(7px);
    font-size: clamp(0.68rem, 2.2vw, 0.8rem);
    font-weight: 850;
    line-height: 1;
    transform: translateX(-50%);
  }
}

@media (max-width: 680px) {
  :root {
    --page-width: min(calc(100vw - 0.7rem), calc((100svh - 6.7rem) * 0.6667));
  }

  .reader-heading {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.46rem;
  }

  .brand-main {
    flex-wrap: wrap;
    gap: 0.28rem 0.5rem;
  }

  .brand {
    gap: 0.46rem;
    min-width: 0;
  }

  .brand-mark {
    width: 1.42rem;
    border-radius: 7px;
  }

  .brand strong {
    font-size: 0.78rem;
  }

  .brand small {
    display: none;
  }

  .reader-title-block {
    max-width: 100%;
    gap: 0.26rem;
    font-size: clamp(0.66rem, 2.7vw, 0.8rem);
  }

  .reader-title-block::before {
    display: none;
  }

  .chapter-jump {
    width: 100%;
  }

  .chapter-select-button {
    width: 100%;
    gap: 0.34rem;
    padding: 0.45rem 0.48rem;
  }

  .chapter-select-icon {
    width: 1.05rem;
    border-radius: 5px;
    font-size: 0.76rem;
  }

  .codex-toggle {
    justify-self: end;
    width: 2.42rem;
    min-height: 2.42rem;
    aspect-ratio: 1;
    padding: 0;
  }

  .codex-toggle-icon {
    width: 1.18rem;
    height: 1.18rem;
  }

  .chapter-option {
    padding: 0.5rem 0.54rem;
    font-size: 0.76rem;
  }

  .reading-mode-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-reader-character] .reading-mode-dialog::after {
    top: 0.8rem;
    right: 2.8rem;
    width: 4.8rem;
    opacity: 0.14;
  }

  .reading-mode-card {
    width: auto;
    padding: 0;
    border-radius: 10px;
  }

  .reading-mode-kicker,
  .reading-mode-switch-copy {
    display: none;
  }

  .reading-mode-switch {
    grid-template-columns: 1fr;
    width: 2.84rem;
    height: 2.84rem;
    min-height: 2.84rem;
    padding: 0.42rem;
  }

  body[data-reader-character] .reading-mode-switch {
    padding: 0.42rem;
  }

  body[data-reader-character] .reading-mode-switch::after {
    right: -0.44rem;
    bottom: -0.46rem;
    width: 1.72rem;
    opacity: 0.92;
  }

  .reading-mode-visual {
    width: 1.86rem;
  }

  .reading-character-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .story-object-title-block h2 {
    font-size: 1.22rem;
  }

  .story-object-meta {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.18rem;
    padding: 0.62rem;
  }

  .story-object-description p,
  .story-object-details li {
    font-size: 0.84rem;
    line-height: 1.42;
  }

  .route-map-toggle {
    right: max(0.75rem, env(safe-area-inset-right));
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    gap: 0.52rem;
    height: 2.84rem;
    min-height: 2.84rem;
    max-width: calc(100vw - 1.5rem);
    padding: 0.42rem 0.58rem;
    background:
      linear-gradient(135deg, rgba(226, 180, 93, 0.18), rgba(226, 180, 93, 0.08) 42%, rgba(14, 17, 21, 0.96)),
      rgba(14, 17, 21, 0.96);
    box-shadow:
      0 0 0 1px rgba(14, 17, 21, 0.72),
      inset 0 1px 0 rgba(255, 255, 255, 0.08),
      0 0.9rem 2rem rgba(0, 0, 0, 0.46);
    backdrop-filter: blur(5px);
  }

  .route-map-icon {
    width: 1.86rem;
  }

  .route-map-toggle-label {
    display: none;
  }

  .route-map-modal {
    width: 100vw;
    max-width: 100vw;
    max-height: 96svh;
    border-radius: 0;
  }

  .route-map-dialog {
    min-height: 82svh;
    max-height: 96svh;
  }

  .route-map-dialog-header {
    flex-wrap: wrap;
    gap: 0.52rem;
    padding: 0.72rem;
  }

  .route-map-dialog-header h2 {
    flex: 1 1 calc(100% - 3rem);
  }

  .route-map-tabs {
    order: 3;
    flex: 1 1 auto;
    width: 100%;
  }

  .route-map-tab {
    flex: 1 1 0;
  }

  .route-map-recenter {
    order: 2;
  }

  .route-map-close {
    order: 1;
  }

  .route-map-dialog-body {
    padding: 1rem 0.7rem;
  }

  .city-map-dialog-body {
    padding: 0.72rem;
  }

  .city-map-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .city-map-panel {
    grid-template-rows: auto auto;
  }

  .city-map-canvas {
    min-height: 0;
  }

  .city-map-overlay-topleft {
    left: 0.62rem;
    top: 0.62rem;
    max-width: calc(100% - 5.8rem);
    gap: 0.32rem;
  }

  .city-map-title {
    padding: 0.5rem 0.62rem;
  }

  .city-map-title-label {
    font-size: 0.82rem;
  }

  .city-map-title-detail {
    display: none;
  }

  .city-map-legend {
    gap: 0.24rem 0.4rem;
    padding: 0.32rem 0.46rem;
  }

  .city-map-legend-item {
    font-size: 0.6rem;
  }

  .city-map-place-label {
    max-width: 7rem;
    font-size: 0.62rem;
  }

  .city-map-levels {
    right: 0.58rem;
    border-radius: 10px;
  }

  .city-map-level-button {
    min-width: 2.58rem;
    padding: 0.52rem 0.4rem;
    font-size: 0.7rem;
  }

  .city-map-place {
    max-width: 8.5rem;
  }

  .city-map-place-label {
    max-width: 7rem;
    font-size: 0.62rem;
  }

  .city-map-details {
    width: min(19rem, calc(100% - 3.7rem));
    padding: 0.72rem;
  }

  .reader-shell {
    min-height: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  #side-route-choices:not([hidden]) .route-follow-panel {
    animation: none;
  }

  .story-object-marker::before {
    animation: none;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}

/* ============================================================
   CODEX — mobile
   ============================================================ */
@media (max-width: 820px) {
  .codex-toggle-label {
    display: none;
  }

  .codex-toggle {
    place-items: center;
    grid-template-columns: auto;
    width: 2.6rem;
    aspect-ratio: 1;
    padding: 0.4rem;
  }

  .codex-modal {
    width: calc(100vw - 0.8rem);
    max-height: calc(100svh - 0.8rem);
    border-radius: 12px;
  }

  .codex-header {
    flex-wrap: wrap;
    gap: 0.6rem;
    padding: 0.8rem 0.85rem 0.7rem;
  }

  .codex-title-block {
    margin-right: 0;
  }

  .codex-tabs {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .codex-body {
    padding: 0.8rem;
  }

  .codex-card,
  .codex-body[data-tab="places"] .codex-card {
    flex-basis: 100%;
  }
}

@media (max-width: 680px) {
  .codex-modal {
    width: calc(100vw - 0.5rem);
    max-height: calc(100svh - 0.5rem);
    margin: 0.25rem auto auto;
    border-radius: 10px;
  }

  .codex-dialog {
    max-height: calc(100svh - 0.5rem);
  }

  .codex-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.58rem;
    padding: 0.72rem 0.7rem 0.62rem;
  }

  .codex-title-block {
    min-width: 0;
  }

  .codex-title-block .eyebrow {
    font-size: 0.58rem;
  }

  .codex-title-block h2 {
    font-size: 1.16rem;
  }

  .codex-close {
    width: 2.05rem;
    border-radius: 8px;
  }

  .codex-tabs {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    border-radius: 10px;
  }

  .codex-tab {
    min-width: 0;
    border-radius: 8px;
    padding: 0.48rem 0.2rem;
    font-size: 0.72rem;
  }

  .codex-body {
    grid-template-columns: 1fr;
    gap: 0.6rem;
    padding: 0.62rem;
  }

  .codex-card,
  .codex-body[data-tab="places"] .codex-card {
    grid-template-rows: none;
    grid-template-columns: minmax(5.3rem, 28%) minmax(0, 1fr);
    overflow: hidden;
    min-height: 7.5rem;
  }

  .codex-card-media,
  .codex-card-media-place {
    align-self: start;
    height: 7.5rem;
    min-height: 7.5rem;
    border-radius: 11px 0 0 11px;
  }

  .codex-badge {
    top: 0.42rem;
    left: 0.42rem;
    padding: 0.16rem 0.42rem;
    font-size: 0.55rem;
  }

  .codex-card-body {
    gap: 0.3rem;
    padding: 0.68rem 0.72rem 0.72rem;
  }

  .codex-card-name {
    font-size: 0.96rem;
  }

  .codex-card-character .codex-card-desc {
    display: none;
  }

  .codex-card-place .codex-card-desc {
    display: -webkit-box;
    overflow: hidden;
    font-size: 0.78rem;
    line-height: 1.34;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
  }

  .codex-card-foot {
    gap: 0.26rem;
    padding-top: 0.22rem;
  }

  .codex-card-meta {
    gap: 0.28rem;
    padding-top: 0.42rem;
  }

  .codex-meta-row {
    gap: 0.38rem;
    min-height: 1.25rem;
  }

  .codex-meta-label {
    font-size: 0.58rem;
  }

  .codex-meta-where {
    overflow: hidden;
    font-size: 0.7rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .codex-meta-avatar {
    width: 1.28rem;
  }

  .codex-card-link {
    margin-top: 0.18rem;
    font-size: 0.74rem;
  }

  .codex-body[data-tab="detail"] {
    padding: 0.72rem;
  }

  .codex-detail {
    gap: 0.78rem;
  }

  .codex-detail-head {
    gap: 0.72rem;
  }

  .codex-detail-portrait {
    width: 4.75rem;
    height: 4.75rem;
    border-radius: 10px;
  }

  .codex-detail-name {
    font-size: 1.05rem;
  }

  .codex-detail-desc {
    font-size: 0.82rem;
    line-height: 1.42;
  }

  .codex-detail-meta {
    width: 100%;
    margin-top: 0.1rem;
  }

  .codex-detail-prop {
    width: 3.35rem;
    margin-top: 0;
  }

  .codex-detail-section {
    font-size: 0.68rem;
  }

  .codex-appearance-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
  }
}

/* ============================================================
