/* index.css — index page specific styles. Depends on common.css tokens. */

/* ===== Hero ===== */
.hero { text-align: center; padding: 26px 0 30px; }
.hero h1 {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.01em;
  margin-bottom: 12px;
}
.subtitle {
  font-size: 0.9rem;
  color: var(--text-2);
  max-width: 560px;
  margin: 0 auto 22px;
  line-height: 1.8;
}
.flow-steps {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  font-size: 0.78rem;
  color: var(--text-2);
}
.flow-steps li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 5px 14px 5px 6px;
}
.flow-steps .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--grad-accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
}

/* ===== Auth bar (inside header) ===== */
.auth-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.auth-loading { font-size: 0.78rem; color: var(--text-3); }
.auth-bar .user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--text-2);
}
.auth-bar .user-info img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--accent-mid);
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.35);
}
.btn-auth {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 5px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn-auth:hover { background: rgba(167, 139, 250, 0.1); text-decoration: none; }

/* ===== Input panel ===== */
.input-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 22px;
  margin-bottom: 22px;
}
.upload-area {
  position: relative;
  border: 1.5px dashed rgba(167, 139, 250, 0.35);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  background: rgba(139, 92, 246, 0.03);
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.upload-area:hover, .upload-area.dragover {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.07);
  box-shadow: inset 0 0 40px rgba(124, 58, 237, 0.08);
}
.upload-area.dragover { border-style: solid; }
.upload-icon {
  width: 36px;
  height: 36px;
  color: var(--accent);
  opacity: 0.9;
  margin-bottom: 10px;
  transition: transform 0.2s;
}
.upload-area:hover .upload-icon, .upload-area.dragover .upload-icon { transform: translateY(-2px); }
.upload-main { font-size: 0.98rem; font-weight: 600; color: var(--text); }
.upload-sub { font-size: 0.8rem; color: var(--text-3); margin-top: 3px; }
.upload-area .filename {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 500;
  margin-top: 10px;
  word-break: break-all;
}
input[type="file"] { display: none; }

.input-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 18px 0;
  color: var(--text-3);
  font-size: 0.76rem;
}
.input-divider::before, .input-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.text-input-area { margin-bottom: 18px; }
.scenario-textarea {
  width: 100%;
  min-height: 130px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.7;
  padding: 12px 14px;
  resize: vertical;
  font-family: inherit;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.scenario-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.16);
}
.scenario-textarea::placeholder { color: var(--text-3); }

/* JSON re-load area (tertiary) */
.json-area {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: transparent;
}
.json-area:hover, .json-area.dragover {
  border-color: var(--text-3);
  background: rgba(148, 148, 180, 0.05);
}
.json-area p { font-size: 0.78rem; color: var(--text-3); }

/* ===== Mode badge ===== */
#modeBadgeWrap { text-align: center; margin-bottom: 8px; }
.mode-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 12px;
  border-radius: var(--radius-full);
}
.mode-badge.text { background: rgba(59, 130, 246, 0.15); color: #93c5fd; border: 1px solid rgba(59, 130, 246, 0.5); }
.mode-badge.vision { background: rgba(167, 139, 250, 0.15); color: #c4b5fd; border: 1px solid rgba(139, 92, 246, 0.5); }

/* ===== Mode selection ===== */
.mode-selection {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  animation: status-in 0.25s ease;
}
.btn-mode-auto {
  background: var(--grad-accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 24px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--glow-accent);
  transition: box-shadow 0.18s, transform 0.12s;
}
.btn-mode-auto:hover { box-shadow: 0 4px 22px rgba(124, 58, 237, 0.55); transform: translateY(-1px); }
.btn-mode-question {
  background: transparent;
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.55);
  border-radius: 10px;
  padding: 11px 24px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, transform 0.12s;
}
.btn-mode-question:hover { background: rgba(59, 130, 246, 0.1); transform: translateY(-1px); }
.model-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.84rem;
  padding: 9px 12px;
  cursor: pointer;
  transition: border-color 0.18s;
}
.model-select:focus { outline: none; border-color: var(--accent); }
.mode-caption {
  flex-basis: 100%;
  width: 100%;
  font-size: 0.76rem;
  color: var(--text-3);
  line-height: 1.6;
}

