/* ==========================================================================
   Carnet des Songes — feuille de style
   Thème clair par défaut, sombre complet en bascule. Les trois intensités
   portent leur couleur partout (teal / violet / corail), validées pour le
   daltonisme sur les deux fonds.
   ========================================================================== */

:root {
  /* Surfaces — neutres tirés vers le bleu du puits, jamais du gris pur */
  --ground: #eef1f9;
  --surface: #ffffff;
  --surface-2: #f5f7fd;
  --surface-3: #e7ebf7;
  --line: #dde2f0;
  --line-strong: #c3cade;

  /* Encres */
  --ink: #151a2e;
  --ink-2: #4c5473;
  --ink-muted: #7b839f;

  /* L'or des kamas : un ton lisible pour le texte, un plus vif pour les marques */
  --gold: #9a6c07;
  --gold-mark: #d79a1f;
  --gold-soft: #d79a1f;
  --gold-wash: #fdf4e0;

  /* Séries catégorielles — validées (CVD ΔE 17.7 / normal 24.0 sur blanc) */
  --reve: #00918d;
  --paradoxe: #6b4fd8;
  --cauchemar: #c2402c;

  /* États */
  --good: #0c7a34;
  --warning: #9a6c07;
  --critical: #c2402c;

  /* Chrome de graphique */
  --grid: #e6eaf6;
  --axis: #c3cade;
  --shadow-sm: 0 1px 2px rgba(21, 26, 46, 0.06), 0 2px 8px -4px rgba(21, 26, 46, 0.1);
  --shadow: 0 10px 34px -20px rgba(21, 26, 46, 0.5), 0 2px 8px -4px rgba(21, 26, 46, 0.12);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 7px;

  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-ui: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="clair"]) {
    --ground: #0b0e1c;
    --surface: #171b2e;
    --surface-2: #1e2339;
    --surface-3: #272d49;
    --line: #2b3250;
    --line-strong: #3c446a;

    --ink: #eef0f8;
    --ink-2: #a8b0cd;
    --ink-muted: #79819f;

    --gold: #e6b449;
    --gold-mark: #e0a93b;
    --gold-soft: #f2c86d;
    --gold-wash: #2a2313;

    --reve: #1aa3a6;
    --paradoxe: #8571e0;
    --cauchemar: #d25a49;

    --good: #3fae5c;
    --warning: #e0a93b;
    --critical: #d25a49;

    --grid: #272d49;
    --axis: #3c446a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 18px 44px -26px rgba(0, 0, 0, 0.95), 0 2px 10px -6px rgba(0, 0, 0, 0.6);

    color-scheme: dark;
  }
}

:root[data-theme="sombre"] {
  --ground: #0b0e1c;
  --surface: #171b2e;
  --surface-2: #1e2339;
  --surface-3: #272d49;
  --line: #2b3250;
  --line-strong: #3c446a;

  --ink: #eef0f8;
  --ink-2: #a8b0cd;
  --ink-muted: #79819f;

  --gold: #e6b449;
  --gold-mark: #e0a93b;
  --gold-soft: #f2c86d;
  --gold-wash: #2a2313;

  --reve: #1aa3a6;
  --paradoxe: #8571e0;
  --cauchemar: #d25a49;

  --good: #3fae5c;
  --warning: #e0a93b;
  --critical: #d25a49;

  --grid: #272d49;
  --axis: #3c446a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 18px 44px -26px rgba(0, 0, 0, 0.95), 0 2px 10px -6px rgba(0, 0, 0, 0.6);

  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Une règle d'auteur sur display écrase le display:none du navigateur. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Le ciel du puits : un halo discret en haut de page, jamais derrière le texte. */
.sky-glow {
  position: fixed;
  inset: 0 0 auto;
  height: 340px;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 100% at 50% -20%, color-mix(in srgb, var(--paradoxe) 16%, transparent), transparent 70%),
    radial-gradient(40% 80% at 85% -10%, color-mix(in srgb, var(--reve) 12%, transparent), transparent 70%);
}
#sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: 0.5; }
:root[data-theme="clair"] #sky { opacity: 0.2; }
@media (prefers-color-scheme: light) { :root:not([data-theme="sombre"]) #sky { opacity: 0.2; } }

.app { position: relative; z-index: 1; }

/* --------------------------------------------------------------- Topbar -- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--ground);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.wordmark { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; flex: none; }
.wordmark svg { width: 32px; height: 32px; flex: none; }
.wordmark-text b {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  line-height: 1.1;
  font-variation-settings: "SOFT" 24, "WONK" 1;
}
.wordmark-text span {
  display: block;
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.tabs { display: flex; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow-sm); }
.tab {
  appearance: none; border: 0; background: transparent; color: var(--ink-2);
  font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 7px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  transition: color 0.16s ease, background 0.16s ease;
}
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--surface); background: var(--ink); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.icon-btn {
  appearance: none; cursor: pointer;
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  transition: color 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.icon-btn svg { width: 17px; height: 17px; }

.account-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 6px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: border-color 0.16s ease;
}
.account-btn:hover { border-color: var(--line-strong); }
.avatar {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--paradoxe); color: #fff; font-size: 11px; font-weight: 800;
}
.avatar.is-local { background: var(--surface-3); color: var(--ink-muted); }
.account-state { font-size: 11px; color: var(--ink-muted); font-weight: 500; }

/* ----------------------------------------------------------------- Page -- */

.page { max-width: 1280px; margin: 0 auto; padding: 0 20px 40px; }
.view { display: none; }
.view.is-active { display: block; animation: view-in 0.3s cubic-bezier(0.2, 0.7, 0.3, 1); }
@keyframes view-in { from { transform: translateY(6px); } to { transform: none; } }

.view-head { padding: 22px 0 14px; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.view-head h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(24px, 3.4vw, 31px);
  letter-spacing: -0.015em;
  font-variation-settings: "SOFT" 24, "WONK" 1;
  text-wrap: balance;
}
.view-head p { margin: 4px 0 0; color: var(--ink-2); max-width: 64ch; font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 14px; }
.card-title {
  margin: 0 0 2px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-muted);
}
.card-sub { margin: 0 0 14px; color: var(--ink-muted); font-size: 12.5px; }

