:root {
  --bg: #0b0e14;
  --bg-elevated: #12161f;
  --bg-card: #151a24;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f4f6fb;
  --text-muted: #8b93a7;
  --gradient: linear-gradient(90deg, #e040fb 0%, #00e5ff 100%);
  --gradient-soft: linear-gradient(135deg, rgba(224, 64, 251, 0.15) 0%, rgba(0, 229, 255, 0.12) 100%);
  --shadow-card: 0 24px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--border);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --col-left: 220px;
  --col-right: minmax(460px, 620px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  min-height: 100%;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 14, 20, 0.85);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--gradient);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 14px;
  color: #0b0e14;
  letter-spacing: -0.5px;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.canvas {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(224, 64, 251, 0.08) 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 80% 60%, rgba(0, 229, 255, 0.06) 0%, transparent 50%),
    var(--bg);
}

/* 三栏 */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: var(--col-left) 1fr var(--col-right);
  min-height: 0;
}

.col-mode {
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.col-mode-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 4px 10px 12px;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.mode-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  flex-shrink: 0;
}

.mode-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.mode-btn.active {
  color: #fff;
  border-color: rgba(224, 64, 251, 0.4);
  background: var(--gradient-soft);
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.1);
}

.history-wrap {
  margin-top: auto;
  width: 100%;
  padding: 8px 4px 4px;
}

.history-toggle {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.history-toggle:hover {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
}

.history-panel {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(7, 10, 16, 0.78);
  max-height: 340px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.history-clear {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
}

.history-clear:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.history-list {
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-meta {
  font-size: 10px;
  color: var(--text-muted);
}

.history-prompt,
.history-output {
  font-size: 11px;
  line-height: 1.45;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.history-output-video {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-output-video video {
  width: 100%;
  max-height: 160px;
  border-radius: 8px;
  background: #000;
}

.history-output-video a {
  font-size: 11px;
  color: #7dd3fc;
  text-decoration: none;
}

.history-output-video a:hover {
  text-decoration: underline;
}

.history-output-images {
  display: flex;
  justify-content: flex-start;
}

.history-image-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-output-images a {
  display: block;
}

.history-output-images img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #000;
}

.history-image-download {
  font-size: 11px;
  color: #7dd3fc;
  text-decoration: none;
}

.history-image-download:hover {
  text-decoration: underline;
}

.history-empty {
  font-size: 11px;
  color: var(--text-muted);
  padding: 8px 4px;
}

.col-input {
  padding: 24px 28px;
  overflow-y: auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.control-row > .chip,
.control-row > .chip-select {
  min-width: 130px;
  min-height: 40px;
}

.control-row-label {
  width: 100%;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.workspace[data-mode="text"] .hide-for-text {
  display: none;
}

.text-only {
  display: none;
}

.workspace[data-mode="text"] .text-only {
  display: inline-flex;
}

.workspace[data-mode="image"] #text-model-chip,
.workspace[data-mode="video"] #text-model-chip {
  display: none !important;
}

.workspace:not([data-mode="video"]) .video-only {
  display: none;
}

.workspace:not([data-mode="image"]) .image-only {
  display: none;
}

.workspace[data-mode="text"] .media-only {
  display: none;
}

.input-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.field-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 10px 0 8px;
}

.prompt-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.25);
  min-height: 180px;
  padding: 16px 16px 16px 100px;
}

.workspace[data-mode="text"] .prompt-wrap {
  padding-left: 16px;
}

.prompt-wrap.system-wrap {
  padding: 16px;
  min-height: 128px;
}

.workspace[data-mode="text"] .upload-zone {
  display: none;
}

.image-preview-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.image-preview-item {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.image-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 14px;
  line-height: 18px;
  padding: 0;
  cursor: pointer;
}

.upload-zone {
  position: absolute;
  left: 16px;
  top: 16px;
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
  background: rgba(255, 255, 255, 0.02);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.upload-zone:hover {
  border-color: rgba(0, 229, 255, 0.45);
  color: #00e5ff;
  background: rgba(0, 229, 255, 0.05);
}

.upload-zone span {
  font-size: 28px;
  font-weight: 300;
  line-height: 1;
}

.upload-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  padding-left: 4px;
}

.workspace[data-mode="text"] .upload-hint {
  display: none;
}

.workspace[data-mode="image"] .system-only {
  display: none;
}

textarea.prompt {
  width: 100%;
  min-height: 148px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  font-family: inherit;
}

textarea.prompt::placeholder {
  color: var(--text-muted);
  opacity: 0.85;
}

textarea.prompt:focus {
  outline: none;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.chip-select {
  position: relative;
  padding-right: 8px;
  cursor: pointer;
}

.chip-select select {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  padding: 2px 22px 2px 0;
  min-width: 88px;
  line-height: 1.4;
  cursor: pointer;
  outline: none;
}

.chip-select select option {
  background: #10141d;
  color: var(--text);
}

.chip:hover {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
}

.chip svg {
  width: 16px;
  height: 16px;
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 1.7;
  flex-shrink: 0;
}

.chip .chev {
  width: 12px;
  height: 12px;
  margin-left: auto;
  stroke: var(--text-muted);
}

.chip-select .chev {
  pointer-events: none;
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 0;
}

.toolbar-spacer {
  flex: 1;
  min-width: 8px;
}

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

.btn-submit {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--gradient);
  color: #0b0e14;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(224, 64, 251, 0.25);
  transition: transform 0.15s, box-shadow 0.2s;
}

.btn-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 40px rgba(0, 229, 255, 0.2);
}

.btn-submit:active {
  transform: translateY(0);
}

.btn-submit svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.2;
}

