/* ==========================================================================
   UGC Video Studio — design system
   Refined dark UI. One violet accent (#6d5efc). System fonts only (offline).
   ========================================================================== */
:root {
  /* surfaces */
  --bg:          #0b0c10;
  --bg-glow:     rgba(109, 94, 252, .14);
  --surface:     #16181f;
  --surface-2:   #1b1e27;   /* inputs, nested cards */
  --surface-3:   #20242f;   /* hover */

  /* ink */
  --ink:    #eceef4;
  --muted:  #a3a9b8;
  --faint:  #8b92a5;   /* bumped for better AA contrast on real text */

  /* lines */
  --line:        rgba(255, 255, 255, .07);
  --line-strong: rgba(255, 255, 255, .13);

  /* accent */
  --accent:       #6d5efc;
  --accent-2:     #8b5cf6;
  --accent-ink:   #ffffff;
  --accent-soft:  rgba(109, 94, 252, .15);
  --accent-line:  rgba(109, 94, 252, .45);
  --grad:         linear-gradient(135deg, #6d5efc 0%, #8b5cf6 60%, #a78bfa 100%);

  /* status */
  --ok:        #34d399;
  --ok-soft:   rgba(52, 211, 153, .14);
  --warn:      #fbbf24;
  --warn-soft: rgba(251, 191, 36, .14);
  --danger:    #f87171;
  --danger-soft: rgba(248, 113, 113, .12);

  /* shape */
  --radius-sm: 10px;
  --radius:    14px;
  --radius-lg: 20px;
  --radius-xl: 26px;

  /* spacing scale (use instead of magic px gaps/margins) */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px;  --space-4: 16px;
  --space-5: 20px; --space-6: 28px; --space-7: 40px;

  /* shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 4px 16px rgba(0, 0, 0, .35), 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .55);
  --shadow-accent: 0 8px 24px rgba(109, 94, 252, .35);

  --font: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
          sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background-color: var(--bg);
  /* atmospheric depth: a soft violet glow up top, fading into deep neutral */
  background-image:
    radial-gradient(1100px 520px at 50% -8%, var(--bg-glow), transparent 70%),
    radial-gradient(800px 600px at 100% 0%, rgba(139, 92, 246, .07), transparent 60%);
  background-attachment: fixed;
  min-height: 100vh;
}

button { font: inherit; cursor: pointer; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
/* readable wrapping: balance heading lines, avoid body orphans */
h1, h2, h3 { text-wrap: balance; }
p, .sub, .hint { text-wrap: pretty; }
::selection { background: rgba(109, 94, 252, .35); color: #fff; }

/* thin custom scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }

.hidden { display: none !important; }
.spacer { flex: 1; }

/* ----- eyebrow / section labels -------------------------------------------- */
.eyebrow {
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: 11px;
  font-weight: 700;
  color: var(--faint);
}

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 14px clamp(14px, 4vw, 30px);
  background: rgba(11, 12, 16, .72);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand .dot {
  width: 26px; height: 26px; border-radius: 8px; background: var(--grad);
  box-shadow: var(--shadow-accent), inset 0 1px 0 rgba(255, 255, 255, .35);
  position: relative;
}
.brand .dot::after {
  content: "▶"; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 10px; color: #fff; padding-left: 2px;
}
.brand b { font-weight: 700; }
.brand .sub { color: var(--faint); font-weight: 500; font-size: 13px; letter-spacing: 0; }

.icon-btn {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-sm); padding: 9px 13px; color: var(--ink);
  display: inline-flex; align-items: center; gap: 7px; font-weight: 500; font-size: 14px;
  transition: border-color .15s, background .15s, transform .1s, color .15s;
}
.icon-btn:hover { border-color: var(--accent-line); background: var(--surface-3); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.icon-btn:active { transform: translateY(0) scale(.96); box-shadow: none; }

.topbar .icon-btn { border-color: transparent; background: transparent; color: var(--muted); padding: 8px 12px; }
.topbar .icon-btn:hover { background: var(--surface-2); color: var(--ink); box-shadow: none; transform: none; }
.topbar .icon-btn[data-icon] .ic-host { color: var(--muted); transition: color .15s; }
.topbar .icon-btn[data-icon]:hover .ic-host { color: var(--ink); }

.group-title { font-size: 12px; font-weight: 700; color: var(--ink); text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 16px 0; opacity: 0.8; }

/* ==========================================================================
   Layout
   ========================================================================== */
main { max-width: 1120px; margin: 0 auto; padding: clamp(18px, 4vw, 40px) clamp(14px, 4vw, 32px); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.pad { padding: clamp(18px, 3.2vw, 30px); }
.stack > * + * { margin-top: 22px; }

.screen-title { font-size: 30px; line-height: 1.15; font-weight: 700; margin: 6px 0 4px; letter-spacing: -.03em; }
.screen-sub { color: var(--muted); margin: 0 0 4px; font-size: 14px; }

label.field, .field {
  display: block; margin-bottom: 8px; font-size: 13px; font-weight: 500;
  color: var(--muted); letter-spacing: .01em;
}
.hint { color: var(--faint); font-size: 13.5px; margin: 8px 0 0; line-height: 1.5; }
.hint code, code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: .9em; }

.row { display: flex; gap: 20px; flex-wrap: wrap; }
.row > .col { flex: 1 1 180px; min-width: 0; }
.form-divider { height: 1px; background: var(--line); margin: 24px 0; border: none; }

/* ==========================================================================
   Form controls (themed globally so JS-built nodes inherit)
   ========================================================================== */
textarea, select, input.text,
input[type="text"], input[type="number"], input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  background: var(--surface-2);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s, background .15s;
  appearance: none;
}
textarea { resize: vertical; line-height: 1.55; }
textarea::placeholder, input::placeholder { color: var(--faint); }

select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px; cursor: pointer;
}
select option { background: var(--surface); color: var(--ink); }

textarea:focus, select:focus, input:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface-2);
}
:focus-visible { outline: none; }
.icon-btn:focus-visible, .btn-primary:focus-visible, .btn-ghost:focus-visible,
.tool-btn:focus-visible, .segmented button:focus-visible, .seg2 button:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-soft); border-color: var(--accent-line);
}

