/* Audio Studio — canvas editor.
 *
 * Visual language (ui-designer, round 004):
 *  - Two typefaces with a job each. System sans = interface chrome
 *    (labels, buttons, prose). Mono = the project's own data (layer ids,
 *    types, tag chips, the JSON dump, warning codes, coordinates readout).
 *  - Two accent colours, kept apart on purpose:
 *      --accent  (teal)  = things you click in the app shell.
 *      --select  (amber) = the layer you are manipulating on the stage.
 *    Amber never appears in the shell; teal never lands on the canvas.
 *  - One deliberate shadow per role: chrome lift on the top bar, a
 *    recessed inset on the canvas host, an ambient drop under the canvas
 *    itself, a glow around the selected box. Cards use border + fill only.
 *  - Radii form a small scale, not one value everywhere: 5px controls,
 *    4px cards, 3px viewport, 0-1px on manipulation handles, a full pill
 *    for the status readout.
 */

:root {
  color-scheme: light dark;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* space scale */
  --s1: 4px;  --s2: 8px;  --s3: 12px;  --s4: 16px;  --s5: 20px;  --s6: 24px;

  /* light theme -------------------------------------------------- */
  --bg-app:        #ecebe7;
  --bg-panel:      #f6f5f2;
  --bg-stage:      #d7d5cf;
  --bg-surface:    #ffffff;
  --bg-surface-2:  #eeece7;
  --text:          #22252b;
  --text-soft:     #565b64;
  --text-faint:    #888d97;
  --line:          #d9d6ce;
  --line-strong:   #c3bfb4;

  --accent:        #0b7c8c;
  --accent-ink:    #ffffff;
  --accent-weak:   #d8ebee;

  --select:        #cc8b1e;
  --select-ink:    #1d1300;
  --select-glow:   rgba(204, 139, 30, 0.30);

  --danger:        #b23b3b;
  --ok:            #2f7d43;
  --warn-font:     #8f6200;
  --warn-timeline: #2c6a82;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-app:        #16171a;
    --bg-panel:      #1d1f23;
    --bg-stage:      #0d0e10;
    --bg-surface:    #26282e;
    --bg-surface-2:  #30333b;
    --text:          #e6e3dd;
    --text-soft:     #a3a7af;
    --text-faint:    #71767e;
    --line:          #34373e;
    --line-strong:   #474b54;

    --accent:        #38b1c3;
    --accent-ink:    #062028;
    --accent-weak:   #15343b;

    --select:        #f0af3c;
    --select-ink:    #1d1300;
    --select-glow:   rgba(240, 175, 60, 0.42);

    --danger:        #e0736a;
    --ok:            #5fbf7a;
    --warn-font:     #e0a458;
    --warn-timeline: #6db4cc;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font: 400 13px/1.5 var(--sans);
  color: var(--text);
  background: var(--bg-app);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--text-faint); font-weight: 400; }
.spacer { flex: 1 1 auto; }

::selection { background: var(--select-glow); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 2px; }

/* thin, quiet scrollbars ---------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 8px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ============================================================== *
 * Top bar
 * ============================================================== */
#topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 9px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line-strong);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04), 0 6px 16px -12px rgba(0, 0, 0, 0.4);
  position: relative;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 4px;
}
.brand-mark {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 3px;
  background:
    linear-gradient(var(--accent), var(--accent)) 3px 6px  / 2px 5px  no-repeat,
    linear-gradient(var(--accent), var(--accent)) 7px 3px  / 2px 11px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 11px 7px / 2px 4px  no-repeat,
    var(--accent-weak);
}
.brand-name {
  font: 650 14px/1 var(--sans);
  letter-spacing: -0.015em;
  color: var(--text);
}
.brand-sub {
  font: 400 11px/1 var(--sans);
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

.tb-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tb-div {
  width: 1px;
  height: 20px;
  background: var(--line-strong);
  margin: 0 2px;
}
.tb-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font: 600 10px/1 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
}

