/*
 * Site-wide design: tokens, Bootstrap/Lexxy theming, page shell, and shared components.
 * Loaded after Bootstrap (CDN) and lexxy.css. Rich text lives in content.css, admin in admin.css.
 * The theme is switched by data-bs-theme on <html> (see the inline script in the layout).
 */

/* ---------- Tokens ---------- */

:root {
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f2f2ef;
  --ink: #111113;
  --ink-2: #3f3f46;
  --muted: #71717a;
  --line: #e7e7e3;
  --line-strong: #d6d6d1;
  --accent: #0c7a45;
  --accent-ink: #ffffff;
  --danger: #c0362c;
  --warning: #a16207;

  --radius: 10px;
  --radius-sm: 7px;
  --header-h: 3.5rem;
  --content-w: 46rem;
  --wide-w: 72rem;

  color-scheme: light;
}

[data-bs-theme="dark"] {
  --bg: #0c0d0f;
  --surface: #141518;
  --surface-2: #1c1e22;
  --ink: #ececee;
  --ink-2: #c4c4cc;
  --muted: #8b8b96;
  --line: #24262b;
  --line-strong: #353840;
  --accent: #3ddc84;
  --accent-ink: #06210f;
  --danger: #ff7a6e;
  --warning: #f5b84a;

  color-scheme: dark;
}

:root,
[data-bs-theme="light"],
[data-bs-theme="dark"] {
  --accent-soft: color-mix(in oklab, var(--accent) 16%, transparent);

  /* Bootstrap */
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--ink);
  --bs-body-font-family: var(--font-sans);
  --bs-font-monospace: var(--font-mono);
  --bs-emphasis-color: var(--ink);
  --bs-heading-color: var(--ink);
  --bs-secondary-color: var(--muted);
  --bs-secondary-bg: var(--surface-2);
  --bs-tertiary-bg: var(--surface-2);
  --bs-border-color: var(--line);
  --bs-border-radius: var(--radius-sm);
  --bs-code-color: inherit;

  /* Lexxy (editor and rendered rich text) */
  --lexxy-color-ink: var(--ink);
  --lexxy-color-ink-medium: var(--ink-2);
  --lexxy-color-ink-light: var(--muted);
  --lexxy-color-ink-lighter: var(--line-strong);
  --lexxy-color-ink-lightest: var(--surface-2);
  --lexxy-color-ink-inverted: var(--surface);
  --lexxy-color-accent-dark: var(--accent);
  --lexxy-color-accent-medium: color-mix(in oklab, var(--accent) 70%, var(--surface));
  --lexxy-color-accent-light: color-mix(in oklab, var(--accent) 24%, var(--surface));
  --lexxy-color-accent-lightest: color-mix(in oklab, var(--accent) 13%, var(--surface));
  --lexxy-color-blue: var(--accent);
  --lexxy-font-base: var(--font-sans);
  --lexxy-font-mono: var(--font-mono);
  --lexxy-radius: var(--radius-sm);
}

[data-bs-theme="dark"] {
  --lexxy-color-code-token-att: #ff7b72;
  --lexxy-color-code-token-comment: #8b949e;
  --lexxy-color-code-token-function: #d2a8ff;
  --lexxy-color-code-token-operator: #ff7b72;
  --lexxy-color-code-token-property: #79c0ff;
  --lexxy-color-code-token-punctuation: #c9d1d9;
  --lexxy-color-code-token-selector: #7ee787;
  --lexxy-color-code-token-variable: #ffa657;
  --lexxy-shadow: 0 2px 12px rgb(0 0 0 / 50%);
}

/* ---------- Base ---------- */

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 1rem);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

a {
  color: inherit;
  text-decoration-color: color-mix(in oklab, currentColor 35%, transparent);
  text-underline-offset: 3px;
  transition: color .15s, text-decoration-color .15s;
}

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

::selection {
  background: color-mix(in oklab, var(--accent) 30%, transparent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.wrap {
  width: min(100% - 2.5rem, var(--wide-w));
  margin-inline: auto;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 200;
  padding: .5rem .875rem;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--bg);
  text-decoration: none;
}

.skip-link:focus {
  top: .75rem;
  color: var(--bg);
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--line);
  background: color-mix(in oklab, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  view-transition-name: site-header;
}

.site-header__inner {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "logo nav actions";
  align-items: center;
  column-gap: 1.5rem;
  min-height: var(--header-h);
}

.logo {
  grid-area: logo;
  display: inline-flex;
  align-items: baseline;
  font: 700 1.3125rem/1 var(--font-mono);
  letter-spacing: -0.05em;
  color: var(--ink);
  text-decoration: none;
}

.logo:hover {
  color: var(--ink);
}

.logo__dot {
  color: var(--accent);
}

/* 127 -> 127.0.0.1 on hover */
.logo__rest {
  max-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-weight: 500;
  opacity: 0;
  white-space: nowrap;
  transition: max-width .35s ease, opacity .25s ease;
}

.logo:hover .logo__rest,
.logo:focus-visible .logo__rest {
  max-width: 6ch;
  opacity: 1;
}

.site-nav {
  grid-area: nav;
  display: flex;
  gap: .125rem;
  overflow-x: auto;
  scrollbar-width: none;
  white-space: nowrap;
}

.site-nav::-webkit-scrollbar {
  display: none;
}

.nav-pill {
  flex: none;
  padding: .3125rem .6875rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 500;
  text-decoration: none;
  transition: color .15s, background-color .15s;
}

.nav-pill:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.nav-pill[aria-current="page"] {
  background: var(--surface-2);
  color: var(--ink);
}

.nav-pill--danger:hover {
  color: var(--danger);
}

.site-actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem;
}

