:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-strong: #f9fafb;
  --panel-soft: #eef2f6;
  --line: #dfe5ec;
  --line-soft: #e9edf3;
  --text: #111827;
  --muted: #7a8491;
  --accent: #00a7d8;
  --accent-strong: #008eb8;
  --blue: #4f86f7;
  --warning: #f6b756;
  --danger: #e5484d;
  --shadow: 0 18px 50px rgba(22, 35, 53, 0.1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
    sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px 18px;
  border-right: 1px solid var(--line-soft);
  background: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand.compact {
  margin-bottom: 8px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(0, 167, 216, 0.18);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(0, 167, 216, 0.12), rgba(79, 134, 247, 0.1));
  color: var(--accent);
  font-weight: 800;
}

.brand-name {
  font-size: 18px;
  font-weight: 780;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.nav-item,
.preset,
.ghost-button,
.small-button,
.primary-button,
.secondary-button {
  border: 1px solid transparent;
  border-radius: 8px;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    transform 0.18s ease;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  border-color: transparent;
  background: #eef2f6;
  color: var(--text);
}

.nav-icon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 6px;
  background: #f2f5f8;
}

.preset-panel {
  display: grid;
  gap: 10px;
}

.panel-title {
  color: var(--muted);
  font-size: 13px;
}

.preset {
  width: 100%;
  padding: 11px 12px;
  background: #f4f6f8;
  color: #2c3440;
  text-align: left;
}

.preset:hover {
  border-color: rgba(0, 167, 216, 0.16);
  background: #eef8fb;
}

.ghost-button {
  margin-top: auto;
  padding: 10px 12px;
  background: transparent;
  color: var(--muted);
}

.ghost-button:hover {
  border-color: var(--line);
  color: var(--text);
}

.account-card {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

.account-card span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 28px 32px 24px;
}

.topbar,
.history-header,
.result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.08;
}

h2 {
  font-size: 20px;
}

.topbar p,
.result-header p,
.history-header p,
.form-title-row p {
  margin-top: 8px;
  color: var(--muted);
}

.status-pill {
  flex: none;
  max-width: 220px;
  padding: 9px 12px;
  border: 1px solid rgba(0, 167, 216, 0.2);
  border-radius: 999px;
  background: #eef9fc;
  color: #087a99;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.status-pill.busy {
  border-color: rgba(246, 183, 86, 0.35);
  background: rgba(246, 183, 86, 0.1);
  color: #a76100;
}

.status-pill.error {
  border-color: rgba(255, 107, 107, 0.35);
  background: rgba(255, 107, 107, 0.1);
  color: #c62a31;
}

.generator-grid {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 18px;
  margin-top: 22px;
  min-height: 0;
}

.composer,
.result-pane,
.history-view,
.settings-view {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.composer {
  order: 2;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 14px 18px;
  position: sticky;
  bottom: 22px;
  z-index: 5;
  border-radius: 24px;
}

.composer .form-title-row,
.composer > .field-label {
  display: none;
}

.form-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.field-label {
  color: #333c48;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 86px;
  resize: vertical;
  border: 0;
  border-radius: 14px;
  padding: 15px;
  background: #f8fafc;
  color: var(--text);
  line-height: 1.65;
  outline: none;
}

#imagePrompt {
  min-height: 120px;
}

textarea:focus,
input:focus {
  border-color: rgba(0, 167, 216, 0.45);
  box-shadow: 0 0 0 3px rgba(0, 167, 216, 0.12);
}

.prompt-footer,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.prompt-footer {
  color: var(--muted);
  font-size: 13px;
}

.video-compose-grid {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 12px;
}

.video-compose-grid .upload-panel {
  grid-column: 1;
  grid-row: 1;
}

.video-compose-grid .prompt-box {
  grid-column: 2;
  grid-row: 1;
}

.prompt-box {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 10px;
  min-width: 0;
}

.small-button,
.secondary-button {
  padding: 9px 12px;
  border-color: var(--line);
  background: #f4f6f8;
  color: #2c3440;
}

.small-button:hover,
.secondary-button:hover {
  background: #eef2f6;
}

.primary-button {
  padding: 11px 16px;
  border-color: rgba(0, 167, 216, 0.36);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.upload-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
  min-width: 0;
}

