/* ── Atlas (home) ── */
body.home {
  overflow: hidden;
}
body.home main {
  padding-top: 0;
  height: 100vh;
}
#atlas-page {
  position: relative;
  overflow: hidden;
  background: transparent;
  height: 100vh;
  isolation: isolate;
}

/* ── Shared visualization primitives ── */
.viz-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  z-index: 1;
}
.viz-stage.is-hovering-node {
  cursor: pointer;
}
.viz-stage:active {
  cursor: grabbing;
}
.viz-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  transition: opacity var(--motion-surface) var(--motion-ease);
  opacity: 1;
}
.viz-stage[data-transitioning="true"] .viz-canvas,
.viz-stage[data-transitioning="true"] .viz-labels {
  opacity: 0;
}
.viz-labels {
  transition: opacity var(--motion-surface) var(--motion-ease);
}
.viz-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}
.viz-radial-center-action {
  appearance: none;
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 26;
  width: 22px;
  height: 22px;
  padding: 2px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid color-mix(in srgb, var(--ui-frame, #8d8d87) 72%, transparent);
  background: rgba(var(--surface-rgb), 0.58);
  color: color-mix(in srgb, var(--fg) 72%, var(--surface) 28%);
  cursor: pointer;
  font-family: inherit;
  font-size: 0;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 24px rgba(var(--shadow-rgb), 0.055);
  transition:
    background var(--motion-state) var(--motion-ease),
    border-color var(--motion-state) var(--motion-ease),
    color var(--motion-state) var(--motion-ease),
    opacity var(--motion-state) var(--motion-ease),
    transform var(--motion-state) var(--motion-ease);
}
.viz-radial-center-action:hover,
.viz-radial-center-action:focus-visible {
  background: var(--ui-grad);
  border-color: var(--ui-frame-strong, var(--fg-muted));
  color: var(--fg);
  outline: 0;
  transform: translate(-50%, -50%) rotate(90deg);
}
.viz-stage[data-transitioning="true"] .viz-radial-center-action {
  opacity: 0;
}
.viz-radial-reset-mark {
  width: 14px;
  height: 14px;
  color: currentColor;
  display: block;
}
.viz-error {
  position: absolute;
  left: 1.5rem;
  bottom: 1.5rem;
  font-size: 0.75rem;
  color: var(--fg-muted);
}

/* ── Shared label primitive ── */
.viz-label {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: auto;
  border: 0;
  background: transparent;
  color: var(--viz-text, #171714);
  font-family: inherit;
  font-size: 0.55rem;
  line-height: 1.15;
  letter-spacing: 0.015em;
  max-width: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  text-shadow:
    0 0 7px var(--viz-text-shadow, rgba(249, 248, 244, 0.96)),
    0 0 12px var(--viz-text-shadow, rgba(249, 248, 244, 0.96));
  transform-origin: 0 50%;
  transition:
    opacity var(--motion-state) var(--motion-ease),
    color var(--motion-state) var(--motion-ease);
  white-space: nowrap;
  backface-visibility: hidden;
  contain: layout style paint;
  text-rendering: geometricPrecision;
  will-change: transform, opacity;
}
.viz-label-reference {
  color: var(--viz-text, #171714);
}
.viz-label.muted {
  opacity: 0.16;
}
.viz-label.active {
  filter: brightness(0.85);
}

.viz-action-button {
  width: 19px;
  height: 19px;
  border: 1px solid var(--ui-frame, var(--border-soft));
  background: rgba(var(--surface-rgb), 0.72);
  color: var(--fg-muted);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  font-family: inherit;
  font-size: 0.66rem;
  line-height: 1;
  padding: 0;
}
.viz-action-button[hidden] {
  display: none;
}
.viz-action-button:hover,
.viz-action-button:focus-visible {
  background: var(--ui-grad);
  border-color: var(--ui-frame-strong);
  color: var(--fg);
  outline: 0;
}
.viz-action-help {
  border-color: var(--profile-primary);
  background: var(--profile-primary-soft);
  color: var(--fg);
  font-size: 0.86rem;
}
.viz-action-help:hover,
.viz-action-help:focus-visible {
  background: var(--profile-grad);
  border-color: var(--profile-primary);
  color: var(--fg);
}
.viz-action-icon-fit {
  width: 14px;
  height: 14px;
  border: 1px solid currentColor;
  display: block;
  position: relative;
}
.viz-action-icon-fit::before,
.viz-action-icon-fit::after {
  content: '';
  position: absolute;
  inset: 2px;
  border: 1px solid currentColor;
  border-color: currentColor transparent transparent currentColor;
}
.viz-action-icon-fit::after {
  transform: rotate(180deg);
}
.atlas-controls {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: block;
  pointer-events: none;
}
.atlas-controls > * {
  pointer-events: auto;
}
/* Barre basse : le bloc des visuels et le bloc des actions restent centrés ; le
   recadrage se pose à leur gauche, hors du flux, pour ne rien décaler. */
.atlas-dock {
  position: absolute;
  left: 50%;
  bottom: 1.15rem;
  transform: translateX(-50%);
  display: flex;
  align-items: stretch;
  gap: var(--ui-dock-gap);
  max-width: calc(100vw - 1.2rem);
}
.atlas-mode-dock,
.atlas-action-dock {
  display: flex;
  align-items: stretch;
  gap: var(--ui-frame-gap);
  border: 1px solid var(--ui-frame);
  background: rgba(var(--surface-rgb), 0.82);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 44px rgba(var(--shadow-rgb), 0.07);
  padding: var(--ui-frame-pad);
}
.atlas-mode-button {
  width: var(--ui-dock-control-size);
  height: var(--ui-dock-control-size);
  border: 1px solid var(--ui-sub-frame);
  background: var(--surface);
  color: var(--fg-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition:
    background var(--motion-state) var(--motion-ease),
    border-color var(--motion-state) var(--motion-ease),
    color var(--motion-state) var(--motion-ease);
}
.atlas-mode-button:hover,
.atlas-mode-button:focus-visible {
  background: var(--ui-sub-grad);
  border-color: var(--ui-sub-frame-strong);
  color: var(--fg);
  outline: 0;
}
.atlas-mode-button.is-current {
  background: var(--ui-sub-grad);
  border-color: var(--ui-sub-frame-strong);
  color: var(--fg);
}
/* Les pictogrammes de la barre basse se lisent a distance : ils occupent
   presque toute la case du bouton, sans changer la taille des boutons. */
.atlas-mode-icon {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 0.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.atlas-reset-button {
  position: absolute;
  right: calc(100% + var(--ui-dock-gap));
  top: 0;
  bottom: 0;
  /* Le recadrage reste carre avec la barre : hauteur de case, plus le padding
     du dock et ses deux cadres. */
  width: calc(var(--ui-dock-control-size) + (var(--ui-frame-pad) * 2) + 2px);
  height: auto;
  border-color: var(--ui-frame);
  background: rgba(var(--surface-rgb), 0.82);
  backdrop-filter: blur(18px);
}
.atlas-action-dock .viz-action-button {
  width: var(--ui-dock-control-size);
  height: var(--ui-dock-control-size);
}
.atlas-play-button {
  border-color: var(--ui-sub-frame);
  background: var(--surface);
}
.atlas-play-button.is-playing {
  background: var(--ui-grad);
}
.atlas-play-icon {
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 8px solid currentColor;
  margin-left: 1px;
}
#atlas-page.is-replaying .viz-stage,
#atlas-page.is-replaying .atlas-panel,
#atlas-page.is-replaying .atlas-rameau-help {
  pointer-events: none;
}
.atlas-controls.is-replaying > * {
  pointer-events: none;
}
body.atlas-replay-lock #nav,
body.atlas-replay-lock .atlas-controls > * {
  filter: grayscale(1);
  opacity: 0.36;
}
body.atlas-replay-lock #nav *,
body.atlas-replay-lock .atlas-controls * {
  pointer-events: none !important;
}
body.atlas-area #nav,
.atlas-controls > * {
  transition:
    filter var(--motion-state) var(--motion-ease),
    opacity var(--motion-state) var(--motion-ease);
}
.atlas-play-button:disabled {
  color: var(--fg);
  opacity: 1;
}

/* Easter egg : respiration de l'atlas (taper 5×a). */
.atlas-flash::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  background: radial-gradient(
    circle at center,
    color-mix(in srgb, var(--accent, #c2632a) 28%, transparent) 0%,
    color-mix(in srgb, var(--accent, #c2632a) 10%, transparent) 38%,
    transparent 70%
  );
  animation: atlas-pulse-flash var(--motion-long) var(--motion-ease) forwards;
}
@keyframes atlas-pulse-flash {
  0%   { opacity: 0; transform: scale(0.5); }
  35%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.5); }
}


.viz-stage[data-mode="timeline"] {
  cursor: ns-resize;
}
.viz-stage[data-mode="timeline"].is-hovering-node {
  cursor: pointer;
}
.viz-timeline-canvas {
  touch-action: none;
  overscroll-behavior: contain;
}
.viz-timeline-canvas:focus-visible {
  outline: 1px solid var(--ui-frame-strong, var(--fg-muted));
  outline-offset: -5px;
}

.atlas-rameau-help {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: var(--nav-clearance) 1rem 1rem;
  pointer-events: auto;
}
.atlas-rameau-help-global {
  position: fixed;
  padding: 1rem;
  z-index: 60;
}
.atlas-rameau-help[hidden] {
  display: none;
}
.atlas-rameau-help-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(var(--bg-rgb), 0.54);
  backdrop-filter: blur(4px);
}
.atlas-rameau-help-shell {
  position: relative;
  z-index: 1;
  width: min(var(--content-rail-width), calc(100vw - 2rem));
}
.atlas-rameau-help-card {
  width: 100%;
  max-height: min(84vh, 860px);
  overflow: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
  /* Carte de modale : bloc principal en couleur primaire, sous-blocs en
     secondaire, exemples au troisieme niveau gris. */
  border: 1px solid var(--ui-frame);
  background: rgba(var(--surface-rgb), 0.94);
  box-shadow: 0 22px 70px rgba(var(--shadow-rgb), 0.16);
  display: grid;
  gap: var(--ui-frame-gap);
  padding: var(--ui-frame-pad);
}
.atlas-rameau-help-card::-webkit-scrollbar {
  display: none;
}
.atlas-rameau-help-close {
  position: absolute;
  right: calc(100% + 7px);
  top: 0;
  width: 20px;
  height: 20px;
  border: 1px solid var(--ui-frame);
  background: rgba(var(--surface-rgb), 0.76);
  color: var(--fg);
  cursor: pointer;
  font: inherit;
  line-height: 1;
  padding: 0;
}
.atlas-rameau-help-close:hover {
  background: var(--ui-grad);
}
.atlas-rameau-help-kicker {
  border: 1px solid var(--ui-frame);
  background:
    linear-gradient(90deg, var(--ui-frame-soft) 0%, rgba(var(--surface-rgb), 0.74) 100%);
  color: var(--fg);
  display: block;
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  line-height: 1.1;
  padding: var(--ui-text-pad);
  text-transform: uppercase;
}
.atlas-rameau-copy,
.atlas-rameau-example,
.atlas-rameau-step {
  border: 1px solid color-mix(in srgb, var(--ui-sub-frame) 52%, var(--border-soft));
  background:
    linear-gradient(135deg, rgba(var(--surface-rgb), 0.78) 0%, color-mix(in srgb, var(--ui-sub-frame-soft) 28%, rgba(var(--surface-rgb), 0.72)) 100%);
  display: grid;
  gap: 6px;
  padding: 6px;
}
.atlas-rameau-copy h2 {
  font-size: 0.84rem;
  line-height: 1.12;
  margin: 0;
  padding: 0;
}
.atlas-rameau-copy p,
.atlas-rameau-example p,
.atlas-rameau-step p {
  color: var(--fg-soft);
  font-size: 0.72rem;
  line-height: 1.34;
  margin: 0;
}
.atlas-rameau-walkthrough {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--ui-frame-gap);
}
.atlas-rameau-column-title {
  border: 1px solid var(--ui-sub-frame);
  background:
    linear-gradient(90deg, var(--ui-sub-frame-soft) 0%, rgba(var(--surface-rgb), 0.74) 100%);
  color: var(--fg);
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  line-height: 1.1;
  margin: 0;
  padding: var(--ui-text-pad);
  text-transform: uppercase;
}
.atlas-rameau-column-title-example {
  border-color: var(--border);
  background: var(--neutral-grad);
}
.atlas-rameau-step {
  align-content: start;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 5px;
  row-gap: 3px;
  min-width: 0;
  padding: 4px 5px;
}
.atlas-rameau-step-example {
  border-color: var(--border);
  background: var(--neutral-grad);
}
.atlas-rameau-step-number {
  align-self: baseline;
  color: var(--fg);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.18;
}
.atlas-rameau-step h4 {
  color: var(--fg);
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.18;
  margin: 0;
}
.atlas-rameau-step p {
  grid-column: 1 / -1;
}
.atlas-rameau-step code {
  color: var(--fg);
  font: inherit;
}
.atlas-rameau-example-lines {
  display: grid;
  gap: 3px;
}
.atlas-rameau-example-lines strong {
  color: var(--fg);
}
.atlas-rameau-links {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--ui-frame-gap);
}
.atlas-rameau-links a {
  border: 1px solid var(--ui-sub-frame);
  background: rgba(var(--surface-rgb), 0.72);
  color: var(--fg);
  font-size: 0.64rem;
  letter-spacing: 0.04em;
  line-height: 1.12;
  padding: 4px 5px;
  text-align: center;
  text-transform: uppercase;
}
.atlas-rameau-links a:hover {
  background: var(--ui-sub-grad);
}

/* ── Selection panel (bottom-right, only visible on selection) ── */
/* Hôte transparent : la sélection réutilise telle quelle la carte de la
   Librairie, à la largeur exacte d'une case de sa grille (rail central moins
   les trois écarts de 6px de #library-grid). */
.viz-panel,
.atlas-panel {
  position: absolute;
  right: var(--chrome-inset);
  bottom: 1.25rem;
  z-index: 30;
  width: min(calc((var(--content-rail-width) - 18px) / 4), calc(100vw - 2.5rem));
  transition:
    opacity var(--motion-state) var(--motion-ease),
    transform var(--motion-state) var(--motion-ease);
  opacity: 1;
  transform: translateY(0);
  color: var(--fg);
}
.viz-panel.is-idle,
.viz-panel:not(.has-selection) {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  visibility: hidden;
}
.atlas-panel.is-access-required {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
  width: var(--side-rail-width);
}
.atlas-access-required {
  backdrop-filter: blur(14px);
}
.viz-panel:not(.is-access-required) p {
  border: 1px solid color-mix(in srgb, var(--viz-panel-accent, var(--border-soft)) 42%, var(--border-soft));
  background: rgba(var(--surface-rgb), 0.64);
  font-size: 0.7rem;
  line-height: 1.18;
  color: var(--fg-soft);
  margin: 0;
  padding: var(--ui-text-pad);
}

.viz-labels .viz-label {
  position: absolute;
}

@media (max-width: 620px) {
  .atlas-dock {
    bottom: 0.6rem;
  }
  .viz-panel,
  .atlas-panel {
    right: 0.6rem;
    bottom: calc(0.6rem + 39px);
  }
  .atlas-rameau-help {
    padding: calc(var(--nav-clearance) + 0.5rem) 0.6rem 0.6rem;
  }
  .atlas-rameau-help-shell {
    width: 100%;
  }
  .atlas-rameau-help-close {
    position: static;
    margin-bottom: 7px;
  }
  .atlas-rameau-links {
    grid-template-columns: minmax(0, 1fr);
  }
  .atlas-rameau-walkthrough {
    grid-template-columns: minmax(0, 1fr);
  }
  .atlas-rameau-column-title {
    display: none;
  }
}
