:root {
  --bg: #0e1014;
  --surface: #161920;
  --surface-2: #1d2129;
  --surface-3: #262b35;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #eceef3;
  --text-2: #a9b0bd;
  --text-3: #8a92a1;
  --accent: #f5b544;
  --accent-hover: #ffc560;
  --on-accent: #1d1305;
  --danger: #e5484d;
  --danger-hover: #f05a5f;
  --danger-text: #ff8589;
  --ok: #3dd68c;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  font-feature-settings: "cv11", "ss01";
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; background: var(--bg); }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--text-3); }
code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.92em;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-3);
}
:focus-visible { outline: none; box-shadow: var(--focus); }

.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon .fill { fill: currentColor; stroke: none; }
.icon-lg { width: 28px; height: 28px; }

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 50;
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--on-accent); font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-weight: 550; white-space: nowrap; cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-3); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { background: #2f3541; border-color: var(--line-strong); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-panic { background: var(--danger); color: #fff; font-weight: 750; letter-spacing: 0.02em; }
.btn-panic:hover:not(:disabled) { background: var(--danger-hover); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 36px; padding: 0; }
.btn-sm.btn-icon { width: 30px; }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: transparent; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 20px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; background: var(--accent);
  box-shadow: inset 0 0 0 5px var(--accent), inset 0 0 0 11px var(--on-accent);
}
.ws-status { margin-right: auto; font-size: 12px; color: var(--text-3); }
.ws-status[data-state="closed"] { color: var(--danger-text); }
.me { display: flex; align-items: center; gap: 10px; color: var(--text-2); }
.me img, .avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--surface-3); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 16px 20px 32px;
  align-items: start;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.center { display: grid; gap: 16px; min-width: 0; outline: none; }

/* ---------- streamer rail ---------- */
.rail { position: sticky; top: 72px; display: grid; gap: 8px; }
.rail-title { font-size: 12px; font-weight: 600; color: var(--text-3); padding: 0 8px; }
.streamer-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.streamer {
  display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 10px; align-items: center;
  width: 100%; padding: 8px; border: 0; border-radius: var(--radius);
  background: transparent; text-align: left; cursor: pointer;
  transition: background-color 0.15s ease;
}
.streamer:hover { background: var(--surface-2); }
.streamer[aria-current="true"] { background: var(--surface-3); }
.streamer-avatar { position: relative; width: 40px; height: 40px; }
.streamer-avatar img, .streamer-avatar .all-mark {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--surface-3);
}
.all-mark { display: grid; place-items: center; color: var(--text-2); }
.dot {
  position: absolute; right: -2px; bottom: -2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #5b6270; border: 3px solid var(--bg);
}
.dot.is-online { background: var(--ok); }
.streamer-name { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 0; }
.streamer-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.streamer-meta { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.streamer-meta .warn { color: var(--danger-text); }
.live {
  flex: none; padding: 1px 5px; border-radius: 4px;
  background: var(--danger); color: #fff; font-size: 10px; font-weight: 750; letter-spacing: 0.04em;
}
.create-overlay { margin-top: 8px; }

/* ---------- preview ---------- */
.preview-panel { padding: 14px; display: grid; gap: 12px; }
.preview-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.target-name { font-size: 18px; font-weight: 650; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-2); font-size: 12px; font-weight: 550;
}
.chip.is-ok::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.chip.is-danger { background: rgba(229, 72, 77, 0.18); color: var(--danger-text); }

.preview {
  position: relative; aspect-ratio: 16 / 9; width: 100%;
  border-radius: var(--radius); overflow: hidden; background: #0a0b0e;
  touch-action: none;
}
.preview > * { position: absolute; inset: 0; }
.preview-bg {
  background-color: #12141a;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: calc(100% / 16) calc(100% / 9);
}
.preview iframe { width: 100%; height: 100%; border: 0; display: block; }
.preview-mirror { pointer-events: none; }
/* Must match the overlay document's (light) scheme, or the browser paints an opaque backdrop. */
.preview-mirror iframe { background: transparent; color-scheme: light; }
.preview-twitch { pointer-events: none; }
.draw-layer { width: 100%; height: 100%; cursor: crosshair; z-index: 4; }
.preview-hint {
  inset: auto 0 12px 0; text-align: center; pointer-events: none;
  color: var(--text-3); font-size: 13px;
}
.editor-layer { z-index: 3; pointer-events: none; }

