.balance-dashboard { max-width: 1800px; margin: auto; padding: 24px; }
.balance-dashboard > p, .balance-dashboard details { line-height: 1.6; }
.balance-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin: 20px 0; }
.balance-toolbar label { display: flex; flex-direction: column; gap: 8px; }
.balance-toolbar .balance-check { flex-direction: row; align-items: center; }
.balance-check input { width: auto; }
.balance-muted, .balance-table small { color: var(--muted); }
.balance-scroll { overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.balance-table { width: 100%; border-collapse: collapse; background: var(--panel); }
.balance-table caption { padding: 12px; text-align: left; color: var(--muted); }
.balance-table th, .balance-table td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.balance-table th { background: var(--panel-3); }
.balance-table th button { background: transparent; color: var(--text); border: 0; cursor: pointer; font-weight: 700; text-align: left; }
.balance-table td:first-child { min-width: 240px; max-width: 360px; overflow-wrap: anywhere; }
.balance-table td:last-child { min-width: 210px; }
.balance-table small { display: block; margin-top: 6px; font-size: 11px; }
.balance-table .balance-number { text-align: right; font-variant-numeric: tabular-nums; }
.balance-table tbody tr:hover { background: var(--panel-2); }
.balance-alert { color: var(--yellow); font-size: 12px; margin: 0 0 8px; }
.balance-table button:focus-visible { outline: 2px solid var(--yellow); outline-offset: 3px; }

:root {
    color-scheme: dark;
    --bg: #0c1018;
    --panel: #121824;
    --panel-2: #171f2e;
    --panel-3: #202a3b;
    --border: #293449;
    --border-bright: #3b4962;
    --text: #edf2f7;
    --muted: #8e9ab0;
    --yellow: #ffd166;
    --orange: #ff9f43;
    --red: #ef476f;
    --green: #62d6a7;
    --blue: #64b5f6;
    --radius: 12px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { height: 100%; }
body { height: 100vh; height: 100dvh; margin: 0; min-width: 900px; background: var(--bg); color: var(--text); overflow: hidden; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }

.app-header {
    flex: 0 0 auto;
    min-height: 76px;
    padding: 12px 22px;
    display: grid;
    grid-template-columns: minmax(230px, 1fr) auto;
    align-items: center;
    gap: 22px;
    background: rgba(18, 24, 36, .96);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 18px; line-height: 1.15; margin: 2px 0 0; }
.eyebrow { margin: 0; color: var(--yellow); letter-spacing: .14em; font-size: 10px; font-weight: 800; }
.egg-mark, .empty-egg {
    width: 38px;
    height: 47px;
    border-radius: 52% 48% 48% 52% / 62% 62% 38% 38%;
    background: linear-gradient(145deg, #fff5c4 0 54%, var(--yellow) 55%);
    transform: rotate(8deg);
    box-shadow: 0 0 28px rgba(255, 209, 102, .16);
}

.tabs { grid-column: 1 / -1; grid-row: 2; display: flex; flex-wrap: wrap; justify-content: center; width: 100%; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 11px; }
.tab { border: 0; background: transparent; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 700; }
.tab span { margin-left: 5px; padding: 1px 7px; border-radius: 99px; background: var(--panel-3); font-size: 11px; }
.tab.active { color: #17120a; background: var(--yellow); }
.tab.active span { background: rgba(0, 0, 0, .15); }
.tab.legacy-tab { opacity: .62; border: 1px dashed var(--border-bright); }
.tab.legacy-tab:hover, .tab.legacy-tab.active { opacity: 1; }

.header-actions { grid-column: 2; grid-row: 1; display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 7px 12px; }
.action-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.button { border: 1px solid transparent; border-radius: 9px; padding: 9px 13px; cursor: pointer; font-weight: 750; transition: .16s ease; }
.button:hover { transform: translateY(-1px); filter: brightness(1.06); }
.button:disabled { cursor: wait; opacity: .55; transform: none; }
.button.primary { background: var(--yellow); color: #17120a; }
.button.secondary { background: var(--panel-3); border-color: var(--border-bright); }
.button.danger { color: #ff92aa; background: rgba(239, 71, 111, .1); border-color: rgba(239, 71, 111, .35); }
.button.square { padding: 7px 13px; font-size: 22px; line-height: 1; background: var(--yellow); color: #17120a; }
.text-button { border: 0; padding: 3px; background: transparent; color: var(--muted); cursor: pointer; text-align: left; }
.text-button:hover { color: var(--text); }

.save-state { min-width: 142px; display: flex; justify-content: flex-end; gap: 7px; align-items: center; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 4px rgba(142, 154, 176, .08); }
.save-state[data-state="saved"] .status-dot { background: var(--green); }
.save-state[data-state="saving"] .status-dot { background: var(--yellow); animation: pulse .8s infinite alternate; }
.save-state[data-state="error"] .status-dot { background: var(--red); }
@keyframes pulse { to { opacity: .35; } }

.workspace { flex: 1 1 auto; display: grid; grid-template-columns: 310px minmax(590px, 1fr); min-height: 0; overflow: hidden; }
.collection-panel { display: flex; flex-direction: column; min-height: 0; overflow: hidden; background: var(--panel); border-right: 1px solid var(--border); }
.collection-tools { display: grid; grid-template-columns: 1fr auto; gap: 9px; padding: 14px; border-bottom: 1px solid var(--border); }
.search-box input, input, select, textarea {
    width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); padding: 9px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 209, 102, .10); }
textarea { resize: vertical; }
.collection-list { flex: 1 1 auto; min-height: 0; padding: 8px; overflow-y: auto; }
.collection-card { width: 100%; border: 1px solid transparent; border-radius: 10px; background: transparent; padding: 10px; margin-bottom: 3px; cursor: pointer; text-align: left; display: grid; grid-template-columns: 34px 1fr; gap: 10px; }
.collection-card:hover { background: var(--panel-2); }
.collection-card.active { border-color: var(--border-bright); background: var(--panel-3); }
.swatch { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: #131722; font-weight: 900; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); }
.dish-swatch { background: #f5e4bb; border-radius: 50%; box-shadow: inset 0 0 0 5px #c8b283, inset 0 0 0 7px #fff4d8; }
.collection-card strong, .collection-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collection-card strong { font-size: 13px; }
.collection-card small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.aside-footer { margin-top: auto; padding: 13px 16px; display: flex; flex-direction: column; gap: 7px; border-top: 1px solid var(--border); font-size: 12px; }

.editor-panel { min-width: 0; min-height: 0; padding: 24px clamp(24px, 4vw, 64px) 70px; overflow-y: auto; }
.editor-shell { max-width: 1720px; margin: 0 auto; }
.editor-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 20px; }
.editor-heading h2 { font-size: 29px; margin: 2px 0 5px; }
.technical-id { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.editor-actions { display: flex; gap: 8px; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 310px; align-items: start; gap: 18px; }
.form-stack { display: grid; gap: 15px; }
.section-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 17px; }
.section-card h3 { margin: 0 0 14px; font-size: 13px; letter-spacing: .04em; }
.legacy-visual-section { grid-column: 1 / -1; border-style: dashed; background: color-mix(in srgb, var(--panel) 72%, var(--bg)); }
.legacy-visual-collapsed { padding: 13px 15px; }
.legacy-visual-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.legacy-visual-heading h3 { margin: 3px 0 4px; color: #aab3c3; }
.legacy-visual-heading .section-help { margin: 0; }
.legacy-visual-heading .eyebrow { color: var(--muted); }
.legacy-visual-heading .button { white-space: nowrap; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: block; color: #bec7d6; font-size: 12px; font-weight: 650; }
label input, label select { display: block; margin-top: 6px; font-weight: 500; }
label small { display: block; margin-top: 5px; color: var(--muted); font-weight: 400; line-height: 1.35; }
.wide-field { margin-top: 14px; }
.wide-field textarea { display: block; margin-top: 6px; }
.color-field { display: grid; grid-template-columns: 48px 1fr; gap: 8px; margin-top: 6px; }
.color-field input[type="color"] { height: 39px; padding: 3px; }

.preview-card { position: sticky; top: 100px; }
.preview-stage { height: 260px; position: relative; overflow: hidden; border-radius: 10px; background: radial-gradient(circle at center, #243047 0 2px, transparent 3px), #0e1420; background-size: 24px 24px; }
.preview-stage svg { width: 100%; height: 100%; }
.swipe-preview { transform-origin: 150px 130px; animation: swipe-preview-spin 2s linear infinite; }
@keyframes swipe-preview-spin { to { transform: rotate(360deg); } }
.preview-caption { margin-top: 12px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.metric { padding: 9px; background: var(--panel-2); border-radius: 8px; }
.metric span, .metric strong { display: block; }
.metric span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.metric strong { font-size: 14px; margin-top: 2px; }
.plate-preview { display: grid; place-items: center; }
.plate { width: 175px; height: 175px; border-radius: 50%; background: #f8eac9; box-shadow: inset 0 0 0 17px #d5c093, inset 0 0 0 21px #fff7e3, 0 17px 35px rgba(0,0,0,.35); display: flex; flex-wrap: wrap; gap: 5px; align-content: center; justify-content: center; padding: 45px; }
.food-dot { width: 24px; height: 24px; border-radius: 44% 56% 52% 48%; box-shadow: inset -3px -4px 5px rgba(0,0,0,.2); }
.material-preview { display: grid; place-items: center; }
.material-orb { width: 142px; height: 142px; border-radius: 46% 54% 58% 42% / 52% 44% 56% 48%; box-shadow: inset -18px -22px 28px rgba(0,0,0,.24), inset 12px 12px 20px rgba(255,255,255,.18), 0 20px 44px rgba(0,0,0,.38); transform: rotate(-8deg); }
.usage-list { display: grid; gap: 7px; }
.usage-pill { padding: 8px 10px; border-radius: 8px; background: var(--panel-2); color: var(--muted); font-size: 12px; }
.usage-pill strong { color: var(--text); }
.upgrade-swatch { border: 2px solid var(--yellow); color: #fff; font-size: 9px; border-radius: 50%; }
.upgrade-swatch.shape-square { border-radius: 5px; }
.upgrade-swatch.shape-diamond { border-radius: 0; clip-path: polygon(50% 0,100% 50%,50% 100%,0 50%); }
.upgrade-swatch.shape-hexagon { clip-path: polygon(25% 5%,75% 5%,100% 50%,75% 95%,25% 95%,0 50%); border-radius: 0; }

.upgrade-editor-shell { max-width: 1480px; }
.upgrade-subtabs { display: flex; gap: 6px; width: fit-content; margin-bottom: 14px; padding: 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.upgrade-subtab { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font: inherit; font-size: 12px; font-weight: 800; cursor: pointer; }
.upgrade-subtab span { min-width: 21px; padding: 2px 6px; border-radius: 999px; background: var(--panel-3); color: var(--text); font-size: 10px; }
.upgrade-subtab.active { background: var(--panel-3); color: var(--yellow); }
/* La carte de l'arbre est la colonne de droite: elle suit le défilement du
 * formulaire au lieu de barrer le haut de la page. Repliée, il ne reste que sa
 * barre de titre, et la colonne rend sa largeur au formulaire. */
.tree-card { padding: 0; overflow: hidden; }
.upgrade-aside { position: sticky; top: 0; align-self: start; max-height: calc(100vh - 24px); overflow: auto; }
.upgrade-aside .tree-card-heading { padding: 9px 11px; }
.upgrade-aside .tree-card-heading h3 { margin: 0; font-size: 12px; }
.tree-card-tools { display: flex; gap: 5px; align-items: center; }
.tree-card-hint { margin: 0; padding: 7px 11px; font-size: 10px; color: var(--muted); border-top: 1px solid var(--border); }
.tree-card .upgrade-tree-preview { height: min(52vh, 460px); min-height: 240px; }
.tree-card.collapsed .upgrade-tree-preview, .tree-card.collapsed .tree-card-hint { display: none; }
.upgrade-editor-grid.tree-hidden { grid-template-columns: minmax(620px, 1fr) minmax(210px, .32fr); }
/* Mode elargi. L'arbre passe a gauche et recupere la largeur rendue par la
   liste de noeuds, qui se replie: on y choisit un noeud en le cliquant. Les
   reglages du noeud tiennent dans une colonne etroite a droite, en lignes
   libelle/valeur, pour rester sous la main sans reprendre la place gagnee.
   Les rappels sous les champs sortent le temps de l'elargissement; ils
   reviennent des qu'on reduit. */
.upgrade-editor-grid.tree-expanded { grid-template-columns: minmax(0, 1fr) minmax(290px, 380px); }
/* Apercu du fond de l'ecran d'upgrades: une surface, pas un objet pose sur un
   damier. Le cadre garde les proportions d'un ecran pour que 'couvrir' et
   'contenir' se distinguent vraiment. */
.upgrade-screen-preview { aspect-ratio: 16 / 9; width: 100%; height: auto; min-height: 0; border-radius: 9px; }
/* Le bandeau de l'apercu: c'est lui qu'on regle, il doit donc se voir sur le
   fond choisi et non a cote. */
.preview-banner { position: absolute; inset: 0 0 auto 0; padding: 9px 12px; font-size: 11px; font-weight: 800; letter-spacing: .05em; }
.upgrade-editor-grid.tree-expanded .upgrade-aside { order: -1; }
.upgrade-editor-grid.tree-expanded .tree-card .upgrade-tree-preview { height: calc(100vh - 268px); min-height: 420px; }
.tree-expanded .form-stack { gap: 10px; }
.tree-expanded .form-stack .section-card { padding: 11px 12px; }
.tree-expanded .form-stack .section-card h3 { margin-bottom: 9px; font-size: 11px; }
.tree-expanded .form-stack .field-grid, .tree-expanded .form-stack .field-grid.three { grid-template-columns: minmax(0, 1fr); gap: 7px; }
.tree-expanded .form-stack .field-grid > label { display: grid; grid-template-columns: 92px minmax(0, 1fr); align-items: center; gap: 8px; font-size: 11px; }
.tree-expanded .form-stack .field-grid > label input, .tree-expanded .form-stack .field-grid > label select { margin-top: 0; }
.tree-expanded .form-stack label small, .tree-expanded .form-stack .section-help:not(.address-preview) { display: none; }
.tree-expanded .form-stack input, .tree-expanded .form-stack select, .tree-expanded .form-stack textarea { padding: 6px 8px; font-size: 12px; }
.tree-expanded .form-stack .wide-field { margin-top: 9px; font-size: 11px; }
.tree-expanded .form-stack .wide-field textarea { margin-top: 4px; }
.tree-expanded .form-stack .nested-list { gap: 6px; margin-top: 8px; }
.tree-expanded .form-stack .nested-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding: 7px; }
.tree-expanded .form-stack .nested-row label { font-size: 10px; }
.tree-expanded .form-stack .nested-add { margin-top: 7px; padding: 6px; font-size: 11px; }
.tree-expanded .form-stack .empty-nested { margin-top: 7px; padding: 8px; }
.tree-expanded .form-stack .quick-conditions { margin-top: 8px; gap: 4px; }
.tree-expanded .form-stack .quick-condition { padding: 6px 8px; font-size: 11px; }
.tree-expanded .form-stack .node-live-preview { min-height: 110px; margin-top: 10px; }
.tree-expanded .form-stack .state-legend > div { margin-top: 5px; font-size: 10px; }
.upgrade-tree-preview { cursor: grab; touch-action: none; }
.upgrade-tree-preview.dragging { cursor: grabbing; }
.upgrade-tree-preview.moving-node { cursor: move; }
/* Atelier du graphe: la barre d'options, le mode reparentage et le noeud
   deplacable doivent se distinguer sans quitter l'aperçu des yeux. */
.tree-card-workshop { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; padding: 9px 11px; border-bottom: 1px solid var(--border); }
.tree-card-workshop .check-row { font-size: 11px; white-space: nowrap; cursor: pointer; }
.tree-card-workshop input { width: auto; margin: 0; accent-color: var(--yellow); }
.tree-card-workshop .button { margin-left: auto; padding: 6px 11px; font-size: 11px; }
.tree-card-workshop .button.active { border-color: var(--yellow); color: var(--yellow); }
.tree-card.reparenting .upgrade-tree-preview { box-shadow: inset 0 0 0 2px var(--yellow); cursor: crosshair; }
.web-tree-node.draggable { cursor: move; }
.tree-grid { pointer-events: none; }
.tree-card-heading { display: flex; justify-content: space-between; align-items: center; padding: 15px 17px; border-bottom: 1px solid var(--border); }
.tree-card-heading h3 { margin-bottom: 4px; }
.tree-card-heading p, .section-help { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
/* Table de poids: une ligne par entrée, rien de plus. L'ajout est un « + » sur
 * la ligne d'en-tête, pas une bande pleine largeur. */
.weight-list { display: grid; gap: 4px; }
.weight-head { display: flex; align-items: center; gap: 6px; font-size: 10px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.weight-head .grow { flex: 1; }
.weight-head-value { width: 66px; }
.weight-row { display: flex; align-items: center; gap: 6px; }
.weight-row select { flex: 1; min-width: 0; padding: 4px 6px; font-size: 11px; }
.weight-row input { width: 66px; padding: 4px 6px; font-size: 11px; }
.weight-row .icon-button, .weight-head .icon-button { width: 24px; height: 24px; line-height: 1; padding: 0; flex: none; }
.weight-empty { font-size: 11px; color: var(--muted); padding: 2px 0; }
.list-sort { display: block; padding: 0 12px 10px; }
.list-sort select { width: 100%; font-size: 11px; padding: 5px 7px; }
.upgrade-tree-preview { height: min(47vh, 520px); min-height: 330px; background-color: #0e1420; overflow: hidden; }
.upgrade-tree-preview svg { width: 100%; height: 100%; }
.web-tree-lines path { transition: .15s ease; }
.web-tree-node { cursor: pointer; }
.web-tree-node path { transition: .15s ease; }
.web-tree-node:hover path, .web-tree-node.selected path { filter: brightness(1.25); stroke-width: 8; }
.web-tree-node text { text-anchor: middle; dominant-baseline: middle; font-size: 11px; font-weight: 900; pointer-events: none; }
.upgrade-editor-grid { display: grid; grid-template-columns: minmax(620px, 1.65fr) minmax(330px, .8fr); gap: 18px; align-items: start; }
/* La page de l'arbre porte beaucoup de petits champs: elle se resserre pour en
 * montrer plus d'un coup, sans changer le vocabulaire des formulaires. */
.upgrade-editor-shell .section-card { padding: 12px 13px; }
.upgrade-editor-shell .section-card h3 { margin-bottom: 9px; font-size: 12px; }
.upgrade-editor-shell .form-stack { gap: 11px; }
.upgrade-editor-shell .field-grid { grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 9px 11px; }
.upgrade-editor-shell .field-grid.three { grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); }
.upgrade-editor-shell label { font-size: 11px; }
.upgrade-editor-shell label small { line-height: 1.3; }
.upgrade-editor-shell .nested-row { gap: 7px; }
.secondary-parent-editor { display: grid; gap: 8px; margin-top: 12px; padding: 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); }
.secondary-parent-heading { display: grid; gap: 2px; }
.secondary-parent-heading small, .empty-secondary-parent, .secondary-parent-row small { color: var(--muted); font-size: 10px; }
.secondary-parent-list { display: grid; gap: 6px; }
.secondary-parent-row { display: flex; align-items: center; justify-content: space-between; gap: 9px; padding: 6px 8px; border-radius: 7px; background: var(--panel); }
.secondary-parent-row span { display: grid; min-width: 0; }
.secondary-parent-row .icon-button { flex: none; }
.secondary-parent-editor select { margin: 0; }
.upgrade-theme-grid { display: grid; grid-template-columns: minmax(700px, 1.5fr) minmax(360px, .75fr); gap: 18px; align-items: start; }
.nested-list { display: grid; gap: 8px; margin-top: 12px; }
.nested-row { display: grid; align-items: end; gap: 8px; padding: 9px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; }
.nested-row.modifier-row { grid-template-columns: 1.2fr 1fr 1fr .7fr auto; }
.nested-row.condition-row { grid-template-columns: .9fr 1.1fr 1.1fr .9fr .8fr auto; }
.nested-row.speech-message-row { grid-template-columns: minmax(0, 1fr) 130px auto; }
.drop-list { display: grid; gap: 8px; }
.nested-row.drop-row { grid-template-columns: minmax(180px, 1fr) minmax(150px, .45fr) auto; }
.nested-row.attack-row { grid-template-columns: minmax(155px, 1.15fr) minmax(175px, 1.25fr) repeat(6, minmax(88px, .55fr)) auto; }
.speech-trigger-list { display: grid; gap: 14px; margin-top: 16px; }
.speech-trigger-card { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.speech-trigger-card h4 { margin: 0; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.speech-message-row textarea { min-height: 54px; resize: vertical; }
/* L'aperçu d'adresse occupe toute la largeur sous les listes en cascade. */
.address-preview { grid-column: 1 / -1; margin: 2px 0 0; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; opacity: .75; }
.address-preview.address-invalid { color: #ff9f43; opacity: 1; }
.nested-row input, .nested-row select { margin-top: 4px; padding: 7px; }
.nested-remove { min-width: 37px; padding: 7px 10px; }
.nested-add { margin-top: 10px; width: 100%; }
.empty-nested { margin-top: 11px; border: 1px dashed var(--border-bright); border-radius: 8px; padding: 12px; color: var(--muted); text-align: center; font-size: 11px; }
/* Case rapide d'une section de conditions: elle porte a elle seule une
   condition d'adresse, elle doit donc se lire comme une ligne, pas comme
   une option perdue sous le texte d'aide. */
.quick-conditions { display: grid; gap: 6px; margin-top: 11px; }
.quick-condition { margin: 0; padding: 9px 11px; border: 1px solid var(--border-bright); border-radius: 8px; background: var(--panel-2); font-size: 12px; cursor: pointer; }
.quick-condition input { width: auto; margin: 0; accent-color: var(--yellow); }
.quick-condition strong { color: var(--yellow); }
.node-live-preview { min-height: 150px; display: grid; place-items: center; margin-top: 15px; border-radius: 9px; background: var(--bg); }
/* L'apercu vivant reprend le trace SVG de l'arbre plutot que de l'imiter en
   CSS: sans cela ni l'arrondi des coins ni le coefficient de taille ne se
   verraient ici, et l'auteur reglerait a l'aveugle. */
.live-node { width: 132px; height: 132px; overflow: visible; }
.theme-state-list { display: grid; gap: 9px; margin-top: 13px; }
.theme-state-card { padding: 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); }
.theme-state-card > strong { display: block; margin-bottom: 8px; color: var(--yellow); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.theme-state-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 7px; align-items: end; }
/* Gras, italique, souligne: des cases a cocher habillees en boutons. La case
   reste la vraie commande, donc le clavier et le branchement commun des champs
   d'etat continuent de marcher. */
.text-style-toggles { display: flex; gap: 4px; align-items: end; }
.text-style-toggle { flex: 1 1 0; margin: 0; cursor: pointer; }
.text-style-toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.text-style-toggle span { display: grid; place-items: center; height: 35px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--muted); font-size: 13px; }
.text-style-toggle input:checked + span { border-color: var(--yellow); background: var(--panel-3); color: var(--yellow); }
.text-style-toggle input:focus-visible + span { box-shadow: 0 0 0 3px rgba(255, 209, 102, .10); }
/* Niveaux d'un plat. Le vert ne decore pas: il dit « cette valeur change au
   niveau ouvert ». La valeur du palier precedent se lit dans le libelle, en
   plus discret, pour comparer sans changer d'onglet. */
/* La barre des niveaux est une navigation, pas une section: une seule ligne
   sous les sous-onglets, avec l'ajout et le retrait au bout. */
.recipe-level-bar { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin: 0 0 15px; }
.recipe-level-bar .icon-button { min-width: 34px; }
.recipe-level-bar .button { margin-left: auto; padding: 7px 12px; font-size: 11px; }
.level-threshold { border-color: var(--border-bright); background: var(--panel-2); }
.level-threshold label { font-size: 12px; }
.level-previous { margin-left: 6px; color: var(--muted); font-size: 10px; font-weight: 400; }
.level-changed > h3, .level-changed > label, label.level-changed { color: var(--green); }
.level-changed .level-previous { color: var(--muted); }
.level-changed > .section-card { border-color: var(--green); }
.theme-state-fields label { color: var(--muted); font-size: 9px; }
.theme-state-fields input, .theme-state-fields select { min-width: 0; margin-top: 4px; padding: 6px; }
.theme-state-fields input[type="color"] { height: 35px; padding: 2px; }
.theme-preview-gallery { display: grid; grid-template-columns: repeat(2, minmax(130px, 1fr)); gap: 9px; margin-top: 12px; }
.theme-state-preview { padding: 8px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); text-align: center; }
.theme-state-preview svg { display: block; width: 100%; height: 82px; }
.theme-state-preview strong, .theme-state-preview small { display: block; }
.theme-state-preview strong { font-size: 11px; }
.theme-state-preview small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.usage-button { width: 100%; border: 0; text-align: left; cursor: pointer; }
.usage-button span { display: block; margin-top: 2px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 10px; }
.link-toggle { margin-top: 13px; }
.state-legend > div { display: flex; align-items: center; gap: 9px; margin-top: 8px; font-size: 11px; }
.state-index { width: 23px; height: 23px; display: grid; place-items: center; border-radius: 50%; background: var(--panel-3); color: var(--yellow); font-weight: 800; }
.toggle-label { display: flex; align-items: center; gap: 9px; margin-top: 20px; }
.toggle-label input { width: auto; margin: 0; accent-color: var(--yellow); }
.value-preview { text-align: center; }
.value-preview .value-kind { display: inline-block; color: var(--yellow); font-weight: 900; letter-spacing: .12em; font-size: 10px; }
.value-preview > strong, .value-preview > b { display: block; margin-top: 12px; }
.value-preview > strong { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.value-preview > b { font-size: 46px; color: var(--blue); overflow-wrap: anywhere; }
.value-preview p { color: var(--muted); line-height: 1.5; font-size: 12px; }

.ingredient-label { font-size: 12px; display: flex; align-items: center; gap: 6px; }
.ingredient-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }

.empty-state { min-height: 65vh; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--text); margin: 18px 0 4px; }
.empty-state p { margin: 0; }
.empty-egg { width: 54px; height: 67px; opacity: .28; filter: grayscale(1); }
.empty-list { padding: 30px 12px; color: var(--muted); text-align: center; font-size: 13px; }

.error-drawer { position: fixed; z-index: 40; right: 16px; bottom: 16px; width: min(560px, calc(100vw - 32px)); max-height: 50vh; overflow: auto; padding: 16px; border: 1px solid rgba(239,71,111,.65); border-radius: 12px; background: #25151d; box-shadow: 0 18px 60px rgba(0,0,0,.55); display: flex; justify-content: space-between; gap: 16px; }
.error-drawer[hidden] { display: none; }
.error-drawer ul { padding-left: 20px; margin: 9px 0 0; color: #ffc1cf; font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translate(-50%, 20px); padding: 10px 15px; border-radius: 9px; background: var(--text); color: #111722; font-weight: 750; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

dialog { width: min(440px, calc(100vw - 40px)); border: 1px solid var(--border-bright); border-radius: 14px; background: var(--panel); color: var(--text); padding: 0; box-shadow: 0 30px 90px rgba(0,0,0,.7); }
dialog::backdrop { background: rgba(4,7,12,.76); backdrop-filter: blur(3px); }
dialog form { padding: 22px; display: grid; gap: 16px; }
dialog h2 { margin: -9px 0 2px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 5px; }

.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; }
@media (max-width: 1100px) {
    .editor-grid { grid-template-columns: 1fr; }
    .preview-card { position: static; order: -1; }
    .preview-stage { height: 220px; }
    .upgrade-editor-grid { grid-template-columns: 1fr; }
    .upgrade-theme-grid { grid-template-columns: 1fr; }
    .theme-state-fields { grid-template-columns: repeat(4, minmax(74px, 1fr)); }
    .nested-row.condition-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .nested-row.speech-message-row { grid-template-columns: minmax(0, 1fr) 110px auto; }
    .nested-row.drop-row { grid-template-columns: minmax(0, 1fr) 140px auto; }
    .nested-row.attack-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .nested-row.attack-row .nested-remove { justify-self: end; }
    .legacy-visual-heading { align-items: flex-start; flex-direction: column; }
    .model-3d-heading { flex-direction: column; gap: 8px; }
    .model-transform-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .model-animation-head { display: none; }
    .model-animation-row { min-width: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 11px; }
    .model-animation-state, .model-animation-clip { grid-column: 1 / -1; }
    .model-field-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; text-transform: uppercase; }
}

/* À largeur CSS suffisante, les cartes du formulaire occupent deux colonnes.
   Le zoom du navigateur réduit cette largeur et repasse automatiquement à la
   pile simple, sans option ni état supplémentaire. */
@media (min-width: 1800px) {
    .editor-grid { grid-template-columns: minmax(0, 1fr) 330px; }
    .editor-grid > .form-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
    .editor-grid > .form-stack > .speech-bubble-editor,
    .editor-grid > .form-stack > .wide-section { grid-column: 1 / -1; }
}
/* --- Page Textes --------------------------------------------------------- */
.loc-table { display: flex; flex-direction: column; gap: 4px; }
.loc-head, .loc-row { display: grid; grid-template-columns: minmax(220px, 1.4fr) repeat(var(--loc-langs, 2), minmax(160px, 1fr)); gap: 10px; align-items: center; }
.loc-head { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; opacity: .6; padding: 0 0 6px; border-bottom: 1px solid rgba(255,255,255,.12); }
.loc-row { padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.loc-source { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.loc-source code { font-size: 11px; opacity: .55; word-break: break-all; }
.loc-source span { font-size: 13px; font-weight: 600; }
.loc-row input { width: 100%; }
.loc-row input.loc-empty { border-color: rgba(255,159,67,.55); background: rgba(255,159,67,.07); }
.lang-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.lang-chip { display: inline-flex; align-items: center; gap: 8px; padding: 5px 6px 5px 12px; border: 1px solid rgba(255,255,255,.14); border-radius: 999px; font-size: 13px; }
.lang-chip span { opacity: .7; }
.lang-chip .lang-remove { padding: 0 7px; line-height: 1.5; font-size: 12px; }
.lang-add { display: inline-flex; gap: 8px; margin-left: auto; }
.lang-add input { width: 180px; }
.loc-filter { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; }

/* --- Gestionnaire de salles ---------------------------------------------- */
/* La grille montre la progression telle qu'elle se joue: une colonne par
   dimension, une case par salle, de haut en bas. */
.room-editor-grid { display: grid; grid-template-columns: minmax(330px, .85fr) minmax(520px, 1.4fr); gap: 18px; align-items: start; }
.room-grid-card { position: sticky; top: 0; max-height: calc(100vh - 130px); display: flex; flex-direction: column; }
.room-grid-shell { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.room-grid { display: flex; gap: 8px; overflow: auto; padding-bottom: 6px; min-height: 0; }
.room-column { display: flex; flex-direction: column; gap: 6px; min-width: 104px; }
.room-column-special { border-left: 1px dashed var(--border); padding-left: 8px; }
.room-column-head { display: flex; flex-direction: column; gap: 1px; padding: 4px 2px; border-bottom: 1px solid var(--border); }
.room-column-head strong { font-size: 13px; letter-spacing: .06em; }
.room-column-head span { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-column-head small { font-size: 10px; color: var(--muted); }
.room-cells { display: flex; flex-direction: column; gap: 5px; overflow-y: auto; }
.room-cell { position: relative; display: flex; flex-direction: column; gap: 1px; padding: 6px 7px; border: 2px solid; border-radius: 8px; cursor: pointer; text-align: left; color: #f4f6fb; }
.room-cell strong { font-size: 11px; letter-spacing: .05em; }
.room-cell span { font-size: 10px; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-cell small { font-size: 10px; opacity: .7; }
.room-cell.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.room-cell-badge { position: absolute; top: 4px; right: 5px; font-size: 9px; font-style: normal; padding: 1px 4px; border-radius: 6px; background: rgba(0, 0, 0, .45); }
.room-column-tools { display: flex; gap: 8px; padding-top: 4px; border-top: 1px solid var(--border); }
.room-empty { font-size: 11px; color: var(--muted); padding: 8px 2px; }
.element-grid { display: flex; flex-direction: column; gap: 7px; }
.element-row { display: grid; grid-template-columns: auto 1fr 78px 66px 66px; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); }
.element-row[data-enabled="false"] { opacity: .5; }
.element-row label { font-size: 10px; color: var(--muted); }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.check-row { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.nested-row.replace-row { grid-template-columns: 1.4fr .7fr .8fr auto; }

@media (max-width: 1500px) {
    .room-editor-grid { grid-template-columns: 1fr; }
    .room-grid-card { position: static; max-height: none; }
}

/* La page Salles porte sa grille au centre: le panneau de gauche se replie
   plutôt que de redire la même chose. */
/* Le panneau masqué sort du flux de la grille: il ne reste qu'un enfant, donc
   une seule piste. Déclarer deux pistes ici enverrait le panneau d'édition dans
   la première et l'écraserait à zéro. */
.workspace.no-list { grid-template-columns: minmax(0, 1fr); }
.workspace.no-list .collection-panel { display: none; }
.room-column-head { width: 100%; border: 1px solid transparent; border-radius: 8px; background: transparent; cursor: pointer; text-align: left; }
.room-column-head.active { border-color: var(--accent); background: var(--panel-2); }

/* Bandeau de péremption: un onglet resté ouvert longtemps travaille peut-être
   sur une version dépassée. Il occupe sa propre bande pour ne pas se glisser
   dans la grille du plan de travail, qui compte ses enfants. */
.stale-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 0 24px 12px;
    padding: 12px 18px;
    border-radius: 10px;
    border: 1px solid #c8973f;
    background: #3a2f18;
    color: #ffe8c2;
}
.stale-banner[hidden] { display: none; }
.stale-banner span { flex: 1 1 320px; }

/* Page Visuels: une ligne par état, avec ce que l'entité affichera vraiment. */
.visual-grid { display: grid; gap: 8px; }
.visual-row { display: grid; grid-template-columns: 40px 150px minmax(0, 1fr) auto; align-items: center; gap: 10px; }
/* Une case de la feuille, pas la bande entiere. La piste est declaree ici: une
   vignette masquee decalerait toute la ligne d'une piste. */
.visual-thumb { width: 40px; height: 40px; border: 1px solid #332941; border-radius: 4px; background-color: #171121; background-repeat: no-repeat; background-position: 0 0; image-rendering: pixelated; }
.visual-thumb.empty { opacity: .35; }
.visual-note { font-size: 12px; color: #857c92; white-space: nowrap; }
.visual-note-own { color: #7fcea5; }
.visual-note-shape { color: #c8973f; }
.model-3d-section { grid-column: 1 / -1; padding: 18px 20px; }
.model-3d-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.model-3d-heading h3 { margin: 3px 0 4px; }
.model-3d-heading .section-help, .model-3d-heading .eyebrow { margin: 0; }
.model-3d-status { flex: none; padding: 6px 9px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: 11px; }
.model-path-field { display: block; margin-top: 13px; }
.model-transform-grid { display: grid; grid-template-columns: repeat(6, minmax(125px, 1fr)); gap: 10px; margin-top: 13px; padding: 12px; border: 1px solid var(--border); border-radius: 9px 9px 0 0; background: var(--panel-2); }
.model-animation-table { overflow-x: auto; border: 1px solid var(--border); border-top: 0; border-radius: 0 0 9px 9px; }
.model-animation-head, .model-animation-row { display: grid; grid-template-columns: 115px minmax(210px, 1.6fr) 84px 165px 135px 92px 92px; gap: 8px; align-items: center; min-width: 1010px; }
.model-animation-head { padding: 8px 10px; color: var(--muted); background: rgba(255,255,255,.025); border-bottom: 1px solid var(--border); font-size: 10px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.model-animation-row { padding: 7px 10px; border-bottom: 1px solid rgba(255,255,255,.055); }
.model-animation-row:last-child { border-bottom: 0; }
.model-animation-state { color: #dce4f2; font-size: 12px; }
.model-animation-row label input, .model-animation-row label select { margin-top: 0; padding: 7px; }
.model-animation-flags { display: flex; flex-wrap: wrap; gap: 3px 9px; }
.model-animation-flags .check-row { margin: 0; white-space: nowrap; font-size: 11px; }
.model-field-label { display: none; }
.model-3d-help { margin-top: 10px; color: var(--muted); font-size: 12px; }
.model-3d-help summary { width: max-content; cursor: pointer; color: #aeb8c9; }
.model-3d-help p { margin: 7px 0 0; line-height: 1.45; }
.visual-preview { max-width: 100%; image-rendering: pixelated; border: 1px solid #332941; border-radius: 4px; background: #171121; }
.visual-preview.empty { padding: 28px 12px; text-align: center; font-size: 12px; color: #857c92; }

/* Une ressource que Godot n'a pas importée n'existe pas en jeu: le dire fort. */
.asset-warning { color: #e8b855; display: block; margin-top: 4px; }

/* --- Generateur de scenes narratives ------------------------------------ */
.story-editor-grid { display: grid; grid-template-columns: minmax(620px, 1.55fr) minmax(360px, .85fr); gap: 18px; align-items: start; }
.story-preview-card { position: sticky; top: 0; }
#story-preview { overflow: hidden; border: 1px solid var(--border); border-radius: 10px; background: #101522; aspect-ratio: 16 / 9; }
#story-preview svg { display: block; width: 100%; height: 100%; }
.story-section-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.story-section-heading h3 { margin-bottom: 5px; }
.story-section-heading .section-help { margin: 0; }
.story-actor-list, .story-event-list { display: flex; flex-direction: column; gap: 10px; }
.story-actor-card, .story-event-card { border: 1px solid var(--border); border-radius: 11px; background: var(--panel-2); padding: 12px; }
.story-actor-card > header, .story-event-card > header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.story-actor-card > header > strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.story-event-card > header > div:nth-child(2) { display: flex; flex-direction: column; gap: 2px; }
.story-row-actions { display: flex; gap: 5px; margin-left: auto; }
.story-event-number { display: grid; place-items: center; width: 28px; height: 28px; flex: 0 0 28px; border-radius: 50%; background: var(--accent); color: #111827; font-weight: 800; font-size: 12px; }
.story-placement { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.story-choice-list { display: flex; flex-direction: column; gap: 7px; }
.story-choice-row { display: grid; grid-template-columns: minmax(170px, 1fr) minmax(140px, .7fr) auto; gap: 7px; align-items: center; }
.story-event-card .wide-field { grid-column: 1 / -1; }
@media (max-width: 1350px) {
    .story-editor-grid { grid-template-columns: 1fr; }
    .story-preview-card { position: static; order: -1; }
}

/* --- La frise d'attaque ------------------------------------------------ */
.frise-mode { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.frise-mode .section-help { margin: 0; flex: 1 1 260px; }
.frise { width: 100%; height: auto; display: block; margin: 4px 0 10px; overflow: visible; }
.frise-lane { fill: rgba(255, 255, 255, .05); stroke: rgba(255, 255, 255, .12); }
.frise-tick { stroke: rgba(255, 255, 255, .08); stroke-width: 1; }
.frise-time { fill: rgba(233, 237, 245, .55); font-size: 9px; text-anchor: middle; }
.frise-label { fill: rgba(233, 237, 245, .78); font-size: 11px; }
.frise-block { cursor: grab; opacity: .82; }
.frise-block:active { cursor: grabbing; }
.frise-block:hover { opacity: 1; }
.frise-block.chosen { stroke: #f8f9fb; stroke-width: 2; opacity: 1; }
.frise-handle { fill: transparent; cursor: ew-resize; }
.frise-handle:hover { fill: rgba(248, 249, 251, .45); }
.frise-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.frise-total { margin: 0; font-size: 12px; color: rgba(233, 237, 245, .72); }
.frise-total-warn { color: #f4a261; }
