/* Facet — studio editor */
html, body { height: 100%; overflow: hidden; }
body { display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0,1fr); }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--line);
  background: var(--surface); z-index: var(--z-nav);
}
.topbar { min-width: 0; }
.topbar .left, .topbar .right { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.topbar .left { flex: 1; }
.preset-switch { min-width: 0; flex: 1; }
@media (max-width: 640px){
  .topbar { padding: var(--sp-3) var(--sp-3); gap: var(--sp-2); }
  .topbar .brand { display: none; }
  .divider-v { display: none; }
  #replayBtn span, #replayBtn { font-size: 0; }
  #replayBtn svg { font-size: 1rem; }
  .topbar .left, .topbar .right { gap: var(--sp-2); }
}
.topbar .brand { font-size: 1.05rem; }
.divider-v { width: 1px; height: 24px; background: var(--line); }
.preset-switch { display: flex; align-items: center; gap: var(--sp-2); }
.preset-switch select {
  appearance: none; background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink); height: 38px; padding: 0 34px 0 14px; border-radius: var(--r-full); font-weight: 500;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23bbb' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; cursor: pointer;
}

/* Main split */
.workspace { display: grid; grid-template-columns: minmax(0,1fr) 340px; min-height: 0; }
@media (max-width: 900px){ .workspace { grid-template-columns: minmax(0,1fr); grid-template-rows: minmax(0,1fr) auto; } }

/* Stage */
.stage-wrap { position: relative; min-width: 0; min-height: 0; display: grid; place-items: center; overflow: hidden; }
.stage-glow { position: absolute; left: 50%; top: 50%; width: 70vmin; height: 70vmin; transform: translate(-50%,-50%);
  background: radial-gradient(circle, var(--glow-green), transparent 62%); filter: blur(40px); opacity: 0.4; pointer-events: none; }
.stage {
  position: relative; background: transparent;
  box-shadow: var(--shadow-lg); border-radius: var(--r-md); overflow: hidden;
  outline: 1px solid var(--line);
}
.stage canvas { display: block; }
.stage-toolbar {
  position: absolute; left: 50%; bottom: var(--sp-5); transform: translateX(-50%);
  display: flex; gap: var(--sp-2); padding: 6px; z-index: 5;
  background: oklch(0.145 0.008 255 / 0.7); backdrop-filter: blur(12px);
  border: 1px solid var(--line-2); border-radius: var(--r-full);
}
.stage-hint { position: absolute; top: var(--sp-4); left: 50%; transform: translateX(-50%);
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); z-index: 5; }

/* Presenter mode. The arrows sit quietly over the stage and surface on hover or keyboard
   focus, so the canvas stays the subject while you compose and the controls are there the
   moment you reach for them. */
.stage-nav { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.stage-nav[hidden] { display: none; }
.stage-arrow {
  position: absolute; top: 50%; margin-top: -22px; pointer-events: auto;
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  color: var(--ink); background: oklch(0.145 0.008 255 / 0.72); backdrop-filter: blur(12px);
  border: 1px solid var(--line-2); border-radius: var(--r-full); cursor: pointer;
  opacity: 0; transform: scale(0.94);
  transition: opacity var(--dur-mid) var(--ease-out-quart), transform var(--dur-mid) var(--ease-out-quart),
              background var(--dur-fast), border-color var(--dur-fast);
}
.stage-arrow svg { width: 20px; height: 20px; }
#slidePrev { left: var(--sp-5); }
#slideNext { right: var(--sp-5); }
.stage-wrap:hover .stage-arrow, .stage-arrow:focus-visible { opacity: 1; transform: scale(1); }
.stage-arrow:hover { background: oklch(0.2 0.012 255 / 0.88); border-color: var(--primary); }
/* Presenter is a mode, not a one-shot action — the toggle has to read as latched. */
#presentBtn[aria-pressed="true"] { color: var(--primary); border-color: var(--primary); background: oklch(0.72 0.17 264 / 0.12); }
.stage-arrow:disabled { opacity: 0; pointer-events: none; }
.stage-count { position: absolute; top: var(--sp-4); right: var(--sp-5);
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.14em; color: var(--faint); }
@media (prefers-reduced-motion: reduce) {
  .stage-arrow { transform: none; transition: opacity var(--dur-fast); }
  .stage-wrap:hover .stage-arrow, .stage-arrow:focus-visible { transform: none; }
}

/* Panel */
.panel { border-left: 1px solid var(--line); background: var(--surface); overflow-y: auto; min-height: 0; }
@media (max-width: 900px){ .panel { border-left: none; border-top: 1px solid var(--line); max-height: 44vh; } }
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 3px solid var(--surface); }

