:root {
  --bg: #f6f5f2; --panel: #ffffff; --text: #1d1d1f; --muted: #6b6b70; --line: #e4e2dc;
  --accent: #6d28d9; --accent-soft: #ede9fe; --danger: #b91c1c; --ok: #15803d; --warn: #b45309;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214; --panel: #1c1c1f; --text: #ececee; --muted: #9a9aa2; --line: #2e2e33;
    --accent: #a78bfa; --accent-soft: #2e2547; --danger: #f87171; --ok: #4ade80; --warn: #fbbf24;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code, pre, textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar .brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar .spacer { flex: 1; }
.topbar select { max-width: 240px; }
.layout { max-width: 1180px; margin: 0 auto; padding: 24px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 16px 0 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--text); border-color: var(--accent); font-weight: 600; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi b { display: block; font-size: 24px; }
.kpi span { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 7px 12px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
:root:not([data-theme="light"]) button.primary { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) button.primary { color: #1c1033; } }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; }
button:disabled { opacity: .5; cursor: default; }

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
label .hint { font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); }
input[type=checkbox] { width: auto; }
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 12px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 12px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.ic { font-size: 24px; width: 36px; text-align: center; }
.ic img { max-width: 32px; max-height: 32px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--accent-soft); color: var(--accent); }
.pill.off { background: var(--line); color: var(--muted); }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.summary { color: var(--muted); font-size: 12.5px; }

/* constructeur de règles */
.group { border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 10px; background: var(--bg); }
.group .group { margin-top: 8px; background: var(--panel); }
.group-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.group-head select { width: auto; }
.cond { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-top: 8px; }
.group .group .cond { background: var(--bg); }
.cond > select { width: auto; max-width: 320px; }
.cond .params { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 200px; }
.cond .params > div { min-width: 120px; flex: 1; }
.cond .params label { font-weight: 400; font-size: 12px; color: var(--muted); margin: 0 0 2px; }
.cond .help { flex-basis: 100%; font-size: 12px; color: var(--muted); }
.neg { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.multi { display: flex; flex-wrap: wrap; gap: 4px 12px; max-height: 120px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--panel); }
.multi label { display: flex; gap: 4px; align-items: center; font-size: 13px; color: var(--text) !important; }

/* modale */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; z-index: 100; }
.modal { background: var(--panel); border-radius: 14px; width: min(860px, 100%); padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; position: sticky; bottom: -22px; background: var(--panel); padding: 12px 0 0; }
.error { color: var(--danger); min-height: 18px; }

#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 380px; }
.toast.err { background: var(--danger); color: #fff; }

.login { max-width: 380px; margin: 12vh auto; }
.empty { text-align: center; padding: 30px; color: var(--muted); }
.copy { position: relative; }
.copy button { position: absolute; top: 6px; right: 6px; font-size: 12px; padding: 3px 8px; }

@media (max-width: 640px) {
  .layout { padding: 16px; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
}

/* aperçu du bouton du jeu */
.launch-stage { position: relative; height: 170px; border: 1px dashed var(--line); border-radius: 12px; background: var(--bg); overflow: hidden; margin: 8px 0; }
.launch-stage::before { content: "Aperçu"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: var(--muted); font-size: 12px; }
.launch-stage.off .launch-preview { opacity: .25; }
.launch-preview { position: absolute; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); line-height: 1; }
.launch-preview b { font-size: 15px; white-space: nowrap; }
/* aperçu du placement précis d'un élément */
.pos-preview { position: relative; width: 200px; height: 125px; flex: none; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); overflow: hidden; }
.pos-preview.el::before { content: ""; position: absolute; left: 60px; top: 40px; width: 80px; height: 45px; border: 1px dashed var(--muted); border-radius: 4px; }
.pos-dot { position: absolute; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=color] { padding: 3px; height: 38px; cursor: pointer; }
.widget-frame { display: block; width: 100%; height: 560px; border: 1px solid var(--line); border-radius: var(--radius); background: #fafaf7; margin-top: 8px; }
.brand-logo { display: inline-flex; align-items: center; margin-right: 6px; }
.brand-logo img { height: 22px; width: auto; vertical-align: middle; }
.login h1 .brand-logo img { height: 30px; }
.site-footer { max-width: 1180px; margin: 0 auto; padding: 8px 24px 32px; display: flex; flex-wrap: wrap; gap: 16px; color: var(--muted); font-size: 12px; }
