:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --line: #d9dfec;
  --text: #1f2937;
  --muted: #6b7280;
  --brand: #1d4ed8;
  --good: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Arial, sans-serif;
}
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }
.legacy-dummy { display: none !important; }
#authView ~ #authView { display: none !important; }
#appView ~ #appView { display: none !important; }
.small { font-size: 12px; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pill { border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; }
.pill.draft { background: #e5e7eb; color: #374151; }
.pill.published { background: #dcfce7; color: #166534; }
.pill.archived { background: #f3f4f6; color: #6b7280; }
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.is-loading {
  position: relative;
  opacity: 0.8;
}
.btn.is-loading::after {
  content: " ";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-left: 6px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.btn.ghost.is-loading::after {
  border-color: #1d4ed8;
  border-right-color: transparent;
}
.btn.secondary { background: #334155; }
.btn.ghost { background: #fff; border-color: var(--line); color: #0f172a; }
.btn.warn { background: var(--danger); }
.field, textarea, select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
  width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.auth-wrap {
  max-width: 460px;
  margin: 72px auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}
.auth-wrap h2 { margin-top: 0; margin-bottom: 6px; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.top-left, .top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.title-input { width: 260px; font-size: 16px; font-weight: 700; }
.theme-input { width: 220px; }

.workspace {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 360px;
  min-height: calc(100vh - 62px);
}
.final-quiz-focus .workspace {
  grid-template-columns: minmax(0, 1fr);
}
.final-quiz-focus .workspace > aside {
  display: none;
}
.final-quiz-focus .workspace > main.col {
  border-right: 0;
}
.col {
  padding: 12px;
  overflow: auto;
  border-right: 1px solid var(--line);
}
.col:last-child { border-right: 0; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.outline-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  margin-bottom: 8px;
  cursor: pointer;
}
.outline-item.active { border-color: #60a5fa; background: #eff6ff; }
.outline-item.drag-target { border-color: #1d4ed8; outline: 2px dashed #1d4ed8; }
.round-progress { font-size: 12px; color: var(--muted); }

.question-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.question-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.question-card.drag-target { border-color: #1d4ed8; outline: 2px dashed #1d4ed8; }
.thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: #eef2ff;
}
.thumb-wrap {
  position: relative;
}
.thumb-prompt-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.2);
  background: rgba(255, 255, 255, 0.92);
  color: #0f172a;
  font-weight: 700;
  line-height: 1;
}
.thumb-prompt-btn:hover {
  background: #ffffff;
}

.dash-layout { max-width: 1300px; margin: 18px auto; width: calc(100% - 24px); }
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dash-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.dash-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}
.dash-brand-title {
  font-weight: 700;
}
.dash-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-menu-wrap {
  position: relative;
}
.user-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 130px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  z-index: 30;
}
.danger-text {
  color: #991b1b !important;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.template-card {
  background: #fff;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.template-card.status-draft { border-left-color: #9ca3af; }
.template-card.status-published { border-left-color: #16a34a; }
.template-card.status-archived { border-left-color: #64748b; }
.theme-tag {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 600;
}
.card-metrics {
  display: flex;
  gap: 12px;
}
.btn.subtle {
  background: transparent;
  border-color: transparent;
  color: #475569;
  padding-left: 0;
  padding-right: 0;
}
.btn.text-danger {
  background: transparent;
  color: #b91c1c;
  border-color: transparent;
}
.card-menu-wrap {
  position: relative;
}
.card-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 170px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 25;
}
.template-empty-card {
  border: 2px dashed #bfdbfe;
  border-radius: 12px;
  background: #f8fbff;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  color: #1e3a8a;
}

.live-session-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  margin-top: 8px;
}
.team-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.team-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px 2px 3px;
  font-size: 11px;
  background: #f8fafc;
  color: #1f2937;
}
.team-chip-avatar {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid #dbe4f3;
  background: #e2e8f0;
}
.team-chip-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}
.team-chip-name {
  font-weight: 600;
}
.team-chip-code {
  border-radius: 999px;
  background: #e9efff;
  color: #1e3a8a;
  padding: 1px 6px;
}

.suggestion-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #fff;
  margin-bottom: 8px;
}
.fact-badge {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
}
.fact-badge.ok { background: #dcfce7; color: #166534; }
.fact-badge.uncertain { background: #fef3c7; color: #92400e; }
.fact-badge.bad { background: #fee2e2; color: #991b1b; }

.log {
  border-radius: 10px;
  border: 1px solid #1e293b;
  background: #0f172a;
  color: #93c5fd;
  padding: 10px;
  min-height: 120px;
  max-height: 210px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
  padding: 18px;
}
.modal-body {
  width: min(980px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 14px;
}
.prompt-popup-body {
  width: min(520px, 100%);
}
.prompt-popup-text {
  margin-top: 10px;
  white-space: pre-wrap;
  max-height: 50vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 10px;
}
.image-crop-canvas {
  width: 100%;
  max-width: 420px;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-top: 10px;
  background: #0f172a;
  display: block;
}
.sample-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.mood-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.mood-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #1e293b;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}
.mood-chip.is-selected {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1e3a8a;
}
#imagePromptInput {
  min-height: 180px;
}
.sample-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
}
.sample-box img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 8px; }
.sample-prompt {
  margin-top: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  max-height: 120px;
  overflow: auto;
  white-space: pre-wrap;
}
.gallery-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.ai-progress {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #f8fafc;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.fq-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 0;
  min-height: calc(100vh - 180px);
}
.fq-sources {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  max-height: calc(100vh - 180px);
  padding: 0;
}
.fq-lineup-col {
  overflow-y: auto;
  max-height: calc(100vh - 180px);
  padding: 10px;
}
.fq-accordion {
  border-bottom: 1px solid var(--line);
}
.fq-accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  user-select: none;
  background: #fafbfd;
}
.fq-accordion-header:hover { background: #f0f2f8; }
.fq-accordion-header .fq-chevron {
  transition: transform 0.2s;
  font-size: 11px;
  color: var(--muted);
}
.fq-accordion.open .fq-chevron { transform: rotate(90deg); }
.fq-accordion-body {
  display: none;
  padding: 6px 8px 10px;
}
.fq-accordion.open .fq-accordion-body { display: block; }
.fq-source-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: grab;
  font-size: 13px;
  border: 1px solid transparent;
  transition: background 0.12s;
}
.fq-source-item:hover { background: #f0f4ff; border-color: var(--line); }
.fq-source-item.in-lineup { opacity: 0.4; cursor: default; }
.fq-source-item img.fq-src-thumb {
  width: 36px;
  height: 36px;
  border-radius: 5px;
  object-fit: cover;
  flex-shrink: 0;
  background: #eef2ff;
}
.fq-src-thumb-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 5px;
  flex-shrink: 0;
  background: #eef2ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.fq-source-item .fq-src-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.fq-source-item .fq-src-title {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
  font-size: 13px;
}
.fq-source-item .fq-src-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fq-table {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.fq-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 4px;
  transition: box-shadow 0.12s, border-color 0.12s;
  min-height: 52px;
}
.fq-row:hover { box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06); }
.fq-row.is-song { background: #f0f6ff; border-left: 3px solid #60a5fa; }
.fq-row.is-set { background: #f3f0ff; border-left: 3px solid #a78bfa; }
.fq-row.drag-over { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.25); }
.fq-row.dragging { opacity: 0.45; }
.fq-row-num {
  width: 28px;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--muted);
  flex-shrink: 0;
}
.fq-row img.fq-row-thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: #eef2ff;
}
.fq-row-thumb-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  flex-shrink: 0;
  background: #eef2ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.fq-row-info {
  flex: 1;
  min-width: 0;
}
.fq-row-title {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.fq-row-meta {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fq-type-pill {
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
.fq-type-pill.trivia { background: #dcfce7; color: #166534; }
.fq-type-pill.soundtrack { background: #dbeafe; color: #1e40af; }
.fq-type-pill.stille-post { background: #ede9fe; color: #5b21b6; }
.fq-type-pill.bluff { background: #fef3c7; color: #92400e; }
.fq-row-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.fq-row-actions button {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.fq-row-actions button:hover { background: #f1f5f9; }
.fq-row-actions button:disabled { opacity: 0.35; cursor: not-allowed; }
.fq-row-actions button.remove-btn:hover { background: #fee2e2; color: var(--danger); }
.fq-drop-zone {
  min-height: 60px;
  border: 2px dashed #c7d2fe;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
  transition: border-color 0.15s, background 0.15s;
}
.fq-drop-zone.drag-over {
  border-color: var(--brand);
  background: #eff6ff;
}

@media (max-width: 900px) {
  .fq-layout { grid-template-columns: 1fr; }
  .fq-sources { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .fq-lineup-col { max-height: none; }
}

@media (max-width: 1200px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr) 300px; }
}
@media (max-width: 980px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .col { border-right: 0; border-bottom: 1px solid var(--line); }
}