.section-group { padding: 0; border-bottom: 1px solid var(--line); }
.section-group > summary {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); cursor: pointer; list-style: none;
  color: var(--faint); font-weight: 600; user-select: none;
  transition: color var(--dur-fast);
}
.section-group > summary::-webkit-details-marker { display: none; }
.section-group > summary:hover { color: var(--muted); }
.section-group > summary .s-ico { width: 16px; height: 16px; flex: none; color: inherit; }
.section-group > summary .s-lab {
  flex: 1; font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase;
}
.section-group > summary .chev { width: 14px; height: 14px; flex: none; transition: transform var(--dur-fast) var(--ease-out-quart); color: var(--faint); }
.section-group[open] > summary { color: var(--ink); }
.section-group[open] > summary .chev { transform: rotate(180deg); }
.section-group > .section-body { padding: 0 var(--sp-5) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); }
.section-group > .section-body > .field,
.section-group > .section-body > .ctrl { margin-top: 0; margin-bottom: 0; }

/* Compact hover tooltip beside a label — replaces long always-visible hint paragraphs */
.info-ico { display: inline-block; width: 14px; height: 14px; margin-left: 6px; color: var(--faint); cursor: help; vertical-align: -2px; flex: none; }
.info-ico:hover { color: var(--muted); }

/* Deck list — the import list IS the running order, so every row carries its slot
   number and a grip. A 3-up thumbnail grid can't express sequence; a list can, and
   dragging a row is the same gesture as re-sequencing the carousel. */
.deck-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: var(--sp-2); }
.deck-lab { font-size: 0.68rem; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
.deck-count { font-family: var(--font-mono); font-size: 0.66rem; color: var(--muted); }

.deck-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px;
  max-height: 336px; overflow-y: auto; overscroll-behavior: contain; }
.deck-list::-webkit-scrollbar { width: 8px; }
.deck-list::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; border: 2px solid var(--surface); }
/* Files dragged in from the desktop land here too, not just via the picker. */
.deck-list.is-dropzone { outline: 1px dashed var(--primary); outline-offset: 3px; border-radius: var(--r-sm); }
.deck-autofill { margin-top: var(--sp-2); border-style: dashed; color: var(--primary); }

.deck-item { display: flex; align-items: center; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--surface-2); flex: none;
  transition: transform var(--dur-mid) var(--ease-out-quart),
              border-color var(--dur-fast), background var(--dur-fast); }
.deck-item:hover { border-color: var(--line-2); }
.deck-item.sel { border-color: var(--primary); background: oklch(0.72 0.17 264 / 0.10); }
/* Lifted out of the stack while it's under the pointer: no transition, because it has
   to track the cursor 1:1 — the settle back into a slot re-enables it via .is-landing. */
.deck-item.is-dragging { position: relative; z-index: 2; transition: none;
  border-color: var(--line-2); background: var(--surface-3); box-shadow: var(--shadow-md); }
.deck-item.is-landing { transition: transform var(--dur-fast) var(--ease-out-quart); }

.di-grip { flex: none; width: 16px; height: 30px; display: grid; place-items: center;
  color: var(--faint); cursor: grab; touch-action: none; }
.di-grip:active { cursor: grabbing; }
.deck-item:hover .di-grip { color: var(--muted); }
.di-grip svg { width: 10px; height: 16px; pointer-events: none; }

.di-select { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px;
  padding: 6px 4px 6px 2px; margin: 0; background: none; border: 0; border-radius: var(--r-sm);
  font: inherit; color: inherit; text-align: left; cursor: pointer; }
.di-thumb { position: relative; flex: none; width: 42px; height: 34px; border-radius: 6px;
  overflow: hidden; background: var(--surface-3); }
.di-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.di-badge { position: absolute; inset: auto 0 0 0; height: 13px; display: grid; place-items: center;
  background: oklch(0.145 0.008 255 / 0.75); color: var(--ink); }
