/* Shorts Studio — dark studio UI.
   No CDN, no webfont request: the Worker's CSP is `default-src 'self'`, so
   every byte the page needs is served from the same origin. */

/* one source of truth: the hidden attribute always wins */
[hidden] { display: none !important; }

:root {
  --bg: #0b0d12;
  --bg-2: #11141c;
  --panel: #151a24;
  --panel-2: #1b2130;
  --line: #232a38;
  --line-2: #2e3748;
  --ink: #eef1f7;
  --ink-2: #a7b0c0;
  --ink-3: #6f7a8d;
  --accent: #ffd640;
  --accent-ink: #201c00;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --info: #7dd3fc;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 12px 32px rgba(0, 0, 0, .38);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic",
    "Apple SD Gothic Neo", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 82% -8%, rgba(255, 214, 64, .08), transparent 62%),
    radial-gradient(760px 420px at 4% 0%, rgba(125, 211, 252, .07), transparent 60%),
    var(--bg);
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: .92em; color: var(--accent); }

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 14px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 20;
}
.skip:focus { left: 0; }

/* ── top bar ─────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 18, .82);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--accent), #ff8a3d 62%, #f87171);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .12) inset;
  position: relative;
}
.mark::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 3px;
  background: #12141a;
}
.brand-text { display: flex; flex-direction: column; gap: 1px; }
.brand-text strong { font-size: 16px; letter-spacing: -.02em; }
.sub { color: var(--ink-3); font-size: 12.5px; }

.conn { display: flex; align-items: center; gap: 10px; }

/* ── primitives ──────────────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
.btn:hover:not(:disabled) { border-color: #3d4a60; background: #1f2634; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover:not(:disabled) { background: #ffe375; border-color: transparent; }
.btn-good { background: rgba(52, 211, 153, .14); color: #86efac; border-color: rgba(52, 211, 153, .38); }
.btn-good:hover:not(:disabled) { background: rgba(52, 211, 153, .24); border-color: rgba(52, 211, 153, .6); }
.btn-bad { background: rgba(248, 113, 113, .12); color: #fca5a5; border-color: rgba(248, 113, 113, .34); }
.btn-bad:hover:not(:disabled) { background: rgba(248, 113, 113, .22); }
.btn-ghost { background: transparent; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.pill-on { color: var(--good); border-color: rgba(52, 211, 153, .35); background: rgba(52, 211, 153, .1); }
.pill-off { color: var(--ink-3); }
.pill-neutral { color: var(--info); border-color: rgba(125, 211, 252, .3); background: rgba(125, 211, 252, .08); }
.pill-warn { color: var(--warn); border-color: rgba(251, 191, 36, .35); background: rgba(251, 191, 36, .1); }
.pill-bad { color: var(--bad); border-color: rgba(248, 113, 113, .35); background: rgba(248, 113, 113, .1); }

.bar {
  height: 6px;
  border-radius: 999px;
  background: #1d2331;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #34d399, var(--accent));
  transition: width .35s ease;
}
.bar > i.is-warn { background: linear-gradient(90deg, var(--accent), #fb923c); }
.bar > i.is-bad { background: linear-gradient(90deg, #fb923c, var(--bad)); }

.note { color: var(--ink-3); font-size: 12.5px; }

/* ── layout ──────────────────────────────────────────────────────────── */
main {
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px 28px 64px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
}
.kpi h2 { font-size: 12.5px; color: var(--ink-3); font-weight: 600; letter-spacing: .01em; }
.kpi .value { font-size: 26px; font-weight: 800; letter-spacing: -.03em; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.kpi .bar { margin-bottom: 6px; }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.25fr) 360px;
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-head h2 { font-size: 14px; letter-spacing: .01em; }

.rail { display: flex; flex-direction: column; gap: 16px; }

