:root {
  --bg: #0b1020;
  --surface: #151b2d;
  --surface-hover: #1e2640;
  --border: #2a3452;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --success: #4ade80;
  --error: #f87171;
  --warning: #fbbf24;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.app {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px;
}

header {
  text-align: center;
  margin-bottom: 28px;
}

header h1 {
  font-size: 1.9rem;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

header p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 20px;
  transition: box-shadow 0.2s;
}

.card h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-intro {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-bottom: 14px;
}

.form-grid,
.editor-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.compact-grid {
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field.row {
  flex-direction: row;
  gap: 14px;
  flex-wrap: wrap;
}

.field.row > div {
  flex: 1;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

input,
select,
textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

button {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s;
  font-weight: 500;
}

button:hover {
  background: var(--border);
}

button.primary {
  background: var(--accent);
  color: #0f172a;
  border-color: var(--accent);
  font-weight: 600;
}

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

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

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  flex-wrap: wrap;
}

.mode-switch {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-chip {
  background: rgba(56, 189, 248, 0.08);
  border-color: rgba(56, 189, 248, 0.22);
}

.mode-chip.active {
  background: var(--accent);
  color: #0f172a;
  border-color: var(--accent);
  font-weight: 700;
}

.mode-copy-box {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.12), rgba(167, 139, 250, 0.08));
  border: 1px solid rgba(56, 189, 248, 0.16);
}

.mode-copy-box strong {
  display: block;
  margin-bottom: 6px;
}

