:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #22262f;
  --border: #2c313c;
  --text: #e8eaed;
  --muted: #9aa3af;
  --accent: #4f8cff;
  --danger: #ff5c5c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  height: 100vh;
  overflow: hidden;
}

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.logo { font-size: 18px; font-weight: 700; color: var(--accent); }

.layout { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 260px; padding: 14px; background: var(--panel);
  border-right: 1px solid var(--border); overflow-y: auto;
}
.sidebar h3 { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.project-list { display: flex; flex-direction: column; gap: 8px; }
.project-item {
  padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; transition: border-color .15s;
}
.project-item:hover { border-color: var(--accent); }
.project-item.active { border-color: var(--accent); }
.project-item .name { font-size: 14px; font-weight: 600; }
.project-item .theme { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.workspace { flex: 1; padding: 20px; overflow-y: auto; }

.empty-state { text-align: center; margin-top: 15vh; color: var(--muted); }
.empty-state h2 { color: var(--text); margin-bottom: 8px; }
.empty-state p { margin-bottom: 16px; }

.editor-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.title-input {
  flex: 1; font-size: 22px; font-weight: 700; background: transparent;
  border: 1px solid transparent; color: var(--text); padding: 4px 8px; border-radius: 6px;
}
.title-input:hover, .title-input:focus { border-color: var(--border); outline: none; }

.status-badge {
  font-size: 12px; padding: 3px 10px; border-radius: 20px;
  background: #2b3a24; color: #8fd47f; white-space: nowrap;
}

.editor-meta {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 0 16px; border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.editor-meta label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.meta-input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 6px 10px; border-radius: 6px; font-size: 13px; min-width: 200px;
}
.meta-input.small { min-width: 60px; width: 70px; }

.gen-status {
  margin: 0 0 14px; padding: 10px 14px; border-radius: 8px;
  background: rgba(79, 140, 255, .12); border: 1px solid rgba(79, 140, 255, .4);
  color: var(--accent); font-size: 13px;
}
.gen-status.error { background: rgba(255, 92, 92, .12); border-color: rgba(255, 92, 92, .4); color: var(--danger); }

.panel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.panel-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.panel-card .page-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.panel-card .page-label .btn.small { margin-top: 0; padding: 2px 8px; font-size: 12px; }
.panel-card .panel-preview {
  height: 200px; background: var(--panel); border: 1px dashed var(--border);
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; overflow: hidden;
}
.panel-card .panel-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.panel-card textarea {
  width: 100%; min-height: 52px; resize: vertical; font-size: 12px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: 6px; border-radius: 6px;
}

.btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 13px;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 22px; width: 420px; max-width: 90vw;
}
.modal-box h3 { margin-bottom: 14px; }
.modal-box label { font-size: 13px; color: var(--muted); display: block; margin: 10px 0 4px; }
.modal-box input, .modal-box textarea, .modal-box select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); padding: 8px 10px; border-radius: 6px; font-size: 13px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.hidden { display: none !important; }

/* ---------- 分步向导 ---------- */
.wizard {
  max-width: 760px; margin: 0 auto; padding: 24px 0;
}
.wizard-steps {
  display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap;
}
.wizard-step {
  padding: 8px 14px; border-radius: 20px; font-size: 13px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.wizard-step.active {
  background: rgba(79, 140, 255, .15); border-color: var(--accent); color: var(--accent); font-weight: 600;
}
.wizard-panel {
  display: none;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 22px;
}
.wizard-panel.active {
  display: block;
}
.wizard-panel h3 { margin-bottom: 14px; font-size: 18px; }
.wizard-panel label { font-size: 13px; color: var(--muted); display: block; margin: 12px 0 4px; }
.wizard-panel input, .wizard-panel textarea, .wizard-panel select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); padding: 9px 11px; border-radius: 6px; font-size: 13px;
  font-family: inherit;
}
.wizard-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.wizard-loading {
  padding: 12px 14px; border-radius: 8px; margin-bottom: 12px;
  background: rgba(79, 140, 255, .12); border: 1px solid rgba(79, 140, 255, .4);
  color: var(--accent); font-size: 13px;
}
.wizard-error {
  padding: 12px 14px; border-radius: 8px; margin-bottom: 12px;
  background: rgba(255, 80, 80, .1); border: 1px solid rgba(255, 80, 80, .45);
  color: #e06060; font-size: 13px; white-space: pre-wrap;
}
.wizard-hint {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 12px;
  background: rgba(255, 200, 80, .1); border: 1px dashed rgba(255, 200, 80, .5);
  color: #d0a24a; font-size: 13px;
}
.asset-empty {
  padding: 24px; text-align: center; border-radius: 8px;
  border: 1px dashed var(--border, #333); color: #888; font-size: 14px;
}
.btn.small {
  padding: 6px 12px; font-size: 13px; margin-top: 8px;
}

/* 画风推荐 */
.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.style-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; cursor: pointer; transition: border-color .15s;
}
.style-card:hover { border-color: var(--accent); }
.style-card.selected { border-color: var(--accent); background: rgba(79, 140, 255, .12); }
.style-card .style-name { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.style-card .style-desc { font-size: 12px; color: var(--muted); }

/* 人物卡片 */
.char-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px;
}
.char-row input { width: 100%; }