.di-badge svg { width: 8px; height: 8px; }
.di-text { min-width: 0; display: grid; gap: 1px; }
.di-name { font-size: 0.78rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deck-item.sel .di-name { color: var(--primary); font-weight: 600; }
.di-meta { font-family: var(--font-mono); font-size: 0.64rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.di-check { flex: none; width: 15px; height: 15px; margin-right: 4px; color: var(--primary);
  opacity: 0; transition: opacity var(--dur-fast); }
.deck-item.sel .di-check { opacity: 1; }
.di-acts { flex: none; display: flex; gap: 1px; padding-right: 4px; }
.di-act { width: 26px; height: 26px; border-radius: 6px; border: 0; background: none;
  color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.di-act:hover { background: var(--surface-3); color: var(--ink); }
.di-act.rm:hover { background: var(--accent-2); color: var(--bg); }
.di-act svg { width: 13px; height: 13px; }
/* On a pointer device the actions stay out of the way until you're on the row (and the
   selected-check hands its spot over to them). Touch has no hover, so they stay put. */
@media (hover: hover) {
  .di-acts { opacity: 0; transition: opacity var(--dur-fast); }
  .deck-item:hover .di-acts, .deck-item:focus-within .di-acts { opacity: 1; }
  .deck-item:hover .di-check, .deck-item:focus-within .di-check { opacity: 0; }
}

.deck-add { width: 100%; margin-top: var(--sp-2); display: flex; align-items: center;
  justify-content: center; gap: 6px; padding: 9px; border: 1px dashed var(--line-2);
  border-radius: var(--r-sm); background: none; color: var(--muted); font: inherit;
  font-size: 0.78rem; cursor: pointer;
  transition: color var(--dur-fast), border-color var(--dur-fast), background var(--dur-fast); }
.deck-add:hover { color: var(--ink); border-color: var(--primary); background: oklch(0.72 0.17 264 / 0.08); }
.deck-add svg { width: 14px; height: 14px; }
.deck-hint { margin: 6px 0 0; font-size: 0.68rem; line-height: 1.4; color: var(--faint); }

/* Framing — zoom/pan for the selected card's image. Inset against the panel so it reads
   as belonging to the selected row above it rather than as another global card setting. */
.framing { margin-top: var(--sp-3); padding: 10px 12px 4px; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--surface-2); }
.framing[hidden] { display: none; }
.framing-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.framing-lab { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.framing-reset { border: 0; background: none; padding: 2px 4px; margin-right: -4px; cursor: pointer;
  font: inherit; font-size: 0.72rem; color: var(--faint); border-radius: 4px;
  transition: color var(--dur-fast), background var(--dur-fast); }
.framing-reset:hover { color: var(--primary); background: oklch(0.72 0.17 264 / 0.10); }
.framing-reset:disabled { opacity: 0.4; cursor: default; }
.framing-reset:disabled:hover { color: var(--faint); background: none; }
/* An axis with no overflow has nothing to pan into. Dimmed rather than removed so the
   control doesn't jump in and out of the layout as you drag zoom past the threshold.
   Note this is per-axis: a landscape image in a portrait card pans horizontally at zoom
   100% while the vertical slider stays dead. */
.framing .ctrl.dead { opacity: 0.4; }
.framing .ctrl.dead input { cursor: default; }
.framing-hint { margin: 2px 0 8px; font-size: 0.66rem; line-height: 1.4; color: var(--faint); }
.framing:not(.no-pan) .framing-hint { display: none; }

@media (prefers-reduced-motion: reduce) {
  .deck-item, .deck-item.is-landing { transition: border-color var(--dur-fast), background var(--dur-fast); }
}

/* Loaded-audio chip: icon, filename (truncated), remove. Replaces its upload button. */
.audio-row { display: flex; align-items: center; gap: 8px; margin-top: 6px;
  padding: 7px 8px 7px 10px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface-2); }
.audio-row[hidden] { display: none; }
.audio-ico { width: 14px; height: 14px; flex: none; color: var(--primary); }
.audio-name { flex: 1; min-width: 0; font-size: 0.78rem; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audio-x { flex: none; width: 20px; height: 20px; border-radius: 50%; border: 0;
  background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.audio-x:hover { background: var(--accent-2); color: #fff; }
.audio-x svg { width: 11px; height: 11px; }

.field { margin-top: var(--sp-3); }
.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.field input[type=text] { width: 100%; height: 38px; padding: 0 12px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); }
.field input[type=text]:focus { border-color: var(--primary); outline: none; }
.field textarea { width: 100%; min-height: 76px; padding: 10px 12px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); font: inherit; resize: vertical; }
.field textarea:focus { border-color: var(--primary); outline: none; }
.field select { width: 100%; height: 38px; padding: 0 12px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); font: inherit; cursor: pointer; }
.field select:focus { border-color: var(--primary); outline: none; }

/* Colour picker row (solid-background text slides) */
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type=color] { width: 42px; height: 38px; padding: 0; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--surface-2); cursor: pointer; flex: none; }
.color-row input[type=color]::-webkit-color-swatch-wrapper { padding: 4px; }
.color-row input[type=color]::-webkit-color-swatch { border: none; border-radius: 6px; }
.color-hint { font-size: 0.74rem; color: var(--muted); line-height: 1.3; }