/* ======================================================= DÉCLARER ======== */

/* Tout doit tenir dans un écran : on compose en bandes, pas en colonnes hautes. */
.declare { display: grid; gap: 12px; }

.band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 13px 16px;
}
.band-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.band-head .card-title { margin: 0; }
.band-head .grow { flex: 1; }

/* Les dix intensités sur une seule ligne, groupées par famille. */
.intensity-bar { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.intensity-family { display: flex; flex-direction: column; gap: 5px; }
.intensity-family > span {
  font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-muted);
}
.intensity-family-row { display: flex; gap: 5px; }

.intens {
  appearance: none; cursor: pointer; font: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-width: 52px; padding: 7px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  transition: transform 0.12s ease, border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}
.intens:hover { transform: translateY(-1px); border-color: var(--line-strong); color: var(--ink); }
.intens b { font-size: 14px; font-weight: 800; letter-spacing: 0.01em; }
.intens span { font-size: 10px; font-variant-numeric: tabular-nums; color: var(--ink-muted); }
.intens[aria-pressed="true"] { color: #fff; border-color: transparent; }
.intens[aria-pressed="true"] span { color: rgba(255, 255, 255, 0.82); }
.intens[data-tier="reve"][aria-pressed="true"] { background: var(--reve); }
.intens[data-tier="paradoxe"][aria-pressed="true"] { background: var(--paradoxe); }
.intens[data-tier="cauchemar"][aria-pressed="true"] { background: var(--cauchemar); }

.intensity-facts { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; align-items: center; }

/* Les champs de run : une seule rangée qui s'enroule. */
.run-fields { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > .lbl { font-size: 11px; font-weight: 700; color: var(--ink-muted); letter-spacing: 0.02em; }
.field .help { font-size: 11px; color: var(--ink-muted); }
.field.w-sm input { width: 74px; }
.field.w-md input { width: 104px; }
.field.w-lg input, .field.w-lg select { width: 148px; }
.field.grow { flex: 1 1 160px; }

input[type="text"], input[type="number"], input[type="date"], input[type="search"],
input[type="email"], input[type="password"], select, textarea {
  font: inherit; font-size: 14px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  padding: 7px 10px;
  width: 100%;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s ease, background 0.15s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, [tabindex]:focus-visible, summary:focus-visible {
  outline: 2px solid var(--paradoxe);
  outline-offset: 2px;
}
textarea { resize: vertical; min-height: 54px; }
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; }
.seg button {
  appearance: none; border: 0; background: transparent; color: var(--ink-2);
  font: inherit; font-size: 13px; font-weight: 600; padding: 5px 12px; border-radius: 999px;
  cursor: pointer; white-space: nowrap; transition: background 0.15s ease, color 0.15s ease;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.seg button[aria-pressed="true"][data-v="win"] { color: var(--good); }
.seg button[aria-pressed="true"][data-v="loss"] { color: var(--critical); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.tier-reve { color: var(--reve); border-color: color-mix(in srgb, var(--reve) 40%, transparent); background: color-mix(in srgb, var(--reve) 10%, transparent); }
.chip.tier-paradoxe { color: var(--paradoxe); border-color: color-mix(in srgb, var(--paradoxe) 40%, transparent); background: color-mix(in srgb, var(--paradoxe) 10%, transparent); }
.chip.tier-cauchemar { color: var(--cauchemar); border-color: color-mix(in srgb, var(--cauchemar) 40%, transparent); background: color-mix(in srgb, var(--cauchemar) 10%, transparent); }
.chip.win { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); background: color-mix(in srgb, var(--good) 10%, transparent); }
.chip.loss { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, transparent); background: color-mix(in srgb, var(--critical) 10%, transparent); }
.chip.gold { color: var(--gold); border-color: color-mix(in srgb, var(--gold-mark) 45%, transparent); background: var(--gold-wash); }

/* Le butin, en grille dense : c'est le geste répété, il doit être court. */
.loot-zone { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 300px); gap: 12px; align-items: start; }
@media (max-width: 1000px) { .loot-zone { grid-template-columns: 1fr; } }

.loot-cat-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-muted); margin: 12px 0 7px;
}
.loot-cat-label:first-child { margin-top: 0; }

