:root {
  /* default dark theme, pitch black */
  --bg: #000000;
  --surface: #141414;
  --border: rgba(255, 255, 255, 0.14);
  --border-hover: rgba(255, 255, 255, 0.32);
  --text-primary: #f4f4f4;
  --text-secondary: #c4c4c4;
  --text-dim: #9e9e9e;
  --accent: #ffffff;

  /* fonts */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

}

/* if user prefers light mode and blocked js */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff;
    --surface: #f5f5f5;
    --border: rgba(0, 0, 0, 0.14);
    --border-hover: rgba(0, 0, 0, 0.32);
    --text-primary: #141414;
    --text-secondary: #444444;
    --text-dim: #6a6a6a;
    --accent: #000000;
  }
}

/* manual js theme toggle */
[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f5f5f5;
  --border: rgba(0, 0, 0, 0.14);
  --border-hover: rgba(0, 0, 0, 0.32);
  --text-primary: #141414;
  --text-secondary: #444444;
  --text-dim: #6a6a6a;
  --accent: #000000;
}

[data-theme="dark"] {
  --bg: #000000;
  --surface: #141414;
  --border: rgba(255, 255, 255, 0.14);
  --border-hover: rgba(255, 255, 255, 0.32);
  --text-primary: #f4f4f4;
  --text-secondary: #c4c4c4;
  --text-dim: #9e9e9e;
  --accent: #ffffff;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* kill ugly browser-default blue links */
a {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.15s ease;
}

a:visited {
  color: inherit;
}

a:hover {
  color: var(--accent);
}

/* lock viewport so only middle card scrolls on home/index */
html,
body {
  height: 100%;
  overflow: hidden;
}

/* let articles scroll normally like actual web pages */
html.page-article,
body.page-article,
html:has(.site-article),
body:has(.site-article) {
  height: auto;
  min-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

html {
  background-color: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.15s ease, color 0.15s ease;
}

body {
  background-color: var(--bg);
  line-height: 1.55;
}

/* homepage and index stay compact at 640px */
.site {
  max-width: 640px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 3rem 2rem 2rem;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

/* articles and source code get more breathing room */
.site.site-article {
  max-width: 780px;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: visible;
}

.site-article .content-scroll {
  overflow: visible;
  mask-image: none;
  -webkit-mask-image: none;
  padding-right: 0;
  margin-right: 0;
  margin-bottom: 2rem;
  padding-bottom: 2rem;
}

.site-article .scroll-hint {
  display: none !important;
}

/* top bar */
.header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.75rem;
  flex-shrink: 0;
}

.header-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.note-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.25rem;
}

.note-title-row h1 {
  font-size: 1.625rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.note-date-inline {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.header h1,
.bio h1 {
  font-size: 1.625rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.bio-text,
.bio p {
  font-size: 0.9375rem;
  font-weight: 400;
  color: var(--text-secondary);
  line-height: 1.55;
}

/* breadcrumbs */
.breadcrumb {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-dim);
}

.breadcrumb a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.15s ease;
}

.breadcrumb a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.breadcrumb-muted {
  color: var(--text-dim);
}

.breadcrumb-curr {
  color: var(--text-primary);
}

.links {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding-top: 0.2rem;
}

.links a,
.links a:visited,
.theme-toggle {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s ease;
}

.links a:hover,
.theme-toggle:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* scrollable middle container */
.content-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  /* always show scrollbar so people know there's more */
  scrollbar-width: thin;
  scrollbar-color: var(--border-hover) var(--surface);
  mask-image: linear-gradient(to bottom, black 0px, black calc(100% - 48px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, black 0px, black calc(100% - 48px), transparent 100%);
}

.content-scroll::-webkit-scrollbar {
  width: 6px;
}

.content-scroll::-webkit-scrollbar-track {
  background: var(--surface);
  border-radius: 999px;
}

.content-scroll::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: 999px;
}

.content-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

.content-scroll:focus:not(:focus-visible) {
  outline: none;
}

.content-scroll:focus-visible {
  outline: 1px dashed var(--text-secondary);
  outline-offset: 2px;
}

/* static non-scrolling middle area (404 / short pages) */
.content-static {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* section title row */
.section {
  display: flex;
  flex-direction: column;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.section-title {
  font-size: 1.125rem;
  font-weight: 600;
  font-family: var(--font-sans);
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
}

.section-header .section-title {
  margin-bottom: 0;
}

/* little scroll hint arrow */
.scroll-hint {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  opacity: 0.85;
  transition: opacity 0.25s ease, transform 0.25s ease;
  user-select: none;
}

.scroll-hint.is-hidden {
  opacity: 0;
  transform: translateY(-3px);
  pointer-events: none;
}

/* css scroll-timeline for browsers that support it */
@supports (animation-timeline: scroll()) {
  @keyframes fadeHintNoJS {
    0% {
      opacity: 0.85;
      transform: translateY(0);
    }
    15% {
      opacity: 0;
      transform: translateY(-3px);
    }
    100% {
      opacity: 0;
      transform: translateY(-3px);
    }
  }

  .content-scroll {
    scroll-timeline-name: --scroll-timeline;
    scroll-timeline-axis: block;
  }

  .scroll-hint {
    animation: fadeHintNoJS linear forwards;
    animation-timeline: --scroll-timeline;
    animation-range: 0px 40px;
  }
}

/* project cards */
.project-list {
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
}

.item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.item-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.item-title {
  font-size: 1.0rem;
  font-weight: 600;
  color: var(--accent);
}

.item-title-link {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--border-hover);
  text-underline-offset: 3px;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.item-title-link:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.item-link,
.item-link:visited {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  text-decoration: underline;
  text-underline-offset: 2px;
  margin-left: 6px;
  white-space: nowrap; /* keep [demo] attached to title on mobile */
  transition: color 0.15s ease;
}

.item-link:hover {
  color: var(--accent);
}

.item-meta {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.note-meta {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.item-desc {
  font-size: 0.9375rem;
  font-weight: 400;
  color: var(--text-secondary);
  line-height: 1.55;
}

.item-desc a,
.note-desc a {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.15s ease;
}

.item-desc a:hover,
.note-desc a:hover {
  color: var(--accent);
}

/* notes list */
.notes-list {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.note-item {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
}

.note-date {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
  width: 95px;
}

.note-content {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.note-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.4;
}

.note-desc {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--text-secondary);
  line-height: 1.55;
}

/* markdown prose styles */
.prose {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.65;
}

.prose p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.65;
}

.prose h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.01em;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

.prose h3 {
  font-size: 1.0rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.01em;
  margin-top: 0.85rem;
  margin-bottom: 0.25rem;
}

.prose h4 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 0.65rem;
  margin-bottom: 0.25rem;
}

.prose strong {
  color: var(--text-primary);
  font-weight: 600;
}

.prose em {
  color: var(--text-primary);
  font-style: italic;
}

.prose a {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: var(--border-hover);
  text-underline-offset: 3px;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.prose a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.prose ul,
.prose ol {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.85rem; /* breathing room between list items */
  padding-left: 0;
  margin: 0.25rem 0;
}

.prose li {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.6;
  position: relative;
  padding-left: 1.25rem;
}

.prose li::before {
  content: "–";
  position: absolute;
  left: 0;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-weight: 400;
}

/* nested lists */
.prose li > ul,
.prose li > ol {
  padding-left: 0.75rem;
  margin-top: 0.45rem;
  gap: 0.4rem;
}

.prose li > ul > li::before {
  content: "›";
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.prose ol {
  counter-reset: prose-counter;
}

.prose ol > li {
  counter-increment: prose-counter;
}

.prose ol > li::before {
  content: counter(prose-counter) ".";
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-dim);
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.8125em;
  padding: 0.15rem 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  word-break: break-word;
  white-space: pre-wrap; /* don't blow out mobile width on long file paths */
}

.prose pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.85rem 1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-primary);
  line-height: 1.5;
  margin: 0.5rem 0;
}

.prose pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
  word-break: normal;
}

.prose blockquote,
.prose .notice {
  border-left: 2px solid var(--border-hover);
  padding-left: 1rem;
  margin: 0.75rem 0;
  color: var(--text-dim);
  font-style: italic;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

/* table styles */
.prose .table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin: 0.5rem 0 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  text-align: left;
  line-height: 1.5;
}

.prose th {
  padding: 0.65rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.prose td {
  padding: 0.6rem 0.85rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.prose tr:last-child td {
  border-bottom: none;
}

/* footer */
.footer {
  flex-shrink: 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-dim);
}

.source-link,
.source-link:visited {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-dim);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.15s ease;
}

.source-link:hover {
  color: var(--accent);
}

.sig-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.25rem 0.55rem;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  text-decoration: none;
  transition: all 0.15s ease;
}

