/* ============================================================
   swaze.nl — homepage as deck
   Layout: fixed left nav · main stage · fixed bottom keystroke row
   No scroll. 4 slides. Crossfade transitions.
   ============================================================ */

html, body { height: 100%; overflow: hidden; }

/* ---------- Accessibility utilities ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: 0;
  left: 0;
  padding: 8px 14px;
  background: var(--ink-300);
  color: var(--cream-100);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: var(--tracking-meta);
  text-transform: uppercase;
  text-decoration: none;
  border-radius: 0 0 4px 0;
  transform: translateY(-100%);
  z-index: 100;
}
.skip-link:focus { transform: translateY(0); outline: 2px solid var(--cream-100); outline-offset: -4px; }

/* Universal focus ring for keyboard users */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
.on-dark :focus-visible,
body.is-dark :focus-visible { outline-color: var(--cream-100); }
body.is-highcontrast :focus-visible { outline-color: #000; outline-width: 2px; }

body {
  position: relative;
  background: var(--surface);
  color: var(--fg-1);
}

.grain {
  position: fixed;
  z-index: 60;
}

:root {
  --nav-w: 220px;
  --keys-h: 100px;
}

/* ---------- LEFT NAV ---------- */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--nav-w);
  height: calc(100vh - var(--keys-h));
  padding: 28px 24px 24px;
  border-right: 1px dashed var(--rule-on-cream-strong);
  display: flex;
  flex-direction: column;
  z-index: 30;
  background: var(--surface);
}

.nav__brand {
  text-decoration: none;
  color: var(--fg-1);
  display: inline-flex;
  align-items: center;
}
.nav__logo {
  width: 140px;
  height: auto;
  display: block;
  /* knock out the white pdf background against cream */
  mix-blend-mode: multiply;
  filter: contrast(1.05);
}

.nav__list {
  list-style: none;
  margin: 56px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav__link {
  display: inline-grid;
  grid-template-columns: 20px auto;
  align-items: baseline;
  gap: 8px;
  padding: 5px 10px;
  margin-left: -10px;
  width: max-content;
  text-decoration: none;
  color: var(--fg-3);
  border-radius: 2px;
  background: transparent;
  /* hard 1px offset, no blur — bottom edge slightly thicker */
  box-shadow: 0 1px 0 0 var(--rule-on-cream);
  transition: color var(--dur-quick) var(--ease),
              background var(--dur-quick) var(--ease),
              box-shadow var(--dur-quick) var(--ease);
}
.nav__link:hover {
  color: var(--fg-1);
  box-shadow: 0 2px 0 0 var(--rule-on-cream-strong);
}
.nav__link.is-active {
  color: var(--fg-1);
  background: var(--surface-raised);
  box-shadow: 0 2px 0 0 var(--ink-300);
}
.nav__num {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tracking-meta);
  text-transform: uppercase;
  color: var(--fg-3);
}
.nav__link.is-active .nav__num { color: var(--fg-2); }
.nav__label {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: var(--weight-medium);
  letter-spacing: -0.005em;
}

.nav__foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--fg-3);
  min-width: 0;
}
.nav__foot > * {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav__foot-coord { opacity: 0.8; }

/* ---------- STAGE / SLIDES ---------- */
.stage {
  position: fixed;
  top: 0;
  left: var(--nav-w);
  right: 0;
  bottom: var(--keys-h);
  overflow: hidden;
  background: var(--ink-500);
}

/* Persistent scanlines — quiet by default, no pulse on swap */
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.16) 0px,
    rgba(0, 0, 0, 0.16) 1px,
    transparent 1px,
    transparent 3px
  );
  opacity: 0.14;
  mix-blend-mode: multiply;
  z-index: 20;
}

/* Center flash line — only visible mid-transition */
.crt-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  transform: translateY(-50%) scaleX(0);
  transform-origin: center;
  background: var(--cream-50);
  box-shadow: 0 0 18px 2px rgba(255, 254, 251, 0.85),
              0 0 60px 6px rgba(255, 254, 251, 0.35);
  opacity: 0;
  pointer-events: none;
  z-index: 25;
}
.stage.is-switching .crt-line {
  animation: crt-flash 520ms var(--ease) forwards;
}

