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

:root {
  --bg:          #1e1e2e;
  --bg-sidebar:  #181825;
  --bg-surface:  #313244;
  --bg-input:    #2a2a3d;
  --bg-hover:    #3a3a55;
  --text:        #cdd6f4;
  --text-dim:    #989db6; /* ≥4.5:1 on --bg and --bg-surface (WCAG AA) */
  --text-muted:  #a6adc8;
  --border:      #313244;
  --accent:      #cba6f7;
  --blue:        #89b4fa;
  --green:       #a6e3a1;
  --red:         #f38ba8;
  --yellow:      #f9e2af;
  --orange:      #fab387;
  --teal:        #94e2d5;
  --on-accent:   #1e1e2e; /* text on accent/blue/red buttons */
  --accent-hover: #d4b8fa;
  --blue-hover:  #9dc5fc;
  --red-hover:   #f5a0b5;
  --focus:       #89b4fa;
  --backdrop:    rgba(0,0,0,0.6);
  --shadow:      0 10px 40px rgba(0,0,0,0.45);
  --radius:      8px;
  --radius-sm:   5px;
  --font-mono:   "Consolas", "Menlo", "Monaco", monospace;
  --font-sans:   "Segoe UI", system-ui, sans-serif;
}

html, body, #app { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
}

/* 100dvh follows the mobile browser chrome; app.js narrows --app-height to the
   visual viewport so the chat input stays above the on-screen keyboard. */
.view { display: flex; height: 100vh; height: var(--app-height, 100dvh); }
.hidden { display: none !important; }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn { min-height: 34px; line-height: 1.3; text-decoration: none; background: var(--bg-surface); color: var(--text); }
.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary  { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover:not(:disabled)  { background: var(--accent-hover); }
.btn-accent   { background: var(--blue); color: var(--on-accent); font-weight: 600; }
.btn-accent:hover:not(:disabled)   { background: var(--blue-hover); }
.btn-ghost    { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled)    { background: var(--bg-hover); color: var(--text); }
.btn-danger   { background: var(--red); color: var(--on-accent); font-weight: 600; }
.btn-danger:hover:not(:disabled)   { background: var(--red-hover); }
.btn-block    { width: 100%; }
.btn-sm       { font-size: 12px; padding: 4px 10px; min-height: 30px; }
.btn-xs       { font-size: 11px; padding: 3px 8px; min-height: 26px; }
.btn-icon     { width: 40px; padding: 0; font-size: 18px; }
.btn.is-busy::after {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}

/* Keyboard focus: one consistent ring for everything focusable */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }
.settings-input:focus-visible, .settings-select:focus-visible, .chat-input:focus-visible { outline-offset: 0; }
a { color: var(--blue); }
a:hover { text-decoration-thickness: 2px; }

/* ── Project Picker ─────────────────────────────────────────────────────── */

#view-projects {
  background: var(--bg);
  align-items: center;
  justify-content: center;
}

.projects-wrap {
  width: 100%;
  max-width: 680px;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.projects-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.project-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 60px;
}

.project-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: border-color 0.15s, background 0.15s;
}
.project-card:hover { border-color: var(--accent); background: var(--bg-hover); }

.project-card-info { display: flex; flex-direction: column; gap: 3px; }
.project-card-title { font-size: 15px; font-weight: 600; color: var(--text); }
.project-card-meta  { font-size: 12px; color: var(--text-dim); display: flex; gap: 10px; }

.project-card-phase {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--phase-color, var(--border));
  color: var(--phase-color, var(--text-muted));
}

.project-card-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--red);
  font-size: 15px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: opacity 0.15s, background 0.15s;
  flex-shrink: 0;
  align-self: center;
}
.project-card:hover .project-card-delete, .project-card:focus-within .project-card-delete { opacity: 0.75; }
.project-card-delete:focus-visible { opacity: 1; }
.project-card-delete:hover { opacity: 1 !important; background: rgba(243,139,168,0.15); }

.import-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.project-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.project-empty-icon { font-size: 34px; line-height: 1; }
.project-empty h3 { font-size: 17px; color: var(--text); }
.project-empty p { max-width: 380px; }
.project-empty-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.projects-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.projects-header-btns { display: flex; gap: 8px; align-items: center; }

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

.series-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 4px;
  border-bottom: 1px solid var(--border);
}
.series-group-title { font-size: 13px; font-weight: 700; color: var(--accent); }
.series-group-meta  { font-size: 11px; color: var(--text-dim); }

.series-group-books { display: flex; flex-direction: column; gap: 6px; padding-left: 12px; }

.btn-add-book {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, color 0.15s;
}
.btn-add-book:hover { border-color: var(--accent); color: var(--accent); }

/* Series badge in sidebar */
.series-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
  padding: 1px 0;
}

