/* allostatik.com
   Plain, typographic, theme-aware. No hero, no gradient, no flourish —
   the register the writing is in.

   Palette: Tidepool (github.com/s3mi0tics/tidepool) — the signature teal #4FB0C2
   with its green/cyan/blue family. Tidepool is a DARK theme, so dark mode uses it
   verbatim and light mode uses darkened same-hue variants: the originals measure
   2.4:1 or worse on a light ground and would fail WCAG AA, which would break the
   accessibility commitment the theme's own README makes.
   Measured contrast is noted per token. Nothing here encodes meaning in a
   red-versus-green difference.

   Colour roles follow Tidepool's own split — blue family = structure, green
   family = data:
     title      -> --title    near-white, bold sans (colbykauk.com "COLBY KAUK")
     body+eyebrow-> --prose   soft blue — ONE value for both, as on colbykauk.com,
                              where the paragraph copy and the small label share it
     links      -> --link     (nav/social blue)
     code       -> --code-text  green, inline AND in blocks. Tidepool's README:
                   "warm tones stay out of your code — red and amber are reserved
                   for errors and warnings", so the light-mode coral is not
                   available for code even though it is the light accent.
     accent     -> --accent     decorative rules (title underline, blockquote)
                   --accent-ink  the accent used as TEXT (the copy control)
                   Two tokens because light mode needs them apart: the coral
                   #EE7868 is 2.66 on the light ground — fine as a 2px rule,
                   a fail as text. In dark, green clears both, so both hold it.
     NOTE the accent hue FLIPS by theme — green in dark, coral in light. That is
     colbykauk.com's own design, not an inconsistency.
   The title is NOT coloured — colbykauk.com puts the colour on the small label
   above it and keeps the name near-white. Links keep their own hue so "heading"
   and "clickable" never share one. */