@keyframes crt-flash {
  0%   { transform: translateY(-50%) scaleX(0); opacity: 0; }
  40%  { transform: translateY(-50%) scaleX(1); opacity: 1; }
  60%  { transform: translateY(-50%) scaleX(1); opacity: 1; }
  100% { transform: translateY(-50%) scaleX(0.001); opacity: 0; }
}

.slide {
  position: absolute;
  inset: 0;
  padding: clamp(40px, 6vw, 80px) clamp(40px, 6vw, 96px);
  display: flex;
  align-items: center;
  background: var(--surface);
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
}
.slide__inner { min-width: 0; }
.slide.on-dark { background: var(--surface-dark); }
.slide.is-active {
  opacity: 1;
  visibility: visible;
}

/* Old-computer redraw: stepped clip-path wipe top → bottom,
   no smooth easing. Feels like the machine is repainting the screen
   one band at a time. */
.slide.is-leaving {
  visibility: visible;
  z-index: 1;
  opacity: 1;
}
.slide.is-entering {
  visibility: visible;
  z-index: 2;
  opacity: 1;
  clip-path: inset(0 0 100% 0);
  animation: redraw 460ms steps(8, end) forwards;
}

@keyframes redraw {
  from { clip-path: inset(0 0 100% 0); }
  to   { clip-path: inset(0 0 0 0); }
}

/* Scan bar that crawls down with the redraw — the "beam" */
.crt-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: var(--cream-50);
  box-shadow: 0 0 0 1px rgba(26,31,29,0.4),
              0 8px 14px -4px rgba(255,254,251,0.35);
  opacity: 0;
  pointer-events: none;
  z-index: 26;
  transform: translateY(-100%);
}
.stage.is-switching .crt-line {
  animation: scanbar 460ms steps(8, end) forwards;
}
@keyframes scanbar {
  0%   { opacity: 1; transform: translateY(0); }
  99%  { opacity: 1; transform: translateY(100vh); }
  100% { opacity: 0; transform: translateY(100vh); }
}

/* Whole stage twitches a hair on each swap — mechanical friction */
.stage.is-switching {
  animation: jitter 460ms steps(4, end);
}
@keyframes jitter {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(1px, 0); }
  50%  { transform: translate(-1px, 1px); }
  75%  { transform: translate(0, -1px); }
  100% { transform: translate(0, 0); }
}

.slide__inner {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
}

.slide__eyebrow { margin-bottom: 32px; }
.on-dark .slide__eyebrow { color: var(--fg-on-dark-3); }

.slide__title {
  font-size: clamp(34px, 4.4vw, 56px);
  letter-spacing: var(--tracking-display);
  line-height: 1.05;
  margin-bottom: 48px;
  max-width: 18ch;
}

/* ---------- SLIDE 01 · HOME ---------- */
.slide--home { position: absolute; }
.home__watermark {
  position: absolute;
  right: -6%;
  bottom: -14%;
  width: 78%;
  max-width: 1100px;
  opacity: 0.07;
  mix-blend-mode: multiply;
  pointer-events: none;
  filter: contrast(1.1);
  z-index: 0;
}
.slide--home .slide__inner { position: relative; z-index: 1; }

.hero {
  font-family: var(--font-display);
  font-weight: var(--weight-medium);
  font-size: clamp(40px, 6vw, 84px);
  line-height: 1.02;
  letter-spacing: var(--tracking-display);
  margin: 0 0 32px;
  max-width: 18ch;
}
.hero__dot { color: var(--emphasis); }
.hero__sub {
  font-size: 18px;
  line-height: 1.55;
  max-width: 48ch;
  color: var(--fg-2);
  margin-bottom: 40px;
}
.hero__row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 20px;
  border-top: 1px solid var(--rule-on-cream);
  max-width: 48ch;
}
.hero__status { font-size: 14px; color: var(--fg-2); }

