/* =============================================================================
   Heptari's Notes — cool-toned, minimalist theme.
   Inspired by 1a-insec.net but with a blue/slate palette instead of sepia.
   ============================================================================= */

/* Self-hosted display font for the home page name. We ship the file with
   the site so it works offline and isn't blocked by any third-party CSP. */
@font-face {
  font-family: "UnifrakturMaguntia";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/UnifrakturMaguntia.ttf") format("truetype");
}

:root {
  /* ------- typography ------- */
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
               "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-serif: ui-serif, "Charter", "Iowan Old Style", "Source Serif Pro",
                Georgia, Cambria, "Times New Roman", Times, serif;
  --font-mono: ui-monospace, "JetBrains Mono", "SF Mono", "Fira Code",
               Menlo, Consolas, monospace;

  --measure: 86ch;

  /* ------- palette: cool / slate (light) ------- */
  --bg:           #f4f6f8;
  --bg-alt:       #eaeef2;
  --bg-soft:      #dde4eb;
  --bg-code:      #e6ecf2;

  --fg:           #1d2733;
  --fg-mute:      #475569;
  --fg-faint:     #7a8597;

  --border:       #cad4df;
  --border-soft:  #dbe2ea;

  --accent:       #2563a8;   /* steel blue */
  --accent-hover: #1d4d85;
  --accent-soft:  rgba(37, 99, 168, 0.12);

  /* layout */
  --header-h: 56px;
  --sidebar-w: 320px;
  --sidebar-min: 180px;
  --sidebar-max: 560px;
  --page-max: 1560px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #0f141a;
    --bg-alt:       #161d26;
    --bg-soft:      #1d2632;
    --bg-code:      #1a232e;

    --fg:           #c9d4e0;
    --fg-mute:      #8a98a8;
    --fg-faint:     #5a6678;

    --border:       #2a3340;
    --border-soft:  #1f2832;

    --accent:       #6fa8dc;
    --accent-hover: #9cc3e6;
    --accent-soft:  rgba(111, 168, 220, 0.14);
  }
}

/* ---------------------------------------------------------- reset & base ---- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:hover {
  color: var(--accent-hover);
  text-decoration-thickness: 2px;
}

code, pre, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

hr {
  border: 0;
  border-top: 1px solid var(--border-soft);
  margin: 2rem 0;
}

/* ---------------------------------------------------------------- header ---- */
/* Sub-pages only — the home page renders no .site-header. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
}
.site-header__inner {
  max-width: var(--page-max);
  margin: 0 auto;
  height: var(--header-h);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.4rem;
}
.site-title {
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: -0.005em;
}
.site-title:hover { color: var(--accent); }

/* "Heptari" wordmark in the header — same blackletter font as the home hero,
   just smaller. Sits on the far left, with the retro nav directly to its right. */
.site-title--retro {
  font-family: "UnifrakturMaguntia", "Apple Chancery",
               ui-serif, Georgia, serif;
  font-weight: 400;
  font-size: 1.5rem;
  letter-spacing: 0.02em;
  color: var(--fg);
  line-height: 1;
  padding-bottom: 0.1em;
}
.site-title--retro:hover { color: var(--accent); }

/* ---- retro nav (shared by home body + sub-page header) ----------------- */
/* Pixel-press-style brackets around each label: [Home] [All] [Search] [About] */
.retro-nav {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}
.retro-nav__btn {
  display: inline-flex;
  align-items: baseline;
  gap: 0.15rem;
  padding: 0.05rem 0.2rem;
  color: var(--fg-mute);
  background: transparent;
  border: 0;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  letter-spacing: inherit;
  transition: color 0.15s;
}
.retro-nav__bracket {
  color: var(--fg-faint);
  font-weight: 400;
  transition: color 0.15s, transform 0.15s;
}
.retro-nav__label {
  border-bottom: 1px dashed transparent;
  padding-bottom: 1px;
  transition: border-color 0.15s, color 0.15s;
}
.retro-nav__btn:hover,
.retro-nav__btn:focus-visible {
  color: var(--accent);
  outline: none;
}
.retro-nav__btn:hover .retro-nav__bracket,
.retro-nav__btn:focus-visible .retro-nav__bracket {
  color: var(--accent);
}
.retro-nav__btn:hover .retro-nav__label,
.retro-nav__btn:focus-visible .retro-nav__label {
  border-bottom-color: var(--accent);
}
.retro-nav__btn.is-active {
  color: var(--fg);
}
.retro-nav__btn.is-active .retro-nav__bracket {
  color: var(--accent);
}
.retro-nav__btn.is-active .retro-nav__label {
  border-bottom-color: var(--accent);
}
.retro-nav__btn--search.is-open .retro-nav__bracket {
  color: var(--accent);
}

