/*
 * Main site theme - clean editorial/research notebook.
 *
 * This keeps the small personal-site footprint and the self-hosted
 * font setup, but drops the previous ornamental framing.
 * Legacy token names are intentionally preserved because a few pages
 * define small inline styles that still read them.
 *
 * On top sits a restrained, texture-first glitchpop layer. It uses no
 * extra colours: the glitch lives in form, drawn in the page's own
 * inks. That means 1-bit dither patterns (--dither-*), pixel-stepped
 * marks, the VT323 bitmap face, and brief one-shot slice shifts where a
 * band of the ink slides sideways (the name, the portrait).
 */

@font-face {
  font-family: 'Spectral';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/assets/fonts/spectral-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Spectral';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/assets/fonts/spectral-latin-600.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Pixel/CRT face for glitchpop details (tags, the links-page door). */
@font-face {
  font-family: 'VT323';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/assets/fonts/vt323-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
                 U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F,
                 U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light dark;

  --paper: #fbfaf7;
  --surface: #f1f4f1;
  --surface-strong: #e8ede8;
  --ink: #24272b;
  --ink-faded: #657078;
  --rule: rgba(36, 39, 43, 0.16);
  --rule-strong: rgba(36, 39, 43, 0.28);
  --blue: #1e6d87;
  --green: #4f7358;
  --rust: #a75d42;
  --shadow: rgba(36, 39, 43, 0.07);

  --parchment: var(--paper);
  --parchment-dark: var(--surface);
  --moss: var(--green);
  --dried-lavender: var(--blue);
  --candlelight: var(--rust);
  --ember: var(--rust);
  --frame: var(--rule);
  --frame-corner: var(--rule-strong);
  --underline: rgba(30, 109, 135, 0.42);
  /* links sit close to the ink: tinted, never underlined at rest */
  --link-ink: #2b5866;

  --background-color: var(--paper);
  --text-color: var(--ink);
  --link-color: var(--link-ink);
  --accent: var(--rust);
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Spectral", Georgia, serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --pixel: "VT323", var(--mono);

  /* 1-bit textures, drawn in currentColor so the element picks the ink
   * with `color`. Use on a 2px x 2px tile: 50% is a checkerboard, 25% is
   * one lit pixel in four. */
  --dither-50: repeating-conic-gradient(currentColor 0 25%, transparent 0 50%);
  --dither-25: conic-gradient(from 90deg at 1px 1px, transparent 75%, currentColor 0);

  /* link direction arrows, used as masks so they take any colour */
  --arrow-out: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3.5 2.5h6v6M9.5 2.5l-7 7' fill='none' stroke='%23000' stroke-width='1.6'/%3E%3C/svg%3E");
  --arrow-down: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M6 1.5v8.5M2.5 6.5L6 10l3.5-3.5' fill='none' stroke='%23000' stroke-width='1.6'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17191b;
    --surface: #202327;
    --surface-strong: #282d31;
    --ink: #e9e5dc;
    --ink-faded: #a9b0b4;
    --rule: rgba(233, 229, 220, 0.16);
    --rule-strong: rgba(233, 229, 220, 0.28);
    --blue: #76bfd4;
    --green: #9ab986;
    --rust: #d18a64;
    --shadow: rgba(0, 0, 0, 0.22);
    --underline: rgba(118, 191, 212, 0.46);
    --link-ink: #b3d0d7;
  }
}

* {
  box-sizing: border-box;
}

html {
  background: var(--background-color);
  scrollbar-width: thin;
  scrollbar-color: var(--ink-faded) transparent;
  min-height: 100%;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--background-color);
  color: var(--text-color);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.68;
  text-rendering: optimizeLegibility;
}

.container {
  width: min(90%, 660px);
  margin: 0 auto;
}

header {
  margin: 34px 0 28px;
}

.menu {
  border-bottom: 0;
  padding-bottom: 12px;
}

