:root {
  --ink: #15120f;
  --ink-2: #1d1915;
  --ink-3: #27221c;
  --line: #3a3229;
  --line-soft: #2e2821;
  --parch: #ece3d0;
  --parch-dim: #b8ac95;
  --muted: #8a7f6c;
  --gold: #d1a95b;
  --gold-soft: rgba(209, 169, 91, 0.14);
  --ember: #c4553b;
  --ember-soft: rgba(196, 85, 59, 0.16);
  --moss: #7d9a6a;
  --radius: 10px;
  --serif: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --bar-h: 76px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ink);
  color: var(--parch);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: 0.01em; margin: 0; }
h1 { font-size: 30px; }
h2 { font-size: 24px; }
h3 { font-size: 19px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; height: 100vh; padding-bottom: var(--bar-h); }
.sidebar {
  background: var(--ink-2);
  border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column; padding: 22px 14px; gap: 4px;
}
.brand { font-family: var(--serif); font-size: 26px; color: var(--gold); padding: 0 10px 18px; line-height: 1.1; }
.brand small { display: block; font-family: var(--sans); font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; color: var(--parch-dim); font: inherit; text-align: left;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
}
.nav-btn svg { width: 18px; height: 18px; flex: none; opacity: 0.8; }
.nav-btn:hover { background: var(--ink-3); color: var(--parch); }
.nav-btn.active { background: var(--gold-soft); color: var(--gold); }
.sidebar .spacer { flex: 1; }
.live-pill { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 8px 12px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.live-dot.on { background: var(--moss); box-shadow: 0 0 0 3px rgba(125, 154, 106, 0.2); }

main { overflow-y: auto; padding: 28px 34px 40px; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.view-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--ink-3); color: var(--parch); border: 1px solid var(--line);
  font: 500 14px var(--sans); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--parch-dim); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--gold); color: #1b150c; border-color: var(--gold); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ember { background: var(--ember-soft); color: #f0a08b; border-color: rgba(196, 85, 59, 0.5); }
.btn.ghost { background: none; border-color: transparent; color: var(--parch-dim); }
.btn.ghost:hover { color: var(--parch); background: var(--ink-3); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 7px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

input, textarea, select {
  width: 100%; background: var(--ink); color: var(--parch); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; font: inherit;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--gold); }
label { display: block; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 14px 0 6px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
input[type=range] { padding: 0; accent-color: var(--gold); border: 0; background: none; }
.search { max-width: 280px; }

/* ---------- Cards ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.card {
  background: var(--ink-2); border: 1px solid var(--line-soft); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: var(--line); }
.card-body { padding: 14px 16px; flex: 1; }
.card-foot { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line-soft); }
.card h3 { margin-bottom: 4px; }
.thumb { aspect-ratio: 4 / 3; background: var(--ink-3) center / cover no-repeat; display: grid; place-items: center; color: var(--muted); font-family: var(--serif); font-size: 40px; }
.portrait { aspect-ratio: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chip {
  font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--ink-3); color: var(--parch-dim);
  border: 1px solid var(--line-soft); cursor: default; white-space: nowrap;
}
.chip.gold { background: var(--gold-soft); color: var(--gold); border-color: rgba(209, 169, 91, 0.3); }
button.chip { cursor: pointer; font-family: inherit; }
button.chip:hover { border-color: var(--gold); color: var(--gold); }
button.chip.on { background: var(--gold); color: #1b150c; border-color: var(--gold); }
.empty { border: 1px dashed var(--line); border-radius: var(--radius); padding: 40px 20px; text-align: center; color: var(--muted); }
.empty h3 { color: var(--parch-dim); margin-bottom: 6px; }

/* ---------- Table (musique) ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:hover td { background: var(--ink-2); }
.table .title-cell { font-weight: 500; }
.table input.inline { background: transparent; border-color: transparent; padding: 5px 7px; }
.table input.inline:hover { border-color: var(--line); }
.kind { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding: 2px 7px; border-radius: 4px; }
.kind.musique { background: var(--gold-soft); color: var(--gold); }
.kind.ambiance { background: rgba(125, 154, 106, 0.16); color: #a9c398; }

/* ---------- Panels ---------- */
.panel { background: var(--ink-2); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 18px 20px; }
.panel + .panel { margin-top: 16px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font: 500 14px var(--sans); padding: 9px 14px; cursor: pointer; margin-bottom: -1px; }
.tab.active { color: var(--gold); border-color: var(--gold); }

/* ---------- Mode Jouer ---------- */
.play-layout { display: grid; grid-template-columns: 290px 1fr; gap: 20px; align-items: start; }
.scene-list { display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; }
.scene-item {
  text-align: left; background: var(--ink-2); border: 1px solid var(--line-soft); color: var(--parch);
  border-radius: 8px; padding: 10px 12px; cursor: pointer; font: inherit; display: flex; gap: 10px; align-items: baseline;
}
.scene-item .num { font-family: var(--serif); color: var(--muted); font-size: 18px; min-width: 18px; }
.scene-item:hover { border-color: var(--line); }
.scene-item.active { border-color: var(--gold); background: var(--gold-soft); }
.scene-item.playing .num { color: var(--ember); }
.read-aloud {
  font-family: var(--serif); font-size: 21px; line-height: 1.45; font-style: italic; color: #f3ead6;
  border-left: 3px solid var(--gold); padding: 4px 0 4px 18px; margin: 14px 0 6px; white-space: pre-wrap;
}
.notes { white-space: pre-wrap; color: var(--parch-dim); }
.scene-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; }
.mini-list { display: flex; flex-direction: column; gap: 6px; }
.mini {
  display: flex; align-items: center; gap: 10px; background: var(--ink); border: 1px solid var(--line-soft);
  border-radius: 8px; padding: 7px 9px;
}
.mini .avatar { width: 36px; height: 36px; border-radius: 6px; background: var(--ink-3) center / cover; flex: none; display: grid; place-items: center; font-family: var(--serif); color: var(--muted); }
.mini .grow { flex: 1; min-width: 0; }
.mini .grow div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score { font-size: 11px; color: var(--muted); }
.quick-desc { display: flex; gap: 8px; }
.quick-desc textarea { min-height: 46px; }