/* ---------- SLIDE 02 · PROJECTS ---------- */
.projects__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 360px);
  gap: 40px;
  align-items: start;
  width: 100%;
  max-width: 100%;
}
.projects__main { min-width: 0; }

.projects {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px dashed var(--rule-on-dark-strong);
}
.projects__row {
  position: relative;
  display: grid;
  grid-template-columns: 50px 1fr 80px;
  align-items: baseline;
  gap: 20px;
  padding: 18px 4px;
  border-bottom: 1px dashed var(--rule-on-dark-strong);
  cursor: pointer;
  transition: padding-left var(--dur-quick) var(--ease),
              background var(--dur-quick) var(--ease);
}
.projects__row:hover,
.projects__row.is-focus {
  padding-left: 10px;
  background: rgba(251, 248, 240, 0.04);
}
.projects__row.is-focus::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14%;
  bottom: 14%;
  width: 2px;
  background: var(--accent);
}
.projects__num { color: var(--fg-on-dark-3); }
.projects__name {
  font-family: var(--font-display);
  font-size: clamp(18px, 1.9vw, 24px);
  font-weight: var(--weight-medium);
  letter-spacing: -0.01em;
  color: var(--fg-on-dark);
  min-width: 0;
  overflow-wrap: anywhere;
}
.projects__year {
  color: var(--accent);
  text-align: right;
}

/* ---------- PREVIEW PANEL ---------- */
.preview {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 120ms steps(2, end),
              transform 120ms steps(2, end);
}
.preview.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.preview__frame {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  background: var(--ink-400);
  border: 1px solid var(--rule-on-dark-strong);
  border-radius: 4px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}
.preview__frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(251, 248, 240, 0.05) 0px,
    rgba(251, 248, 240, 0.05) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: screen;
  opacity: 0.35;
  z-index: 3;
}

.preview__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  display: block;
  filter: contrast(1.02);
}

.preview__overlay {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  color: var(--fg-on-dark);
}
.preview__overlay--top {
  top: 0;
  background: linear-gradient(
    to bottom,
    rgba(15, 20, 19, 0.78),
    rgba(15, 20, 19, 0)
  );
}
.preview__overlay--bottom {
  bottom: 0;
  background: linear-gradient(
    to top,
    rgba(15, 20, 19, 0.85),
    rgba(15, 20, 19, 0)
  );
}
.preview__num,
.preview__tags,
.preview__year { color: rgba(251, 248, 240, 0.85); }

.preview__name {
  font-family: var(--font-display);
  font-weight: var(--weight-medium);
  font-size: 14px;
  color: var(--fg-on-dark);
  letter-spacing: -0.005em;
}

.preview__hint {
  color: var(--fg-on-dark-3);
  align-self: end;
}

/* ---------- SLIDE 03 · TALKS ---------- */
.talks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}
.talks__item {
  position: relative;
  padding: 28px 24px 32px;
  border: 1px solid var(--rule-on-cream-strong);
  border-radius: 4px;
  background: var(--surface-raised);
  transition: border-color var(--dur-quick) var(--ease),
              transform var(--dur-quick) var(--ease);
  overflow: hidden;
  min-width: 0;
}
.talks__item .meta--upper {
  display: block;
  overflow-wrap: anywhere;
  hyphens: auto;
}
.talks__item:hover,
.talks__item.is-focus {
  border-color: var(--ink-300);
  transform: translateY(-1px);
}
.talks__title {
  margin-top: 14px;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: var(--weight-medium);
  letter-spacing: -0.01em;
  line-height: 1.2;
  max-width: 22ch;
}

/* ---------- SLIDE 04 · ABOUT ---------- */
.about__grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 56px;
  align-items: start;
}

.about__photo {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.about__photo img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  border-radius: 4px;
  filter: contrast(1.02);
}
.about__photo figcaption {
  color: var(--fg-on-dark-3);
}