/* controls ----------------------------------------------------- */
button, select, input {
  font: 500 12px/1 var(--sans);
  height: 28px;
  padding: 0 10px;
  color: var(--text);
  background: var(--bg-surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}
input {
  font-weight: 400;
  font-family: var(--mono);
  font-size: 11px;
  min-width: 0;
}
input::placeholder { color: var(--text-faint); }
select { padding-right: 4px; }

button {
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
button:hover { background: var(--bg-surface-2); }
button:active { background: var(--bg-surface-2); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.is-primary {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 68%, #000);
  font-weight: 650;
}
button.is-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
button.is-primary:active { background: color-mix(in srgb, var(--accent) 80%, #000); }

/* render in progress: JS disables #renderBtn for the duration */
#renderBtn:disabled {
  opacity: 1;
  color: #fff;
  cursor: progress;
  border-color: color-mix(in srgb, var(--accent) 68%, #000);
  background-image: repeating-linear-gradient(
    -45deg,
    color-mix(in srgb, var(--accent) 82%, #000) 0 8px,
    color-mix(in srgb, var(--accent) 60%, #000) 8px 16px);
  background-size: 200% 100%;
  animation: as-progress 900ms linear infinite;
}
@keyframes as-progress {
  from { background-position: 0 0; }
  to   { background-position: -32px 0; }
}

/* status readout --------------------------------------------- */
#status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 26px;
  max-width: 40ch;
  padding: 0 12px 0 10px;
  font: 500 11px/1 var(--mono);
  color: var(--text-soft);
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#status::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* ============================================================== *
 * Three-pane layout
 * ============================================================== */
#app {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr) 328px;
}
#app > * { overflow: auto; }

#layerList {
  padding: 14px 12px;
  background: var(--bg-panel);
  border-right: 1px solid var(--line-strong);
}
#props {
  padding: 14px 14px 20px;
  background: var(--bg-panel);
  border-left: 1px solid var(--line-strong);
}
#canvasWrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 16px;
  background: var(--bg-stage);
}

h2 {
  margin: 0 0 8px;
  padding-bottom: 6px;
  font: 700 10px/1 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
  border-bottom: 1px solid var(--line);
}
#props h2:nth-of-type(n + 2) { margin-top: 18px; }

/* ============================================================== *
 * Layer list
 * ============================================================== */
#layers {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
#layers li {
  padding: 7px 9px;
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
#layers li > div:first-child {
  font: 600 12px/1.3 var(--mono);
  letter-spacing: -0.01em;
  color: var(--text);
  word-break: break-all;
}
#layers li .lt {
  margin-top: 2px;
  font: 400 10px/1.5 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}
#layers li:hover {
  background: var(--bg-surface-2);
  border-color: var(--line-strong);
}
#layers li.sel {
  background: color-mix(in srgb, var(--select) 12%, var(--bg-surface));
  border-color: var(--select);
  box-shadow: inset 3px 0 0 var(--select);
  padding-left: 12px;
}
#layers li.sel > div:first-child { color: var(--text); }

/* empty state: JS appends <li class="lt"> with no per-row <li> class */
#layers li.lt {
  background: transparent;
  border-color: transparent;
  cursor: default;
  text-align: center;
  padding: 18px 8px;
  font: 400 11px/1.4 var(--sans);
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-faint);
}

/* ============================================================== *
 * Canvas stage
 * ============================================================== */
#canvasHost {
  flex: 1 1 auto;
  min-height: 220px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  position: relative;
  background: var(--bg-stage);
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.3);
}
/* placeholder — covered by #canvas once a project gives it a size */
#canvasHost::before {
  content: "Mở một sample hoặc project để dựng canvas";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: 26ch;
  text-align: center;
  font: 400 12px/1.5 var(--sans);
  color: var(--text-faint);
  pointer-events: none;
}

#canvas {
  position: relative;
  background: #000;
  outline: 1px solid var(--line-strong);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 14px 40px -12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

/* Background layer — the real video frame. object-fit:fill stretches it to
 * EXACTLY #canvas's box (coord.len(canvas.width/height)), no letterboxing:
 * any letterbox gap would offset the video from the .box overlay math,
 * which assumes the background fills 0..canvas.width/height 1:1. */
#canvas .canvas-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  pointer-events: none;
}

/* Overlay layer — transparent, sits on top of .canvas-bg, holds the .box
 * elements. inset:0 + pointer-events:none so empty space doesn't swallow
 * clicks; individual .box opt back into pointer-events below. */
#canvasOverlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#canvas .box {
  pointer-events: auto;
  position: absolute;
  border: 1px dashed rgba(150, 160, 178, 0.65);
  background: rgba(150, 160, 180, 0.06);
  font: 11px/1.3 var(--mono);
  color: #fff;
  cursor: move;
  transition: border-color 100ms ease, background-color 100ms ease, box-shadow 100ms ease;
}
#canvas .box:hover:not(.sel) {
  border-style: solid;
  border-color: var(--select);
  background: color-mix(in srgb, var(--select) 9%, transparent);
}
#canvas .box.sel {
  border: 1px solid var(--select);
  background: color-mix(in srgb, var(--select) 11%, transparent);
  box-shadow: 0 0 0 1px var(--select), 0 0 12px var(--select-glow);
  z-index: 5;
}
#canvas .box.nogeom { cursor: default; }

#canvas .box .tag {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 100%;
  padding: 1px 5px;
  font: 10px/1.5 var(--mono);
  letter-spacing: 0.01em;
  color: #f2f3f5;
  background: rgba(10, 12, 16, 0.72);
  border-bottom-right-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
#canvas .box.sel .tag {
  color: var(--select-ink);
  background: var(--select);
  font-weight: 650;
}

#canvas .box .h {
  position: absolute;
  width: 9px;
  height: 9px;
  background: var(--select);
  border: 1.5px solid #fff;
  border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  transition: transform 90ms ease, box-shadow 90ms ease;
}
#canvas .box .h.se {
  right: -5px;
  bottom: -5px;
  cursor: nwse-resize;
}
#canvas .box .h.se:hover { transform: scale(1.3); }

/* live drag / resize feedback (classes set in app.js beginDrag/onDragEnd) */
#canvas.dragging,
#canvas.dragging * { user-select: none; }
#canvas.drag-move,
#canvas.drag-move * { cursor: grabbing !important; }
#canvas.drag-resize,
#canvas.drag-resize * { cursor: nwse-resize !important; }
#canvas.dragging .box.sel {
  box-shadow: 0 0 0 1px var(--select), 0 0 0 4px var(--select-glow);
  border-style: solid;
}
#canvas.drag-resize .box.sel {
  box-shadow: 0 0 0 1px var(--select), 0 0 0 5px var(--select-glow);
}
#canvas.drag-resize .box.sel .h.se { transform: scale(1.3); }

/* Playback bar for #canvasBg — lives BELOW #canvasHost (see index.html),
 * never over the video's pixel area, so it can never overlap a draggable
 * .box (e.g. the subtitle layer's default near-bottom position). */
.bg-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.bg-controls[hidden] { display: none; }
.bg-controls button {
  flex: 0 0 auto;
  min-width: 28px;
  padding: 3px 7px;
  font: 400 12px/1 var(--sans);
  cursor: pointer;
}
.bg-controls input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
}
.bg-controls .bg-time {
  flex: 0 0 auto;
  font: 400 11px/1.5 var(--mono);
  color: var(--text-soft);
  white-space: nowrap;
}

#canvasNote {
  margin: 10px 0 0;
  text-align: center;
  font: 400 11px/1.5 var(--sans);
  color: var(--text-faint);
}

/* render metadata — the canvas itself now IS the render preview (its
 * background swaps to the rendered file); this is just the leftover text
 * readout (resolution/duration/TTS backend/warnings summary). */
#renderMeta {
  width: 100%;
  margin: 10px 0 0;
  font: 400 11px/1.5 var(--mono);
  color: var(--text-soft);
  word-break: break-word;
}

/* ============================================================== *
 * Properties dump
 * ============================================================== */
#propBody > p.muted {
  margin: 0;
  padding: 24px 8px;
  text-align: center;
  color: var(--text-faint);
}
#propBody > p.muted::before {
  content: "\2316"; /* position target */
  display: block;
  margin-bottom: 6px;
  font-size: 20px;
  opacity: 0.55;
}
#propBody pre {
  margin: 0;
  padding: 10px;
  font: 400 11px/1.5 var(--mono);
  color: var(--text);
  background: var(--bg-stage);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
