:root {
  --bg: #0b0e14;
  --bg-2: #121723;
  --bg-3: #19202e;
  --panel: #141a26;
  --border: #26303f;
  --border-2: #313d50;
  --text: #e6ebf2;
  --text-dim: #93a1b5;
  --text-faint: #647285;
  --accent: #7fb3ff;
  --accent-2: #5fc9b7;
  --ok: #43c98b;
  --warn: #f2c14e;
  --fail: #e76f51;
  --info: #a78bfa;
  --running: #7fb3ff;
  --radius: 12px;
  --radius-sm: 8px;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Noto Sans KR", -apple-system, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: rgba(11,14,20,.88); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 800; font-size: 15px; letter-spacing: -.01em; }
.clock { color: var(--text-faint); font-variant-numeric: tabular-nums; font-size: 12px; }
.auto-toggle { color: var(--text-dim); font-size: 12px; display: flex; align-items: center; gap: 4px; }

.view { padding: 20px; max-width: 1500px; margin: 0 auto; }
.loading { color: var(--text-dim); padding: 40px; text-align: center; }

/* ---------- buttons / pills ---------- */
.btn {
  border: 1px solid var(--border-2); background: var(--bg-3); color: var(--text);
  padding: 7px 13px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg-2); border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-accent { background: var(--accent); color: #06101e; border-color: var(--accent); }
.btn-accent:hover { filter: brightness(1.08); }
.btn-ok { background: var(--ok); color: #05130c; border-color: var(--ok); }
.btn-fail { background: var(--fail); color: #1a0805; border-color: var(--fail); }
.btn-sm { padding: 4px 9px; font-size: 12px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
  border: 1px solid var(--border-2); color: var(--text-dim); white-space: nowrap;
}
.pill-muted { color: var(--text-faint); }
.pill-ok { background: rgba(67,201,139,.14); color: var(--ok); border-color: transparent; }
.pill-warn { background: rgba(242,193,78,.14); color: var(--warn); border-color: transparent; }
.pill-fail { background: rgba(231,111,81,.16); color: var(--fail); border-color: transparent; }
.pill-info { background: rgba(167,139,250,.16); color: var(--info); border-color: transparent; }
.pill-run { background: rgba(127,179,255,.16); color: var(--running); border-color: transparent; }
.pill-accent { background: rgba(127,179,255,.16); color: var(--accent); border-color: transparent; }

/* ---------- project cards ---------- */
.section-title { font-size: 13px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .08em; margin: 4px 0 14px; font-weight: 700; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: border-color .12s, transform .08s;
  display: flex; flex-direction: column; gap: 10px;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card-topic { font-weight: 700; font-size: 15px; line-height: 1.35; }
.card-pid { color: var(--text-faint); font-size: 11px; font-family: ui-monospace, monospace; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.progress { height: 7px; background: var(--bg-3); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.progress-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); }

.gate-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.gate-dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.g-pass { background: var(--ok); } .g-fail { background: var(--fail); }
.g-warn { background: var(--warn); } .g-pending { background: var(--border-2); }
.g-running { background: var(--running); } .g-overridden { background: var(--info); }
.g-na { background: #3a4556; }

/* ---------- detail ---------- */
.detail-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.detail-head-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.detail-topic { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.detail-sub { color: var(--text-dim); font-size: 12.5px; display: flex; gap: 14px; flex-wrap: wrap; }
.detail-sub code { color: var(--text-faint); }

.banner {
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; margin-bottom: 14px;
  border: 1px solid var(--border-2);
}
.banner-goal { background: rgba(127,179,255,.10); border-color: rgba(127,179,255,.4); }
.banner-static { background: rgba(242,193,78,.10); border-color: rgba(242,193,78,.4); color: var(--warn); }
.banner-blocked { background: rgba(231,111,81,.10); border-color: rgba(231,111,81,.4); }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab { padding: 9px 16px; border: none; background: none; color: var(--text-dim); font-size: 14px; font-weight: 600; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }

/* phase timeline */
.timeline { display: flex; flex-direction: column; gap: 2px; }
.tl-row { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; padding: 5px 0; }
.tl-node { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--border-2); justify-self: center; }
.tl-line { position: relative; }
.tl-name { font-size: 13px; }
.tl-name small { color: var(--text-faint); display: block; font-size: 11px; }
.tl-time { color: var(--text-faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.st-completed .tl-node { background: var(--ok); border-color: var(--ok); }
.st-skipped .tl-node { background: #3a4556; border-color: #3a4556; }
.st-in_progress .tl-node { background: var(--running); border-color: var(--running); box-shadow: 0 0 0 3px rgba(127,179,255,.2); animation: pulse 1.6s infinite; }
.st-failed .tl-node { background: var(--fail); border-color: var(--fail); }
.st-blocked .tl-node { background: var(--warn); border-color: var(--warn); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(127,179,255,0); } }

/* gate grid */
.gates { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 8px; }
.gate {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px;
  font-size: 12px; cursor: pointer; transition: border-color .1s;
}
.gate:hover { border-color: var(--accent); }
.gate-name { font-weight: 600; display: block; margin-bottom: 4px; word-break: break-all; }
.gate-required { border-left: 3px solid var(--accent); }

/* action queue */
.queue-item { border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px; }
.queue-item.p-critical { border-left-color: var(--fail); }
.queue-item.p-high { border-left-color: var(--warn); }
.queue-item.p-medium { border-left-color: var(--accent); }
.queue-item.p-low { border-left-color: var(--border-2); }
.queue-meta { display: flex; gap: 8px; font-size: 11px; color: var(--text-faint); margin-bottom: 3px; }

.notes-list { max-height: 320px; overflow-y: auto; font-size: 12.5px; }
.note-row { padding: 6px 0; border-bottom: 1px solid var(--border); }
.note-row time { color: var(--text-faint); font-size: 11px; }

/* ---------- scene gallery ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type=text], .toolbar select, .field input, .field select, .field textarea {
  background: var(--bg-3); border: 1px solid var(--border-2); color: var(--text);
  border-radius: var(--radius-sm); padding: 7px 10px; font-size: 13px; font-family: inherit;
}
.toolbar .count { color: var(--text-dim); font-size: 12px; }

.scene-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: 12px; }
.scene-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: border-color .1s; }
.scene-card:hover { border-color: var(--accent); }
.scene-thumb { aspect-ratio: 16/9; background: #05070c; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.scene-thumb-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scene-thumb .ph { color: var(--text-faint); font-size: 12px; }
.scene-thumb .sid { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.6); padding: 1px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.scene-thumb .fb { position: absolute; top: 6px; right: 6px; font-size: 13px; }
.scene-info { padding: 9px 11px; }
.scene-info .row1 { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 5px; }
.scene-info .narr { color: var(--text-dim); font-size: 12px; line-height: 1.4; min-height: 2.6em; }
.tag { font-size: 10.5px; padding: 1px 7px; border-radius: 5px; background: var(--bg-3); color: var(--text-dim); border: 1px solid var(--border); }
.tag-ai { color: var(--accent); } .tag-i2v { color: var(--info); } .tag-ref { color: var(--accent-2); } .tag-data { color: var(--warn); }

.contact-sheets { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.contact-sheets img { height: 150px; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2,4,8,.78); backdrop-filter: blur(3px); }
.modal-body { position: relative; background: var(--bg-2); border: 1px solid var(--border-2); border-radius: var(--radius);
  max-width: min(1100px, 94vw); max-height: 92vh; overflow-y: auto; padding: 20px; width: 100%; }
.modal-media { width: 100%; border-radius: var(--radius-sm); background: #05070c; margin-bottom: 12px; max-height: 60vh; object-fit: contain; }
.modal-frametabs { display: flex; gap: 6px; margin-bottom: 10px; }
.modal-narr { background: var(--bg-3); border-radius: var(--radius-sm); padding: 12px; font-size: 14px; line-height: 1.7; margin-bottom: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.field textarea { min-height: 70px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.fb-history { font-size: 12px; margin-top: 10px; }
.fb-history .e { padding: 5px 0; border-top: 1px solid var(--border); }

/* ---------- jobs ---------- */
.job { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px; }
.job-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.job-log { background: #05070c; border-radius: 6px; padding: 10px; font-family: ui-monospace, monospace; font-size: 11.5px; white-space: pre-wrap; word-break: break-all; max-height: 240px; overflow-y: auto; margin-top: 8px; color: #b9c4d4; }

.empty { color: var(--text-faint); padding: 24px; text-align: center; font-size: 13px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--border-2); color: var(--text);
  padding: 11px 18px; border-radius: var(--radius-sm); z-index: 200; font-size: 13px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: 90vw;
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--fail); }

.muted { color: var(--text-faint); }
.mono { font-family: ui-monospace, monospace; }
