/* Mode sombre NeoVia — tokens DA v0.4.2 (mode sombre validé par Ali le 20/11/2026 à 20 h 16).
   Chargé APRÈS tokens.css, styles.css, ui.css et space-base.css. Les feuilles des espaces (Twitch, Discord, admin) arrivent
   plus tard : chaque règle sombre est donc préfixée par :root[data-theme='sombre'] pour l'emporter sans !important.
   Aucun hex en dur ici : seulement les rôles --ui-*, --btn-*, --card-*, --theme-toggle-*, --product-* et --stream-*.
   Les overlays OBS (regles/overlay.html, compteur.html, classement.html) ne chargent ni ce fichier ni theme-init.js. */

/* ---------- Interrupteur de thème (rond 40 px, zone 48 px, icône 20 px, contour 2 px) ---------- */
.theme-toggle {
  position: relative; flex: none; display: inline-grid; place-items: center;
  width: var(--theme-toggle-size); height: var(--theme-toggle-size); padding: 0; margin: 0;
  border: var(--theme-toggle-border-width) solid currentColor; border-radius: var(--theme-toggle-radius);
  background: var(--theme-toggle-bg); color: var(--theme-toggle-fg); cursor: pointer;
  transition: background-color var(--theme-toggle-duration) var(--ui-ease-standard), color var(--theme-toggle-duration) var(--ui-ease-standard);
}
/* Les en-têtes imposent 44 px de haut à leurs boutons : l'interrupteur garde 40 px visibles, sa zone de clic de 48 px est assurée par ::before. */
:root .theme-toggle { min-width: 0; min-height: 0; }
/* Sans JavaScript, le site reste clair et l'interrupteur ne servirait à rien : il est masqué. */
:root:not([data-theme]) .theme-toggle { display: none; }
/* Zone cliquable de 48 px autour du visuel de 40 px (l'inset part de l'intérieur du contour, d'où le retrait de son épaisseur). */
.theme-toggle::before { content: ""; position: absolute; inset: calc((var(--theme-toggle-size) - var(--theme-toggle-hit)) / 2 - var(--theme-toggle-border-width)); border-radius: var(--theme-toggle-radius); }
.theme-toggle:hover { background: var(--theme-toggle-bg-hover); color: var(--theme-toggle-fg-hover); }
.theme-toggle:active { background: var(--theme-toggle-bg-pressed); color: var(--theme-toggle-fg-pressed); }
/* Focus : liseré de fond 3 px puis anneau 3 px (obligatoire). Remplace l'outline commun pour ce seul bouton. */
.theme-toggle:focus-visible { outline: none; box-shadow: var(--theme-toggle-focus); }
.theme-icone { grid-area: 1 / 1; width: var(--theme-toggle-icon-size); height: var(--theme-toggle-icon-size); transition: opacity var(--theme-toggle-icon-duration) var(--ui-ease-standard), transform var(--theme-toggle-icon-duration) var(--ui-ease-standard); }
/* L'icône montre la destination : lune en clair, soleil en sombre. Une seule visible. */
.theme-icone-soleil { opacity: 0; transform: rotate(-45deg); visibility: hidden; }
:root[data-theme='sombre'] .theme-icone-lune { opacity: 0; transform: rotate(45deg); visibility: hidden; }
:root[data-theme='sombre'] .theme-icone-soleil { opacity: 1; transform: none; visibility: visible; }
/* Infobulle au survol et au focus, même texte que l'aria-label (texte --ui-bg sur fond --ui-text). */
.theme-toggle::after {
  content: attr(data-infobulle); position: absolute; top: calc(100% + 10px); right: 0; z-index: 30;
  padding: 6px 10px; border-radius: var(--ui-radius-xs); background: var(--ui-text); color: var(--ui-bg);
  font: 600 .75rem/1.3 Sora, system-ui, sans-serif; letter-spacing: 0; white-space: nowrap; pointer-events: none;
  opacity: 0; visibility: hidden; transition: opacity var(--theme-toggle-duration) var(--ui-ease-standard);
}
.theme-toggle:is(:hover, :focus-visible)::after { opacity: 1; visibility: visible; }
@media (prefers-reduced-motion: reduce) {
  .theme-icone, :root[data-theme='sombre'] .theme-icone-lune, .theme-icone-soleil { transform: none; transition: opacity var(--ui-duration-micro) linear; }
}
/* Bascule instantanée des couleurs : transitions coupées pendant une image, sauf l'icône. */
.theme-bascule *:not(.theme-icone), .theme-bascule *::before, .theme-bascule *::after { transition: none !important; }

