:root {
  --bg: #F6F5F8;
  --surface: #FFFFFF;
  --surface-2: #FBFAFC;
  --ink: #17131C;
  --ink-2: #463F4F;
  --muted: #6B6573;
  --line: #E8E4EC;
  --line-2: #D8D2DF;
  --brand: #672E7E;
  --brand-hover: #56246A;
  --brand-soft: #F3ECF6;
  --accent: #E3341C;
  --danger: #B8301B;
  --ok: #1F7A4D;
  --font-ui: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Bricolage Grotesque', var(--font-ui);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 400 15px/1.5 var(--font-ui); -webkit-font-smoothing: antialiased; }
img { max-width: 100%; }
a { color: var(--brand); }
h1, h2 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 18px; }
:focus-visible { outline: 3px solid rgba(103, 46, 126, 0.35); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
[hidden] { display: none !important; }

/* ---------- app shell ---------- */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 248px; flex: none; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 22px 14px 18px; position: sticky; top: 0; height: 100vh;
}
.side-logo { display: block; padding: 2px 10px 28px; }
.side-logo img { height: 36px; display: block; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px;
  color: var(--ink-2); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: #F4F1F6; color: var(--ink); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
.nav svg { width: 19px; height: 19px; flex: none; }
.side-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.ws-name { font-weight: 600; font-size: 14px; }
.user-line { color: var(--muted); font-size: 13px; }

.main { flex: 1; min-width: 0; padding: 34px 44px 64px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.sub { color: var(--muted); margin: 6px 0 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.note { color: var(--muted); margin: -10px 0 22px; font-size: 14px; }
.block { margin-bottom: 30px; }
.block-title { margin-bottom: 12px; }

/* ---------- buttons ---------- */
.btn {
  font: 600 14px/1 var(--font-ui); border-radius: 8px; padding: 0 16px; height: 40px;
  border: 1px solid transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; text-decoration: none; white-space: nowrap;
}
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { background: var(--surface); border-color: var(--line-2); color: var(--ink); }
.btn-ghost:hover { background: #F4F1F6; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-wide { width: 100%; height: 44px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
.table-wrap table { min-width: 640px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; letter-spacing: 0.04em;
  text-transform: uppercase; padding: 11px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap;
}
td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #FCFBFD; }
.chip {
  display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 999px;
  background: #F1EEF4; color: var(--ink-2); font-size: 12px; font-weight: 500; margin: 2px 4px 2px 0; white-space: nowrap;
}
.chip-brand { background: var(--brand-soft); color: var(--brand); }
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #A69EB0; }
.status[data-s="creating"]::before, .status[data-s="rendering"]::before, .status[data-s="publishing"]::before { background: var(--brand); }
.status[data-s="ready"]::before, .status[data-s="published"]::before { background: var(--ok); }
.status[data-s="failed"]::before { background: var(--accent); }

/* ---------- empty states ---------- */
.empty {
  background: var(--surface); border: 1px dashed var(--line-2); border-radius: 14px;
  padding: 52px 24px; text-align: center; max-width: 720px;
}
.empty-dot { width: 40px; height: 40px; }
.empty h2 { font-size: 20px; margin: 14px 0 6px; }
.empty p { color: var(--muted); margin: 0 auto 20px; max-width: 440px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.field.grow { flex: 1; min-width: 220px; margin-bottom: 0; }
label, .label { font-weight: 600; font-size: 13px; color: var(--ink); }
input[type="text"], input[type="email"], input[type="password"], select {
  height: 42px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 12px;
  font: 400 15px var(--font-ui); color: var(--ink); background: #fff; width: 100%;
}
input:focus, select:focus { border-color: var(--brand); outline: 3px solid rgba(103, 46, 126, 0.16); outline-offset: 0; }
.err { color: var(--danger); font-size: 13px; }
.err:empty { display: none; }
.hint { color: var(--muted); font-size: 13px; }
.hint:empty { display: none; }
.inline-form { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 22px; max-width: 640px; }
.inline-form .btn { margin-top: 25px; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { border: 1px solid var(--line-2); border-radius: 10px; padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-weight: 400; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.choice input { accent-color: var(--brand); margin: 3px 0 0; }
.choice b { display: block; font-size: 14px; }
.choice span span { font-size: 13px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 12px; font-size: 14px; font-weight: 500; cursor: pointer; }
.check input { accent-color: var(--brand); margin: 0; }
.check:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }

/* ---------- dialog ---------- */
dialog.sheet { border: 0; padding: 0; border-radius: 16px; width: min(580px, calc(100vw - 32px)); color: var(--ink); box-shadow: 0 24px 64px rgba(23, 19, 28, 0.24); }
dialog::backdrop { background: rgba(23, 19, 28, 0.38); }
.sheet-head { padding: 22px 24px 4px; }
.sheet-body { padding: 14px 24px 4px; max-height: 70vh; overflow-y: auto; }
.sheet-foot { padding: 16px 24px 20px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); }

/* ---------- sign in ---------- */
.auth { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 100vh; background: var(--surface); }
.auth-form { display: flex; flex-direction: column; justify-content: center; padding: 56px clamp(24px, 7vw, 112px); }
.auth-form > * { max-width: 400px; width: 100%; }
.auth-logo { width: 210px; margin-bottom: 44px; }
.auth-form h1 { font-size: 30px; margin-bottom: 4px; }
.auth-form form { margin-top: 22px; }
.auth-art { background: var(--brand); position: relative; overflow: hidden; display: flex; align-items: flex-end; padding: 56px; }
.auth-art img { position: absolute; width: 560px; max-width: none; right: -140px; top: -120px; }
.auth-art p { position: relative; color: #fff; font-family: var(--font-display); font-weight: 600; font-size: clamp(34px, 3.8vw, 54px); line-height: 1.04; letter-spacing: -0.02em; margin: 0; }

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .shell { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-logo { padding: 0; }
  .side-logo img { height: 26px; }
  .nav { flex-direction: row; flex-wrap: wrap; order: 3; width: 100%; }
  .side-foot { margin: 0 0 0 auto; padding: 0; border: 0; flex-direction: row; align-items: center; }
  .who { display: none; }
  .main { padding: 24px 16px 48px; }
  .choices { grid-template-columns: 1fr; }
}

/* ---------- bundle 2: project page, settings ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.small { font-size: 13px; }
.crumb { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 500; margin-bottom: 8px; }
.crumb:hover { color: var(--brand); }
.crumb svg { width: 15px; height: 15px; }
.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 10px; }
.meta-row .chip { margin: 0; }
.row-link { color: var(--ink); text-decoration: none; }
.row-link:hover { color: var(--brand); text-decoration: underline; text-underline-offset: 3px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; margin-bottom: 18px; }
.panel h2 { margin-bottom: 4px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel > .field:last-child { margin-bottom: 0; }
textarea {
  width: 100%; border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px;
  font: 400 15px/1.5 var(--font-ui); color: var(--ink); background: #fff; resize: vertical;
}
textarea:focus { border-color: var(--brand); outline: 3px solid rgba(103, 46, 126, 0.16); outline-offset: 0; }
.row-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.working { display: flex; align-items: center; gap: 12px; margin-top: 16px; color: var(--ink-2); font-size: 14px; }
.working .bar { position: relative; width: 120px; height: 4px; border-radius: 4px; background: var(--brand-soft); overflow: hidden; flex: none; }
.working .bar::after { content: ''; position: absolute; inset: 0; width: 40%; border-radius: 4px; background: linear-gradient(90deg, var(--brand), var(--accent)); animation: ms-slide 1.2s ease-in-out infinite; }
@keyframes ms-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
.edit-table { min-width: 900px; }
.edit-table td { vertical-align: top; padding: 10px 8px; }
.edit-table td:first-child { padding-left: 16px; }
.edit-table textarea { font-size: 14px; padding: 8px 10px; min-height: 84px; }
.edit-table .num { width: 32px; color: var(--muted); font-weight: 600; padding-top: 18px; }
.edit-table .sec { width: 72px; }
.edit-table .sec input { width: 64px; text-align: center; }
.edit-table .x { width: 90px; padding-top: 14px; }
.add-scene { margin-top: 12px; }
.captions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 18px; margin-top: 12px; }
.caption { border: 1px solid var(--line); border-radius: 12px; padding: 16px 16px 2px; }
.caption h3 { margin: 0 0 12px; font-family: var(--font-display); font-size: 16px; font-weight: 600; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.counter { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter.over { color: var(--danger); font-weight: 600; }
.versions { list-style: none; margin: 8px 0 0; padding: 0; font-size: 14px; }
.versions li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.versions li:last-child { border-bottom: 0; }
.savebar {
  position: sticky; bottom: 0; display: flex; align-items: center; justify-content: flex-end; gap: 14px; flex-wrap: wrap;
  padding: 14px 0; background: linear-gradient(rgba(246, 245, 248, 0), var(--bg) 30%);
}
.ok-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--ink-2); }
@media (max-width: 860px) {
  .grid-3 { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .panel { padding: 18px 16px; }
}
@media (prefers-reduced-motion: reduce) { .working .bar::after { animation-duration: 2.4s; } }