/* the dump is a live coordinate readout while a box is being dragged */
#app:has(#canvas.dragging) #propBody pre {
  border-color: var(--select);
  box-shadow: 0 0 0 1px var(--select-glow);
}

/* ============================================================== *
 * Validate errors
 * ============================================================== */
#errors {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
#errors li {
  position: relative;
  padding: 6px 9px 6px 24px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 32%, transparent);
  border-radius: 4px;
}
#errors li::before {
  content: "!";
  position: absolute;
  left: 9px;
  top: 6px;
  font: 700 12px/1.45 var(--mono);
}
#errors li.ok {
  padding-left: 9px;
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 10%, transparent);
  border-color: color-mix(in srgb, var(--ok) 32%, transparent);
}
#errors li.ok::before { content: none; } /* JS text already carries a check */

/* ============================================================== *
 * Render warnings — grouped by code prefix: .font vs .timeline
 * ============================================================== */
#warnings {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#warnings li {
  padding: 7px 9px 7px 10px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-soft);
  background: var(--bg-surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: 4px;
}
#warnings li code {
  font: 400 10px/1.6 var(--mono);
  padding: 0 4px;
  border-radius: 3px;
  color: var(--text);
  background: var(--bg-surface-2);
  border: 1px solid var(--line);
}
#warnings li.font {
  border-left-color: var(--warn-font);
}
#warnings li.font code {
  color: var(--warn-font);
  border-color: color-mix(in srgb, var(--warn-font) 45%, transparent);
  background: color-mix(in srgb, var(--warn-font) 12%, transparent);
}
#warnings li.timeline {
  border-left-color: var(--warn-timeline);
}
#warnings li.timeline code {
  color: var(--warn-timeline);
  border-color: color-mix(in srgb, var(--warn-timeline) 45%, transparent);
  background: color-mix(in srgb, var(--warn-timeline) 12%, transparent);
}
#warnings li.muted {
  padding: 12px 8px;
  text-align: center;
  background: transparent;
  border: 0;
  color: var(--text-faint);
}

/* ============================================================== *
 * Per-type property forms (reserved for T21)
 * ============================================================== */
.field { margin-bottom: 10px; }
.field label {
  display: block;
  margin-bottom: 3px;
  font: 700 10px/1.4 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}
.field input, .field select, .field textarea { width: 100%; }

/* ============================================================== *
 * Narrow viewport: stack the three panes
 * ============================================================== */
@media (max-width: 940px) {
  #app {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(150px, auto);
  }
  #layerList { border-right: 0; border-bottom: 1px solid var(--line-strong); }
  #props { border-left: 0; border-top: 1px solid var(--line-strong); }
  #canvasWrap { min-height: 320px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ============================================================== *
 * T21-T23 — property forms, cue editor, warning groups, progress
 * (functional styling; keeps the ui-designer visual language)
 * ============================================================== */
.addrow { display: flex; gap: 6px; margin-top: 10px; }
.addrow select { flex: 1; }

.prop-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 8px;
}
.prop-head .lt { font: 600 11px/1 var(--mono); color: var(--text-soft); }

.form .field { margin-bottom: 9px; }
.field textarea { resize: vertical; font: 12px/1.4 var(--mono); min-height: 34px; }
.field input[type="color"] { height: 26px; padding: 1px 2px; }
.field input[type="checkbox"] { width: auto; }

/* Volume sliders (0-200%, unity at 100%). Track is drawn from three
 * stacked gradients so the 100% mark reads even before the user has
 * touched the control:
 *   1. "boost" fill   — accent, only paints past the midpoint
 *   2. "baseline" fill — accent at 45% mix, paints up to the midpoint
 *   3. a 2px tick permanently sitting at the midpoint, under the fill
 * app.js sets --fillpct (0-100, = value/2) on input so the two fill
 * layers track live drag/typing without any other JS/logic change. */
.percent-field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  row-gap: 4px;
  gap: 6px 8px;
}
.percent-field::after {
  content: "100% = giữ nguyên mức gốc";
  flex-basis: 100%;
  font: 400 10px/1.4 var(--sans);
  color: var(--text-faint);
}