/* ---------- Logos : version claire / version sombre de la DA ---------- */
/* traverse-sombre.svg peint sa coupure en Encre : il n'est posé que sur --ui-bg (en-têtes), jamais sur une carte. */
:root:not([data-theme='sombre']) .logo-sombre, :root[data-theme='sombre'] .logo-clair { display: none; }
/* Le classeur TCG a une illustration par thème. */
:root:not([data-theme='sombre']) .illustration-sombre, :root[data-theme='sombre'] .illustration-claire { display: none; }

/* ---------- Réconciliation tokens DA / ui.css (Codex) ----------
   Six noms communs : --ui-surface, --ui-success(-bg), --ui-warning(-bg), --ui-focus.
   Clair : ui.css est chargé après tokens.css, ses valeurs restent (rendu clair inchangé, vérifié par captures).
   Sombre : ce bloc remet les valeurs sombres de la DA et branche les autres noms de Codex sur les rôles DA. */
:root[data-theme='sombre'] {
  color-scheme: dark;
  --ui-surface: var(--nv-encre-surface);
  --ui-success: var(--nv-succes-sombre);
  --ui-success-bg: var(--nv-encre-surface);
  --ui-warning: var(--nv-alerte-sombre);
  --ui-warning-bg: var(--nv-encre-surface);
  --ui-focus: var(--nv-papier);
  --ui-focus-halo: var(--ui-bg);
  --ui-ink: var(--ui-text);
  --ui-muted: var(--ui-text-muted);
  --ui-primary: var(--ui-action);
  --ui-on-primary: var(--ui-on-action);
  --ui-line: var(--ui-border);
  --ui-control: var(--ui-border-field);
  --ui-error: var(--ui-danger);
  --ui-error-bg: var(--ui-danger-bg);
  --ui-info: var(--ui-link);
  --ui-info-bg: var(--ui-surface);
  /* Variables de l'accueil (styles.css) */
  --ink: var(--ui-text);
  --muted: var(--ui-text-muted);
  --paper: var(--ui-bg);
  --panel: var(--ui-surface);
  --lavender: var(--ui-action-soft);
  --accent: var(--ui-link);
  --action: var(--btn-bg);
  --action-hover: var(--btn-bg-hover);
  --control: var(--ui-border-field);
  --white: var(--card-bg);
}

