:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #64727b;
  --line: #d9e0e4;
  --panel: #ffffff;
  --soft: #f4f7f5;
  --brand: #0f766e;
  --brand-dark: #0b5d57;
  --accent: #c2542d;
  --shadow: 0 18px 45px rgba(23, 32, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Noto Sans CJK SC",
    Arial,
    sans-serif;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.08), transparent 34%),
    linear-gradient(180deg, #fbfcfb 0%, #eef4f1 100%);
}

button,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

a.secondary-button {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

button:hover {
  transform: translateY(-1px);
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 92px;
  padding: 0 2px 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 6px;
  font-size: 18px;
  line-height: 1.3;
}

p {
  color: var(--muted);
  line-height: 1.65;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 20px;
  min-height: calc(100vh - 142px);
}

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

.input-panel,
.output-panel,
.settings-panel {
  display: flex;
  flex-direction: column;
  padding: 22px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.compact-header {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.panel-header p {
  margin-bottom: 0;
  font-size: 14px;
}

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

textarea:focus,
select:focus,
input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

#ideaInput {
  flex: 1;
  min-height: 390px;
  padding: 18px;
  resize: none;
  line-height: 1.7;
}

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

label span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select {
  height: 44px;
  padding: 0 12px;
}

input {
  height: 44px;
  padding: 0 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.api-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid #e2c8bd;
  border-radius: 8px;
  padding: 0 11px;
  background: #fff8f4;
  color: #8a3f25;
  font-size: 13px;
  font-weight: 700;
}

.api-pill.is-ready {
  border-color: rgba(15, 118, 110, 0.28);
  background: #e9f4f1;
  color: var(--brand-dark);
}

.action-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.ghost-button,
.plain-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 700;
  white-space: nowrap;
}

.primary-button {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.24);
}

.primary-button:hover {
  background: var(--brand-dark);
}

.secondary-button {
  border: 1px solid rgba(15, 118, 110, 0.3);
  background: #e9f4f1;
  color: var(--brand-dark);
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.plain-button {
  background: transparent;
  color: var(--muted);
}

.output-box {
  flex: 1;
  overflow: auto;
  min-height: 500px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  white-space: pre-wrap;
  line-height: 1.78;
}

.optimize-section {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.optimized-box {
  flex: 0 0 auto;
  min-height: 640px;
  max-height: none;
}

.empty-state {
  display: grid;
  min-height: 420px;
  place-items: center;
  margin: 0;
  color: #87939a;
  text-align: center;
}

.compact-empty {
  min-height: 240px;
}

.settings-view {
  min-height: calc(100vh - 142px);
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.42fr) minmax(0, 0.58fr);
  gap: 22px;
  align-items: stretch;
}

.settings-copy {
  padding: 28px 8px;
}

.settings-copy h2 {
  max-width: 480px;
  font-size: 34px;
}

.settings-copy p {
  max-width: 540px;
}

.mini-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 26px;
}

.mini-list span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid rgba(194, 84, 45, 0.32);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(194, 84, 45, 0.08);
  color: #743a27;
  font-size: 13px;
  font-weight: 700;
}

#conventionInput {
  min-height: 360px;
  padding: 18px;
  resize: vertical;
  line-height: 1.72;
}

#optimizeConventionInput {
  min-height: 300px;
  padding: 18px;
  resize: vertical;
  line-height: 1.72;
}

.rule-block {
  margin-top: 18px;
}

.api-settings {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.api-settings h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.wide-field {
  display: block;
  margin-top: 14px;
}

.settings-note {
  margin: 10px 0 0;
  font-size: 13px;
}

.is-hidden {
  display: none;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 48px));
  border-radius: 8px;
  padding: 12px 14px;
  background: #172026;
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.login-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.login-shell {
  width: min(460px, calc(100vw - 36px));
}

.login-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 30px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-error {
  min-height: 22px;
  margin: 0;
  color: #9f2d16;
}

.user-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.user-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfdfc;
  color: var(--muted);
  font-size: 13px;
}

.batch-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.12fr);
  gap: 20px;
}

.project-home {
  display: grid;
  gap: 20px;
}

.project-create-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: center;
}

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

.project-card {
  display: grid;
  gap: 14px;
  align-content: space-between;
  min-height: 174px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfdfc;
}

.project-card h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

.project-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.workspace-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.workspace-head h2 {
  margin: 2px 0 0;
  font-size: 24px;
}

