/* === Comic Fonts === */
@import url('https://fonts.googleapis.com/css2?family=Bangers&display=swap');

/* === CSS Variables & Theme === */
:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #12122a;
  --bg-card: #1a1a3e;
  --bg-input: #0f0f2a;
  --text-primary: #e8e8ff;
  --text-secondary: #9898cc;
  --text-muted: #7878bb;
  --accent: #7c3aed;
  --accent-hover: #9b5cf6;
  --accent-glow: rgba(124, 58, 237, 0.3);
  --accent-subtle: rgba(124, 58, 237, 0.08);
  --accent-gradient: linear-gradient(135deg, #7c3aed, #c084fc);
  --glass-bg: rgba(18, 18, 42, 0.75);
  --glass-border: rgba(124, 58, 237, 0.2);
  --card-glow: 0 0 20px rgba(124, 58, 237, 0.15);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --shadow-colored: 0 4px 20px rgba(124, 58, 237, 0.25);
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --border: #2a2a5a;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 4px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
  --topbar-h: 56px;
  --bottomnav-h: 64px;
  --sidebar-w: 280px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* === Reset === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(124, 58, 237, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(192, 132, 252, 0.04) 0%, transparent 50%);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
a {
  color: var(--accent);
  text-decoration: none;
}
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
input,
textarea,
select {
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  outline: none;
  width: 100%;
  transition: border-color 0.2s;
}
input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
textarea {
  resize: vertical;
  min-height: 80px;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239898cc' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
img {
  max-width: 100%;
  display: block;
}

/* === App Layout === */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* === Top Bar === */
#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  padding-top: var(--safe-top);
  background: var(--glass-bg);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  padding-left: 12px;
  padding-right: 12px;
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow:
    0 1px 0 rgba(124, 58, 237, 0.15),
    0 4px 20px rgba(0, 0, 0, 0.3);
}
#topbar h1 {
  flex: 1;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#menu-btn,
#settings-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}
#menu-btn:hover,
#settings-btn:hover {
  background: var(--bg-card);
}

/* === Sidebar === */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  z-index: 200;
  transform: translateX(0);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
#sidebar.closed {
  transform: translateX(-100%);
}
#sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
}
#sidebar-overlay.hidden {
  display: none;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.logo-text {
  font-size: 1.2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#sidebar-close {
  font-size: 1.6rem;
  padding: 4px 8px;
}
.nav-list {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}
.nav-link {
  display: block;
  padding: 14px 24px;
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}
.nav-link:hover,
.nav-link.active {
  color: var(--text-primary);
  background: rgba(124, 58, 237, 0.12);
  border-left-color: var(--accent);
}
.nav-link.active {
  box-shadow: inset 0 0 20px rgba(124, 58, 237, 0.08);
}
.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
}

/* === Main Content === */
#content {
  flex: 1;
  margin-top: var(--topbar-h);
  margin-bottom: var(--bottomnav-h);
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  max-width: 800px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  overflow-y: auto;
}

/* === Bottom Nav === */
#bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottomnav-h);
  padding-bottom: var(--safe-bottom);
  background: var(--glass-bg);
  border-top: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}
.bnav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 500;
  transition: color 0.2s;
  min-width: 56px;
}
.bnav-btn.active {
  color: var(--accent);
}
.bnav-btn.create-btn {
  background: var(--accent-gradient);
  color: #fff;
  border-radius: 50%;
  width: 52px;
  height: 52px;
  margin-top: -16px;
  box-shadow: 0 4px 16px var(--accent-glow);
  padding: 0;
  justify-content: center;
  animation: pulse-glow 2.5s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%,
  100% {
    box-shadow: 0 4px 16px var(--accent-glow);
  }
  50% {
    box-shadow: 0 4px 28px rgba(124, 58, 237, 0.55);
  }
}
.bnav-btn.create-btn span {
  display: none;
}
.bnav-btn svg {
  flex-shrink: 0;
}

/* === Cards === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition:
    border-color var(--transition-base),
    box-shadow var(--transition-base),
    transform var(--transition-base);
}
.card:hover {
  border-color: var(--glass-border);
  box-shadow: var(--shadow), var(--card-glow);
  transform: translateY(-2px);
}
.card-glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow), var(--card-glow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-title {
  font-size: 1.1rem;
  font-weight: 700;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  transition: all var(--transition-base);
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 2px 16px var(--accent-glow);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #6d28d9, #a855f7);
  transform: translateY(-2px);
  box-shadow: var(--shadow-colored);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  border-color: var(--accent);
  background: rgba(124, 58, 237, 0.08);
}
.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 2px 12px rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}
.btn-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
}
.btn-block {
  width: 100%;
}
.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* === Forms === */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* === Range Sliders === */
.range-group {
  display: flex;
  align-items: center;
  gap: 12px;
}
.range-group input[type='range'] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  border: none;
  padding: 0;
}
.range-group input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow);
  cursor: pointer;
}
.range-group input[type='range']::-moz-range-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  border: none;
}
.range-group input[type='range']::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow);
  cursor: pointer;
  border: none;
}
.range-value {
  min-width: 48px;
  text-align: right;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
}