/* ---------- Accueil et espace créateur (styles.css) en sombre ---------- */
/* Élévation : surface plus claire (--card-bg) + liseré (--card-shadow), plutôt que des ombres. */
:root[data-theme='sombre'] body { background: var(--ui-bg); color: var(--ui-text); }
:root[data-theme='sombre'] .button { color: var(--btn-fg); }
:root[data-theme='sombre'] .button:hover { background: var(--btn-bg-hover); }
:root[data-theme='sombre'] .button:active:not(.button-outline) { background: var(--btn-bg-pressed); }
:root[data-theme='sombre'] .button-outline { background: var(--btn-secondary-bg); color: var(--btn-secondary-fg); border: var(--btn-secondary-border); }
:root[data-theme='sombre'] .button-outline:hover { background: var(--btn-secondary-bg); color: var(--ui-action-hover); border-color: var(--ui-action-hover); }
:root[data-theme='sombre'] .button:disabled { background: var(--ui-disabled-bg); color: var(--ui-disabled-text); }
:root[data-theme='sombre'] .header nav .header-account { background: var(--ui-surface); color: var(--ui-text); }
:root[data-theme='sombre'] .header nav button.header-account { background: var(--btn-bg); color: var(--btn-fg); }
:root[data-theme='sombre'] .header nav button.header-account:hover { background: var(--btn-bg-hover); }
:root[data-theme='sombre'] .admin-badge { border-color: var(--ui-border-field); background: var(--ui-action-soft); color: var(--ui-text); }
:root[data-theme='sombre'] :is(.account-admin-link, .account-access) { border-color: var(--ui-border-field); background: var(--card-bg); }
:root[data-theme='sombre'] .account-admin-link:hover { background: var(--ui-action-soft); }
:root[data-theme='sombre'] .hero { background: var(--ui-surface); }
:root[data-theme='sombre'] .hero-launcher { background: var(--card-bg); color: var(--ui-text); border-color: transparent; box-shadow: var(--card-shadow-levee); }
:root[data-theme='sombre'] .launcher-row { border-top-color: var(--ui-border); }
:root[data-theme='sombre'] :is(.launcher-heading small, .launcher-label small, .hero-launcher > p) { color: var(--ui-text-muted); }
:root[data-theme='sombre'] .launcher-row { color: var(--launcher-accent); } /* en sombre, libellé et flèche à la couleur produit (menthe, or, lavande) */
:root[data-theme='sombre'] .tool, :root[data-theme='sombre'] .tool[data-tool] { --tile: var(--card-bg); --badge: var(--ui-surface); background: var(--tile); color: var(--ui-text); box-shadow: var(--card-shadow); }
:root[data-theme='sombre'] .tool-icon { color: var(--ui-text); }
:root[data-theme='sombre'] .tool .tool-stage, :root[data-theme='sombre'] .tool[data-tool] .tool-stage { border-color: var(--ui-border-field); color: var(--ui-text-muted); }
:root[data-theme='sombre'] .tool[data-tool] :focus-visible { outline-color: var(--ui-focus); }
:root[data-theme='sombre'] :is(.journey-steps, .journey-steps li + li, .account-progress, .account-progress-step + .account-progress-step, .account-session, .activation, .agency-inner, .footer) { border-color: var(--ui-border); }
:root[data-theme='sombre'] .account-welcome { background: var(--card-bg); border-color: transparent; box-shadow: var(--card-shadow); }
:root[data-theme='sombre'] .account-progress-number { background: var(--ui-action-soft); color: var(--ui-text); }
:root[data-theme='sombre'] .activation { background: var(--card-bg); box-shadow: var(--card-shadow); }
:root[data-theme='sombre'] .activation-badge { color: var(--ui-success); background: var(--ui-success-bg); }
/* Fenêtre de connexion : déjà sombre en clair ; en sombre elle devient une surface levée. */
:root[data-theme='sombre'] .auth-dialog {
  --ink: var(--ui-surface); --paper: var(--ui-text); --white: var(--ui-text); --panel: var(--ui-text-muted); --lavender: var(--ui-action);
  --auth-surface: var(--card-bg); --auth-hover: var(--ui-action-soft); --auth-border: var(--ui-border-field); --auth-muted: var(--ui-text-muted);
  border-color: var(--ui-border); box-shadow: var(--card-shadow-levee);
}
:root[data-theme='sombre'] .auth-dialog .auth-method-google { color: var(--ui-bg); }
/* Chargement des espaces (space-base.css) */
:root[data-theme='sombre'] .ui-skel-side { background: var(--card-bg); border-color: var(--ui-border); }
:root[data-theme='sombre'] .ui-skeleton i { background: var(--ui-surface); }

/* ---------- Discord (data-produit="discord") ---------- */
:root[data-theme='sombre'] .discord-dashboard {
  --discord-bg: var(--ui-bg); --discord-surface: var(--card-bg); --discord-raised: var(--ui-surface);
  --discord-text: var(--ui-text); --discord-muted: var(--ui-text-muted);
  --discord-accent: var(--product-action); --discord-mint: var(--product-accent); --discord-on-mint: var(--product-on-accent);
  --discord-wash: var(--product-role-choisi-bg); --discord-dark: var(--ui-text);
  --discord-line: var(--ui-border); --discord-control-line: var(--ui-border-field);
  --ui-primary: var(--product-action); --ui-focus: var(--ui-text);
}
/* O traversé sombre : seulement sur --ui-bg (sa coupure est peinte en Encre). */
:root[data-theme='sombre'] .discord-topbar { background: var(--ui-bg); }
.discord-topbar-fin { display: flex; align-items: center; gap: 12px; justify-self: end; grid-column: -2 / -1; grid-row: 1; }

