/* Cellulo — table lumineuse d'animateur : papier bleuté, encre indigo, jaune « cellulo ». */
@font-face { font-family: "Fredoka"; src: url("../fonts/Fredoka.ttf") format("truetype"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("../fonts/AtkinsonHyperlegible-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --paper: #e6edf4;
  --panel: #f7fafc;
  --ink: #1e2a4a;
  --ink-2: #5a6584;
  --line: #c9d4e2;
  --cel: #ffc93c;
  --leaf: #2a9d8f;
  --red: #c8423f;
  --display: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --body: system-ui, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font: 14px/1.45 var(--body); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--leaf); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- barre */
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 18px; border-bottom: 2px solid var(--ink); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 8px; font: 600 22px/1 var(--display); }
.brand svg { width: 34px; height: 34px; }
.title-input { flex: 1; min-width: 80px; font: 500 20px/1.2 var(--display); border: 0; border-bottom: 2px dashed transparent; background: transparent; padding: 4px 2px; }
.title-input:hover, .title-input:focus { border-bottom-color: var(--line); outline: none; }
.save-state { color: var(--ink-2); font-size: 12px; white-space: nowrap; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn { border: 2px solid var(--ink); border-radius: 8px; padding: 7px 13px; cursor: pointer; background: var(--panel); font-weight: 700; white-space: nowrap; text-decoration: none; display: inline-block; }
.btn.primary { background: var(--cel); box-shadow: 3px 3px 0 var(--ink); }
.btn.primary:hover { background: #ffd45e; }
.btn.primary:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { border-color: var(--line); color: var(--ink); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------------------------------------------------------- disposition */
.studio { display: grid; grid-template-columns: 300px minmax(0, 1fr) 340px; gap: 14px; padding: 14px 18px; height: calc(100% - 60px); }
.panel { background: var(--panel); border: 2px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 7px 9px; border-radius: 8px 8px 0 0; cursor: pointer; font-weight: 700; color: var(--ink-2); font-size: 13px; }
.tabs button[aria-selected="true"] { background: var(--ink); color: #fff; }
.tab-body { padding: 12px 14px 18px; overflow-y: auto; flex: 1; }
.tab-body h3 { font: 600 16px/1.2 var(--display); margin: 18px 0 8px; }
.tab-body h3:first-child { margin-top: 2px; }

/* ---------------------------------------------------------------- champs */
.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; font-size: 12px; color: var(--ink-2); }
.field input, .field select, .field textarea { color: var(--ink); font-size: 14px; background: #fff; border: 1.5px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.field textarea { resize: vertical; min-height: 60px; }
.field input[type=color] { padding: 2px; height: 34px; width: 100%; }
.field input[type=range] { padding: 0; border: 0; background: none; accent-color: var(--leaf); }
.val { color: var(--ink); font-variant-numeric: tabular-nums; float: right; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.check { display: flex; align-items: center; gap: 7px; margin: 2px 0 10px; cursor: pointer; font-size: 13px; }
.check input { accent-color: var(--leaf); width: 17px; height: 17px; }
.note { font-size: 12px; color: var(--ink-2); margin: 0 0 10px; }
.note.warn { color: #8a5a00; background: #fff4d6; padding: 8px 10px; border-radius: 8px; }
details.sect { border-top: 1.5px solid var(--line); padding-top: 4px; margin-top: 6px; }
details.sect > summary { cursor: pointer; font: 600 15px/1.2 var(--display); padding: 8px 0; list-style: none; }
details.sect > summary::before { content: "▸ "; color: var(--ink-2); }
details.sect[open] > summary::before { content: "▾ "; }
.segmented { display: flex; border: 1.5px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 10px; flex-wrap: wrap; }
.segmented button { flex: 1; border: 0; padding: 6px 4px; background: #fff; cursor: pointer; font-size: 13px; min-width: 60px; }
.segmented button + button { border-left: 1.5px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.upload { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.upload img { width: 56px; height: 42px; object-fit: cover; border-radius: 6px; border: 1.5px solid var(--line); background: #fff; }
.upload .name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--ink-2); font-size: 13px; }

/* ---------------------------------------------------------------- palette */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }
.tile { border: 1.5px solid var(--line); border-radius: 10px; background: #fff; padding: 6px 4px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; text-align: center; line-height: 1.15; min-height: 92px; }
.tile:hover { border-color: var(--ink); transform: translateY(-1px); }
.tile img { width: 58px; height: 58px; object-fit: contain; }
.tile span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lib-grid { grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); }
.lib-grid .tile { min-height: 0; padding: 5px; }
.lib-grid .tile img { width: 42px; height: 42px; }
.search { width: 100%; border: 1.5px solid var(--line); border-radius: 8px; padding: 7px 10px; margin-bottom: 8px; background: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 99px; padding: 3px 9px; font-size: 12px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.more { width: 100%; margin-top: 8px; }
.text-presets { display: flex; flex-direction: column; gap: 6px; }
.text-presets button { text-align: left; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; padding: 8px 10px; cursor: pointer; }
.text-presets button:hover { border-color: var(--ink); }
.text-presets b { font: 600 15px var(--display); display: block; }
.text-presets small { color: var(--ink-2); }

/* ---------------------------------------------------------------- scène */
.stage-col { display: flex; flex-direction: column; min-width: 0; overflow-y: auto; }
.stage-frame { background: var(--ink); border-radius: 14px; padding: 12px; display: grid; place-items: center; }
.stage { position: relative; width: 100%; max-height: 50vh; aspect-ratio: 16 / 9; background: #33406a; border-radius: 4px; overflow: hidden; cursor: grab; touch-action: none; user-select: none; }
.stage:active { cursor: grabbing; }
.stage img { width: 100%; height: 100%; object-fit: fill; display: block; pointer-events: none; }
.busy { position: absolute; right: 8px; top: 8px; background: var(--cel); color: var(--ink); font-weight: 700; font-size: 12px; padding: 2px 9px; border-radius: 99px; opacity: 0; transition: opacity .15s; }
.stage.loading .busy { opacity: 1; }
.marker { position: absolute; width: 20px; height: 20px; margin: -10px 0 0 -10px; border: 3px solid var(--cel); border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 2px var(--ink); }
.marker.to { border-style: dashed; border-color: #fff; }
.transport { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; margin: 10px 2px 0; }
.transport input { accent-color: var(--leaf); }
.transport output { font-variant-numeric: tabular-nums; min-width: 46px; text-align: right; }
.hint { margin: 4px 2px 0; font-size: 12px; color: var(--ink-2); }

.layers { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.layer { border: 1.5px solid var(--line); background: #fff; border-radius: 8px; padding: 3px 8px 3px 4px; display: flex; align-items: center; gap: 5px; cursor: pointer; font-size: 12px; max-width: 180px; }
.layer img { width: 22px; height: 22px; object-fit: contain; }
.layer span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer[aria-pressed="true"] { border-color: var(--leaf); box-shadow: inset 0 -3px 0 var(--leaf); }

.strip-wrap { margin-top: 12px; position: relative; display: flex; background: var(--ink); border-radius: 6px; padding: 20px 10px; }
.strip-wrap::before, .strip-wrap::after { content: ""; position: absolute; left: 10px; right: 10px; height: 7px; background: repeating-linear-gradient(90deg, var(--paper) 0 9px, transparent 9px 20px); opacity: .85; }
.strip-wrap::before { top: 6px; }
.strip-wrap::after { bottom: 6px; }
.strip { list-style: none; margin: 0; padding: 0; display: flex; gap: 8px; overflow-x: auto; flex: 1; }
.frame { flex: 0 0 132px; cursor: pointer; border: 3px solid transparent; border-radius: 4px; background: #33406a; color: #fff; }
.frame:hover { border-color: var(--ink-2); }
.frame[aria-current="true"] { border-color: var(--cel); }
.frame .thumb { aspect-ratio: 16 / 9; width: 100%; display: block; object-fit: cover; background: #3d4b78; }
.frame .meta { display: flex; justify-content: space-between; gap: 4px; padding: 3px 6px; font-size: 11px; }
.frame .meta b { font: 600 12px var(--display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.add-scene { flex: 0 0 auto; margin-left: 8px; padding: 0 14px; border: 2px dashed var(--ink-2); border-radius: 4px; background: transparent; color: #fff; font: 600 14px var(--display); cursor: pointer; }
.add-scene:hover { border-color: var(--cel); color: var(--cel); }
.total { margin: 6px 2px 0; font-size: 12px; color: var(--ink-2); }

.render-box { margin-top: 12px; border: 2px solid var(--ink); border-radius: 14px; padding: 12px 14px; background: var(--panel); }
.render-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.render-head span { color: var(--ink-2); font-size: 13px; }
.bar { height: 12px; border-radius: 99px; background: var(--paper); border: 1.5px solid var(--ink); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--cel); transition: width .4s; }
.render-box.error { border-color: var(--red); }
.render-box.error .bar span { background: var(--red); }
.render-box pre { white-space: pre-wrap; font-size: 12px; background: var(--paper); padding: 8px; border-radius: 8px; }
.media-out { width: 100%; border-radius: 8px; margin-top: 10px; display: block; background: #000; }
.actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- inspecteur */
.el-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.el-head img { width: 38px; height: 38px; object-fit: contain; }
.el-head h2 { font: 600 17px/1.2 var(--display); margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tools { display: flex; gap: 2px; }
.icon-btn { border: 1.5px solid transparent; background: transparent; border-radius: 6px; width: 30px; height: 30px; cursor: pointer; color: var(--ink-2); font-size: 15px; }
.icon-btn:hover { border-color: var(--line); color: var(--ink); }
.icon-btn.danger:hover { color: var(--red); border-color: var(--red); }

/* ---------------------------------------------------------------- boîtes de dialogue */
dialog#dlg { border: 2px solid var(--ink); border-radius: 14px; padding: 16px; width: min(860px, 94vw); background: var(--panel); max-height: 90vh; }
dialog#dlg::backdrop { background: rgba(30, 42, 74, .55); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dlg-head strong { font: 600 19px var(--display); }
.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.list li { border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #fff; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.list li > div { flex: 1; min-width: 180px; }
.list small { color: var(--ink-2); display: block; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: 90vw; white-space: pre-line; }
.toast.error { background: var(--red); }

@media (max-width: 1250px) {
  .studio { grid-template-columns: 270px minmax(0, 1fr); height: auto; }
  .inspector { grid-column: 1 / -1; }
  .panel { max-height: 80vh; }
}
@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; }
  .studio { grid-template-columns: 1fr; padding: 10px; }
  .palette { order: 2; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