.percent-range {
  flex: 1 1 auto;
  min-width: 60px;
  -webkit-appearance: none;
  appearance: none;
  height: 15px;
  padding: 0;
  background: transparent;
  border: 0;
  cursor: pointer;
  /* three stacked gradients, shared by both vendor track rules below */
  --grad-boost: linear-gradient(to right, transparent 0 50%, var(--accent) 50% max(calc(var(--fillpct, 50) * 1%), 50%));
  --grad-base:  linear-gradient(to right, color-mix(in srgb, var(--accent) 45%, var(--bg-surface-2)) 0 min(calc(var(--fillpct, 50) * 1%), 50%), transparent min(calc(var(--fillpct, 50) * 1%), 50%) 100%);
  --grad-tick:  linear-gradient(to right, transparent 0 calc(50% - 1px), var(--line-strong) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px) 100%);
}
.percent-range:focus-visible { outline: none; } /* ring lives on the thumb, not the hit box */

/* NOTE: -webkit- and -moz- pseudo-elements must stay in separate rules —
 * a browser that doesn't recognise one of two comma-joined selectors
 * drops the whole rule, so the two vendors never share a rule block. */
.percent-range::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background-color: var(--bg-surface-2);
  background-image: var(--grad-boost), var(--grad-base), var(--grad-tick);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}
.percent-range::-moz-range-track {
  height: 5px;
  border-radius: 3px;
  background-color: var(--bg-surface-2);
  background-image: var(--grad-boost), var(--grad-base), var(--grad-tick);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.percent-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-panel);
  box-shadow: 0 0 0 1px var(--line-strong), 0 1px 2px rgba(0, 0, 0, 0.35);
  cursor: grab;
  transition: transform 100ms ease, box-shadow 100ms ease, background-color 120ms ease;
}
.percent-range::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-panel);
  box-shadow: 0 0 0 1px var(--line-strong), 0 1px 2px rgba(0, 0, 0, 0.35);
  cursor: grab;
  transition: transform 100ms ease, box-shadow 100ms ease, background-color 120ms ease;
}
.percent-range:hover::-webkit-slider-thumb,
.percent-range:focus-visible::-webkit-slider-thumb {
  transform: scale(1.15);
  box-shadow: 0 0 0 1px var(--line-strong), 0 0 0 4px color-mix(in srgb, var(--accent) 26%, transparent), 0 1px 2px rgba(0, 0, 0, 0.35);
}
.percent-range:hover::-moz-range-thumb,
.percent-range:focus-visible::-moz-range-thumb {
  transform: scale(1.15);
  box-shadow: 0 0 0 1px var(--line-strong), 0 0 0 4px color-mix(in srgb, var(--accent) 26%, transparent), 0 1px 2px rgba(0, 0, 0, 0.35);
}
.percent-range:active::-webkit-slider-thumb {
  cursor: grabbing;
  background: color-mix(in srgb, var(--accent) 82%, #000);
}
.percent-range:active::-moz-range-thumb {
  cursor: grabbing;
  background: color-mix(in srgb, var(--accent) 82%, #000);
}

.percent-field input[type="number"] {
  /* the house 0 10px padding + the UA spin-button eat most of 4.5em,
     clipping the leading digit of "100"/"150"/"200" — give it room */
  width: 5.5em;
  padding: 0 4px;
  flex: none;
  font-variant-numeric: tabular-nums;
}
.percent-field .percent-suffix { font: 11px/1 var(--mono); color: var(--text-soft); flex: none; }

.cues { display: flex; flex-direction: column; gap: 4px; }
.cue-row { display: grid; grid-template-columns: 4.5em 4.5em 1fr auto; gap: 4px; }
.cue-row input { width: 100%; font: 11px/1.3 var(--mono); }
.cue-row button, .cues > button { height: 24px; padding: 0 8px; }

#warnings .warn-group {
  list-style: none; margin: 8px 0 3px -18px;
  font: 700 10px/1.4 var(--sans); text-transform: uppercase; letter-spacing: 0.06em;
}
#warnings .warn-group.font { color: var(--warn-font); }
#warnings .warn-group.timeline { color: var(--warn-timeline); }
#warnings .warn-item { margin-bottom: 6px; }
#warnings .warn-item .wl { font: 600 11px/1 var(--mono); color: var(--text-soft); }
#warnings .warn-item .wm { margin-top: 2px; }
#warnings .warn-item .wd { margin-top: 1px; font: 11px/1.3 var(--mono); }

#canvas .box.warn { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }

#renderProgress { width: 100%; margin-top: 8px; display: flex; align-items: center; gap: 8px; }
#renderProgress[hidden] { display: none; } /* ID specificity above beats the UA [hidden] rule otherwise */
#renderProgress progress { flex: 1; height: 8px; }
#renderPhase { font: 11px/1 var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============================================================== *
 * VÒNG 005 — "Tạo project mới" — modal dialog
 * ui-designer polish (round 005): the modal is app chrome, so it
 * stays in the sans/teal register — amber never appears here. Mono
 * is reserved for the data the dialog echoes back (file names, sizes,
 * upload percentages). Radii follow the house scale: 6px on the
 * dialog shell (one step above the 4px cards), 5px on controls,
 * 3px on the progress bars.
 * ============================================================== */
#newProject {
  position: fixed;
  inset: 0;
  z-index: 100;                 /* above #topbar (z-index: 10) */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  background: rgba(11, 13, 17, 0.56);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  overflow: auto;
  animation: np-overlay-in 130ms ease-out;
}
#newProject[hidden] { display: none; }   /* id beats [hidden]'s UA rule */

