:root {
  /* Dark palette — default. */
  --bg: #0f1115;
  --fg: #e8e8e8;
  --muted: #8a8f98;
  --accent: #6ee7b7;
  --accent-2: #38bdf8;
  --bubble-bot: #1a1d24;
  --bubble-user: #2a4365;
  --card: #161922;
  --border: #2a2e36;
  --code-bg: #0b0d12;
  --button-fg: #0f1115;
  --bg-tint-a: rgba(110, 231, 183, 0.07);
  --bg-tint-b: rgba(56, 189, 248, 0.06);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Auto-light when the user hasn't explicitly picked a theme. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #fafbfc;
    --fg: #1a1d24;
    --muted: #6b7280;
    --accent: #10b981;
    --accent-2: #0ea5e9;
    --bubble-bot: #f1f3f5;
    --bubble-user: #dbeafe;
    --card: #ffffff;
    --border: #e5e7eb;
    --code-bg: #f6f8fa;
    --button-fg: #ffffff;
    --bg-tint-a: rgba(16, 185, 129, 0.06);
    --bg-tint-b: rgba(14, 165, 233, 0.05);
  }
}

/* Explicit override via toggle. */
:root[data-theme="light"] {
  --bg: #fafbfc;
  --fg: #1a1d24;
  --muted: #6b7280;
  --accent: #10b981;
  --accent-2: #0ea5e9;
  --bubble-bot: #f1f3f5;
  --bubble-user: #dbeafe;
  --card: #ffffff;
  --border: #e5e7eb;
  --code-bg: #f6f8fa;
  --button-fg: #ffffff;
  --bg-tint-a: rgba(16, 185, 129, 0.06);
  --bg-tint-b: rgba(14, 165, 233, 0.05);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 0% 0%, var(--bg-tint-a), transparent 40%),
    radial-gradient(circle at 100% 0%, var(--bg-tint-b), transparent 40%),
    var(--bg);
  color: var(--fg);
  line-height: 1.55;
}

.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 3rem 1.25rem 4rem;
}

.muted { color: var(--muted); margin: 0.25rem 0; }

/* --- Hero --- */
.hero {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-bottom: 2.5rem;
}
.avatar {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0f1115;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(110, 231, 183, 0.15);
}
.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar-initials { position: relative; z-index: 0; }
.hero-text h1 { margin: 0; font-size: 1.9rem; letter-spacing: -0.01em; }
.hero-text .title { margin: 0.2rem 0 0; color: var(--fg); font-weight: 500; }
.hero-text .location { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.95rem; }

/* --- Theme toggle --- */
.theme-toggle {
  margin-left: auto;
  align-self: center;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--bubble-bot);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Sections --- */
section { margin: 2rem 0; }
section > h2 {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
}
section p { margin: 0.5rem 0; }

.about p { color: var(--fg); }

/* --- Card grid --- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  align-items: stretch;
}
@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.35rem;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.card:hover { border-color: rgba(110, 231, 183, 0.35); }
.card h3 { margin: 0 0 0.4rem; font-size: 1rem; color: var(--fg); }
.card-line { margin: 0; }
.card .muted { font-size: 0.9rem; }
.card p { font-size: 0.95rem; }

.bare {
  list-style: none;
  padding: 0;
  margin: 0.25rem 0 0;
  font-size: 0.95rem;
}
.bare li { padding: 0.45rem 0; border-top: 1px dashed var(--border); }
.bare li:first-child { border-top: none; padding-top: 0.25rem; }

/* --- Project links --- */
.project-list li { padding: 0; }
.project-link {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.55rem 0.15rem;
  color: var(--fg);
  text-decoration: none;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease, padding 0.15s ease;
}
a.project-link:hover {
  color: var(--accent);
  background: rgba(110, 231, 183, 0.05);
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}
.project-link .muted { font-size: 0.85rem; flex: 1; }
.project-link .arrow {
  color: var(--muted);
  transition: transform 0.15s ease, color 0.15s ease;
}
a.project-link:hover .arrow { color: var(--accent); transform: translateX(2px); }
.project-link.static { cursor: default; }

