/* ============================================================
   Leon Chen — personal site
   Tokens + font borrowed from stocktaper.com for visual continuity:
     - IBM Plex Mono everywhere
     - Cream background (#fbf7eb), ink (#141414)
     - Medium gray borders (#9e9e9e / #bebebe)
     - Success #2f7d31 / fail #c6392c
   ============================================================ */

:root {
  /* ---- stocktaper palette ---- */
  --bg: #fbf7eb;
  --bg-soft: #f6f1df;
  --bg-hover: #ebe7dc;
  --card-bg: #ffffff;

  --ink: #141414;
  --ink-soft: #404040;
  --ink-mute: #525252;
  --ink-faint: #737373;

  --border: #bebebe;
  --border-strong: #9e9e9e;

  --accent-ink: #2563eb;
  --accent-hover: #1d4ed8;
  --up: #2f7d31;
  --down: #c6392c;

  /* ---- type ---- */
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas,
    monospace;

  /* ---- scale ---- */
  --radius: 10px;
  --radius-sm: 6px;

  --container: 1120px;
  --gutter: clamp(16px, 4vw, 32px);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.55;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Scrollbars — themed to blend with the cream palette ---------- */
/* Firefox */
html { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.chat-log { scrollbar-color: var(--border-strong) var(--bg-soft); }

/* WebKit / Chromium */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
  border: 2px solid var(--bg);   /* fakes a smaller thumb on the cream page */
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
::-webkit-scrollbar-corner { background: transparent; }

/* Inside the chat log the track background is --bg-soft, so the thumb's
   "padding" border needs to match that to keep the optical illusion. */
.chat-log::-webkit-scrollbar-track { background: var(--bg-soft); }
.chat-log::-webkit-scrollbar-thumb { border-color: var(--bg-soft); }

a {
  color: var(--accent-ink);
  text-decoration: underline;
  text-decoration-color: color-mix(in oklab, var(--accent-ink) 40%, transparent);
  text-underline-offset: 3px;
}
a:hover { color: var(--accent-hover); text-decoration-color: currentColor; }

.container {
  max-width: var(--container);
  margin: 0 auto;
  padding-inline: var(--gutter);
}

/* ---------- Header (nav only) ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 56px;
}
.site-nav {
  display: flex;
  gap: clamp(14px, 2.4vw, 26px);
}
.site-nav a {
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  letter-spacing: 0.02em;
}
.site-nav a:hover {
  color: var(--accent-ink);
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* ---------- Hero ---------- */
.hero {
  padding: clamp(56px, 9vw, 112px) 0 clamp(48px, 7vw, 80px);
}
.hero-top {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: clamp(28px, 4vw, 56px);
  align-items: center;
}
@media (max-width: 680px) {
  .hero-top {
    grid-template-columns: 1fr;
    justify-items: start;
    gap: 24px;
  }
}
.hero-photo {
  margin: 0;
  width: 100%;
  max-width: 240px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
}
.hero-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 40%;
}
.hero-title {
  font-size: clamp(40px, 6.5vw, 64px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-weight: 700;
  margin: 0 0 8px;
}
.hero-location {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
  text-transform: uppercase;
  margin: 0 0 14px;
  font-weight: 500;
}
.hero-tagline {
  max-width: 620px;
  font-size: clamp(15.5px, 1.4vw, 17px);
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.6;
}

/* ---------- Timeline (inside Projects section-head, faded) ----------
   Vertical timeline tucked under the "Projects" title in the left column.
   Opacity is dialed down so the project cards stay the focal point; the
   timeline reads as quiet context alongside the section label. */

.section-head .timeline-rail {
  margin-top: 24px;
}
.timeline-rail {
  position: relative;
  margin: 0;
  padding: 14px 0 6px 28px;
  opacity: 0.45;
  transition: opacity .2s ease;
}
.timeline-rail:hover,
.timeline-rail:focus-within,
.timeline-rail.is-filtering { opacity: 0.95; }

.tl-arrow {
  position: absolute;
  top: 0;
  left: 12px;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 9px solid var(--border-strong);
}
.tl-axis {
  position: absolute;
  top: 14px;
  bottom: 10px;
  left: 12px;
  width: 1px;
  background: var(--border-strong);
  transform: translateX(-50%);
}
.tl-stops {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.tl-stop {
  position: relative;
  padding-left: 18px;
}
.tl-icon {
  position: absolute;
  top: 2px;
  left: -9px;
  width: 14px;
  height: 14px;
  display: block;
  color: var(--ink-mute);
  background: var(--bg);   /* breaks the axis line behind the icon */
  border-radius: 3px;
  padding: 1px;
  box-sizing: border-box;
  z-index: 1;
}
.tl-icon-edu { color: var(--ink-soft); }
.tl-icon-vibe { color: var(--ink); }
.tl-info { font-size: 12.5px; line-height: 1.35; }
.tl-info strong {
  display: block;
  font-weight: 600;
  color: var(--ink);
  font-size: 13px;
}
.tl-info span {
  display: block;
  color: var(--ink-mute);
  font-size: 11.5px;
}
.tl-info em {
  display: block;
  font-style: normal;
  font-size: 11px;
  color: var(--ink-mute);
  margin-top: 2px;
  letter-spacing: 0.02em;
}
.tl-info .tl-loc {
  display: block;
  font-style: normal;
  font-size: 10.5px;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

/* Stops that have at least one tied project become interactive on hover/focus.
   The JS layer adds .tl-stop-has-projects at startup. */
.tl-stop-has-projects { cursor: pointer; }
.tl-stop-has-projects:focus { outline: none; }
.tl-stop-has-projects:focus-visible .tl-info strong { text-decoration: underline; }

/* When any stop is being hovered/focused, other stops fade and the active
   stop pops — the timeline rail's own :hover opacity bump already kicks in. */
.timeline-rail.is-filtering .tl-stop:not(.is-active):not(.is-locked) { opacity: 0.45; }
.timeline-rail.is-filtering .tl-stop.is-active .tl-icon { color: var(--ink); }
.timeline-rail.is-filtering .tl-stop.is-active .tl-info strong { color: var(--ink); }
.tl-stop { transition: opacity .15s ease; }

/* Locked stop keeps a persistent underline + full-opacity icon so it stays
   legible even while the user is hovering a different stop to peek. */
.tl-stop.is-locked { opacity: 1; }
.tl-stop.is-locked .tl-icon { color: var(--ink); }
.tl-stop.is-locked .tl-info strong {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
}

/* Project cards hide when they don't match the active stop's experience. */
.project-card { transition: border-color .15s, box-shadow .15s; }
.project-grid.is-filtering .project-card.is-dim { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid var(--ink);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
  text-decoration: none;
  letter-spacing: 0.02em;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { background: #000; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Section scaffolding ---------- */
.section { padding: clamp(48px, 7vw, 80px) 0; }
.section-divider {
  border: none;
  border-top: 1px solid var(--border-strong);
  margin: 0;
}
.section-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: clamp(24px, 4vw, 56px);
}
@media (max-width: 820px) {
  .section-grid { grid-template-columns: 1fr; }
}
.section-kicker {
  font-size: 11.5px;
  color: var(--ink-mute);
  letter-spacing: 0.12em;
  margin: 0 0 10px;
  text-transform: uppercase;
  font-weight: 500;
}
.section-title {
  font-size: clamp(26px, 3vw, 32px);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}
.lede {
  font-size: 15.5px;
  color: var(--ink-soft);
  margin-top: 0;
  line-height: 1.65;
}

/* ---------- Tag list (project cards) ---------- */
.tag-list {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-list li {
  font-size: 11.5px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--ink-soft);
  background: var(--bg-soft);
  letter-spacing: 0.02em;
}
.tag-list.small li { font-size: 11px; padding: 1px 7px; }

/* ---------- Projects ---------- */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
  align-items: start;  /* cards in a row size to their own content, so an expanded card doesn't force its neighbors to match */
}
.project-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  transition: border-color .15s, box-shadow .15s;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.project-card:hover {
  border-color: var(--ink);
}

/* Folded by default: show only tag + title + tech tags.
   Description and metrics appear on hover/focus. */
.project-card > p,
.project-card > .project-metrics { display: none; }
.project-card:hover > p,
.project-card:focus-within > p { display: block; }
.project-card:hover > .project-metrics,
.project-card:focus-within > .project-metrics { display: flex; }
.project-head { display: flex; flex-direction: column; gap: 8px; }
.project-tag {
  align-self: flex-start;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--bg-hover);
  padding: 3px 8px;
  border-radius: 3px;
  font-weight: 500;
}
.project-card h3 { margin: 0; font-size: 16px; font-weight: 600; }
.project-card p { margin: 0; color: var(--ink-soft); font-size: 13.5px; line-height: 1.55; }
.project-metrics {
  display: flex;
  gap: 18px;
  margin: 4px 0 0;
  padding: 10px 0;
  border-top: 1px dashed var(--border);
  border-bottom: 1px dashed var(--border);
}
.project-metrics div { display: flex; flex-direction: column; gap: 2px; }
.project-metrics dt {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 500;
}
.project-metrics dd {
  margin: 0;
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
}
.project-metrics dd.up { color: var(--up); }
.project-metrics dd.down { color: var(--down); }

/* ---------- Floating chatbot (launcher + panel) ---------- */
.chat-launcher {
  position: fixed;
  right: clamp(16px, 3vw, 24px);
  bottom: clamp(16px, 3vw, 24px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  border: 1px solid var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-family: inherit;
  z-index: 50;
  box-shadow: 0 6px 18px rgba(20, 20, 20, 0.18), 0 2px 4px rgba(20, 20, 20, 0.12);
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.chat-launcher:hover {
  background: #000;
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(20, 20, 20, 0.22), 0 3px 6px rgba(20, 20, 20, 0.14);
}
.chat-launcher:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 3px;
}
.chat-launcher-avatar {
  font-size: 26px;
  line-height: 1;
  user-select: none;
}
.chat-launcher-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid var(--ink);
  opacity: 0;
  pointer-events: none;
  animation: chat-pulse 2.6s ease-out infinite;
}
@keyframes chat-pulse {
  0%   { transform: scale(0.85); opacity: 0.55; }
  70%  { transform: scale(1.15); opacity: 0; }
  100% { transform: scale(1.15); opacity: 0; }
}
.chat-launcher.is-open .chat-launcher-pulse { display: none; }

/* Nudge pill that points at the launcher until the user opens the panel. */
.chat-nudge {
  position: fixed;
  right: calc(clamp(16px, 3vw, 24px) + 56px + 14px);
  bottom: calc(clamp(16px, 3vw, 24px) + 14px);
  z-index: 49;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: var(--ink);
  color: var(--bg);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(20, 20, 20, 0.18);
  pointer-events: none;
  animation: chat-nudge-bob 2.4s ease-in-out infinite;
}
.chat-nudge[hidden] { display: none; }
.chat-nudge::after {
  content: "";
  position: absolute;
  right: -4px;
  top: 50%;
  width: 10px;
  height: 10px;
  background: var(--ink);
  transform: translateY(-50%) rotate(45deg);
  border-radius: 2px;
}
.chat-nudge-arrow { font-size: 14px; line-height: 1; }
@keyframes chat-nudge-bob {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(-4px); }
}
@media (max-width: 480px) {
  .chat-nudge { display: none; }
}

.chat-panel {
  position: fixed;
  right: clamp(16px, 3vw, 24px);
  bottom: calc(clamp(16px, 3vw, 24px) + 56px + 12px);
  width: min(494px, calc(100vw - 32px));
  max-height: min(640px, calc(100vh - 120px));
  z-index: 49;
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(20, 20, 20, 0.18), 0 4px 10px rgba(20, 20, 20, 0.10);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: chat-pop .16s ease-out;
}
.chat-panel[hidden] { display: none; }
@keyframes chat-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}
.chat-panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.chat-panel-avatar {
  flex: 0 0 32px;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-size: 17px;
  line-height: 1;
  user-select: none;
}
.chat-panel-titles {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  flex: 1 1 auto;
  min-width: 0;
}
.chat-panel-titles strong { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.chat-panel-titles span { font-size: 11.5px; color: var(--ink-mute); }
.chat-close {
  flex: 0 0 28px;
  width: 28px; height: 28px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-mute);
  font-family: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.chat-close:hover { background: var(--bg-hover); color: var(--ink); border-color: var(--border); }

/* ---------- Chat ---------- */
.chat {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  overflow: hidden;
  min-height: 0;
}
.chat-log {
  padding: 18px;
  flex: 1 1 auto;
  min-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg-soft);
}
.chat-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.chat-msg-user { justify-content: flex-end; }
.chat-msg-user .chat-bubble {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.chat-msg-user .chat-avatar { display: none; }
.chat-avatar {
  flex: 0 0 32px;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--ink);
  display: grid;
  place-items: center;
  margin-top: 2px;
  font-size: 17px;
  line-height: 1;
  user-select: none;
}
.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink);
  overflow-wrap: break-word;
}
/* User messages preserve whatever formatting they typed (line breaks,
   multiple spaces). Bot bubbles render structured markdown HTML so the
   default whitespace collapsing is what we want. */
