/* =========================================================
   HTML -> VIDEO STUDIO  |  Styles
   ========================================================= */
:root {
  --bg:        #0a0d14;
  --bg2:       #0d1119;
  --panel:     #111827;
  --panel2:    #151d30;
  --panel3:    #1a2338;
  --border:    #232e48;
  --border2:   #2e3b5c;
  --text:      #e8edf7;
  --muted:     #8d99b4;
  --muted2:    #6b7690;
  --accent:    #f59e0b;
  --accent2:   #8b5cf6;
  --danger:    #ef4444;
  --ok:        #22c55e;
  --grad:      linear-gradient(135deg, #f59e0b 0%, #ec4899 52%, #8b5cf6 100%);
  --radius:    12px;
  --shadow:    0 10px 30px rgba(0,0,0,.45);
  --header-h:  56px;
  --console-h: 190px;
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  overflow: hidden;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #26314d; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #35436a; }

button, input, select { font-family: inherit; font-size: 13px; color: inherit; }

/* ---------------- Layout ---------------- */
#app { display: flex; flex-direction: column; height: 100vh; }

header.topbar {
  height: var(--header-h);
  flex: 0 0 var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: linear-gradient(180deg, #111827 0%, #0c1120 100%);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}

.logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 16px; letter-spacing: .2px;
  white-space: nowrap;
}
.logo .mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--grad);
  display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(236,72,153,.35);
}
.logo .mark svg { display: block; }
.logo .grad-text {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.logo small { display: block; font-size: 10px; font-weight: 600; color: var(--muted2); letter-spacing: .8px; text-transform: uppercase; -webkit-text-fill-color: var(--muted2); }

.topbar .spacer { flex: 1; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 13px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: var(--panel3); border-color: var(--border2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { display: block; }

.btn.primary {
  background: var(--grad);
  border: none;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 4px 16px rgba(236,72,153,.3);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary.busy { position: relative; overflow: hidden; }
.btn.primary.busy::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.35) 50%, transparent 70%);
  background-size: 220% 100%;
  animation: shimmer 1.1s linear infinite;
}
@keyframes shimmer { from { background-position: 180% 0; } to { background-position: -60% 0; } }

.btn.ghost { background: transparent; }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }

select, input[type="number"], input[type="text"] {
  height: 34px; padding: 0 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  width: 100%;
}
select:focus, input:focus { border-color: var(--accent); }
select { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238d99b4' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

/* ---------------- Main columns ---------------- */
main.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

#editorPane {
  width: 36%;
  min-width: 300px;
  border-right: 1px solid var(--border);
  background: var(--bg2);
}

#previewPane { flex: 1; min-width: 320px; background: var(--bg); }

#settingsPane {
  width: 296px;
  flex: 0 0 296px;
  border-left: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
}