/* --- Chips --- */
.chips {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.chips li {
  background: var(--bubble-bot);
  border: 1px solid var(--border);
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--fg);
}

/* --- Chat --- */
.chat-section {
  margin: 2rem 0 2.5rem;
  padding: 1.4rem 1.5rem 1.5rem;
  background: linear-gradient(180deg, rgba(110, 231, 183, 0.05), rgba(56, 189, 248, 0.03));
  border: 1px solid var(--border);
  border-radius: 14px;
}
.chat-section > h2 { margin-top: 0; }
.chat-section .muted { margin: 0 0 1rem; }

.chat {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem 0 1rem;
}

.message {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  max-width: 80%;
  line-height: 1.4;
}
.message.bot { background: var(--bubble-bot); align-self: flex-start; }
.message.user { background: var(--bubble-user); align-self: flex-end; white-space: pre-wrap; }
.message.bot.streaming::after {
  content: "▌";
  display: inline-block;
  margin-left: 2px;
  color: var(--accent);
  animation: caret-blink 0.9s steps(2) infinite;
}
@keyframes caret-blink {
  50% { opacity: 0; }
}

/* --- Markdown rendering inside bot bubbles --- */
.message.bot.markdown {
  max-width: 92%;
  overflow-x: auto;
}
.message.bot.markdown > *:first-child { margin-top: 0; }
.message.bot.markdown > *:last-child { margin-bottom: 0; }
.message.bot.markdown p { margin: 0.55rem 0; }
.message.bot.markdown ul,
.message.bot.markdown ol { margin: 0.55rem 0; padding-left: 1.4rem; }
.message.bot.markdown li { margin: 0.18rem 0; }
.message.bot.markdown li > p { margin: 0.2rem 0; }
.message.bot.markdown h1,
.message.bot.markdown h2,
.message.bot.markdown h3,
.message.bot.markdown h4 {
  margin: 0.85rem 0 0.35rem;
  line-height: 1.25;
}
.message.bot.markdown h1 { font-size: 1.15rem; }
.message.bot.markdown h2 { font-size: 1.05rem; }
.message.bot.markdown h3 { font-size: 1rem; }
.message.bot.markdown strong { color: var(--fg); font-weight: 600; }
.message.bot.markdown a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.message.bot.markdown a:hover { text-decoration-thickness: 2px; }
.message.bot.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.85rem 0;
}
.message.bot.markdown blockquote {
  margin: 0.55rem 0;
  padding: 0.1rem 0.85rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-style: italic;
}

/* Inline + block code */
.message.bot.markdown code {
  background: rgba(255, 255, 255, 0.07);
  padding: 0.08rem 0.38rem;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
}
.message.bot.markdown pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 0.95rem;
  margin: 0.65rem 0;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}
.message.bot.markdown pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: var(--fg);
}

/* Tables */
.message.bot.markdown table {
  border-collapse: collapse;
  margin: 0.65rem 0;
  font-size: 0.88rem;
  width: max-content;
  max-width: 100%;
}
.message.bot.markdown th,
.message.bot.markdown td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.7rem;
  text-align: left;
  vertical-align: top;
}
.message.bot.markdown th {
  background: rgba(110, 231, 183, 0.08);
  color: var(--fg);
  font-weight: 600;
}
.message.bot.markdown tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.015);
}

.chat-form { display: flex; gap: 0.5rem; }
.chat-form input {
  flex: 1;
  padding: 0.75rem 1rem;
  background: var(--bubble-bot);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font: inherit;
}
.chat-form input::placeholder { color: var(--muted); }
.chat-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.chat-form button {
  padding: 0.75rem 1.25rem;
  background: var(--accent);
  color: var(--button-fg);
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.chat-form button:disabled,
.chat-form input:disabled { opacity: 0.5; cursor: not-allowed; }

.status {
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
  margin-top: 0.75rem;
}

/* --- Small screens --- */
@media (max-width: 520px) {
  .hero { gap: 1rem; }
  .avatar { width: 64px; height: 64px; font-size: 1.3rem; }
  .hero-text h1 { font-size: 1.5rem; }
}
