/* ─────────────────────────────────────────────────────────────────────────── */
/* TypeMotion — Anime.js Text Animation Studio                                  */
/* Aesthetic : Warm editorial / motion design studio — cream + charcoal         */
/* ─────────────────────────────────────────────────────────────────────────── */

:root {
  /* Palette */
  --bg:         #f5f0e8;
  --surface:    #faf8f4;
  --surface2:   #ede8df;
  --border:     #d6cfc3;
  --border2:    #c2bab0;
  --dark:       #1a1714;
  --dark2:      #2c2825;
  --text:       #1a1714;
  --text-dim:   #706860;
  --text-faint: #a89f94;
  --accent:     #e05a2b;      /* burnt orange */
  --accent-h:   #c94e23;
  --accent2:    #2563eb;      /* electric blue */
  --green:      #22c55e;

  /* Stage */
  --stage-bg:   #111010;

  /* Typography */
  --font-ui:    'DM Sans', system-ui, sans-serif;
  --font-disp:  'Fraunces', Georgia, serif;
  --font-mono:  'Fira Code', monospace;

  /* Misc */
  --radius:     8px;
  --radius-sm:  5px;
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg:  0 8px 40px rgba(0,0,0,.18);
  --tr:         0.15s cubic-bezier(.4,0,.2,1);

  /* Layout */
  --header-h:   52px;
  --sidebar-w:  200px;
  --config-w:   300px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── SCROLLBAR ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── HEADER ──────────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.2rem;
  flex-shrink: 0;
  gap: 1rem;
  z-index: 50;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-disp);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--dark);
  white-space: nowrap;
}
.logo-icon { color: var(--accent); font-size: 1.2rem; }
.app-logo em { font-style: italic; color: var(--accent); font-weight: 300; }

/* Contrôle nombre d'items */
.item-count-ctrl {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.25rem 0.8rem;
}
.item-count-ctrl label {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-weight: 500;
  white-space: nowrap;
}
.btn-count {
  width: 24px; height: 24px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--dark);
  transition: var(--tr);
  font-family: var(--font-ui);
}
.btn-count:hover { background: var(--dark); color: var(--surface); border-color: var(--dark); }
.count-display {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 500;
  min-width: 20px;
  text-align: center;
}

/* Boutons header */
.btn-header {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--dark);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  transition: var(--tr);
  white-space: nowrap;
}
.btn-header:hover { background: var(--dark); color: #fff; border-color: var(--dark); }
.btn-header.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-header.btn-accent:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn-icon { font-size: 0.9rem; }
.header-right { display: flex; align-items: center; gap: 0.5rem; }

/* ── WORKSPACE ───────────────────────────────────────────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--config-w);
  flex: 1;
  overflow: hidden;
}

/* ── SIDEBAR ─────────────────────────────────────────────────────────────── */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar-inner { padding: 0.6rem; display: flex; flex-direction: column; gap: 0.3rem; }
.sidebar-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  padding: 0.4rem 0.4rem 0.2rem;
}