:root {
  /* light — colbykauk.com light theme, ground lifted to #FAFCFF. Ratios vs --bg:
     title 13.93, prose 8.77, link 6.42, muted 4.81.
     Three sampled values needed darkening to clear AA; the originals are noted
     so the source is still traceable. */
  --bg:        #fdfeff;  /*           lifted again from #FAFCFF        */
  --surface:   #cde6fd;  /*           left-panel blue                 */
  --title:     #0d2a59;  /* 13.4 AAA  "MAESTRO MODERN" navy, verbatim */
  --prose:     #3c4b62;  /*  8.6 AAA  from #6A7D9B (3.98 — body fail) */
  --muted:     #667287;  /*  4.9 AA                                   */
  --rule:      #d8e4f0;
  --link:      #3a55c0;  /*  6.2 AA   from #587AEF (3.67)             */
  --link-hover:#3049a8;  /*  7.6 AAA                                  */
  --accent:    #ee7868;  /*           coral, VERBATIM — decorative rules only */
  --accent-ink:#b8422f;  /*  5.2 AA   coral darkened, for accent-as-text */
  --select:    #cde6fd;
  --code-bg:   #ecf2fa;  /*           held apart from the lifted ground */
  --code-line: #cfdcea;  /*           the gentle outline           */
  --code-track:#f2f6fc;  /*           scrollbar track — a step lighter than --code-bg */
  --code-thumb:#c3d2e4;
  --code-text: #1a5c3e;  /*  6.3 AA on --code-bg, 5.5 on --surface (blockquote) */
  /* Lift. Light mode: layered shadows — a tight one for the contact edge and a
     wide soft one for the ambient drop. Two layers read as depth; one reads as a
     blur. Tinted with the navy rather than pure black so it sits in the palette. */
  --lift:      0 1px 2px rgba(13, 42, 89, 0.07),
               0 8px 20px -10px rgba(13, 42, 89, 0.16);
  --lift-edge: none;
  /* Reading measure. MEASURED, not estimated — at 20px on the launch post:
       34rem -> 61 chars/line, 8920px document
       40rem -> 68 chars/line, 7762px document  (-13% scroll)
       44rem -> 77 chars/line, 7228px document  (-19%, but above the 60-75 band)
     40rem sits in the middle of the band a serif wants. 34rem was already inside
     it at the low end, so widening is a real but modest gain — it does not make
     a long post short. Set once here; every column follows it. */
  --measure:   40rem;
  --font-body: ui-serif, Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --font-ui:   ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

/* dark — ground #1E1E20. Ratios vs #1E1E20:
   title 13.21, prose 9.59, link 6.67, green 6.81, muted 6.18.
   Note --code-bg is LIGHTER than --bg, not darker: code blocks lift off the
   page rather than sinking into it. --code-text is #7ACB9B rather than the
   accent green #65B687 — on the lighter code ground the accent measures 5.86,
   and the lift keeps code at AAA where it is read character by character.
   --muted is NOT Tidepool's #6E6E6E comment grey: that measures 2.63 here and
   fails AA for page text. Lightened to #9a9ea3 (6.18 here) for the same role. */
@media (prefers-color-scheme: dark) {
  /* Excludes EVERY pinned theme, not just light. With only light+dark this read
     as :not([data-theme='light']); adding a third pinned theme made that wrong —
     picking ink on a dark-OS machine would have layered dark tokens over it. */
  :root:not([data-theme='light']):not([data-theme='ink']) {
    --bg:        #1e1e20;  /* darker again                          */
    --surface:   #171718;  /* held below --bg                       */
    --title:     #e5e5e5;  /* 10.6 AAA  colbykauk.com "COLBY KAUK"    */
    --prose:     #b0c7e1;  /*  7.7 AAA  colbykauk.com body + eyebrow    */
    --muted:     #9a9ea3;  /*  5.0 AA   (Tidepool's #6E6E6E comment grey is 2.63 — fails) */
    --rule:      #2c2c2e;
    --link:      #69aec0;  /*  5.4 AA   colbykauk.com nav/social      */
    --link-hover:#8fc9d8;  /*  7.4 AAA                                */
    --accent:    #65b687;  /*  6.4      green — decorative rules            */
    --accent-ink:#65b687;  /*  6.4 AA   green clears the text bar too, so one value */
    --select:    #3d5a60;  /* Tidepool editor.selectionBackground   */
    --code-bg:   #2a2a2d;  /* LIGHTER than --bg — code lifts off the page */
    --code-line: #3f3f44;  /* the gentle outline                    */
    --code-track:#333338;  /* a step LIGHTER than --code-bg, both modes */
    --code-thumb:#4a4a52;
    --code-text: #7acb9b;  /*  7.4 AAA  green, lifted from #65B687 for code-bg */
    /* Lift, dark. A drop shadow alone does almost nothing on a #1E1E20 page —
       there is nothing left to darken. What reads as raised here is the inset
       highlight on the TOP edge: light falls from above and catches the lip of
       a raised surface. The drop below is kept, but it is the junior partner. */
    --lift:      0 1px 2px rgba(0, 0, 0, 0.4),
                 0 10px 24px -12px rgba(0, 0, 0, 0.65);
    --lift-edge: inset 0 1px 0 rgba(255, 255, 255, 0.055);

  }
}

:root[data-theme='dark'] {
  --bg:        #1e1e20;
  --surface:   #171718;
  --title:     #e5e5e5;
  --prose:     #b0c7e1;
  --muted:     #9a9ea3;
  --rule:      #2c2c2e;
  --link:      #69aec0;
  --link-hover:#8fc9d8;
  --accent:    #65b687;
  --accent-ink:#65b687;
  --select:    #3d5a60;
  --code-bg:   #2a2a2d;
  --code-line: #3f3f44;
  --code-track:#333338;
  --code-thumb:#4a4a52;
  --code-text: #7acb9b;
  --lift:      0 1px 2px rgba(0, 0, 0, 0.4),
               0 10px 24px -12px rgba(0, 0, 0, 0.65);
  --lift-edge: inset 0 1px 0 rgba(255, 255, 255, 0.055);
}

/* ink — the original palette this site started from, before Tidepool: a cool
   near-black ground with warm off-white writing, a pale blue link and an ochre
   accent. Kept as a third pinned theme for comparison. Faithful to the original
   in one place the rest of the site has since moved on from: code is BLUE here,
   not green — green-for-code is a Tidepool rule, and the point of this theme is
   to show what the site looked like before that rule existed.
   Ratios vs #14161A noted per token. */
:root[data-theme='ink'] {
  --bg:        #14161a;
  --surface:   #1c1f25;
  --title:     #f5f3ee;  /* 16.3 AAA */
  --prose:     #e6e3dd;  /* 14.1 AAA */
  --muted:     #9b968d;  /*  6.2 AA  */
  --rule:      #2e3239;
  --link:      #8fc2de;  /*  9.4 AAA */
  --link-hover:#b9dcef;  /* 12.6 AAA */
  --accent:    #c8a978;  /*  8.1 AAA ochre — decorative rules */
  --accent-ink:#c8a978;  /*  8.1 AAA */
  --select:    #2b3a44;
  --code-bg:   #22262e;  /* lighter than the ground, as elsewhere */
  --code-line: #343a44;
  --code-track:#2b303a;
  --code-thumb:#454c58;
  --code-text: #aac8e4;  /*  8.7 AAA the original's blue */
  --lift:      0 1px 2px rgba(0, 0, 0, 0.45),
               0 10px 24px -12px rgba(0, 0, 0, 0.7);
  --lift-edge: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

::selection { background: var(--select); color: var(--title); }

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--prose);
  font-family: var(--font-body);
  font-size: clamp(1.125rem, 1.04rem + 0.35vw, 1.25rem);  /* +1pt */
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: 1rem; top: 1rem;
  z-index: 10;
  background: var(--surface);
  color: var(--title);
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-family: var(--font-ui);
}