.menu ul {
  display: flex;
  justify-content: flex-end;
  gap: 1.35rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.menu a {
  border: 0;
  color: var(--ink-faded);
  font-family: var(--sans);
  font-size: 0.86rem;
  letter-spacing: 0.01em;
  text-decoration: none;
}

.menu a:hover,
.menu a.nav-dot {
  color: var(--text-color);
}

.menu a:hover {
  background: none;
}

/* current page: a small dithered square */
.menu a.nav-dot::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 0.45em;
  vertical-align: 0.1em;
  color: var(--text-color);
  background: var(--dither-50) 0 0 / 2px 2px;
}

main {
  min-height: 56vh;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-color);
  margin: 0 0 0.45em;
}

/* same serif as the text, one size step up from the body rather than a
 * poster headline */
h1 {
  margin-top: 1.1em;
  font-family: var(--serif);
  font-size: clamp(2rem, 5.4vw, 2.5rem);
  font-weight: 400;
  line-height: 1.12;
  letter-spacing: -0.01em;
}

/* section headings trail off into a dithered rule that thins out in
 * hard steps */
main > h2 {
  display: flex;
  align-items: center;
  gap: 0.9em;
}

main > h2::after {
  content: "";
  flex: 1;
  height: 2px;
  color: var(--ink-faded);
  background: var(--dither-50) 0 0 / 2px 2px;
  -webkit-mask-image: linear-gradient(90deg,
    #000 0 30%, rgba(0, 0, 0, 0.5) 30% 65%, rgba(0, 0, 0, 0.2) 65%);
  mask-image: linear-gradient(90deg,
    #000 0 30%, rgba(0, 0, 0, 0.5) 30% 65%, rgba(0, 0, 0, 0.2) 65%);
}

h2 {
  margin-top: 2.1em;
  color: var(--ink-faded);
  font-family: var(--sans);
  font-size: 0.94rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h3 {
  margin-top: 1.6em;
  font-family: var(--sans);
  font-size: 1rem;
}

p, ul, ol {
  margin: 0 0 1em;
}

strong, b {
  font-weight: 600;
}

/* Links are marked by a tint only. On hover or focus they turn to ink
 * over a 1-bit dotted underline (one pixel on, two off). */
a {
  color: var(--link-color);
  text-decoration: none;
  transition: color 0.18s ease;
}

a:hover,
a:focus-visible {
  color: var(--text-color);
  background: repeating-linear-gradient(90deg,
    currentColor 0 1px, transparent 1px 3px) left bottom / 100% 1px no-repeat;
}

::selection {
  background: color-mix(in srgb, var(--ink) 15%, transparent);
}

main img {
  max-width: 100%;
  height: auto;
}

blockquote {
  margin: 1.6em 0;
  padding-left: 1em;
  border-left: 3px solid var(--rule-strong);
  color: var(--ink-faded);
}

hr {
  height: 1px;
  margin: 2.4em 0;
  border: 0;
  background: linear-gradient(90deg, var(--rule-strong), transparent);
}

table {
  width: 100%;
  margin: 1.5em 0;
  border-collapse: collapse;
  font-size: 0.94em;
}

th {
  color: var(--ink-faded);
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-align: left;
  text-transform: uppercase;
}

th, td {
  padding: 0.5em 0.55em;
  border-bottom: 1px solid var(--rule);
}

#line-art-canvas-container {
  position: relative;
  margin: 1.7em 0 1.4em;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Crop marks at the frame corners. The frame (sized inline in
 * index.html) is the drawn canvas plus 7px a side, so the marks hug the
 * picture. */
#line-art-canvas-container::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: var(--ink-faded);
  opacity: 0.7;
  background:
    linear-gradient(currentColor, currentColor) top left / 10px 1px,
    linear-gradient(currentColor, currentColor) top left / 1px 10px,
    linear-gradient(currentColor, currentColor) top right / 10px 1px,
    linear-gradient(currentColor, currentColor) top right / 1px 10px,
    linear-gradient(currentColor, currentColor) bottom left / 10px 1px,
    linear-gradient(currentColor, currentColor) bottom left / 1px 10px,
    linear-gradient(currentColor, currentColor) bottom right / 10px 1px,
    linear-gradient(currentColor, currentColor) bottom right / 1px 10px;
  background-repeat: no-repeat;
}

#line-art-canvas {
  display: block;
  pointer-events: none;
  touch-action: none;
  mix-blend-mode: multiply;
  opacity: 0.9;
  filter: grayscale(1) contrast(1.04);
  background-color: transparent;
}

/* Hovering the portrait (class set briefly by script) runs the strokes
 * through #slice-shift, an inline SVG filter that slides a few
 * horizontal bands sideways, reseeded every few frames. */
#line-art-canvas-container.is-glitching #line-art-canvas {
  filter: url(#slice-shift) grayscale(1) contrast(1.04);
}

@media (prefers-color-scheme: dark) {
  #line-art-canvas,
  noscript img {
    mix-blend-mode: normal;
    opacity: 1;
    background-color: #f2efe7;
  }
}

main > ul {
  list-style: none;
  padding-left: 0;
}

main > ul > li {
  position: relative;
  padding: 0.22em 0 0.22em 1.05em;
}

/* square pixel bullets; the hovered row's pixel breaks into a dither
 * and slips a pixel */
main > ul > li::before {
  content: "";
  position: absolute;
  top: 0.98em;
  left: 0;
  width: 6px;
  height: 6px;
  color: var(--text-color);
  background: var(--ink-faded);
}

main > ul > li:hover::before {
  background: var(--dither-50) 0 0 / 2px 2px;
  transform: translateX(1px);
}

/* Contact rows: a quiet label column, then the link itself. Each link
 * ends in a direction arrow (up-right leaves the site, down downloads)
 * so it reads as a link at a glance without an underline. */
main > ul.contact > li {
  display: flex;
  align-items: baseline;
  padding-left: 0;
}

main > ul.contact > li::before {
  content: none;
}

.contact-label {
  flex: 0 0 9.4rem;
  color: var(--ink-faded);
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: color 0.15s ease;
}

.contact li:hover .contact-label {
  color: var(--text-color);
}

.contact a::after {
  content: "";
  display: inline-block;
  width: 0.62em;
  height: 0.62em;
  margin-left: 0.34em;
  vertical-align: 0.02em;
  background: var(--ink-faded);
  -webkit-mask: var(--arrow-out) center / contain no-repeat;
  mask: var(--arrow-out) center / contain no-repeat;
  transition: transform 0.16s steps(2, end), background-color 0.16s steps(1, end);
}

.contact a.is-download::after {
  -webkit-mask-image: var(--arrow-down);
  mask-image: var(--arrow-down);
}

.contact a:hover::after,
.contact a:focus-visible::after {
  background: var(--text-color);
  transform: translate(2px, -2px);
}

.contact a.is-download:hover::after,
.contact a.is-download:focus-visible::after {
  transform: translateY(2px);
}

pre, code {
  font-family: var(--mono);
  font-size: 0.9em;
}

pre {
  margin: 1.4em 0;
  padding: 1em;
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--surface);
  line-height: 1.55;
}