.mode-copy-box p {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.preset-card {
  text-align: left;
  min-height: 112px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  justify-content: flex-start;
  background: linear-gradient(180deg, rgba(30, 38, 64, 0.95), rgba(21, 27, 45, 0.95));
}

.preset-card strong {
  font-size: 0.96rem;
}

.preset-card span {
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.summary-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.summary-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-sub {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.status-note {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.status-note.success {
  border-color: rgba(74, 222, 128, 0.35);
  background: rgba(74, 222, 128, 0.12);
  color: var(--text);
}

.status-note.warn {
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.12);
  color: var(--text);
}

.advanced-panel {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(11, 16, 32, 0.5);
  overflow: hidden;
}

.advanced-panel summary {
  cursor: pointer;
  padding: 14px 16px;
  color: var(--text);
  font-weight: 600;
  list-style: none;
}

.advanced-panel summary::-webkit-details-marker {
  display: none;
}

.advanced-panel-body {
  padding: 0 16px 16px;
}

.panel-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.compliance-card {
  border-color: rgba(251, 191, 36, 0.42);
  background:
    linear-gradient(135deg, rgba(251, 191, 36, 0.13), rgba(56, 189, 248, 0.06)),
    var(--surface);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
}

.info-card-body {
  display: block;
}

.card.is-minimized {
  padding-bottom: 14px;
}

.card.is-minimized .info-card-body {
  display: none;
}

.compliance-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.compliance-heading h2 {
  margin-bottom: 8px;
  color: var(--warning);
}

.compliance-badge {
  border: 1px solid rgba(251, 191, 36, 0.36);
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.12);
  color: var(--text);
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.guide-title-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.minimize-btn {
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(11, 16, 32, 0.55);
  border-color: rgba(148, 163, 184, 0.34);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.minimize-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.compliance-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding-left: 1.1rem;
  color: var(--text);
  font-size: 0.9rem;
}

.compliance-list li::marker {
  color: var(--warning);
}

.compliance-list strong {
  color: #fde68a;
}

.compliance-details {
  margin-top: 14px;
  border-top: 1px solid rgba(251, 191, 36, 0.22);
  padding-top: 12px;
}

.compliance-details summary {
  cursor: pointer;
  color: #fde68a;
  font-weight: 700;
  font-size: 0.9rem;
}

.compliance-rules {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.compliance-rules > div {
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 12px;
  background: rgba(11, 16, 32, 0.52);
  padding: 12px;
}

.compliance-rules h3 {
  color: var(--text);
  font-size: 0.92rem;
  margin-bottom: 6px;
}

.compliance-rules p {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.55;
}

.diy-guide-card {
  background:
    linear-gradient(180deg, rgba(56, 189, 248, 0.08), rgba(167, 139, 250, 0.05)),
    var(--surface);
}

.guide-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.guide-heading h2 {
  margin-bottom: 8px;
}

.guide-badge {
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.1);
  color: var(--text);
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.guide-panel,
.guide-format-card,
.guide-recipes > div {
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 12px;
  background: rgba(11, 16, 32, 0.52);
  padding: 14px;
}

.guide-panel h3,
.guide-format-card h3,
.guide-recipes h3 {
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.guide-defs {
  display: grid;
  gap: 10px;
}

.guide-defs div {
  border-top: 1px solid rgba(148, 163, 184, 0.14);
  padding-top: 10px;
}

.guide-defs div:first-child {
  border-top: none;
  padding-top: 0;
}

.guide-defs dt {
  color: #bae6fd;
  font-weight: 700;
  font-size: 0.86rem;
  margin-bottom: 2px;
}

.guide-defs dd,
.guide-format-card li,
.guide-recipes p {
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.55;
}

.guide-format-row {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 12px;
  margin-top: 12px;
}

.guide-format-card ul {
  display: grid;
  gap: 8px;
  padding-left: 1.1rem;
}

.guide-format-card li::marker {
  color: var(--accent);
}

.guide-format-card pre {
  overflow-x: auto;
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.24);
  padding: 12px;
  margin: 0;
}

.guide-format-card code {
  color: #e0f2fe;
  font-size: 0.8rem;
  line-height: 1.5;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Fira Code", monospace;
}

.guide-details {
  margin-top: 14px;
  border-top: 1px solid rgba(56, 189, 248, 0.18);
  padding-top: 12px;
}

.guide-details summary {
  cursor: pointer;
  color: #bae6fd;
  font-weight: 700;
  font-size: 0.9rem;
}

.guide-recipes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.mini-action {
  padding: 4px 10px;
  font-size: 0.76rem;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.1);
  border-color: rgba(56, 189, 248, 0.24);
}

.editor-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(56, 189, 248, 0.06);
}

.toolbar-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.token-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
}

.token-count.warning {
  color: var(--warning);
}

.token-count.danger {
  color: var(--error);
}

#avatar-preview {
  width: 220px;
  height: 220px;
  border-radius: 14px;
  background: var(--bg);
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  overflow: hidden;
  margin-bottom: 12px;
}

#avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.import-box {
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

.import-box h3 {
  font-size: 1.05rem;
  margin-bottom: 10px;
  color: var(--text);
}

#detect-status,
#import-status,
#generate-status,
#config-status {
  font-size: 0.9rem;
  min-height: 1.4em;
}

#detect-status.found,
#import-status.success,
#config-status.success,
#generate-status.success {
  color: var(--success);
}

#detect-status.notfound,
#import-status.error,
#config-status.error,
#generate-status.error {
  color: var(--error);
}

.alt-greeting-item {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: stretch;
}

.alt-greeting-item textarea {
  flex: 1;
}

.alt-greeting-item button {
  padding: 0 12px;
  background: transparent;
  color: var(--error);
  border: none;
  font-size: 1.1rem;
}

@media (max-width: 640px) {
  .mode-switch,
  .actions,
  .editor-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .mode-chip,
  .editor-toolbar button,
  .actions button {
    width: 100%;
  }
}

.alt-greeting-item button:hover {
  background: rgba(248, 113, 113, 0.1);
}

.total-tokens {
  text-align: right;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.total-tokens strong {
  color: var(--text);
}

footer {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 0;
  font-size: 0.85rem;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 22px;
}

.export-option {
  margin-bottom: 10px;
}

.export-opt-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: all 0.2s;
}

.export-opt-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.export-opt-btn.primary {
  background: rgba(56, 189, 248, 0.1);
  border-color: var(--accent);
}