.ghost {
  position: absolute; pointer-events: auto; cursor: grab;
  border: 2px dashed rgba(245, 181, 68, 0.9); border-radius: 8px;
  background: rgba(245, 181, 68, 0.08);
  touch-action: none;
}
.ghost:focus-visible { box-shadow: 0 0 0 3px rgba(245, 181, 68, 0.55); outline: none; }
.ghost.is-dragging { cursor: grabbing; }
.ghost > img, .ghost > video {
  width: 100%; height: 100%; object-fit: contain; opacity: 0.75; border-radius: 6px; pointer-events: none;
}
.ghost-label {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 6px;
  color: var(--text); font-size: 13px; text-align: center; padding: 8px; pointer-events: none;
  text-shadow: 0 1px 2px #000;
}
.ghost-handle {
  position: absolute; right: -9px; bottom: -9px; width: 18px; height: 18px;
  border-radius: 4px; background: var(--accent); border: 2px solid var(--bg);
  cursor: nwse-resize; touch-action: none;
}
.ghost-handle::after { content: ""; position: absolute; inset: -12px; }
.ghost.is-fullscreen .ghost-handle { display: none; }
.ghost.is-fullscreen { cursor: default; border-radius: 0; }
.guide { position: absolute; background: rgba(245, 181, 68, 0.9); opacity: 0; transition: opacity 0.12s; pointer-events: none; }
.guide.v { top: 0; bottom: 0; width: 1px; }
.guide.h { left: 0; right: 0; height: 1px; }
.editor-layer.is-dragging .guide { opacity: 0.18; }
.editor-layer .guide.is-active { opacity: 1; }

.quickbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.quickbar .sep { width: 1px; height: 20px; background: var(--line-strong); margin: 0 6px; }
.quickbar .readout { margin-left: auto; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ---------- controls ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; align-items: center; }
.controls .btn-panic { margin-left: auto; min-height: 44px; padding: 0 22px; font-size: 15px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; padding: 6px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs [role="tab"] {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 34px; padding: 0 12px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2); font-weight: 550; cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tabs [role="tab"]:hover { color: var(--text); background: var(--surface-2); }
.tabs [role="tab"][aria-selected="true"] { color: var(--text); background: var(--surface-3); }
.tabpanel { padding: 16px; }

/* ---------- forms ---------- */
.send { position: sticky; top: 72px; }
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; align-content: start; min-width: 0; border: 0; margin: 0; padding: 0; }
.field label, .field legend { font-size: 13px; font-weight: 550; color: var(--text-2); padding: 0; display: flex; justify-content: space-between; gap: 8px; }
.field output { color: var(--text-3); font-variant-numeric: tabular-nums; font-weight: 500; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.help { font-size: 12px; color: var(--text-3); }
input[type="text"], input[type="url"], input[type="number"], input[type="password"], select, textarea {
  width: 100%; min-height: 38px; padding: 8px 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text);
  transition: border-color 0.15s ease;
}
textarea { resize: vertical; min-height: 64px; }
input::placeholder, textarea::placeholder { color: #7a8292; }
input:hover, select:hover, textarea:hover { border-color: rgba(255, 255, 255, 0.26); }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 24px; }
input[type="color"] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg); }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 28px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.form-actions .btn-primary { min-width: 120px; }

.dropzone {
  display: grid; justify-items: center; gap: 6px; padding: 22px 16px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius);
  background: var(--bg); color: var(--text-2); text-align: center; cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: rgba(245, 181, 68, 0.06); }
.dropzone:focus-within { box-shadow: var(--focus); }
.dropzone.has-file { border-style: solid; border-color: rgba(245, 181, 68, 0.5); }
.dropzone-title { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.dropzone-sub { font-size: 12px; }
.clear-file { justify-self: start; margin-top: -6px; }

.progress { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
progress { width: 100%; height: 8px; appearance: none; border: 0; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--surface-3); }
progress::-webkit-progress-value { background: var(--accent); transition: width 0.2s ease; }
progress::-moz-progress-bar { background: var(--accent); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line-strong); cursor: pointer; padding: 0;
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text); }

