/*==========================================================================
  core.css — tokens, base, chrome, page scaffold, motion
  Monochrome, text-first. One column, a left rail for dates and labels,
  hairlines for structure. Colour is reserved for state (the "available" dot).
  Shared by every page; the chrome markup comes from assets/js/chrome.js.
==========================================================================*/

/*--------------------------------------------------------------------------
  1. TOKENS
--------------------------------------------------------------------------*/

:root {
  --bg:          #0a0a0a;
  --bg-elev:     #111111;
  --bg-hover:    #161616;
  --line:        #1f1f1f;
  --line-strong: #2e2e2e;

  --text-hi:    #ededed;
  --text-prose: #d0d0d0;
  --text-mid:   #a1a1a1;
  --text-low:   #7a7a7a;

  --btn-bg: #ededed;
  --btn-fg: #0a0a0a;
  --live:   #3fb950;

  --ff-sans: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --ff-mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --measure: 720px;   /* content column */
  --aside:   152px;   /* left rail inside the column */
  --col-gap: 32px;
  --gutter:  24px;
  --bar-h:   56px;
  --radius:  8px;
  --ease:    cubic-bezier(0.2, 0, 0, 1);

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg:          #fafafa;
  --bg-elev:     #ffffff;
  --bg-hover:    #f0f0f0;
  --line:        #e6e6e6;
  --line-strong: #d2d2d2;

  --text-hi:    #0a0a0a;
  --text-prose: #2b2b2b;
  --text-mid:   #525252;
  --text-low:   #737373;

  --btn-bg: #0a0a0a;
  --btn-fg: #fafafa;
  --live:   #1a7f37;

  color-scheme: light;
}

/*--------------------------------------------------------------------------
  2. BASE
--------------------------------------------------------------------------*/

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: var(--bar-h);
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text-mid);
  font-family: var(--ff-sans);
  font-size: 15px;
  line-height: 1.6;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
body.is-locked { overflow-y: hidden; }

li { list-style: none; }
a { color: inherit; text-decoration: none; }
img, svg, figure { display: block; max-width: 100%; }
button, input, textarea, select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
address { font-style: normal; }
h1, h2, h3, h4, h5, h6 { color: var(--text-hi); font-weight: 600; line-height: 1.3; letter-spacing: -0.011em; }
time, .num { font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--text-hi); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--text-hi); color: var(--bg); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 120;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 13px;
  font-weight: 500;
  transition: top 0.15s;
}
.skip-link:focus { top: 12px; }

/* inline text link */
.link,
.prose a {
  color: var(--text-hi);
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: text-decoration-color 0.15s;
}
.link:hover,
.prose a:hover { text-decoration-color: var(--text-hi); }

.ico { width: 16px; height: 16px; flex-shrink: 0; }

/*--------------------------------------------------------------------------
  3. LAYOUT
--------------------------------------------------------------------------*/

.wrap {
  width: 100%;
  max-width: calc(var(--measure) + var(--gutter) * 2);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/*--------------------------------------------------------------------------
  4. TOP BAR
--------------------------------------------------------------------------*/

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--bar-h);
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s, background 0.2s;
  /* stays put while pages cross-fade underneath it */
  view-transition-name: topbar;
}
.topbar.stuck {
  border-bottom-color: var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
          backdrop-filter: blur(12px);
}
.topbar-inner {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-hi);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.nav {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-left: auto;
}
.nav-link {
  position: relative;
  font-size: 13.5px;
  color: var(--text-low);
  transition: color 0.15s;
  white-space: nowrap;
}
.nav-link:hover,
.nav-link[aria-current="page"] { color: var(--text-hi); }

/* current-page marker on the bar's bottom edge; slides between pages */
.nav-ind {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc((100% - var(--bar-h)) / 2);
  height: 1px;
  background: var(--text-hi);
  view-transition-name: nav-ind;
}

.bar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  display: grid;
  place-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  color: var(--text-low);
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--text-hi); background: var(--bg-hover); }

.theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: none; }

.bar-actions .btn { margin-left: 8px; }

.burger { display: none; }
.burger i {
  display: block;
  width: 16px;
  height: 1.5px;
  border-radius: 1px;
  background: currentColor;
  transition: transform 0.25s var(--ease);
}
.burger i + i { margin-top: 5px; }
body.drawer-open .burger i:first-child { transform: translateY(3.25px) rotate(45deg); }
body.drawer-open .burger i:last-child  { transform: translateY(-3.25px) rotate(-45deg); }

/*--------------------------------------------------------------------------
  5. MOBILE DRAWER
--------------------------------------------------------------------------*/

.drawer {
  position: fixed;
  inset: var(--bar-h) 0 0;
  z-index: 49;
  padding: 16px var(--gutter) 40px;
  background: var(--bg);
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}
body.drawer-open .drawer { opacity: 1; visibility: visible; }

.drawer-link {
  display: block;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.015em;
  color: var(--text-mid);
  transition: color 0.15s;
}
.drawer-link:hover,
.drawer-link[aria-current="page"] { color: var(--text-hi); }
body.drawer-open .drawer-link {
  animation: enter 0.45s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 35ms);
}

.drawer-foot {
  margin-top: 28px;
  display: grid;
  gap: 12px;
  font-size: 14px;
}
.drawer-foot a { color: var(--text-mid); }
.drawer-foot a:hover { color: var(--text-hi); }

/*--------------------------------------------------------------------------
  6. BUTTONS
--------------------------------------------------------------------------*/

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-hi);
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.15s var(--ease);
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--btn-bg);
  border-color: var(--btn-bg);
  color: var(--btn-fg);
}
.btn-primary:hover { background: var(--btn-bg); opacity: 0.86; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }

/*--------------------------------------------------------------------------
  7. PAGE SCAFFOLD — header, breadcrumb, previous/next
--------------------------------------------------------------------------*/

.page-head { padding-block: clamp(48px, 9vw, 88px) clamp(28px, 4vw, 40px); }
.page-title {
  font-size: clamp(28px, 4.4vw, 36px);
  line-height: 1.15;
  letter-spacing: -0.026em;
}
.page-lede {
  margin-top: 12px;
  max-width: 58ch;
  font-size: 16.5px;
  line-height: 1.65;
  color: var(--text-mid);
}
.page-meta {
  margin-top: 14px;
  font-size: 13.5px;
  color: var(--text-low);
  font-variant-numeric: tabular-nums;
}
.page-body { padding-bottom: clamp(48px, 7vw, 64px); }

.crumb {
  display: inline-flex;
  margin-bottom: clamp(24px, 4vw, 36px);
  font-size: 13.5px;
  color: var(--text-low);
  transition: color 0.15s;
}
.crumb:hover { color: var(--text-hi); }

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding-block: 8px clamp(48px, 7vw, 72px);
}
.pager-link {
  display: grid;
  gap: 2px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  transition: background 0.15s, border-color 0.15s;
}
.pager-link:hover { background: var(--bg-hover); border-color: var(--line-strong); }
.pager-link.next { grid-column: 2; text-align: right; }
.pager-dir { font-size: 12.5px; color: var(--text-low); }
.pager-name { font-size: 15px; font-weight: 500; color: var(--text-hi); }

/*--------------------------------------------------------------------------
  8. FOOTER
--------------------------------------------------------------------------*/

.footer { border-top: 1px solid var(--line); }
.footer-inner {
  padding-block: 36px 44px;
  display: grid;
  gap: 16px;
  font-size: 13.5px;
  color: var(--text-low);
}
.footer-name { color: var(--text-hi); font-weight: 500; }
.footer-nav,
.footer-base { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.footer-nav a,
.footer-base a { transition: color 0.15s; }
.footer-nav a:hover,
.footer-base a:hover { color: var(--text-hi); }
.footer-base .up { margin-left: auto; }

/*--------------------------------------------------------------------------
  9. COMMAND PALETTE
--------------------------------------------------------------------------*/

.cmdk {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  align-items: start;
  justify-items: center;
  padding: clamp(56px, 14vh, 140px) 16px 24px;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s;
}
.cmdk.open { opacity: 1; visibility: visible; }

.cmdk-panel {
  width: min(560px, 100%);
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  box-shadow: 0 24px 64px -16px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  transform: translateY(-6px) scale(0.99);
  transition: transform 0.2s var(--ease);
}
.cmdk.open .cmdk-panel { transform: none; }

.cmdk-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--text-low);
}
.cmdk-field input {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  color: var(--text-hi);
}
.cmdk-field input::placeholder { color: var(--text-low); }
.cmdk-field input:focus-visible { outline: none; }

kbd {
  font-family: var(--ff-mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  color: var(--text-low);
}

.cmdk-list { max-height: min(52vh, 400px); overflow-y: auto; padding: 6px; }
.cmdk-group {
  font-size: 12px;
  color: var(--text-low);
  padding: 10px 10px 6px;
}
.cmdk-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-mid);
  text-align: left;
}
.cmdk-item .hint { margin-left: auto; font-size: 12px; color: var(--text-low); }
.cmdk-item[aria-selected="true"] { background: var(--bg-hover); color: var(--text-hi); }
.cmdk-empty { padding: 24px 10px; text-align: center; font-size: 13px; color: var(--text-low); }

/*--------------------------------------------------------------------------
  10. TOAST
--------------------------------------------------------------------------*/

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 110;
  transform: translate(-50%, 8px);
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  font-size: 13px;
  color: var(--text-hi);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s var(--ease);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/*--------------------------------------------------------------------------
  11. MOTION
--------------------------------------------------------------------------*/

/* entrance: page headings and the intro rise in on load, staggered by --i */
@keyframes enter {
  from { opacity: 0; transform: translateY(10px); }
}
.enter {
  animation: enter 0.7s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 70ms + 40ms);
}

/* scroll reveals: children of [data-reveal] rise in as they enter the
   viewport. Hidden only when JS is on (.js is set in <head>); if app.js never
   runs, the failsafe shows everything after a moment. */
.js [data-reveal] > :not(.state-line) {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.55s var(--ease), transform 0.7s var(--ease);
  transition-delay: var(--rd, 0ms);
  animation: reveal-failsafe 0s 2.5s forwards;
}
.js.reveal-ready [data-reveal] > * { animation: none; }
.js [data-reveal] > .in { opacity: 1; transform: none; }
@keyframes reveal-failsafe {
  to { opacity: 1; transform: none; }
}

/* page-to-page: the bar holds still, content cross-fades, the nav marker slides */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: vt-out 0.16s ease both; }
::view-transition-new(root) { animation: vt-in 0.26s ease both; }
::view-transition-group(nav-ind) {
  animation-duration: 0.4s;
  animation-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; } }

/*--------------------------------------------------------------------------
  12. RESPONSIVE CHROME
--------------------------------------------------------------------------*/

@media (max-width: 800px) {
  .nav, .kbd-btn { display: none; }
  .burger { display: grid; }
  .bar-actions { margin-left: auto; }
}

@media (max-width: 640px) {
  .footer-base .up { margin-left: 0; }
}

@media (max-width: 420px) {
  :root { --gutter: 18px; }
}

/*--------------------------------------------------------------------------
  13. REDUCED MOTION
--------------------------------------------------------------------------*/

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
  }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}