@keyframes np-overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes np-modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

.np-modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 512px;
  max-height: 90vh;
  background: var(--bg-surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  box-shadow:
    0 18px 50px -16px rgba(0, 0, 0, 0.55),
    0 4px 14px -8px rgba(0, 0, 0, 0.35);
  overflow: hidden;            /* head/foot square with the rounded frame */
  animation: np-modal-in 170ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

.np-modal-head {
  flex: none;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--line);
}
.np-modal-head h2 {
  position: relative;
  margin: 0;
  padding: 0 0 10px;
  border: 0;
  font: 640 17px/1.25 var(--sans);
  text-transform: none;
  letter-spacing: -0.012em;
  color: var(--text);
}
.np-modal-head h2::after {   /* short teal tick — ties the dialog to the app shell */
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 26px;
  height: 2px;
  background: var(--accent);
}

.np-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;            /* body scrolls; head + foot stay put */
  padding: 16px 24px 18px;
}
.np-modal-body > p.muted {
  margin: 0 0 18px;
  font: 400 12px/1.55 var(--sans);
  color: var(--text-soft);
}

.np-modal-foot {
  flex: none;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 13px 24px 15px;
  border-top: 1px solid var(--line);
  background: var(--bg-panel);
}

/* footer primary button, while createNewProject() runs: JS sets .disabled.
 * Mirrors #renderBtn:disabled — a barber-pole says "working", not "dead". */