.search {
  position: relative;
  display: flex;
}

.search svg {
  position: absolute;
  top: 50%;
  left: .75rem;
  width: .9375rem;
  height: .9375rem;
  color: var(--muted);
  pointer-events: none;
  translate: 0 -50%;
}

.search input {
  width: 11rem;
  height: 2.25rem;
  padding: 0 .75rem 0 2.125rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: .875rem;
  transition: width .2s ease, border-color .15s, box-shadow .15s;
}

.search input::placeholder {
  color: var(--muted);
}

.search input:focus {
  width: 15rem;
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.icon-btn {
  display: inline-grid;
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  place-items: center;
  transition: color .15s, border-color .15s;
}

.icon-btn:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.icon-btn svg {
  width: 1rem;
  height: 1rem;
}

.icon-moon,
[data-bs-theme="dark"] .icon-sun {
  display: none;
}

[data-bs-theme="dark"] .icon-moon {
  display: block;
}

@media (max-width: 60rem) {
  /* Two rows tall here, so it scrolls away instead of covering the text. */
  .site-header {
    position: static;
  }

  .site-header__inner {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "logo actions"
      "nav nav";
  }

  .site-header__inner > .logo,
  .site-header__inner > .site-actions {
    min-height: var(--header-h);
  }

  .logo {
    align-items: center;
  }

  .site-nav {
    margin-inline: -1.25rem;
    padding: 0 1.25rem .625rem;
  }

  .search input,
  .search input:focus {
    width: min(11rem, 38vw);
  }
}

/* ---------- Main and footer ---------- */

.site-main {
  flex: 1;
  padding-bottom: 5rem;
}

.layout-public .site-main {
  width: min(100% - 2.5rem, var(--content-w));
}

.site-main > .alert {
  margin: 1.5rem 0 0;
}

.site-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font: 500 .8125rem var(--font-mono);
}

.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem 1.5rem;
  padding-block: 1.75rem;
}

.site-footer nav {
  display: flex;
  gap: 1.25rem;
}

.site-footer a {
  text-decoration: none;
}

/* ---------- Page head ---------- */

.page-head {
  padding: 3.5rem 0 2rem;
}

.crumbs {
  margin: 0 0 .875rem;
  color: var(--muted);
  font: 500 .8125rem var(--font-mono);
}

.crumbs a {
  text-decoration: none;
}

.crumbs__sep {
  margin-inline: .125rem;
  opacity: .6;
}

.page-head h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 2.75rem);
  font-weight: 750;
  letter-spacing: -0.035em;
  line-height: 1.08;
  text-wrap: balance;
}

.page-head__lead {
  max-width: 40rem;
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 1.0625rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
  margin-top: 1.25rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: .125rem .5625rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font: 500 .75rem/1.6 var(--font-mono);
  text-decoration: none;
  white-space: nowrap;
}

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

.chip[aria-current="page"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--bg);
}

/* ---------- Article list ---------- */

.post-list {
  border-top: 1px solid var(--line);
}

.post {
  position: relative;
  padding: 1.75rem 0;
  border-bottom: 1px solid var(--line);
}

.post__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .375rem .75rem;
  margin-bottom: .625rem;
  color: var(--muted);
  font: 500 .8125rem var(--font-mono);
}

/* The chip stays clickable above the stretched title link. */
.post__meta .chip {
  position: relative;
  z-index: 1;
}

.post__title {
  margin: 0 0 .5rem;
  font-size: 1.375rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.28;
  text-wrap: balance;
}

.post__title a {
  color: var(--ink);
  text-decoration: none;
}

.post__title a::before {
  position: absolute;
  inset: 0;
  content: "";
}

.post__title a::after {
  display: inline-block;
  margin-left: .375rem;
  color: var(--accent);
  content: "→";
  opacity: 0;
  translate: -.375rem 0;
  transition: opacity .2s, translate .2s;
}

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

.post:hover .post__title a::after {
  opacity: 1;
  translate: 0 0;
}