/* ---------- Barre audio ---------- */
.audio-bar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--bar-h);
  background: #0f0d0b; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 20px; align-items: center; padding: 0 22px; z-index: 20;
}
.deck { display: flex; align-items: center; gap: 12px; min-width: 0; }
.deck-label { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.deck-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.deck-info { min-width: 0; flex: 1; }
.deck input[type=range] { width: 90px; flex: none; }
.progress { height: 3px; background: var(--line-soft); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--gold); }
.deck.ambience .progress div { background: var(--moss); }
.output-toggle { display: flex; align-items: center; gap: 10px; }
.seg { display: inline-flex; background: var(--ink-3); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { background: none; border: 0; color: var(--muted); font: 500 12px var(--sans); padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.seg button.on { background: var(--gold); color: #1b150c; }

/* ---------- Modale ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(5, 4, 3, 0.72); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--ink-2); border: 1px solid var(--line); border-radius: 14px; width: min(720px, 100%); max-height: 90vh; overflow-y: auto; padding: 24px 26px; }
.modal.wide { width: min(980px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-bottom: 6px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 20px; bottom: calc(var(--bar-h) + 16px); display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink-3); border: 1px solid var(--line); border-left: 3px solid var(--gold); padding: 10px 14px; border-radius: 8px; max-width: 360px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); }
.toast.err { border-left-color: var(--ember); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(ellipse at top, #2a2219 0%, var(--ink) 60%); }
.login-card { width: min(380px, 100%); background: var(--ink-2); border: 1px solid var(--line); border-radius: 14px; padding: 32px 30px; text-align: center; }
.login-card .brand { padding: 0 0 20px; font-size: 34px; }

/* ---------- Responsive (iPad portrait, téléphones) ---------- */
@media (max-width: 900px) {
  :root { --bar-h: 158px; }
  .output-toggle { padding-bottom: env(safe-area-inset-bottom); }
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; overflow-x: auto; padding: 10px; gap: 2px; border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .brand, .sidebar .spacer, .live-pill { display: none; }
  .nav-btn { width: auto; padding: 8px 10px; }
  main { padding: 20px 16px 30px; }
  .play-layout { grid-template-columns: 1fr; }
  .scene-list { position: static; }
  .audio-bar { grid-template-columns: 1fr; gap: 6px; padding: 8px 16px; }
}
