/* nebulo design system
 *
 * One ink on one background. Everything is set in mono and every level of emphasis is the ink at an
 * alpha step, so a page (or a single card) is re-themed by changing two variables:
 *
 *   --ink, --bg       space-separated RGB channels, e.g. --ink: 255 207 138
 *
 * Set them on :root, or on any element with [data-look] (the ink levels are re-derived there).
 * Entries in content/*.js set them through their `look`, see js/site.js.
 *
 * Tokens
 *   --ink-1 .. --ink-6   ink at full, text, label, caption, faint, rule strength
 *   --mono, --heavy      type families (heavy is what the reliefs are carved from)
 *   --fs-xs .. --fs-xl   type scale
 *   --track, --track-w   letter spacing (labels, captions)
 *   --sp-1 .. --sp-7     spacing
 *   --blink              the caret's blink period
 *
 * Components
 *   .n-bar        top bar: .n-brand (bracketed, like the links) on the left, .n-links on the right
 *   .n-links      [ bracketed ] links; hover / focus inverts; .soon for a dimmed placeholder;
 *                 aria-current="page" for the active one
 *   .n-caption    the HUD voice: small, tracked, dim
 *   .n-caret      a blinking block caret
 *   .n-frame      the cursor's corner brackets around a box; they close in on hover / focus
 *   .n-tag        a small [tag]; .n-tags a row of them
 *   .n-rule       a dashed glyph rule
 *   .n-title      a page's title; .n-lede the line under it
 *   .n-prose      long-form text (rendered markdown)
 *   .n-linkrow    a row of [ bracketed ] links in running text
 *   n-relief      a carved ASCII header (js/relief.js)
 *   n-portrait    a picture set in glyphs, that takes its colours back when held (js/portrait.js)
 *
 * Page patterns (js/site.js, js/about.js)
 *   .n-hero       full-width relief header      .n-main     the frame: one column for every page
 *   .n-head       the line under the hero       .n-log      the dated list (blog and projects)
 *   .n-log-pics   a log whose entries have covers: beside the hovered row, or in each row on touch
 *   .n-viewer     the image viewer (js/viewer.js); .n-zoom a picture that opens it
 *   .n-entry      one entry: meta | title, text | contents
 *   .n-pager      older / newer links           .n-about    the about page
 */

:root, [data-look] {
  --ink-1: rgb(var(--ink) / 1);
  --ink-2: rgb(var(--ink) / .62);
  --ink-3: rgb(var(--ink) / .45);
  --ink-4: rgb(var(--ink) / .32);
  --ink-5: rgb(var(--ink) / .22);
  --ink-6: rgb(var(--ink) / .12);
  --paper: rgb(var(--bg));
}

:root {
  --ink: 255 255 255;
  --bg: 0 0 0;

  --mono: Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --heavy: "Arial Black", "Arial Bold", Gadget, "Helvetica Neue", Arial, sans-serif;

  --fs-xs: 11px;
  --fs-s: 12px;
  --fs-m: 14px;
  --fs-l: 18px;
  --fs-xl: 24px;
  --track: .06em;
  --track-w: .08em;

  --sp-1: 2px;
  --sp-2: 6px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 48px;
  --sp-7: 96px;

  --blink: 1.1s;
  --measure: 72ch;   /* prose */
  --frame: 132ch;    /* the page column (see page patterns) */
  --rail: 12ch;      /* its left track: dates and meta */
  --gutter: 2ch;

  color-scheme: dark;
}

/* ---------- base (pages that scroll: blog, projects) ---------- */

.n-page {
  margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink-2);
  font: var(--fs-m)/1.7 var(--mono);
  -webkit-text-size-adjust: 100%;
}
.n-page ::selection { background: var(--ink-1); color: var(--paper); }
.n-page a { color: var(--ink-1); text-decoration: underline; text-decoration-color: var(--ink-4); text-underline-offset: 3px; }
.n-page a:hover { text-decoration-color: var(--ink-1); }
.n-page :focus-visible { outline: 1px solid var(--ink-2); outline-offset: 3px; }

.n-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- top bar ---------- */

.n-bar {
  display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3); font: var(--fs-s)/1 var(--mono); letter-spacing: var(--track);
}
.n-brand { flex: none; padding: var(--sp-2); color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.n-brand::before { content: '[ '; opacity: .4; }
.n-brand::after { content: ' ]'; opacity: .4; }
.n-page a.n-brand { color: var(--ink-2); text-decoration: none; }
a.n-brand:hover, a.n-brand:focus-visible { color: var(--paper) !important; background: var(--ink-1); outline: none; }
a.n-brand:hover::before, a.n-brand:hover::after, a.n-brand:focus-visible::before, a.n-brand:focus-visible::after { opacity: 1; }

/* ---------- [ bracketed ] links ---------- */

.n-links { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-1); font: var(--fs-s)/1 var(--mono); letter-spacing: var(--track); }
.n-links a, .n-links .soon, :is(a, button).n-link {
  color: var(--ink-2); text-decoration: none; padding: var(--sp-2); white-space: nowrap;
}
button.n-link { background: none; border: 0; border-radius: 0; margin: 0; cursor: pointer; }
.n-links a::before, .n-links .soon::before, :is(a, button).n-link::before { content: '[ '; opacity: .4; }
.n-links a::after,  .n-links .soon::after,  :is(a, button).n-link::after  { content: ' ]'; opacity: .4; }
.n-links a:hover, .n-links a:focus-visible, :is(a, button).n-link:hover, :is(a, button).n-link:focus-visible { color: var(--paper); background: var(--ink-1); outline: none; }
.n-links a:hover::before, .n-links a:hover::after, .n-links a:focus-visible::before, .n-links a:focus-visible::after,
:is(a, button).n-link:hover::before, :is(a, button).n-link:hover::after, :is(a, button).n-link:focus-visible::before, :is(a, button).n-link:focus-visible::after { opacity: 1; }
.n-links a[aria-current="page"]:not(:hover, :focus-visible) { color: var(--ink-1); }   /* hover / focus still invert */
.n-links a[aria-current="page"]::before, .n-links a[aria-current="page"]::after { opacity: 1; }
.n-links .soon { color: var(--ink-5); cursor: default; }
:is(a, button).n-link { display: inline-block; font: var(--fs-s)/1 var(--mono); letter-spacing: var(--track); }
@media (pointer: coarse) { .n-links a, .n-links .soon, .n-brand, :is(a, button).n-link { padding: 11px 7px; } }
/* narrow: the links take their own row under the brand, left-aligned with it (and the page's column) */
@media (max-width: 560px) {
  .n-bar { flex-wrap: wrap; row-gap: 0; }
  .n-links { justify-content: flex-start; }
}
@media (max-width: 420px) {   /* tighter: one size down, closer brackets, so the brand and the links share a row */
  .n-bar, .n-bar .n-links { font-size: var(--fs-xs); letter-spacing: 0; }
  .n-bar :is(.n-brand, .n-links a, .n-links .soon) { padding-inline: 4px; }
  .n-bar :is(.n-brand, .n-links a, .n-links .soon)::before { content: '['; }
  .n-bar :is(.n-brand, .n-links a, .n-links .soon)::after { content: ']'; }
}

/* ---------- small type ---------- */

.n-caption { font: var(--fs-xs)/1.4 var(--mono); letter-spacing: var(--track-w); color: var(--ink-4); }

.n-caret { opacity: .7; animation: n-blink var(--blink) steps(1) infinite; }
@keyframes n-blink { 50% { opacity: 0; } }

.n-tag { font: var(--fs-xs)/1 var(--mono); letter-spacing: var(--track-w); color: var(--ink-3); white-space: nowrap; }
.n-tag::before { content: '['; opacity: .6; }
.n-tag::after { content: ']'; opacity: .6; }

.n-tags { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-2); }

.n-rule { border: 0; height: 1em; margin: var(--sp-6) 0; overflow: hidden; color: var(--ink-5); font: var(--fs-s)/1 var(--mono); }
.n-rule::before { content: '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'; white-space: pre; }

/* ---------- frame: the cursor's corner brackets ---------- */

.n-frame {
  --l: 10px; --c: var(--ink-4);
  position: relative; padding: var(--sp-4);
  background:
    linear-gradient(var(--c) 0 0) top left / var(--l) 1px,
    linear-gradient(var(--c) 0 0) top left / 1px var(--l),
    linear-gradient(var(--c) 0 0) top right / var(--l) 1px,
    linear-gradient(var(--c) 0 0) top right / 1px var(--l),
    linear-gradient(var(--c) 0 0) bottom left / var(--l) 1px,
    linear-gradient(var(--c) 0 0) bottom left / 1px var(--l),
    linear-gradient(var(--c) 0 0) bottom right / var(--l) 1px,
    linear-gradient(var(--c) 0 0) bottom right / 1px var(--l);
  background-repeat: no-repeat;
  transition: background-size .18s cubic-bezier(.2, .7, .2, 1);
}
.n-frame:is(:hover, :focus-within) { --c: var(--ink-1); --l: 18px; }

/* ---------- titles ---------- */

.n-title { color: var(--ink-1); font-size: var(--fs-xl); font-weight: normal; line-height: 1.25; margin: 0; }
.n-lede { color: var(--ink-3); margin: var(--sp-3) 0 0; }

/* ---------- prose ---------- */

.n-prose { max-width: var(--measure); color: var(--ink-2); }
.n-prose > :first-child { margin-top: 0; }
.n-prose p, .n-prose ul, .n-prose ol, .n-prose blockquote, .n-prose pre, .n-prose figure { margin: 0 0 1.25em; }
.n-prose h2, .n-prose h3, .n-prose h4 { color: var(--ink-1); font-weight: normal; line-height: 1.3; margin: 2.4em 0 .8em; scroll-margin-top: var(--sp-5); }
.n-prose h2 { font-size: var(--fs-l); }
.n-prose h3, .n-prose h4 { font-size: var(--fs-m); }
.n-prose strong { color: var(--ink-1); font-weight: normal; }
.n-prose em { font-style: normal; color: var(--ink-1); }
.n-prose ul, .n-prose ol { padding-left: 3ch; }
.n-prose ul { list-style: none; }
.n-prose ul > li::before { content: var(--mark, '-'); color: var(--ink-4); display: inline-block; width: 3ch; margin-left: -3ch; }
.n-prose li::marker { color: var(--ink-4); }
.n-prose blockquote { border-left: 1px solid var(--ink-5); padding-left: 2ch; color: var(--ink-3); }
.n-prose code { color: var(--ink-1); }
.n-prose :not(pre) > code { background: var(--ink-6); padding: .1em .5ch; }
.n-prose pre { font-size: var(--fs-s); line-height: 1.55; overflow-x: auto; }
.n-prose pre.n-frame { padding: var(--sp-4) 2ch; }
.n-prose img { max-width: 100%; height: auto; display: block; }
.n-zoom { display: block; max-width: 100%; padding: 0; margin: 0; border: 0; background: none; cursor: zoom-in; }
.n-zoom:focus-visible { outline: 1px solid var(--ink-2); outline-offset: 3px; }
.n-prose figcaption { margin-top: var(--sp-2); }
.n-prose hr { border: 0; }

.n-linkrow { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.n-linkrow .n-link:first-child { margin-left: calc(-1 * var(--sp-2)); }

/* ---------- relief, portrait ---------- */

n-relief, n-portrait { display: block; position: relative; overflow: hidden; background: var(--paper); }
n-relief canvas, n-portrait canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
n-portrait {
  aspect-ratio: 1; touch-action: pan-y;   /* a held finger develops it, a dragged one scrolls */
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}

/* ---------- page patterns ----------
 * Every page is the top bar, a header image, then the frame: a column --frame wide, centred. Lists use the
 * whole frame, with dates in its left track (--rail). Text keeps to --measure, centred under the header
 * like the word in it, with anything about it to its left and its contents to its right.
 */

.n-hero { width: 100%; height: clamp(140px, min(34vh, 44vw), 340px); }
.n-main { max-width: var(--frame); margin: 0 auto; padding: var(--sp-4) var(--sp-4) var(--sp-7); }
.n-head { margin-bottom: var(--sp-5); }   /* a list's first line: its intro */
.n-head > p { margin: 0; }

/* log: date | title, summary, tags; each row in its entry's ink */
.n-log { list-style: none; margin: 0; padding: 0; }
.n-log li { color: var(--ink-2); }
.n-log a {
  display: grid; grid-template-columns: var(--rail) 1fr; column-gap: var(--gutter); row-gap: var(--sp-1);
  padding: var(--sp-3) 0; color: inherit; text-decoration: none; border-top: 1px dashed var(--ink-6);
}
.n-log li:last-child a { border-bottom: 1px dashed var(--ink-6); }
.n-log time { grid-row: span 3; padding-top: .3em; }
.n-log-title { color: var(--ink-1); justify-self: start; }
.n-log-title::before { content: var(--mark, '>') ' '; color: var(--ink-4); }
.n-log-sum { color: var(--ink-3); font-size: var(--fs-s); line-height: 1.6; }
.n-log a:hover .n-log-title, .n-log a:focus-visible .n-log-title { background: var(--ink-1); color: var(--paper); }
.n-log a:hover .n-log-title::before, .n-log a:focus-visible .n-log-title::before { color: var(--paper); }
.n-log a:focus-visible { outline: none; }
@media (max-width: 560px) { .n-log a { grid-template-columns: 1fr; } .n-log time { grid-row: auto; } }

/* log with covers (.n-log-pics). Wide, with a pointer: the text keeps to a column and the hovered row's
   picture shows to its right (.n-log-pic, placed by js/site.js). Otherwise each row shows its own: in a
   track at the right of the row, and on phones floated top right, the text running round it */
.n-logbox { position: relative; }
.n-log-thumb { display: block; width: 100%; height: auto; aspect-ratio: 16 / 10; object-fit: cover; object-position: top; opacity: .85; }
.n-log a:is(:hover, :focus-visible) .n-log-thumb { opacity: 1; }
.n-log-pic {
  --c: var(--ink-1); --l: 18px;
  position: absolute; right: 0; margin: 0; padding: var(--sp-2); pointer-events: none; background-color: var(--paper);
  width: min(520px, calc(100% - var(--rail) - var(--gutter) - 60ch - var(--sp-6)));
  transition: top .2s cubic-bezier(.2, .7, .2, 1);
}
.n-log-pic.n-still { transition: none; }
.n-log-pic img { display: block; width: 100%; height: auto; }
.n-log-pic.n-wipe img { animation: n-wipe .22s steps(8, end); }
@keyframes n-wipe { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0); } }
@media (hover: hover) and (min-width: 1001px) {
  .n-log-pics a { grid-template-columns: var(--rail) minmax(0, 60ch); }
  .n-log-thumb { display: none; }
}
@media not ((hover: hover) and (min-width: 1001px)) {
  .n-log-pic { display: none; }
  .n-log-pics a { grid-template-columns: var(--rail) minmax(0, 1fr) min(30%, 220px); grid-template-rows: auto auto auto 1fr; }
  .n-log-pics a > * { grid-column: 2; }
  .n-log-pics time { grid-column: 1; grid-row: 1 / span 3; }
  .n-log-pics .n-log-thumb { grid-column: 3; grid-row: 1 / span 4; align-self: start; }   /* its height goes to the spare row */
}
@media (max-width: 560px) {
  .n-log-pics a { display: flow-root; }
  .n-log-pics a > :is(time, .n-log-sum) { display: block; margin-bottom: var(--sp-1); }
  .n-log-pics .n-log-title { display: table; margin-bottom: var(--sp-1); }   /* its highlight hugs the name */
  .n-log-pics .n-log-thumb { float: right; width: 38%; margin: .3em 0 var(--sp-2) var(--sp-3); }
  .n-log-pics .n-tags { margin-top: var(--sp-1); }
}

/* one entry: back | title | .   /   meta | text, footer | contents */
.n-entry {
  display: grid; column-gap: var(--sp-6); align-items: start;
  grid-template-columns: minmax(0, 1fr) minmax(0, var(--measure)) minmax(0, 1fr);
  grid-template-areas: "back head share" "meta body toc" "meta foot toc";
}
.n-back { grid-area: back; justify-self: end; align-self: baseline; margin: 0; }
.n-back .n-link { margin-right: calc(-1 * var(--sp-2)); }
.n-entry-share { grid-area: share; justify-self: start; align-self: baseline; margin: 0; }
.n-entry-share .n-link { margin-left: calc(-1 * var(--sp-2)); }
.n-entry-head { grid-area: head; align-self: baseline; margin-bottom: var(--sp-6); }
.n-entry .n-prose { grid-area: body; }
.n-entry-foot { grid-area: foot; }
.n-meta {
  grid-area: meta; justify-self: end; position: sticky; top: var(--sp-5);
  display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-2); text-align: end;
}
.n-meta p { margin: 0; }
.n-meta > :empty { display: none; }
.n-meta .n-tags { justify-content: flex-end; }
.n-meta-links { display: flex; flex-direction: column; align-items: flex-end; margin-right: calc(-1 * var(--sp-2)) !important; }
.n-toc { grid-area: toc; position: sticky; top: var(--sp-5); }
.n-toc:empty { display: none; }
.n-toc ol { list-style: none; margin: var(--sp-2) 0 0; padding: 0; font-size: var(--fs-s); line-height: 1.4; }
.n-toc li { position: relative; margin-bottom: var(--sp-2); }
.n-page .n-toc a { color: var(--ink-4); text-decoration: none; }
.n-page .n-toc a:is(:hover, [aria-current]) { color: var(--ink-1); }
.n-toc a[aria-current]::before { content: var(--mark, '>'); position: absolute; right: 100%; padding-right: 1ch; color: var(--ink-4); }
/* narrower: no contents, the meta keeps a track of its own; one column below 560px */
@media (max-width: 1040px) {
  .n-entry { grid-template-columns: 16ch minmax(0, var(--measure)); justify-content: center; column-gap: var(--sp-5); grid-template-areas: "back share" "head head" "meta body" "meta foot"; }
  .n-entry-share { justify-self: start; }
  .n-toc { display: none; }
}
@media (max-width: 560px) {
  .n-entry { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--sp-3); grid-template-areas: "back share" "head head" "meta meta" "body body" "foot foot"; }
  .n-back { justify-self: start; margin-bottom: var(--sp-5); }
  .n-back .n-link { margin: 0 0 0 calc(-1 * var(--sp-2)); }
  .n-entry-share { justify-self: end; align-self: baseline; }
  .n-entry-share .n-link { margin-right: calc(-1 * var(--sp-2)); }
  .n-entry-head { margin-bottom: var(--sp-3); }
  .n-meta { position: static; justify-self: stretch; flex-flow: row wrap; align-items: baseline; gap: var(--sp-1) var(--sp-3); text-align: start; margin-bottom: var(--sp-5); }
  .n-meta .n-tags { justify-content: flex-start; }
  .n-meta-links { flex: 1 0 100%; flex-direction: row; margin: 0 0 0 calc(-1 * var(--sp-2)) !important; }
}

.n-empty { padding: var(--sp-5) 0; }

.n-pager { display: flex; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.n-pager .n-link { white-space: normal; }
.n-pager .n-link:first-child { margin-left: calc(-1 * var(--sp-2)); }
.n-pager .n-link:last-child:not(:first-child) { margin-right: calc(-1 * var(--sp-2)); }

/* about: the portrait in the header's place, the text centred under it; on wide screens side by side,
   centred in the screen under the bar */
.n-about { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; row-gap: var(--sp-5); }
.n-sitter { width: min(100%, 62vh, 520px); margin: 0; }
.n-sitter figcaption { text-align: center; margin-top: var(--sp-3); }
.n-about-text { width: 100%; max-width: var(--measure); }
.n-about .n-title { margin-bottom: var(--sp-5); }
@media (min-width: 1000px) {
  .n-about {
    grid-template-columns: min(46%, 70vh, 600px) minmax(0, var(--measure)); justify-content: center; align-items: center;
    column-gap: var(--sp-7); min-height: calc(100vh - 7rem); padding-top: 0; padding-bottom: var(--sp-6);
  }
  .n-sitter { width: 100%; }
}

/* the image viewer: the picture on the page's background, its caption under it, the links above */
html.n-viewing { overflow: hidden; }
.n-viewer {
  position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: var(--paper); color: var(--ink-2); font: var(--fs-m)/1.7 var(--mono);
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.n-viewer[open] { display: grid; }
.n-viewer::backdrop { background: transparent; }
.n-viewer ::selection { background: var(--ink-1); color: var(--paper); }
.n-viewer-bar { display: flex; align-items: center; gap: var(--sp-1); padding: var(--sp-3); }
.n-viewer-gap { flex: 1; }
.n-viewer-count { font: var(--fs-xs)/1 var(--mono); letter-spacing: var(--track-w); color: var(--ink-4); padding-left: var(--sp-2); }
.n-viewer-stage { position: relative; display: flex; overflow: hidden; padding: 0 var(--sp-5); }
.n-viewer-pic { display: block; margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; }
.n-viewer-pic.n-big { cursor: zoom-in; }
.n-viewer-stage.n-zoomed { overflow: auto; padding: 0; }
.n-zoomed .n-viewer-pic { max-width: none; max-height: none; cursor: zoom-out; }
.n-viewer-cap { margin: 0; padding: var(--sp-3) var(--sp-4) var(--sp-4); text-align: center; }
@media (max-width: 560px) { .n-viewer-stage { padding: 0; } }

@media (prefers-reduced-motion: reduce) {
  .n-caret { animation: none; }
  .n-frame { transition: none; }
  .n-log-pic.n-wipe img { animation: none; }
  .n-log-pic { transition: none; }
}