.post__summary {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--ink-2);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

.empty {
  padding: 2.5rem 0;
  color: var(--muted);
}

/* ---------- Article page ---------- */

.article__head {
  margin-bottom: 2.5rem;
  padding: 3.5rem 0 2rem;
  border-bottom: 1px solid var(--line);
}

.article__title {
  margin: 0;
  font-size: clamp(2rem, 6.2vw, 3rem);
  font-weight: 750;
  letter-spacing: -0.035em;
  line-height: 1.08;
  text-wrap: balance;
}

.article__meta {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem .625rem;
  margin: 1.25rem 0 0;
  color: var(--muted);
  font: 500 .8125rem var(--font-mono);
}

.article__foot {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font: 500 .875rem var(--font-mono);
}

.article__foot a {
  text-decoration: none;
}

/* ---------- Bootstrap components ---------- */

.btn {
  --bs-btn-border-radius: var(--radius-sm);
  --bs-btn-font-size: .9375rem;
  --bs-btn-font-weight: 500;
  --bs-btn-padding-x: .875rem;
  --bs-btn-focus-box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  --bs-btn-color: var(--bg);
  --bs-btn-bg: var(--ink);
  --bs-btn-border-color: var(--ink);
  --bs-btn-hover-color: var(--accent-ink);
  --bs-btn-hover-bg: var(--accent);
  --bs-btn-hover-border-color: var(--accent);
  --bs-btn-active-color: var(--accent-ink);
  --bs-btn-active-bg: var(--accent);
  --bs-btn-active-border-color: var(--accent);
  --bs-btn-disabled-color: var(--bg);
  --bs-btn-disabled-bg: var(--muted);
  --bs-btn-disabled-border-color: var(--muted);
}

.btn-secondary,
.btn-outline-secondary,
.btn-outline-dark {
  --bs-btn-color: var(--ink);
  --bs-btn-bg: var(--surface);
  --bs-btn-border-color: var(--line-strong);
  --bs-btn-hover-color: var(--ink);
  --bs-btn-hover-bg: var(--surface-2);
  --bs-btn-hover-border-color: var(--line-strong);
  --bs-btn-active-color: var(--ink);
  --bs-btn-active-bg: var(--surface-2);
  --bs-btn-active-border-color: var(--line-strong);
}

.btn-danger {
  --bs-btn-color: var(--danger);
  --bs-btn-bg: transparent;
  --bs-btn-border-color: color-mix(in oklab, var(--danger) 45%, transparent);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--danger);
  --bs-btn-hover-border-color: var(--danger);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--danger);
  --bs-btn-active-border-color: var(--danger);
}

.alert {
  --bs-alert-bg: var(--surface);
  --bs-alert-color: var(--ink);
  --bs-alert-border-color: var(--line);
  --bs-alert-border-radius: var(--radius);
  --bs-alert-padding-x: 1rem;
  --bs-alert-padding-y: .75rem;
  --bs-alert-margin-bottom: 1.25rem;

  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  border-left: 3px solid var(--muted);
  font-size: .9375rem;
}

.alert-success,
.alert-info {
  border-left-color: var(--accent);
}

.alert-warning {
  border-left-color: var(--warning);
}

.alert-danger {
  border-left-color: var(--danger);
}

.alert__close {
  flex: none;
  margin: -.125rem -.25rem 0 0;
  padding: 0 .25rem;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
}

.alert__close:hover {
  color: var(--ink);
}

.pagination {
  --bs-pagination-color: var(--ink-2);
  --bs-pagination-bg: transparent;
  --bs-pagination-border-color: transparent;
  --bs-pagination-border-radius: var(--radius-sm);
  --bs-pagination-hover-color: var(--ink);
  --bs-pagination-hover-bg: var(--surface-2);
  --bs-pagination-hover-border-color: transparent;
  --bs-pagination-focus-color: var(--ink);
  --bs-pagination-focus-bg: var(--surface-2);
  --bs-pagination-focus-box-shadow: 0 0 0 3px var(--accent-soft);
  --bs-pagination-active-color: var(--bg);
  --bs-pagination-active-bg: var(--ink);
  --bs-pagination-active-border-color: var(--ink);
  --bs-pagination-disabled-color: var(--muted);
  --bs-pagination-disabled-bg: transparent;
  --bs-pagination-disabled-border-color: transparent;
  --bs-pagination-font-size: .875rem;

  flex-wrap: wrap;
  justify-content: center;
  gap: .25rem;
  margin: 2.5rem 0 0;
  font-family: var(--font-mono);
}

.pagination .page-link {
  min-width: 2.25rem;
  border-radius: var(--radius-sm);
  text-align: center;
}

/* ---------- Motion ---------- */

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: .18s;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}

@media (max-width: 40rem) {
  .page-head,
  .article__head {
    padding-top: 2.25rem;
  }
}