/* Series actions in sidebar */
.series-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

/* Series panel */
.series-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }

.series-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  gap: 8px;
}

.series-list-item .item-text { flex: 1; }

.series-list-item .btn-remove {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.series-list-item .btn-remove:hover { color: var(--red); }

.series-add-row { display: flex; gap: 8px; align-items: center; }
.series-lore-input { width: 100%; font-family: var(--font-sans); line-height: 1.6; resize: vertical; }

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  max-height: calc(var(--app-height, 100dvh) - 32px);
  box-shadow: var(--shadow);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal h2 { font-size: 18px; font-weight: 700; color: var(--text); }

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.graduate-section { display: flex; flex-direction: column; gap: 8px; }
.graduate-section h4 { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; color: var(--text-muted); text-transform: uppercase; }

.graduate-check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  padding: 4px 0;
}
.graduate-check-item input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }

.graduate-summary-label { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.graduate-summary-input { width: 100%; font-family: var(--font-sans); font-size: 13px; resize: vertical; line-height: 1.6; }

/* ── Format Picker ──────────────────────────────────────────────────────── */

#view-picker {
  background: var(--bg);
  align-items: center;
  justify-content: center;
}

.picker-wrap {
  width: 100%;
  max-width: 700px;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.picker-header { text-align: center; }

.logo {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent);
  font-family: var(--font-mono);
  margin-bottom: 10px;
}

.picker-subtitle {
  color: var(--text-muted);
  font-size: 15px;
}

.format-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.format-card {
  background: var(--bg-surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 20px 16px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.format-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-2px);
}
.format-card .card-icon { font-size: 26px; margin-bottom: 8px; }
.format-card .card-label { font-weight: 600; font-size: 13px; color: var(--text); }

.picker-footer { text-align: right; }

/* ── Chat Layout ────────────────────────────────────────────────────────── */

#view-chat {
  flex-direction: row;
  background: var(--bg);
}

/* Sidebar */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 16px;
  overflow-y: auto;
}

.sidebar-top { display: flex; flex-direction: column; gap: 8px; }

.app-name {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.session-meta { display: flex; flex-direction: column; gap: 2px; }

.session-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 16px;
}
.session-title:hover { color: var(--accent); }
.session-title:empty::before { content: "Untitled"; color: var(--text-dim); font-style: italic; }

.session-format {
  font-size: 11px;
  color: var(--text-dim);
}

/* Phase nav */
.phase-nav { display: flex; flex-direction: column; gap: 6px; }
.phase-nav-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  padding: 0 4px;
}

.phase-nav ul { list-style: none; display: flex; flex-direction: column; gap: 2px; }

.phase-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
  user-select: none;
}
.phase-item:hover { background: var(--bg-hover); color: var(--text); }
.phase-item.active {
  background: var(--bg-surface);
  color: var(--text);
  font-weight: 600;
}
.phase-item.complete-phase { opacity: 0.45; }

.phase-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.phase-item.active .phase-dot { background: var(--phase-color, var(--accent)); box-shadow: 0 0 6px var(--phase-color, var(--accent)); }
.phase-item.done .phase-dot { background: var(--green); }

/* Sidebar action area */
.sidebar-actions { display: flex; flex-direction: column; gap: 6px; }
.write-actions { display: flex; flex-direction: column; gap: 6px; }

.auto-write-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--blue);
  padding: 4px 0;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  animation: pulse 1.2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}

/* Sidebar bottom */
.sidebar-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.export-row { display: flex; flex-direction: column; gap: 5px; }
.label-sm { font-size: 10px; font-weight: 700; letter-spacing: 0.1em; color: var(--text-dim); }
.export-btns { display: flex; flex-wrap: wrap; gap: 4px; }

/* Chat main */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

/* Message bubbles */
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 80%; }
.msg.msg-user { align-self: flex-end; align-items: flex-end; }
.msg.msg-agent { align-self: flex-start; align-items: flex-start; }
.msg.msg-system { align-self: center; }

.msg-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  padding: 0 4px;
}
.msg-user .msg-label { color: var(--text-muted); }
.msg-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 0 6px;
  border: 1px solid var(--text-dim);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: 1px;
}
.import-progress .btn { margin-left: 8px; }

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.65;
  font-size: 14px;
  word-break: break-word;
}

.msg-user .msg-bubble {
  background: var(--bg-surface);
  color: var(--text);
  border-bottom-right-radius: 3px;
}

.msg-agent .msg-bubble {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 3px;
}

.msg-system .msg-bubble {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  text-align: center;
}

