@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/inter-latin-wght-normal.woff2) format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: italic;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/inter-latin-wght-italic.woff2) format('woff2');
}

/* ---------- tokens: neutral grays only ---------- */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar: #f8f8f7;
  --raised: #ffffff;
  --hover: rgba(0, 0, 0, 0.045);
  --active: rgba(0, 0, 0, 0.075);
  --border: #e6e6e4;
  --border-strong: #d4d4d2;
  --text: #1a1a1a;
  --muted: #6b6b69;
  --faint: #9b9b98;
  --code-bg: #f4f4f3;
  --accent: #1a1a1a;
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 24px rgba(0, 0, 0, 0.06);
  --sb-w: 268px;
  --tb-h: 48px;
  --col: 46rem;
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #1c1c1b;
    --sidebar: #151515;
    --raised: #262625;
    --hover: rgba(255, 255, 255, 0.055);
    --active: rgba(255, 255, 255, 0.095);
    --border: #2f2f2e;
    --border-strong: #3d3d3c;
    --text: #ececea;
    --muted: #a3a3a0;
    --faint: #737371;
    --code-bg: #262625;
    --accent: #ececea;
    --on-accent: #1a1a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #1c1c1b;
  --sidebar: #151515;
  --raised: #262625;
  --hover: rgba(255, 255, 255, 0.055);
  --active: rgba(255, 255, 255, 0.095);
  --border: #2f2f2e;
  --border-strong: #3d3d3c;
  --text: #ececea;
  --muted: #a3a3a0;
  --faint: #737371;
  --code-bg: #262625;
  --accent: #ececea;
  --on-accent: #1a1a1a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 24px rgba(0, 0, 0, 0.35);
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, textarea { font: inherit; color: inherit; }
.icon { flex: none; display: block; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; border-radius: 6px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---------- shell ---------- */

.shell { min-height: 100dvh; }
html { scroll-padding-top: calc(var(--tb-h) + 12px); }

/* One bar across the whole window: the sidebar toggle above the sidebar, the page title above the page. */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 40;
  display: flex;
  align-items: center;
  height: var(--tb-h);
  background: var(--bg);
  box-shadow: 0 1px 0 var(--border);
}
.tb-side {
  flex: none;
  display: flex;
  align-items: center;
  width: var(--sb-w);
  height: 100%;
  padding-left: 10px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  transition: width 0.2s ease;
}
.topbar-title { padding: 0 16px; font-size: 14px; line-height: 20px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-ico { display: none; }
.tb-close { display: block; }
.sb-closed .tb-side { width: 50px; }
.sb-closed .tb-close { display: none; }
.sb-closed .tb-open { display: block; }

.sidebar {
  position: fixed;
  inset: var(--tb-h) auto 0 0;
  z-index: 30;
  width: var(--sb-w);
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  transition: transform 0.2s ease;
}
.main {
  margin-left: var(--sb-w);
  padding-top: var(--tb-h);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s ease;
}
.sb-closed .sidebar { transform: translateX(-100%); }
.sb-closed .main { margin-left: 0; }
.scrim { display: none; }

.sb-nav { padding: 8px; display: grid; gap: 1px; border-bottom: 1px solid var(--border); }
.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 20px;
  text-decoration: none;
  color: var(--text);
}
.sb-item .icon { color: var(--muted); }
.sb-item:hover { background: var(--hover); }
.sb-item[aria-current='page'] { background: var(--active); }
.sb-item[aria-current='page'] .icon { color: var(--text); }
.sb-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-item .ext { color: var(--faint); }
.sb-scroll .sb-item { font-weight: 370; }

.sb-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 8px 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-gutter: stable;
}
.sb-group { margin-top: 14px; }
.sb-group summary {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  margin-bottom: 2px;
  font-size: 12.5px;
  line-height: 18px;
  font-weight: 450;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  border-radius: 6px;
  user-select: none;
}
.sb-group summary::-webkit-details-marker { display: none; }
.sb-group summary:hover { color: var(--text); }
.sb-group summary .chev { margin-left: -3px; color: var(--faint); transition: transform 0.15s ease; }
.sb-group summary:hover .chev { color: var(--muted); }
.sb-group:not([open]) summary .chev { transform: rotate(-90deg); }

.sb-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 14px;
  border-top: 1px solid var(--border);
}
.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.sb-foot-name { flex: 1; font-size: 14px; font-weight: 500; }
[data-mode-icon] { display: none; }
[data-theme-toggle][data-mode='system'] [data-mode-icon='system'],
[data-theme-toggle][data-mode='light'] [data-mode-icon='light'],
[data-theme-toggle][data-mode='dark'] [data-mode-icon='dark'] { display: block; }
[data-theme-toggle]:not([data-mode]) [data-mode-icon='system'] { display: block; }