/* Sliders */
.ctrl { margin-bottom: var(--sp-3); }
.ctrl .lab { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 6px; }
.ctrl .lab .val { color: var(--muted); font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: 0.78rem; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 4px;
  background: var(--surface-3); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary); cursor: pointer; border: 3px solid var(--surface); box-shadow: 0 1px 4px oklch(0 0 0 / 0.4); transition: transform var(--dur-fast); }
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--primary); cursor: pointer; border: 3px solid var(--surface); }

/* Segmented control */
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-full); padding: 3px; gap: 3px; }
.seg button { flex: 1; height: 32px; border-radius: var(--r-full); font-size: 0.82rem; color: var(--muted); transition: all var(--dur-fast); }
.seg button.active { background: var(--surface-3); color: var(--ink); }
.seg.primary button.active { background: var(--primary); color: var(--primary-ink); font-weight: 600; }

.reset-btn { width: 100%; margin-top: var(--sp-2); height: 36px; border-radius: var(--r-sm);
  background: transparent; border: 1px solid var(--line); color: var(--muted); font-size: 0.85rem; transition: all var(--dur-fast); }
.reset-btn:hover { color: var(--ink); border-color: var(--line-2); }

/* Modal */
.backdrop { position: fixed; inset: 0; background: oklch(0 0 0 / 0.6); backdrop-filter: blur(6px);
  z-index: var(--z-modal-backdrop); display: none; place-items: center; padding: var(--sp-5); }
.backdrop.open { display: grid; }
.modal { width: min(520px, 100%); background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-lg); padding: var(--sp-6); box-shadow: var(--shadow-lg); z-index: var(--z-modal); }
.modal h3 { font-size: 1.4rem; margin-bottom: var(--sp-2); }
.modal .sub { color: var(--muted); font-size: 0.92rem; margin-bottom: var(--sp-5); }
.export-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px,1fr)); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.export-opt { padding: var(--sp-4); border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface-2);
  cursor: pointer; text-align: center; transition: all var(--dur-fast); }
.export-opt.sel { border-color: var(--primary); background: oklch(0.22 0.03 264); }
.export-opt svg { width: 26px; height: 26px; margin: 0 auto var(--sp-2); color: var(--primary); }
.export-opt .t { font-weight: 600; font-size: 0.95rem; }
.export-opt .d { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.modal-row { display: flex; gap: var(--sp-3); align-items: center; margin-bottom: var(--sp-4); }
.modal-row > .field { flex: 1; margin: 0; }
.modal-actions { display: flex; gap: var(--sp-3); justify-content: flex-end; margin-top: var(--sp-5); }
.checkrow { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-4); font-size: 0.9rem; color: var(--ink); cursor: pointer; }
.checkrow input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.checkrow input:disabled { cursor: not-allowed; }
.checkrow:has(input:disabled) { color: var(--faint); cursor: not-allowed; }
.checkrow em { color: var(--faint); font-style: normal; font-family: var(--font-mono); font-size: 0.72rem; }
.progress { height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; margin-top: var(--sp-4); display: none; }
.progress.show { display: block; }
.progress .bar { height: 100%; width: 0; background: var(--primary); transition: width 0.2s; }
.progress-label { font-size: 0.82rem; color: var(--muted); margin-top: var(--sp-2); text-align: center; display: none; }
.progress-label.show { display: block; }
.embed-out { display: none; margin-top: var(--sp-4); }
.embed-out.show { display: block; }
.embed-out textarea { width: 100%; height: 90px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm);
  color: var(--muted); font-family: var(--font-mono); font-size: 0.72rem; padding: var(--sp-3); resize: none; }

/* Toast */
.toast { position: fixed; bottom: var(--sp-5); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface-3); border: 1px solid var(--line-2); color: var(--ink); padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-full); box-shadow: var(--shadow-md); z-index: var(--z-toast); opacity: 0; pointer-events: none;
  transition: opacity var(--dur-mid), transform var(--dur-mid) var(--ease-out-quart); font-size: 0.9rem; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.preset-plan-dialog { width:min(520px, calc(100vw - 32px)); padding:28px; border:1px solid var(--line); border-radius:16px; color:var(--ink); background:var(--surface); margin:auto; }
.preset-plan-dialog::backdrop { background:rgba(0,0,0,.65); }
.preset-plan-dialog h2 { margin:20px 0 16px; font-size:24px; }
.preset-plan-dialog p { margin-bottom:16px; line-height:1.6; }
.preset-plan-actions { display:flex; flex-wrap:wrap; gap:12px; }
.preset-plan-actions [hidden] { display:none; }
