/* ==========================================================================
   mednabouli.me — shared foundation (tokens, reset, base, shared components)
   Two modes drive the whole site: html[data-mode="photo"] and [data-mode="code"]
   ========================================================================== */

/* ---------- Fonts (self-hosted) ---------- */
@font-face {
  font-family: "Instrument Serif";
  src: url("/assets/fonts/instrument-serif.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Serif";
  src: url("/assets/fonts/instrument-serif-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/assets/fonts/jetbrains-mono.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  color-scheme: dark;

  --bg: #080808;
  --ink: #ece8e1;
  --muted: #a39f98;
  --accent: #ff4a3d;
  --accent-ink: #120503;
  --line: rgb(255 255 255 / 0.07);

  --font-serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Photo mode is the default voice */
  --font-display: var(--font-serif);
  --font-ui: var(--font-sans);

  --pad: clamp(1.25rem, 3.2vw, 3rem);

  /* Type scale: every text size on the site is one of these ten steps */
  --fs-xs: 0.8125rem;
  --fs-sm: 0.875rem;
  --fs-base: 1rem;
  --fs-md: 1.125rem;
  --fs-lg: clamp(1.15rem, 1.6vw, 1.4rem);
  --fs-xl: clamp(1.5rem, 2.6vw, 2.25rem);
  --fs-2xl: clamp(2rem, 4.2vw, 3.5rem);
  --fs-3xl: clamp(2.5rem, 6vw, 5rem);
  --fs-4xl: clamp(3rem, 8vw, 7rem);
  --fs-5xl: clamp(3.5rem, 11vw, 10.5rem);

  /* Shape and speed: one corner style for controls, one for boxes, three speeds */
  --radius-control: 999px;
  --radius-box: 0px;
  --t-fast: 0.2s;
  --t: 0.3s;
  --t-slow: 0.6s;

  /* Space above each major section */
  --space-section: clamp(3rem, 8vw, 6.5rem);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (max-width: 720px) {
  :root {
    --fs-2xl: clamp(1.75rem, 7.5vw, 2.6rem);
    --fs-3xl: clamp(2.1rem, 10vw, 3.4rem);
    --fs-4xl: clamp(2.5rem, 12.5vw, 4.25rem);
    --fs-5xl: clamp(3.25rem, 17vw, 5.75rem);
  }
}

html[data-mode="code"] {
  --radius-control: 4px;
  --radius-box: 6px;
  --font-display: var(--font-mono);
  --font-ui: var(--font-mono);
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body,
h1,
h2,
h3,
p,
ul,
ol,
figure {
  margin: 0;
}
ul[class],
ol[class] {
  padding: 0;
  list-style: none;
}
img,
canvas,
svg {
  display: block;
  max-width: 100%;
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
a {
  color: inherit;
  text-decoration: none;
}
[hidden] {
  display: none !important;
}

/* ---------- Base ---------- */
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 2px;
}

/* Content that belongs to one mode only */
html[data-mode="photo"] [data-m="code"],
html[data-mode="code"] [data-m="photo"] {
  display: none;
}

.skip {
  position: absolute;
  left: var(--pad);
  top: -4rem;
  z-index: 10;
  padding: 0.5rem 0.9rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  transition: top var(--t-fast) var(--ease);
}
.skip:focus {
  top: 0.75rem;
}

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

/* ---------- Shared: header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: var(--pad) var(--pad) 0;
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.wordmark {
  padding: 0.5rem 0;
  font-weight: 600;
  letter-spacing: 0.14em;
}
html[data-mode="code"] .wordmark {
  text-transform: lowercase;
  letter-spacing: 0;
  color: var(--ink);
}

.lang {
  display: flex;
  gap: 0.25rem;
}
.lang a {
  padding: 0.5rem 0.6rem;
  color: var(--muted);
  transition: color var(--t-fast);
}
.lang a:hover {
  color: var(--ink);
}
.lang a[aria-current="true"] {
  color: var(--ink);
  box-shadow: inset 0 -1px 0 var(--accent);
}

/* ---------- Shared: mode switch ---------- */
.mode-switch {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: rgb(8 8 8 / 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.mode-switch button {
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-control);
  font-size: var(--fs-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color var(--t-fast), background-color var(--t-fast);
}
.mode-switch button:hover {
  color: var(--ink);
}
.mode-switch button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
html[data-mode="code"] .mode-switch,
html[data-mode="code"] .mode-switch button {
  text-transform: lowercase;
  letter-spacing: 0;
}

/* "Coming soon" marker for pages not built yet */
.soon {
  margin-left: 0.5em;
  padding: 0.1em 0.5em;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  font-style: normal;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  vertical-align: middle;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Shared: main nav (inner pages) ---------- */
.site-nav {
  display: flex;
  gap: 1.5rem;
  margin-left: auto;
  margin-right: 1rem;
}
.site-nav a {
  padding: 0.5rem 0;
  color: var(--muted);
  transition: color var(--t-fast);
}
.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--ink);
}

/* ---------- Shared: page footer (inner pages) ---------- */
.page-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem 2rem;
  margin-top: var(--space-section);
  padding: 1.5rem var(--pad) var(--pad);
  border-top: 1px solid var(--line);
  font-size: var(--fs-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.page-footer ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.page-footer a {
  display: inline-block;
  padding: 0.35rem 0;
}
.page-footer a:hover {
  color: var(--accent);
}

/* Header button that opens the command palette */
.kbd-btn {
  margin-right: 0.75rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  font-size: var(--fs-xs);
  color: var(--muted);
  transition: color var(--t-fast), border-color var(--t-fast);
}
.kbd-btn:hover {
  color: var(--ink);
  border-color: var(--accent);
}
@media (max-width: 720px) {
  .kbd-btn {
    display: none;
  }
}

/* ---------- Command palette ---------- */
.palette {
  width: min(36rem, calc(100vw - 2rem));
  margin-top: 14vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-box);
  background: #0e0e0e;
  color: var(--ink);
  font-family: var(--font-mono);
  box-shadow: 0 30px 80px rgb(0 0 0 / 0.6);
}
.palette::backdrop {
  background: rgb(0 0 0 / 0.6);
  backdrop-filter: blur(3px);
}
.palette__input {
  width: 100%;
  padding: 1rem 1.1rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  outline: 0;
  background: none;
  color: inherit;
  font: inherit;
}
.palette__input::placeholder {
  color: var(--muted);
}
.palette__list {
  max-height: 20rem;
  margin: 0;
  padding: 0.4rem;
  overflow-y: auto;
  list-style: none;
}
.palette__item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-box);
  font-size: var(--fs-sm);
  cursor: pointer;
}
.palette__item small {
  color: var(--muted);
}
.palette__item[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}
.palette__item[aria-selected="true"] small {
  color: inherit;
}
.palette__empty {
  padding: 1rem 0.7rem;
  font-size: var(--fs-sm);
  color: var(--muted);
}

/* ==========================================================================
   App shell: page transitions, entrances, scroll reveals, guided next steps
   ========================================================================== */

/* ---------- Page-to-page transitions (browsers that support them) ---------- */
@view-transition {
  navigation: auto;
}
.site-header {
  view-transition-name: site-header;
}
::view-transition-old(root) {
  animation: vt-out 0.22s ease-in both;
}
::view-transition-new(root) {
  animation: vt-in 0.5s var(--ease) both;
}
@keyframes vt-out {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}
@keyframes vt-in {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
}
/* Fallback: a plain fade-in where page transitions are not supported */
html.no-vt.motion main {
  animation: page-in 0.5s var(--ease) both;
}
@keyframes page-in {
  from {
    opacity: 0;
    translate: 0 12px;
  }
}

/* ---------- Scroll reveals ---------- */
html.js.motion:not(.reveal-all) [data-reveal] {
  opacity: 0;
  translate: 0 1.5rem;
}
[data-reveal] {
  transition: opacity 0.8s var(--ease), translate 0.8s var(--ease);
  transition-delay: calc(var(--i, 0) * 70ms);
}
html.js.motion [data-reveal].is-in {
  opacity: 1;
  translate: none;
}

/* ---------- Scroll progress (thin line under the top edge) ---------- */
.progress {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 20;
  height: 2px;
  background: var(--accent);
  transform-origin: left;
  scale: var(--progress, 0) 1;
  pointer-events: none;
}

/* ---------- Guided next step at the end of a page ---------- */
.next {
  display: block;
  margin: var(--space-section) var(--pad) 0;
  padding: clamp(2rem, 5vw, 4rem) 0;
  border-block: 1px solid var(--line);
  transition: border-color var(--t);
}
.next__label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: var(--fs-xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.next__title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  line-height: 1;
  letter-spacing: -0.02em;
}
.next__title::after {
  content: "→";
  color: var(--accent);
  transition: translate var(--t) var(--ease);
}
.next:hover,
.next:focus-visible {
  border-color: var(--accent);
}
.next:hover .next__title::after,
.next:focus-visible .next__title::after {
  translate: 0.6rem 0;
}
html[data-mode="code"] .next__label {
  text-transform: lowercase;
  letter-spacing: 0;
}
html[data-mode="code"] .next__title {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.05em;
  text-transform: lowercase;
}
.next + .page-footer {
  margin-top: 0;
  border-top: 0;
}

/* Stagger siblings that reveal together (no inline styles, so it is done by position) */
[data-reveal]:nth-child(2) { --i: 1; }
[data-reveal]:nth-child(3) { --i: 2; }
[data-reveal]:nth-child(4) { --i: 3; }
[data-reveal]:nth-child(5) { --i: 4; }
[data-reveal]:nth-child(6) { --i: 5; }

html[data-mode="code"] .site-header {
  text-transform: lowercase;
  letter-spacing: 0;
}

/* ==========================================================================
   Header v2: sticky bar that hides on scroll down, menu with a sliding pill,
   language toggle, full-screen menu on small screens
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 15;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 1.1rem var(--pad);
  transition: translate var(--t) var(--ease);
}
/* Frosted backdrop, only once the page has scrolled */
.site-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-bottom: 1px solid var(--line);
  background: rgb(8 8 8 / 0.74);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0;
  transition: opacity var(--t);
}
.site-header.is-stuck::before {
  opacity: 1;
}
.site-header.is-hidden {
  translate: 0 -110%;
}
.wordmark {
  justify-self: start;
}

/* ---------- Menu ---------- */
.site-nav {
  position: relative;
  gap: 0.15rem;
  margin: 0;
  padding: 0.3rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: rgb(8 8 8 / 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.site-nav a {
  position: relative;
  z-index: 1;
  padding: 0.5rem 1.05rem;
  border-radius: var(--radius-control);
  color: var(--muted);
  transition: color var(--t-fast);
}
.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--ink);
}
/* The pill slides under the link you point at and rests on the current page */
.site-nav__pill {
  position: absolute;
  top: 0.3rem;
  bottom: 0.3rem;
  left: 0;
  width: 0;
  border-radius: var(--radius-control);
  background: var(--ink);
  opacity: 0;
  pointer-events: none;
  transition: translate var(--t) var(--ease), width var(--t) var(--ease), opacity var(--t-fast);
}
.site-nav__pill.is-on {
  opacity: 1;
}
.site-nav a.is-over,
.site-nav a.is-over:hover {
  color: var(--bg) !important;
  opacity: 1 !important;
  text-shadow: none !important;
}
/* Without the script there is no pill, so mark the current page with an underline */
html:not(.js) .site-nav a[aria-current="page"] {
  box-shadow: inset 0 -1px 0 var(--accent);
}
html[data-mode="code"] .site-nav__pill {
  background: var(--accent);
}
html[data-mode="code"] .site-nav a.is-over {
  color: var(--accent-ink) !important;
}

/* ---------- Right side: command menu, language, menu button ---------- */
.header-tools {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 0.6rem;
}
.kbd-btn {
  margin-right: 0;
}
.lang {
  gap: 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: rgb(8 8 8 / 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.lang a {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-control);
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  line-height: 1.2;
  color: var(--muted);
  transition: color var(--t-fast), background-color var(--t-fast);
}
.lang a[aria-current="true"],
.lang a[aria-current="true"]:hover {
  background: var(--accent);
  box-shadow: none;
  color: var(--accent-ink) !important;
  font-weight: 600;
  opacity: 1 !important;
  text-shadow: none !important;
}

.menu-btn {
  display: none;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: rgb(8 8 8 / 0.5);
  font-size: var(--fs-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.menu-btn i {
  position: relative;
  width: 1rem;
  height: 0.5rem;
}
.menu-btn i::before,
.menu-btn i::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: 1.5px;
  background: var(--ink);
}
.menu-btn i::before {
  top: 0;
}
.menu-btn i::after {
  bottom: 0;
  width: 60%;
}
html[data-mode="code"] .menu-btn {
  letter-spacing: 0;
  text-transform: lowercase;
}

/* Small screens: the row of links becomes a "Menu" button (when the script runs) */
@media (max-width: 1000px) {
  .site-header {
    grid-template-columns: 1fr auto;
  }
  html.js .site-nav {
    display: none;
  }
  html.js .menu-btn {
    display: inline-flex;
  }
  html:not(.js) .site-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: start;
    order: 0;
    width: auto;
    max-width: 100%;
    margin-top: 0.75rem;
    overflow-x: auto;
  }
}

/* ---------- Full-screen menu ---------- */
.menu-sheet {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 1.1rem var(--pad) var(--pad);
  border: 0;
  background: var(--bg);
  color: var(--ink);
}
.menu-sheet::backdrop {
  background: var(--bg);
}
.menu-sheet[open] {
  display: grid;
  grid-template-rows: auto 1fr auto;
  animation: sheet-in 0.45s var(--ease);
}
@keyframes sheet-in {
  from {
    clip-path: inset(0 0 100% 0);
  }
  to {
    clip-path: inset(0);
  }
}
.menu-sheet__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--fs-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.menu-sheet__links {
  display: grid;
  align-content: center;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.menu-sheet__links a {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.35rem 0;
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.menu-sheet__links span {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0;
  color: var(--muted);
}
.menu-sheet__links a[aria-current="page"] {
  font-style: italic;
  color: var(--accent);
}
html.motion .menu-sheet[open] .menu-sheet__links li {
  animation: sheet-item 0.6s var(--ease) both;
  animation-delay: calc(0.12s + var(--n, 0) * 0.06s);
}
.menu-sheet__links li:nth-child(2) { --n: 1; }
.menu-sheet__links li:nth-child(3) { --n: 2; }
.menu-sheet__links li:nth-child(4) { --n: 3; }
.menu-sheet__links li:nth-child(5) { --n: 4; }
@keyframes sheet-item {
  from {
    opacity: 0;
    translate: 0 1.5rem;
  }
}
.menu-sheet__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: var(--fs-xs);
}
.menu-sheet__social {
  display: flex;
  gap: 1.25rem;
  color: var(--muted);
}
.menu-sheet__social a {
  padding: 0.4rem 0;
}
html[data-mode="code"] .menu-sheet__links a {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.05em;
  text-transform: lowercase;
}
html[data-mode="code"] .menu-sheet__links a[aria-current="page"] {
  font-style: normal;
}
html[data-mode="code"] .menu-sheet__bar {
  text-transform: lowercase;
  letter-spacing: 0;
}
.menu-sheet .menu-btn {
  display: inline-flex;
}

/* ==========================================================================
   Buttons: one filled style for the main action, one outlined style for the rest
   ========================================================================== */
.button {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1.6rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius-control);
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.2;
  white-space: nowrap;
  transition: background-color var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.button::after {
  content: "→";
  transition: translate var(--t) var(--ease);
}
.button:hover,
.button:focus-visible {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--bg);
}
.button:hover::after {
  translate: 0.3rem 0;
}
.button--ghost {
  border-color: var(--line);
  background: none;
  color: var(--ink);
}
.button--ghost:hover,
.button--ghost:focus-visible {
  border-color: var(--ink);
  background: none;
  color: var(--ink);
}
html[data-mode="code"] .button {
  letter-spacing: 0;
  text-transform: lowercase;
}

/* Button variants */
.button--back::after {
  content: none;
}
.button--back::before {
  content: "←";
  transition: translate var(--t) var(--ease);
}
.button--back:hover::before {
  translate: -0.3rem 0;
}
.button--toggle::after {
  content: "↓";
  transition: rotate var(--t) var(--ease);
}
.button--toggle:hover::after {
  translate: none;
}
.button--toggle[aria-expanded="true"]::after {
  rotate: 180deg;
}
button.button {
  cursor: pointer;
}
.button[disabled] {
  opacity: 0.5;
  cursor: progress;
}

/* ---------- Closing prompt at the end of a page ---------- */
.book {
  width: 100%;
  max-width: 76rem;
  margin-inline: auto;
  padding: var(--space-section) var(--pad) 0;
}
.book__title {
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.02em;
}
.book__title em {
  color: var(--muted);
}
.book__text {
  max-width: 40ch;
  margin: 0.9rem 0 1.5rem;
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  line-height: 1.3;
  color: color-mix(in srgb, var(--ink) 80%, var(--bg));
}

/* ---------- Coder side: long text reads in a plain sans face ----------
   Monospace stays for titles, labels, buttons and anything terminal-like. */
html[data-mode="code"] main :is(p, li, dd, td):not(.eyebrow, .comment, [class*="label"], [class*="kind"], [class*="caption"], [class*="readout"], [class*="hint"], [class*="title"], [class*="quote"]):not(:is(.term, .shell, .postcard, .finder, .hero, .steps, nav, .stack, .facts-row) *) {
  font-family: var(--font-sans);
  letter-spacing: 0;
}

/* ---------- Touch screens: every control is at least 44px tall ---------- */
@media (pointer: coarse), (max-width: 720px) {
  .page-footer a,
  .lang a,
  .album-nav a,
  .choice span,
  .wordmark,
  .menu-btn,
  .fov__scale button,
  .contact__links a,
  .hero__more,
  .cta,
  .mode-switch button,
  summary {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
  }
}

/* ---------- Side switch in the header ---------- */
.side-switch a {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-control);
  font-size: var(--fs-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color var(--t-fast), background-color var(--t-fast);
}
.side-switch a:hover {
  color: var(--ink);
}
html[data-mode="photo"] .side-switch a[data-side="photo"],
html[data-mode="code"] .side-switch a[data-side="code"] {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
html[data-mode="code"] .side-switch a {
  text-transform: lowercase;
  letter-spacing: 0;
}
@media (max-width: 1000px) {
  .site-header .side-switch {
    display: none;
  }
}
@media (max-width: 1280px) {
  .site-header .kbd-btn {
    display: none;
  }
}

/* Phone menu: links are numbered here so the count follows the current side */
.menu-sheet__links {
  counter-reset: menu-item -1;
}
.menu-sheet__links li {
  counter-increment: menu-item;
}
.menu-sheet__links a > span:first-child::before {
  content: counter(menu-item, decimal-leading-zero);
}

/* ---------- Scrollbar ---------- */
html {
  scrollbar-color: color-mix(in srgb, var(--ink) 28%, var(--bg)) var(--bg);
  scrollbar-width: thin;
}

/* ---------- Custom cursor (mouse only, see cursor.js) ---------- */
.cursor,
.cursor-dot {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
}
html.has-cursor .cursor,
html.has-cursor .cursor-dot {
  opacity: 1;
}
html.has-cursor,
html.has-cursor :is(a, button, summary, label, [role="button"], input[type="radio"], input[type="checkbox"]) {
  cursor: none;
}
html.has-cursor dialog,
html.has-cursor dialog * {
  cursor: auto;
}
html.has-cursor dialog :is(a, button, summary, label) {
  cursor: pointer;
}
html:has(dialog[open]) .cursor,
html:has(dialog[open]) .cursor-dot,
html.cursor-text .cursor,
html.cursor-text .cursor-dot {
  opacity: 0;
  visibility: hidden;
}
html.cursor-text :is(input, textarea) {
  cursor: text;
}

/* Photographer side: a viewfinder frame around a focus point */
.cursor {
  width: 2.25rem;
  height: 2.25rem;
  margin: -1.125rem 0 0 -1.125rem;
  background:
    linear-gradient(var(--ink), var(--ink)) top left / 9px 1.5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) top left / 1.5px 9px no-repeat,
    linear-gradient(var(--ink), var(--ink)) top right / 9px 1.5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) top right / 1.5px 9px no-repeat,
    linear-gradient(var(--ink), var(--ink)) bottom left / 9px 1.5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) bottom left / 1.5px 9px no-repeat,
    linear-gradient(var(--ink), var(--ink)) bottom right / 9px 1.5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) bottom right / 1.5px 9px no-repeat;
  mix-blend-mode: difference;
  transition: scale var(--t) var(--ease), opacity var(--t-fast);
}
.cursor-dot {
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: var(--accent);
  transition: scale var(--t-fast) var(--ease), opacity var(--t-fast);
}
html.cursor-over .cursor {
  scale: 0.62;
}
html.cursor-over .cursor-dot {
  scale: 1.6;
}
html.cursor-down .cursor {
  scale: 0.5;
}