.loot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 7px; }

.loot {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 9px;
  row-gap: 4px;
  align-items: center;
  padding: 7px 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  transition: border-color 0.16s ease, background 0.16s ease;
}
.loot:hover { border-color: var(--line-strong); }
.loot.has-qty {
  background: var(--gold-wash);
  border-color: color-mix(in srgb, var(--gold-mark) 45%, var(--line));
}
.loot img { grid-row: 1 / span 2; width: 34px; height: 34px; display: block; }
.loot-name { grid-column: 2; min-width: 0; }
.loot-name b { display: block; font-size: 12.5px; font-weight: 600; line-height: 1.2; }
.loot-name span { display: block; font-size: 10.5px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.loot-row2 { grid-column: 2; display: flex; align-items: center; gap: 6px; }
.loot-stepper { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.loot-stepper button {
  appearance: none; width: 24px; height: 24px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; line-height: 1; display: grid; place-items: center;
  transition: background 0.14s ease, color 0.14s ease, transform 0.1s ease;
}
.loot-stepper button:hover { background: var(--ink); color: var(--surface); }
.loot-stepper button:active { transform: scale(0.92); }
.loot-stepper input { width: 46px; text-align: center; padding: 4px 2px; font-weight: 700; font-size: 13px; }
.loot-stepper input.is-zero { color: var(--ink-muted); font-weight: 500; }
.loot-stepper input.is-expr { color: var(--gold); font-weight: 800; }

.sum-btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; padding: 0; font-size: 13px; font-weight: 700;
  border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-muted);
  cursor: pointer; transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.sum-btn:hover { background: var(--paradoxe); border-color: transparent; color: #fff; }

/* Calculette multi-personnages, ancrée sous la pastille. */
.sumpad {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 60;
  width: 268px;
  max-width: calc(100vw - 32px);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: pad-in 0.16s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes pad-in { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: none; } }
.sumpad-head { display: flex; flex-direction: column; margin-bottom: 10px; }
.sumpad-head b { font-size: 13px; }
.sumpad-head span { font-size: 11px; color: var(--ink-muted); }
.sumpad-rows { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.sumpad-row { display: flex; align-items: center; gap: 7px; }
.sumpad-row span { font-size: 11px; font-weight: 700; color: var(--ink-muted); width: 16px; flex: none; }
.sumpad-row input { padding: 5px 8px; font-size: 13px; font-weight: 600; text-align: right; }
.sumpad-foot { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-top: 11px; }
.sumpad-foot .btn { white-space: nowrap; }
.sumpad-foot .btn-primary { flex: 1 0 100%; margin-top: 2px; }
.sumpad-total { font-size: 12px; color: var(--ink-muted); }
.sumpad-total b { color: var(--gold); font-size: 15px; font-variant-numeric: tabular-nums; }

details.loot-more { margin-top: 10px; border: 1px solid var(--line); border-radius: var(--radius-xs); background: var(--surface-2); }
details.loot-more > summary {
  cursor: pointer; list-style: none; padding: 9px 12px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2);
}
details.loot-more > summary::-webkit-details-marker { display: none; }
details.loot-more > summary::before {
  content: ""; width: 6px; height: 6px; flex: none;
  border-right: 2px solid var(--ink-muted); border-bottom: 2px solid var(--ink-muted);
  transform: rotate(-45deg); transition: transform 0.2s ease;
}
details.loot-more[open] > summary::before { transform: rotate(45deg); }
details.loot-more > summary em { font-style: normal; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--ink-muted); font-size: 11.5px; }
.loot-more-body { padding: 0 12px 12px; display: grid; gap: 9px; }
.loot-grid.scroller { max-height: 232px; overflow-y: auto; padding-right: 4px; }

/* La barre de conclusion : toujours sous la main. */
.conclude {
  position: sticky; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.conclude-total { display: flex; flex-direction: column; }
.conclude-total .label { font-size: 10px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--ink-muted); font-weight: 700; }
.conclude-total .value { font-weight: 800; font-size: 25px; line-height: 1.15; color: var(--gold); letter-spacing: -0.01em; }
.conclude-total .value.bump { animation: bump 0.36s cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }
.conclude-detail { color: var(--ink-muted); font-size: 12.5px; max-width: 46ch; }

.btn {
  appearance: none; font: inherit; font-weight: 700; font-size: 14px; cursor: pointer;
  padding: 9px 17px; border-radius: 9px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-muted); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--paradoxe); color: #fff; border-color: transparent; }
