:root {
  color-scheme: dark;
  --bg: #07101d;
  --bg-soft: #0b1625;
  --panel: rgba(15, 28, 45, 0.88);
  --panel-strong: #111f31;
  --line: rgba(148, 177, 202, 0.16);
  --line-strong: rgba(148, 177, 202, 0.28);
  --text: #edf5f7;
  --muted: #8fa6b7;
  --muted-strong: #b9c9d3;
  --accent: #41dfb2;
  --accent-strong: #1fc495;
  --accent-ink: #03271e;
  --blue: #69a7ff;
  --warning: #f7c768;
  --danger: #ff7f8f;
  --radius: 22px;
  --radius-small: 13px;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 8% -5%, rgba(49, 108, 159, 0.2), transparent 34rem),
    radial-gradient(circle at 96% 8%, rgba(39, 181, 142, 0.1), transparent 30rem),
    var(--bg);
}

button, input, textarea, select { font: inherit; }
button, label, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 12px max(22px, env(safe-area-inset-right)) 12px max(22px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(7, 16, 29, 0.78);
  backdrop-filter: blur(18px);
}

.brand { display: inline-flex; align-items: center; gap: 11px; font-weight: 760; letter-spacing: -0.02em; }
.brand-mark { display: inline-flex; align-items: flex-end; gap: 3px; width: 52px; height: 52px; padding: 11px; border-radius: 16px; background: linear-gradient(145deg, #4aefc0, #36a9cf); box-shadow: 0 12px 32px rgba(54, 208, 167, .24); }
.brand-mark span { flex: 1; border-radius: 99px; background: #03271e; }
.brand-mark span:nth-child(1) { height: 46%; }
.brand-mark span:nth-child(2) { height: 100%; }
.brand-mark span:nth-child(3) { height: 70%; }
.brand-mark-small { width: 34px; height: 34px; padding: 8px; border-radius: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; color: var(--muted-strong); font-size: .78rem; }
.status-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 4px rgba(247, 199, 104, .09); }
.status-pill.is-online i { background: var(--accent); }
.status-pill.is-error i { background: var(--danger); }

.config-banner {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  padding: 12px max(22px, calc((100vw - 1440px) / 2));
  color: #fff2cc;
  background: rgba(129, 88, 16, .3);
  border-bottom: 1px solid rgba(247, 199, 104, .23);
  font-size: .84rem;
}
.config-banner-copy { display: flex; gap: 12px; align-items: baseline; }
.config-banner span { color: #d7c9a5; }
.key-setup-form { display: flex; flex: 0 1 520px; gap: 8px; }
.key-setup-form input { min-height: 38px; }
.key-setup-form .button { flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
  align-items: start;
  gap: 24px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 30px 24px 60px;
}

.card { border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(155deg, rgba(18, 34, 53, .94), rgba(10, 22, 37, .96)); box-shadow: var(--shadow); }
.composer { padding: clamp(22px, 4vw, 42px); }
.jobs { position: sticky; top: 94px; max-height: calc(100vh - 120px); overflow: hidden; padding: 25px; }
.section-heading, .jobs-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.section-heading { margin-bottom: 34px; }
.section-heading h1 { max-width: 680px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.75rem, 4vw, 2.6rem); line-height: 1.05; letter-spacing: -.045em; }
h2 { margin-bottom: 0; font-size: 1.35rem; letter-spacing: -.025em; }
.eyebrow { margin-bottom: 8px; color: var(--accent); font-size: .68rem; font-weight: 800; letter-spacing: .16em; }
.draft-badge { flex: none; padding: 7px 10px; border: 1px solid rgba(65, 223, 178, .2); border-radius: 999px; color: var(--accent); background: rgba(65, 223, 178, .07); font-size: .73rem; font-weight: 700; }

fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.field-group { margin: 0 0 31px; }
.field-group > legend, .field-group > label, .label-row label { display: block; margin-bottom: 11px; color: var(--muted-strong); font-size: .79rem; font-weight: 720; letter-spacing: .02em; }
.label-row { display: flex; align-items: center; justify-content: space-between; }
.label-row span { color: var(--muted); font-size: .72rem; }
.field-hint { margin: 10px 0 0; color: var(--muted); font-size: .76rem; line-height: 1.5; }

textarea, input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  outline: none;
  color: var(--text);
  background: rgba(4, 14, 25, .64);
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
textarea { min-height: 158px; padding: 16px; line-height: 1.55; resize: vertical; }
input[type="text"], input[type="password"], input[type="number"], select { min-height: 48px; padding: 0 13px; }
textarea::placeholder, input::placeholder { color: #5f778a; }
textarea:focus, input:focus, select:focus { border-color: rgba(65, 223, 178, .72); box-shadow: 0 0 0 4px rgba(65, 223, 178, .09); background: rgba(4, 14, 25, .9); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #7890a2 50%), linear-gradient(135deg, #7890a2 50%, transparent 50%); background-position: calc(100% - 18px) 21px, calc(100% - 13px) 21px; background-size: 5px 5px; background-repeat: no-repeat; }
select:disabled, input:disabled { opacity: .5; cursor: not-allowed; }

.model-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.model-option { position: relative; display: flex; align-items: center; gap: 13px; min-height: 82px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; cursor: pointer; background: rgba(5, 16, 28, .38); transition: .18s ease; }
.model-option:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.model-option.is-selected { border-color: rgba(65, 223, 178, .68); background: linear-gradient(145deg, rgba(65, 223, 178, .11), rgba(28, 68, 73, .12)); box-shadow: inset 0 0 0 1px rgba(65, 223, 178, .07); }
.model-option input { position: absolute; opacity: 0; pointer-events: none; }
.model-orb { display: grid; flex: none; place-items: center; width: 42px; height: 42px; border-radius: 13px; font-weight: 850; }
.seedance-orb { color: #052a20; background: linear-gradient(145deg, #5ef0c4, #36c59d); }
.wan-orb { color: #0b1e38; background: linear-gradient(145deg, #9bc9ff, #6799f6); }
.model-copy { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.model-copy strong { font-size: .9rem; }
.model-copy small { overflow: hidden; color: var(--muted); font-size: .69rem; text-overflow: ellipsis; white-space: nowrap; }
.check-dot { position: absolute; top: 12px; right: 12px; width: 10px; height: 10px; border: 2px solid #506679; border-radius: 50%; }
.is-selected .check-dot { border-color: var(--accent); background: var(--accent); box-shadow: 0 0 0 3px rgba(65, 223, 178, .1); }

.settings-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.control > span { display: block; margin-bottom: 7px; color: var(--muted); font-size: .72rem; font-weight: 650; }
.control > span small { font-weight: 500; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; border: 1px solid var(--line); border-radius: 14px; background: rgba(4, 14, 25, .56); }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: grid; min-height: 39px; place-items: center; padding: 6px 9px; border-radius: 10px; color: var(--muted); font-size: .75rem; font-weight: 680; text-align: center; transition: .16s ease; }
.segmented input:checked + span { color: var(--text); background: #1a2c40; box-shadow: 0 3px 12px rgba(0, 0, 0, .2); }
.guidance-panel { margin-top: 13px; }
.upload-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.upload-box { position: relative; display: flex; min-height: 126px; flex-direction: column; align-items: center; justify-content: center; gap: 5px; padding: 16px; border: 1px dashed rgba(131, 166, 191, .32); border-radius: 15px; cursor: pointer; text-align: center; background: rgba(4, 14, 25, .36); transition: .16s ease; }
.upload-box:hover { border-color: rgba(65, 223, 178, .5); background: rgba(65, 223, 178, .04); }
.upload-box input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-box strong { font-size: .82rem; }
.upload-box small { color: var(--muted); font-size: .68rem; }
.upload-box-wide { width: 100%; }
.upload-icon { display: grid; width: 29px; height: 29px; place-items: center; border-radius: 9px; color: var(--accent); background: rgba(65, 223, 178, .1); font-size: 1.1rem; }
.file-name { display: block; max-width: 100%; margin-top: 4px; overflow: hidden; color: var(--accent); font-size: .68rem; text-overflow: ellipsis; white-space: nowrap; }
.upload-box.is-disabled { pointer-events: none; opacity: .42; }

.switch-row { display: flex !important; align-items: center; justify-content: space-between; gap: 20px; margin: 0 0 14px !important; padding: 15px; border: 1px solid var(--line); border-radius: 15px; cursor: pointer; background: rgba(4, 14, 25, .34); }
.switch-row span { display: flex; flex-direction: column; gap: 4px; }
.switch-row small { color: var(--muted); font-weight: 500; line-height: 1.4; }
.switch-row input { position: absolute; opacity: 0; }
.switch-row i { position: relative; flex: none; width: 46px; height: 26px; border-radius: 99px; background: #26394b; transition: .2s ease; }
.switch-row i::after { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #a9bac5; content: ""; transition: .2s ease; }
.switch-row input:checked + i { background: var(--accent); }
.switch-row input:checked + i::after { left: 23px; background: var(--accent-ink); }
.soundtrack-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(150px, .8fr); gap: 12px; }
.soundtrack-file input[type="file"] { width: 100%; min-height: 48px; padding: 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-small); color: var(--muted); background: rgba(4, 14, 25, .64); }
.soundtrack-file input::file-selector-button { margin-right: 10px; padding: 7px 10px; border: 0; border-radius: 8px; color: var(--text); background: #20364a; }

.estimate-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 8px 0 18px; padding: 18px; border: 1px solid rgba(65, 223, 178, .2); border-radius: 16px; background: linear-gradient(120deg, rgba(65, 223, 178, .08), rgba(29, 68, 93, .12)); }
.estimate-card > div { display: flex; flex-direction: column; gap: 4px; }
.estimate-label { color: var(--muted-strong); font-size: .72rem; }
#estimate-value { color: var(--accent); font-size: 1.35rem; }
.estimate-card p { max-width: 330px; margin: 0; color: var(--muted); font-size: .7rem; line-height: 1.4; text-align: right; }
.confirmations { display: grid; gap: 9px; margin-bottom: 18px; }
.check-row { display: flex; align-items: flex-start; gap: 9px; color: var(--muted-strong); font-size: .75rem; line-height: 1.4; cursor: pointer; }
.check-row input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }

.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; border: 1px solid transparent; border-radius: 11px; cursor: pointer; font-size: .78rem; font-weight: 750; transition: transform .15s ease, filter .15s ease, background .15s ease; }
.button:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button-primary { color: var(--accent-ink); background: linear-gradient(135deg, #50e9bc, #32cba0); box-shadow: 0 10px 28px rgba(50, 203, 160, .16); }
.button-accent { min-height: 37px; color: var(--accent); border-color: rgba(65, 223, 178, .25); background: rgba(65, 223, 178, .08); }
.button-quiet { color: var(--muted-strong); border-color: var(--line); background: rgba(255, 255, 255, .025); }
.button-small { min-height: 34px; padding: 0 11px; font-size: .7rem; }
.button-wide { width: 100%; }
.submit-button { min-height: 54px; justify-content: space-between; padding: 0 20px; font-size: .9rem; }
.submit-button b { font-size: 1.2rem; }
.is-loading { pointer-events: none; }
.is-loading::before { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; content: ""; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.jobs-heading { align-items: center; margin-bottom: 18px; }
.icon-button, .dialog-close { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid var(--line); border-radius: 11px; cursor: pointer; color: var(--muted-strong); background: rgba(255, 255, 255, .025); }
.jobs-list { display: grid; max-height: calc(100vh - 205px); gap: 11px; overflow: auto; padding-right: 3px; scrollbar-width: thin; scrollbar-color: #294158 transparent; }
.empty-state { display: grid; min-height: 310px; place-items: center; align-content: center; padding: 30px; color: var(--muted); text-align: center; }
.empty-state > span { margin-bottom: 12px; color: #446078; font-size: 2rem; }
.empty-state strong { color: var(--muted-strong); }
.empty-state p { max-width: 250px; margin: 7px 0 0; font-size: .75rem; line-height: 1.5; }
.job-card { padding: 14px; border: 1px solid var(--line); border-radius: 15px; background: rgba(4, 14, 25, .43); }
.job-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.job-model { display: flex; align-items: center; gap: 8px; font-size: .78rem; font-weight: 720; }
.job-model i { width: 9px; height: 9px; border-radius: 3px; background: var(--blue); }
.job-card[data-model^="bytedance"] .job-model i { background: var(--accent); }
.job-status { padding: 4px 7px; border-radius: 999px; color: var(--warning); background: rgba(247, 199, 104, .08); font-size: .62rem; font-weight: 750; text-transform: uppercase; }
.job-status.completed { color: var(--accent); background: rgba(65, 223, 178, .08); }
.job-status.failed, .job-status.cancelled, .job-status.expired { color: var(--danger); background: rgba(255, 127, 143, .08); }
.job-prompt { display: -webkit-box; margin: 12px 0 10px; overflow: hidden; color: var(--muted-strong); font-size: .74rem; line-height: 1.45; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.job-meta { display: flex; flex-wrap: wrap; gap: 5px 10px; color: var(--muted); font-size: .64rem; }
.job-progress { height: 3px; margin: 13px 0 0; overflow: hidden; border-radius: 99px; background: #1a2b3c; }
.job-progress i { display: block; width: 34%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, transparent, var(--accent), transparent); animation: progress 1.7s ease-in-out infinite; }
@keyframes progress { from { transform: translateX(-110%); } to { transform: translateX(300%); } }
.job-video { width: 100%; margin-top: 12px; border-radius: 11px; background: #03080e; }
.job-actions { display: flex; gap: 8px; margin-top: 10px; }
.job-actions .button { min-height: 34px; flex: 1; font-size: .68rem; }
.job-warning { margin: 9px 0 0; color: var(--warning); font-size: .66rem; line-height: 1.35; }

.confirm-dialog { width: min(92vw, 470px); padding: 0; border: 1px solid var(--line-strong); border-radius: 22px; color: var(--text); background: #101f30; box-shadow: var(--shadow); }
.confirm-dialog::backdrop { background: rgba(1, 7, 13, .76); backdrop-filter: blur(4px); }
.confirm-dialog form { position: relative; padding: 28px; }
.dialog-close { position: absolute; top: 16px; right: 16px; border: 0; font-size: 1.15rem; }
.confirm-summary { display: grid; grid-template-columns: auto 1fr; gap: 10px 20px; margin: 23px 0; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: rgba(4, 14, 25, .42); }
.confirm-summary dt { color: var(--muted); font-size: .72rem; }
.confirm-summary dd { margin: 0; font-size: .76rem; font-weight: 700; text-align: right; }
.dialog-note { color: var(--muted); font-size: .73rem; line-height: 1.5; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1.25fr; gap: 10px; margin-top: 20px; }

.toast-stack { position: fixed; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 100; display: grid; width: min(390px, calc(100vw - 36px)); gap: 8px; }
.toast { padding: 13px 15px; border: 1px solid var(--line-strong); border-radius: 13px; color: var(--muted-strong); background: #142536; box-shadow: 0 14px 34px rgba(0,0,0,.32); font-size: .75rem; line-height: 1.4; animation: toast-in .2s ease-out; }
.toast.error { border-color: rgba(255,127,143,.35); color: #ffd5db; }
.toast.success { border-color: rgba(65,223,178,.35); color: #caffed; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.privacy-note { margin: 18px 0 0; color: #647c8e; font-size: .67rem; line-height: 1.55; }
.centered { text-align: center; }
.alert { margin: 20px 0; padding: 12px 14px; border: 1px solid; border-radius: 12px; font-size: .75rem; line-height: 1.45; }
.alert-warning { color: #ffe3a5; border-color: rgba(247,199,104,.3); background: rgba(247,199,104,.08); }
.alert-error { color: #ffd0d7; border-color: rgba(255,127,143,.3); background: rgba(255,127,143,.08); }

.login-body { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-shell { width: min(100%, 440px); }
.login-card { padding: clamp(28px, 7vw, 48px); border: 1px solid var(--line); border-radius: 26px; background: linear-gradient(150deg, rgba(18,34,53,.98), rgba(9,20,34,.98)); box-shadow: var(--shadow); }
.login-card .brand-mark { margin-bottom: 26px; }
.login-card h1 { margin-bottom: 14px; }
.login-copy { color: var(--muted-strong); font-size: .87rem; line-height: 1.65; }
.login-form { margin-top: 25px; }
.login-form label { display: block; margin-bottom: 8px; color: var(--muted-strong); font-size: .75rem; font-weight: 700; }
.login-form .button { margin-top: 12px; min-height: 50px; }
code { padding: 1px 4px; border-radius: 4px; color: var(--accent); background: rgba(65,223,178,.09); }

@media (max-width: 1080px) {
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; max-width: 780px; }
  .jobs { position: static; max-height: none; }
  .jobs-list { max-height: none; }
  .empty-state { min-height: 190px; }
}

@media (max-width: 620px) {
  .topbar { min-height: 60px; padding: 10px 14px; }
  .brand > span:last-child { display: none; }
  .status-pill { font-size: .68rem; }
  .button-small { padding: 0 9px; }
  .config-banner { display: grid; gap: 3px; padding: 10px 15px; }
  .config-banner-copy { display: grid; gap: 3px; }
  .key-setup-form { display: grid; grid-template-columns: 1fr; margin-top: 8px; }
  .app-layout { gap: 16px; padding: 15px 12px 50px; }
  .composer, .jobs { padding: 20px 16px; border-radius: 18px; }
  .section-heading { margin-bottom: 27px; }
  .section-heading h1 { font-size: 1.75rem; }
  .draft-badge { display: none; }
  .model-grid, .upload-grid, .settings-grid, .soundtrack-row { grid-template-columns: 1fr; }
  .model-option { min-height: 72px; }
  .segmented span { min-height: 44px; padding: 6px 5px; font-size: .68rem; }
  .estimate-card { align-items: flex-start; flex-direction: column; }
  .estimate-card p { text-align: left; }
  .dialog-actions { grid-template-columns: 1fr; }
  .confirm-dialog form { padding: 24px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