.batch-panel {
  padding: 22px;
}

.upload-box {
  display: grid;
  min-height: 120px;
  place-items: center;
  border: 1px dashed rgba(15, 118, 110, 0.38);
  border-radius: 8px;
  background: rgba(15, 118, 110, 0.06);
  cursor: pointer;
}

.upload-box input {
  display: none;
}

.upload-box span {
  margin: 0;
  color: var(--brand-dark);
  font-size: 16px;
  font-weight: 800;
}

.batch-summary {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfdfc;
}

.summary-box {
  min-height: 320px;
  max-height: none;
}

.episode-section {
  margin-top: 20px;
}

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

.episode-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfdfc;
}

.episode-card h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.episode-meta {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.status-row {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 700;
}

.status-pill.done {
  border-color: rgba(15, 118, 110, 0.28);
  background: #e9f4f1;
  color: var(--brand-dark);
}

.status-pill.running,
.status-pill.queued {
  border-color: rgba(194, 84, 45, 0.26);
  background: rgba(194, 84, 45, 0.08);
  color: #743a27;
}

.status-pill.failed {
  border-color: rgba(159, 45, 22, 0.28);
  background: rgba(159, 45, 22, 0.08);
  color: #9f2d16;
}

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

.episode-actions button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.project-flow,
.asset-view,
.asset-detail-view {
  display: grid;
  gap: 20px;
}

.flow-hero h2 {
  margin: 4px 0 8px;
  font-size: 28px;
}

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

.flow-card {
  display: grid;
  gap: 24px;
  min-height: 260px;
  align-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: #fbfdfc;
}

.flow-card h3 {
  margin: 6px 0 12px;
  font-size: 24px;
}

.flow-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

#assetConventionInput {
  min-height: 220px;
  padding: 18px;
  resize: vertical;
  line-height: 1.72;
}

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

.asset-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfdfc;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.asset-card:hover {
  transform: translateY(-2px);
  border-color: rgba(48, 128, 116, 0.38);
  box-shadow: 0 18px 45px rgba(18, 37, 33, 0.08);
}

.asset-card-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.asset-card h3 {
  margin: 0;
  font-size: 18px;
}

.asset-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.62;
}

.asset-detail-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 24px;
  align-items: stretch;
}

.asset-portrait-placeholder {
  min-height: 360px;
  border: 1px solid rgba(197, 145, 64, 0.35);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(197, 145, 64, 0.32), rgba(20, 28, 26, 0.88)),
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.16), transparent 45%);
  color: rgba(255, 255, 255, 0.82);
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
}

.asset-detail-copy {
  display: grid;
  gap: 12px;
}

.asset-detail-copy-wide {
  width: 100%;
}

.asset-detail-copy h3 {
  margin: 0;
  font-size: 18px;
}

.asset-detail-copy pre {
  min-height: 140px;
  margin: 0;
  padding: 18px;
  border: 1px solid rgba(28, 68, 60, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  white-space: pre-wrap;
  line-height: 1.75;
  font-family: inherit;
}

.variant-card {
  min-height: 180px;
}

.variant-card pre {
  overflow: auto;
  max-height: 340px;
  margin: 4px 0 0;
  padding: 14px;
  border: 1px solid rgba(28, 68, 60, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  white-space: pre-wrap;
  line-height: 1.72;
  font-family: inherit;
}

.section-note,
.generation-timer {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.generation-timer {
  margin-top: 8px;
  color: var(--accent);
  font-weight: 800;
}

.logic-panel textarea,
#assetConventionInput {
  min-height: 260px;
}

.preview-view {
  min-height: 100vh;
  padding: 28px;
}

.preview-toolbar {
  display: flex;
  gap: 12px;
  margin: 0 auto 18px;
  width: min(1180px, 100%);
}

.preview-panel {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.preview-panel pre {
  overflow: auto;
  min-height: 70vh;
  margin: 18px 0 0;
  white-space: pre-wrap;
  line-height: 1.8;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 18px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  h1 {
    font-size: 24px;
  }

  .workspace,
  .settings-layout,
  .batch-layout,
  .project-create-row,
  .project-grid,
  .episode-grid {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  #ideaInput,
  #conventionInput,
  .output-box {
    min-height: 360px;
  }

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

  .settings-copy {
    padding: 10px 2px 0;
  }

  .settings-copy h2 {
    font-size: 25px;
  }
}
