:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --line: #dfe3e8;
  --line-strong: #c7cdd4;
  --text: #17191c;
  --muted: #68717c;
  --red: #d83328;
  --red-dark: #b5251d;
  --green: #26865c;
  --blue: #2e5f9f;
  --shadow: 0 10px 32px rgba(25, 32, 40, 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button, select, summary, label[for] { cursor: pointer; }
svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

.login-screen { min-height: 100vh; display: none; place-items: center; padding: 24px; background: #f3f5f7; }
.auth-pending .topbar, .auth-pending .workspace, .auth-required .topbar, .auth-required .workspace { display: none; }
.auth-pending .login-screen, .auth-required .login-screen { display: grid; }
.login-card { width: min(420px, 100%); display: grid; gap: 18px; padding: 34px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.login-mark { width: 42px; height: 42px; }
.login-copy { display: grid; gap: 7px; }
.login-copy > span { color: var(--red); font-size: .72rem; font-weight: 850; }
.login-copy h1 { margin: 0; font-size: 1.45rem; }
.login-copy p { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.5; }
.login-button { margin-top: 2px; }
.login-error { margin: -5px 0 0; color: var(--red-dark); font-size: .8rem; line-height: 1.4; }

.topbar {
  height: 64px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 760; font-size: 1rem; }
.brand-mark { width: 32px; height: 32px; border-radius: 7px; display: grid; place-items: center; background: var(--red); color: white; }
.brand-mark svg { width: 22px; height: 22px; }
.cloud-status { color: var(--muted); font-size: .86rem; display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(38,134,92,.1); }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.logout-button { min-height: 34px; display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: #4d555f; padding: 0 10px; font-size: .78rem; font-weight: 700; }
.logout-button:hover { border-color: var(--line-strong); color: var(--text); background: #f7f8fa; }
.logout-button svg { width: 16px; height: 16px; }

.workspace {
  width: min(1540px, calc(100% - 40px));
  margin: 26px auto 48px;
  display: grid;
  grid-template-columns: minmax(300px, .85fr) minmax(420px, 1.15fr) minmax(300px, .9fr);
  gap: 16px;
  align-items: start;
}
.source-panel, .settings-panel, .result-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  min-width: 0;
}
.settings-panel { box-shadow: var(--shadow); }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.section-heading > div { display: flex; align-items: center; gap: 10px; min-width: 0; }
.section-heading h1, .section-heading h2 { font-size: 1.05rem; margin: 0; line-height: 1.25; }
.step { color: var(--red); font-size: .72rem; font-weight: 800; padding: 4px 6px; background: #fff0ef; border-radius: 4px; }

.icon-button { border: 0; background: transparent; color: var(--muted); padding: 7px; border-radius: 5px; }
.icon-button:hover { background: #f0f2f4; color: var(--text); }

.upload-zone {
  min-height: 460px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 7px;
  background: #fafbfc;
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: border-color .18s, background .18s;
}
.upload-zone.dragover { border-color: var(--red); background: #fff7f6; }
.upload-empty { display: flex; align-items: center; flex-direction: column; gap: 10px; text-align: center; padding: 32px 18px; }
.upload-empty > span:not(.upload-icon):not(.choose-file) { color: var(--muted); font-size: .84rem; }
.upload-icon { width: 52px; height: 52px; border: 1px solid var(--line); border-radius: 7px; display: grid; place-items: center; color: var(--red); background: #fff; margin-bottom: 6px; }
.upload-icon svg { width: 26px; height: 26px; }
.choose-file { margin-top: 8px; background: #fff; border: 1px solid var(--line-strong); border-radius: 5px; padding: 9px 14px; font-weight: 650; font-size: .88rem; }
#source-preview { width: 100%; height: 460px; background: #0d0e10; object-fit: contain; }
.file-list { margin-top: 12px; display: grid; gap: 7px; max-height: 290px; overflow: auto; }
.file-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto 28px; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 5px; background: #fafbfc; }
.file-index { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 4px; color: var(--red); background: #fff0ef; font-size: .72rem; font-weight: 800; }
.file-copy { min-width: 0; display: grid; gap: 2px; }
.file-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .78rem; }
.file-copy span, .file-row > span { color: var(--muted); font-size: .7rem; }
.remove-one { border: 0; background: transparent; color: var(--muted); padding: 4px; display: grid; place-items: center; }
.remove-one svg { width: 16px; height: 16px; }
.add-more { width: 100%; margin-top: 8px; border: 1px solid var(--line-strong); border-radius: 5px; background: #fff; min-height: 38px; font-weight: 700; font-size: .8rem; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 14px; }
.field { min-width: 0; display: grid; gap: 7px; border: 0; padding: 0; margin: 0; }
.field > span, .field legend { font-size: .82rem; color: #343a41; font-weight: 700; }
.field small { color: var(--muted); font-weight: 500; }
.field-wide { grid-column: 1 / -1; }
select, textarea, input[type="password"], input[type="text"], .field input:not([type]) {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 5px; background: #fff; color: var(--text); padding: 10px 11px; outline: none; min-height: 42px;
}
textarea { resize: vertical; line-height: 1.45; }
select:focus, textarea:focus, input[type="password"]:focus, input[type="text"]:focus, .field input:not([type]):focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(46,95,159,.1); outline: none; }
.product-picker { display: grid; grid-template-columns: minmax(0, 1fr) 42px 42px; gap: 8px; }
.bordered { border: 1px solid var(--line-strong); background: #fff; }
.slider-field > span { display: flex; justify-content: space-between; gap: 8px; }
output { color: var(--red); font-weight: 800; }
input[type="range"] { accent-color: var(--red); width: 100%; margin: 7px 0 0; }
.range-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: .72rem; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line-strong); border-radius: 5px; overflow: hidden; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { min-height: 40px; display: grid; place-items: center; text-align: center; padding: 7px; font-size: .78rem; border-right: 1px solid var(--line); }
.segmented label:last-child span { border-right: 0; }
.segmented input:checked + span { background: #25292e; color: #fff; }
.advanced { border-top: 1px solid var(--line); padding-top: 12px; }
.advanced summary { color: var(--muted); font-size: .8rem; }
.compact { margin-top: 12px; }
.toggle-label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle-label input { position: absolute; opacity: 0; }
.toggle { width: 36px; height: 20px; border-radius: 10px; background: #cfd4da; position: relative; transition: background .18s; }
.toggle::after { content: ""; position: absolute; width: 16px; height: 16px; top: 2px; left: 2px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.22); transition: transform .18s; }
.toggle-label input:checked + .toggle { background: var(--red); }
.toggle-label input:checked + .toggle::after { transform: translateX(16px); }
.subtitle-settings.disabled .segmented { opacity: .45; pointer-events: none; }
.primary-button, .download-button, .secondary-button {
  min-height: 46px; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 750; text-decoration: none;
}
.primary-button { width: 100%; border: 0; background: var(--red); color: #fff; margin-top: 20px; }
.primary-button:hover:not(:disabled) { background: var(--red-dark); }
.primary-button:disabled { background: #d8dce1; color: #838b95; cursor: not-allowed; }
.download-button { border: 0; background: var(--red); color: #fff; padding: 0 18px; }
.secondary-button { border: 1px solid var(--line-strong); background: #fff; color: var(--text); padding: 0 16px; }

.result-state { font-size: .74rem; color: var(--muted); background: #f0f2f4; border-radius: 999px; padding: 5px 9px; }
.result-state.active { color: var(--blue); background: #edf4ff; }
.result-state.done { color: var(--green); background: #eaf7f0; }
.result-state.failed { color: var(--red); background: #fff0ef; }
.result-empty { min-height: 460px; background: #f7f8fa; border: 1px solid var(--line); border-radius: 7px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; color: #8a929c; font-size: .84rem; text-align: center; }
.result-empty svg { width: 38px; height: 38px; }
.processing { min-height: 460px; border: 1px solid var(--line); border-radius: 7px; padding: 36px 26px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.progress-ring { width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--red) var(--progress, 0%), #eceff2 0); position: relative; }
.progress-ring::after { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: #fff; }
.progress-ring span { position: relative; z-index: 1; font-weight: 800; font-size: 1.1rem; }
.processing-copy { display: grid; gap: 6px; margin-top: 20px; }
.processing-copy span { color: var(--muted); font-size: .82rem; }
.progress-track { width: 100%; height: 6px; border-radius: 4px; background: #eceff2; margin-top: 24px; overflow: hidden; }
.progress-track span { display: block; height: 100%; width: 0; background: var(--red); transition: width .3s; }
.stage-list { width: 100%; list-style: none; display: grid; gap: 9px; padding: 0; margin: 22px 0 0; text-align: left; }
.stage-list li { color: #9299a2; font-size: .79rem; padding-left: 22px; position: relative; }
.stage-list li::before { content: ""; position: absolute; left: 1px; top: 5px; width: 8px; height: 8px; border-radius: 50%; background: #d7dbe0; }
.stage-list li.current { color: var(--text); font-weight: 700; }
.stage-list li.current::before { background: var(--red); box-shadow: 0 0 0 4px #fff0ef; }
.stage-list li.complete { color: var(--green); }
.stage-list li.complete::before { background: var(--green); }
.result-ready video { width: 100%; height: 460px; background: #0d0e10; object-fit: contain; border-radius: 7px; }
.result-actions { display: grid; grid-template-columns: 1.2fr 1fr; gap: 10px; margin-top: 14px; }
.error-box { min-height: 300px; border: 1px solid #f0c4c0; background: #fff6f5; border-radius: 7px; padding: 26px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 12px; }
.error-box span { color: #744b48; line-height: 1.5; font-size: .86rem; }
.batch-results { display: grid; gap: 10px; }
.batch-job { border: 1px solid var(--line); border-radius: 7px; padding: 11px; background: #fafbfc; }
.batch-job-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.batch-job-name { min-width: 0; display: grid; gap: 3px; }
.batch-job-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; }
.batch-job-name span { color: var(--muted); font-size: .7rem; }
.job-badge { flex: 0 0 auto; font-size: .68rem; padding: 4px 7px; border-radius: 999px; background: #eceff2; color: var(--muted); }
.job-badge.active { color: var(--blue); background: #edf4ff; }
.job-badge.done { color: var(--green); background: #eaf7f0; }
.job-badge.failed { color: var(--red); background: #fff0ef; }
.job-progress { height: 5px; border-radius: 4px; background: #e7eaee; overflow: hidden; margin-top: 10px; }
.job-progress span { display: block; height: 100%; width: 0; background: var(--red); transition: width .3s; }
.job-detail { display: block; margin-top: 7px; min-height: 1.1em; color: var(--muted); font-size: .72rem; }
.job-output { margin-top: 10px; display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 10px; align-items: center; }
.job-output video { width: 84px; aspect-ratio: 9 / 16; object-fit: cover; background: #111; border-radius: 4px; }
.job-output-copy { min-width: 0; display: grid; gap: 8px; }
.job-angle { color: var(--green); font-size: .72rem; font-weight: 750; }
.job-download { min-height: 36px; border-radius: 5px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 10px; background: var(--red); color: #fff; text-decoration: none; font-size: .76rem; font-weight: 750; }
.job-download svg { width: 15px; height: 15px; }
.job-error { color: var(--red); }
.content-card { border: 1px solid var(--line); border-radius: 7px; background: #fff; overflow: hidden; }
.content-card-head { padding: 11px; display: grid; grid-template-columns: 54px minmax(0,1fr); gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.content-thumb { width: 54px; aspect-ratio: 9 / 16; object-fit: cover; border-radius: 4px; background: #17191c; }
.content-name { min-width: 0; }
.content-name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; }
.content-name span { color: var(--muted); font-size: .7rem; }
.content-body { padding: 11px; display: grid; gap: 9px; }
.content-label { color: var(--red); font-size: .68rem; font-weight: 800; text-transform: uppercase; }
.content-title { font-size: .82rem; font-weight: 800; line-height: 1.35; }
.content-copy { color: #4d555f; font-size: .76rem; line-height: 1.5; margin: 0; }
.angle-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.angle-chip { border: 1px solid var(--line-strong); background: #fff; color: #444c55; border-radius: 999px; padding: 6px 8px; font-size: .68rem; }
.angle-chip.active { background: #fff0ef; border-color: #edaaa5; color: var(--red-dark); font-weight: 750; }
.card-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.card-actions button { min-height: 36px; }
.analyze-button { width: 100%; min-height: 42px; border: 1px solid var(--line-strong); border-radius: 5px; background: #fff; color: var(--text); font-weight: 750; margin-bottom: 10px; }
.analyze-button:disabled { color: #9299a2; background: #f1f3f5; }
.product-dialog { width: min(680px, calc(100% - 28px)); border: 0; border-radius: 8px; padding: 0; box-shadow: 0 24px 70px rgba(20,25,30,.25); }
.product-dialog::backdrop { background: rgba(25,30,36,.45); }
.product-dialog form { padding: 22px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.dialog-head > div { display: grid; gap: 8px; }
.dialog-head h2 { margin: 0; font-size: 1.08rem; }
.dialog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dialog-actions { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }
.compact-primary { width: auto; margin: 0; padding: 0 18px; }
.toast { position: fixed; right: 22px; bottom: 22px; background: #202327; color: #fff; padding: 12px 15px; border-radius: 6px; box-shadow: var(--shadow); font-size: .85rem; z-index: 30; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: minmax(320px, .9fr) minmax(460px, 1.1fr); }
  .result-panel { grid-column: 1 / -1; }
  .result-panel .result-empty, .result-panel .processing { min-height: 320px; }
  .result-ready { display: grid; grid-template-columns: minmax(280px, 420px) 1fr; gap: 18px; align-items: center; }
  .result-ready.hidden { display: none; }
  .result-ready video { height: 420px; }
  .result-actions { display: flex; flex-direction: column; align-items: stretch; }
}

@media (max-width: 760px) {
  .topbar { padding: 0 16px; }
  .cloud-status { font-size: 0; }
  .login-card { padding: 26px 22px; }
  .logout-button span { display: none; }
  .workspace { width: min(100% - 20px, 600px); margin-top: 12px; grid-template-columns: 1fr; }
  .result-panel { grid-column: auto; }
  .source-panel, .settings-panel, .result-panel { padding: 17px; }
  .upload-zone, #source-preview, .result-ready video { min-height: 0; height: auto; aspect-ratio: 9 / 13; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .segmented { grid-template-columns: 1fr; }
  .segmented span { border-right: 0; border-bottom: 1px solid var(--line); }
  .segmented label:last-child span { border-bottom: 0; }
  .result-ready { display: block; }
  .result-ready.hidden { display: none; }
  .result-actions { display: grid; grid-template-columns: 1fr; }
  .dialog-grid { grid-template-columns: 1fr; }
  .dialog-grid .field-wide { grid-column: auto; }
}
