:root {
  --bg: #14150f;
  --surface: #1b1c14;
  --surface-2: #22241a;
  --border: #2c2e22;
  --border-hi: #40432f;
  --text: #e9e7db;
  --muted: #9a9c8a;
  --accent: #a8b56a;
  --accent-ink: #17190e;
  --accent-soft: rgba(168, 181, 106, 0.12);
  --live: #8fbf6f;
  --down: #e07a6a;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
  --radius: 8px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f5ee;
  --surface: #fcfbf6;
  --surface-2: #edecdf;
  --border: #dcd9c8;
  --border-hi: #c2bfa8;
  --text: #26281d;
  --muted: #6b6e5c;
  --accent: #5f6f2e;
  --accent-ink: #f4f4e8;
  --accent-soft: rgba(95, 111, 46, 0.1);
  --live: #3d8b4f;
  --down: #c2503f;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body,
.topbar,
.chat-wrap,
.chat,
.msg,
.think,
.contact-main,
.contact-list a,
.ask-form input,
.theme-btn,
.card {
  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.brand { color: var(--text); font-weight: 600; letter-spacing: -0.01em; }
.topbar-right { margin-left: auto; }
.theme-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}
.theme-btn:hover { color: var(--accent); border-color: var(--accent); }
.theme-btn svg { width: 14px; height: 14px; }
:root[data-theme="dark"] .icon-moon { display: none; }
:root[data-theme="light"] .icon-sun { display: none; }

/* page */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px calc(24px + env(safe-area-inset-bottom));
}
section { margin-top: 56px; }
h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 16px;
}

/* hero */
.hero { margin-top: 72px; }
.hero h1 {
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0;
}
.hero h1 .name { color: var(--accent); }
.ask-status { margin: 10px 0 0; }

/* llm status — sits above the ask box */
.sb-llm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.sb-llm-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}
.sb-llm-dot.live { background: var(--live); }
.sb-llm-dot.down { background: var(--down); }

/* chat window — its own scrollable panel */
.chat-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.chat-wrap:has(.chat:empty) { display: none; }
.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  max-height: 420px;
  padding: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hi) transparent;
}

/* messages */
.msg {
  width: fit-content;
  max-width: 88%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  line-height: 1.55;
}
.msg p { margin: 0; }
.msg p + p { margin-top: 8px; }
.msg-bot {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.msg-user {
  background: var(--accent-soft);
  border: 1px solid var(--border-hi);
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

/* thinking block — collapsible reasoning, streams live */
.think {
  margin: 0 0 10px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.think summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.think summary::-webkit-details-marker { display: none; }
.think summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid var(--muted);
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  transition: transform 0.15s ease;
}
.think[open] > summary::before { transform: rotate(90deg); }
.think-body {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.think-dots { display: inline-flex; gap: 3px; }
.think-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1s infinite;
}
.think-dots i:nth-child(2) { animation-delay: 0.15s; }
.think-dots i:nth-child(3) { animation-delay: 0.3s; }
.think:not(.waiting) .think-dots { display: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ask form */
.ask-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.ask-form input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}
.ask-form input::placeholder { color: var(--muted); }
.ask-form input:disabled { opacity: 0.55; }
.ask-form button {
  flex: none;
  width: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border-hi);
  background: var(--surface-2);
  color: var(--accent);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.ask-form button:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ask-form button:active { transform: translateY(1px); }

/* cards */
.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card:hover { border-color: var(--border-hi); }
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.card h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.tag {
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}
.more { margin-top: 16px; font-size: 0.9rem; }
.more a { color: var(--accent); text-decoration: none; }
.more a:hover { text-decoration: underline; }

/* contact */
.contact-main {
  display: inline-block;
  color: var(--text);
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 500;
}
.contact-main:hover { color: var(--accent); text-decoration: underline; }
.contact-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  gap: 16px;
}
.contact-list a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}
.contact-list a:hover { color: var(--text); text-decoration: underline; }

/* footer */
footer {
  max-width: 640px;
  margin: 56px auto 0;
  padding: 0 20px calc(24px + env(safe-area-inset-bottom));
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

/* desktop: roomier type */
@media (min-width: 720px) {
  .hero { margin-top: 96px; }
  .hero h1 { font-size: 3rem; }
  section { margin-top: 64px; }
}

@media (prefers-reduced-motion: reduce) {
  body,
  .topbar,
  .chat-wrap,
  .chat,
  .msg,
  .think,
  .contact-main,
  .contact-list a,
  .ask-form input,
  .theme-btn,
  .card {
    transition: none;
  }
  .think-dots i { animation: none; }
}