/* In the sub-page header, the nav sits flush-left next to the wordmark. */
.retro-nav--header {
  font-size: 0.92rem;
}

/* On the home page, the nav appears under the giant "Heptari" name. */
.retro-nav--home {
  margin: 0.6rem 0 1.2rem;
  font-size: 1rem;
}

/* ----------------------------------------------------------------- search ---- */
/* The search input lives in a collapsible panel toggled by the [Search]
   nav button. The panel itself spans the full width of the header (or the
   home column) so the input gets enough room to type into. */
.site-search--panel {
  position: relative;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
}
.site-search--panel[hidden] { display: none; }
.site-search__wrap {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0.55rem 1.5rem 0.7rem;
  position: relative;
}
.site-search--home {
  border-bottom: 1px dashed var(--border-soft);
  border-top: 1px dashed var(--border-soft);
  margin: 0 0 1.4rem;
}
.site-search--home .site-search__wrap {
  padding: 0.6rem 0 0.7rem;
}
.site-search__input {
  width: 100%;
  height: 32px;
  padding: 0 0.7rem;
  font: inherit;
  font-size: 0.88rem;
  color: var(--fg);
  background: var(--bg-alt);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.site-search__input::placeholder { color: var(--fg-faint); }
.site-search__input:focus {
  border-color: var(--accent);
  background: var(--bg);
}
.site-search__results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: min(70vh, 540px);
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  z-index: 20;
  padding: 0.3rem;
}
.ss-empty {
  padding: 0.9rem 0.8rem;
  color: var(--fg-faint);
  font-size: 0.9rem;
  font-style: italic;
}
.ss-hit {
  display: block;
  padding: 0.55rem 0.7rem;
  border-radius: 4px;
  color: var(--fg);
  text-decoration: none;
  border: 1px solid transparent;
}
.ss-hit + .ss-hit { margin-top: 2px; }
.ss-hit:hover, .ss-hit.is-active {
  background: var(--accent-soft);
  border-color: var(--border-soft);
}
.ss-hit__title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.3;
}
.ss-hit__crumbs {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--fg-faint);
  margin-top: 2px;
}
.ss-hit__snippet {
  font-size: 0.83rem;
  color: var(--fg-mute);
  margin-top: 3px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ss-hit mark {
  background: transparent;
  color: var(--accent);
  font-weight: 600;
}

/* ------------------------------------------------------------------ main ---- */
.site-main {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  min-height: calc(100vh - var(--header-h) - 80px);
}
body.with-sidebar .site-main {
  grid-template-columns: var(--sidebar-w) 1fr;
}

/* --------------------------------------------------------------- sidebar ---- */
.sidebar {
  position: relative;
  padding: 1.5rem 0;
  border-right: 1px solid var(--border-soft);
  min-width: 0;
}
/* Vertical drag handle on the right edge of the sidebar. Click & drag to
   resize; double-click resets to the default width. Hidden on narrow screens
   where the sidebar collapses above the content instead. */
.sidebar__resizer {
  position: absolute;
  top: 0; right: -4px;
  width: 8px; height: 100%;
  cursor: col-resize;
  background: transparent;
  z-index: 5;
  touch-action: none;
}
.sidebar__resizer::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 1px;
  background: transparent;
  transition: background 0.15s;
}
.sidebar__resizer:hover::after,
.sidebar__resizer.is-dragging::after,
body.sb-resizing .sidebar__resizer::after {
  background: var(--accent);
}
body.sb-resizing { cursor: col-resize; user-select: none; }
body.sb-resizing * { user-select: none !important; }
.sidebar__inner {
  position: sticky;
  top: calc(var(--header-h) + 1rem);
  max-height: calc(100vh - var(--header-h) - 2rem);
  overflow-y: auto;
  padding-right: 0.6rem;
  line-height: 1.55;
}
.sb-root, .sb-root ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.sb-details { margin: 0; }
.sb-details > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.sb-details > summary::-webkit-details-marker { display: none; }
.sb-details > summary::before {
  content: "▸";
  font-size: 0.7em;
  color: var(--fg-faint);
  transition: transform 0.15s ease;
  display: inline-block;
}
.sb-details[open] > summary::before { transform: rotate(90deg); }