/* Coder side: a terminal block caret, no frame */
html[data-mode="code"] .cursor {
  display: none;
}
html[data-mode="code"] .cursor-dot {
  width: 0.6rem;
  height: 1.15rem;
  margin: -0.575rem 0 0 -0.1rem;
  border-radius: 1px;
  mix-blend-mode: difference;
  background: var(--ink);
}
html[data-mode="code"].has-cursor .cursor-dot {
  animation: cursor-blink 1.1s steps(1) infinite;
}
html[data-mode="code"].cursor-over .cursor-dot {
  scale: 1;
  background: var(--accent);
  mix-blend-mode: normal;
  animation: none;
}
@keyframes cursor-blink {
  50% {
    opacity: 0.25;
  }
}

/* ==========================================================================
   Guide, tooltips and background motion (guide.js, tips.js, ambient.js)
   ========================================================================== */

/* ---------- Guide card ---------- */
.guide {
  position: fixed;
  right: var(--pad);
  bottom: 1.25rem;
  z-index: 30;
  display: grid;
  gap: 0.6rem;
  width: min(19rem, calc(100vw - 2 * var(--pad)));
  padding: 1rem 1.1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-box);
  background: rgb(12 12 12 / 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0;
  translate: 0 1.25rem;
  visibility: hidden;
  transition: opacity var(--t) var(--ease), translate var(--t-slow) var(--ease), visibility 0s var(--t);
}
.guide.is-on {
  opacity: 1;
  translate: 0 0;
  visibility: visible;
  transition-delay: 0s;
}
html[data-mode="photo"] .guide {
  border-radius: 1rem;
}
.guide__meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.guide__dots {
  display: inline-flex;
  gap: 4px;
}
.guide__dots i {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--ink) 18%, var(--bg));
}
.guide__dots i.is-done {
  background: var(--accent);
}
.guide__text {
  padding-right: 1.25rem;
  font-family: var(--font-display);
  font-size: var(--fs-md);
  line-height: 1.3;
}
html[data-mode="code"] .guide__text {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
}
.guide__go {
  justify-self: start;
}
.guide__close {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--muted);
}
.guide__close:hover {
  color: var(--ink);
}
html.motion .guide.is-nudged {
  animation: guide-nudge 0.6s var(--ease);
}
@keyframes guide-nudge {
  30% {
    translate: 0 -8px;
    border-color: var(--accent);
  }
}
html:has(dialog[open]) .guide {
  visibility: hidden;
}

