/* ===========================================================
   Tokens

   The theme is built from THREE base tokens that flow into derived
   ones via color-mix(). To re-theme the site, override only the
   base tokens. To add a new theme (light/dark/etc), override only
   the base tokens within a [data-theme="..."] block.
   =========================================================== */
:root {
  /* === Base tokens — the only ones to override per theme === */
  --color-bg:     hsl(0, 0%, 100%);
  --color-text:   hsl(0, 0%, 13%);
  --color-accent: hsl(220, 70%, 50%);

  /* === Derived tokens — cascade from the three above === */
  --color-bg-alt:     color-mix(in srgb, var(--color-text)  5%, var(--color-bg));
  --color-text-muted: color-mix(in srgb, var(--color-text) 55%, var(--color-bg));
  --color-border:     color-mix(in srgb, var(--color-text) 15%, var(--color-bg));

  /* === Type === */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* === Layout === */
  --topbar-height: 56px;
  --panel-width:   280px;

  /* === Motion === */
  --transition: 200ms ease;

  /* === Syntax highlighting (rouge tokens) — light palette === */
  --syntax-comment:     #6a737d;
  --syntax-keyword:     #d73a49;
  --syntax-string:      #032f62;
  --syntax-number:      #005cc5;
  --syntax-function:    #6f42c1;
  --syntax-tag:         #22863a;
  --syntax-variable:    #e36209;
  --syntax-punctuation: #24292e;
  --syntax-error-fg:    #b31d28;
  --syntax-error-bg:    color-mix(in srgb, var(--syntax-error-fg) 10%, transparent);
}

/* Dark theme — override only the three base tokens.
   Derived tokens (bg-alt, text-muted, border) recompute automatically. */
[data-theme="dark"] {
  --color-bg:     hsl(220, 13%, 9%);
  --color-text:   hsl(0, 0%, 92%);
  --color-accent: hsl(220, 80%, 65%);

  /* Syntax tokens — dark palette (GitHub Dark inspired) */
  --syntax-comment:     #8b949e;
  --syntax-keyword:     #ff7b72;
  --syntax-string:      #a5d6ff;
  --syntax-number:      #79c0ff;
  --syntax-function:    #d2a8ff;
  --syntax-tag:         #7ee787;
  --syntax-variable:    #ffa657;
  --syntax-punctuation: #c9d1d9;
  --syntax-error-fg:    #ffa198;
}

/* Smooth color transitions when switching themes */
html {
  transition: background-color var(--transition), color var(--transition);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

img, picture, video, canvas, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }

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

/* ===========================================================
   Topbar — [logo-toggle | page.title | toc-toggle]
   Panels overlap the topbar (z-index above), so the topbar buttons
   fade away when their corresponding panel opens.
   =========================================================== */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  z-index: 20;
}

.topbar-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--color-text);
  transition: opacity var(--transition), background var(--transition);
}
.topbar-btn:hover { background: var(--color-bg-alt); }

.topbar-logo-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 4px;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-title:hover { text-decoration: none; color: var(--color-accent); }

/* Hide the topbar button whose panel is open (panel takes over) */
body.site-panel-open .topbar-logo {
  opacity: 0;
  pointer-events: none;
}
body.toc-panel-open .topbar-toc {
  opacity: 0;
  pointer-events: none;
}

/* ===========================================================
   Panels — full height, overlap topbar (z-index above)
   =========================================================== */
.site-panel,
.toc-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  width: var(--panel-width);
  background: var(--color-bg);
  border: 0 solid var(--color-border);
  z-index: 25;
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
}

.site-panel {
  left: 0;
  border-right-width: 1px;
  transform: translateX(-100%);
}
.toc-panel {
  right: 0;
  border-left-width: 1px;
  transform: translateX(100%);
}

body.site-panel-open .site-panel { transform: translateX(0); }
body.toc-panel-open  .toc-panel  { transform: translateX(0); }

/* === Panel internal header — flex row, three children === */
.panel-header {
  flex-shrink: 0;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
}

.panel-header-action {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--color-text);
  transition: background var(--transition);
}
.panel-header-action:hover { background: var(--color-bg-alt); }
.panel-header-action svg { fill: currentColor; }

.panel-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.panel-title a {
  color: inherit;
  text-decoration: none;
}
.panel-title a:hover { color: var(--color-accent); }

.panel-header-logo {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.panel-header-logo-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 4px;
}

/* === Theme toggle icons — show only the active one === */
.theme-icon { display: none; }
[data-theme="light"] .theme-icon-light { display: block; }
[data-theme="dark"]  .theme-icon-dark  { display: block; }

/* ===========================================================
   Search — input + dropdown results inside the site panel
   =========================================================== */
