:root {
  --bg: #0a0d13;
  --surface: #10151e;
  --card: #151b26;
  --card-2: #1b2230;
  --line: #242d3e;
  --line-2: #313c51;
  --text: #e9edf4;
  --muted: #8a94a7;
  --accent: #ff6b1f;
  --accent-hover: #ff8540;
  --accent-soft: rgba(255, 107, 31, 0.14);
  --ok: #2bd17e;
  --ok-soft: rgba(43, 209, 126, 0.14);
  --warn: #f5a524;
  --warn-soft: rgba(245, 165, 36, 0.14);
  --danger: #ff5d5d;
  --radius: 14px;
  --radius-sm: 10px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
code { font-size: 0.92em; background: rgba(255, 255, 255, 0.06); padding: 1px 5px; border-radius: 5px; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: rgba(16, 21, 30, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #d0331a);
  color: #fff;
  font: italic 16px/1 Anton, Impact, sans-serif;
  letter-spacing: 0.04em;
}
.brand h1 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 12.5px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.lang-select { width: auto; padding-top: 7px; padding-bottom: 7px; font-weight: 600; }

.seg {
  display: inline-flex;
  padding: 3px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 6px 16px;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button[aria-selected="true"] {
  background: var(--card-2);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ---------- Mise en page ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 24px;
  padding: 24px;
  align-items: start;
  max-width: 1720px;
  margin: 0 auto;
}
.stage-col { position: sticky; top: 87px; min-width: 0; }

.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000;
  box-shadow: 0 0 0 1px var(--line), 0 24px 60px rgba(0, 0, 0, 0.5);
}
.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
}
.stage canvas.is-dragging { cursor: grabbing !important; }

.drop-hint {
  position: absolute;
  inset: 0;
  display: none;
  grid-template-columns: 1fr 1fr;
  pointer-events: none;
}
.stage.is-dropping .drop-hint { display: grid; }
.drop-hint > div {
  display: grid;
  place-items: center;
  margin: 12px;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  border-radius: var(--radius-sm);
  background: rgba(5, 8, 14, 0.55);
  color: rgba(255, 255, 255, 0.7);
  text-align: center;
  transition: background 0.12s, border-color 0.12s;
}
.drop-hint > div.is-active { border-color: var(--accent); background: rgba(255, 107, 31, 0.25); color: #fff; }
.drop-hint strong { display: block; font-size: 22px; margin-top: 4px; color: #fff; }

.stage-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12.5px;
}
#statusText strong { color: var(--text); font-weight: 600; }
#statusText .num { font-variant-numeric: tabular-nums; }
kbd {
  font: 600 11px/1 var(--font);
  padding: 3px 6px;
  border-radius: 5px;
  background: var(--card-2);
  border: 1px solid var(--line-2);
  color: var(--text);
}

/* ---------- Panneau latéral ---------- */
.panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card {
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 700;
}
.step {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.note { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.note.warn { color: var(--warn); }
.note:empty { display: none; }

/* Fond */
.template-row { display: flex; align-items: center; gap: 12px; }
.template-thumb {
  flex: none;
  width: 112px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: linear-gradient(115deg, #13235c 0 49%, #6b1222 51% 100%);
}
.template-thumb.is-football { background: linear-gradient(115deg, #0d4a32 0 49%, #0a2e4d 51% 100%); }
.template-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.template-thumb img:not([src]), .template-thumb img[src=""] { display: none; }
.template-info { min-width: 0; }
.template-info strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-info .note { margin-top: 2px; }

/* Équipes */
.team {
  padding: 12px;
  margin-bottom: 10px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.team.is-selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.team.is-locked { border-color: rgba(43, 209, 126, 0.45); }
.team-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.team-label { font-weight: 700; }
.team-label em { margin-left: 6px; font-style: normal; font-weight: 500; color: var(--muted); }

.badge {
  padding: 3px 9px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }

.club-select { margin-bottom: 8px; }
.club-select:disabled { opacity: 0.6; cursor: not-allowed; }

.drop {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 10px;
  border: 1.5px dashed var(--line-2);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.drop img {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 3px;
  object-fit: contain;
  border-radius: 6px;
  background: repeating-conic-gradient(#2a3242 0 25%, #20273444 0 50%) 0 0 / 10px 10px;
}
.drop span { min-width: 0; overflow-wrap: anywhere; }
.team.is-locked .drop { pointer-events: none; opacity: 0.75; }

.range {
  display: grid;
  grid-template-columns: auto 1fr 46px;
  align-items: center;
  gap: 10px;
  margin: 12px 0 2px;
  color: var(--muted);
  font-size: 12.5px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="range"]:disabled { opacity: 0.4; }
output { text-align: right; font-size: 12.5px; color: var(--text); font-variant-numeric: tabular-nums; }

.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.row-btns:empty { display: none; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Boutons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--card-2);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: #242c3d; border-color: #3d4964; }
.btn:focus-visible, .seg button:focus-visible, .select:focus-visible, .field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.small { padding: 6px 11px; font-size: 12.5px; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; padding: 12px; font-size: 15px; }

/* Champs */
.select {
  width: 100%;
  appearance: none;
  padding: 9px 34px 9px 12px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--card-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%238a94a7' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  cursor: pointer;
}
.field { display: grid; gap: 6px; color: var(--muted); font-size: 12.5px; }
.field input[type="text"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--card-2);
}
.field input[type="file"] { font-size: 12px; color: var(--muted); }

.add-site { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.add-site summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; list-style: none; }
.add-site summary::-webkit-details-marker { display: none; }
.add-site form { display: grid; gap: 12px; margin-top: 12px; }
.add-site form .btn { justify-self: start; }
.file-pick { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; }
.dialog-sm { width: min(420px, calc(100vw - 32px)); }
.dialog-sm form { padding: 20px; }
.dialog-sm p { margin: 0 0 6px; line-height: 1.5; }
.dialog-sm .row-btns { justify-content: flex-end; margin-top: 16px; }

/* Checklist */
.checklist { display: grid; gap: 8px; margin: 0 0 14px; padding: 0; list-style: none; }
.checklist li { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.checklist li::before {
  content: "";
  flex: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--line-2);
  border-radius: 50%;
}
.checklist li.ok { color: var(--text); }
.checklist li.ok::before {
  border-color: var(--ok);
  background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='m2.5 6.2 2.3 2.3 4.7-5' fill='none' stroke='%23fff' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px no-repeat;
}
.checklist li.warn::before {
  border-color: var(--warn);
  background: var(--warn-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 3v3.6' stroke='%23f5a524' stroke-width='1.8' stroke-linecap='round'/%3E%3Ccircle cx='6' cy='9' r='1' fill='%23f5a524'/%3E%3C/svg%3E") center / 12px no-repeat;
}

/* ---------- Fenêtre d'aperçu ---------- */
.dialog {
  width: min(1040px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.dialog::backdrop { background: rgba(5, 7, 12, 0.78); backdrop-filter: blur(4px); }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.dialog-head h3 { margin: 0; font-size: 15px; }
.icon-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--card-2); color: var(--text); }
.preview-img { padding: 18px; }
.preview-img img { display: block; width: 100%; height: auto; border-radius: 10px; box-shadow: 0 0 0 1px var(--line); }
.preview-img img[src=""] { display: none; }
.preview-error {
  margin: 0;
  padding: 14px 16px;
  border-radius: 10px;
  background: rgba(255, 93, 93, 0.1);
  color: #ffb3b3;
}
.dialog-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
}
.dialog-foot .grow { flex: 1 1 260px; }
.dialog-foot .row-btns { margin: 0 0 0 auto; }
.filename {
  display: flex;
  align-items: center;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background: var(--card-2);
  overflow: hidden;
}
.filename input[type="text"] { border: 0; border-radius: 0; background: transparent; min-width: 0; }
.filename input:focus-visible { outline: none; }
.filename:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.filename em { padding: 0 12px; color: var(--muted); font-style: normal; }
.preview-meta { align-self: center; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* ---------- Notification ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: #1f2737;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 1020px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .stage-col { position: static; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 12px 16px; }
  .topbar-actions { flex-wrap: wrap; }
  .brand p { display: none; }
  .stage-bar .keys { display: none; }
}