.btn-primary:hover { background: color-mix(in srgb, var(--paradoxe) 85%, #000); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { color: var(--ink); background: var(--surface-2); }
.btn-danger { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, var(--line)); background: transparent; }
.btn-danger:hover { background: color-mix(in srgb, var(--critical) 12%, transparent); color: var(--critical); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ======================================================= HISTORIQUE ====== */

.toolbar { display: flex; gap: 9px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.runs { display: flex; flex-direction: column; gap: 7px; }

.run {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 0.16s ease;
}
.run:hover { border-color: var(--line-strong); }
.run-head {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) auto auto;
  gap: 13px; align-items: center;
  padding: 10px 14px; width: 100%; text-align: left;
  background: none; border: 0; color: inherit; font: inherit; cursor: pointer;
}
.run-badge {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  font-weight: 800; font-size: 14px; color: #fff;
}
.run-badge[data-tier="reve"] { background: var(--reve); }
.run-badge[data-tier="paradoxe"] { background: var(--paradoxe); }
.run-badge[data-tier="cauchemar"] { background: var(--cauchemar); }
.run-main { min-width: 0; }
.run-main b { display: block; font-size: 14px; }
.run-meta { font-size: 11.5px; color: var(--ink-muted); display: flex; gap: 9px; flex-wrap: wrap; }
.run-value { text-align: right; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.run-value small { display: block; font-weight: 500; font-size: 10.5px; color: var(--ink-muted); }
.run-caret { color: var(--ink-muted); transition: transform 0.2s ease; }
.run.is-open .run-caret { transform: rotate(90deg); }
.run-body { padding: 0 14px 14px; border-top: 1px solid var(--line); display: grid; gap: 12px; }
.run-drops { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 12px; }
.drop-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 4px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 12px;
}
.drop-pill img { width: 20px; height: 20px; }
.drop-pill b { font-variant-numeric: tabular-nums; }
.drop-pill span { color: var(--ink-muted); }
.drop-pill.is-bound { border-style: dashed; }
.run-notes { font-size: 13px; color: var(--ink-2); white-space: pre-wrap; }
.run-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.run-shot img { max-width: 100%; border-radius: var(--radius-xs); border: 1px solid var(--line); display: block; }

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 34px 24px;
  text-align: center;
  color: var(--ink-muted);
  background: var(--surface);
}
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

/* ====================================================== STATISTIQUES ===== */

.tiles { display: grid; grid-template-columns: 1fr; gap: 11px; }
@media (min-width: 620px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.tile {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 15px; box-shadow: var(--shadow-sm);
}
.tile .label { font-size: 11.5px; color: var(--ink-2); font-weight: 600; }
.tile .value { font-size: 26px; font-weight: 800; line-height: 1.15; margin-top: 2px; letter-spacing: -0.015em; }
.tile .value.gold { color: var(--gold); }
.tile .sub { font-size: 11.5px; color: var(--ink-muted); margin-top: 2px; }
.tile.hero { background: linear-gradient(152deg, var(--gold-wash), var(--surface) 65%); border-color: color-mix(in srgb, var(--gold-mark) 34%, var(--line)); }
.tile.hero .value { font-size: clamp(29px, 4.6vw, 38px); color: var(--gold); }

.chart-card { margin-top: 14px; }
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.chart-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.chart-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-muted); max-width: 70ch; }
.legend { display: flex; gap: 13px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; }
.chart-wrap { position: relative; margin-top: 12px; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-scroll { overflow-x: auto; }

.tooltip {
  position: absolute; z-index: 20; pointer-events: none;
  background: var(--ink); color: var(--surface);
  border-radius: 9px; padding: 7px 10px; font-size: 12.5px;
  box-shadow: var(--shadow); white-space: nowrap;
  opacity: 0; transform: translate(-50%, -112%); transition: opacity 0.12s ease;
}
.tooltip.is-on { opacity: 1; }
.tooltip b { color: var(--gold-mark); font-variant-numeric: tabular-nums; }
.tooltip .t-label { color: color-mix(in srgb, var(--surface) 70%, transparent); display: block; font-size: 11px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.data th { font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-muted); font-weight: 700; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .with-icon { display: flex; align-items: center; gap: 9px; }
table.data .with-icon img { width: 24px; height: 24px; }
.with-icon .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.bar-cell { min-width: 120px; }
.bar-cell .track { display: flex; align-items: center; gap: 9px; }
.bar-cell .bar { height: 9px; border-radius: 0 4px 4px 0; background: var(--gold-mark); display: block; flex: none; }
.bar-cell .pct { font-size: 11.5px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

.bribe-count { display: flex; align-items: center; gap: 9px; }
.bribe-count img { width: 26px; height: 26px; }
.bribe-count b { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bribe-count span { font-size: 12px; color: var(--ink-muted); }
.goals { display: grid; gap: 13px; margin-top: 15px; }
.goal { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; align-items: center; }
.goal img { width: 32px; height: 32px; }
.goal-head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; margin-bottom: 5px; }
.goal-head b { font-size: 13.5px; font-weight: 600; }
.goal-head span { font-size: 11.5px; color: var(--ink-muted); }
.meter-track { height: 9px; border-radius: 99px; background: color-mix(in srgb, var(--gold-mark) 22%, var(--surface-3)); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 99px; background: var(--gold-mark); transition: width 0.5s cubic-bezier(0.2, 0.7, 0.3, 1); }
.goal-foot { font-size: 11.5px; color: var(--ink-2); margin-top: 5px; font-variant-numeric: tabular-nums; }

/* ========================================================= BESTIAIRE ===== */

.bestiary-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); gap: 14px; align-items: start; }
@media (max-width: 980px) { .bestiary-layout { grid-template-columns: 1fr; } }

.mob-list { display: grid; gap: 6px; max-height: 66vh; overflow-y: auto; padding-right: 4px; }
.mob {
  display: grid; grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 11px; align-items: center;
  padding: 7px 10px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-xs);
  font: inherit; color: inherit; cursor: pointer;
  transition: border-color 0.14s ease, background 0.14s ease;
}
.mob:hover { border-color: var(--line-strong); background: var(--surface-2); }
.mob[aria-current="true"] { border-color: var(--paradoxe); background: color-mix(in srgb, var(--paradoxe) 8%, var(--surface)); }
.mob img { width: 42px; height: 42px; object-fit: contain; }
.mob-name { min-width: 0; }
.mob-name b { display: block; font-size: 13.5px; }
.mob-name span { font-size: 11px; color: var(--ink-muted); }
.mob-flags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 200px; }
.flag {
  font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 5px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.flag.push { color: var(--cauchemar); border-color: color-mix(in srgb, var(--cauchemar) 40%, transparent); background: color-mix(in srgb, var(--cauchemar) 10%, transparent); }
.flag.boss { color: var(--gold); border-color: color-mix(in srgb, var(--gold-mark) 45%, transparent); background: var(--gold-wash); }
.flag.aberration { color: var(--paradoxe); border-color: color-mix(in srgb, var(--paradoxe) 40%, transparent); background: color-mix(in srgb, var(--paradoxe) 10%, transparent); }

.mob-sheet { position: sticky; top: 74px; }
.sheet-head { display: flex; gap: 13px; align-items: center; margin-bottom: 12px; }
.sheet-head img { width: 64px; height: 64px; object-fit: contain; }
.sheet-head h3 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 21px; font-variation-settings: "SOFT" 24, "WONK" 1; }
.sheet-head p { margin: 2px 0 0; font-size: 12px; color: var(--ink-muted); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 7px; margin-bottom: 13px; }
.stat-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-xs); padding: 7px 9px; }
.stat-box .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-muted); font-weight: 700; }
.stat-box .v { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.note-field { margin-bottom: 10px; }
.note-field label { display: block; font-size: 11px; font-weight: 700; color: var(--ink-muted); margin-bottom: 3px; letter-spacing: 0.04em; }
.note-field textarea { min-height: 48px; font-size: 13px; }
.aberration-box {
  border-left: 3px solid var(--paradoxe);
  background: color-mix(in srgb, var(--paradoxe) 7%, var(--surface-2));
  padding: 10px 12px; border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  font-size: 13px; color: var(--ink-2); margin-bottom: 12px;
}
.aberration-box b { color: var(--ink); display: block; margin-bottom: 3px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }

/* =========================================================== RÉGLAGES ==== */

.price-row {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) 132px 92px auto;
  gap: 11px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line);
}
.price-row:last-child { border-bottom: 0; }
.price-row img { width: 32px; height: 32px; }
.price-row .nm b { display: block; font-size: 13px; }
.price-row .nm span { font-size: 11px; color: var(--ink-muted); }
.price-row .ref { font-size: 12px; color: var(--ink-muted); text-align: right; font-variant-numeric: tabular-nums; }
.price-row .src { font-size: 10.5px; color: var(--ink-muted); }
.price-row .src.is-custom { color: var(--gold); font-weight: 700; }
@media (max-width: 720px) {
  .price-row { grid-template-columns: 32px minmax(0, 1fr) 104px; row-gap: 3px; }
  .price-row .ref, .price-row .src { grid-column: 2 / -1; text-align: left; }
}

