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

:root {
  --bg: #fef8f0;
  --surface: #ffffff;
  --sidebar: #3d2c5e;
  --sidebar-hover: #4e3d73;
  --sidebar-active: #ff7eb3;
  --text: #2d2d3a;
  --text2: #666;
  --text3: #999;
  --accent: #ff7eb3;
  --accent-light: #fff0f5;
  --success: #2ed573;
  --error: #ff6b6b;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --border: #f0e6d9;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Login ──────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #fce4ec 0%, #f3e5f5 50%, #e8eaf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px 36px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.1);
  text-align: center;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--sidebar);
}

.login-sub {
  font-size: 13px;
  color: var(--text3);
  margin-bottom: 24px;
}

.login-card .field { margin-bottom: 16px; text-align: left; }
.login-card .field label { font-size: 13px; font-weight: 600; display: block; margin-bottom: 6px; }
.login-card .field input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}
.login-card .field input:focus { outline: none; border-color: var(--accent); }

.captcha-row { display: flex; gap: 10px; align-items: center; }
.captcha-row input { flex: 1; }
.captcha-row img {
  height: 42px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
}

.login-error { color: var(--error); font-size: 13px; margin-bottom: 12px; min-height: 18px; }

.btn-full { width: 100%; justify-content: center; }

/* ── Demo Hint ────────────────────────────────── */
.demo-hint {
  margin-top: 20px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #fff0f5 0%, #f3e5f5 100%);
  border: 1px dashed var(--accent);
  border-radius: 10px;
  text-align: left;
}
.demo-hint-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 6px;
}
.demo-hint-row {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 2px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.demo-hint-row code {
  background: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: "SF Mono", "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--text);
  border: 1px solid var(--border);
}

/* ── App Layout ─────────────────────────────────── */
.app-container { display: flex; height: 100vh; overflow: hidden; }

/* ── Mobile Header ──────────────────────────────── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: var(--sidebar);
  color: #fff;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  gap: 12px;
}

.mobile-title { font-size: 16px; font-weight: 600; flex: 1; }
.mobile-logout {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.hamburger {
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: all 0.3s;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 49;
}

/* ── Sidebar ────────────────────────────────────── */
.sidebar {
  width: 260px;
  background: var(--sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-header h1 { font-size: 18px; font-weight: 700; }
.sidebar-header p { font-size: 12px; color: rgba(255,255,255,0.5); margin-top: 4px; }

/* ── Mode Switcher ─────────────────────────────── */
.mode-switcher {
  display: flex;
  gap: 4px;
  padding: 0 12px;
  margin: 12px 0 4px;
}

.mode-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  border-radius: 8px;
  text-decoration: none;
  color: rgba(255,255,255,0.5);
  background: transparent;
  transition: all 0.2s;
  cursor: pointer;
}

.mode-item:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.8);
}

.mode-item.active {
  background: var(--accent);
  color: #fff;
}

.mode-icon { font-size: 20px; line-height: 1; }
.mode-label { font-size: 11px; font-weight: 600; white-space: nowrap; }

