:root {
  --bg: #0b0d12;
  --bg-2: #11141c;
  --card: #151926;
  --card-2: #1b2030;
  --line: #262c3d;
  --text: #e8ebf3;
  --muted: #8b93a7;
  --accent: #6d8cff;
  --accent-2: #a97bff;
  --good: #3ecf8e;
  --warn: #f5b544;
  --bad: #ff6b6b;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6fa;
    --bg-2: #eceef5;
    --card: #ffffff;
    --card-2: #f4f6fb;
    --line: #e0e4ee;
    --text: #171a22;
    --muted: #666e83;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 15% -10%, #1a2240 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 26px; }
.topbar h1 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.topbar p { margin: 0; font-size: 12.5px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.pill {
  font-size: 12px; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--line); color: var(--muted);
}
.pill-ok { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.pill-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }

/* ----------------------------------------------------------- layout */
.layout {
  display: grid; grid-template-columns: minmax(340px, 400px) 1fr;
  gap: 18px; padding: 18px 22px 40px; align-items: start;
  max-width: 1600px; margin: 0 auto;
}
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } }

.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.col-output { position: sticky; top: 78px; }
@media (max-width: 980px) { .col-output { position: static; } }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.card.fill { display: flex; flex-direction: column; min-height: calc(100vh - 120px); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* ---------------------------------------------------------- controls */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input[type=text], input[type=url], input[type=password], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 9px;
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  font: inherit; font-size: 14px; outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin: 8px 0; }
.check input { accent-color: var(--accent); }

button {
  font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid transparent;
  padding: 9px 14px; transition: .15s ease;
}
button:disabled { opacity: .45; cursor: not-allowed; }
.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 600; border: none;
}
.primary:not(:disabled):hover { filter: brightness(1.08); }
.ghost { background: var(--card-2); border: 1px solid var(--line); color: var(--text); }
.ghost:not(:disabled):hover { border-color: var(--accent); }
.ghost.danger { color: var(--bad); }
.tiny { padding: 5px 9px; font-size: 12px; }
.big { width: 100%; padding: 12px; font-size: 15px; }

.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.hint a { color: var(--accent); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs.small { margin-bottom: 12px; }
.tab {
  background: none; border: none; color: var(--muted);
  padding: 8px 12px; border-radius: 8px 8px 0 0; font-size: 13.5px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab:disabled { opacity: .35; cursor: not-allowed; }

/* ---------------------------------------------------------- dropzone */
.drop {
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  padding: 26px 16px; text-align: center; cursor: pointer; transition: .15s;
  background: var(--card-2);
}
.drop:hover, .drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--card-2)); }
.drop-icon { font-size: 22px; display: block; margin-bottom: 6px; color: var(--accent); }
.drop p { margin: 0 0 4px; font-size: 14px; }
.drop small { color: var(--muted); font-size: 11.5px; }

#videoEl { width: 100%; border-radius: 10px; background: #000; max-height: 220px; }
.filemeta { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12.5px; }
.filemeta > span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------ chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12.5px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card-2); color: var(--muted);
}
.chip.on { border-color: var(--accent); color: var(--text); background: color-mix(in srgb, var(--accent) 15%, var(--card-2)); }

/* --------------------------------------------------------- progress */
.progress { margin-top: 12px; }
.bar { height: 4px; border-radius: 4px; background: var(--card-2); overflow: hidden; }
#barFill { height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.steps { margin-top: 10px; display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; }
.step { display: flex; gap: 8px; align-items: baseline; color: var(--muted); }
.step .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); flex: none; position: relative; top: -1px; }
.step.run .dot { background: var(--accent); animation: pulse 1.1s infinite; }
.step.run { color: var(--text); }
.step.done .dot { background: var(--good); }
.step.fail .dot { background: var(--bad); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.error {
  margin-top: 12px; padding: 10px 12px; border-radius: 9px; font-size: 13px;
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); color: var(--bad);
  white-space: pre-wrap; word-break: break-word;
}
.usage { margin-top: 10px; font-size: 11.5px; color: var(--muted); font-family: var(--mono); }

/* ---------------------------------------------------------- outputs */
.out-actions { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.panes { flex: 1; overflow: auto; min-height: 0; }
.outpane { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.empty { text-align: center; color: var(--muted); padding: 70px 20px; }
.empty span { font-size: 40px; display: block; margin-bottom: 12px; opacity: .6; }
.empty p { margin: 0 0 6px; }
.empty small { font-size: 12px; }

.block {
  border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 12px; overflow: hidden; background: var(--card-2);
}
.block-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); background: var(--card);
}
.block-head h3 { margin: 0; font-size: 14px; flex: 1; }
.block-body { padding: 12px; }
.prompt-text {
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word; margin: 0;
}
.meta-line { margin-top: 10px; font-size: 12px; color: var(--muted); }
.meta-line code { background: var(--card); padding: 2px 6px; border-radius: 5px; font-size: 11.5px; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 4px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.sec { margin-bottom: 20px; }
.sec > h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--accent); margin: 0 0 8px; padding-bottom: 5px; border-bottom: 1px solid var(--line);
}

table.shots { width: 100%; border-collapse: collapse; font-size: 13px; }
table.shots th, table.shots td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.shots th { color: var(--muted); font-weight: 500; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }

.frames { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.frame { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card-2); }
.frame img { width: 100%; display: block; }
.frame span { display: block; padding: 5px 8px; font-size: 11px; color: var(--muted); font-family: var(--mono); }

#rawOut {
  font-family: var(--mono); font-size: 12px; white-space: pre-wrap;
  word-break: break-word; margin: 0; color: var(--muted);
}

/* ------------------------------------------------------------ modal */
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(0,0,0,.55); backdrop-filter: blur(3px); padding: 20px;
}
.modal-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px; width: min(560px, 100%);
}
.modal-card h2 { margin: 0 0 16px; font-size: 16px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.modal-actions .spacer { flex: 1; }

/* Key diagnostics can be several lines with a command to copy. */
.keymsg:not(:empty) {
  display: block; margin-top: 12px; padding: 10px 12px; border-radius: 9px;
  background: var(--card-2); border: 1px solid var(--line);
  font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  max-height: 260px; overflow: auto; color: var(--muted);
}
.keymsg.bad:not(:empty) {
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 35%, transparent);
  background: color-mix(in srgb, var(--bad) 10%, transparent);
}
.keymsg.ok:not(:empty) { color: var(--good); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--accent); color: var(--text);
  padding: 9px 16px; border-radius: 999px; font-size: 13px; z-index: 60;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