.pane-head {
  height: 42px; flex: 0 0 42px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.015);
}
.pane-head .title {
  font-size: 11px; font-weight: 800; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--muted);
}
.pane-head .spacer { flex: 1; }
.pane-head .pv-label {
  font-size: 10.5px; font-weight: 800; letter-spacing: .9px;
  text-transform: uppercase; color: var(--muted2);
}
/* ---------------- Editor ---------------- */
#editorWrap { flex: 1; min-height: 0; position: relative; overflow: hidden; }
#editorWrap .CodeMirror {
  position: absolute; inset: 0;
  height: 100%;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  background: #0b0f1a;
}
.CodeMirror-gutters { background: #0b0f1a !important; border-right: 1px solid #1c2540 !important; }
.CodeMirror-linenumber { color: #4c5a7d !important; }
.CodeMirror-cursor { border-left-color: #f59e0b !important; }
.CodeMirror-selected { background: #233056 !important; }
.CodeMirror-focused .CodeMirror-selected { background: #2b3a6b !important; }
.CodeMirror-activeline-background { background: #141b31 !important; }
.cm-s-dracula.CodeMirror, .cm-s-dracula .CodeMirror-gutters { background: #0b0f1a; }

/* ---------------- Preview ---------------- */
#previewStage {
  flex: 1; min-height: 0;
  position: relative;
  display: flex;
  padding: 22px;
  overflow: hidden;
  background-color: #07090f;
  background-image: radial-gradient(circle, #1a2238 1px, transparent 1px);
  background-size: 26px 26px;
}
/* When zoomed in we scroll instead of clipping; the iframe keeps its
   size via margin:auto so it still centers when it fits. */
#previewStage.zoomable { overflow: auto; }
#frame {
  margin: auto;
  flex: 0 0 auto;
  border: 1px solid var(--border2);
  border-radius: 6px;
  background: #000;
  box-shadow: 0 20px 60px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.04), 0 0 80px rgba(139,92,246,.12);
}

.transport {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.transport .tbtn {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--panel2); border: 1px solid var(--border);
  cursor: pointer; transition: background .15s, border-color .15s;
  flex: 0 0 auto;
}
.transport .tbtn:hover { background: var(--panel3); border-color: var(--border2); }
.transport .tbtn.playing { background: var(--grad); border: none; box-shadow: 0 3px 12px rgba(236,72,153,.35); }

#timeLabel { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--text); min-width: 74px; text-align: center; }
#durLabel  { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--muted2); min-width: 74px; text-align: center; }

.scrub { flex: 1; -webkit-appearance: none; appearance: none; height: 34px; background: transparent; cursor: pointer; }
.scrub::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) var(--fill,0%), #222b44 var(--fill,0%), #222b44 100%);
}
.scrub::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; margin-top: -5px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.scrub::-moz-range-track { height: 6px; border-radius: 3px; background: #222b44; }
.scrub::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
.scrub::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }

.badge {
  font-size: 11px; font-weight: 700; color: var(--muted);
  background: var(--bg2); border: 1px solid var(--border);
  padding: 4px 9px; border-radius: 20px; white-space: nowrap;
}
.badge b { color: var(--text); font-weight: 700; }
/* ---------------- Settings sidebar ---------------- */
.set-section { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.set-section h4 {
  font-size: 11px; font-weight: 800; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--muted); margin-bottom: 12px;
}
.set-row { margin-bottom: 11px; }
.set-row:last-child { margin-bottom: 0; }
.set-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.set-row .hint { font-size: 11px; color: var(--muted2); margin-top: 5px; line-height: 1.45; }

#customResWrap { display: none; gap: 8px; align-items: center; }
#customResWrap input { width: 100%; text-align: center; }
#customResWrap span { color: var(--muted2); }

#estimate {
  margin-top: 4px; font-size: 12px; color: var(--text);
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 11px; line-height: 1.5;
}
#estimate b { color: var(--accent); }

/* ---------------- Console ---------------- */
#consoleBar {
  flex: 0 0 34px; height: 34px; overflow: hidden;
  border-top: 1px solid var(--border);
  background: #0b0f1a;
  transition: flex-basis .22s ease, height .22s ease;
  display: flex; flex-direction: column;
}
#consoleBar.open { flex-basis: var(--console-h); height: var(--console-h); }
#consoleHead {
  flex: 0 0 34px; height: 34px;
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  cursor: pointer; user-select: none;
}
#consoleHead .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px rgba(34,197,94,.7); }
#consoleHead .title { font-size: 11px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
#consoleHead .spacer { flex: 1; }
#consoleBody {
  flex: 1; overflow-y: auto; padding: 4px 14px 10px;
  font-family: 'JetBrains Mono', Consolas, monospace; font-size: 11.5px; line-height: 1.7;
}
.log-line { white-space: pre-wrap; word-break: break-word; }
.log-info  { color: #9fb0d0; }
.log-ok    { color: #4ade80; }
.log-warn  { color: #fbbf24; }
.log-error { color: #f87171; }
/* ---------------- Modals ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: none; align-items: center; justify-content: center;
  background: rgba(4,6,12,.72);
  backdrop-filter: blur(4px);
}
.modal.show { display: flex; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border2);
  border-radius: 16px;
  box-shadow: var(--shadow);
  max-height: 88vh; overflow: hidden;
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 15px; font-weight: 800; }
.modal-head .sub { font-size: 12px; color: var(--muted); }
.modal-head .spacer { flex: 1; }

/* Gallery */
#galleryModal .modal-card { width: min(900px, 92vw); }
#galleryGrid {
  padding: 18px; display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  overflow-y: auto;
}
.tpl-card {
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 12px; padding: 0; overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; text-align: left;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  color: var(--text);
}
.tpl-card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 12px 26px rgba(0,0,0,.4); }
.tpl-thumb { position: relative; aspect-ratio: 16 / 9; background: #07090f; overflow: hidden; }
.tpl-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tpl-thumb-ph { position: absolute; inset: 0; display: grid; place-items: center; background: #0b1020; }
.tpl-thumb-ph span { font-size: 11px; color: var(--muted2); }
.tpl-thumb-ph img { position: static; width: 100%; height: 100%; object-fit: cover; }
.tpl-thumb-fallback { background: linear-gradient(135deg,#1b2440,#2a1a3d); }
.tpl-name { padding: 10px 12px 2px; font-size: 13px; font-weight: 700; }
.tpl-tag  { padding: 0 12px 11px; font-size: 11px; color: var(--muted2); }
.thumb-iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; opacity: 0; pointer-events: none; }

/* Export */
#exportModal .modal-card { width: min(640px, 92vw); }
.export-body { padding: 20px; }
.export-view { display: none; }
.export-view.active { display: block; }
#exportStatus { font-size: 13px; color: var(--muted); margin: 14px 0 10px; }
.progress-track {
  height: 12px; border-radius: 7px; background: #0b1020;
  border: 1px solid var(--border); overflow: hidden;
}
#exportBarFill {
  height: 100%; width: 0%; border-radius: 6px;
  background: var(--grad);
  transition: width .12s linear;
  box-shadow: 0 0 14px rgba(236,72,153,.5);
}
#exportPct { font-size: 26px; font-weight: 800; margin-top: 12px; font-variant-numeric: tabular-nums; }
#exportVideoWrap {
  position: relative;
  display: flex;
  max-height: 340px;
  overflow: auto;
  border-radius: 10px;
  background: #000;
  border: 1px solid var(--border);
}
#exportVideo {
  width: 100%;
  height: auto;
  max-height: none;
  border: 0;
  display: block;
  margin: auto;
  flex: 0 0 auto;
}
.result-tools {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px;
}
.result-tools .rt-label { font-size: 12px; font-weight: 700; color: var(--muted2); }
.result-tools select {
  height: 30px; padding: 0 8px;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer;
}
#exportMeta { font-size: 12px; color: var(--muted); margin: 10px 0 14px; line-height: 1.6; }
#exportErrorMsg { font-size: 13px; color: #fca5a5; background: rgba(239,68,68,.08); border: 1px solid rgba(239,68,68,.3); border-radius: 10px; padding: 12px 14px; line-height: 1.6; }
.export-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* ---------------- Prompt Builder ---------------- */
#promptModal .modal-card { width: min(760px, 92vw); }
.prompt-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.prompt-fields { display: flex; flex-direction: column; gap: 12px; }
.pf { display: flex; flex-direction: column; gap: 6px; font-size: 11.5px; font-weight: 700; color: var(--muted2); }
.pf textarea,
.pf select {
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; outline: none;
  font: inherit; font-size: 13px; font-weight: 500;
}
.pf textarea { resize: vertical; min-height: 66px; line-height: 1.5; }
.pf textarea:focus,
.pf select:focus { border-color: var(--accent); }
.pf-row { display: flex; gap: 12px; }
.pf-row .pf { flex: 1; }
.pf-check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.pf-check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.pf-check i { color: var(--muted2); font-style: normal; font-weight: 500; }
.prompt-context { display: flex; flex-wrap: wrap; gap: 8px; }
.prompt-context .chip {
  font-size: 11.5px; font-weight: 700; color: var(--muted);
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 11px;
}
.prompt-preview-wrap { display: flex; flex-direction: column; gap: 6px; }
.pplabel { display: flex; justify-content: space-between; font-size: 11.5px; font-weight: 700; color: var(--muted2); }
#pfCount { font-variant-numeric: tabular-nums; }
.prompt-preview {
  margin: 0; max-height: 300px; overflow: auto;
  background: #07090f; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px;
  font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  font-size: 11.5px; line-height: 1.65;
  color: #c8d3ee; white-space: pre-wrap; word-break: break-word; tab-size: 2;
}
.prompt-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.prompt-actions .spacer { flex: 1; }

/* ---------------- Preview zoom select ---------------- */
.zoom-select {
  height: 28px; padding: 0 8px;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 11.5px; font-weight: 600;
  cursor: pointer;
}

/* ---------------- Large video viewer (theater) ---------------- */
#theater {
  position: fixed; inset: 0; z-index: 200;
  display: none; align-items: center; justify-content: center;
  background: rgba(4, 6, 12, .96);
}
#theater.show { display: flex; }
#theater video {
  max-width: 96vw; max-height: 92vh;
  border-radius: 10px; background: #000;
  box-shadow: 0 30px 80px rgba(0,0,0,.7);
}
#theater #btnCloseTheater {
  position: absolute; top: 16px; right: 16px;
  background: rgba(20, 26, 44, .85);
}

/* ---------------- Responsive ---------------- */
@media (max-width: 1100px) {
  #editorPane { width: 42%; }
  #settingsPane { width: 250px; flex-basis: 250px; }
}
@media (max-width: 900px) {
  main.workspace { flex-direction: column; overflow-y: auto; }
  #editorPane { width: 100%; min-width: 0; border-right: none; border-bottom: 1px solid var(--border); height: 340px; flex: 0 0 340px; }
  #previewPane { min-height: 320px; }
  #settingsPane { width: 100%; flex-basis: auto; border-left: none; border-top: 1px solid var(--border); }
  .logo small { display: none; }
}