.callout {
  display: flex; gap: 11px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--paradoxe) 8%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--paradoxe) 28%, transparent);
  font-size: 13px; color: var(--ink-2);
}
.callout b { color: var(--ink); }
.callout.warn { background: var(--gold-wash); border-color: color-mix(in srgb, var(--gold-mark) 40%, transparent); }

.invite-code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 14px; font-weight: 700; letter-spacing: 0.04em;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px;
}

/* ============================================================= MODALE ==== */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  /* Pas de backdrop-filter ici : un flou plein écran au-dessus du canvas
     animé fait recomposer toute la page à chaque image, ce qui met à genoux
     les grands écrans. Un voile opaque donne le même résultat pour rien. */
  background: color-mix(in srgb, var(--ink) 72%, transparent);
  display: grid; place-items: center; padding: 20px;
  animation: fade-in 0.16s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: min(430px, 100%);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; max-height: 88vh; overflow-y: auto;
}
.modal.wide { width: min(680px, 100%); }
.modal h2 {
  margin: 0 0 4px; font-family: var(--font-display); font-weight: 600; font-size: 22px;
  font-variation-settings: "SOFT" 24, "WONK" 1;
}
.modal p.sub { margin: 0 0 16px; color: var(--ink-muted); font-size: 13px; }
.modal .field { margin-bottom: 11px; }
.modal-actions { display: flex; gap: 9px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.modal-error {
  background: color-mix(in srgb, var(--critical) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--critical) 35%, transparent);
  color: var(--critical); border-radius: var(--radius-xs); padding: 8px 11px; font-size: 13px; margin-bottom: 11px;
}
.tab-switch { display: flex; gap: 4px; margin-bottom: 16px; }
.tab-switch button {
  flex: 1; appearance: none; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  padding: 7px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2);
}
.tab-switch button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: transparent; }

/* ============================================================== DIVERS === */

.row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--ink-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.toasts {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%); z-index: 95;
  display: flex; flex-direction: column; gap: 7px; align-items: center; pointer-events: none;
}
.toast {
  background: var(--ink); color: var(--surface);
  border-radius: 9px; padding: 9px 15px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow); animation: toast-in 0.26s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.toast.is-err { background: var(--critical); color: #fff; }
.toast.is-out { animation: toast-out 0.22s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-muted); flex: none; }
.sync-dot.ok { background: var(--good); }
.sync-dot.busy { background: var(--gold-mark); animation: pulse 1s ease-in-out infinite; }
.sync-dot.err { background: var(--critical); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

footer.credits {
  max-width: 1280px; margin: 0 auto; padding: 22px 20px 36px;
  color: var(--ink-muted); font-size: 12px; border-top: 1px solid var(--line);
}
footer.credits a { color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
