/* Themes. Each [data-theme] block sets the colors for the page (on <html>) and
   for its own preview button on the Theme screen. */
:root,
[data-theme="light"],
[data-theme="system"] {
  --bg: #f6f5f2;
  --fg: #1d1d1b;
  --muted: #6b6a66;
  --panel: #ffffff;
  --border: #dcdad4;
  --user: #e8e5dd;
  --accent: #c2603e;
  --on-accent: #ffffff;
  --error: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]),
  [data-theme="system"] {
    --bg: #1b1b1a;
    --fg: #ecebe7;
    --muted: #a09e98;
    --panel: #262624;
    --border: #3a3936;
    --user: #33322f;
    --accent: #d97757;
    --on-accent: #ffffff;
    --error: #f2b8b5;
    color-scheme: dark;
  }
}
[data-theme="dark"] {
  --bg: #1b1b1a;
  --fg: #ecebe7;
  --muted: #a09e98;
  --panel: #262624;
  --border: #3a3936;
  --user: #33322f;
  --accent: #d97757;
  --on-accent: #ffffff;
  --error: #f2b8b5;
  color-scheme: dark;
}
[data-theme="midnight"] {
  --bg: #0d1626;
  --fg: #dbe6f5;
  --muted: #8ea3c0;
  --panel: #15213a;
  --border: #26365a;
  --user: #1d2e4f;
  --accent: #5fa8f5;
  --on-accent: #0d1626;
  --error: #ffb4ab;
  color-scheme: dark;
}
[data-theme="forest"] {
  --bg: #17201a;
  --fg: #e0eadf;
  --muted: #9cb09d;
  --panel: #1f2b22;
  --border: #33473a;
  --user: #2a3a2e;
  --accent: #7cc48f;
  --on-accent: #10180f;
  --error: #ffb4ab;
  color-scheme: dark;
}
[data-theme="rose"] {
  --bg: #fbf3f4;
  --fg: #2a1e21;
  --muted: #7a6267;
  --panel: #ffffff;
  --border: #ead6da;
  --user: #f5e1e5;
  --accent: #c2456a;
  --on-accent: #ffffff;
  --error: #a3241f;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h2 { margin: 0; font-size: 1.25rem; font-weight: 600; align-self: center; }

button, input, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 14px;
  min-height: 44px;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; justify-self: center; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login form { width: min(340px, 100%); display: grid; gap: 12px; }
.login h1 { margin: 0 0 8px; text-align: center; font-weight: 600; }
.login input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}
.captcha { display: flex; gap: 8px; align-items: center; }
.captcha img {
  flex: 1;
  min-width: 0;
  height: 64px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f4f1ea;
}
.captcha button { width: 44px; padding: 0; font-size: 20px; }
.error { color: var(--error); min-height: 1.5em; margin: 0; }

/* Chat and Theme screens share the column layout */
.chat,
.theme-page {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
.bar { display: flex; justify-content: space-between; gap: 8px; padding: 12px 0; }
.bar-right { display: flex; gap: 8px; }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 8px 0 16px; }
.msg { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--user);
  padding: 10px 14px;
  border-radius: 16px;
}
.msg.assistant { align-self: stretch; }
.msg.pending { color: var(--muted); }
.msg.error { color: var(--error); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
}
.composer textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  max-height: 40vh;
  padding: 8px;
  field-sizing: content;
}
.composer textarea:focus-visible { outline: none; }
.composer button {
  width: 44px;
  padding: 0;
  border-radius: 12px;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-size: 20px;
}

/* Theme screen: each option shows its own colors */
.theme-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  padding: 8px 0 24px;
  overflow-y: auto;
}
.theme-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 14px;
  min-height: 96px;
  background: var(--bg);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: 14px;
  text-align: left;
}
.theme-option[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.swatch { display: flex; gap: 6px; }
.dot { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--border); }
.dot.bg { background: var(--panel); }
.dot.accent { background: var(--accent); }
.dot.user { background: var(--user); }