/* Top-level directory headings: label-style, same vertical rhythm as nested. */
.sb-root > li.sb-dir > .sb-details > .sb-dir__label {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-mute);
  font-weight: 600;
  margin: 0.55rem 0 0.2rem 0;
  padding: 0.15rem 0;
}
/* Nested directory labels — a little more breathing room than top-level. */
.sb-dir__label {
  font-size: 0.88rem;
  color: var(--fg);
  font-weight: 600;
  margin: 0.35rem 0 0.2rem 0;
  padding: 0.15rem 0;
}
.sb-dir__label:hover { color: var(--accent); }
.sb-file a {
  display: block;
  font-size: 0.9rem;
  color: var(--fg-mute);
  text-decoration: none;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  border-left: 2px solid transparent;
}
.sb-file a:hover {
  color: var(--fg);
  background: var(--bg-alt);
}
.sb-file.active a {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
  font-weight: 500;
}
.sb-root > li.sb-dir > .sb-details > ul,
.sb-root > li.sb-dir > .sb-details > ul > li.sb-dir > .sb-details > ul {
  margin-left: 0.5rem;
  padding-left: 0.65rem;
  border-left: 1px dashed var(--border-soft);
}

/* ------------------------------------------------------------- content ---- */
.content {
  padding: 2.2rem 0 3rem;
  min-width: 0;   /* allow long code blocks to scroll instead of overflowing */
}

/* --------------------------------------------------------------- article ---- */
.page, .home, .filetree {
  max-width: var(--measure);
}
body.no-sidebar .content { display: flex; justify-content: center; }
body.no-sidebar .home,
body.no-sidebar .filetree { width: 100%; }

.page-body {
  font-family: var(--font-serif);
  font-size: 1.04rem;
  line-height: 1.8;
}
.page-body h1, .page-body h2, .page-body h3, .page-body h4 {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.page-body h1 { font-size: 1.9rem; margin: 0.2em 0 0.6em; }
.page-body h2 {
  font-size: 1.35rem;
  margin: 2.2rem 0 0.6rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--border-soft);
}
.page-body h3 { font-size: 1.12rem; margin: 1.6rem 0 0.4rem; }
.page-body p { margin: 0.85em 0; }
.page-body ul, .page-body ol { padding-left: 1.5em; }
.page-body li { margin: 0.25em 0; }

.page-body :not(pre) > code {
  background: var(--bg-code);
  color: var(--fg);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.88em;
}
.page-body pre {
  background: var(--bg-code);
  color: var(--fg);
  padding: 0.95rem 1.1rem;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.55;
  border: 1px solid var(--border-soft);
}
.page-body pre code { background: transparent; padding: 0; }

.page-body blockquote {
  margin: 1.2em 0;
  padding: 0.1em 1.1em;
  border-left: 3px solid var(--border);
  color: var(--fg-mute);
  font-style: italic;
}

.page-body table {
  border-collapse: collapse;
  margin: 1.4em 0;
  font-size: 0.94em;
  font-family: var(--font-sans);
}
.page-body th, .page-body td {
  border: 1px solid var(--border-soft);
  padding: 0.45em 0.85em;
  text-align: left;
}
.page-body th { background: var(--bg-alt); font-weight: 600; }

.page-body img { max-width: 100%; height: auto; border-radius: 3px; }

.page-body a {
  color: var(--accent);
}
.page-body h2 .header-anchor,
.page-body h3 .header-anchor {
  color: var(--fg-faint);
  text-decoration: none;
  margin-left: 0.4em;
  opacity: 0;
  transition: opacity 0.15s;
}
.page-body h2:hover .header-anchor,
.page-body h3:hover .header-anchor { opacity: 1; }

/* breadcrumb + footer-nav */
.breadcrumb {
  font-size: 0.84rem;
  color: var(--fg-mute);
  margin-bottom: 1.2rem;
  font-family: var(--font-mono);
}
.breadcrumb a {
  color: var(--fg-mute);
  text-decoration: none;
}
.breadcrumb a:hover { color: var(--accent); text-decoration: underline; }
.breadcrumb .sep { margin: 0 0.4em; color: var(--fg-faint); }

.page-meta {
  margin-top: 2.5rem;
  font-size: 0.82rem;
  color: var(--fg-faint);
  font-family: var(--font-mono);
}

.page-nav {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.92rem;
}
.page-nav a { text-decoration: none; color: var(--accent); }
.page-nav a:hover { text-decoration: underline; }
.page-nav .next { margin-left: auto; text-align: right; }