.upload-drop {
  cursor: pointer;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  min-height: 86px;
  border: 1px dashed rgba(0, 167, 216, 0.28);
  border-radius: 14px;
  background: #f8fafc;
  color: #2c3440;
  text-align: center;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.upload-drop:hover,
.upload-drop.dragover {
  border-color: rgba(0, 167, 216, 0.6);
  background: #eef9fc;
}

.upload-drop.dragover {
  transform: translateY(-1px);
}

.upload-drop.has-file {
  min-height: 62px;
}

.upload-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-icon {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  background: rgba(0, 167, 216, 0.1);
  color: var(--accent);
  font-size: 24px;
  font-weight: 800;
}

.upload-drop small,
.first-frame-preview small {
  max-width: 360px;
  color: var(--muted);
  line-height: 1.45;
}

.first-frame-preview {
  display: grid;
  gap: 10px;
}

.first-frame-preview img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f3f6f9;
}

.first-frame-preview[data-aspect="9:16"] img {
  aspect-ratio: 9 / 16;
}

.first-frame-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.first-frame-tools small {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: #f8fafc;
}

.control span {
  color: var(--muted);
  font-size: 13px;
}

.control input,
.control select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 9px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.control small {
  color: var(--muted);
}

.control select {
  min-height: 39px;
}

.control-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.range-control input {
  padding: 0;
  accent-color: var(--accent);
}

.ratio-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.ratio-group legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 13px;
}

.ratio-group label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fafc;
  color: #2c3440;
}

.ratio-group input {
  accent-color: var(--accent);
}

.result-pane {
  order: 1;
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr) auto;
  gap: 14px;
  flex: 1;
  min-height: 430px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.preview-frame {
  position: relative;
  display: grid;
  min-height: min(42vh, 520px);
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  background: #fff;
}

.preview-empty {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.preview-empty strong {
  color: var(--text);
  font-size: 18px;
}

.progress-panel {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  width: min(520px, 100%);
  margin: auto;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.progress-panel strong {
  color: var(--text);
  font-size: 18px;
}

.progress-panel p {
  color: var(--muted);
  font-size: 14px;
}

.progress-bar {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef2f6;
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  transition: width 280ms ease;
}

.preview-mark {
  width: 92px;
  height: 52px;
  border: 2px solid rgba(0, 167, 216, 0.34);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(0, 167, 216, 0.12), rgba(79, 134, 247, 0.1));
}

.preview-video {
  width: 100%;
  height: min(58vh, 560px);
  min-height: 320px;
  max-height: 72vh;
  background: #000;
  object-fit: contain;
}

.media-card {
  display: grid;
  gap: 12px;
  align-self: center;
  width: 100%;
  padding: 16px;
}

.media-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.media-actions.compact {
  padding-top: 10px;
}

.media-actions .small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  text-decoration: none;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-content: center;
  width: 100%;
  padding: 16px;
}

.image-grid a {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f6f9;
}

.image-card {
  display: grid;
  gap: 8px;
}

.image-grid img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

.link-list {
  display: grid;
  align-content: center;
  gap: 12px;
  padding: 20px;
}

.link-list a {
  color: #087a99;
  overflow-wrap: anywhere;
}

.raw-output {
  max-height: 240px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  color: #2c3440;
  font-size: 12px;
  line-height: 1.55;
}

.history-view,
.settings-view {
  margin-top: 28px;
  padding: 20px;
}

.settings-form {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.settings-form fieldset {
  display: grid;
  gap: 14px;
  margin: 0;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 16px;
}

.settings-form legend {
  padding: 0 6px;
  color: #333c48;
  font-weight: 750;
}

.settings-form label {
  display: grid;
  gap: 8px;
}

.settings-form label span {
  color: var(--muted);
  font-size: 13px;
}

.settings-form input,
.settings-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.settings-form small {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.settings-message {
  align-self: center;
  color: var(--muted);
  font-size: 14px;
}

.history-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
}

.history-item strong {
  display: block;
  margin-bottom: 6px;
}

.history-item p {
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.login-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(6, 8, 12, 0.74);
  backdrop-filter: blur(12px);
}

.login-dialog {
  display: grid;
  gap: 14px;
  width: min(380px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-dialog input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.login-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    padding: 14px 18px;
  }

  .side-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .preset-panel {
    display: none;
  }

  .ghost-button {
    margin-top: 0;
  }

  .generator-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 20px 14px;
  }

  .topbar,
  .history-header,
  .result-header {
    display: grid;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .side-nav {
    grid-template-columns: 1fr 1fr;
  }

  .control-grid,
  .control-grid.two,
  .video-compose-grid,
  .ratio-group,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .result-pane {
    min-height: 520px;
  }

  .preview-frame {
    min-height: 300px;
  }

  .history-item {
    grid-template-columns: 1fr;
  }
}
