:root {
  --bg: #0e0f13;
  --panel: #171922;
  --panel-2: #1e212c;
  --line: #2a2e3c;
  --text: #e8eaf0;
  --muted: #9aa1b4;
  --accent: #6f8cff;
  --accent-2: #8f6fff;
  --ok: #46c98b;
  --warn: #e8b04b;
  --bad: #f0616d;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 120px;
}

h1 { font-size: 17px; margin: 0; letter-spacing: -0.2px; }
h2 { font-size: 22px; margin: 0; letter-spacing: -0.4px; }
h3 { font-size: 15px; margin: 0 0 2px; }

a { color: var(--accent); }

/* --- chrome --------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 24px;
  background: rgba(14, 15, 19, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.brand .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.topbar-right { display: flex; align-items: center; gap: 8px; }
.project-select {
  width: auto; max-width: 220px; padding: 5px 10px;
  border-radius: 999px; font-size: 13px; color: var(--muted);
}
.project-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); font-size: 13px;
}
.project-bar .name { color: var(--text); font-weight: 600; }
.project-bar input { width: 220px; padding: 6px 10px; }
.credits {
  font-variant-numeric: tabular-nums; color: var(--muted);
  background: transparent;
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 13px;
  cursor: pointer;
}
.credits:hover { color: var(--text); border-color: var(--accent); }
.credits.low { color: var(--warn); border-color: var(--warn); }

.account {
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: transparent; border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px; font-size: 13px; color: var(--muted);
}
.account:hover { color: var(--text); border-color: var(--accent); }

.pack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.pack {
  border: 1px solid var(--line); border-radius: 14px; padding: 18px; text-align: center;
  background: var(--panel);
}
.pack-credits { font-size: 30px; font-weight: 650; margin-top: 8px; font-variant-numeric: tabular-nums; }
.pack button { width: 100%; }

.ledger { width: 100%; border-collapse: collapse; font-size: 13px; }
.ledger th { text-align: left; font-weight: 600; color: var(--muted); padding: 6px 10px; }
.ledger td { padding: 8px 10px; border-top: 1px solid var(--line); vertical-align: top; }
.ledger .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ledger .pos { color: var(--ok); }

.cost {
  font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cost.bad { color: var(--bad); }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }

.ethics {
  margin: 0; padding: 8px 24px;
  font-size: 12.5px; color: var(--muted);
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.ethics strong { color: var(--text); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 28px 24px; }

/* --- layout primitives ---------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: 22px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.spacer { flex: 1; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
}
.card.tight { padding: 14px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* --- controls ------------------------------------------------------------- */

button {
  font: inherit; cursor: pointer; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 9px 16px; transition: filter .15s, opacity .15s;
}
button:hover:not(:disabled) { filter: brightness(1.25); }
button:disabled { opacity: .45; cursor: not-allowed; }

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff; font-weight: 600;
}
button.ghost { background: transparent; padding: 6px 10px; color: var(--muted); }
button.danger { color: var(--bad); }
button.small { padding: 6px 11px; font-size: 13px; }