/* === Tags / Chips === */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-base);
}
.chip.active,
.chip:hover {
  background: var(--accent-gradient);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 12px var(--accent-glow);
}

/* === Genre Grid === */
.genre-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.genre-card {
  padding: 14px 12px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-base);
}
.genre-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  background: rgba(124, 58, 237, 0.1);
  box-shadow: var(--card-glow);
}
.genre-card.active {
  border-color: var(--accent);
  background: rgba(124, 58, 237, 0.15);
  box-shadow: 0 0 16px var(--accent-glow);
}
.genre-emoji {
  font-size: 1.6rem;
  display: block;
  margin-bottom: 6px;
  transition: transform var(--transition-base);
}
.genre-card:hover .genre-emoji {
  transform: scale(1.15);
}

/* === Image Upload Areas === */
.img-upload {
  width: 100%;
  height: 160px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s;
  overflow: hidden;
  position: relative;
}
.img-upload:hover {
  border-color: var(--accent);
}
.img-upload img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.img-upload-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.img-upload-grid .img-upload {
  height: 120px;
}

/* === Character Multi-Image Gallery === */
.char-img-gallery {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.char-img-slot {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}
.char-img-slot-preview {
  flex-shrink: 0;
  width: 90px;
  height: 90px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  transition: border-color 0.2s;
}
.char-img-slot-preview:hover {
  border-color: var(--accent);
}
.char-img-slot-preview img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.char-img-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.char-img-tag {
  font-size: 0.8rem;
  padding: 4px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  color: var(--text);
}
.char-img-desc {
  font-size: 0.8rem;
  padding: 4px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  color: var(--text);
}
.char-img-actions {
  display: flex;
  gap: 6px;
}
.char-img-primary {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  padding: 2px 6px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  transition:
    color 0.15s,
    border-color 0.15s;
}
.char-img-primary.active {
  color: #f5a623;
  border-color: #f5a623;
}
.char-img-primary:hover {
  border-color: #f5a623;
}
.char-img-delete {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  padding: 2px 6px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  transition:
    color 0.15s,
    border-color 0.15s;
}
.char-img-delete:hover {
  color: var(--danger, #e55);
  border-color: var(--danger, #e55);
}
.char-img-caption {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  padding: 2px 6px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  transition:
    color 0.15s,
    border-color 0.15s;
}
.char-img-caption:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.char-img-caption:disabled {
  opacity: 0.5;
  cursor: default;
}
.char-img-regen {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  padding: 2px 6px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  transition:
    color 0.15s,
    border-color 0.15s;
}
.char-img-regen:hover {
  color: var(--accent);
  border-color: var(--accent);
}
.char-img-regen:disabled {
  opacity: 0.5;
  cursor: default;
}
/* Embedding status badge — tiny inline indicator next to tag dropdown */
.char-img-emb-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.65rem;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 8px;
  white-space: nowrap;
}
.char-img-emb-badge.emb-valid {
  background: rgba(76, 175, 80, 0.15);
  color: #4caf50;
}
.char-img-emb-badge.emb-stale {
  background: rgba(255, 193, 7, 0.15);
  color: #ffc107;
}
.char-img-emb-badge.emb-missing {
  background: rgba(158, 158, 158, 0.12);
  color: var(--text-muted);
}
/* Gallery toolbar — row of buttons below the image slots */
.char-img-toolbar {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
/* Inline dropdown panel for reference image generation */
.gen-ref-dropdown {
  margin-top: 10px;
  padding: 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.gen-ref-dropdown .gen-ref-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.gen-ref-dropdown select {
  flex: 1 1 180px;
  min-width: 0;
}
.gen-ref-dropdown .gen-ref-prompt {
  width: 100%;
  min-height: 60px;
  resize: vertical;
  font-size: 0.85rem;
  line-height: 1.4;
}
.gen-ref-dropdown .gen-ref-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.gen-ref-dropdown .gen-ref-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.comic-page {
  background: #fff;
  border-radius: var(--radius);
  padding: 8px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.comic-page.layout-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.comic-page.layout-grid .comic-panel:first-child {
  grid-column: 1 / -1;
}
.comic-page.layout-grid .comic-panel:last-child:nth-child(even) {
  grid-column: 1 / -1;
}
@media (max-width: 500px) {
  .comic-page.layout-grid {
    grid-template-columns: 1fr;
  }
}
.comic-panel {
  background: var(--bg-input);
  border: 2px solid #333;
  border-radius: var(--radius-xs);
  margin-bottom: 8px;
  overflow: hidden;
  min-height: 200px;
  position: relative;
}
.comic-panel img {
  width: 100%;
  display: block;
}
.comic-text {
  padding: 12px 16px;
  color: #000;
  font-size: 0.95rem;
  line-height: 1.5;
}
.comic-narration {
  background: #fffde7;
  border: 2px solid #c8a800;
  padding: 8px 14px;
  margin: 8px;
  border-radius: var(--radius-xs);
  font-style: italic;
  color: #222;
  font-size: 0.92rem;
  font-family: 'Bangers', 'Comic Sans MS', 'Segoe UI', cursive, sans-serif;
  letter-spacing: 0.02em;
  box-shadow: 2px 2px 0 #c8a800;
}
.comic-dialogue {
  background: #fff;
  border: 2.5px solid #111;
  border-radius: 20px;
  padding: 8px 14px 8px 14px;
  margin: 10px 8px 14px 8px;
  position: relative;
  color: #111;
  font-size: 1rem;
  font-family: 'Bangers', 'Comic Sans MS', 'Segoe UI', cursive, sans-serif;
  letter-spacing: 0.02em;
  line-height: 1.4;
  box-shadow: 2px 2px 0 #111;
}
.comic-dialogue::after {
  content: '';
  position: absolute;
  bottom: -13px;
  left: 22px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 4px solid transparent;
  border-top: 13px solid #111;
}
.comic-dialogue::before {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 23px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 3px solid transparent;
  border-top: 11px solid #fff;
  z-index: 1;
}
.speaker-name {
  font-weight: 900;
  font-size: 0.72rem;
  color: #fff;
  background: #111;
  border-radius: 6px 6px 0 0;
  display: inline-block;
  padding: 1px 7px 1px 7px;
  margin-bottom: 4px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* === Choice Buttons === */
.choices-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}
.choice-btn {
  padding: 14px 20px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.95rem;
  text-align: left;
  transition: all 0.2s;
}
.choice-btn:hover {
  border-color: var(--accent);
  background: rgba(124, 58, 237, 0.1);
  transform: translateX(4px);
}

/* === Loading / Spinner === */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  box-shadow: 0 0 12px var(--accent-glow);
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--text-secondary);
}
.streaming-text {
  min-height: 40px;
  white-space: pre-wrap;
  font-size: 0.95rem;
  line-height: 1.6;
}

/* === Modal === */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
#modal-overlay.hidden {
  display: none;
}
#modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: var(--shadow-lg), var(--card-glow);
  animation: modalSlideIn 0.25s ease;
}
@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 16px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}