.about__body {
  display: flex;
  flex-direction: column;
  gap: 22px;
  max-width: 640px;
  min-width: 0;
}

.about__title {
  font-family: var(--font-display);
  font-weight: var(--weight-medium);
  font-size: clamp(28px, 3.4vw, 44px);
  line-height: 1.05;
  letter-spacing: var(--tracking-display);
  color: var(--fg-on-dark);
  margin: 0;
}

.about__lede {
  font-size: 17px;
  line-height: 1.55;
  color: var(--fg-on-dark);
  margin: 0;
}
.about__copy {
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--fg-on-dark-2);
  margin: 0;
}

.about__skills {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 14px;
  border-top: 1px dashed var(--rule-on-dark-strong);
}
.about__skillrow {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 16px;
  align-items: baseline;
}
.about__skilllabel { color: var(--accent); }
.about__skillitems {
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.01em;
  color: var(--fg-on-dark);
  min-width: 0;
  overflow-wrap: anywhere;
}

.about__timeline {
  list-style: none;
  margin: 8px 0 0;
  padding: 14px 0 0;
  border-top: 1px dashed var(--rule-on-dark-strong);
  display: flex;
  flex-direction: column;
  gap: 0;
}
.about__step {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 20px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px dashed var(--rule-on-dark);
}
.about__step:last-child { border-bottom: 0; }
.about__when { color: var(--fg-on-dark-3); }
.about__what {
  font-size: 14px;
  color: var(--fg-on-dark);
  line-height: 1.4;
}

@media (max-width: 900px) {
  .about__grid {
    grid-template-columns: 1fr;
    gap: 28px;
  }
  .about__photo { max-width: 280px; }
}

/* ---------- BOTTOM KEYS ROW ---------- */
:root { --keys-h: 80px; }

.keys {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--keys-h);
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 24px;
  border-top: 1px dashed var(--rule-on-cream-strong);
  background: var(--surface);
  z-index: 40;
  overflow: hidden;
}

.keys__group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.keys__group--right { margin-left: auto; }

.keys__label {
  color: var(--fg-3);
  margin-right: 2px;
  font-size: 10px;
}
.keys__counter {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: var(--tracking-meta);
  text-transform: uppercase;
  color: var(--fg-3);
  white-space: nowrap;
}

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 26px;
  padding: 0 7px;
  border-radius: 2px;
  border: 1px solid var(--rule-on-cream-strong);
  background: var(--surface-raised);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-medium);
  color: var(--fg-1);
  box-shadow: 0 2px 0 0 var(--ink-300);
  transition: transform var(--dur-quick) var(--ease),
              background var(--dur-quick) var(--ease),
              color var(--dur-quick) var(--ease),
              box-shadow var(--dur-quick) var(--ease);
}
.key--wide { min-width: 34px; }

.key-pair {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.key-pair__name {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tracking-meta);
  text-transform: uppercase;
  color: var(--fg-3);
  transition: color var(--dur-quick) var(--ease);
}
.key-pair:has(.key.is-on) .key-pair__name { color: var(--fg-1); }

.key.is-pressed,
.key.is-on {
  background: var(--ink-300);
  color: var(--cream-100);
  box-shadow: 0 0 0 0 var(--ink-300);
  transform: translateY(2px);
}

/* ============================================================
   RESPONSIVE
   1100 — tighten nav + padding
   1024 — about stacks to single column
    960 — nav becomes a top bar (was 720, moved up to prevent
          the cramped 700-960px zone seen in screenshots)
    680 — hide D/H mode keys
    560 — hide arrow keys, lighter type
    420 — tightest layout
   ============================================================ */

