/* ---- tokens: three themes ----
   "Our Theme" (brand, vivid Forest & Copper) is the base :root and the
   default for a first-time visitor — no data-theme attribute needed, so
   it paints correctly before script.js even runs, no flash possible.
   [data-theme="light"] / [data-theme="dark"] are deliberately neutral
   (no green/copper) so they read as plain alternates and "Our Theme"
   reads as the distinctive, vivid option by contrast. --accent2 is a
   secondary brand hue used for a couple of gradient flourishes; it's
   just a duplicate of --accent on the two neutral themes so those
   gradients quietly become solid colors there. */
:root {
  --ink: #16281D;
  --ink-soft: #4C5F54;
  --ink-faint: #85948C;
  --paper: #FFFFFF;
  --page: #F2F5F1;
  --rule: #DEE6E0;
  --rule-strong: #BDCBC2;
  --accent: #C2600D;
  --accent-hover: #A34F0A;
  --accent-soft: #F5E0C9;
  --accent-ink: #6E3D10;
  --accent2: #2F6B46;
  --danger: #B3261E;
  --danger-soft: #FBEAE9;
  --user-bubble: #E7EFE8;
  --font: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius: 10px;
}

:root[data-theme="light"] {
  --ink: #1A1D1F;
  --ink-soft: #5B6368;
  --ink-faint: #8D949A;
  --paper: #FFFFFF;
  --page: #F4F5F6;
  --rule: #E1E4E7;
  --rule-strong: #C4C9CE;
  --accent: #3B5BA9;
  --accent-hover: #314B8C;
  --accent-soft: #E3E9F7;
  --accent-ink: #203668;
  --accent2: #3B5BA9;
  --danger: #B3261E;
  --danger-soft: #FBEAE9;
  --user-bubble: #EEF1F4;
}

:root[data-theme="dark"] {
  --ink: #ECEDEE;
  --ink-soft: #AEB4B9;
  --ink-faint: #767D82;
  --paper: #1C1F21;
  --page: #121415;
  --rule: #2B2F32;
  --rule-strong: #3B4044;
  --accent: #5A7AD1;
  --accent-hover: #6E8FE0;
  --accent-soft: #223050;
  --accent-ink: #C3D2F5;
  --accent2: #5A7AD1;
  --danger: #E5675F;
  --danger-soft: #3A1C1A;
  --user-bubble: #23272A;
}
* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}

button, input, textarea {
  font-family: inherit;
}

.hidden { display: none !important; }

/* ---- app shell ---- */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-mark {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-rule {
  width: 22px;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.account {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.account-email {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.main {
  flex: 1;
  display: flex;
  justify-content: center;
  width: 100%;
}

.app-loading {
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem 0;
}

@keyframes loadingPulse {
  0%, 100% { opacity: 0.25; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

.app-loading-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: loadingPulse 1s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .app-loading-dot { animation: none; opacity: 0.7; }
}


/* ---- buttons ---- */
.btn {
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0.6rem 1.1rem;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

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

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--rule-strong);
  color: var(--ink-soft);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--user-bubble);
  color: var(--ink);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

/* ---- auth screen ---- */
.auth-screen {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 3.5rem 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  flex: 0 0 380px;
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 0.4rem;
  letter-spacing: -0.01em;
}

.auth-sub {
  font-size: 0.92rem;
  color: var(--ink-soft);
  line-height: 1.5;
  margin: 0 0 1.75rem;
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1.5rem;
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 0.6rem 0;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink-faint);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.auth-tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-soft);
}

.field-input {
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  font-size: 0.95rem;
  background: var(--paper);
  color: var(--ink);
}

.field-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-error {
  font-size: 0.85rem;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  margin: 0;
}

.auth-status {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 1rem 0 0;
  text-align: center;
}


.auth-layout {
  display: flex;
  align-items: center;
  gap: 3.5rem;
  width: 100%;
  max-width: 920px;
}

.auth-hero {
  flex: 1;
  min-width: 0;
}

.auth-hero-eyebrow {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin: 0 0 0.9rem;
}

.auth-hero-title {
  font-size: 1.85rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 0 0 1.85rem;
  color: var(--ink);
}

.auth-hero-points {
  list-style: none;
  margin: 0 0 1.6rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1.05rem;
}

.auth-hero-points li {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.auth-hero-icon {
  flex: none;
  font-size: 1.1rem;
  line-height: 1.5;
}

.auth-hero-points strong {
  color: var(--ink);
  font-weight: 600;
}

.auth-hero-note {
  font-size: 0.85rem;
  color: var(--ink-faint);
  margin: 0;
}

/* ---- chat empty-state starter prompts ---- */
.chat-starters {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.1rem;
}

.chat-starter {
  text-align: left;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease, background-color 0.12s ease;
}

.chat-starter:hover {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--accent-soft);
}

/* ---- mistake disclaimer ----
   Deliberately NOT styled like faint grey fine print — that's the pattern
   everyone (Claude, Gemini, GPT included) already uses, and it's exactly
   why people stop reading it. This uses the brand accent color (not the
   danger/red used for actual errors) so it reads as "pay attention" rather
   than "something broke" or "ignorable legal boilerplate". Intentionally
   NOT dismissible — it should cost zero clicks to see, every time. */
.disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin: 1.1rem 0 0;
  padding: 0.7rem 0.9rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--accent-ink);
}

.disclaimer strong {
  font-weight: 600;
}