.btn-new {
  margin: 16px 20px;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-new:hover { background: #e56da0; }

.project-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.project-item {
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s;
}
.project-item:hover { background: var(--sidebar-hover); }
.project-item.active { background: var(--sidebar-active); }
.project-item .pj-topic { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-item .pj-meta { font-size: 11px; color: rgba(255,255,255,0.45); margin-top: 3px; }

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-switch {
  display: block;
  text-align: center;
  padding: 8px;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.8);
  border: none;
  border-radius: 6px;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-switch:hover { background: rgba(255,255,255,0.15); color: #fff; }

.btn-logout-desktop {
  width: 100%;
  padding: 8px;
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.5);
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-logout-desktop:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.8); }

/* ── Main ───────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.main-header {
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.main-header h2 { font-size: 18px; font-weight: 700; }

.tab-bar {
  display: flex;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 0;
}
.tab-btn {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text3);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  padding-bottom: 60px;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Form Elements ──────────────────────────────── */
.field { margin-bottom: 20px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--text3); margin-top: 4px; }

.field input, .field textarea, .field select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.field textarea { resize: vertical; line-height: 1.6; }

.field-row { display: flex; gap: 16px; }
.field-row .field { flex: 1; }

/* ── Buttons ────────────────────────────────────── */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #e56da0; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--accent-light); color: var(--accent); }
.btn-secondary:hover { background: #ffe0ec; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 6px 14px; font-size: 13px; }

/* ── Cards ──────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 12px; }

/* ── Generate ───────────────────────────────────── */
.gen-row { display: flex; gap: 16px; align-items: flex-end; margin-bottom: 20px; }
.gen-row .field { flex: 1; margin-bottom: 0; }

.gen-status {
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.6;
  display: none;
}
.gen-status.show { display: block; }
.gen-status.running { background: #fff0f5; color: #b54a7a; border: 1px solid #ffcce0; }
.gen-status.done { background: #eafbf0; color: #1a7a3a; border: 1px solid #b4ecc5; }
.gen-status.error { background: #fff0f0; color: #c53030; border: 1px solid #fcc; }

/* ── Pages List ─────────────────────────────────── */
.pages-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 28px;
  background: var(--accent-light);
  margin: -24px -28px 16px -28px;
}
.pages-hint { font-size: 13px; color: var(--text2); margin-left: auto; }

.page-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 10px;
  display: grid;
  grid-template-columns: 50px 1fr;
  gap: 12px;
  align-items: start;
  transition: all 0.2s;
}
.page-card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(255,126,179,0.1); }

.page-num {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  text-align: center;
  line-height: 1;
  padding-top: 4px;
}

.page-body { flex: 1; }

.page-meta { display: flex; gap: 8px; margin-bottom: 6px; }

.type-badge, .act-badge {
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.type-badge { background: var(--accent-light); color: var(--accent); }
.act-badge { background: #f0f0f0; color: var(--text2); }

.page-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.page-text { font-size: 13px; color: var(--text2); line-height: 1.5; margin-top: 4px; }
.page-emoji { font-size: 20px; margin-right: 4px; }

.page-dialogue {
  margin-top: 8px;
  padding: 8px 12px;
  background: #fef6f0;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
}
.page-dialogue .dlg-line { margin-bottom: 2px; }
.page-dialogue .dlg-char { font-weight: 600; color: var(--accent); }

.page-sfx {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  background: #fff3e0;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  color: #e67e22;
}

/* ── Page Card: selection + actions ─────────────── */
.page-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255,126,179,0.2);
}

.page-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.btn-edit, .btn-copy-md {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-edit:hover { background: var(--accent-light); border-color: var(--accent); }
.btn-copy-md:hover { background: #f5f5f5; }

/* ── Page Editor Modal ─────────────────────────── */
.modal-slide-editor {
  width: 700px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  text-align: left;
}

.slide-editor-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.slide-editor-header h3 { margin: 0; font-size: 16px; }
.slide-editor-meta { display: flex; gap: 6px; }

.slide-editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.slide-editor-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.editor-field {
  margin-bottom: 14px;
  flex: 1;
}
.editor-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 4px;
}
.editor-field input, .editor-field textarea, .editor-field select {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
.editor-field input:focus, .editor-field textarea:focus, .editor-field select:focus {
  outline: none;
  border-color: var(--accent);
}
.editor-field textarea { resize: vertical; }

.editor-field-row {
  display: flex;
  gap: 12px;
}

/* ── Dialogue Editor ───────────────────────────── */
.dialogue-editor { display: flex; flex-direction: column; gap: 6px; }
.dialogue-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.dialogue-row .dlg-character { flex: 0 0 90px; }
.dialogue-row .dlg-text { flex: 1; }
.dialogue-row .dlg-emotion { flex: 0 0 90px; }
.dialogue-row input {
  padding: 6px 8px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
}
.dialogue-row input:focus { outline: none; border-color: var(--accent); }

.btn-icon {
  width: 24px;
  height: 24px;
  border: none;
  background: #f5f5f5;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  color: var(--text3);
}
.btn-icon:hover { background: #ff5252; color: #fff; }

/* ── Output List ────────────────────────────────── */
.output-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
}
.out-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}
.out-icon.html { background: #e44d26; }
.out-icon.pdf { background: #d24726; }
.out-icon.pptx { background: #c8371e; font-size: 10px; }
.out-info { flex: 1; }
.out-name { font-size: 14px; font-weight: 500; }
.out-meta { font-size: 12px; color: var(--text3); margin-top: 2px; }
.out-actions { display: flex; gap: 6px; }

/* ── Empty State ────────────────────────────────── */
.empty { text-align: center; padding: 60px 20px; color: var(--text3); }
.empty h3 { font-size: 18px; margin-bottom: 8px; color: var(--text2); }
.empty p { font-size: 14px; }

/* ── Toast ──────────────────────────────────────── */
.save-toast {
  position: fixed;
  top: 16px;
  right: 16px;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: var(--success);
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s;
  z-index: 500;
  pointer-events: none;
}
.save-toast.show { opacity: 1; transform: translateY(0); }

/* ── Scrollbar ──────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ddd; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #bbb; }

/* ── Modal ────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }

.modal {
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  width: 400px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  text-align: center;
}

.modal.modal-large {
  width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.modal .modal-sub {
  font-size: 13px;
  color: #999;
  margin-bottom: 20px;
}

.modal .modal-close {
  margin-top: 16px;
  font-size: 13px;
  color: #999;
  cursor: pointer;
  border: none;
  background: none;
}
.modal .modal-close:hover { color: #333; }

/* ── History List ─────────────────────────────── */
.history-list {
  flex: 1;
  overflow-y: auto;
  margin: 16px 0;
  text-align: left;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border: 1px solid #eee;
  border-radius: 8px;
  margin-bottom: 12px;
  transition: all 0.2s;
}

.history-item:hover {
  border-color: #6366f1;
  background: #f5f3ff;
}

.history-info { flex: 1; }

.history-version {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.history-time {
  font-size: 12px;
  color: #999;
  margin-bottom: 4px;
}

.history-note {
  font-size: 13px;
  color: #666;
}

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

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 768px) {
  .mobile-header { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }

  .app-container { padding-top: 52px; }

  .main-header { padding: 12px 16px; }
  .main-header h2 { font-size: 16px; }

  .tab-bar {
    padding: 0 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tab-btn { padding: 10px 14px; font-size: 13px; white-space: nowrap; }

  .tab-content { padding: 16px; }

  .field-row { flex-direction: column; gap: 0; }
  .gen-row { flex-direction: column; gap: 0; }

  .pages-toolbar { padding: 10px 16px; margin: -16px -16px 12px -16px; }
}

@media (max-width: 380px) {
  .mobile-title { font-size: 14px; }
  .tab-btn { padding: 8px 10px; font-size: 12px; }
}