/* === Toast === */
#toast-container {
  position: fixed;
  top: calc(var(--topbar-h) + 8px);
  right: 16px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 320px;
  border-left: 4px solid transparent;
  box-shadow: var(--shadow);
}
.toast-success {
  background: var(--success);
  color: #fff;
  border-left-color: #16a34a;
}
.toast-error {
  background: var(--danger);
  color: #fff;
  border-left-color: #b91c1c;
}
.toast-info {
  background: var(--accent);
  color: #fff;
  border-left-color: #5b21b6;
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(60px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* === Section Headers === */
.section-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 16px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
@media (forced-colors: active) {
  .section-title {
    -webkit-text-fill-color: CanvasText;
    background: none;
    color: CanvasText;
  }
}
.section-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

/* === List Items === */
.list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  transition:
    border-color var(--transition-base),
    background var(--transition-base),
    box-shadow var(--transition-base),
    transform var(--transition-base);
  cursor: pointer;
}
.list-item:hover {
  border-color: var(--accent);
  background: rgba(124, 58, 237, 0.06);
  box-shadow: var(--card-glow);
  transform: translateX(2px);
}
.list-item-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid var(--border);
  transition: border-color var(--transition-base);
}
.list-item:hover .list-item-avatar {
  border-color: var(--accent);
}
.list-item-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.list-item-info {
  flex: 1;
  min-width: 0;
}
.list-item-title {
  font-weight: 600;
  font-size: 0.95rem;
}
.list-item-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  display: block;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}
.empty-state-text {
  font-size: 1rem;
  margin-bottom: 16px;
}