/* Tablet / small laptop -------------------------------------- */
@media (max-width: 1100px) {
  :root { --nav-w: 184px; }
  .nav__logo { width: 116px; }
  .slide { padding: clamp(28px, 5vw, 56px) clamp(28px, 5vw, 64px); }
  .talks { gap: 20px; }
  .about__grid {
    grid-template-columns: minmax(220px, 280px) 1fr;
    gap: 36px;
  }
  .home__watermark { width: 70%; right: -8%; }

  /* Projects: drop preview into single-column flow */
  .projects__layout {
    grid-template-columns: 1fr;
    gap: 28px;
  }
  .preview { max-width: 360px; }
  .preview__hint { display: none; }

  /* Keys row: hide pair labels (Dark / Contrast) — keep just D and H */
  .key-pair__name { display: none; }
  .keys { gap: 18px; }
}

/* About slide stacks earlier — at 1024 not 900 */
@media (max-width: 1024px) {
  .about__grid {
    grid-template-columns: 1fr;
    gap: 28px;
  }
  .about__photo { max-width: 280px; }
}

/* Talks goes single column at mid widths */
@media (max-width: 960px) {
  .talks { grid-template-columns: 1fr; }
}

/* Tablet portrait / large phone ------------------------------ */
@media (max-width: 960px) {
  :root {
    --nav-w: 0px;
    --nav-h: 56px;
    --keys-h: 84px;
  }

  .nav {
    width: 100%;
    height: var(--nav-h);
    padding: 0 16px;
    border-right: 0;
    border-bottom: 1px dashed var(--rule-on-cream-strong);
    flex-direction: row;
    align-items: center;
    gap: 16px;
  }
  .nav__logo { width: 78px; }

  .nav__list {
    flex-direction: row;
    margin: 0 0 0 auto;
    gap: 10px;
    flex-wrap: nowrap;
    min-width: 0;
    overflow: hidden;
  }
  .nav__link {
    grid-template-columns: auto auto;
    gap: 6px;
    padding: 4px 6px;
  }
  /* Mobile pattern: numbers always shown; active link expands to show label */
  .nav__num {
    display: inline;
    font-size: 13px;
    color: var(--fg-2);
  }
  .nav__label { display: none; }
  .nav__link.is-active .nav__num { color: var(--fg-1); }
  .nav__link.is-active .nav__label {
    display: inline;
    font-size: 12px;
    font-weight: var(--weight-medium);
    color: var(--fg-1);
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .nav__foot { display: none; }

  .stage {
    left: 0;
    top: var(--nav-h);
  }

  .slide {
    padding: 28px 24px 32px;
    align-items: flex-start;
  }
  .slide__inner {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .slide__eyebrow { margin-bottom: 20px; }
  .slide__title {
    font-size: clamp(26px, 6.4vw, 40px);
    margin-bottom: 28px;
    max-width: 22ch;
  }

  /* Home — fit cleanly, leave room for the home__watermark */
  .hero {
    font-size: clamp(28px, 7.2vw, 56px);
    line-height: 1.04;
    margin-bottom: 24px;
    max-width: 100%;
  }
  .hero__sub { font-size: 15px; margin-bottom: 24px; max-width: 50ch; }
  .hero__row { flex-wrap: wrap; gap: 10px 16px; }
  .home__watermark {
    width: 100%;
    right: -10%;
    bottom: -18%;
    opacity: 0.05;
  }

  /* Projects */
  .projects__layout { grid-template-columns: 1fr; gap: 20px; }
  .preview {
    position: relative;
    order: -1;
    max-width: 280px;
    margin: 0 auto;
  }
  .preview__hint { display: none; }
  .projects__row {
    grid-template-columns: 36px 1fr;
    grid-template-rows: auto auto;
    gap: 4px 16px;
    padding: 14px 0;
  }
  .projects__name {
    grid-column: 2;
    font-size: 17px;
  }
  .projects__year {
    grid-column: 2;
    grid-row: 2;
    text-align: left;
  }
  .projects__num { grid-row: 1 / span 2; align-self: start; padding-top: 4px; }
  .projects__row:hover,
  .projects__row.is-focus { padding-left: 0; }
  .projects__row.is-focus::before { left: -10px; }

  /* Talks */
  .talks { grid-template-columns: 1fr; gap: 14px; }
  .talks__title { font-size: 18px; }

  /* About */
  .about__grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  .about__photo { max-width: 220px; }
  .about__title { font-size: clamp(24px, 6.5vw, 34px); }
  .about__lede { font-size: 16px; }
  .about__copy { font-size: 14px; }
  .about__skillrow,
  .about__step {
    grid-template-columns: 70px 1fr;
    gap: 12px;
  }

  /* Keys row — keep the bottom strip tight on tablet/phone */
  .keys { gap: 12px; padding: 0 14px; flex-wrap: nowrap; }
  .keys__label { display: none; }
  .key-pair__name { display: none; }
  .key {
    min-width: 30px;
    min-height: 30px;
    height: 30px;
    font-size: 12px;
    padding: 0 7px;
  }
  .key--wide { min-width: 36px; }
  .keys__counter { font-size: 10px; white-space: nowrap; }

  /* Mobile project rows — make whole row tappable with adequate height */
  .projects__row { min-height: 56px; padding: 14px 0; }
}

/* Mid-narrow — drop the Mode group (D/H) before they get squeezed */
@media (max-width: 680px) {
  .keys__group--modes { display: none; }
  .keys { gap: 14px; padding: 0 12px; }
}

/* Narrow phone — drop arrow keys, keep 1-4 + counter */
@media (max-width: 560px) {
  :root { --keys-h: 72px; }

  .nav__logo { width: 64px; }
  .nav__list { gap: 6px; }
  .nav__link { padding: 4px 4px; gap: 4px; }
  .nav__link.is-active .nav__label { font-size: 11px; max-width: 64px; }

  .slide { padding: 22px 18px 24px; }
  .slide__title { font-size: clamp(22px, 7vw, 32px); margin-bottom: 22px; }
  .hero { font-size: clamp(26px, 8.4vw, 44px); margin-bottom: 18px; }
  .hero__sub { font-size: 14px; margin-bottom: 18px; }
  .hero__row { padding-top: 14px; }

  /* hide arrow keys group — keyboard still works, just less chrome */
  .keys__group:nth-child(2) { display: none; }
  .keys { gap: 10px; padding: 0 10px; }
  .key { min-width: 32px; min-height: 30px; height: 30px; font-size: 11px; padding: 0 6px; }
  .keys__counter { font-size: 10px; }
}

/* Tiniest — strip to absolute essentials */
@media (max-width: 420px) {
  :root { --keys-h: 66px; }
  .nav { padding: 0 12px; gap: 10px; }
  .nav__list { gap: 4px; }
  .slide { padding: 18px 14px 20px; }
  .hero { font-size: clamp(22px, 8.6vw, 36px); }
  .hero__sub { font-size: 13.5px; }
  .keys { padding: 0 8px; gap: 8px; }
  .key { min-width: 28px; font-size: 10.5px; padding: 0 5px; }
}

/* Very small / landscape phone — keep counter visible */
@media (max-height: 480px) and (max-width: 960px) {
  :root { --keys-h: 64px; }
  .slide { padding: 14px 16px; align-items: flex-start; }
  .slide__eyebrow { margin-bottom: 12px; }
  .slide__title { margin-bottom: 16px; }
}

/* ============================================================
   DARK MODE — flip cream surfaces to ink
   Toggled via the D key
   ============================================================ */
body.is-dark { background: var(--surface-dark); color: var(--fg-on-dark); }

body.is-dark .slide:not(.on-dark) {
  background: var(--surface-dark);
  color: var(--fg-on-dark);
}
body.is-dark .slide:not(.on-dark) .slide__eyebrow { color: var(--fg-on-dark-3); }

/* Nav */
body.is-dark .nav {
  background: var(--surface-dark);
  border-right-color: var(--rule-on-dark-strong);
}
body.is-dark .nav__logo {
  mix-blend-mode: screen;
  filter: invert(1) contrast(1.05);
}
body.is-dark .nav__link {
  color: var(--fg-on-dark-3);
  box-shadow: 0 1px 0 0 var(--rule-on-dark);
}
body.is-dark .nav__link:hover {
  color: var(--fg-on-dark);
  box-shadow: 0 2px 0 0 var(--rule-on-dark-strong);
}
body.is-dark .nav__link.is-active {
  color: var(--fg-on-dark);
  background: var(--surface-dark-raised);
  box-shadow: 0 2px 0 0 var(--cream-100);
}
body.is-dark .nav__num { color: var(--fg-on-dark-3); }
body.is-dark .nav__foot { color: var(--fg-on-dark-3); }

/* Home */
body.is-dark .hero { color: var(--fg-on-dark); }
body.is-dark .hero__sub { color: var(--fg-on-dark-2); }
body.is-dark .hero__row { border-top-color: var(--rule-on-dark); }
body.is-dark .hero__status { color: var(--fg-on-dark-2); }
body.is-dark .home__watermark {
  mix-blend-mode: screen;
  filter: invert(1) contrast(1.05);
  opacity: 0.08;
}

/* Talks */
body.is-dark .slide--talks .talks__item {
  background: var(--surface-dark-raised);
  border-color: var(--rule-on-dark-strong);
}
body.is-dark .slide--talks .talks__item:hover {
  border-color: var(--cream-100);
}
body.is-dark .slide--talks .talks__item .meta--upper { color: var(--fg-on-dark-3); }
body.is-dark .slide--talks .talks__title { color: var(--fg-on-dark); }

/* Keys row */
body.is-dark .keys {
  background: var(--surface-dark);
  border-top-color: var(--rule-on-dark-strong);
}
body.is-dark .keys__label,
body.is-dark .keys__counter { color: var(--fg-on-dark-3); }
body.is-dark .key {
  background: var(--surface-dark-raised);
  color: var(--fg-on-dark);
  border-color: var(--rule-on-dark-strong);
  box-shadow: 0 2px 0 0 var(--cream-100);
}
body.is-dark .key.is-pressed,
body.is-dark .key.is-on {
  background: var(--cream-100);
  color: var(--ink-300);
  box-shadow: 0 0 0 0 var(--cream-100);
}

/* Stage backdrop */
body.is-dark .stage { background: var(--ink-500); }
body.is-dark .stage::before {
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(251, 248, 240, 0.10) 0px,
    rgba(251, 248, 240, 0.10) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: screen;
}

/* Scanbar flips to ink on cream-less backgrounds — keep cream for glow */
body.is-dark .crt-line {
  background: var(--cream-100);
  box-shadow: 0 0 0 1px rgba(251, 248, 240, 0.5);
}

/* ============================================================
   HIGH CONTRAST MODE — monochrome, thin rules, restrained
   Toggled via the H key. Strips warmth and color; reduces ink.
   ============================================================ */
body.is-highcontrast {
  --cream-50:   #ffffff;
  --cream-100:  #ffffff;
  --cream-200:  #ffffff;
  --cream-300:  #f4f4f4;
  --ink-100:    #555555;
  --ink-200:    #1a1a1a;
  --ink-300:    #000000;
  --ink-400:    #000000;
  --ink-500:    #000000;
  --teal-400:   #000000;
  --teal-500:   #000000;
  --teal-600:   #000000;
  --teal-700:   #000000;
  --red-500:    #000000;
  --red-600:    #000000;
  --accent:     #000000;
  --emphasis:   #000000;

  --rule-on-cream:        rgba(0, 0, 0, 0.08);
  --rule-on-cream-strong: rgba(0, 0, 0, 0.20);
  --rule-on-dark:         rgba(255, 255, 255, 0.10);
  --rule-on-dark-strong:  rgba(255, 255, 255, 0.30);

  --fg-1:         #000000;
  --fg-2:         #1a1a1a;
  --fg-3:         rgba(0, 0, 0, 0.55);
  --fg-on-dark:   #ffffff;
  --fg-on-dark-2: rgba(255, 255, 255, 0.78);
  --fg-on-dark-3: rgba(255, 255, 255, 0.52);
}

/* Strip texture and atmosphere */
body.is-highcontrast .grain { display: none; }
body.is-highcontrast .stage::before { display: none; }
body.is-highcontrast .home__watermark { opacity: 0.04; filter: grayscale(1) contrast(1); }

/* Thin and quiet all rules — no dashes */
body.is-highcontrast .projects,
body.is-highcontrast .projects__row,
body.is-highcontrast .about__skills,
body.is-highcontrast .about__timeline,
body.is-highcontrast .about__step,
body.is-highcontrast .about__meta,
body.is-highcontrast .about__row,
body.is-highcontrast .hero__row,
body.is-highcontrast .nav,
body.is-highcontrast .keys {
  border-style: solid !important;
  border-width: 0;
}
body.is-highcontrast .projects { border-top-width: 1px; }
body.is-highcontrast .projects__row { border-bottom-width: 1px; }
body.is-highcontrast .about__skills,
body.is-highcontrast .about__timeline { border-top-width: 1px; }
body.is-highcontrast .about__step:not(:last-child) { border-bottom-width: 1px; }
body.is-highcontrast .nav { border-right-width: 1px; }
body.is-highcontrast .keys { border-top-width: 1px; }

/* Remove the letterpress shadows */
body.is-highcontrast .nav__link,
body.is-highcontrast .nav__link:hover,
body.is-highcontrast .nav__link.is-active,
body.is-highcontrast .key,
body.is-highcontrast .talks__item.is-focus,
body.is-highcontrast .preview__frame {
  box-shadow: none;
}

/* Active nav: just a hairline underline, no fill */
body.is-highcontrast .nav__link.is-active {
  background: transparent;
  box-shadow: 0 1px 0 0 #000;
}

/* Cards become bare frames */
body.is-highcontrast .talks__item {
  border-color: rgba(0, 0, 0, 0.20);
}
body.is-highcontrast .talks__item:hover,
body.is-highcontrast .talks__item.is-focus {
  border-color: #000;
}

/* Keys: thin outline, no fill change on toggle */
body.is-highcontrast .key {
  background: transparent;
  border-color: rgba(0, 0, 0, 0.30);
}
body.is-highcontrast .key.is-pressed,
body.is-highcontrast .key.is-on {
  background: #000;
  color: #fff;
  transform: none;
}

/* Images go grayscale on the projects slide */
body.is-highcontrast .preview__img { filter: grayscale(1) contrast(1.04); }
body.is-highcontrast .about__photo img { filter: grayscale(1) contrast(1.04); }

/* Hero red dot becomes the only black-on-white moment */
body.is-highcontrast .hero__dot,
body.is-highcontrast .nav__dot,
body.is-highcontrast .preview__dot { color: #000; }

/* Focus indicator becomes a 1px black line */
body.is-highcontrast .projects__row.is-focus::before { background: #000; width: 1px; }

/* Stage backdrop pure white */
body.is-highcontrast .stage { background: #fafafa; }

/* ============================================================
   SYSTEM PREFERENCES
   ============================================================ */

/* Respect prefers-reduced-motion: kill the redraw, scanbar, jitter */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
  .slide.is-entering,
  .slide.is-leaving { animation: none !important; clip-path: none !important; }
  .stage.is-switching { animation: none !important; }
  .stage.is-switching .crt-line { animation: none !important; opacity: 0 !important; }
}

/* Auto-darken rules when the OS asks for higher contrast.
   This is a light touch — for full mono use the H toggle. */
@media (prefers-contrast: more) {
  body {
    --rule-on-cream: rgba(26, 31, 29, 0.30);
    --rule-on-cream-strong: rgba(26, 31, 29, 0.55);
    --rule-on-dark: rgba(251, 248, 240, 0.30);
    --rule-on-dark-strong: rgba(251, 248, 240, 0.55);
    --fg-3: var(--ink-200);
  }
  body .grain { opacity: 0; }
}