/* ── queue ───────────────────────────────────────────────────────────── */
.seg { display: flex; gap: 4px; background: var(--bg-2); padding: 3px; border-radius: 10px; border: 1px solid var(--line); }
.seg-btn {
  border: 0;
  background: transparent;
  color: var(--ink-3);
  padding: 5px 9px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.is-on { background: var(--panel-2); color: var(--ink); }

.queue { display: flex; flex-direction: column; gap: 8px; max-height: 720px; overflow: auto; }

.ep {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.ep:hover { border-color: var(--line-2); background: #161b26; }
.ep.is-on { border-color: var(--accent); background: rgba(255, 214, 64, .06); }
.ep-idx { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.ep-main { min-width: 0; }
.ep-title { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ep-meta { color: var(--ink-3); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ep-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.tag-draft, .tag-scripted { color: var(--ink-2); background: #1e2431; border-color: var(--line-2); }
.tag-review { color: var(--warn); background: rgba(251, 191, 36, .12); border-color: rgba(251, 191, 36, .3); }
.tag-approved { color: #86efac; background: rgba(52, 211, 153, .12); border-color: rgba(52, 211, 153, .3); }
.tag-queued, .tag-rendering { color: var(--info); background: rgba(125, 211, 252, .1); border-color: rgba(125, 211, 252, .28); }
.tag-rendered { color: #a5b4fc; background: rgba(165, 180, 252, .12); border-color: rgba(165, 180, 252, .3); }
.tag-failed { color: var(--bad); background: rgba(248, 113, 113, .12); border-color: rgba(248, 113, 113, .3); }
.tag-rejected { color: var(--ink-3); background: #1a1f2a; border-color: var(--line); }
.tag-published { color: var(--good); background: rgba(52, 211, 153, .16); border-color: rgba(52, 211, 153, .34); }

/* ── preview ─────────────────────────────────────────────────────────── */
.preview-body { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 14px; }
.stage {
  position: relative;
  aspect-ratio: 9 / 16;
  border-radius: 12px;
  background: #0a0c11;
  border: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stage video, .stage img { width: 100%; height: 100%; object-fit: cover; display: block; }
.stage-hint { color: var(--ink-3); font-size: 12px; text-align: center; padding: 12px;
  width: 100%; max-width: 100%; min-width: 0; word-break: keep-all; line-height: 1.5; }
.detail h3 { font-size: 16px; margin-bottom: 4px; }
.scenes { margin: 12px 0 14px; display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow: auto; }
.scenes li {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 8px;
  font-size: 12px;
  color: var(--ink-2);
  border-left: 2px solid var(--line-2);
  padding-left: 9px;
}
.scenes .k { color: var(--ink-3); font-family: var(--mono); font-size: 10.5px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

/* ── presets ─────────────────────────────────────────────────────────── */
.presets { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }
.preset {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.preset:hover { border-color: var(--line-2); }
.preset.is-on { border-color: var(--accent); background: rgba(255, 214, 64, .06); }
.preset-name { font-weight: 650; font-size: 13px; }
.preset-desc { color: var(--ink-3); font-size: 11.5px; grid-column: 1 / -1; }
.swatch { width: 10px; height: 10px; border-radius: 3px; margin-top: 5px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field > span { font-size: 12px; color: var(--ink-3); font-weight: 600; }
input[type="text"], input[type="password"], select, textarea {
  background: #0e1219;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13.5px;
  width: 100%;
  outline: none;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 214, 64, .14);
}
textarea { resize: vertical; min-height: 62px; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row-end { justify-content: flex-end; }
.field-inline { flex: 1; margin-bottom: 0; }

.image-out { margin-top: 10px; }
.image-out img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #0a0c11;
  margin-bottom: 6px;
}

.meter { margin-bottom: 12px; }
.meter-row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; }
.meter-row b { color: var(--ink); font-variant-numeric: tabular-nums; }

.incidents { display: flex; flex-direction: column; gap: 7px; }
.incidents li {
  border: 1px solid rgba(248, 113, 113, .26);
  background: rgba(248, 113, 113, .06);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  color: #fecaca;
}
.incidents .inc-meta { color: var(--ink-3); font-size: 11px; margin-top: 3px; }
.incidents button { margin-top: 6px; padding: 3px 9px; font-size: 11.5px; }

.logs { display: flex; flex-direction: column; gap: 5px; max-height: 220px; overflow: auto; }
.logs li { font-size: 11.5px; color: var(--ink-3); font-family: var(--mono); display: flex; gap: 6px; }
.logs .agent { color: var(--info); }
.logs .fail { color: var(--bad); }

.empty { color: var(--ink-3); font-size: 12.5px; padding: 6px 2px; }

/* ── modal + toast ───────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, .72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 30;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal-card h2 { font-size: 16px; margin-bottom: 6px; }
.modal-card .note { margin-bottom: 14px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: #1d2534;
  border: 1px solid var(--line-2);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  max-width: min(560px, 90vw);
  z-index: 40;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-bad { border-color: rgba(248, 113, 113, .5); color: #fecaca; }

/* ── responsive ──────────────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .rail { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  main { padding: 16px 14px 48px; }
  .topbar { padding: 12px 14px; gap: 8px; flex-wrap: nowrap; }
  .brand { min-width: 0; }
  .brand-text { min-width: 0; }
  .brand-text .sub { display: none; }        /* 자리만 차지하고 잘리던 부제 */
  .brand-text strong { white-space: nowrap; }
  .conn { gap: 6px; flex: 0 0 auto; }
  .conn .btn { white-space: nowrap; padding: 8px 11px; font-size: 12px; }
  .pill { white-space: nowrap; font-size: 11px; padding: 6px 9px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .preview-body { grid-template-columns: 130px minmax(0, 1fr); }
  .rail { grid-template-columns: minmax(0, 1fr); }
  .queue { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