#npCreate:disabled {
  opacity: 1;
  color: #fff;
  cursor: progress;
  border-color: color-mix(in srgb, var(--accent) 68%, #000);
  background-image: repeating-linear-gradient(
    -45deg,
    color-mix(in srgb, var(--accent) 82%, #000) 0 8px,
    color-mix(in srgb, var(--accent) 60%, #000) 8px 16px);
  background-size: 200% 100%;
  animation: as-progress 900ms linear infinite;
}

.np-field { margin-bottom: 15px; }
.np-field:last-of-type { margin-bottom: 4px; }
.np-field > label {
  display: block; margin-bottom: 5px;
  font: 700 10px/1.4 var(--sans); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-faint);
}
.np-field .req {
  margin-left: 7px; padding: 1px 5px 2px; border-radius: 3px;
  background: var(--accent-weak); color: var(--accent);
  font: 700 9px/1.4 var(--sans); text-transform: uppercase; letter-spacing: 0.04em;
  vertical-align: 1px;
}

/* text name field — the one typed control; keep a clear focus state
 * even on programmatic focus() when :focus-visible may not match */
.np-field input:not([type]),
.np-field input[type="text"] {
  width: 100%;
  height: 30px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.np-field input:not([type]):focus,
.np-field input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* file inputs — hide the ugly UA field frame, keep the button as a
 * real, labelled control (the <label for> still drives it) */
.np-field input[type="file"] {
  width: 100%;
  height: auto;
  padding: 0;
  font: 400 11px/1.4 var(--mono);
  color: var(--text-soft);
  background: transparent;
  border: 0;
  border-radius: 0;
}
.np-field input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 6px 12px;
  font: 600 11px/1 var(--sans);
  color: var(--text);
  background: var(--bg-surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}
.np-field input[type="file"]::file-selector-button:hover {
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-surface-2));
  border-color: var(--accent);
}
.np-field input[type="file"]:focus-visible::file-selector-button {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.np-meta {
  display: block;
  margin-top: 5px;
  font: 400 11px/1.4 var(--mono);
  color: var(--text-faint);
}
.np-meta:empty { display: none; }

/* per-file upload progress row */
.np-prog {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.np-prog[hidden] { display: none; }
.np-track {
  flex: 1 1 auto;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  overflow: hidden;
}
.np-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 140ms linear, background-color 160ms ease;
}
.np-prog-txt {
  flex: none;
  min-width: 12ch;
  font: 500 11px/1 var(--mono);
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.np-prog.is-done .np-fill { background: var(--ok); }
.np-prog.is-done .np-prog-txt {
  position: relative;
  padding-left: 16px;
  color: var(--ok);
}
.np-prog.is-done .np-prog-txt::before {   /* drawn check — no glyph in the JS string */
  content: "";
  position: absolute;
  left: 3px;
  top: 50%;
  width: 4px;
  height: 8px;
  margin-top: -6px;
  border: solid var(--ok);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* prominent shared step line (probe / build) — must not read as the
 * quiet note below it: teal-tinted panel + a live ring on the left */
.np-step {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 4px;
  padding: 11px 13px;
  border: 1px solid color-mix(in srgb, var(--accent) 38%, var(--line));
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  background: var(--accent-weak);
  font: 600 12px/1.4 var(--sans);
  color: var(--text);
}
.np-step[hidden] { display: none; }
.np-spinner {
  flex: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 26%, transparent);
  border-top-color: var(--accent);
  animation: np-spin 640ms linear infinite;
}
@keyframes np-spin { to { transform: rotate(360deg); } }

/* quiet advisory ("audio dài hơn video") — deliberately understated
 * so the step line above stays the loud element */
.np-note { margin: 10px 0 0; }
.np-note:empty { display: none; }
.np-note:not(:empty) {
  position: relative;
  padding-left: 17px;
  font: 500 11px/1.5 var(--sans);
  color: var(--warn-timeline);
}
.np-note:not(:empty)::before {
  content: "!";
  position: absolute;
  left: 4px;
  top: 0;
  font: 700 11px/1.5 var(--mono);
}

#npErrors {
  flex: none;
  list-style: none;
  margin: 0;
  padding: 12px 24px;
  max-height: 24vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#npErrors:empty { display: none; }
#npErrors:not(:empty) {
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--danger) 6%, transparent);
}
#npErrors li {
  position: relative;
  margin: 0;
  padding: 6px 10px 6px 24px;
  font: 400 12px/1.45 var(--sans);
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 32%, transparent);
  border-radius: 4px;
}
#npErrors li::before {
  content: "!";
  position: absolute;
  left: 9px;
  top: 6px;
  font: 700 12px/1.45 var(--mono);
}

/* short viewports: tighten the frame so the body keeps room to scroll */
@media (max-height: 640px) {
  #newProject { padding: 14px; }
  .np-modal { max-height: 94vh; }
  .np-modal-head { padding: 14px 24px 11px; }
  .np-modal-body { padding: 13px 24px 14px; }
  .np-field { margin-bottom: 11px; }
  .np-step { margin-top: 12px; }
  .np-modal-foot { padding: 11px 24px 12px; }
  #npErrors { max-height: 30vh; }
}

/* narrow: shrink the horizontal gutters in step with the overlay */
@media (max-width: 560px) {
  #newProject { padding: 12px; }
  .np-modal-head,
  .np-modal-body,
  .np-modal-foot,
  #npErrors { padding-left: 16px; padding-right: 16px; }
}
