  :root {
    --bg: #000000;
    --fg: #ffffff;
    --dim: rgba(255, 255, 255, 0.55);
    --mono: "Courier New", Courier, monospace;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #000000; --fg: #ffffff; } }
  :root[data-theme="dark"] { --bg: #000000; --fg: #ffffff; }

  *, *::before, *::after { box-sizing: inherit; }
  html, body { height: 100%; margin: 0; }
  body {
    background-color: var(--bg);
    /* evenly spaced dot grid, centred on the screen */
    background-image: radial-gradient(circle at center, #4f4f4f 0, #4f4f4f 1.4px, transparent 2px);
    background-size: var(--dot-gap, 140px) var(--dot-gap, 140px);
    background-position: center center;
    background-attachment: fixed;
    color: var(--fg);
    font-family: var(--mono);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    user-select: none;
    -webkit-user-select: none;
  }
  html { touch-action: none; }
  .stage { touch-action: none; }

  .stage { position: fixed; inset: 0; display: grid; place-items: center; overflow: hidden; }
  .anchor { position: relative; width: var(--S, 320px); height: var(--S, 320px); }
  .frame {
    position: absolute; inset: 0;
    will-change: transform, filter, opacity;
    opacity: 0;
    transform-origin: 50% 50%;
  }
  .frame svg { width: 100%; height: 100%; display: block; overflow: visible; }
  .frame svg * { pointer-events: none; }
  .frame svg .hit { pointer-events: auto; cursor: pointer; }
  .frame.logo .mark { fill: var(--fg); }

  .nav {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 20px);
    left: 24px; right: 24px;
    display: flex; justify-content: space-between;
    font-size: 14px;
    z-index: 50;
    opacity: 0; transition: opacity 1s ease;
  }
  body.ready .nav { opacity: 1; }
  .nav div { display: flex; gap: 20px; }
  .nav a { color: var(--fg); text-decoration: none; }
  .nav a:hover, .nav a:focus-visible { text-decoration: underline; text-underline-offset: 3px; outline: none; }

  .info {
    position: fixed;
    left: 24px; right: 24px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
    display: flex; justify-content: space-between; align-items: end; gap: 24px;
    z-index: 50;
    pointer-events: none;
  }
  .title { font-size: clamp(20px, 2.4vw, 32px); line-height: 1.15; min-height: 1.15em; }
  .cat { font-size: 14px; color: var(--dim); margin-top: 6px; min-height: 1.3em; }
  .count { font-size: 13px; color: var(--dim); white-space: nowrap; }
  .caret {
    display: inline-block; width: .55em; height: .9em; vertical-align: -0.08em;
    background: var(--fg); margin-left: 3px;
    animation: blink 1s steps(1) infinite;
  }
  @keyframes blink { 50% { opacity: 0; } }
  .scrollhint {
    position: fixed; left: 0; right: 0;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 11vh);
    text-align: center; font-size: 13px; color: var(--dim);
    z-index: 50; opacity: 0; transition: opacity .8s ease; pointer-events: none;
  }
  body.ready:not(.away) .scrollhint { opacity: 1; }

  /* ---------- Project window ---------- */
  .modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; }
  .modal[hidden] { display: none; }
  .backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0.45);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    opacity: 0; transition: opacity .35s ease;
  }
  .window {
    --w-bg: #000000; --w-fg: #ffffff; --w-dim: rgba(255, 255, 255, 0.55);
    position: relative;
    width: min(1180px, 92vw);
    height: min(860px, 86vh);
    background: var(--w-bg); color: var(--w-fg);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 24px;
    display: grid;
    grid-template-columns: minmax(280px, 0.8fr) 1.2fr;
    overflow: hidden;
    opacity: 0;
    transform: translateY(24px) scale(0.97);
    transition: opacity .35s ease, transform .45s cubic-bezier(.2, .8, .2, 1);
    touch-action: pan-y;
  }
  .modal.open .backdrop { opacity: 1; }
  .modal.open .window { opacity: 1; transform: none; }
  body.modal-open .nav, body.modal-open .info { opacity: 0; }
  .nav, .info { transition: opacity .35s ease; }

  .mtext {
    padding: 56px 40px 40px;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  .mtext h2 {
    font-family: var(--mono); font-weight: 400;
    font-size: clamp(26px, 2.6vw, 38px); line-height: 1.1;
    margin: 0 0 8px; letter-spacing: -0.01em;
  }
  .mcat { margin: 0 0 32px; font-size: 14px; color: var(--w-dim); }
  .mbody { font-size: 15px; line-height: 1.6; max-width: 60ch; }
  .mbody p { margin: 0 0 1em; }
  .mbody h2, .mbody h3 { font-size: 17px; font-weight: 700; margin: 1.6em 0 .5em; }
  .mbody a { color: inherit; }
  .mbody ul, .mbody ol { padding-left: 1.2em; }

  .mmedia {
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px 12px 12px 0;
    display: flex; flex-direction: column; gap: 12px;
    touch-action: pan-y;
  }
  .mmedia img, .mmedia video { width: 100%; height: auto; display: block; border-radius: 14px; }
  .mmedia iframe { width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; display: block; border-radius: 14px; }

  .close {
    position: absolute; top: 18px; left: 40px;
    font-family: var(--mono); font-size: 14px;
    background: none; border: 0; padding: 0; color: var(--w-fg);
    cursor: pointer; z-index: 2;
  }
  .close:hover, .close:focus-visible { text-decoration: underline; text-underline-offset: 3px; outline: none; }

  @media (max-width: 760px) {
    .window {
      width: 100vw; height: 100%;
      border: 0; border-radius: 0;
      grid-template-columns: 1fr;
      display: block;
      overflow-y: auto;
      overscroll-behavior: contain;
      padding-top: env(safe-area-inset-top, 0px);
      padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .mtext { overflow: visible; padding: 60px 20px 24px; }
    .mmedia { overflow: visible; padding: 0 12px 20px; }
    .close { position: sticky; top: 0; left: auto; display: block; width: 100%; text-align: left; padding: 18px 20px; background: var(--w-bg); }
    .mtext { padding-top: 8px; }
  }
  @media (prefers-reduced-motion: reduce) {
    .window, .backdrop { transition: none; }
  }

  /* echo copies never catch clicks */
  .frame.ghost, .frame.ghost * { pointer-events: none !important; }

  /* film grain over everything, gently flickering */
  .grain {
    position: fixed; inset: -50%;
    z-index: 60;
    pointer-events: none;
    opacity: .62;
    mix-blend-mode: screen;
    animation: grain 0.9s steps(6) infinite;
  }
  /* phone: flickering static instead of a moving tile */
  .grain.static { inset: 0; animation: none; opacity: .6; image-rendering: pixelated; }
  @keyframes grain {
    0%   { transform: translate(0, 0); }
    20%  { transform: translate(-7%, 4%); }
    40%  { transform: translate(5%, -6%); }
    60%  { transform: translate(-3%, -9%); }
    80%  { transform: translate(8%, 3%); }
    100% { transform: translate(0, 0); }
  }
  @media (prefers-reduced-motion: reduce) { .grain { animation: none; } }

  /* details list inside the project window */
  .mdetails { margin: 0 0 28px; font-size: 14px; max-width: 60ch; }
  .mdetails .row {
    display: flex; justify-content: space-between; gap: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.22);
    padding: 9px 0;
  }
  .mdetails .row:last-child { border-bottom: 1px solid rgba(255, 255, 255, 0.22); }
  .mdetails dt { color: var(--w-dim); }
  .mdetails dd { margin: 0; text-align: right; }
  .mdetails[hidden] { display: none; }
  .mmedia img { background: #111; object-fit: cover; }

  /* computer: project name and category centred, where "Scroll" sits */
  @media (min-width: 701px) {
    .info {
      left: 0; right: 0;
      bottom: calc(env(safe-area-inset-bottom, 0px) + 11vh);
      flex-direction: column; align-items: center; justify-content: flex-end;
      gap: 0; text-align: center;
    }
    .title { font-size: 17px; line-height: 1.3; min-height: 1.3em; }
    .cat { font-size: 13px; margin-top: 4px; }
    .count {
      position: fixed; right: 24px;
      bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
    }
  }
  /* no category line (About me): keep some air between title and details */
  .mcat[hidden] + .mdetails { margin-top: 22px; }
  .mcat[hidden] + .mdetails[hidden] + .mbody { margin-top: 22px; }
  /* a window without pictures becomes a single, narrower column */
  .window.nomedia { grid-template-columns: 1fr; width: min(760px, 92vw); }
  .window.nomedia .mmedia { display: none; }
  @media (max-width: 700px) { body { --dot-gap: 90px; } }