a { color: var(--link); text-underline-offset: 0.15em; text-decoration-thickness: 1px; }
a:hover { color: var(--link-hover); }

header.site, footer.site, main {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: 1.25rem;
}

header.site {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 2rem 0;
  font-family: var(--font-ui);
  font-size: 0.875rem;
}

.wordmark {
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  color: var(--title);
}
.wordmark:hover { color: var(--link); }

header.site nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}
header.site nav a { color: var(--muted); text-decoration: none; }
header.site nav a:hover { color: var(--link); text-decoration: underline; }

/* Theme control. Hidden until the script un-hides it, so a no-JS reader is not
   offered a button that cannot work. */
.theme-toggle[hidden] { display: none; }
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 2px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.theme-toggle:hover {
  color: var(--link);
  border-color: var(--link);
  box-shadow: var(--lift-edge), var(--lift);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}
.theme-toggle svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* one icon at a time, chosen by the stored preference */
.theme-toggle svg { display: none; }
[data-theme-pref='system'] .theme-toggle .i-system,
[data-theme-pref='light']  .theme-toggle .i-light,
[data-theme-pref='dark']   .theme-toggle .i-dark,
[data-theme-pref='ink']    .theme-toggle .i-ink { display: block; }

main { padding-block: 3rem 4rem; }

/* --- home --- */

.lede h1 {
  color: var(--title);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: clamp(2rem, 1.6rem + 1.6vw, 2.75rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 0.75rem;
}
.lede p { margin: 0 0 0.75rem; }
.lede .sub { font-family: var(--font-ui); font-size: 0.9375rem; color: var(--muted); }
.lede .sub a { color: var(--link); }

.writing {
  margin-top: 3.5rem;
  border-top: 2px solid var(--rule);
  padding-top: 1.5rem;
}
.writing h2 {
  color: var(--prose);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 600;
  margin: 0 0 1.25rem;
}

ul.posts { list-style: none; margin: 0; padding: 0; }
ul.posts li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1rem;
  padding-block: 0.6rem;
}
ul.posts li + li { border-top: 1px solid var(--rule); }
ul.posts a { color: var(--link); text-decoration: none; font-size: 1.0625rem; }
ul.posts a:hover { text-decoration: underline; }
ul.posts time,
ul.posts .empty {
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  color: var(--muted);
  margin-left: auto;
  white-space: nowrap;
}
ul.posts .empty { margin-left: 0; }

/* --- post --- */

.post-head { margin-bottom: 2.5rem; }
.post-head h1 {
  color: var(--title);
  font-family: var(--font-ui);
  font-weight: 700;
  border-bottom: 3px solid var(--accent);   /* heaviest rule on the page */
  padding-bottom: 0.55rem;
  font-size: clamp(1.875rem, 1.5rem + 1.5vw, 2.5rem);
  line-height: 1.18;
  letter-spacing: -0.015em;
  margin: 0 0 0.6rem;
  text-wrap: balance;
}
/* the eyebrow — colbykauk.com puts the colour here, above a near-white title */
.post-head .eyebrow {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--prose);
  margin: 0 0 0.6rem;
}

.post h2 {
  color: var(--prose);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 1.25rem;
  line-height: 1.3;
  letter-spacing: -0.005em;
  margin: 3rem 0 0.9rem;
}

.post p { margin: 0 0 1.25rem; }
.post strong, .post-head h1 strong { color: var(--title); font-weight: 600; }
.post ul, .post ol { margin: 0 0 1.25rem; padding-left: 1.25rem; }
.post li { margin-bottom: 0.75rem; }
.post li > strong:first-child { color: var(--title); }

.post blockquote {
  margin: 1.75rem 0;
  padding: 0.85rem 1.15rem;
  border-left: 4px solid var(--accent);
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--lift-edge), var(--lift);          /* matches the code blocks — one radius on the page */
  font-size: 0.9375em;
}
.post blockquote p:last-child { margin-bottom: 0; }

/* Tidepool's own split, applied: green family = data, blue family = structure.
   Inline code is a value (a filename, a symbol) -> green.
   Code blocks are structure -> blue. */
.post code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  color: var(--code-text);
  background: var(--code-bg);
  padding: 0.12em 0.35em;
  border-radius: 3px;
  overflow-wrap: anywhere;
  word-break: break-word;
}
/* Code blocks. The copy control sits in a left gutter, so the block is a
   positioned wrapper and <pre> carries padding to clear it.
   The border, radius and background live on the WRAPPER, not on <pre>. <pre> is
   the scroll container, and a scroll container paints its scrollbar inside its
   own padding box — so with the radius on <pre>, the scrollbar's square ends sat
   on top of the rounded corners. Clipping happens on the wrapper instead. */
.code-block {
  position: relative;
  margin: 0 0 1.5rem;
  background: var(--code-bg);
  border: 2px solid var(--code-line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--lift-edge), var(--lift);
}
.post pre {
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0.95rem 1.1rem 0.95rem 3.1rem;
  overflow-x: auto;
  margin: 0;
  scrollbar-width: thin;                                   /* Firefox */
  scrollbar-color: var(--code-thumb) var(--code-track);    /* Firefox */
}
.post pre::-webkit-scrollbar { height: 10px; }
.post pre::-webkit-scrollbar-track {
  background: var(--code-track);
  border-radius: 0 0 12px 12px;   /* follows the wrapper's 14px minus its 2px border */
}
.post pre::-webkit-scrollbar-thumb {
  background: var(--code-thumb);
  border-radius: 999px;
  border: 2px solid var(--code-track);
}
.post pre::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.copy-btn {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  border: 2px solid var(--code-line);
  border-radius: 9px;
  background: var(--code-bg);
  color: var(--muted);
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.copy-btn:hover {
  color: var(--accent-ink);
  border-color: var(--accent-ink);
  box-shadow: var(--lift-edge), var(--lift);
}
.copy-btn:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.copy-btn svg {
  width: 0.95rem; height: 0.95rem;
  fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.copy-btn .i-done { display: none; }
.copy-btn.is-done { color: var(--accent-ink); border-color: var(--accent-ink); }
.copy-btn.is-done .i-copy { display: none; }
.copy-btn.is-done .i-done { display: block; }
.copy-btn[hidden] { display: none; }
.post pre code {
  background: none;
  padding: 0;
  font-size: 0.875rem;
  color: var(--code-text);
}

/* Tables scroll inside their wrapper; the page never scrolls sideways.
   Radius lives on the wrapper with overflow:hidden, same as the code blocks —
   but the wrapper carries NO border of its own, because the cells' own 2px
   borders already draw the outer edge and a wrapper border would double it. */
.post .table-wrap {
  max-width: 100%;
  overflow: auto;
  border-radius: 14px;
  margin: 0 0 1.5rem;
  box-shadow: var(--lift-edge), var(--lift);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--code-thumb) var(--code-track);
}
.post .table-wrap::-webkit-scrollbar { height: 10px; }
.post .table-wrap::-webkit-scrollbar-track { background: var(--code-track); }
.post .table-wrap::-webkit-scrollbar-thumb {
  background: var(--code-thumb);
  border-radius: 999px;
  border: 2px solid var(--code-track);
}
.post table {
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  line-height: 1.5;
  margin: 0;
  white-space: normal;
}
.post th, .post td {
  border: 2px solid var(--rule);
  padding: 0.5rem 0.7rem;
  text-align: left;
  vertical-align: top;
  min-width: 8rem;
}
.post th { background: var(--surface); font-weight: 600; }

.post hr {
  border: 0;
  border-top: 2px solid var(--rule);
  margin: 3rem 0;
}

.post > p:last-child em { color: var(--muted); }

footer.site {
  border-top: 2px solid var(--rule);
  padding-block: 1.5rem 3rem;
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  color: var(--muted);
}
footer.site p { margin: 0; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle, .copy-btn { transition: none; }
}