/* ---------- Tooltip ---------- */
.tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 60;
  max-width: 16rem;
  margin-left: 0;
  padding: 0.35rem 0.65rem;
  border-radius: 4px;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 4px);
  transition: opacity var(--t-fast), transform var(--t-fast) var(--ease);
}
.tip--above {
  transform: translate(-50%, calc(-100% - 4px));
}
.tip.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
}
.tip--above.is-on {
  transform: translate(-50%, -100%);
}

/* ---------- Drifting words and agent log ---------- */
.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  color: var(--ink);
}
.ambient span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  white-space: nowrap;
  opacity: 0;
  animation: ambient-drift var(--t) ease-in-out var(--d) infinite;
}
@keyframes ambient-drift {
  0%,
  100% {
    opacity: 0;
    translate: 0 14px;
  }
  35%,
  65% {
    opacity: 0.13;
  }
  50% {
    translate: 0 -14px;
  }
}
.ambient__agent {
  position: absolute;
  left: var(--pad);
  bottom: 3rem; /* above the strip the bug walks along */
  /* A small status chip with its own background, so it never sits on top of page text */
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-box);
  background: rgb(12 12 12 / 0.9);
  color: var(--muted);
  letter-spacing: 0;
  display: none;
}
@media (min-width: 1000px) {
  html[data-mode="code"] .ambient__agent {
    display: block;
  }
}
.ambient span.is-right {
  left: auto;
  right: var(--x);
}
/* The words live in the page margins: without margins there is no room for them */
@media (max-width: 1280px) {
  .ambient span {
    display: none;
  }
}