code {
  padding: 0.1em 0.28em;
  border-radius: 3px;
  background: var(--surface);
}

pre code {
  padding: 0;
  background: transparent;
}

input, select, textarea {
  width: 100%;
  padding: 0.5em 0.6em;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-color);
  font: inherit;
}

input[type=submit] {
  width: auto;
  cursor: pointer;
}

input[type=submit]:hover {
  border-color: var(--accent);
}

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

.highlight .c, .highlight .cm, .highlight .c1, .highlight .cs {
  color: var(--ink-faded);
  font-style: italic;
}
.highlight .k, .highlight .kc, .highlight .kd, .highlight .kn,
.highlight .kp, .highlight .kr, .highlight .nf, .highlight .nc {
  color: var(--green);
}
.highlight .s, .highlight .sb, .highlight .sc, .highlight .sd,
.highlight .s2, .highlight .se, .highlight .sh, .highlight .si,
.highlight .sx, .highlight .s1 {
  color: var(--blue);
}
.highlight .m, .highlight .mf, .highlight .mh, .highlight .mi,
.highlight .mo, .highlight .il, .highlight .nt {
  color: var(--rust);
}

/* Glitch text: the text is split into a top and a bottom slice (two
 * copies from data-text, clipped to complementary bands) that slide
 * sideways in a few hard steps while the original hides. On one frame
 * the lower slice inverts into a solid block. `.is-glitching` fires it
 * once: set in the markup for the load-time shift on the name, re-added
 * by a small script on hover. */