.segmented { display: flex; gap: 6px; }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: grid; place-items: center; min-height: 40px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--bg); cursor: pointer; font-weight: 600;
}
.segmented input:checked + span { border-color: var(--danger); background: rgba(229, 72, 77, 0.16); color: #fff; }
.segmented input:focus-visible + span { box-shadow: var(--focus); }

/* ---------- history and stats ---------- */
.panel-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.entry {
  display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 8px; border-radius: var(--radius); background: var(--surface-2);
}
.thumb {
  width: 72px; height: 48px; border-radius: 6px; background: var(--surface-3); overflow: hidden;
  display: grid; place-items: center; color: var(--text-2);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.entry-main { min-width: 0; display: grid; gap: 2px; }
.entry-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--text-3); align-items: center; }
.entry-author { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.entry-author img { width: 18px; height: 18px; border-radius: 50%; }
.empty { padding: 24px 8px; text-align: center; color: var(--text-3); }

.stats { display: grid; grid-template-columns: 180px 1fr 1fr; gap: 16px; }
.stat-total { display: grid; align-content: start; gap: 4px; padding: 16px; border-radius: var(--radius); background: var(--surface-2); }
.stat-total strong { font-size: 32px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-list h3 { font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.stat-list ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.stat-list li { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: var(--radius-sm); background: var(--surface-2); }
.stat-list .rank { color: var(--text-3); font-variant-numeric: tabular-nums; }
.stat-list .who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.stat-list .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-list .count { font-variant-numeric: tabular-nums; color: var(--text-2); }

/* ---------- settings ---------- */
.settings { display: grid; gap: 20px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.settings h3 { font-size: 14px; font-weight: 650; }
.settings section { display: grid; gap: 12px; }
.settings .preview { max-width: 520px; }
.obs-link { display: flex; gap: 6px; }
.obs-link input { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.steps { margin: 0; padding-left: 20px; color: var(--text-2); display: grid; gap: 4px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- toasts and dialogs ---------- */
.toasts {
  position: fixed; z-index: 100; right: 16px; bottom: 16px;
  display: grid; gap: 8px; width: min(380px, calc(100vw - 32px));
}
.toast {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: start;
  padding: 12px 12px 12px 14px; border-radius: var(--radius);
  background: var(--surface-3); border: 1px solid var(--line-strong);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.22s var(--ease-out);
}
.toast.is-error { border-color: rgba(229, 72, 77, 0.6); }
.toast.is-error p::before { content: "Erreur : "; font-weight: 650; color: var(--danger-text); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.16s ease-in, transform 0.16s ease-in; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.dialog {
  width: min(440px, calc(100vw - 32px)); padding: 0;
  border: 1px solid var(--line-strong); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.dialog::backdrop { background: rgba(5, 6, 8, 0.7); }
.dialog[open] { animation: dialog-in 0.2s var(--ease-out); }
@keyframes dialog-in { from { opacity: 0; transform: scale(0.97); } }
.dialog-body { display: grid; gap: 16px; padding: 20px; }
.dialog h2 { font-size: 17px; font-weight: 650; }
.dialog p { color: var(--text-2); }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(440px, 100%); display: grid; gap: 14px; padding: 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.login-card h1 { font-size: 20px; font-weight: 650; margin-top: 8px; }
.login-card p { color: var(--text-2); }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr); }
  .send { grid-column: 2; position: static; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat-total { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .me span, #logout span { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px; gap: 12px; }
  .rail { position: static; }
  .rail-title { display: none; }
  .streamer-list { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 4px; scroll-snap-type: x proximity; }
  .streamer-list li { flex: none; scroll-snap-align: start; }
  .streamer { grid-template-columns: 32px auto; padding: 6px 10px 6px 6px; background: var(--surface); border: 1px solid var(--line); }
  .streamer-avatar, .streamer-avatar img, .streamer-avatar .all-mark { width: 32px; height: 32px; }
  .streamer-meta { max-width: 140px; }
  /* Send panel right under the preview on phones: it is the main action. */
  .center { display: contents; }
  .preview-panel { order: 1; }
  .send { grid-column: auto; order: 2; }
  .controls { order: 3; }
  .lower { order: 4; }
  .controls .btn span { font-size: 13px; }
  .controls .btn-panic { margin-left: 0; flex: 1 1 100%; }
  .settings-grid, .field-row, .stats { grid-template-columns: 1fr; }
  .entry { grid-template-columns: 56px minmax(0, 1fr); }
  .entry .btn { grid-column: 1 / -1; justify-self: stretch; }
  .thumb { width: 56px; height: 40px; }
  .btn { min-height: 40px; }
  .quickbar .btn-icon { width: 40px; }
}

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