/* ---------- The bug ---------- */
.bug {
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  animation: bug-walk 16s linear forwards;
}
@keyframes bug-walk {
  from {
    translate: -3rem 0;
  }
  to {
    translate: 62vw 0;
  }
}
/* Body, with legs drawn as short strokes that shuffle */
.bug i {
  position: relative;
  width: 13px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: bug-wobble 0.28s steps(2) infinite;
}
.bug i::before,
.bug i::after {
  content: "";
  position: absolute;
  left: -3px;
  right: -3px;
  height: 1.5px;
  background:
    linear-gradient(90deg, var(--accent) 3px, transparent 3px calc(100% - 3px), var(--accent) calc(100% - 3px)) 0 0 / 100% 100%;
}
.bug i::before {
  top: 1px;
  rotate: 14deg;
}
.bug i::after {
  bottom: 1px;
  rotate: -14deg;
}
@keyframes bug-wobble {
  50% {
    rotate: 9deg;
  }
}
.bug b {
  position: absolute;
  bottom: 100%;
  left: 50%;
  translate: -50% 0.4rem;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 400;
  white-space: nowrap;
  color: var(--accent);
  opacity: 0;
  transition: opacity var(--t-fast), translate var(--t-slow) var(--ease);
}
.bug.is-fixed {
  animation-play-state: paused;
}
.bug.is-fixed i {
  animation: none;
  scale: 1.4 0.25;
  opacity: 0.5;
  transition: scale var(--t-fast), opacity var(--t-slow);
}
.bug.is-fixed b {
  opacity: 1;
  translate: -50% -0.2rem;
}
html[data-mode="photo"] .bug {
  display: none;
}