#script {
  min-height: 172px; font-size: 16px; padding: 15px 17px; border-radius: var(--radius);
}

/* color input (overlay editor) */
input[type="color"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 40px; padding: 4px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 6px; }
input[type="range"] { accent-color: var(--accent); width: 100%; }

/* segmented controls */
.segmented, .seg2 {
  display: inline-flex; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 4px; gap: 4px;
}
.seg2 { display: flex; width: 100%; }
.segmented button, .seg2 button {
  border: 0; background: transparent; color: var(--muted);
  padding: 9px 18px; border-radius: 8px; /* concentric: 12px group − 4px pad */ font-weight: 600; font-size: 14px;
  transition: color .15s, background .15s, box-shadow .15s; white-space: nowrap;
}
.seg2 button { flex: 1; }
.segmented button:hover, .seg2 button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"], .seg2 button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--line-strong);
}

/* toggle */
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 14px; font-weight: 600; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { width: 44px; height: 26px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line-strong); position: relative; transition: background .18s, border-color .18s; flex: 0 0 auto; }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.toggle input:checked + .track { background: var(--accent); border-color: transparent; }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn-primary {
  width: 100%; border: 0; border-radius: var(--radius); padding: 15px 20px;
  background: var(--grad); color: var(--accent-ink); font-weight: 700; font-size: 15.5px;
  letter-spacing: .01em; box-shadow: var(--shadow-accent);
  transition: transform .12s, box-shadow .15s, filter .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(109,94,252,.5); filter: brightness(1.08); }
.btn-primary:active { transform: translateY(0) scale(.96); box-shadow: 0 4px 12px rgba(109,94,252,.3); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; filter: saturate(.6); }