.disclaimer-icon {
  flex: none;
  line-height: 1.4;
}

.disclaimer-chat {
  margin-top: 0.75rem;
}

/* ---- chat screen ---- */
.chat-screen {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.25rem 1.25rem;
  height: calc(100vh - 65px);
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.chat-empty {
  margin: auto 0.5rem;
  padding: 1.5rem;
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius);
}

.chat-empty-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.4rem;
}

.chat-empty-body {
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.55;
  margin: 0;
}

.bubble {
  max-width: 84%;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  line-height: 1.5;
  word-wrap: break-word;
}

/* Plain-text bubbles still use textContent, so line breaks in the raw
   string need to render as line breaks. The model bubble holds real HTML
   from renderMarkdown() instead, where <p>/<ul>/<br> already control
   spacing — pre-wrap on top of that would double it up. */
.bubble-user,
.bubble-error,
.bubble-pending {
  white-space: pre-wrap;
}

.bubble-user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--ink);
  border-bottom-right-radius: 3px;
}

.bubble-model {
  align-self: flex-start;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-bottom-left-radius: 3px;
}

.bubble-model p { margin: 0 0 0.6em; }
.bubble-model p:last-child { margin-bottom: 0; }
.bubble-model ul,
.bubble-model ol {
  margin: 0 0 0.6em;
  padding-left: 1.25em;
}
.bubble-model ul:last-child,
.bubble-model ol:last-child { margin-bottom: 0; }
.bubble-model li { margin: 0.15em 0; }
.bubble-model strong { font-weight: 600; }
.bubble-model code {
  background: var(--page);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.05em 0.35em;
  font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bubble-model .bubble-heading {
  margin: 0.8em 0 0.3em;
  font-weight: 600;
  color: var(--ink);
}
.bubble-model .bubble-heading:first-child { margin-top: 0; }

/* ---- reveal animation (model replies "type" in letter by letter) ----
   Each character is wrapped in its own span (see wrapCharsForReveal in
   script.js) with a staggered animation-delay, so they fade/slide in
   left-to-right across the already fully-laid-out bubble — no reflow as
   the reply appears, since the bubble's final height is there from the
   first frame. */
@keyframes charIn {
  from { opacity: 0; transform: translateY(0.3em); }
  to { opacity: 1; transform: translateY(0); }
}

.char-reveal {
  display: inline-block;
  opacity: 0;
  animation: charIn 0.22s ease-out forwards;
}

@keyframes caretBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.type-caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 1px;
  background: var(--ink-soft);
  vertical-align: text-bottom;
  animation: caretBlink 0.9s steps(1) infinite;
}

@media (prefers-reduced-motion: reduce) {
  .char-reveal { animation: none; opacity: 1; }
  .type-caret { animation: none; }
}


.bubble-error {
  align-self: flex-start;
  background: var(--danger-soft);
  color: var(--danger);
  border-bottom-left-radius: 3px;
}

.bubble-pending {
  align-self: flex-start;
  background: var(--paper);
  border: 1px solid var(--rule);
  color: var(--ink-faint);
  border-bottom-left-radius: 3px;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 0.75rem;
}

.composer-input {
  border: none;
  resize: none;
  font-size: 0.95rem;
  line-height: 1.5;
  max-height: 160px;
  padding: 0.2rem;
  color: var(--ink);
  background: transparent;
}

.composer-input:focus {
  outline: none;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}


/* ---- settings modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 12, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1rem;
  z-index: 50;
}

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-faint);
  padding: 0.2rem 0.4rem;
}

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

.settings-section {
  margin-bottom: 1.75rem;
}
.settings-section:last-child { margin-bottom: 0; }

.settings-heading {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  margin: 0 0 0.75rem;
}

.theme-options {
  display: flex;
  gap: 0.6rem;
}

.theme-option {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  padding: 0.7rem 0.4rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--page);
  color: var(--ink-soft);
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.theme-option.is-active {
  border-color: var(--accent);
  color: var(--ink);
  background: var(--accent-soft);
}

.theme-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.theme-swatch-brand { background: linear-gradient(135deg, #FFFFFF 38%, #C2600D 68%, #2F6B46 100%); }
.theme-swatch-light { background: linear-gradient(135deg, #FFFFFF 50%, #3B5BA9 50%); }
.theme-swatch-dark  { background: linear-gradient(135deg, #1C1F21 50%, #5A7AD1 50%); }

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}
.settings-form:last-child { margin-bottom: 0; }

.settings-status {
  min-height: 1.1em;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin: 0;
}
.settings-status.is-error { color: var(--danger); }
.settings-status.is-success { color: var(--accent); }

/* ---- responsive ---- */
@media (max-width: 840px) {
  .auth-layout {
    flex-direction: column;
    align-items: stretch;
    gap: 2.25rem;
  }
  .auth-hero { max-width: 100%; }
  .auth-card { flex: 0 1 auto; margin: 0 auto; }
}

@media (max-width: 480px) {
  .topbar { padding: 0.9rem 1rem; }
  .chat-screen { padding: 1rem 0.75rem; height: calc(100vh - 58px); }
  .bubble { max-width: 92%; }
  .modal-backdrop { padding: 1.5rem 0.75rem; align-items: center; }
  .modal { padding: 1.25rem; }
  .auth-screen { padding: 2.5rem 1.25rem; }
  .auth-hero-title { font-size: 1.5rem; }
}