.search-box {
  flex-shrink: 0;
  position: relative;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
}

.search-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-text);
  font-size: 14px;
  transition: border-color var(--transition), background var(--transition);
}
.search-input::placeholder { color: var(--color-text-muted); }
.search-input:focus {
  outline: none;
  border-color: var(--color-accent);
  background: var(--color-bg);
}

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: none;
  position: absolute;
  top: calc(100% - 4px);
  left: 16px;
  right: 16px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  z-index: 10;
}
.search-results:not(:empty) { display: block; }

.search-results li {
  border-bottom: 1px solid var(--color-border);
}
.search-results li:last-child { border-bottom: none; }

.search-results li a {
  display: block;
  padding: 10px 12px;
  color: var(--color-text);
  text-decoration: none;
  transition: background var(--transition);
}
.search-results li a:hover {
  background: var(--color-bg-alt);
  text-decoration: none;
}

.search-results .result-title {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
}
.search-results .result-excerpt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 2px;
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.4;
}

.search-results .no-results {
  padding: 10px 12px;
  color: var(--color-text-muted);
  font-size: 13px;
  font-style: italic;
}

.panel-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}
.panel-nav ul { list-style: none; }
.panel-nav li > a,
.panel-nav li > em {
  display: block;
  padding: 6px 20px;
  color: var(--color-text);
  font-size: 14px;
  font-style: normal;
}
.panel-nav li > a:hover {
  background: var(--color-bg-alt);
  color: var(--color-accent);
  text-decoration: none;
}
.panel-nav li > em { color: var(--color-text-muted); }

/* ===========================================================
   TOC (Table of Contents) — generated into #toc-panel by toc.js
   =========================================================== */
.panel-nav .toc-list {
  list-style: none;
  padding: 8px 0;
}

.toc-empty {
  padding: 20px;
  color: var(--color-text-muted);
  font-size: 13px;
  font-style: italic;
  text-align: center;
}
.panel-nav .toc-item > a {
  display: block;
  padding: 5px 20px 5px 17px;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1.4;
  border-left: 3px solid transparent;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.panel-nav .toc-item > a:hover {
  color: var(--color-text);
  text-decoration: none;
  background: var(--color-bg-alt);
}
.panel-nav .toc-item.toc-active > a {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  font-weight: 500;
}

/* Indentation by heading depth */
.panel-nav .toc-item.toc-depth-0 > a { padding-left: 17px; }
.panel-nav .toc-item.toc-depth-1 > a { padding-left: 33px; }
.panel-nav .toc-item.toc-depth-2 > a { padding-left: 49px; }
.panel-nav .toc-item.toc-depth-3 > a { padding-left: 65px; }
.panel-nav .toc-item.toc-depth-4 > a { padding-left: 81px; }

/* ===========================================================
   Site Navigation (the tree rendered by nav-tree.html)
   =========================================================== */
.site-nav .site-nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.site-nav .site-nav-item {
  margin: 0;
}

.site-nav .site-nav-link,
.site-nav .site-nav-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 20px;
  background: none;
  border: none;
  text-align: left;
  font: inherit;
  font-size: 14px;
  color: var(--color-text);
  text-decoration: none;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.site-nav .site-nav-link:hover,
.site-nav .site-nav-toggle:hover {
  background: var(--color-bg-alt);
  color: var(--color-accent);
  text-decoration: none;
}

.site-nav .site-nav-link.current {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 8%, transparent);
  font-weight: 500;
}

.site-nav .site-nav-text {
  flex: 1;
  min-width: 0;
}

.site-nav .site-nav-external {
  margin-left: 4px;
  flex-shrink: 0;
  opacity: 0.65;
}

/* Chevron — rotates 90deg when group is expanded */
.site-nav .site-nav-chevron {
  flex-shrink: 0;
  color: var(--color-text-muted);
  transition: transform 150ms ease;
}
.site-nav .site-nav-group.expanded > .site-nav-toggle .site-nav-chevron,
.site-nav .site-nav-group.expanded > .site-nav-linkable-row > .site-nav-expander .site-nav-chevron {
  transform: rotate(90deg);
}

/* Linkable group: link on the left, expander button on the right */
.site-nav .site-nav-linkable-row {
  display: flex;
  align-items: stretch;
}
.site-nav .site-nav-linkable-row > .site-nav-link {
  flex: 1;
  min-width: 0;
}
.site-nav .site-nav-expander {
  flex-shrink: 0;
  width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background 120ms ease, color 120ms ease;
}
.site-nav .site-nav-expander:hover {
  background: var(--color-bg-alt);
  color: var(--color-accent);
}