.item-chip {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 0.5rem 0.6rem;
  cursor: pointer;
  transition: var(--tr);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.item-chip:hover { border-color: var(--accent); }
.item-chip.selected {
  border-color: var(--accent);
  background: #fdf3ee;
  box-shadow: inset 3px 0 0 var(--accent);
}
.chip-num {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-faint);
  flex-shrink: 0;
}
.chip-preview {
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.chip-badge {
  font-size: 0.6rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 0.4rem;
  color: var(--text-faint);
  flex-shrink: 0;
}
.chip-badge.loop { background: #dcfce7; border-color: #86efac; color: #15803d; }

/* ── STAGE ───────────────────────────────────────────────────────────────── */
.stage-wrapper {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.stage {
  flex: 1;
  background: var(--stage-bg);
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
  padding: 3rem 2rem;
  position: relative;
  /* Subtle grid pattern */
  background-image: radial-gradient(circle at 1px 1px, rgba(255,255,255,0.04) 1px, transparent 0);
  background-size: 24px 24px;
  transition: background-color 0.4s ease;
}
.stage.bg-light { background-color: #f0ece4; background-image: radial-gradient(circle at 1px 1px, rgba(0,0,0,0.05) 1px, transparent 0); }

.stage-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  color: rgba(255,255,255,0.12);
  text-align: center;
  font-family: var(--font-disp);
  pointer-events: none;
}
.stage-empty-icon { font-size: 2.5rem; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.stage-empty p { font-size: 0.88rem; line-height: 1.7; font-style: italic; }
.stage.has-items .stage-empty { display: none; }

/* Bloc de texte animé dans la scène */
.text-block {
  position: relative;
  cursor: pointer;
  outline: 2px solid transparent;
  border-radius: 4px;
  transition: outline-color 0.15s;
  padding: 0.5rem;
}
.text-block:hover { outline-color: rgba(224,90,43,0.3); }
.text-block.selected { outline-color: var(--accent); }

/* Indicateur "selected" */
.text-block.selected::before {
  content: '';
  position: absolute;
  left: -12px; top: 50%;
  transform: translateY(-50%);
  width: 4px; height: 60%;
  background: var(--accent);
  border-radius: 2px;
}

/* Chaque ligne de texte */
.text-line {
  display: block;
  white-space: nowrap;
}

/* Unités de split pour anime.js */
.char, .word, .line-anim {
  display: inline-block;
  will-change: transform, opacity;
}
.space { display: inline-block; width: 0.3em; }

/* ── STAGE TOOLBAR ───────────────────────────────────────────────────────── */
.stage-toolbar {
  height: 40px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  flex-shrink: 0;
}
.btn-tool {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  transition: var(--tr);
}
.btn-tool:hover { border-color: var(--dark); color: var(--dark); background: var(--surface2); }
.btn-tool.btn-save { margin-left: auto; background: var(--dark); color: #fff; border-color: var(--dark); }
.btn-tool.btn-save:hover { background: var(--dark2); }

/* ── CONFIG PANEL ────────────────────────────────────────────────────────── */
.config-panel {
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.no-selection {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 0.8rem;
  color: var(--text-faint);
  font-family: var(--font-disp);
  font-style: italic;
  text-align: center;
  padding: 2rem;
}
.no-sel-icon { font-size: 2rem; }
.no-selection p { font-size: 0.85rem; line-height: 1.7; }

.config-inner { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

/* Tabs */
.cfg-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.cfg-tab {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-dim);
  padding: 0.65rem 0.3rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--tr);
}
.cfg-tab:hover { color: var(--dark); }
.cfg-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* Tab bodies */
.cfg-body {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem;
  flex-direction: column;
  gap: 0.75rem;
}
.cfg-body.active { display: flex; }

/* Fields */
.cfg-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.cfg-field > label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.field-val { font-weight: 400; color: var(--accent); font-family: var(--font-mono); }
.field-hint { font-size: 0.62rem; color: var(--text-faint); font-style: italic; }

.cfg-field textarea,
.cfg-field input[type="text"],
.cfg-field select,
.cfg-field .hex-input {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  padding: 0.45rem 0.6rem;
  outline: none;
  transition: var(--tr);
  width: 100%;
  resize: vertical;
}
.cfg-field textarea:focus,
.cfg-field input:focus,
.cfg-field select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(224,90,43,0.12); }

.cfg-field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
}

.cfg-field input[type="color"] {
  width: 36px; height: 32px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 2px;
  cursor: pointer;
  background: var(--bg);
}

.hex-input {
  font-family: var(--font-mono) !important;
  font-size: 0.78rem !important;
  width: auto !important;
  flex: 1;
}

.color-row { display: flex; align-items: center; gap: 0.4rem; }

/* Toggle switch */
.toggle-switch { display: inline-flex; align-items: center; cursor: pointer; }
.toggle-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  width: 36px; height: 20px;
  background: var(--border2);
  border-radius: 10px;
  position: relative;
  transition: var(--tr);
}
.toggle-track::after {
  content: '';
  position: absolute;
  left: 2px; top: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: var(--tr);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-track { background: var(--accent); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(16px); }

/* Bouton group (alignement) */
.btn-group { display: flex; gap: 0.3rem; }
.btn-align {
  flex: 1;
  border: 1px solid var(--border2);
  background: var(--bg);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.9rem;
  padding: 0.35rem;
  cursor: pointer;
  transition: var(--tr);
}
.btn-align.active,
.btn-align:hover { background: var(--dark); color: #fff; border-color: var(--dark); }

/* Preset grid */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.preset-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 0.55rem 0.5rem;
  cursor: pointer;
  transition: var(--tr);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}
.preset-card:hover { border-color: var(--accent); background: #fdf3ee; }
.preset-card.active { border-color: var(--accent); background: #fdf3ee; box-shadow: inset 0 0 0 1px var(--accent); }
.preset-card.loop-type { }
.preset-icon { font-size: 1.2rem; line-height: 1; }
.preset-label { font-size: 0.65rem; font-weight: 600; color: var(--text-dim); line-height: 1.2; }
.preset-category {
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.preset-card.active .preset-label { color: var(--accent); }

/* Section header dans preset grid */
.preset-section-title {
  grid-column: span 2;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  padding: 0.4rem 0 0.1rem;
  border-bottom: 1px solid var(--border);
  margin-top: 0.3rem;
}

/* Boutons du bas de config */
.cfg-play-row {
  display: flex;
  gap: 0.4rem;
  padding: 0.7rem 0.8rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.btn-play-item {
  flex: 1;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.6rem;
  cursor: pointer;
  transition: var(--tr);
}
.btn-play-item:hover { background: var(--accent-h); transform: translateY(-1px); }
.btn-duplicate {
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  transition: var(--tr);
}
.btn-duplicate:hover { border-color: var(--dark); color: var(--dark); }

/* ── MODALS ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(26,23,20,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: 85vh;
  transform: scale(0.96) translateY(8px);
  transition: transform 0.2s ease;
}
.modal-overlay.open .modal-box { transform: scale(1) translateY(0); }

.code-modal-box { width: min(900px, 92vw); }
.saves-modal-box { width: min(520px, 92vw); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-family: var(--font-mono); font-size: 0.82rem; font-weight: 500; }
.modal-actions { display: flex; align-items: center; gap: 0.4rem; }
.btn-modal-action, .btn-modal-close {
  border: 1px solid var(--border2);
  background: var(--bg);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  transition: var(--tr);
}
.btn-modal-action:hover { border-color: var(--dark); color: var(--dark); }
.btn-modal-close { padding: 0.3rem 0.55rem; }
.btn-modal-close:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Code viewer */
.code-preview {
  flex: 1;
  overflow: auto;
  background: #0f1117;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 1.2rem 1.5rem;
  margin: 0;
}
code#code-content {
  font-family: var(--font-mono);
  font-size: 0.73rem;
  line-height: 1.7;
  color: #a8b4c8;
  white-space: pre;
  display: block;
}

/* Saves modal */
.modal-body { padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: 1rem; overflow-y: auto; }
.save-form { display: flex; gap: 0.5rem; }
.save-form input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  padding: 0.5rem 0.8rem;
  outline: none;
}
.save-form input:focus { border-color: var(--accent); }

.saves-list { display: flex; flex-direction: column; gap: 0.4rem; max-height: 50vh; overflow-y: auto; }
.saves-loading { color: var(--text-faint); font-size: 0.8rem; text-align: center; padding: 1.5rem; font-style: italic; }
.save-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  transition: var(--tr);
}
.save-row:hover { border-color: var(--accent); }
.save-info { flex: 1; overflow: hidden; }
.save-name { font-size: 0.85rem; font-weight: 500; color: var(--dark); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-meta { font-size: 0.65rem; color: var(--text-faint); font-family: var(--font-mono); }
.btn-load-save, .btn-del-save {
  border: 1px solid var(--border2);
  background: var(--surface);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.72rem;
  font-family: var(--font-ui);
  padding: 0.28rem 0.6rem;
  cursor: pointer;
  transition: var(--tr);
  white-space: nowrap;
}
.btn-load-save:hover { background: var(--dark); color: #fff; border-color: var(--dark); }
.btn-del-save { color: #dc2626; border-color: #fecaca; }
.btn-del-save:hover { background: #dc2626; color: #fff; border-color: #dc2626; }

/* ── UNDERLINE OPTIONS ───────────────────────────────────────────────────── */

.cfg-separator {
  height: 1px;
  background: var(--border);
  margin: 0.3rem 0 0.6rem;
}

.underline-options {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  padding-left: 0.3rem;
  border-left: 2px solid var(--border);
  margin-left: 0.1rem;
}
.underline-options.visible { display: flex; }

/* Style picker — 5 boutons picto */
.ul-style-picker {
  display: flex;
  gap: 0.3rem;
}
.ul-style-btn {
  flex: 1;
  border: 1px solid var(--border2);
  background: var(--bg);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  padding: 0.35rem 0.2rem;
  cursor: pointer;
  transition: var(--tr);
  text-align: center;
}
.ul-style-btn:hover { border-color: var(--accent); color: var(--accent); }
.ul-style-btn.active {
  background: var(--dark);
  color: var(--accent);
  border-color: var(--dark);
}

/* La barre de soulignement dans la scène
   Positionnée en absolu sous le bloc texte.
   Toutes les propriétés visuelles sont pilotées
   par des variables CSS inline (--ul-*) injectées par JS. */
.uline-bar {
  position: absolute;
  left: 0;
  width: 100%;
  will-change: transform, opacity, width;
  pointer-events: none;
  /* Les variables par défaut (écrasées en inline style par JS) */
  height:           var(--ul-thick, 3px);
  bottom:           calc(-1 * var(--ul-offset, 6px));
  background-color: var(--ul-color, currentColor);
  border-radius:    var(--ul-radius, 2px);
}
/* Styles spéciaux via border-bottom (la height passe à 0) */
.uline-bar.ul-dashed {
  background: none;
  height: 0;
  border-bottom: var(--ul-thick, 3px) dashed var(--ul-color, currentColor);
  border-radius: 0;
}
.uline-bar.ul-dotted {
  background: none;
  height: 0;
  border-bottom: var(--ul-thick, 3px) dotted var(--ul-color, currentColor);
  border-radius: 0;
}
.uline-bar.ul-double {
  background: none;
  height: 0;
  border-bottom: var(--ul-thick, 3px) double var(--ul-color, currentColor);
  border-radius: 0;
}
/* Ondulée : SVG inline encodé en data URI, scale vertical selon épaisseur */
.uline-bar.ul-wavy {
  background: none;
  background-image: var(--ul-wave-svg);
  background-repeat: repeat-x;
  background-position: 0 center;
  background-size: 20px var(--ul-thick, 3px);
  height: calc(var(--ul-thick, 3px) * 2.5);
  border-radius: 0;
}

/* Bloc de texte en position relative pour accueillir la barre en absolu */
.text-block { position: relative; }

/* ── PREVIEW MODE ────────────────────────────────────────────────────────── */

/* Bouton Aperçu — état actif */
.btn-preview-mode.active {
  background: var(--dark);
  color: var(--accent);
  border-color: var(--dark);
}

/* Bouton Record — caché par défaut, visible seulement en preview mode */
.btn-record {
  display: none;
  gap: 0.45rem;
  color: #dc2626;
  border-color: #fecaca;
  background: #fff5f5;
}
.btn-record:hover { background: #dc2626 !important; color: #fff !important; border-color: #dc2626 !important; }
.btn-record.recording {
  background: #dc2626 !important;
  color: #fff !important;
  border-color: #dc2626 !important;
  animation: rec-btn-pulse 1.2s ease-in-out infinite;
}
@keyframes rec-btn-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(220,38,38,0); }
}

body.preview-mode .btn-record { display: inline-flex; }

/* Point rouge animé */
.rec-dot {
  width: 8px; height: 8px;
  background: currentColor;
  border-radius: 50%;
  flex-shrink: 0;
}
.btn-record.recording .rec-dot { animation: blink 0.8s step-start infinite; }
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0; } }

/* En mode aperçu : on cache la sidebar, le config panel et la toolbar */
body.preview-mode .sidebar,
body.preview-mode .config-panel,
body.preview-mode .stage-toolbar { display: none; }

/* La scène occupe toute la largeur */
body.preview-mode .workspace {
  grid-template-columns: 1fr;
}

/* Header réduit : on masque les contrôles d'édition */
body.preview-mode .item-count-ctrl,
body.preview-mode #btn-toggle-bg,
body.preview-mode #btn-open-saves { display: none; }

/* Supprime TOUT indicateur de sélection sur les blocs */
body.preview-mode .text-block {
  outline: none !important;
  cursor: default !important;
  pointer-events: none;
}
body.preview-mode .text-block::before { display: none !important; }
body.preview-mode .text-block:hover  { outline: none !important; }

/* ── RECORDING OVERLAY ───────────────────────────────────────────────────── */
#record-overlay {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: rgba(15, 10, 10, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(220,38,38,0.4);
  border-radius: 12px;
  padding: 1rem 1.4rem;
  display: none;           /* caché par défaut */
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  min-width: 320px;
  box-shadow: 0 8px 40px rgba(220,38,38,0.25);
}
#record-overlay.visible { display: flex; }

.rec-indicator {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.rec-pulse {
  width: 12px; height: 12px;
  background: #dc2626;
  border-radius: 50%;
  animation: rec-pulse-anim 0.8s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes rec-pulse-anim {
  0%,100% { transform: scale(1); opacity: 1; }
  50%     { transform: scale(1.4); opacity: 0.6; }
}

.rec-label {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: #dc2626;
  letter-spacing: 0.12em;
}

.rec-status {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: #fff;
  min-width: 140px;
  text-align: center;
}

.rec-info {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  color: rgba(255,255,255,0.4);
  text-align: center;
  line-height: 1.5;
}

.rec-stop-btn {
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.5rem 1.4rem;
  cursor: pointer;
  transition: var(--tr);
  letter-spacing: 0.04em;
}
.rec-stop-btn:hover { background: #b91c1c; transform: scale(1.02); }

/* ── STAGE BACKGROUND IMAGE overlay ─────────────────────────────────────── */

/* L'overlay est inséré par JS comme premier enfant de #stage */
.stage-bg-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  /* backgroundImage / size / pos / opacity injectés via JS inline style */
}

/* Tous les blocs texte doivent passer au-dessus */
.text-block {
  position: relative;
  z-index: 1;
}

/* Bouton Image dans le header */
#btn-bgimg {
  gap: 0.4rem;
}
#btn-bgimg.has-image {
  color: var(--accent);
  border-color: var(--accent);
}

/* ── MODAL FOND — structure générale ─────────────────────────────────────── */

.bgimg-modal-box {
  width: min(520px, 94vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.bgimg-modal-box .modal-body {
  overflow-y: auto;
  flex: 1;
  padding: 0;
}

/* Sections internes */
.modal-section {
  padding: 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.modal-section-title {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}
.modal-divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}

/* ── APERÇU FOND ─────────────────────────────────────────────────────────── */
#stage-bg-preview-strip {
  height: 52px;
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  background: #111010;
  transition: background 0.3s ease;
  position: relative;
  overflow: hidden;
}
#stage-bg-preview-strip::after {
  content: 'Aperçu';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.25);
  pointer-events: none;
}

/* ── BOUTONS DE MODE (Uni / Linéaire / Radial) ───────────────────────────── */
.bg-mode-group {
  display: flex;
  gap: 0;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.bg-mode-btn {
  flex: 1;
  border: none;
  background: var(--bg);
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  transition: var(--tr);
  border-right: 1px solid var(--border2);
}
.bg-mode-btn:last-child { border-right: none; }
.bg-mode-btn:hover:not(.active) { background: var(--surface2); color: var(--text); }
.bg-mode-btn.active {
  background: var(--dark);
  color: #fff;
  font-weight: 600;
}

/* ── GRILLE DE PRESETS ───────────────────────────────────────────────────── */
.bg-presets-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.35rem;
  margin-top: 0.2rem;
}
.bg-preset-swatch {
  aspect-ratio: 1.4;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  transition: var(--tr);
  position: relative;
  overflow: hidden;
}
.bg-preset-swatch:hover {
  border-color: var(--accent);
  transform: scale(1.08);
  z-index: 1;
}
.bg-preset-swatch::after {
  content: attr(title);
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.48rem;
  font-family: var(--font-ui);
  text-align: center;
  padding: 0.12rem 0;
  opacity: 0;
  transition: opacity 0.15s;
  line-height: 1.4;
}
.bg-preset-swatch:hover::after { opacity: 1; }

.bgimg-options {
  display: none;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.1rem;
}
.bgimg-options.visible { display: flex; }

/* Onglets URL / Upload */
.bgimg-tabs {
  display: flex;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.bgimg-tab {
  flex: 1;
  border: none;
  background: var(--bg);
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  transition: var(--tr);
}
.bgimg-tab.active {
  background: var(--dark);
  color: #fff;
}
.bgimg-tab:hover:not(.active) { background: var(--surface2); }

/* Panneaux URL / Upload */
.bgimg-panel { display: none; }
.bgimg-panel.active { display: flex; flex-direction: column; gap: 0.5rem; }

/* Bouton appliquer URL */
.btn-bgimg-apply {
  width: 30px; height: 30px;
  background: var(--dark);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: var(--tr);
}
.btn-bgimg-apply:hover { background: var(--accent); }

/* ── DROPZONE ────────────────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border2);
  border-radius: var(--radius);
  padding: 1.2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: var(--tr);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg);
}
.drop-zone:hover,
.drop-zone:focus,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: #fdf3ee;
  outline: none;
}
.drop-zone-icon {
  font-size: 1.6rem;
  color: var(--text-faint);
  line-height: 1;
  transition: var(--tr);
}
.drop-zone:hover .drop-zone-icon,
.drop-zone.drag-over .drop-zone-icon { color: var(--accent); transform: translateY(-2px); }
.drop-zone-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.5;
}
.drop-zone-label span { font-size: 0.7rem; color: var(--accent); text-decoration: underline; }
.drop-zone-hint {
  font-size: 0.6rem;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

/* Barre de progression */
.upload-progress {
  display: none;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 22px;
  position: relative;
}
.upload-progress.visible { display: flex; }
.upload-progress-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
  border-radius: var(--radius-sm);
  opacity: 0.3;
}
.upload-progress-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  position: relative;
  z-index: 1;
  padding: 0 0.6rem;
}

/* Prévisualisation miniature */
.bgimg-preview-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
}
.bgimg-thumb {
  width: 44px; height: 32px;
  border-radius: 3px;
  background: var(--border2) center/cover no-repeat;
  flex-shrink: 0;
  border: 1px solid var(--border2);
}
.bgimg-preview-info { flex: 1; overflow: hidden; display: flex; flex-direction: column; gap: 0.2rem; }
.bgimg-preview-src {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}
.btn-bgimg-clear {
  border: 1px solid #fecaca;
  background: transparent;
  color: #dc2626;
  border-radius: var(--radius-sm);
  font-size: 0.62rem;
  font-family: var(--font-ui);
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  transition: var(--tr);
  white-space: nowrap;
}
.btn-bgimg-clear:hover { background: #dc2626; color: #fff; border-color: #dc2626; }

/* Grille de position 3×3 */
.bgimg-pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
}
.pos-btn {
  aspect-ratio: 1;
  border: 1px solid var(--border2);
  background: var(--bg);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--tr);
  display: flex; align-items: center; justify-content: center;
  height: 28px;
}
.pos-btn:hover  { border-color: var(--accent); color: var(--accent); }
.pos-btn.active { background: var(--dark); color: #fff; border-color: var(--dark); }

/* ── TOAST ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  pointer-events: none;
}
.toast {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.5rem 1.2rem;
  border-radius: 20px;
  background: var(--dark);
  color: #fff;
  animation: toastIn 0.25s ease forwards;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}
.toast.success { background: #15803d; }
.toast.error   { background: #dc2626; }
.toast.info    { background: var(--accent2); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