@media (max-width: 860px) {
  .main, .sb-closed .main { margin-left: 0; }
  .sidebar, .sb-closed .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); width: min(85vw, 300px); }
  .tb-side, .sb-closed .tb-side { width: 50px; }
  .tb-close, .sb-closed .tb-open { display: none; }
  .tb-menu { display: block; }
  .topbar-title { padding-left: 12px; }
  .sb-mobile-open .sidebar { transform: none; }
  .sb-mobile-open .scrim { display: block; position: fixed; inset: var(--tb-h) 0 0 0; z-index: 25; background: rgba(0, 0, 0, 0.35); }
}

/* ---------- page column ---------- */

.page {
  flex: 1;
  width: 100%;
  max-width: calc(var(--col) + 48px);
  margin: 0 auto;
  padding: 24px 24px 48px;
}
@media (max-width: 600px) { .page { padding: 12px 16px 40px; } }

.prose { overflow-wrap: break-word; }
.prose h1 { font-size: 2rem; line-height: 1.2; letter-spacing: -0.025em; font-weight: 650; margin: 0.2em 0 0.5em; }
.prose h2 { font-size: 1.35rem; line-height: 1.3; letter-spacing: -0.015em; font-weight: 620; margin: 2em 0 0.6em; }
.prose h3 { font-size: 1.1rem; font-weight: 620; margin: 1.6em 0 0.5em; }
.prose h4, .prose h5, .prose h6 { font-size: 1rem; font-weight: 620; margin: 1.4em 0 0.4em; }
.prose p, .prose ul, .prose ol, .prose pre, .prose blockquote, .prose table { margin: 0 0 1.1em; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: 0.25em 0; }
.prose li::marker { color: var(--faint); }
.prose a { text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; text-decoration-thickness: 1px; }
.prose a:hover { text-decoration-color: var(--text); }
.prose strong { font-weight: 620; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.prose img, .prose video { max-width: 100%; height: auto; border-radius: 8px; }
.prose blockquote { margin-left: 0; padding-left: 1em; border-left: 3px solid var(--border-strong); color: var(--muted); }
.prose code { font-family: var(--mono); font-size: 0.86em; background: var(--code-bg); padding: 0.12em 0.36em; border-radius: 5px; }
.prose pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; overflow-x: auto; line-height: 1.5; }
.prose pre code { background: none; padding: 0; font-size: 0.84em; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 0.92em; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.prose th { background: var(--code-bg); font-weight: 600; }
.prose .katex { font-size: 1.05em; }

.meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 14px; line-height: 20px; margin: -0.2em 0 1.6em !important; }
.meta > span { display: inline-flex; align-items: center; gap: 6px; }
.lede { font-size: 1.1rem; color: var(--muted); }


.section { margin-top: 40px; }
.section-title { display: flex; align-items: center; gap: 8px; font-size: 14px; line-height: 20px; font-weight: 600; color: var(--muted); margin: 0 0 8px; }
.section-title .count { font-weight: 500; color: var(--faint); }
.section-more { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-weight: 500; text-decoration: none; color: var(--muted); }
.section-more:hover { color: var(--text); }

.rows { display: grid; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.row { display: flex; align-items: flex-start; gap: 14px; padding: 12px 16px; text-decoration: none; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row:hover { background: var(--hover); }
.row-icon { color: var(--muted); padding-top: 2px; }
.row-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.row-title { font-weight: 550; font-size: 15px; }
.row-sub { color: var(--muted); font-size: 14px; line-height: 1.45; }
.row-meta { flex: none; color: var(--faint); font-size: 13px; padding-top: 2px; }
@media (max-width: 600px) { .row-meta { display: none; } }
.chip { display: inline-block; padding: 1px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--raised);
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  text-decoration: none !important;
  cursor: pointer;
}
.btn:hover { background: var(--hover); }
.btn-quiet { border-color: var(--border); color: var(--muted); }
.link-buttons { display: flex; flex-wrap: wrap; gap: 8px; }

.todo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 8px;
  border: 1px dashed var(--faint);
  border-radius: 6px;
  font-size: 0.85em;
  font-style: normal;
  color: var(--muted);
}