/* ------------------------------------------------------------------ home ---- */
.home {
  font-family: var(--font-serif);
  font-size: 1.04rem;
  line-height: 1.8;
  padding-top: 1rem;
}
.home .tagline-current {
  border-left: 3px solid var(--accent);
  padding: 0.1em 0 0.1em 0.9em;
  color: var(--fg-mute);
  font-style: italic;
  margin: 0 0 0.5em 0;
}
.home .past-taglines {
  font-size: 0.88rem;
  color: var(--fg-faint);
  margin-bottom: 2rem;
}
.home .past-taglines summary {
  cursor: pointer;
  user-select: none;
  font-family: var(--font-mono);
}
.home .past-taglines ul { padding-left: 1.4em; margin: 0.4em 0 0; list-style: square; }
.home__name {
  font-family: "UnifrakturMaguntia", "Apple Chancery",
               ui-serif, Georgia, serif;
  font-weight: 400;
  font-size: 3.4rem;
  margin: 0.2em 0 0.1em;
  letter-spacing: 0.01em;
  line-height: 1.1;
  color: var(--fg);
}
.home__role {
  color: var(--fg-mute);
  margin: 0 0 1.4em;
  font-family: var(--font-sans);
  font-size: 0.95em;
}
.home p { margin: 0.9em 0; }
.home a { color: var(--accent); }

.home-section { margin-top: 2.4rem; }
.home-section h2 {
  font-family: var(--font-sans);
  font-size: 1.08rem;
  font-weight: 600;
  margin: 0 0 0.6em;
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--border-soft);
  letter-spacing: -0.005em;
}
.home-section ul { padding-left: 1.4em; }
.home-section li { margin: 0.35em 0; }

/* ------------------------------------------------------------- filetree ---- */
.filetree {
  padding-top: 1rem;
}
.filetree h1 {
  font-family: var(--font-sans);
  font-size: 1.7rem;
  margin: 0 0 0.4em;
  font-weight: 600;
}
.filetree .preamble {
  color: var(--fg-mute);
  margin-bottom: 1.8em;
  max-width: 60ch;
  font-family: var(--font-serif);
}
.filetree ul {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.7;
}
.filetree .ft-row { display: flex; align-items: baseline; }
.filetree .ft-details { margin: 0; }
.filetree .ft-details > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.filetree .ft-details > summary::-webkit-details-marker { display: none; }
.filetree .ft-details > summary .ft-dir::before {
  content: "▸ ";
  color: var(--fg-faint);
  display: inline-block;
  transition: transform 0.15s ease;
}
.filetree .ft-details[open] > summary .ft-dir::before {
  content: "▾ ";
}
.filetree .ft-details > summary:hover .ft-dir { color: var(--accent); }
.filetree .ft-prefix {
  color: var(--fg-faint);
  white-space: pre;
  user-select: none;
}
.filetree .ft-dir {
  color: var(--fg);
  font-weight: 600;
}
.filetree .ft-file a {
  color: var(--accent);
  text-decoration: none;
}
.filetree .ft-file a:hover { text-decoration: underline; }

/* ----------------------------------------------------------------- footer ---- */
.site-footer {
  border-top: 1px solid var(--border-soft);
  background: var(--bg-alt);
  margin-top: 3rem;
  padding: 1.5rem 1rem;
  text-align: center;
  font-size: 0.86rem;
  color: var(--fg-faint);
}
.site-footer__inner { max-width: 720px; margin: 0 auto; }
.site-footer .links a {
  color: var(--fg-mute);
  margin: 0 0.4em;
  text-decoration: none;
}
.site-footer .links a:hover { color: var(--accent); text-decoration: underline; }
.site-footer .copy { margin: 0.3em 0 0; }

/* --------------------------------------------------------------- responsive */
@media (max-width: 800px) {
  body.with-sidebar .site-main { grid-template-columns: 1fr; }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border-soft);
    padding: 1rem 0;
  }
  .sidebar__resizer { display: none; }
  .sidebar__inner {
    position: static;
    max-height: 320px;
  }
  .content { padding-top: 1.2rem; }
  .site-header__inner {
    gap: 0.7rem 1rem;
    padding: 0 1rem;
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-h);
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }
  .retro-nav--header { font-size: 0.88rem; gap: 0.2rem 0.4rem; }
  .site-title--retro { font-size: 1.3rem; }
  .site-search__wrap { padding-left: 1rem; padding-right: 1rem; }
  .site-main { padding: 0 1rem; }
}

/* ------------------------------------------------------------------ katex ---- */
/* Display math: allow horizontal scrolling on narrow screens instead of
   overflowing the layout. Inline math is kept inline as KaTeX intends. */
.content .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.4em 0;
  margin: 1em 0;
}
.content .katex { font-size: 1.05em; }
.content .katex-display > .katex { font-size: 1.15em; }