.glitch {
  position: relative;
  display: inline-block;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  color: var(--text-color);
  opacity: 0;
  pointer-events: none;
}

.glitch.is-glitching {
  animation: glitch-hide 0.44s steps(1, end) 0.2s;
}

.glitch.is-glitching::before {
  animation: slice-top 0.44s steps(1, end) 0.2s;
}

.glitch.is-glitching::after {
  animation: slice-bottom 0.44s steps(1, end) 0.2s;
}

@keyframes glitch-hide {
  0%, 99% { color: transparent; }
}

@keyframes slice-top {
  0% { opacity: 1; clip-path: inset(0 0 58% 0); transform: translateX(-4px); }
  25% { opacity: 1; clip-path: inset(0 0 30% 0); transform: translateX(3px); }
  50% { opacity: 1; clip-path: inset(0 0 66% 0); transform: translateX(-2px); }
  75% { opacity: 1; clip-path: inset(0 0 45% 0); transform: translateX(1px); }
  99% { opacity: 1; clip-path: inset(0 0 45% 0); transform: none; }
  100% { opacity: 0; }
}

@keyframes slice-bottom {
  0% { opacity: 1; clip-path: inset(42% 0 0 0); transform: translateX(3px);
       color: var(--text-color); background: transparent; }
  25% { opacity: 1; clip-path: inset(70% 0 0 0); transform: translateX(-1px);
        color: var(--text-color); background: transparent; }
  50% { opacity: 1; clip-path: inset(34% 0 0 0); transform: translateX(5px);
        color: var(--background-color); background: var(--text-color); }
  75% { opacity: 1; clip-path: inset(55% 0 0 0); transform: translateX(-2px);
        color: var(--text-color); background: transparent; }
  99% { opacity: 1; clip-path: inset(55% 0 0 0); transform: none;
        color: var(--text-color); background: transparent; }
  100% { opacity: 0; }
}

/* Pixel tag for small status words, with a blinking block cursor. */
.pixel-tag {
  margin-right: 0.3em;
  color: var(--ink-faded);
  font-family: var(--pixel);
  font-size: 1.12em;
  letter-spacing: 0.03em;
  line-height: 1;
  text-transform: uppercase;
}

.pixel-tag::after {
  content: "";
  display: inline-block;
  width: 0.42em;
  height: 0.72em;
  margin-left: 0.12em;
  vertical-align: -0.02em;
  background: currentColor;
  animation: cursor-blink 1.1s steps(1, end) infinite;
}

@keyframes cursor-blink {
  50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .glitch,
  .glitch::before,
  .glitch::after,
  .pixel-tag::after {
    animation: none !important;
  }

  #line-art-canvas-container.is-glitching #line-art-canvas {
    filter: grayscale(1) contrast(1.04);
  }
}

footer {
  margin: 62px auto 30px;
  padding-top: 14px;
  border-top: 0;
  color: var(--ink-faded);
  font-family: var(--sans);
  font-size: 0.82rem;
  text-align: right;
}

@media only screen and (max-width: 600px) {
  body {
    font-size: 15px;
  }

  .container {
    width: min(92%, 660px);
  }

  .menu ul {
    gap: 1rem;
  }

  h1 {
    font-size: 2rem;
  }
}
