:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #181a1f;
  --panel-soft: #20232a;
  --line: #343842;
  --text: #f0f2f5;
  --muted: #a5adba;
  --muted-2: #7d8593;
  --brand: #39b6a3;
  --brand-strong: #24d0b5;
  --warn: #f0b45a;
  --danger: #f07178;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

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

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

button,
.button {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--brand);
  color: #071513;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

button:hover,
.button:hover {
  background: var(--brand-strong);
}

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

button:disabled:hover {
  background: var(--brand);
}

button.ghost,
.button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

button.ghost:hover,
.button.ghost:hover {
  border-color: var(--brand);
  color: var(--brand-strong);
  background: rgba(57, 182, 163, 0.08);
}

.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-shell {
  width: min(1880px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 30px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #15171c;
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
}

.topbar p,
.panel-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.topbar-actions,
.mini-actions,
.panel-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 14px 0;
}

.metrics div {
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metrics span {
  display: block;
  color: var(--muted-2);
  font-size: 12px;
}

.metrics strong {
  display: block;
  margin-top: 4px;
  font-size: 19px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(440px, 1.15fr) minmax(320px, 0.8fr);
  gap: 14px;
  align-items: stretch;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-head {
  min-height: 74px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111318;
  color: var(--text);
  outline: none;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.55;
  font-size: 13px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(57, 182, 163, 0.15);
}

.prompt-panel textarea,
.script-panel textarea {
  height: 520px;
  border: 0;
  border-radius: 0;
  background: #121419;
}

.prompt-panel textarea {
  height: 440px;
}

.prompt-library {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.prompt-library label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.prompt-library input,
.prompt-library select {
  height: 36px;
  padding: 0 10px;
}

button.danger {
  border-color: #78464d;
  background: #2b1b1e;
  color: #ffb5bd;
}

button.danger:hover {
  border-color: #a45b65;
  background: #382126;
}

.output-panel {
  margin-top: 14px;
}

.chunk-panel {
  margin-top: 14px;
}

.api-panel {
  margin-top: 14px;
}

.output-panel textarea {
  height: 300px;
  border: 0;
  border-radius: 0 0 8px 8px;
  background: #121419;
}

.api-panel textarea {
  height: 420px;
  border: 0;
  border-radius: 0 0 8px 8px;
  background: #121419;
}

.batch-status {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  background: #14171d;
}

.panel-foot {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.split-settings {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr;
  gap: 10px;
  padding: 12px 14px 0;
  background: var(--panel);
}

.split-settings label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.split-settings input,
.split-settings select {
  height: 36px;
  padding: 0 10px;
}

.api-settings {
  display: grid;
  grid-template-columns: minmax(280px, 1.25fr) minmax(260px, 0.95fr) minmax(190px, 0.7fr) minmax(110px, 0.38fr) minmax(150px, 0.52fr) minmax(120px, 0.34fr);
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.api-settings label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.api-settings input {
  height: 36px;
  padding: 0 10px;
}

.api-settings .checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 21px;
}

.api-settings .checkbox-label input {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.api-settings .checkbox-label span {
  margin: 0;
  color: var(--text);
  font-weight: 700;
}

.episode-list {
  height: 609px;
  overflow: auto;
  padding: 10px;
}

.episode-empty {
  margin: 0;
  padding: 16px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  line-height: 1.6;
}

.episode-item {
  width: 100%;
  min-height: 66px;
  display: block;
  text-align: left;
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  cursor: pointer;
}

.episode-item:hover,
.episode-item.active {
  border-color: var(--brand);
  background: rgba(57, 182, 163, 0.1);
}

.episode-item strong {
  display: block;
  margin-bottom: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.episode-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.chunk-size {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.chunk-size input {
  width: 104px;
  height: 34px;
  padding: 0 8px;
}

.chunk-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
  padding: 12px 14px 14px;
}

.chunk-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  overflow: hidden;
}

.chunk-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.chunk-card strong {
  font-size: 13px;
}

.chunk-card p {
  min-height: 72px;
  max-height: 104px;
  overflow: hidden;
  margin: 0;
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #20242c;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1280px) {
  body {
    min-width: 960px;
  }

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

  .episode-panel {
    grid-column: 1 / -1;
  }

  .episode-list {
    height: 220px;
  }

  .api-settings {
    grid-template-columns: 1fr 1fr 1fr;
  }
}