/* ---------- Twitch : bot et règles (data-produit="stream") ---------- */
:root[data-theme='sombre'] .rg {
  --acc: var(--product-accent); --txt: var(--stream-text); --mut: var(--stream-muted); --w: var(--stream-surface); --pg: var(--stream-bg);
  --tint: var(--stream-border); --line: var(--stream-border); --danger: var(--ui-danger); --lav-300: var(--stream-border-field);
}
:root[data-theme='sombre'] body:has(:is(#regles, #bot):not([hidden])) { background: var(--ui-bg); }
/* En-tête Twitch sur --ui-bg : seul fond admis pour O traversé sombre. */
:root[data-theme='sombre'] .rg .rg-top { background: var(--ui-bg); }
:root[data-theme='sombre'] .rg :is(.btn.pri, .btn.main) { background: var(--stream-action); color: var(--stream-on-action); }
:root[data-theme='sombre'] .rg .btn.pri:hover:not(:disabled) { background: var(--stream-action-hover); }
:root[data-theme='sombre'] .rg .btn.sec { background: transparent; color: var(--stream-link); box-shadow: inset 0 0 0 2px var(--stream-link); }
:root[data-theme='sombre'] .rg :is(.seg button[aria-pressed="true"], .fonts button[aria-pressed="true"], .pgrid button[aria-checked="true"], .li .st.on, .tab.cur, .fiche-tab, .prev-x, .back .back-ic, .pa-btn .pa-ic, .lw[data-fiche-open="false"] .fiche-tab .fiche-tab-ic) { background: var(--stream-action); color: var(--stream-on-action); }
:root[data-theme='sombre'] .rg .ov-steps li::before { background: var(--stream-action); color: var(--stream-on-action); }
:root[data-theme='sombre'] .rg .ib[data-tip]:is(:hover, :focus-visible)::after { background: var(--stream-text); color: var(--stream-bg); }
:root[data-theme='sombre'] .rg .tg.on .tr i { background: var(--stream-surface); }
:root[data-theme='sombre'] .rg .tnav a { color: var(--stream-muted); }
:root[data-theme='sombre'] .rg .tnav a:is(:hover, .on) { color: var(--stream-text); }
:root[data-theme='sombre'] .rg .brand { color: var(--stream-text); }

/* Étiquettes de mode du bot : texte Charbon profond seulement sur Lavande ; sur les autres fonds, texte Twitch. */
:root[data-theme='sombre'] #bot.rg :is(.mode-tag.m-test, .mode-tag.m-ecoute) { color: var(--stream-text); box-shadow: inset 0 0 0 1px var(--stream-border-field); }

/* ---------- Administration ---------- */
:root[data-theme='sombre'] .admin {
  --ad-bg: var(--ui-bg); --ad-panel: var(--card-bg); --ad-ink: var(--ui-text); --ad-muted: var(--ui-text-muted);
  --ad-border: var(--ui-border); --ad-accent: var(--ui-action); --ad-error: var(--ui-danger); --ad-soft: var(--ui-surface);
}
:root[data-theme='sombre'] .ad-topbar { background: var(--ui-bg); }
:root[data-theme='sombre'] .ad-button { color: var(--btn-fg); }
:root[data-theme='sombre'] .ad-button:hover { background: var(--btn-bg-hover); }
:root[data-theme='sombre'] .ad-button-secondary { background: transparent; color: var(--btn-secondary-fg); }
:root[data-theme='sombre'] .ad-button-secondary:hover { color: var(--ui-action-hover); border-color: var(--ui-action-hover); background: transparent; }
.ad-topbar .theme-toggle { margin-inline-start: auto; }
/* Ligne « Session administrateur vérifiée » : vert codé en dur dans admin.css (#356050, 1,6:1 mesuré sur #3C3844 en sombre) ; rôle succès de la DA. */
:root[data-theme='sombre'] .ad-security-line { color: var(--ui-success); }
/* Confirmation destructive (ui.js) : ui.css écrit le texte en blanc ; sur l'erreur sombre de la DA, texte Encre. */
:root[data-theme='sombre'] .ui-button-danger { color: var(--ui-on-action); }

/* ---------- TCG ----------
   Fichiers tcg (tcg.css, views.js) intouchés : ils appartiennent à l'assistant site web. L'atelier garde son rendu clair
   dans les deux thèmes, en attendant le lot TCG sombre (--tcg-rarete-*-cadre-sombre, intérieur --tcg-rarete-voile-sombre,
   liseré 2 px --tcg-rarete-secrete-lisere-sombre obligatoire sur la Secrète). */
:root[data-theme='sombre'] #tcg { color-scheme: light; }
:root[data-theme='sombre']:has(#tcg:not([hidden])) { color-scheme: light; }

/* Pseudos Twitch (bot) : couleur du nom par variables (--pseudo en clair, --pseudo-sombre en sombre, posées par bot/vues.js).
   Le bleu violet d'exemple devient #BF94FF en sombre, comme Twitch en sombre (Ali, 20/11 20 h 46) ; le clair ne change pas. */
#bot.rg .pseudo-twitch { color: var(--pseudo); }
:root[data-theme='sombre'] #bot.rg .pseudo-twitch { color: var(--pseudo-sombre, var(--pseudo)); }

/* Twitch (bot et règles), mobile : l'interrupteur tient sur la ligne du logo sans faire passer le statut à la ligne. */
@media (max-width: 640px) {
  :root .rg .rg-top { column-gap: 8px; padding-inline: 12px; }
  :root .rg .rg-top .who { gap: 8px; }
}