/* ===== Actions bar ===== */
.actions {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  align-items: center;
}

/* ===== Questions section ===== */
.questions-section { display: none; margin-bottom: 28px; }
.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
}
.question-card .q-text {
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 14px;
  font-weight: 600;
}
.question-choices { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-choice {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-2);
  padding: 7px 18px;
  font-family: inherit;
  font-size: 0.86rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s, box-shadow 0.15s;
}
.btn-choice:hover { border-color: var(--accent); color: var(--text); }
.btn-choice.selected {
  background: var(--grad-accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 1px 10px rgba(124, 58, 237, 0.4);
}
.btn-confirm-questions {
  background: linear-gradient(135deg, #10b981, #047857);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 26px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
  box-shadow: 0 2px 14px rgba(16, 185, 129, 0.28);
  transition: box-shadow 0.18s, transform 0.12s, opacity 0.18s;
}
.btn-confirm-questions:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.btn-confirm-questions:hover:not(:disabled) {
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.42);
  transform: translateY(-1px);
}

/* ===== Generation options ===== */
.gen-options-section {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 22px;
  margin-bottom: 28px;
}
.gen-options-section .section-header { margin-bottom: 6px; border-bottom: none; padding-bottom: 0; }
.gen-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.gen-option:last-of-type { border-bottom: none; }
.gen-option input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 40px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}
.gen-option input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #8f8ba8;
  transition: transform 0.2s, background 0.2s;
}
.gen-option input[type="checkbox"]:checked {
  background: var(--grad-accent);
  border-color: transparent;
}
.gen-option input[type="checkbox"]:checked::after { transform: translateX(18px); background: #fff; }
.gen-option input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.4; }
.gen-option label { color: var(--text); font-size: 0.9rem; cursor: pointer; }
.gen-option label.muted { color: var(--text-3); cursor: not-allowed; }
.gen-option .gen-note { font-size: 0.76rem; color: var(--text-3); margin-left: 5px; }
.btn-generate-start {
  background: var(--grad-accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 13px 32px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  margin-top: 18px;
  width: 100%;
  box-shadow: var(--glow-accent);
  transition: box-shadow 0.18s, transform 0.12s, opacity 0.18s;
}
.btn-generate-start:hover:not(:disabled) {
  box-shadow: 0 4px 24px rgba(124, 58, 237, 0.55);
  transform: translateY(-1px);
}
.btn-generate-start:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

/* ===== Pipeline task cards ===== */
.pipeline-section { margin-top: 20px; }
.pipeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.pipeline-header .pipeline-title { font-size: 0.92rem; color: var(--text); font-weight: 700; }
.btn-zip-rebuild {
  background: transparent;
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.5);
  border-radius: var(--radius-sm);
  padding: 6px 16px;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn-zip-rebuild:hover:not(:disabled) { background: rgba(59, 130, 246, 0.12); }
.btn-zip-rebuild:disabled { opacity: 0.4; cursor: not-allowed; }
.task-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.task-card {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 94px;
  transition: border-color 0.25s;
}
.task-card.running { border-color: rgba(139, 92, 246, 0.6); }
.task-card.running::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 200% 100%;
  animation: task-shimmer 1.4s linear infinite;
}
@keyframes task-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}
.task-card.done { border-color: rgba(16, 185, 129, 0.5); }
.task-card.error { border-color: rgba(239, 68, 68, 0.55); }
.task-card-head { display: flex; align-items: center; gap: 8px; }
.task-kind {
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.task-kind.bg { background: rgba(59, 130, 246, 0.16); color: #93c5fd; }
.task-kind.npc { background: rgba(251, 191, 36, 0.16); color: var(--warn); }
.task-kind.bgm { background: rgba(167, 139, 250, 0.16); color: #c4b5fd; }
.task-kind.zip { background: rgba(16, 185, 129, 0.16); color: #6ee7b7; }
.task-label {
  font-size: 0.85rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.task-state { font-size: 0.76rem; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.task-state.pending { color: var(--text-3); }
.task-state.running { color: var(--accent); }
.task-state.done { color: #6ee7b7; }
.task-state.error { color: #fca5a5; }
.task-note { font-size: 0.7rem; color: var(--gold); }
.task-thumb {
  width: 100%;
  height: 90px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
}
.task-icon {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  align-self: center;
}
.task-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-task {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 11px;
  font-family: inherit;
  font-size: 0.74rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-task-retry { background: rgba(239, 68, 68, 0.12); color: #fca5a5; border-color: rgba(239, 68, 68, 0.4); }
.btn-task-retry:hover { background: rgba(239, 68, 68, 0.25); color: #fff; }
.btn-task-preset { background: rgba(59, 130, 246, 0.1); color: #93c5fd; border-color: rgba(59, 130, 246, 0.45); }
.btn-task-preset:hover { background: rgba(59, 130, 246, 0.22); color: #fff; }

/* ===== Scene list (index) ===== */
.scene-list { margin-bottom: 28px; }
.scene-list .scene-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 8px;
  display: block;
}
.scene-card h3 {
  font-size: 0.98rem;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.scene-card h3 .order {
  background: var(--grad-accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 0;
  border-radius: 6px;
  min-width: 30px;
  text-align: center;
  box-shadow: 0 1px 8px rgba(124, 58, 237, 0.3);
  flex-shrink: 0;
}
.scene-card .bg-key {
  font-size: 0.74rem;
  font-family: var(--font-mono);
  color: var(--text-3);
  margin-bottom: 8px;
}
.scene-texts { font-size: 0.85rem; line-height: 1.7; color: var(--text-2); }
.scene-texts .line { padding: 1px 0; }
.scene-texts .line.at-line {
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

/* ===== bg_prompts section ===== */
.bgp-section { margin-bottom: 28px; }
.bgp-warning {
  background: rgba(234, 179, 8, 0.09);
  border: 1px solid rgba(202, 138, 4, 0.5);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.83rem;
  color: #fde047;
  margin-bottom: 12px;
}
.bgp-list { margin-bottom: 12px; }
.bgp-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  margin-bottom: 6px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color 0.2s;
}
.bgp-item:hover { border-color: var(--border-strong); }
.bgp-item .bgp-label { color: var(--text); font-weight: 500; min-width: 120px; flex-shrink: 0; }
.bgp-item .bgp-prompt {
  color: var(--text-3);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bgp-item .bgp-thumb {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.bgp-item .bgp-error { color: #fca5a5; font-size: 0.78rem; }

/* Small pill buttons (preset / save / auto-match) */
.btn-preset, .npc-card .npc-preset-btn {
  background: rgba(59, 130, 246, 0.1);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.45);
  border-radius: 6px;
  padding: 4px 11px;
  font-family: inherit;
  font-size: 0.74rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.btn-preset:hover, .npc-card .npc-preset-btn:hover { background: rgba(59, 130, 246, 0.22); color: #fff; }
.btn-save-preset, .btn-save-bgm-preset {
  background: rgba(139, 92, 246, 0.1);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.45);
  border-radius: 6px;
  padding: 4px 11px;
  font-family: inherit;
  font-size: 0.74rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.btn-save-preset:hover, .btn-save-bgm-preset:hover { background: rgba(139, 92, 246, 0.25); color: #fff; }
.btn-save-bgm-preset { margin-top: 8px; }
.btn-auto-match {
  background: rgba(34, 197, 94, 0.1);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.45);
  border-radius: var(--radius-sm);
  padding: 5px 14px;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  margin-left: auto;
  transition: background 0.15s;
}
.btn-auto-match:hover { background: rgba(34, 197, 94, 0.22); }

/* ===== BGM section (index) ===== */
.bgm-section { margin-bottom: 28px; }
.bgm-list { margin-bottom: 12px; }
.bgm-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  transition: border-color 0.2s;
}
.bgm-item:hover { border-color: var(--border-strong); }
.bgm-item-header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.bgm-item .bgm-label { color: var(--text); font-weight: 600; min-width: 120px; flex-shrink: 0; }
.bgm-item .bgm-mood {
  background: rgba(99, 102, 241, 0.16);
  color: #a5b4fc;
  border-radius: var(--radius-full);
  padding: 1px 9px;
  font-size: 0.72rem;
}
.bgm-item .bgm-genre {
  background: rgba(59, 130, 246, 0.14);
  color: #93c5fd;
  border-radius: var(--radius-full);
  padding: 1px 9px;
  font-size: 0.72rem;
}
.bgm-item .bgm-prompt { color: var(--text-3); font-size: 0.78rem; margin-bottom: 4px; }
.bgm-item .bgm-error { color: #fca5a5; font-size: 0.78rem; margin-top: 4px; }
.bgm-player { width: 100%; margin-top: 8px; accent-color: var(--accent); }
.bgm-r2-url { font-size: 0.72rem; color: var(--text-3); word-break: break-all; margin-top: 4px; }
.bgm-r2-url a { color: #60a5fa; }

/* ===== NPC section (index) ===== */
.npc-section { margin-bottom: 28px; }
.npc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: border-color 0.2s;
}
.npc-card:hover { border-color: var(--border-strong); }
.npc-card .npc-icon {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg);
}
.npc-card .npc-icon-empty {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  border: 1px dashed var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: #38344e;
}
.npc-card .npc-body { flex: 1; min-width: 0; }
.npc-card h4 { color: var(--text); font-size: 0.94rem; font-weight: 600; margin-bottom: 3px; }
.npc-card .npc-secret {
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.45);
  border-radius: var(--radius-full);
  padding: 1px 8px;
  vertical-align: 2px;
  margin-left: 4px;
}
.npc-card .memo { font-size: 0.83rem; color: var(--text-2); line-height: 1.6; }
.npc-card .npc-preset-btn { margin-top: 8px; }

/* ===== Saved scenarios ===== */
.saved-section { margin-bottom: 36px; }
.saved-empty { font-size: 0.84rem; color: var(--text-3); padding: 12px 0; }
.saved-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.2s;
}
.saved-item:hover { border-color: var(--border-strong); }
.saved-item .saved-info { flex: 1; min-width: 0; }
.saved-item .saved-title {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 500;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.saved-item .saved-meta { font-size: 0.76rem; color: var(--text-3); }
.saved-item .saved-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn-sm {
  padding: 5px 13px;
  font-family: inherit;
  font-size: 0.78rem;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-load { background: var(--surface-3); color: var(--text-2); border-color: var(--border); }
.btn-load:hover { color: var(--text); border-color: var(--border-strong); }
.btn-del { background: rgba(239, 68, 68, 0.1); color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); }
.btn-del:hover { background: rgba(239, 68, 68, 0.22); color: #fff; }
.btn-import { background: rgba(16, 185, 129, 0.1); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.4); }
.btn-import:hover:not(:disabled) { background: rgba(16, 185, 129, 0.2); }
.actions .btn-import {
  padding: 10px 22px;
  font-size: 0.92rem;
  border-radius: 10px;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

/* ===== Preset modal ===== */
.modal-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.modal-filters select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  padding: 6px 11px;
  font-size: 0.84rem;
  cursor: pointer;
}
.modal-filters select:focus { outline: none; border-color: var(--accent); }
.modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  overflow-y: auto;
  flex: 1;
  padding: 2px;
}
.modal-msg { color: var(--text-3); font-size: 0.85rem; padding: 8px 2px; }
.modal-msg.error { color: #fca5a5; }
.preset-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.preset-card:hover {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.07);
  transform: translateY(-1px);
}
.preset-card .pc-label { color: var(--text); font-size: 0.84rem; font-weight: 600; margin-bottom: 3px; }
.preset-card .pc-cat { font-size: 0.7rem; color: var(--text-3); margin-bottom: 4px; }
.preset-card .pc-tags {
  font-size: 0.68rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preset-card .pc-thumb {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: 5px;
  margin-bottom: 7px;
}
.preset-card .pc-no-img {
  width: 100%;
  height: 80px;
  background: var(--surface-2);
  border-radius: 5px;
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--text-3);
}

/* Save-as-preset form modal */
.save-preset-form { display: flex; flex-direction: column; gap: 12px; }
.save-preset-form label {
  font-size: 0.8rem;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.save-preset-form input, .save-preset-form select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  padding: 8px 11px;
  font-size: 0.86rem;
  width: 100%;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.save-preset-form input:focus, .save-preset-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.16);
}
.save-preset-form .form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

/* ===== Knowledge section ===== */
.knowledge-section { margin-top: 36px; }
.knowledge-list { display: flex; flex-direction: column; gap: 8px; }
.knowledge-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  transition: border-color 0.2s;
}
.knowledge-card:hover { border-color: var(--border-strong); }
.knowledge-card .kn-info { flex: 1; min-width: 0; }
.knowledge-card .kn-title {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.knowledge-card .kn-meta { font-size: 0.74rem; color: var(--text-3); }
.knowledge-card .kn-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-kn {
  padding: 5px 13px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.76rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.5;
  transition: background 0.15s, color 0.15s;
}
.btn-kn:hover { text-decoration: none; }
.btn-kn-view { background: var(--surface-3); color: var(--text-2); border-color: var(--border); }
.btn-kn-view:hover { color: var(--text); border-color: var(--border-strong); }
.btn-kn-download { background: rgba(16, 185, 129, 0.12); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.4); }
.btn-kn-download:hover { background: rgba(16, 185, 129, 0.24); }
.btn-kn-delete { background: rgba(239, 68, 68, 0.1); color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); }
.btn-kn-delete:hover { background: rgba(239, 68, 68, 0.22); color: #fff; }
.btn-kn-save {
  background: transparent;
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.5);
  border-radius: 10px;
  padding: 9px 18px;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, opacity 0.18s;
}
.btn-kn-save:hover:not(:disabled) { background: rgba(59, 130, 246, 0.12); }
.btn-kn-save:disabled { opacity: 0.45; cursor: not-allowed; }
.knowledge-empty { color: var(--text-3); font-size: 0.84rem; }

/* Cache note in status messages */
.note-cache { color: var(--gold); }

/* ===== Mobile responsive ===== */
@media (max-width: 640px) {
  .container { padding: 18px 14px 56px; }
  .hero { padding: 14px 0 22px; }
  .hero h1 { font-size: 1.32rem; }
  .subtitle { font-size: 0.84rem; }
  .flow-steps { gap: 5px; }
  .flow-steps li { padding: 4px 11px 4px 5px; font-size: 0.72rem; }

  .input-panel { padding: 16px; }
  .upload-area { padding: 30px 16px; }

  .actions { gap: 8px; }
  .actions .btn { padding: 12px 14px; font-size: 0.88rem; flex: 1; min-width: 0; }

  .auth-bar { gap: 8px; }
  /* On phones, the avatar alone identifies the user — drop the name text
     (only when an avatar image is actually present). */
  .auth-bar .user-info:has(img) .user-name { display: none; }

  .scene-card { padding: 13px 14px; }
  .scene-card h3 { font-size: 0.92rem; }

  .bgp-item { flex-direction: column; align-items: stretch; gap: 6px; }
  .bgp-item .bgp-label { min-width: unset; }
  .bgp-item .bgp-prompt { white-space: normal; }
  .bgp-item .bgp-thumb { width: 100%; height: 120px; }

  .bgm-item-header { flex-wrap: wrap; }
  .bgm-item .bgm-label { min-width: unset; width: 100%; }

  .modal {
    padding: 18px 16px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 90vh;
    width: 100vw;
    max-width: 100vw;
    position: fixed;
    bottom: 0;
  }
  .modal-overlay { padding: 0; }
  .modal-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }

  .question-choices { gap: 6px; }
  .btn-choice { padding: 9px 15px; font-size: 0.84rem; min-height: 40px; }

  .gen-options-section { padding: 16px; }
  .gen-option { padding: 13px 0; }

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

  .saved-item { flex-direction: column; align-items: stretch; gap: 8px; }
  .saved-item .saved-actions { justify-content: flex-end; }

  .knowledge-card { flex-direction: column; align-items: stretch; gap: 8px; }
  .knowledge-card .kn-actions { justify-content: flex-end; }

  .model-select { width: 100%; }

  .mode-selection { flex-direction: column; align-items: stretch; }
  .btn-mode-question, .btn-mode-auto { width: 100%; padding: 14px; }
}

/* Narrow phones (~375px): keep the top action labels on one line each by
   laying the buttons out as an even 2-per-row grid with a tighter font. */
@media (max-width: 420px) {
  .actions { gap: 6px; }
  .actions .btn, .actions .btn-kn-save {
    flex: 1 1 calc(50% - 3px);
    min-width: 0;
    min-height: 40px;
    padding: 10px 4px;
    font-size: 0.72rem;
    white-space: nowrap;
    text-align: center;
  }
}