/* === Tabs === */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}
.tab-btn {
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  white-space: nowrap;
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  text-shadow: 0 0 12px var(--accent-glow);
}

/* === Collapsible Section === */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  cursor: pointer;
  user-select: none;
}
.collapsible-header::after {
  content: '\25BC';
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.collapsible-header.collapsed::after {
  transform: rotate(-90deg);
}
.collapsible-body {
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.collapsible-body.collapsed {
  max-height: 0 !important;
}

/* === Preset Card === */
.preset-card {
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.preset-card-name {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 4px;
}
.preset-card-preview {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  max-height: 40px;
  overflow: hidden;
}

/* === Model Picker === */
.model-picker {
  position: relative;
  width: 100%;
}
.model-picker-selected {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-primary);
  transition: border-color 0.2s;
  min-height: 42px;
}
.model-picker-selected:hover {
  border-color: var(--accent);
}
.model-picker-arrow {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: 8px;
  flex-shrink: 0;
}
.model-picker-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  z-index: 50;
  max-height: 400px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.model-picker-search-wrap {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.model-picker-search {
  width: 100%;
  padding: 8px 12px;
  font-size: 0.9rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
}
.model-picker-search:focus {
  border-color: var(--accent);
}
.model-picker-status {
  padding: 10px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}
.model-picker-list {
  overflow-y: auto;
  flex: 1;
  max-height: 320px;
}
.model-group {
}
.model-group-header {
  position: sticky;
  top: 0;
  padding: 8px 14px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.model-option {
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(42, 42, 90, 0.3);
}
.model-option:hover {
  background: var(--bg-card);
}
.model-option.selected {
  background: rgba(124, 58, 237, 0.15);
  border-left: 3px solid var(--accent);
}
.model-option-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-all;
}
.model-option-id {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  font-family: monospace;
  word-break: break-all;
}
.model-option-details {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 3px;
}
.model-picker-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  font-family: inherit;
}
.btn-link:hover {
  color: var(--accent-hover);
}

/* === Error Log === */
.error-badge {
  position: absolute;
  top: -4px;
  right: -6px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  padding: 0 4px;
  pointer-events: none;
}
#error-panel {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  width: 420px;
  max-width: 100vw;
  max-height: calc(100vh - var(--topbar-h) - var(--bnav-h));
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  z-index: 450;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 4px 20px rgba(0, 0, 0, 0.4);
  animation: slideInRight 0.2s ease;
}
@keyframes slideInRight {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}
.error-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.error-panel-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--danger);
}
#error-panel-body {
  overflow-y: auto;
  flex: 1;
}
.error-log-entry {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(244, 67, 54, 0.1);
}
.error-log-header {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}
.error-log-context {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.8rem;
}
.error-log-time {
  color: var(--text-muted);
  font-size: 0.75rem;
}
.error-log-msg {
  color: var(--text-primary);
  word-break: break-word;
  font-size: 0.85rem;
  margin-bottom: 4px;
}
.error-log-details {
  color: var(--text-secondary);
  word-break: break-word;
  font-size: 0.8rem;
  margin-bottom: 4px;
}
.error-log-stack {
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
  font-size: 0.7rem;
  margin-top: 4px;
  max-height: 100px;
  overflow-y: auto;
  padding: 6px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* === Utility === */
.hidden {
  display: none !important;
}
.flex {
  display: flex;
}
.flex-col {
  flex-direction: column;
}
.flex-center {
  align-items: center;
  justify-content: center;
}
.gap-sm {
  gap: 8px;
}
.gap-md {
  gap: 16px;
}
.mt-sm {
  margin-top: 8px;
}
.mt-md {
  margin-top: 16px;
}
.mb-sm {
  margin-bottom: 8px;
}
.mb-md {
  margin-bottom: 16px;
}
.text-center {
  text-align: center;
}
.text-muted {
  color: var(--text-muted);
}
.text-sm {
  font-size: 0.85rem;
}
.w-full {
  width: 100%;
}

/* === Responsive === */
@media (max-width: 400px) {
  .genre-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .img-upload-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .bnav-btn span {
    font-size: 0.6rem;
  }
}

/* === Focus Indicators (Keyboard Navigation) === */
.btn:focus-visible,
.chip:focus-visible,
.genre-card:focus-visible,
.choice-btn:focus-visible,
.list-item:focus-visible,
.nav-link:focus-visible,
.bnav-btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* === Animations === */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.fade-in {
  animation: fadeIn 0.3s ease;
}
.slide-up {
  animation: slideUp 0.4s ease;
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .empty-state-icon {
    animation: none;
  }
  .bnav-btn.create-btn {
    animation: none;
  }
}