/* Heading (no url, no items) — small uppercase category label */
.site-nav .site-nav-heading {
  padding: 14px 20px 6px;
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.site-nav > .site-nav-list > .site-nav-heading:first-child {
  padding-top: 6px;
}

/* Nested indentation — links/toggles inside a nested list get more padding */
.site-nav .site-nav-list .site-nav-list .site-nav-link,
.site-nav .site-nav-list .site-nav-list .site-nav-toggle {
  padding-left: 36px;
}
.site-nav .site-nav-list .site-nav-list .site-nav-list .site-nav-link,
.site-nav .site-nav-list .site-nav-list .site-nav-list .site-nav-toggle {
  padding-left: 52px;
}

/* Interactive mode (set by site-nav.js): collapse non-expanded groups */
.site-nav-interactive .site-nav-group:not(.expanded) > .site-nav-list {
  display: none;
}

.panel-footer {
  flex-shrink: 0;
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
  font-size: 12px;
  color: var(--color-text-muted);
}

.site-copyright {
  display: block;
  text-align: center;
}

/* === Social icons in the site-panel footer === */
.social-icons {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}

.social-link {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--color-text-muted);
  transition: color var(--transition), background var(--transition);
}
.social-link:hover {
  color: var(--color-accent);
  background: var(--color-bg-alt);
  text-decoration: none;
}
.social-link svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ===========================================================
   TOC panel footer — page metadata rows
   =========================================================== */
.toc-panel-footer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 20px;
}

.toc-panel-footer .meta-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.4;
}

.toc-panel-footer .meta-item svg {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  opacity: 0.85;
}

.toc-panel-footer .meta-item time,
.toc-panel-footer .meta-item > span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tags wrap to multiple lines when they overflow */
.toc-panel-footer .meta-tags {
  align-items: flex-start;
}
.toc-panel-footer .meta-tags svg {
  margin-top: 2px;
}
.toc-panel-footer .meta-tags > span {
  white-space: normal;
}
.toc-panel-footer .tag-sep {
  margin: 0 4px;
  opacity: 0.6;
}

/* ===========================================================
   Main content
   =========================================================== */
.main-content {
  margin-top: var(--topbar-height);
  padding: 32px 24px;
  transition: margin var(--transition);
}

.markdown-body {
  max-width: 760px;
  margin: 0 auto;
}

/* ===========================================================
   Blog — post-back link + post list (blog.md)
   =========================================================== */
.post-back {
  display: inline-block;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--color-text-muted);
}
.post-back:hover { color: var(--color-accent); text-decoration: none; }

.post-list {
  list-style: none;
  padding: 0;
  margin: 24px 0 0;
}

.post-list-item {
  padding: 16px 0;
  border-bottom: 1px solid var(--color-border);
}
.post-list-item:first-child { padding-top: 0; }

.post-list-title {
  font-size: 17px;
  font-weight: 600;
}
.post-list-title:hover { text-decoration: none; color: var(--color-accent); }

.post-list-date {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--color-text-muted);
}

.post-list-excerpt {
  margin: 8px 0 0;
  color: var(--color-text-muted);
  font-size: 14px;
}

.post-list-empty {
  color: var(--color-text-muted);
  font-style: italic;
}

/* ===========================================================
   Breadcrumbs — generated by _includes/breadcrumbs.html
   Sits above .markdown-body and shares its centering.
   =========================================================== */
.breadcrumbs {
  max-width: 760px;
  margin: 0 auto 1.5em;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  font-size: 14px;
  color: var(--color-text-muted);
}

.breadcrumbs .crumb {
  display: inline-block;
  padding: 3px 8px;
  color: var(--color-accent);
  text-decoration: none;
  border-radius: 4px;
  transition: background var(--transition), color var(--transition);
}
.breadcrumbs a.crumb:hover {
  background: var(--color-bg-alt);
  text-decoration: none;
}

.breadcrumbs .crumb.current {
  color: var(--color-text);
  font-weight: 500;
  cursor: default;
}

.breadcrumbs .crumb-sep {
  color: var(--color-text-muted);
  user-select: none;
  margin: 0 2px;
}

/* Desktop: panels push the content area when open */
@media (min-width: 1024px) {
  body.site-panel-open .main-content { margin-left: var(--panel-width); }
  body.toc-panel-open  .main-content { margin-right: var(--panel-width); }
}

/* ===========================================================
   Backdrop — mobile only, covers everything below panels
   (panels = 25, backdrop = 22, topbar = 20)
   =========================================================== */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
  z-index: 22;
}

@media (max-width: 1023px) {
  body.site-panel-open .backdrop,
  body.toc-panel-open  .backdrop {
    opacity: 1;
    pointer-events: auto;
  }
}