.sig-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 5px rgba(34, 197, 94, 0.5);
  flex-shrink: 0;
}

.sig-text {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.15s ease;
}

.sig-badge:hover {
  border-color: var(--border-hover);
}

.sig-badge:hover .sig-text {
  color: var(--accent);
}

/* source viewer: wrap everything, no horizontal scroll traps */
.code-view {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 0.75rem;
  overflow-x: hidden;          /* kill horizontal scroll */
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.65;
  color: var(--text-secondary);
  counter-reset: line-counter;
}

.code-view code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
  display: block;
}

/* css grid hack to keep line numbers sticky on wrapped lines */
.code-line {
  display: grid;
  grid-template-columns: 2.75rem 1fr;
  column-gap: 1rem;
  min-height: 1.65em;
  white-space: pre-wrap;       /* wrap long lines */
  word-break: break-word;      /* break giant base64 or urls */
}

.code-line::before {
  counter-increment: line-counter;
  content: counter(line-counter);
  text-align: right;
  color: var(--text-dim);
  opacity: 0.45;
  user-select: none;
  padding-right: 0.25rem;
}

/* Monochrome Syntax Highlighting */
.hl-tag {
  color: var(--accent);
  font-weight: 500;
}

.hl-attr {
  color: var(--text-primary);
}

.hl-str {
  color: var(--text-dim);
}

.hl-comm {
  color: var(--text-dim);
  font-style: italic;
  opacity: 0.7;
}

.hl-entity {
  color: var(--text-secondary);
}

/* mobile overrides */
@media (max-width: 540px) {
  .site {
    padding: 2rem 1.25rem 1.5rem;
  }

  .header {
    gap: 0.75rem;
    padding-bottom: 1.25rem;
    margin-bottom: 1.25rem;
  }

  .header-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.65rem;
  }

  .note-title-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .content-scroll {
    gap: 2rem;
    padding-right: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 1.5rem;
  }

  .item-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
  }

  .note-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }

  .note-date {
    width: auto;
  }

  .footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding-top: 1.25rem;
  }

  .code-view {
    padding: 0.75rem 0.5rem;
    font-size: 0.75rem;
  }

  .code-line {
    grid-template-columns: 2rem 1fr;
    column-gap: 0.65rem;
  }
}

/* print view so ctrl+p doesn't look cursed */
@media print {
  html, body {
    height: auto;
    overflow: visible;
    background: #ffffff;
    color: #000000;
  }

  .site {
    height: auto;
    max-width: 100%;
    padding: 0;
  }

  .content-scroll {
    overflow: visible;
    mask-image: none;
    -webkit-mask-image: none;
  }

  .theme-toggle,
  .scroll-hint {
    display: none !important;
  }
}