.btn-ghost {
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink);
  border-radius: var(--radius-sm); padding: 11px 16px; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; gap: 8px; transition: border-color .15s, background .15s, transform .1s;
}
.btn-ghost:hover { border-color: var(--accent-line); background: var(--surface-3); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.btn-ghost:active { transform: translateY(0) scale(.96); box-shadow: none; }
/* post-save confirmation: green check + label, button held disabled for ~10s */
.btn-ghost.saved-ok, .btn-ghost.saved-ok:hover {
  color: var(--ok); border-color: rgba(52, 211, 153, .35); background: var(--ok-soft);
  cursor: default; opacity: 1; transform: none;
}

.disclosure-btn {
  background: none; border: 0; color: var(--accent); font-weight: 600; font-size: 14px;
  padding: 6px 0; display: inline-flex; gap: 7px; align-items: center; position: relative;
}
/* ~40px tap height for the text-only disclosure toggle */
.disclosure-btn::before { content: ""; position: absolute; inset: -4px 0; }
.disclosure-btn:hover { color: var(--accent-2); }
.disclosure-btn .caret { transition: transform .18s; display: inline-block; }
.disclosure-btn[aria-expanded="true"] .caret { transform: rotate(90deg); }

/* ==========================================================================
   AI scriptwriter block
   ========================================================================== */
.sw-block {
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 2.6vw, 22px);
  background:
    radial-gradient(120% 140% at 0% 0%, var(--accent-soft), transparent 55%),
    var(--surface-2);
  position: relative; overflow: hidden;
}
.sw-head { display: flex; align-items: center; gap: 11px; margin-bottom: 4px; }
.sw-badge {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: var(--grad); color: #fff; font-size: 15px; box-shadow: var(--shadow-accent); flex: 0 0 auto;
}
.sw-title { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.sw-block .seg2 { margin: 14px 0 14px; }
#sw-text { min-height: 96px; font-size: 15px; }
.sw-extra { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; }
.sw-extra .col { flex: 1 1 150px; min-width: 0; }
#sw-status { display: flex; align-items: center; gap: 8px; margin-top: 12px; min-height: 18px; font-size: 13px; color: var(--muted); }
#sw-status.err { color: var(--danger); }
#sw-status.ok { color: var(--ok); }
.sw-actions { display: flex; gap: 12px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.sw-actions .btn-primary { width: auto; padding: 12px 20px; }

/* ==========================================================================
   Advanced scenes
   ========================================================================== */
#advanced { margin-top: 14px; }
.scene-card {
  border: 1px solid transparent; border-radius: var(--radius-lg);
  padding: 18px; background: var(--surface-2); transition: border-color .15s, box-shadow .2s, transform .15s, background-color .2s;
  border-left: 3px solid var(--accent);
}
.scene-card:nth-child(even) {
  background: var(--surface);
  border-left-color: var(--accent-2);
}
.scene-card + .scene-card { margin-top: 18px; }
.scene-card:hover { border-color: var(--accent-line); background: var(--surface-3); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.scene-card.dragging { opacity: .4; box-shadow: var(--shadow-lg); }
.scene-card .scene-head { display: flex; align-items: center; gap: 11px; margin-bottom: 12px; }
.drag-handle { cursor: grab; color: var(--faint); font-size: 17px; padding: 0 4px; line-height: 1; }
.drag-handle:active { cursor: grabbing; }
.scene-num { font-weight: 700; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.scene-head select { max-width: 190px; }
.remove-x { margin-left: auto; border: 1px solid var(--line); background: var(--surface); color: var(--danger); font-weight: 700; font-size: 14px; width: 30px; height: 30px; border-radius: 8px; line-height: 1; transition: background .15s, border-color .15s; }
.remove-x:hover { background: var(--danger-soft); border-color: var(--danger); }
/* 40x40 hit area for the standalone scene-delete button (visual size stays 30px);
   NOT applied to the corner remove-x in .actor-cell/.lib-cell — it would overlap the cell's own click surface */
.scene-head .remove-x { position: relative; }
.scene-head .remove-x::before { content: ""; position: absolute; inset: -5px; }
/* uploaded-image previews: large enough to actually see the product/reference.
   Subtle white outline (dark UI) + concentric radius per the interface guidelines. */
.thumb { width: 124px; height: 124px; object-fit: cover; border-radius: 12px;
  outline: 1px solid rgba(255,255,255,.10); outline-offset: -1px;
  border: 1px solid var(--line-strong); margin-top: 10px; display: block; }
/* the generated/uploaded actor still — a 9:16 portrait card, clearly visible */
#actor-thumb img.thumb { width: 184px; height: 327px; max-width: none; max-height: none; }
input[type="file"] { font-size: 13px; color: var(--muted); }
input[type="file"]::file-selector-button { font: inherit; font-weight: 600; margin-right: 10px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; transition: border-color .15s, background .15s; }
input[type="file"]::file-selector-button:hover { border-color: var(--accent-line); background: var(--surface-3); }

/* ==========================================================================
   Progress
   ========================================================================== */
.stages { display: flex; gap: 10px; margin: 20px 0; }
.stage {
  flex: 1; text-align: center; padding: 13px 6px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--faint); font-weight: 600; font-size: 13px;
  border: 1px solid var(--line); position: relative;
  transition: background .25s, color .25s, border-color .25s;
}
.stage::before { content: "●"; display: block; font-size: 9px; margin-bottom: 5px; opacity: .5; }
.stage.active { background: var(--accent-soft); color: #c4bbff; border-color: var(--accent-line); }
.stage.active::before { content: "◌"; opacity: 1; animation: pulse 1.2s ease-in-out infinite; }
.stage.done { background: var(--ok-soft); color: var(--ok); border-color: rgba(52,211,153,.35); }
.stage.done::before { content: "✓"; opacity: 1; }
@keyframes pulse { 50% { opacity: .35; } }

.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; width: 0%; background: var(--grad); border-radius: 999px; transition: width .5s ease; box-shadow: 0 0 12px rgba(109,94,252,.6); }
.progress-text { margin-top: 14px; color: var(--muted); display: flex; align-items: center; gap: 9px; font-size: 14px; font-variant-numeric: tabular-nums; }

.error-box { background: var(--danger-soft); border: 1px solid rgba(248,113,113,.35); color: #fecaca; border-radius: var(--radius); padding: 16px; }
.error-box .err-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

/* skeleton shimmer */
.skeleton { background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ==========================================================================
   Result / editor
   ========================================================================== */
.result-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.editor { display: flex; gap: 30px; align-items: flex-start; }
.editor .preview-col { flex: 0 0 auto; }
.editor .tools-col { flex: 1; min-width: 0; }

/* phone / reel device frame */
.device {
  position: relative; width: 300px; padding: 11px; border-radius: var(--radius-xl);
  background: linear-gradient(160deg, #23262f, #0f1116);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,.06);
}
.device::before { /* speaker / notch */
  content: ""; position: absolute; top: 19px; left: 50%; transform: translateX(-50%);
  width: 52px; height: 5px; border-radius: 99px; background: rgba(255,255,255,.14); z-index: 3;
}
.stage-wrap {
  position: relative; width: 100%; aspect-ratio: 9 / 16; background: #000;
  border-radius: 15px; /* concentric: 26px device − 11px pad */ overflow: hidden; border: 1px solid #000;
}
.stage-wrap video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.overlay-layer { position: absolute; inset: 0; pointer-events: none; }
.ov-box {
  position: absolute; transform: translate(-50%, -50%); pointer-events: auto;
  background: #FFD400; color: #111; font-weight: 700; font-size: 13px;
  padding: 6px 10px; border-radius: 8px; cursor: grab; max-width: 84%;
  box-shadow: 0 2px 10px rgba(0,0,0,.4); white-space: pre-wrap; text-align: center; line-height: 1.25;
}
.ov-box:active { cursor: grabbing; }
.ov-box.sel { outline: 2px solid #fff; box-shadow: 0 0 0 4px var(--accent-soft), 0 2px 10px rgba(0,0,0,.4); }
.ov-box .ov-del { position: absolute; top: -10px; right: -10px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--surface); background: var(--danger); color: #fff; font-size: 11px; line-height: 16px; padding: 0; }

.device-caption { text-align: center; color: var(--faint); font-size: 12px; margin-top: 14px; letter-spacing: .02em; }

/* toolbar */
.toolbar { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); }
.tool-btn {
  border: 1px solid transparent; background: var(--surface-2); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  min-width: 104px; transition: border-color .2s, background .2s, transform .15s, box-shadow .2s;
}
.tool-btn:hover { border-color: var(--accent-line); background: var(--surface); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.15); }
.tool-btn:active { transform: translateY(0) scale(.96); box-shadow: none; }
.tool-btn[aria-pressed="true"] { border-color: var(--accent-line); background: var(--accent-soft); }
.tool-btn .ti-ic { color: var(--muted); }
.tool-btn[aria-pressed="true"] .ti-ic { color: var(--accent); }
.tool-btn.download .ti-ic { color: #fff; }
.tool-btn .t-name { font-weight: 700; font-size: 14px; }
.tool-btn .t-cost { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-variant-numeric: tabular-nums; }
.tool-btn .t-cost.free { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.tool-btn .t-cost.slow { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.tool-btn.download { background: var(--grad); color: #fff; border-color: transparent; box-shadow: var(--shadow-accent); }
.tool-btn.download .t-cost { color: #fff; background: rgba(255,255,255,.18); border-color: transparent; }
.tool-btn.download:hover { filter: brightness(1.05); }

.tool-panel { margin-top: 18px; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; background: var(--surface-2); }
.tool-panel h3 { margin: 0 0 14px; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.field-row { margin-bottom: 14px; }
.field-row:last-of-type { margin-bottom: 0; }

/* ==========================================================================
   Toast + spinner
   ========================================================================== */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(8px);
  background: var(--surface); color: var(--ink); padding: 12px 18px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); box-shadow: var(--shadow-lg); z-index: 60; font-size: 14px;
  max-width: 90vw; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast:not(.hidden) { opacity: 1; transform: translateX(-50%) translateY(0); }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; vertical-align: -3px; flex: 0 0 auto; }
.spinner.dark { border-color: var(--line-strong); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Settings popover + drawer + backdrop
   ========================================================================== */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(5,6,9,.6); backdrop-filter: blur(2px); z-index: 40; }
.panel-pop { position: fixed; top: 70px; right: clamp(8px, 4vw, 24px); width: min(380px, 92vw); z-index: 50; padding: 22px; }
.panel-pop h3 { margin: 0 0 14px; font-size: 16px; font-weight: 700; }

.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(400px, 94vw);
  background: var(--surface); z-index: 50; box-shadow: var(--shadow-lg);
  padding: 22px; overflow-y: auto; border-left: 1px solid var(--line-strong);
}
.drawer-head { display: flex; align-items: center; margin-bottom: 18px; }
.drawer-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.vid-item { display: flex; align-items: center; gap: 11px; padding: 14px; border: 1px solid transparent; border-radius: var(--radius-lg); background: var(--surface-2); transition: border-color .2s, background .2s, transform .15s; }
.vid-item:hover { border-color: var(--accent-line); background: var(--surface); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.vid-item + .vid-item { margin-top: 11px; }
.vid-item .vi-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 14px; }
.vid-item .vi-meta { font-size: 12px; color: var(--faint); margin-top: 2px; }
.empty-state { text-align: center; padding: 36px 16px; color: var(--faint); }
.empty-state .ico { font-size: 30px; opacity: .6; display: block; margin-bottom: 10px; }

/* entrance animation for screens */
.screen-enter { animation: rise .35s cubic-bezier(.16,.84,.44,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 760px) {
  .editor { flex-direction: column; align-items: stretch; }
  .editor .preview-col { align-self: center; }
  .device { width: min(300px, 86vw); }
  .stages { gap: 6px; }
  .stage { font-size: 11px; padding: 11px 4px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ==========================================================================
   Cost pill ("собівартість") — derived current production cost
   ========================================================================== */
.cost-box { position: relative; }
.cost-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  color: var(--ink); font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.cost-pill:hover { background: var(--surface-3); }
.cost-pill .cost-label { color: var(--muted); font-weight: 600; }
.cost-pill .cost-amount { color: var(--ink); font-weight: 700; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.cost-pill .cost-caret { color: var(--faint); font-size: 11px; }
.cost-detail {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20;
  width: 280px; max-width: 78vw; padding: 12px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.cost-detail .cost-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.cost-row { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; }
.cost-row span:first-child { color: var(--muted); }
.cost-row span:last-child { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.cost-note { color: var(--faint); font-size: 11px; line-height: 1.45; margin: 0; }
/* spend journal (cost-modal): one record per line, no wrap, aligned numbers */
.cj-row { display: flex; align-items: baseline; gap: 10px; padding: 7px 2px; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: 13px; }
.cj-row:last-child { border-bottom: 0; }
.cj-left { display: flex; align-items: baseline; gap: 8px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.cj-left b { flex: 0 0 auto; color: var(--ink); font-weight: 600; }
.cj-model { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.cj-right { flex: 0 0 auto; color: var(--faint); font-variant-numeric: tabular-nums; }
.cj-right .cj-cost { color: var(--ink); font-weight: 600; }
/* beta tools gate: BETA_FEATURES=0 -> the server reports beta off -> body.beta-off hides them */
.beta-off .beta-only { display: none !important; }

/* ── redesign: language switch, stepper, source cards, brief bar ─────────── */
.lang-switch { display: inline-flex; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 2px; margin-right: 6px; }
.lang-switch button { border: 0; background: transparent; color: var(--muted); font: 600 11.5px/1 var(--font); padding: 6px 9px; border-radius: 999px; cursor: pointer; position: relative; }
/* ~40px tap height; vertical-only so adjacent language pills don't overlap */
.lang-switch button::before { content: ""; position: absolute; inset: -9px 0; }
.lang-switch button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); }

.step-label { font: 700 13px/1.2 var(--font); letter-spacing: .02em; color: var(--accent); text-transform: uppercase; margin: 0 0 4px; }

.source-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-top: 14px; }
@media (max-width: 720px) { .source-cards { grid-template-columns: 1fr; } }
.source-card { text-align: left; display: flex; flex-direction: column; gap: 6px; padding: 20px; cursor: pointer;
  background: var(--surface-2); border: 1px solid transparent; border-radius: var(--radius-lg); transition: border-color .2s, transform .15s, box-shadow .2s; }
.source-card:hover { background: var(--surface); border-color: var(--accent-line); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
.source-card:active { transform: translateY(0) scale(.98); }
.sc-title { font: 600 16px/1.2 var(--font); color: var(--ink); letter-spacing: -0.01em; }
.sc-desc { font-size: 13.5px; line-height: 1.5; color: var(--faint); margin-top: 4px; }

.src-panel { margin-top: 4px; }
.brief-bar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 22px; margin-top: 14px; margin-bottom: 18px; }
.io-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.io-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
.log-summary { font-size: 12.5px; color: var(--muted); padding: 8px 0 12px; border-bottom: 1px solid var(--line); margin-bottom: 10px; font-variant-numeric: tabular-nums; }

/* projects home + studio header */
.proj-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 4px 0 14px; }
.proj-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; align-items: start; }
.proj-card { border: 1px solid transparent; border-radius: var(--radius-lg); background: var(--surface-2); transition: border-color .2s, transform .15s, box-shadow .2s; }
.proj-card:hover { border-color: var(--accent-line); background: var(--surface); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
/* staggered entrance */
.proj-list .proj-card { animation: rise .32s cubic-bezier(.16,.84,.44,1) both; }
.proj-list .proj-card:nth-child(1) { animation-delay: 0ms; }
.proj-list .proj-card:nth-child(2) { animation-delay: 40ms; }
.proj-list .proj-card:nth-child(3) { animation-delay: 80ms; }
.proj-list .proj-card:nth-child(4) { animation-delay: 120ms; }
.proj-list .proj-card:nth-child(5) { animation-delay: 160ms; }
.proj-list .proj-card:nth-child(6) { animation-delay: 200ms; }
.proj-list .proj-card:nth-child(n+7) { animation-delay: 240ms; }
/* skeleton placeholder card (shown while the list loads) */
.proj-card.is-skeleton { pointer-events: none; animation: none; }
.proj-card.is-skeleton .proj-cover { background: var(--surface-2); }
.sk-line { height: 11px; border-radius: 6px; margin-top: 9px; }
.sk-line.w60 { width: 60%; } .sk-line.w40 { width: 40%; }
/* richer empty state */
.empty-state .ico .ic { width: 30px; height: 30px; }
.empty-state .es-sub { font-size: 13px; color: var(--faint); margin: 6px 0 16px; max-width: 360px; margin-inline: auto; }
.proj-cover { position: relative; aspect-ratio: 9 / 16; background: var(--surface); display: flex; align-items: center; justify-content: center; cursor: pointer; overflow: hidden; border-radius: var(--radius) var(--radius) 0 0; }
.proj-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.proj-cover-ph { font-size: 30px; opacity: .4; }
.proj-card-body { padding: 10px 11px 11px; }
.proj-card-body .vi-title { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-card-body .vi-meta { font-size: 11px; color: var(--faint); margin-top: 3px; }
.proj-card-actions { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 12px; }
.btn-ghost.sm, .icon-btn.sm { width: auto; padding: 6px 11px; font-size: 12.5px; }
.proj-menu-wrap { position: relative; }
.proj-menu { position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 20;
  min-width: 168px; padding: 6px; display: flex; flex-direction: column; gap: 2px;
  background: var(--surface-3); border: 1px solid var(--line-strong);
  border-radius: var(--radius); /* concentric: 8px items + 6px pad */ box-shadow: var(--shadow-lg); }
.proj-menu-item { text-align: left; width: 100%; padding: 9px 11px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink); font-size: 13px; font-weight: 500; }
.proj-menu-item:hover { background: var(--surface); }
.proj-menu-item:last-child { color: var(--danger); }

/* generation splash overlay */
.gen-overlay { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center;
  padding: var(--space-4); background: rgba(8,9,12,.66);
  backdrop-filter: saturate(120%) blur(8px); -webkit-backdrop-filter: saturate(120%) blur(8px);
  animation: gen-fade .2s ease both; }
@keyframes gen-fade { from { opacity: 0; } to { opacity: 1; } }
.gen-splash { position: relative; width: 100%; max-width: 640px; text-align: center; box-shadow: var(--shadow-lg); }
.gen-splash h2 { font-size: 20px; font-weight: 700; margin: var(--space-4) 0 0; letter-spacing: -.02em; }
.gen-splash .hint { margin-top: var(--space-2); }
.gen-spinner { width: 54px; height: 54px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--line-strong); border-top-color: var(--accent); animation: gen-spin .8s linear infinite; }
@keyframes gen-spin { to { transform: rotate(360deg); } }
.gen-actions { display: flex; gap: var(--space-2); justify-content: center; flex-wrap: wrap; margin-top: var(--space-4); }
@media (prefers-reduced-motion: reduce) { .gen-spinner { animation-duration: .001ms; } }

/* voice preview player (native audio, dark via color-scheme) */
.voice-audio { width: 100%; height: 34px; margin-top: var(--space-2); color-scheme: dark; }

/* voice browser (modal results list) */
.vb-results { margin-top: var(--space-3); max-height: 50vh; overflow: auto; }
.vb-row { display: flex; justify-content: space-between; align-items: center;
  gap: var(--space-3); padding: var(--space-2) var(--space-1);
  border-bottom: 1px solid rgba(255, 255, 255, .08); }
.vb-info { display: flex; flex-direction: column; min-width: 0; }
.vb-info b { font-weight: 600; }
.vb-info .hint { text-transform: capitalize; }
.vb-actions { display: flex; gap: var(--space-2); align-items: center; flex: none; }

/* inline (Lucide) icons */
.ic { display: block; }
.ic-host { display: inline-flex; align-items: center; }
button[data-icon], a[data-icon] { display: inline-flex; align-items: center; gap: var(--space-2); }
.icon-btn[data-icon] .ic-host { color: var(--muted); }
.icon-btn[data-icon]:hover .ic-host { color: var(--ink); }
.source-card .sc-ic { color: var(--accent); margin-bottom: var(--space-2); }
.tool-main .sc-ic { color: var(--accent); }
.proj-cover-ph .ic { width: 30px; height: 30px; }

/* ==========================================================================
   Studio page (/studio) — uses the shared design system
   ========================================================================== */
.studio-wrap { max-width: 1160px; margin: 0 auto; padding: clamp(18px,4vw,40px) clamp(14px,4vw,32px) 96px; }
.studio-wrap > .card { margin-bottom: var(--space-4); }
.tab-panel > .card { margin-bottom: var(--space-4); }
/* Setup tab: two-column canvas — core inputs (left) stay the primary path,
   enhancements (right) remain in view via sticky, so no context is lost */
.setup-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: var(--space-4); align-items: start; }
.setup-col > .card { margin-bottom: var(--space-4); }
.setup-col-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 var(--space-2); }
.setup-col-extras { position: sticky; top: 76px; } /* 76 = sticky topbar (~56) + breathing room */
@media (max-width: 1023px) {
  .setup-grid { grid-template-columns: 1fr; }
  .setup-col-extras { position: static; }
}
/* stage tabs (Setup / Scenes / Generate & versions) */
.tabbar { display: flex; gap: var(--space-1); margin-bottom: var(--space-4);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 4px; }
.tabbar .tab { flex: 1; padding: 10px 12px; border: 0; border-radius: 6px; /* concentric: 10px bar − 4px pad */
  background: transparent; color: var(--muted); font-weight: 600; font-size: 14px;
  white-space: nowrap; transition: color .15s, background .15s; }
.tabbar .tab:hover { color: var(--ink); }
.tabbar .tab.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.studio-wrap h2 { font-size: 18px; font-weight: 700; margin: 0 0 var(--space-1); letter-spacing: -.01em; }
.studio-wrap .sub { color: var(--muted); font-size: 13px; margin: 0 0 var(--space-4); }
.modelrow { gap: var(--space-2); align-items: center; margin-top: var(--space-2); }
/* the three translate controls (scope + language + button) stay together as one right-aligned group
   on one line, wrapping as a unit — instead of the language/button dropping to a separate line */
.translate-group { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.translate-group select.text { width: auto; }
.thumbrow { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-2); }
.thumbcell { position: relative; }
.actor-gallery { align-items: center; }
/* selectable actor thumbnail (gallery + per-scene picker) */
.actor-cell { position: relative; width: 56px; height: 56px; border-radius: 10px; overflow: hidden;
  border: 2px solid var(--line); cursor: pointer; display: flex; align-items: center;
  justify-content: center; background: var(--surface); flex: none;
  transition: border-color .15s, transform .12s cubic-bezier(0.2, 0, 0, 1); }
.actor-cell.on { border-color: var(--accent, #6d5efc); }
.actor-cell:active { transform: scale(0.96); }   /* tactile feedback on tap (never below 0.95) */
.actor-cell img.thumb { width: 100%; height: 100%; max-width: none; max-height: none;
  object-fit: cover; margin: 0; border: 0; border-radius: 0; }
.actor-cell .actor-ph { color: var(--faint, #7a8092); font-weight: 700; }
.actor-cell .remove-x { position: absolute; top: 0; right: 0; width: 18px; height: 18px;
  font-size: 11px; border-radius: 0 0 0 8px; margin: 0; }
/* the actor PALETTE shows real people — give those cells a readable 9:16 portrait size
   (the compact per-scene pickers keep the small default above). */
.actor-gallery .actor-cell { width: 76px; height: 116px; border-radius: 12px; }
.actor-gallery .actor-cell .actor-ph { font-size: 18px; }
.actor-gallery .actor-cell .remove-x { width: 22px; height: 22px; font-size: 13px; }

/* named-location palette cell: a thumbnail + an @name input + remove */
.loc-cell { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); }
.loc-cell img.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.loc-cell .loc-name { width: 110px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg, #fff); font-size: 13px; }
.loc-cell .remove-x { width: 24px; height: 24px; font-size: 12px; margin: 0; }
/* per-scene location PICKER: a thumbnail tile with the @name as a readable caption UNDERNEATH
   (never overlaid on the image — that clipped the name over the photo). */
.loc-pick { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: none; }
.loc-pick-name { max-width: 72px; font-size: 10px; line-height: 1.2; text-align: center;
  color: var(--faint, #7a8092); word-break: break-word; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
/* "regenerate but keep the next continued scene" modifier next to the scene's regen button */
.keepnext { display: inline-flex; align-items: center; gap: 4px; font-size: 12px;
  color: var(--faint, #7a8092); cursor: pointer; user-select: none; white-space: nowrap; }
.keepnext input { margin: 0; cursor: pointer; }
/* @mention autocomplete popover */
.mention-pop { background: var(--surface, #fff); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 4px; max-height: 240px; overflow: auto; }
.mention-it { padding: 6px 10px; border-radius: 6px; /* concentric: 10px pop − 4px pad */ font-size: 13px; cursor: pointer; white-space: nowrap; }
.mention-it:hover { background: var(--accent-soft, #eef0ff); }

/* media library picker modal */
.lib-btns { display: inline-flex; gap: 6px; margin-left: 6px; }
.lib-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 100;
  display: flex; align-items: center; justify-content: center; }
.lib-panel { background: var(--surface, #fff); border: 1px solid var(--line); border-radius: 14px;
  width: min(680px, 92vw); max-height: 82vh; overflow: auto; padding: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.lib-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
.lib-cell { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  cursor: pointer; background: var(--bg, #fff); display: flex; flex-direction: column; }
.lib-cell img.thumb { width: 100%; height: 110px; object-fit: cover; }
.lib-cell:hover { border-color: var(--accent, #6d5efc); }
.lib-cell .lib-name { font-size: 12px; padding: 5px 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-cell .remove-x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; font-size: 12px; margin: 0; }
.lib-cell .lib-name-input { width: 100%; border: none; border-top: 1px solid var(--line); padding: 5px 7px;
  font-size: 12px; background: transparent; color: inherit; }
.lib-manager { width: min(900px, 94vw); }
/* yes/no confirm dialog */
.confirm-panel { background: var(--surface, #fff); border: 1px solid var(--line); border-radius: 14px;
  width: min(420px, 92vw); padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.confirm-danger { color: var(--danger, #d64545); border-color: var(--danger, #d64545); }
/* 4-keyframe variant picker: large 9:16 previews — click the photo to zoom, button to pick */
.variant-cell { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); }
.variant-cell img { width: 150px; height: 267px; object-fit: cover; border-radius: 12px;
  border: 1px solid var(--line-strong); outline: 1px solid rgba(255,255,255,.10); outline-offset: -1px;
  cursor: zoom-in; display: block; }
.variant-cell .btn-primary { width: auto; }
/* version history rows */
.ver-row { display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-1); border-bottom: 1px solid var(--line); }
.ver-row.on { background: var(--accent-soft); border-radius: var(--radius-sm); border-bottom-color: transparent; }
.ver-cover { width: 54px; height: 96px; flex: none; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface-2) center/cover no-repeat; }
.ver-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ver-info b { font-weight: 600; font-size: 14px; }
.ver-actions { display: flex; gap: var(--space-1); flex: none; }
/* "add scene here" bar rendered above the first scene and after every scene, so a new scene is
   inserted right where you click. The inter-scene bars are compact + muted so many of them don't
   overwhelm the list; they lift on hover to signal the insertion point. */
.scene-insert { display: flex; gap: var(--space-2); flex-wrap: wrap; margin: var(--space-2) 0; }
.scene-insert.compact { gap: 6px; margin: 6px 0; opacity: .45; transition: opacity .12s; }
.scene-insert.compact:hover { opacity: 1; }
.scene-insert.compact .btn-ghost.sm { padding: 4px 8px; font-size: 12px; }
/* actor-from-URL picker: selectable image cell (ring when chosen) */
/* Projects panel: budget strip + per-card spend/budget (real spend from cost ledgers) */
.spend-summary { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.spend-chip { display: inline-flex; align-items: baseline; gap: 6px; padding: 6px 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; color: var(--muted); }
.spend-chip b { color: var(--ink); font-variant-numeric: tabular-nums; }
.proj-spend { display: flex; align-items: center; gap: var(--space-2); margin-top: 6px; }
.proj-spend-num { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.proj-budget-bar { flex: 1; height: 4px; min-width: 40px; border-radius: 2px;
  background: var(--surface-2); overflow: hidden; }
.proj-budget-bar i { display: block; height: 100%; border-radius: 2px; background: var(--accent);
  transition: width .3s ease; }
.proj-budget-bar.over i { background: var(--warn); }
.user-row { margin: 4px 0; }
.user-balance { font-variant-numeric: tabular-nums; color: var(--ink); font-size: 14px; }

/* Admin panel */
.tnum { font-variant-numeric: tabular-nums; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-3); }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 18px 20px; }
.stat-label { margin: 0 0 6px; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); }
.stat-value { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.02em;
  color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.admin-table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: 0; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.chip-on { color: #4ade80; border-color: rgba(74, 222, 128, .35); }
.chip-off { color: var(--warn); border-color: rgba(251, 191, 36, .35); }
.provider-list { display: flex; flex-direction: column; }
.provider-row { display: flex; justify-content: space-between; gap: var(--space-3);
  padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.provider-row:last-child { border-bottom: 0; }
.provider-row span { color: var(--muted); font-variant-numeric: tabular-nums; }
.price-input { width: 110px; text-align: right; padding: 8px 10px; }
.key-test { margin-left: 8px; }

.lib-cell.url-pick { cursor: pointer; border: 2px solid transparent; border-radius: 10px; position: relative; }
.lib-cell.url-pick.on { border-color: var(--accent, #6c5ce7); }
.url-pick-badge { position: absolute; top: 4px; left: 4px; font-size: 11px; padding: 2px 6px;
  border-radius: 6px; background: rgba(0,0,0,.7); color: #fff; pointer-events: none; }
/* segmented toggle (refined inset look, matches .segmented in the main app) */
.seg { display: inline-flex; gap: var(--space-1); flex-wrap: wrap; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 3px; margin-bottom: var(--space-3); }
.seg button { padding: 7px 14px; border-radius: 7px; /* concentric: 10px group − 3px pad */ border: 1px solid transparent; background: transparent;
  color: var(--muted); font-weight: 600; font-size: 13px; transition: background .15s, color .15s; }
.seg button.on { background: var(--surface); color: var(--ink); border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.gen-bar { position: sticky; bottom: 0; z-index: 5; background: rgba(11,12,16,.82);
  backdrop-filter: saturate(140%) blur(14px); -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-top: 1px solid var(--line); box-shadow: 0 -8px 24px rgba(0,0,0,.3);
  padding: var(--space-3) 0 calc(var(--space-3) + env(safe-area-inset-bottom)); margin-top: var(--space-2); }
@media (max-width: 520px) { .proj-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.studio-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.studio-name { flex: 1; min-width: 160px; max-width: 360px; }
.tool-tabs { display: flex; gap: 6px; }
.tool-tab { font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); position: relative; }
/* ~40px tap height; vertical-only so neighbouring tabs (6px gap) don't overlap */
.tool-tab::before { content: ""; position: absolute; inset: -5px 0; }
.tool-tab.active { background: var(--surface-2); color: inherit; border-color: var(--line-strong); }
.studio-proj-name { font-weight: 600; font-size: 14px; color: var(--muted); }
#tool-cards .source-card { position: relative; }
#tool-cards .source-card.tool-main { border-color: var(--accent-line); background: var(--accent-soft); }
.sc-badge { position: absolute; top: 10px; right: 10px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 999px; padding: 2px 7px; }

.beats-block {
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-lg);
  padding: 20px;
  background: 
    radial-gradient(120% 140% at 0% 0%, var(--accent-soft), transparent 60%), 
    var(--surface-2);
  margin-top: 14px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.25s, box-shadow 0.25s, background-color 0.25s, filter 0.2s;
}
.beats-block:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-accent);
  filter: brightness(1.03);
}

.translate-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  margin-top: var(--space-4);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.translate-block .tb-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.85;
}
.translate-block .translate-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}




/* library scope badges (personal vs global items) */
.lib-scope-chip { position: absolute; top: 6px; left: 6px; font-size: 10px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,.72); color: var(--accent-2);
  border: 1px solid var(--accent-line); pointer-events: none; }
.lib-cell { position: relative; }
.lib-scope-btn { margin-top: 4px; font-size: 11px; padding: 4px 8px; }