.export-opt-btn.primary:hover {
  background: rgba(56, 189, 248, 0.2);
}

.opt-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}

.opt-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.opt-info strong {
  font-size: 0.95rem;
  color: var(--text);
}

.opt-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 400;
}

@media (max-width: 640px) {
  .app {
    padding: 14px;
  }
  header h1 {
    font-size: 1.5rem;
  }
  .field.row {
    flex-direction: column;
  }
  .field.row > div {
    min-width: auto;
  }
}

/* ========== 创建方式 Tab ========== */
.creation-mode-tabs {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.mode-tab {
  flex: 1;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.93rem;
  font-weight: 500;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.mode-tab:hover {
  border-color: var(--accent);
  color: var(--text);
}

.mode-tab.active {
  background: var(--accent);
  color: #0f172a;
  border-color: var(--accent);
  font-weight: 600;
}

/* ========== 面板显示控制 ========== */
.library-panel.hidden,
.generator-panel.hidden {
  display: none;
}

/* ========== 角色库工具栏 ========== */
.library-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

#library-search {
  width: 100%;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.92rem;
}

.library-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filter-chip {
  padding: 0.32rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.2s;
}

.filter-chip:hover,
.filter-chip.active {
  border-color: var(--accent);
  color: var(--accent);
}

.filter-chip.active {
  background: rgba(56, 189, 248, 0.12);
}

.library-bulkbar {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(11, 16, 32, 0.55);
  padding: 12px;
  margin-bottom: 1rem;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

#library-selected-count {
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
}

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

.library-bulk-actions button {
  padding: 8px 12px;
  font-size: 0.84rem;
}

/* ========== 角色卡片网格 ========== */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.85rem;
}

.library-card-wrap {
  position: relative;
}

.library-select {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: auto;
  padding: 4px 7px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  background: rgba(11, 16, 32, 0.86);
  color: var(--text-muted);
  font-size: 0.72rem;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.library-select input {
  width: 13px;
  height: 13px;
  padding: 0;
  margin: 0;
  accent-color: var(--accent);
}

.library-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  padding: 2.15rem 0.75rem 0.85rem;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  width: 100%;
  min-height: 210px;
  color: inherit;
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.library-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  border-color: var(--accent);
}

.library-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.library-card-avatar {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  margin: 0 auto 0.6rem;
  background: linear-gradient(135deg, #38bdf8, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.library-card-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-card-game {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.library-card-brief {
  margin: 0.65rem 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.library-card-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 0.7rem;
}

.library-card-tags span {
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.7rem;
  line-height: 1;
  padding: 0.26rem 0.45rem;
}

.library-card-action {
  margin-top: auto;
  padding-top: 0.8rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
}

.library-empty {
  text-align: center;
  padding: 2.5rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* ------------------------------------------------------------------ */
/* Header layout                                                        */
/* ------------------------------------------------------------------ */

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.header-brand {
  flex: 1 1 auto;
}

/* ------------------------------------------------------------------ */
/* User bar                                                             */
/* ------------------------------------------------------------------ */

.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding-top: 4px;
}

#auth-guest,
#auth-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-bar-btn {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #0b1020;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.user-bar-btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.user-bar-btn--outline {
  background: transparent;
  color: var(--accent);
}

.user-bar-btn--outline:hover {
  background: rgba(56, 189, 248, 0.1);
}

.user-bar-btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 6px 10px;
}

.user-bar-btn--ghost:hover {
  color: var(--text);
  background: rgba(255,255,255,0.06);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent);
  border: 1.5px solid rgba(56,189,248,0.4);
}

.user-avatar[src=""] {
  visibility: hidden;
  width: 0;
  margin: 0;
  padding: 0;
  border: none;
}

.user-name {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 500;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* Login gate                                                           */
/* ------------------------------------------------------------------ */

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg, #0b1020);
  padding: 24px;
}