.disclaimer { margin-top: 48px; font-size: 13px; color: var(--faint); }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 40px; }
.pager-link { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; text-decoration: none; font-size: 14px; font-weight: 500; }
.pager-link small { display: block; font-size: 12px; color: var(--faint); font-weight: 400; }
.pager-link.next { justify-content: flex-end; text-align: right; }
.pager-link:hover { background: var(--hover); }
.pager-link .icon { color: var(--muted); }

.readme { margin-top: 40px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.readme-title { display: flex; align-items: center; gap: 8px; margin: 0; padding: 10px 16px; font-size: 14px; line-height: 20px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--sidebar); }
.readme .prose { padding: 8px 20px 4px; font-size: 15px; }
.readme .prose h1 { font-size: 1.5rem; margin-top: 1em; }

.empty { display: grid; justify-items: center; gap: 4px; text-align: center; padding-top: 18vh; color: var(--muted); }
.empty h1 { margin: 8px 0; font-size: 1.5rem; color: var(--text); }

/* ---------- composer ---------- */

.composer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  width: 100%;
  max-width: calc(var(--col) + 48px);
  margin: 0 auto;
  padding: 18px 24px max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 18px);
}
@media (max-width: 600px) { .composer { padding: 14px 12px max(10px, env(safe-area-inset-bottom)); } }
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 10px 10px 16px;
  background: var(--raised);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.composer-box:focus-within { border-color: var(--faint); }
.composer textarea {
  flex: 1;
  min-height: 26px;
  max-height: 200px;
  padding: 4px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: none;
  font-size: 16px;
  line-height: 1.5;
}
.composer textarea::placeholder { color: var(--faint); }
.send-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}
.send-btn:disabled { opacity: 0.3; cursor: default; }
.send-btn .when-busy, .composer.busy .send-btn .when-idle { display: none; }
.composer.busy .send-btn .when-busy { display: block; }

/* ---------- chat ---------- */

.page-chat { display: flex; flex-direction: column; }
.chat-empty { display: none; }
.page-chat.is-empty .chat-empty {
  display: grid;
  justify-items: center;
  gap: 12px;
  margin: auto;
  padding-bottom: 8vh;
  text-align: center;
  color: var(--muted);
}
.chat-empty-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--hover); color: var(--text); }
.thread { display: grid; gap: 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.bubble { max-width: 85%; padding: 10px 16px; border-radius: 18px; background: var(--active); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant > :last-child { margin-bottom: 0; }
.msg-error { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.typing { display: inline-flex; gap: 4px; padding: 10px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ---------- islands ---------- */

.island { margin: 1.4em 0; padding: 16px; border: 1px solid var(--border); border-radius: 12px; }
.island-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 14px; }
.island-controls .stat { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.island label { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.island canvas { display: block; width: 100%; height: auto; max-width: 640px; border: 1px solid var(--border-strong); border-radius: 6px; touch-action: none; }
.island input[type='range'] { accent-color: var(--text); max-width: 100%; }
.fn-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 4px 0; font-size: 15px; font-variant-numeric: tabular-nums; }
.fn-row code { font-family: var(--mono); font-size: 0.9em; }
.fn-row .delta { color: var(--muted); }
.fn-row.out { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.btn-icon { display: contents; }

/* Optical alignment: centered in their row, icons sit about 1.5px below the middle of the capital letters
   (measured in rendered pixels), so icons next to text move up a pixel. Icon-only buttons stay centered. */
.icon { translate: 0 -1px; }
.meta .icon { translate: 0 -2px; } /* 16px icons beside 14px text need one more */
.icon-btn .icon, .send-btn .icon, .sb-more .icon, .row-icon .icon, .chat-empty-icon .icon, .empty > .icon { translate: none; }

/* ---------- chats in the sidebar ---------- */

.sb-chat { position: relative; }
.sb-chat .sb-item { padding-right: 36px; }
.sb-more {
  position: absolute;
  top: 50%;
  right: 4px;
  translate: 0 -50%;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
}
.sb-chat:hover .sb-more, .sb-chat.menu-open .sb-more, .sb-more:focus-visible { opacity: 1; }
.sb-chat:hover .sb-item, .sb-chat.menu-open .sb-item { background: var(--hover); }
.sb-chat .sb-item[aria-current='page'] { background: var(--active); }
.sb-more:hover, .sb-chat.menu-open .sb-more { color: var(--text); background: var(--active); }
@media (hover: none) { .sb-more { opacity: 1; } }

.menu {
  position: fixed;
  z-index: 60;
  min-width: 150px;
  padding: 4px;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  font-size: 14px;
  line-height: 20px;
  text-align: left;
  cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }
