/* Lab: the homepage and portfolio's design language (black stage, point clouds, big display type, mono labels)
   applied to Writing and Contact, with a light and a dark theme. Colours are roles; each has a dark and a light value.
   Dark is the default; light follows the system unless the viewer picks. */
:root {
  --lab-bg: #000; --lab-bg-2: #0e0e0e; --lab-fg: #fff; --lab-fg-2: rgba(255,255,255,0.72); --lab-fg-3: rgba(255,255,255,0.58);
  --lab-line: rgba(255,255,255,0.18); --lab-line-2: rgba(255,255,255,0.4); --lab-fill: #fff; --lab-on-fill: #000;
  --lab-scrim: rgba(0,0,0,0.78); --lab-halo: 0 1px 18px rgba(0,0,0,0.5);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --lab-bg: #f4f2ee; --lab-bg-2: #ebe8e2; --lab-fg: #111; --lab-fg-2: rgba(17,17,17,0.78); --lab-fg-3: #5c5a56;
    --lab-line: rgba(17,17,17,0.16); --lab-line-2: rgba(17,17,17,0.42); --lab-fill: #111; --lab-on-fill: #f4f2ee;
    --lab-scrim: rgba(244,242,238,0.86); --lab-halo: 0 1px 18px rgba(244,242,238,0.7);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --lab-bg: #f4f2ee; --lab-bg-2: #ebe8e2; --lab-fg: #111; --lab-fg-2: rgba(17,17,17,0.78); --lab-fg-3: #5c5a56;
  --lab-line: rgba(17,17,17,0.16); --lab-line-2: rgba(17,17,17,0.42); --lab-fill: #111; --lab-on-fill: #f4f2ee;
  --lab-scrim: rgba(244,242,238,0.86); --lab-halo: 0 1px 18px rgba(244,242,238,0.7);
  color-scheme: light;
}
:root[data-theme="dark"] { color-scheme: dark; }

/* ---- shared lab chrome ---- */
body.lab { --ink: var(--lab-fg); --mute: var(--lab-fg-3); background: var(--lab-bg); color: var(--lab-fg); }
body.lab .masthead { position: fixed; top: 0; left: 0; right: 0; z-index: 6; max-width: none; background: linear-gradient(var(--lab-bg), transparent); }
body.lab .masthead::before, body.lab .sitename { display: none; }
body.lab nav a { color: var(--lab-fg-2); }
body.lab nav a:hover, body.lab nav a[aria-current] { color: var(--lab-fg); border-bottom-color: var(--lab-fg); }
body.lab main { border: 0; max-width: none; padding: 0; }
body.lab .foot { color: var(--lab-fg-3); border-top: 0.5px solid var(--lab-line); max-width: none; }
body.lab a:focus-visible, body.lab button:focus-visible { outline: 2px solid var(--lab-fg); outline-offset: 3px; }

.labbar { position: fixed; right: 1.5rem; top: 4.4rem; z-index: 6; display: flex; gap: 1rem; align-items: center; }
.labbar a { font: 0.68rem/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--lab-fg-2); text-decoration: none;
  border-bottom: 1px solid var(--lab-line-2); padding: 0.55rem 0; }
.labbar a:hover { color: var(--lab-fg); border-color: var(--lab-fg); }
.theme-switch { display: inline-flex; border: 0.5px solid var(--lab-line-2); }
.theme-switch button { font: 0.66rem/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; background: transparent; color: var(--lab-fg-2);
  border: 0; padding: 0 0.7rem; min-height: 30px; cursor: pointer; }
.theme-switch button[aria-pressed="true"] { background: var(--lab-fill); color: var(--lab-on-fill); }
.theme-switch button:hover { color: var(--lab-fg); }
.theme-switch button[aria-pressed="true"]:hover { color: var(--lab-on-fill); }
@media (pointer: coarse) { .theme-switch button { min-height: 44px; padding: 0 0.9rem; } .labbar a { padding: 0.9rem 0; } }

.field { position: fixed; top: 0; right: 0; bottom: 0; width: 52vw; z-index: 0; pointer-events: none; }
.field canvas { width: 100%; height: 100%; display: block; }
.lab-col { position: relative; z-index: 2; width: min(46rem, 50vw); padding: 9rem 0 5rem 1.5rem; }
.lab-kicker { font: 0.72rem/1.4 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--lab-fg-3); margin: 0 0 1rem; }
.lab-col h1 { font: 700 clamp(2.8rem, 6.5vw, 6rem)/0.95 var(--display); letter-spacing: -0.04em; margin: 0 0 1.25rem; }
.lab-col .blurb, .lab-col .note { font-size: clamp(1.05rem, 1.3vw, 1.25rem); line-height: 1.5; color: var(--lab-fg-2); max-width: 36rem; margin: 0 0 2rem; }
.lab-col .blurb a { color: var(--lab-fg); }

/* ---- Writing ---- */
.lab-writing .controls { display: grid; grid-template-columns: none; gap: 0.6rem; margin: 0 0 1.5rem; border: 0; padding: 0; }
.lab-writing .controls .ctl { display: flex; }
.lab-writing .controls .k { padding-top: 0; }
.lab-writing .chip:hover { background: transparent; color: var(--lab-fg); }
.lab-writing .ctl { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; border: 0; padding: 0; }
.lab-writing .ctl .k { font: 0.66rem/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--lab-fg-3); min-width: 3.5rem; }
.lab-writing .chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.lab-writing .chip { font: 0.68rem/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; background: transparent; color: var(--lab-fg-2);
  border: 0.5px solid var(--lab-line-2); padding: 0 0.75rem; min-height: 32px; cursor: pointer; }
.lab-writing .chip.on { background: var(--lab-fill); color: var(--lab-on-fill); border-color: var(--lab-fill); }
.lab-writing .chip span { opacity: 0.7; margin-left: 0.35rem; }
@media (pointer: coarse) { .lab-writing .chip { min-height: 44px; } }
.lab-writing .index { list-style: none; margin: 0; padding: 0; border-top: 0.5px solid var(--lab-line); border-bottom: 0; }
.lab-writing .index li, .lab-writing .index li:last-child { border-bottom: 0.5px solid var(--lab-line); }
.lab-writing .index .row { display: grid; grid-template-columns: 2.5rem minmax(0, 1fr) auto; gap: 0.25rem 1rem; padding: 1.5rem 0; text-decoration: none; color: inherit; }
.lab-writing .row .no, .lab-writing .row time { font: 0.72rem/1.6 var(--mono); letter-spacing: 0.08em; color: var(--lab-fg-3); }
.lab-writing .row .ti b { display: block; font: 700 clamp(1.5rem, 2.6vw, 2.4rem)/1.05 var(--display); letter-spacing: -0.03em; }
.lab-writing .row .ti em { display: block; font-style: normal; color: var(--lab-fg-2); margin-top: 0.5rem; max-width: 34rem; }
.lab-writing .row .tp { grid-column: 2; display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.6rem; }
.lab-writing .row .tag { font: 0.62rem/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--lab-fg-2); border: 0.5px solid var(--lab-line-2); padding: 0.35rem 0.45rem 0.3rem; }
.lab-writing .index .row time { grid-column: 3; grid-row: 1; text-align: right; }
.lab-writing .row:hover .ti b, .lab-writing .row:focus-visible .ti b { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 0.18em; }
.lab-writing .empty { color: var(--lab-fg-2); padding: 1.5rem 0; }

/* ---- Contact ---- */
.lab-contact .primary { display: inline-flex; align-items: center; gap: 0.75rem; min-height: 48px; padding: 0 1.25rem; background: var(--lab-fill); color: var(--lab-on-fill);
  font: 700 clamp(1.05rem, 1.5vw, 1.35rem)/1 var(--display); letter-spacing: -0.01em; text-decoration: none; margin: 0 0 2.5rem; }
.lab-contact .primary:hover { opacity: 0.88; }
.lab-contact .mailrow { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem; margin: 0 0 2.5rem; }
.lab-contact .mailrow .primary { margin: 0; }
.lab-contact .addr a { font: 0.8rem/1 var(--mono); letter-spacing: 0.04em; color: var(--lab-fg-2); text-decoration: none; border-bottom: 1px solid var(--lab-line-2); padding: 0.4rem 0; }
.lab-contact .chan { list-style: none; margin: 0; padding: 0; border-top: 0.5px solid var(--lab-line); max-width: 36rem; }
.lab-contact .chan li { border-bottom: 0.5px solid var(--lab-line); }
.lab-contact .chan a { display: grid; grid-template-columns: 7rem 1fr auto; gap: 1rem; align-items: baseline; padding: 1.1rem 0; color: inherit; text-decoration: none; min-height: 44px; }
.lab-contact .chan .k { font: 0.66rem/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--lab-fg-3); }
.lab-contact .chan b { font: 700 1.15rem/1.2 var(--display); }
.lab-contact .chan small { display: block; color: var(--lab-fg-2); font-size: 0.9rem; margin-top: 0.2rem; }
.lab-contact .chan i { font-style: normal; color: var(--lab-fg-3); }
.lab-contact .chan a:hover b, .lab-contact .chan a:focus-visible b { text-decoration: underline; text-underline-offset: 0.18em; }

/* ---- narrow screens: one column; the field sits behind the top, faint, never behind body text ---- */
@media (max-width: 900px) {
  .field { position: absolute; width: 100vw; height: 46vh; bottom: auto; opacity: 0.55; }   /* scrolls away with the top: never behind the list */
  body.lab { position: relative; }
  body.lab .masthead { background: var(--lab-bg); box-shadow: 0 0.75rem 1rem var(--lab-bg); }   /* solid, so text never runs under the menu */
  .lab-col { width: auto; padding: 38vh 1rem 7rem; }   /* room under the last item for the floating theme bar */
  .labbar { position: absolute; right: 1rem; top: auto; bottom: 1rem; background: var(--lab-bg); padding: 0.35rem 0.5rem; border: 0.5px solid var(--lab-line); }   /* at the foot of the page, not floating over the list */
  .lab-writing .index .row { grid-template-columns: 2rem minmax(0, 1fr); }
  .lab-writing .index .row time { grid-column: 2; grid-row: auto; text-align: left; justify-self: start; }
  .lab-contact .chan a { grid-template-columns: 1fr auto; }
  .lab-contact .chan .k { grid-column: 1 / -1; }
}
@media (max-width: 560px) { body.lab .masthead { padding-left: 4.5rem; padding-right: 1rem; } body.lab .ident { position: absolute; left: 1rem; top: 1.1rem; } body.lab nav { gap: 0.25rem 1rem; justify-content: flex-end; } }

/* ---- the reel, themed ---- */
:root[data-resolved="light"] body.reel-page { background: var(--lab-bg); color: var(--lab-fg); }
:root[data-resolved="light"] body.reel-page .reel-stage { background: var(--lab-bg); }
:root[data-resolved="light"] body.reel-page nav a { color: var(--lab-fg-2); }
:root[data-resolved="light"] .reel-stage .scrim { background: linear-gradient(to top, var(--lab-scrim), rgba(244,242,238,0.3) 38%, rgba(244,242,238,0) 60%), linear-gradient(to bottom, rgba(244,242,238,0.7), rgba(244,242,238,0) 18%); }
:root[data-resolved="light"] .rc { text-shadow: var(--lab-halo); color: var(--lab-fg); }
:root[data-resolved="light"] .rc p, :root[data-resolved="light"] .rc .no, :root[data-resolved="light"] .rc .kind, :root[data-resolved="light"] .rc .label, :root[data-resolved="light"] .rc .hint, :root[data-resolved="light"] .reel-count, :root[data-resolved="light"] .reel-grid { color: var(--lab-fg-2); }
:root[data-resolved="light"] .rc-outro .more { color: var(--lab-fg); border-color: var(--lab-fg); }
:root[data-resolved="light"] .rc-outro .more.fill { background: var(--lab-fill); color: var(--lab-on-fill); }
:root[data-resolved="light"] .reel-page a:focus-visible { outline-color: var(--lab-fg); }

/* ---- the homepage, themed (lab copy) ---- */
html body.lab-home { background: var(--lab-bg); color: var(--lab-fg); }
html body.lab-home .stage { background: var(--lab-bg); }
html body.lab-home nav a { color: var(--lab-fg-2); }
html body.lab-home nav a:hover { color: var(--lab-fg); border-bottom-color: var(--lab-fg); }
html body.lab-home .hb-name, html body.lab-home.home-c .hc-above, html body.lab-home.home-c .hc-below, html body.lab-home.home-c .hc-above .roles { color: var(--lab-fg); }
:root[data-resolved="light"] body.lab-home.home-c .hc-above, :root[data-resolved="light"] body.lab-home.home-c .hc-below {
  text-shadow: 0 0 3px var(--lab-bg), 0 0 10px var(--lab-bg), 0 0 22px var(--lab-bg); }
/* light: the black-backed portrait becomes a spotlit print that dissolves into the paper */
:root[data-resolved="light"] body.lab-home .portrait { -webkit-mask-image: radial-gradient(closest-side, #000 62%, transparent 100%); mask-image: radial-gradient(closest-side, #000 62%, transparent 100%); }
html body.lab-home .labbar { top: auto; bottom: 1.5rem; }

/* home easter egg: the face dissolves and explodes into the portfolio */
.egg-canvas { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 20; pointer-events: none; }
body.egg-go .stage canvas, body.egg-go .hb-name, body.egg-go .hc-above, body.egg-go .hc-below, body.egg-go .masthead, body.egg-go .labbar { transition: opacity 0.6s ease; opacity: 0; }

/* the ZC mark: just the letters in the text colour, no box (black on light, white on dark) */
html body.lab .mark, html body.reel-page .mark { background: transparent; color: var(--lab-fg); width: auto; padding: 0; }

/* Home on iPhone: the one-tap offer to move the particles by tilting the phone (Android needs no tap) */
.tilt-btn { position: absolute; left: 1rem; bottom: 1.5rem; z-index: 6; min-height: 44px; padding: 0 0.9rem; background: var(--lab-bg);
  border: 0.5px solid var(--lab-line); color: var(--lab-fg-2); font: 0.68rem/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; }
.tilt-btn:disabled { opacity: 0.7; }
body.egg-go .tilt-btn { opacity: 0; transition: opacity 0.6s ease; }

/* Writing rows: never the old site's filled hover (white on white here). The title underlines; with a real pointer the
   row also lifts very slightly. Touch gets no sticky hover state at all. */
html body.lab .lab-writing .index .row:hover { background: transparent; color: inherit; }
html body.lab .lab-writing .index .row:hover em { color: var(--lab-fg-2); }
html body.lab .lab-writing .index .row:hover .tag { border-color: var(--lab-line-2); }
@media (hover: hover) and (pointer: fine) { html body.lab .lab-writing .index .row:hover { background: rgba(255,255,255,0.04); } }

/* ---- About ---- */
.lab-about .figs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 2rem 0 0; border-top: 0.5px solid var(--lab-line); }
.lab-about .figs div { padding: 1.25rem 1rem 1.25rem 0; }
.lab-about .figs div + div { padding-left: 1rem; border-left: 0.5px solid var(--lab-line); }
.lab-about .figs dt { font: 700 clamp(2rem, 3.6vw, 3.2rem)/1 var(--display); letter-spacing: -0.04em; }
.lab-about .figs dd { margin: 0.6rem 0 0; font: 0.66rem/1.45 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--lab-fg-3); }
.lab-about section { border-top: 0.5px solid var(--lab-line); padding: 1.75rem 0 2rem; }
.lab-about section h2 { font-weight: 400; }
.lab-about .statement { font: 700 clamp(1.35rem, 2.2vw, 1.9rem)/1.22 var(--display); letter-spacing: -0.02em; margin: 0; max-width: 40rem; }
.lab-about .about-text p { color: var(--lab-fg-2); max-width: 36rem; margin: 0 0 1rem; }
.lab-about .next { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.5rem; margin: 1rem 0 0; }
.lab-about .primary { display: inline-flex; align-items: center; min-height: 48px; padding: 0 1.25rem; background: var(--lab-fill); color: var(--lab-on-fill); text-decoration: none; font-weight: 700; }
.lab-about .primary:hover { opacity: 0.88; }
.lab-about .quiet { font: 0.8rem/1 var(--mono); letter-spacing: 0.04em; color: var(--lab-fg-2); text-decoration: none; border-bottom: 1px solid var(--lab-line-2); padding: 0.9rem 0 0.4rem; }
.lab-about .quiet:hover { color: var(--lab-fg); }
@media (max-width: 900px) { .lab-about .figs { grid-template-columns: 1fr 1fr; } .lab-about .figs div:nth-child(3) { padding-left: 0; border-left: 0; } .lab-about .figs div:nth-child(n+3) { border-top: 0.5px solid var(--lab-line); } }

/* ---- Newsletter ---- */
.lab-nl .blurb { color: var(--lab-fg-2); max-width: 36rem; font-size: 1.05rem; line-height: 1.55; margin: 0 0 2rem; }
.lab-nl .nl-facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0 0 1rem; border-top: 0.5px solid var(--lab-line); }
.lab-nl .nl-facts div { padding: 1.1rem 1rem 1.25rem 0; }
.lab-nl .nl-facts div + div { padding-left: 1rem; border-left: 0.5px solid var(--lab-line); }
.lab-nl .nl-facts dt { font: 0.66rem/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--lab-fg-3); margin-bottom: 0.6rem; }
.lab-nl .nl-facts dd { margin: 0; color: var(--lab-fg); font-size: 0.95rem; line-height: 1.45; }
.lab-nl section { border-top: 0.5px solid var(--lab-line); padding: 1.75rem 0 1.5rem; }
.lab-nl section h2 { font-weight: 400; }
.lab-nl .nl-frame { border: 0.5px solid var(--lab-line-2); max-width: 36rem; overflow: hidden; }
/* Substack's embed is light and can't be styled; it's all greys, so inverting it gives a clean dark version */
.lab-nl .nl-frame iframe { display: block; width: 100%; height: 300px; border: 0; filter: invert(1) hue-rotate(180deg); background: #fff; }
.lab-nl .small { color: var(--lab-fg-2); font-size: 0.9rem; margin: 1rem 0 0; max-width: 36rem; }
.lab-nl .small a { color: var(--lab-fg); }
.lab-nl .sent { list-style: none; margin: 0; padding: 0; max-width: 40rem; }
.lab-nl .sent a { display: grid; grid-template-columns: 7rem 1fr; gap: 1rem; align-items: baseline; padding: 1rem 0; border-bottom: 0.5px solid var(--lab-line); color: inherit; text-decoration: none; min-height: 44px; }
.lab-nl .sent time { font: 0.72rem/1 var(--mono); letter-spacing: 0.08em; color: var(--lab-fg-3); }
.lab-nl .sent b { font: 700 1.15rem/1.25 var(--display); letter-spacing: -0.01em; }
.lab-nl .sent a:hover b, .lab-nl .sent a:focus-visible b { text-decoration: underline; text-underline-offset: 0.18em; }
@media (max-width: 900px) { .lab-nl .nl-facts { grid-template-columns: 1fr 1fr; } .lab-nl .nl-facts div:nth-child(3) { padding-left: 0; border-left: 0; } .lab-nl .nl-facts div:nth-child(n+3) { border-top: 0.5px solid var(--lab-line); } }
@media (max-width: 480px) { .lab-nl .sent a { grid-template-columns: 1fr; gap: 0.35rem; } }