input, textarea, select {
  font: inherit; width: 100%;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

/* --- steps ---------------------------------------------------------------- */

.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.step-num {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.card.done .step-num { background: var(--ok); border-color: transparent; color: #05170f; }
.card.locked { opacity: .5; }
.card.locked .step-body { display: none; }

/* --- media ---------------------------------------------------------------- */

.thumb {
  width: 100%; aspect-ratio: 2 / 3; object-fit: cover;
  border-radius: 10px; background: var(--panel-2); display: block;
}
.thumb.wide { aspect-ratio: 9 / 16; }
.thumb.square { aspect-ratio: 1 / 1; }

.tile { display: flex; flex-direction: column; gap: 8px; }
.tile .cap { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }

.char-card {
  text-align: left; padding: 10px; display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.char-card:hover { border-color: var(--accent); }

.placeholder {
  width: 100%; aspect-ratio: 2 / 3; border-radius: 10px;
  border: 1px dashed var(--line); display: grid; place-items: center;
  color: var(--muted); font-size: 12.5px; text-align: center; padding: 10px;
}
.placeholder.wide { aspect-ratio: 9 / 16; }

video { width: 100%; border-radius: 10px; background: #000; display: block; }

.dropzone {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 26px; text-align: center; color: var(--muted); cursor: pointer;
}
.dropzone.hot { border-color: var(--accent); color: var(--text); background: var(--panel-2); }

/* --- style picker --------------------------------------------------------- */

.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }

.style-card {
  display: flex; flex-direction: column; gap: 3px; align-items: flex-start;
  text-align: left; padding: 12px 14px; line-height: 1.35;
}
.style-card strong { font-size: 14px; }
.style-card.on {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(111, 140, 255, .16), rgba(143, 111, 255, .12));
}
.style-card.on strong { color: #fff; }

/* selected first frame */
.tile.sel .thumb, .tile.sel .placeholder {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
[data-pick-scene] { cursor: pointer; }

/* --- notice --------------------------------------------------------------- */

.notice {
  border: 1px solid rgba(111, 140, 255, .35);
  background: linear-gradient(135deg, rgba(111, 140, 255, .12), rgba(143, 111, 255, .08));
  border-radius: 12px; padding: 12px 15px; font-size: 13.5px; color: var(--text);
}

/* --- physique ------------------------------------------------------------- */

.sub-card {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 16px;
}

.chip {
  padding: 6px 14px; border-radius: 999px; font-size: 13px;
  background: transparent; color: var(--muted);
}
.chip.on {
  border-color: var(--accent); color: #fff;
  background: linear-gradient(135deg, rgba(111, 140, 255, .22), rgba(143, 111, 255, .16));
}

/* --- hook library --------------------------------------------------------- */

.hook-result { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.hook-line {
  font-size: 15px; line-height: 1.5;
  padding: 12px 14px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
}
.hook-line::first-letter { text-transform: uppercase; }

.hook-list { margin-top: 14px; max-height: 300px; overflow-y: auto; }
.hook-row {
  display: block; width: 100%; text-align: left; margin-bottom: 4px;
  font-size: 13px; line-height: 1.45; padding: 9px 12px;
  background: transparent; color: var(--muted);
}
.hook-row:hover { background: var(--panel); color: var(--text); border-color: var(--accent); }

/* --- toggle --------------------------------------------------------------- */

.toggle {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); font-size: 13.5px; color: var(--muted);
  user-select: none; white-space: nowrap;
}
.toggle input { width: auto; margin: 0; accent-color: var(--accent); }
.toggle:has(input:checked) { color: var(--text); border-color: var(--warn); }

/* --- badges --------------------------------------------------------------- */

.badge {
  font-size: 11.5px; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: rgba(70, 201, 139, .35); }
.badge.run { color: var(--accent); border-color: rgba(111, 140, 255, .4); }
.badge.bad { color: var(--bad); border-color: rgba(240, 97, 109, .4); }

/* --- jobs panel ----------------------------------------------------------- */

.jobs {
  position: fixed; right: 20px; bottom: 20px; z-index: 30; width: 320px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
  overflow: hidden;
}
.jobs-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.jobs.collapsed ul { display: none; }
.jobs ul { list-style: none; margin: 0; padding: 6px; max-height: 300px; overflow: auto; }
.jobs li { padding: 8px 10px; border-radius: 9px; font-size: 13px; }
.jobs li + li { margin-top: 2px; border-top: 1px solid var(--line); }
.jobs li .small { margin-top: 2px; }
.jobs li.row-bad { background: rgba(240, 97, 109, .07); }

.bar { height: 3px; border-radius: 2px; background: var(--panel-2); margin-top: 7px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s; }

/* Kie doesn't report progress for every model — animate rather than sit still,
   so "working" never looks like "stuck". */
.bar.indet > i { width: 40%; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

/* --- toasts --------------------------------------------------------------- */

.toasts { position: fixed; left: 20px; bottom: 20px; z-index: 40; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  padding: 11px 15px; border-radius: 10px; max-width: 420px; font-size: 13.5px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .4);
}
.toast.bad { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }

.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- sign-in gate --------------------------------------------------------- */

/* `display: grid` here is an author rule and `[hidden] { display: none }` is a
   UA rule, so setting `hidden` on this element does nothing without the second
   selector below. The overlay then covers the app permanently, whatever the
   JavaScript decides — which looks exactly like the sign-in never working. */
.gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 24px;
  background: var(--bg);
}
.gate[hidden] { display: none; }
.gate-card {
  display: flex; flex-direction: column; gap: 18px; align-items: center;
  width: 100%; max-width: 420px; min-height: 200px;
}
.gate-card h2 { text-align: center; }
.gate-card > div { width: 100%; display: flex; justify-content: center; }

.portal-link {
  display: inline-block; padding: 10px 18px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 600; text-decoration: none;
}

/* `display` here would override the hidden attribute, exactly as it did on
   .gate itself — that bug cost an afternoon, so the guard is explicit. */
.gate-fallback[hidden] { display: none; }
.gate-fallback {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding-top: 18px; border-top: 1px solid var(--line); width: 100%;
}

.keep { padding: 2px 6px; font-size: 15px; line-height: 1; }
.keep.on { color: var(--warn); }
.expiry { color: var(--warn); }