/* 右侧输出 */
.col-output {
  border-left: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 20px 20px 24px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.output-head {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 14px;
}

.output-panel {
  flex: 1;
  min-height: 260px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-strong);
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}

.output-panel.has-content {
  align-items: stretch;
  justify-content: flex-start;
  text-align: left;
}

.output-panel.has-content .output-empty {
  display: none;
}

.output-stream {
  width: 100%;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 100px;
}

.output-error {
  width: 100%;
  font-size: 13px;
  line-height: 1.5;
  color: #f87171;
  white-space: pre-wrap;
  word-break: break-word;
}

.output-video {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.output-video video {
  width: 100%;
  max-height: 520px;
  border-radius: 10px;
  background: #000;
}

.output-video a {
  font-size: 12px;
  color: #7dd3fc;
  text-decoration: none;
}

.output-video a:hover {
  text-decoration: underline;
}

.output-image-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.output-image-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.output-image-item img {
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #000;
}

.output-image-item a {
  font-size: 12px;
  color: #7dd3fc;
  text-decoration: none;
}

.output-image-item a:hover {
  text-decoration: underline;
}

.video-progress {
  font-size: inherit;
  font-weight: 400;
  line-height: inherit;
  color: var(--text);
}

.video-progress .time {
  display: inline-block;
  margin-top: 8px;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.output-panel svg {
  width: 48px;
  height: 48px;
  stroke: var(--text-muted);
  opacity: 0.5;
}

.output-placeholder-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

.output-placeholder-desc {
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.85;
  max-width: 220px;
  line-height: 1.5;
}

.btn-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }

  .col-mode {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    padding: 16px;
  }

  .col-mode-title {
    width: 100%;
    padding-bottom: 8px;
  }

  .mode-btn {
    flex: 1;
    min-width: 100px;
    justify-content: center;
  }

  .col-output {
    border-left: none;
    border-top: 1px solid var(--border);
    min-height: 240px;
  }

  .prompt-wrap {
    padding-left: 16px;
    padding-top: 96px;
  }

  .upload-zone {
    left: 50%;
    transform: translateX(-50%);
    top: 16px;
  }

  .workspace[data-mode="text"] .prompt-wrap {
    padding-top: 16px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-spacer {
    display: none;
  }

  .submit-group {
    justify-content: flex-end;
    width: 100%;
  }
}

@media (max-width: 720px) {
  .header {
    padding: 12px 16px;
  }

  .col-input {
    padding: 16px;
  }
}