/* Phones: the guide is a slim bar and waits until the visitor has scrolled */
@media (max-width: 720px) {
  .guide {
    left: 0.75rem;
    right: 0.75rem;
    bottom: 0.75rem;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.5rem 0.75rem;
    width: auto;
    padding: 0.7rem 2.4rem 0.7rem 0.9rem;
  }
  .guide__meta {
    display: none;
  }
  .guide__text {
    padding-right: 0;
    font-size: var(--fs-sm);
  }
  .guide__go {
    padding-inline: 0.9rem;
    font-size: var(--fs-xs);
    white-space: nowrap;
  }
}

.tip--left,
.tip--left.is-on {
  transform: translate(-100%, -50%);
}

/* The guide steps aside while the page shows its own next step */
.guide.is-on.is-away {
  opacity: 0;
  translate: 0 1.25rem;
  visibility: hidden;
  transition-delay: 0s, 0s, var(--t);
}

/* Wide screens have the side switch in the header: in-page copies are dropped */
@media (min-width: 1001px) {
  .story-head__label,
  .story-head__tools .mode-switch,
  .lost__actions .mode-switch {
    display: none;
  }
}

/* ---------- Text pages (privacy) ---------- */
.legal {
  width: 100%;
  max-width: 46rem;
  margin-inline: auto;
  padding: var(--space-section) var(--pad) 0;
}
.legal__eyebrow,
.legal__date {
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.legal__title {
  margin-top: 0.75rem;
  font-family: var(--font-display);
  font-size: var(--fs-4xl);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: -0.02em;
}
.legal__intro {
  margin: 1.25rem 0 1rem;
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  line-height: 1.35;
}
.legal__body {
  display: grid;
  gap: 2.25rem;
  margin-top: clamp(2rem, 5vw, 3.5rem);
  padding-top: clamp(2rem, 5vw, 3.5rem);
  border-top: 1px solid var(--line);
}
.legal__body section {
  display: grid;
  gap: 0.75rem;
}
.legal__body h2 {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 400;
  line-height: 1.15;
}
.legal__body p {
  font-family: var(--font-sans);
  line-height: 1.6;
  color: color-mix(in srgb, var(--ink) 82%, var(--bg));
}
.legal__cta {
  margin-top: 2.5rem;
}

.form__privacy a,
.audit__note a {
  color: var(--ink);
  box-shadow: inset 0 -1px 0 var(--accent);
}
.legal__title {
  overflow-wrap: anywhere;
}
html[data-mode="code"] .legal__title {
  font-size: var(--fs-3xl);
  font-weight: 700;
  letter-spacing: -0.05em;
  text-transform: lowercase;
}
@media (max-width: 720px) {
  html[data-mode="code"] .legal__title {
    font-size: var(--fs-2xl);
  }
}

/* ---------- Logo: viewfinder corners that close into code brackets ----------
   Each side of the mark is one path. On the photographer side a dash pattern shows
   only its two corners; on the coder side the full bracket is drawn. */
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}
.wordmark__mark {
  flex: none;
  width: 1.35rem;
  height: 1.35rem;
  overflow: visible;
}
.wordmark__mark path {
  fill: none;
  stroke: currentColor;
  stroke-width: 5;
  stroke-linecap: square;
  stroke-dasharray: 16 20 16;
  transition: stroke-dasharray var(--t-slow) var(--ease);
}
.wordmark__mark circle {
  fill: var(--accent);
  transform-origin: 32px 32px;
  transition: transform var(--t) var(--ease);
}
html[data-mode="code"] .wordmark__mark path {
  stroke-dasharray: 26 0 26;
}
.wordmark:hover .wordmark__mark circle {
  transform: scale(1.35);
}
html[data-mode="photo"] .wordmark > span {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 400;
  letter-spacing: -0.01em;
  text-transform: none;
}