/* Streaming cursor */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.7s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Markdown in messages */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  margin: 12px 0 6px;
  line-height: 1.3;
  color: var(--text);
}
.msg-bubble h1 { font-size: 18px; }
.msg-bubble h2 { font-size: 16px; }
.msg-bubble h3 { font-size: 14px; font-weight: 700; }
.msg-bubble p  { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg-bubble strong { font-weight: 700; color: var(--text); }
.msg-bubble em { font-style: italic; color: var(--text-muted); }

/* Input area */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.chat-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 14px;
  resize: none;
  min-height: 42px;
  max-height: 180px;
  overflow-y: auto;
  transition: border-color 0.15s;
}
.chat-input:focus { outline: none; border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-dim); }

/* ── Settings ────────────────────────────────────────────────────────────── */

#view-settings {
  background: var(--bg);
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
}

.settings-wrap {
  width: 100%;
  max-width: 640px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.settings-header {
  display: flex;
  align-items: center;
  gap: 16px;
}
.settings-header h2 { font-size: 20px; font-weight: 700; color: var(--text); }

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.settings-section h3 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.settings-hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

.settings-fields { display: flex; flex-direction: column; gap: 12px; }

.field-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 12px;
}
.field-row label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.field-input-wrap {
  display: flex;
  gap: 6px;
  align-items: center;
}
.settings-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 10px;
  transition: border-color 0.15s;
}
.settings-input:focus { outline: none; border-color: var(--accent); }
.settings-input::placeholder { color: var(--text-dim); font-family: inherit; }

.settings-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 7px 10px;
  cursor: pointer;
}
.settings-select:focus { outline: none; border-color: var(--accent); }

.phase-model-row {
  display: grid;
  grid-template-columns: 130px 120px 1fr;
  align-items: center;
  gap: 10px;
}

.phase-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-surface);
  color: var(--phase-color, var(--text-muted));
  border: 1px solid var(--phase-color, var(--border));
}

.settings-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-top: 8px;
}
.settings-status {
  font-size: 12px;
  color: var(--green);
  opacity: 0;
  transition: opacity 0.3s;
}
.settings-status.visible { opacity: 1; }
.settings-status.error { color: var(--red); }

/* API key rows: masked text inputs (not type=password, so password managers
   leave them alone) and a clear "saved" line per provider. */
.key-block { display: flex; flex-direction: column; gap: 6px; }
.key-input { -webkit-text-security: disc; text-security: disc; }
.key-input.revealed { -webkit-text-security: none; text-security: none; }
.key-saved { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.key-saved-text { font-size: 12px; color: var(--green); margin-right: 4px; }
.key-note { font-size: 12px; color: var(--text-dim); }
.key-note:empty { display: none; }
.key-note.ok { color: var(--green); }
.key-note.warn { color: var(--red); }

/* Account section (web only) */
.account-subform { display: flex; flex-direction: column; gap: 10px; padding: 14px 0; border-top: 1px solid var(--border); }
.account-subform h4 { font-size: 13px; font-weight: 600; color: var(--text); }
.account-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.acct-username-hint { position: absolute; left: -10000px; width: 1px; height: 1px; opacity: 0; }
.danger-zone h4 { color: var(--red); }
.btn-danger-lg { font-size: 13px; padding: 7px 14px; font-weight: 600; }
.modal-label { font-size: 13px; color: var(--text-muted); }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-surface); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-hover); }

/* ── Loading ────────────────────────────────────────────────────────────── */

.view-loading { align-items: center; justify-content: center; gap: 12px; color: var(--text-muted); }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--bg-surface); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Chat extras: error card, top bar, drawer ───────────────────────────── */

.msg.msg-error { align-self: stretch; max-width: 100%; }
.msg-error .msg-bubble {
  border: 1px solid var(--red);
  background: color-mix(in srgb, var(--red) 10%, var(--bg));
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
}
.msg-error .msg-error-text { flex: 1 1 260px; color: var(--text); }

.chat-topbar { display: none; }
/* Keep reading lines comfortable on wide screens */
@media (min-width: 1200px) { .messages { padding-inline: max(28px, calc((100% - 980px) / 2)); } }
.drawer-backdrop { display: none; }

/* ── Welcome ────────────────────────────────────────────────────────────── */