.chat-msg-user .chat-bubble { white-space: pre-wrap; }
.chat-bubble.typing { font-style: italic; color: var(--ink-mute); }

/* Markdown rendering inside bot bubbles */
.chat-bubble p { margin: 0 0 8px; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul, .chat-bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.chat-bubble li { margin-bottom: 2px; }
.chat-bubble li:last-child { margin-bottom: 0; }
.chat-bubble strong { font-weight: 600; }
.chat-bubble em { font-style: italic; }
.chat-bubble code {
  font-family: inherit;
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12.5px;
}
.chat-bubble pre {
  margin: 6px 0;
  padding: 8px 10px;
  background: var(--bg-hover);
  border-radius: 4px;
  overflow-x: auto;
  font-size: 12px;
}
.chat-bubble pre code {
  background: none;
  padding: 0;
}
.chat-bubble a {
  color: var(--accent-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-msg-user .chat-bubble a { color: var(--bg); text-decoration-color: var(--border); }
.chat-input {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
}
.chat-input input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  font-size: 13.5px;
  font-family: inherit;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
}
.chat-input input:focus {
  outline: 2px solid color-mix(in oklab, var(--accent-ink) 30%, transparent);
  border-color: var(--accent-ink);
}
.chat-input input:disabled { background: var(--bg-hover); }
.chat-hint {
  margin: 0;
  padding: 0 14px 14px;
  font-size: 11.5px;
  color: var(--down);
  background: var(--card-bg);
}
.chat-hint:empty { display: none; }
.chat-suggestions {
  list-style: none;
  margin: 0;
  padding: 0 12px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--card-bg);
}
.chip {
  font-family: inherit;
  font-size: 11.5px;
  padding: 5px 10px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink-soft);
  cursor: pointer;
  transition: background .15s, border-color .15s;
  letter-spacing: 0.02em;
}
.chip:hover { background: var(--bg-hover); border-color: var(--ink); color: var(--ink); }
.chip:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Connect ---------- */
.connect-list {
  list-style: none;
  margin: 0; padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--card-bg);
}
.connect-list li {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.connect-list li:last-child { border-bottom: none; }
.connect-label {
  flex: 0 0 96px;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 500;
}
.connect-list a {
  font-size: 13.5px;
  color: var(--ink);
  word-break: break-all;
  text-decoration-color: var(--border-strong);
}
.connect-list a:hover { color: var(--accent-ink); }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border-strong);
  padding: 20px 0;
  margin-top: 32px;
  background: var(--bg-soft);
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-mute);
}
.footer-inner p { margin: 0; }
.back-top { color: var(--ink-mute); text-decoration: none; }
.back-top:hover { color: var(--ink); }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