.login-gate-card {
  width: 100%;
  max-width: 380px;
  background: #111827;
  border: 1px solid #1e293b;
  border-radius: 16px;
  padding: 36px 32px 32px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.login-gate-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-gate-icon {
  font-size: 2.2rem;
  display: block;
  margin-bottom: 10px;
}

.login-gate-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text, #e2e8f0);
  margin: 0 0 6px;
}

.login-gate-brand p {
  font-size: 0.8rem;
  color: var(--text-muted, #94a3b8);
  margin: 0;
}

#login-gate-checking {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted, #94a3b8);
  font-size: 0.88rem;
  padding: 16px 0;
}

.login-gate-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #1e293b;
  border-top-color: var(--accent, #38bdf8);
  border-radius: 50%;
  animation: gate-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes gate-spin {
  to { transform: rotate(360deg); }
}

.gate-submit-btn {
  width: 100%;
}

.login-gate-signup-row {
  margin-top: 18px;
  text-align: center;
  font-size: 0.84rem;
  color: var(--text-muted, #94a3b8);
}

.login-gate-signup-link {
  color: var(--accent, #38bdf8);
  text-decoration: none;
  font-weight: 600;
  margin-left: 4px;
}

.login-gate-signup-link:hover {
  text-decoration: underline;
}

/* ------------------------------------------------------------------ */
/* Auth status (shared)                                                 */
/* ------------------------------------------------------------------ */

.auth-status {
  display: block;
  margin-top: 10px;
  font-size: 0.84rem;
  min-height: 1.2em;
}

.auth-status.error   { color: #f87171; }
.auth-status.success { color: #4ade80; }
.auth-status.loading { color: var(--text-muted); }

@media (max-width: 640px) {
  .header-top {
    flex-direction: column;
    align-items: flex-start;
  }
  .user-bar {
    align-self: flex-end;
  }
}

@media (max-width: 640px) {
  .creation-mode-tabs {
    gap: 0.5rem;
  }
  .library-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  .library-bulk-actions {
    width: 100%;
  }
  .library-bulk-actions button {
    flex: 1 1 140px;
  }
  .guide-format-row {
    grid-template-columns: 1fr;
  }
  .guide-title-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

/* ------------------------------------------------------------------ */
/* Generation mode switch                                               */
/* ------------------------------------------------------------------ */

.gen-mode-switch {
  display: flex;
  gap: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #1e293b;
  width: fit-content;
}

.gen-mode-btn {
  padding: 8px 20px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.gen-mode-btn:not(:last-child) {
  border-right: 1px solid #1e293b;
}

.gen-mode-btn.active {
  background: var(--accent);
  color: #0b1020;
}

.gen-mode-btn:hover:not(.active) {
  background: rgba(56, 189, 248, 0.08);
  color: var(--text);
}

/* ------------------------------------------------------------------ */
/* Platform info card & quota bars                                      */
/* ------------------------------------------------------------------ */

.platform-info-card {
  margin-top: 16px;
  padding: 16px 18px;
  background: rgba(56, 189, 248, 0.05);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 10px;
}

.platform-provider-badge {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 14px;
}

.quota-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quota-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.quota-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  width: 90px;
  flex-shrink: 0;
}

.quota-bar-wrap {
  flex: 1;
  height: 6px;
  background: #1e293b;
  border-radius: 3px;
  overflow: hidden;
}

.quota-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s;
}

.quota-bar-fill--image {
  background: #a78bfa;
}

.quota-text {
  font-size: 0.8rem;
  color: var(--text);
  width: 44px;
  text-align: right;
  flex-shrink: 0;
}

.platform-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 12px 0 0;
}

/* ------------------------------------------------------------------ */
/* Cloud key sync section                                               */
/* ------------------------------------------------------------------ */

.cloud-key-section {
  margin-top: 14px;
  padding: 14px 16px;
  background: rgba(255,255,255,0.03);
  border: 1px solid #1e293b;
  border-radius: 10px;
}

.cloud-key-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.cloud-key-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}
