:root {
  --bg: #ffffff;
  --bg-elev: #f9f9f9;
  --fg: #0d0d0d;
  --fg-muted: #6e6e80;
  --border: #e5e5e5;
  --user-bubble: #f4f4f4;
  --accent: #0d0d0d;
  --accent-fg: #ffffff;
  --chip-bg: #ffffff;
  --chip-hover: #f4f4f4;
  --shadow: 0 0 0 1px rgba(0,0,0,.05), 0 2px 12px rgba(0,0,0,.06);
  --radius: 26px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --emoji-font: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --bg-elev: #2f2f2f;
    --fg: #ececec;
    --fg-muted: #b4b4b4;
    --border: #3a3a3a;
    --user-bubble: #2f2f2f;
    --accent: #ececec;
    --accent-fg: #0d0d0d;
    --chip-bg: #2a2a2a;
    --chip-hover: #383838;
    --shadow: 0 0 0 1px rgba(255,255,255,.06), 0 2px 12px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 17px; }
.brand-mark { font-family: var(--emoji-font); font-size: 20px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; border: 0;
  background: transparent; color: var(--fg); cursor: pointer;
}
.icon-btn:hover { background: var(--user-bubble); }

/* Chat area */
.chat {
  flex: 1;
  width: 100%;
  max-width: 48rem;
  margin: 0 auto;
  padding: 8px 16px 24px;
  display: flex;
  flex-direction: column;
}
.empty {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 6px; padding: 40px 0;
}
.empty[hidden] { display: none; }
.empty-mark { font-family: var(--emoji-font); font-size: 56px; margin-bottom: 8px; }
.empty h1 { font-size: 28px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.empty p { margin: 0 0 18px; color: var(--fg-muted); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 34rem; }
.chip {
  border: 1px solid var(--border); background: var(--chip-bg); color: var(--fg);
  border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 14px; cursor: pointer;
  transition: background .15s;
}
.chip:hover { background: var(--chip-hover); }

.messages { display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; animation: rise .22s ease-out; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  max-width: 78%;
  background: var(--user-bubble);
  border-radius: 20px;
  padding: 10px 16px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.assistant { align-items: flex-start; gap: 12px; }
.avatar {
  flex: 0 0 auto;
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  font-family: var(--emoji-font); font-size: 18px;
  margin-top: 2px;
}
.msg.assistant .bubble {
  font-family: var(--emoji-font);
  font-size: 30px;
  line-height: 1.35;
  padding: 2px 0;
  white-space: pre-wrap;
  word-break: break-word;
  letter-spacing: 0.04em;
}
.msg.assistant .bubble { font-family: var(--emoji-font), var(--font); }
.msg.assistant .bubble.error {
  font-family: var(--font); font-size: 15px; color: var(--fg-muted);
}

/* Typing indicator */
.typing { display: inline-flex; gap: 5px; padding: 12px 2px; }
.typing i {
  width: 8px; height: 8px; border-radius: 50%; background: var(--fg-muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }

/* Composer */
.composer-wrap {
  position: sticky;
  bottom: 0;
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.composer {
  max-width: 48rem;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 10px;
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.think-toggle {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 5px;
  height: 32px; padding: 0 10px; margin-bottom: 4px;
  border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--fg-muted);
  font: inherit; font-size: 13px; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.think-toggle:hover { background: var(--user-bubble); color: var(--fg); }
.think-toggle[aria-pressed="true"] {
  background: color-mix(in srgb, #3b82f6 14%, transparent);
  border-color: color-mix(in srgb, #3b82f6 50%, transparent);
  color: #2563eb;
}
@media (prefers-color-scheme: dark) { .think-toggle[aria-pressed="true"] { color: #93c5fd; } }
@media (max-width: 480px) { .think-toggle span { display: none; } .think-toggle { padding: 0 8px; } }
.msg.assistant .bubble.thought { position: relative; }
.msg.assistant .bubble.thought::after {
  content: 'thought'; position: absolute; left: 0; bottom: -14px;
  font-family: var(--font); font-size: 11px; letter-spacing: 0; color: var(--fg-muted);
}

.composer textarea {
  flex: 1;
  display: block;
  margin: 0;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  line-height: 1.5;
  padding: 8px 0;
  height: calc(1.5em + 16px); /* exactly one row + padding; JS grows it with content */
  max-height: 200px;
  overflow-y: hidden;
  -webkit-appearance: none;
  appearance: none;
}
.composer textarea::placeholder { color: var(--fg-muted); }
.send-btn {
  flex: 0 0 auto;
  width: 36px; height: 36px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-fg);
  cursor: pointer; transition: opacity .15s, transform .1s;
}
.send-btn:disabled { opacity: .25; cursor: default; }
.send-btn:not(:disabled):active { transform: scale(.94); }
.hint {
  max-width: 48rem; margin: 8px auto 0; text-align: center;
  font-size: 12px; color: var(--fg-muted);
}
.hint-sep { margin: 0 2px; }
.hint-link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.hint-link:hover { color: var(--fg); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .msg, .typing i { animation: none; }
}
@media (max-width: 480px) {
  .msg.assistant .bubble { font-size: 26px; }
  .empty h1 { font-size: 24px; }
}

/* Share button, toast */
.topbar-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn[hidden] { display: none; } /* author display beats the UA [hidden] rule */
.toast {
  position: fixed; left: 50%; top: calc(56px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  z-index: 20; padding: 8px 14px; border-radius: 999px; font-size: 14px;
  background: var(--accent); color: var(--accent-fg); box-shadow: var(--shadow);
  animation: rise .18s ease-out;
}
.toast[hidden] { display: none; }

/* Shared-chat page */
.share-page .brand { color: inherit; text-decoration: none; }
.share-note { margin: 4px 0 18px; text-align: center; font-size: 13px; color: var(--fg-muted); }
.share-footer { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.continue-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 44px; padding: 0 22px; border-radius: 999px;
  background: var(--accent); color: var(--accent-fg); text-decoration: none; font-weight: 600;
}
.continue-btn:active { transform: scale(.98); }
/* Rows are in the HTML, not appended later: no entrance animation, so nothing depends on it running. */
.share-page .msg { animation: none; }