.modal-welcome { max-width: 600px; }
.modal-welcome p { color: var(--text-muted); }
.welcome-phases { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px 14px; list-style: none; }
.welcome-phases li { font-size: 13px; color: var(--text-muted); }
.welcome-phases strong { color: var(--phase-color, var(--text)); }
.welcome-steps { display: flex; flex-direction: column; gap: 12px; }
.welcome-step { display: flex; gap: 12px; align-items: flex-start; font-size: 14px; }
.welcome-step .step-num {
  flex: 0 0 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-surface); color: var(--text); font-weight: 700; font-size: 13px;
}
.welcome-step.done .step-num { background: var(--green); color: var(--on-accent); }
.welcome-step.done .step-num::before { content: "✓"; }
.welcome-step.done .step-num { font-size: 0; }
.welcome-step.done .step-num::before { font-size: 14px; }
.welcome-links { list-style: none; display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.welcome-uses { font-size: 12px; color: var(--text-dim); }

/* ── Light theme (follows the system setting) ───────────────────────────── */

@media (prefers-color-scheme: light) {
  :root {
    --bg:          #eff1f5;
    --bg-sidebar:  #e6e9ef;
    --bg-surface:  #ffffff;
    --bg-input:    #ffffff;
    --bg-hover:    #dce0e8;
    --text:        #3c3f58;
    --text-dim:    #5f6278;
    --text-muted:  #4c4f69;
    --border:      #c5c9d6;
    --accent:      #7c33e0;
    --accent-hover:#6a22cc;
    --blue:        #1a5cd8;
    --blue-hover:  #154fbd;
    --green:       #2e7d1f;
    --red:         #c40e34;
    --red-hover:   #a80b2c;
    --yellow:      #8a5a00;
    --orange:      #b5470a;
    --teal:        #0f6f68;
    --on-accent:   #ffffff;
    --focus:       #1a5cd8;
    --backdrop:    rgba(40,40,60,0.45);
    --shadow:      0 10px 40px rgba(40,40,60,0.18);
  }
  .logo, .app-name { color: var(--accent); }
  .project-card { box-shadow: 0 1px 2px rgba(40,40,60,0.06); }
  /* Phase colours are pastel; darken them where they're used as text */
  .phase-badge, .project-card-phase, .welcome-phases strong {
    color: color-mix(in srgb, var(--phase-color, var(--text-muted)) 45%, #000);
  }
  .msg-user .msg-bubble { background: #dfe3f0; }
  ::-webkit-scrollbar-thumb { background: #c5c9d6; }
}

/* ── Phones and tablets ─────────────────────────────────────────────────── */

/* Touch: tap targets of at least 44px, 16px inputs (no iOS zoom on focus) */
@media (pointer: coarse), (max-width: 760px) {
  .btn, .btn-sm, .btn-xs { min-height: 44px; }
  .btn-xs { padding: 3px 12px; }
  .btn-icon { width: 44px; }
  .settings-input, .settings-select, .chat-input { font-size: 16px; min-height: 44px; }
  .phase-item { min-height: 44px; font-size: 14px; }
  .project-card-delete { opacity: 0.75; min-width: 44px; min-height: 44px; font-size: 18px; }
  .export-btns .btn { flex: 1 1 auto; }
}

/* Tablet and down: the sidebar becomes a slide-in drawer under a top bar */
@media (max-width: 900px) {
  #view-chat { position: relative; }
  .chat-topbar {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--border); background: var(--bg-sidebar);
  }
  .topbar-title { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
  #topbar-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-phase { font-size: 12px; color: var(--phase-color, var(--text-muted)); }
  .sidebar {
    position: absolute; top: 0; bottom: 0; left: 0; z-index: 900;
    width: min(300px, 86vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  #view-chat.drawer-open .sidebar { transform: none; }
  #view-chat.drawer-open .drawer-backdrop { display: block; position: absolute; inset: 0; z-index: 800; background: var(--backdrop); }
  .messages { padding: 16px 14px; }
  .msg { max-width: 92%; }
  .input-area { padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}

/* Phones */
@media (max-width: 600px) {
  body { font-size: 15px; }
  .projects-wrap, .picker-wrap { padding: 20px 14px; gap: 20px; }
  #view-projects, #view-picker { align-items: flex-start; overflow-y: auto; }
  .projects-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .projects-header .logo { text-align: center; margin-bottom: 0; }
  .projects-header-btns { flex-wrap: wrap; }
  .projects-header-btns .btn { flex: 1 1 auto; }
  .projects-footer { justify-content: stretch; flex-wrap: wrap; }
  .projects-footer .btn { flex: 1 1 auto; }
  .project-card { padding: 12px 12px 12px 14px; gap: 8px; }
  .project-card-meta { flex-wrap: wrap; gap: 4px 10px; }
  .format-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .format-card { padding: 16px 10px; }
  .settings-wrap { padding: 18px 14px 32px; gap: 22px; }
  .field-row { grid-template-columns: 1fr; gap: 6px; }
  .phase-model-row { grid-template-columns: minmax(0, 110px) minmax(0, 1fr); gap: 6px 8px; }
  .phase-model-row .settings-input { grid-column: 1 / -1; }
  .phase-model-row .phase-badge { justify-self: start; }
  .key-saved { gap: 8px; }
  .settings-footer { flex-wrap: wrap; }
  .modal { padding: 20px 16px; gap: 14px; }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1 1 auto; }
  .msg { max-width: 100%; }
  .msg-user { max-width: 92%; }
  .msg-bubble { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