/* 资产卡片 */
.asset-section { margin-top: 4px; }
.asset-section h4 { font-size: 14px; color: var(--muted); margin: 14px 0 8px; }
.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}
.asset-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.asset-head { display: flex; align-items: center; justify-content: space-between; }
.asset-status { font-size: 12px; color: var(--muted); }
.asset-card textarea { width: 100%; resize: vertical; font-size: 12px; }
.asset-img { min-height: 40px; }
.asset-img img { width: 100%; border-radius: 8px; border: 1px solid var(--border); }

/* 编辑器摘要/人物 */
.editor-summary, .editor-chars { margin-bottom: 14px; }
.editor-summary summary, .editor-chars summary {
  cursor: pointer; font-size: 14px; font-weight: 600; color: var(--accent); margin-bottom: 8px;
}
.editor-summary textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); padding: 8px 10px; border-radius: 6px; font-size: 13px; resize: vertical;
}
.proj-char {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 8px;
}
.proj-char-name { font-weight: 600; font-size: 14px; }
.proj-char-name span { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 12px; }
.proj-char-appearance { font-size: 12px; color: var(--muted); margin-top: 4px; }
.proj-char img { max-width: 200px; border-radius: 8px; margin-top: 8px; border: 1px solid var(--border); }

/* ---------- 宽高比选择 ---------- */
.aspect-options { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.aspect-option {
  display: flex; align-items: center; gap: 5px; padding: 8px 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; font-size: 13px;
}
.aspect-option:hover { border-color: var(--primary); }

/* ---------- 图片灯箱 ---------- */
#lightbox {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: rgba(0, 0, 0, 0.85);
  align-items: center; justify-content: center; flex-direction: column; gap: 14px;
  padding: 24px;
}
#lightbox.active { display: flex; }
#lightbox img {
  max-width: 92vw; max-height: 80vh; object-fit: contain;
  border-radius: 8px; background: #000; box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.lightbox-actions { display: flex; gap: 12px; }
#lightbox .btn { cursor: pointer; }

/* ---------- 移动端适配（手机 / 窄屏） ---------- */
.topbar-left { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  display: none; font-size: 20px; line-height: 1;
  padding: 6px 12px; min-width: 44px; min-height: 44px;
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 90;
  background: rgba(0, 0, 0, 0.5);
}

@media (max-width: 768px) {
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
  .topbar { padding: 8px 12px; }
  .topbar-actions .btn { padding: 8px 12px; font-size: 13px; }

  /* 侧栏抽屉化 */
  .layout { position: relative; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 95;
    width: 280px; max-width: 82vw;
    transform: translateX(-105%); transition: transform .25s ease;
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
    padding-top: 16px;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay { display: block; }
  .workspace { padding: 12px; }

  /* 触控区放大 */
  .btn { min-height: 44px; }
  .btn.small { min-height: 36px; }
  .project-item { padding: 12px 14px; }
  .project-item .name { font-size: 15px; }

  /* 编辑器顶部元信息堆叠 */
  .editor-header { flex-wrap: wrap; gap: 8px; }
  .title-input { font-size: 18px; min-width: 0; }
  .editor-meta { flex-direction: column; align-items: stretch; gap: 10px; }
  .editor-meta label { flex-wrap: wrap; }
  .meta-input { min-width: 0; width: 100%; }
  .meta-input.small { width: 80px; }

  /* 网格手机端 1~2 列 */
  .panel-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .panel-card .panel-preview { height: 160px; }
  .style-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .asset-grid { grid-template-columns: 1fr; }

  /* 向导 */
  .wizard { padding: 12px 0; }
  .wizard-panel { padding: 16px; }
  .wizard-steps { gap: 6px; }
  .wizard-step { padding: 7px 10px; font-size: 12px; }
  .wizard-actions { flex-wrap: wrap; gap: 8px; }
  .wizard-actions .btn { flex: 1; min-width: 120px; }
  .aspect-option { flex: 1 1 45%; }

  /* 灯箱 */
  #lightbox { padding: 16px; gap: 12px; }
  #lightbox img { max-width: 96vw; max-height: 70vh; }
  .lightbox-actions { width: 100%; max-width: 320px; }
  .lightbox-actions .btn { flex: 1; }

  /* 弹窗全宽 */
  .modal-box { width: 100%; max-width: 94vw; padding: 18px; }

  .empty-state { margin-top: 8vh; }
  .proj-char img { max-width: 100%; }
}
