/* =============================================================================
   KM — personal site design system.
   Hand-written CSS, no frameworks. Modern platform features used:
   nesting, color-mix(), :has(), scroll-driven animations, view transitions,
   popover, container-friendly fluid type. Both themes share one token set.
   ============================================================================= */

/* ---------------------------------------------------------------- tokens -- */
:root {
  --font-display: "Unbounded", "Arial Black", sans-serif;
  --font-body: "Onest", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;

  --maxw: 1100px;
  --radius: 14px;
  --radius-s: 8px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #070a12;
  --bg-2: #0a0f1a;
  --surface: #0d1322;
  --surface-2: #111a2e;
  --border: color-mix(in srgb, #94a3b8 14%, transparent);
  --border-strong: color-mix(in srgb, #94a3b8 26%, transparent);
  --text: #e8edf6;
  --text-2: #aab5c8;
  --muted: #8b95ac;
  --accent: #61e3ff;
  --accent-deep: #19b8dd;
  --accent-2: #8f7bff;
  --anomaly: #ff5d7d;
  --warn: #e5b567;
  --ok: #3ddc84;
  --glow: color-mix(in srgb, var(--accent) 22%, transparent);
  --card-shadow: 0 18px 50px -18px rgb(0 0 0 / 0.55);

  --net-node: #9fb4d8;
  --net-edge: #5b6f96;
  --net-packet: #61e3ff;
  --net-anomaly: #ff5d7d;
  --net-glow: #61e3ff;

  --lab-normal: #61e3ff;
  --lab-flagged: #ff5d7d;
  --lab-grid: #1c2740;
  --lab-ring: #ff8ba3;
  --lab-ref: #93a0b8;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fb;
  --bg-2: #eceff7;
  --surface: #ffffff;
  --surface-2: #f6f8fd;
  --border: color-mix(in srgb, #33415e 14%, transparent);
  --border-strong: color-mix(in srgb, #33415e 28%, transparent);
  --text: #101a2e;
  --text-2: #3d4a66;
  --muted: #5b657e;
  --accent: #006e97;
  --accent-deep: #00587a;
  --accent-2: #5f45d6;
  --anomaly: #c00f42;
  --warn: #855a00;
  --ok: #0b7f47;
  --glow: color-mix(in srgb, var(--accent) 18%, transparent);
  --card-shadow: 0 16px 44px -20px rgb(30 45 80 / 0.28);

  --net-node: #5a6c8f;
  --net-edge: #93a3c2;
  --net-packet: #006e97;
  --net-anomaly: #c00f42;
  --net-glow: #006e97;

  --lab-normal: #006e97;
  --lab-flagged: #c00f42;
  --lab-grid: #dbe2f0;
  --lab-ring: #d64a76;
  --lab-ref: #6b7690;
}

/* ------------------------------------------------------------------ reset -- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 84px;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 80% -10%, color-mix(in srgb, var(--accent-2) 7%, transparent), transparent 60%),
    radial-gradient(900px 600px at -10% 30%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

img, canvas, svg { display: block; max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
ul, ol, dl, dd { padding: 0; }
li { list-style: none; }

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

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  /* content must never sit hidden waiting for a reveal animation */
  .js-reveal :is(.section, .reveal):not(.is-visible) {
    opacity: 1 !important;
    transform: none !important;
  }
}

/* visually hidden, available to assistive tech */
.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* -------------------------------------------------------------- skip link -- */
.skip-link {
  position: fixed;
  top: -100px;
  left: 16px;
  z-index: 100;
  padding: 10px 18px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  transition: top 0.2s;

  &:focus-visible { top: 12px; }
}

/* -------------------------------------------------- scroll progress (CSS) -- */
.scroll-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 60;
  background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--anomaly));
  transform-origin: 0 50%;
  transform: scaleX(0);
}

@supports (animation-timeline: scroll()) {
  .scroll-progress {
    animation: progress linear both;
    animation-timeline: scroll(root);
  }
  @keyframes progress { from { transform: scaleX(0); } to { transform: scaleX(1); } }
}

/* ----------------------------------------------------------------- header -- */
.site-head {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px clamp(16px, 4vw, 36px);
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s, background-color 0.3s;

  &.scrolled { border-bottom-color: var(--border); }
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.brand-mark {
  width: 30px;
  height: 30px;

  .bm-node { fill: var(--text-2); }
  .bm-anomaly { fill: var(--anomaly); }
  .bm-edge { stroke: var(--muted); stroke-width: 1.4; fill: none; }
}

.brand-cursor { color: var(--accent); animation: blink 1.15s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.site-nav {
  display: flex;
  gap: clamp(10px, 2vw, 22px);
  margin-inline: auto;
  font-size: 0.92rem;
  font-weight: 500;

  a {
    position: relative;
    color: var(--text-2);
    padding: 6px 2px;
    transition: color 0.2s;

    &::after {
      content: "";
      position: absolute;
      inset: auto 0 0 0;
      height: 2px;
      border-radius: 2px;
      background: linear-gradient(90deg, var(--accent), var(--accent-2));
      transform: scaleX(0);
      transform-origin: 0 50%;
      transition: transform 0.3s var(--ease-out);
    }

    &:hover { color: var(--text); }
    &:hover::after { transform: scaleX(1); }
  }

  .nav-lab { color: var(--accent); }
}

.head-controls { display: flex; align-items: center; gap: 10px; }

.lang-switch {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 3px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.lang-btn {
  padding: 4px 12px;
  border-radius: 999px;
  color: var(--muted);
  transition: color 0.2s, background-color 0.2s;

  &[aria-pressed="true"] {
    color: var(--bg);
    background: var(--accent);
    font-weight: 600;
  }

  &[aria-pressed="false"]:hover { color: var(--text); }
}

.icon-btn {
  display: grid;
  place-items: center;
  min-width: 38px;
  height: 38px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text-2);
  transition: color 0.2s, border-color 0.2s, box-shadow 0.2s;

  svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  &:hover {
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 50%, transparent);
    box-shadow: 0 0 0 3px var(--glow);
  }
}

:root[data-theme="dark"] .ico-sun { display: none; }
:root[data-theme="light"] .ico-moon { display: none; }
:root[data-theme="dark"] .ico-moon { fill: currentColor; stroke: none; }

.kbd-hint {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.menu-btn { display: none; }

/* --------------------------------------------------------- mobile popover -- */
#mobile-menu {
  position: fixed;
  inset: 68px 16px auto auto;
  min-width: 220px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);

  nav { display: grid; }

  a {
    padding: 11px 14px;
    border-radius: var(--radius-s);
    color: var(--text);
    font-weight: 500;

    &:hover { background: var(--surface-2); color: var(--accent); }
  }

  &::backdrop { background: color-mix(in srgb, var(--bg) 45%, transparent); backdrop-filter: blur(3px); }
}

/* ------------------------------------------------------------------- hero -- */
.hero {
  position: relative;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 120px clamp(16px, 5vw, 48px) 80px;
  overflow: clip;
}

#net-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hero-scrim {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 55% at 50% 45%, color-mix(in srgb, var(--bg) 55%, transparent), transparent 30%, transparent),
    linear-gradient(180deg, transparent 55%, var(--bg) 96%);
  pointer-events: none;
}

.hero-inner {
  position: relative;
  max-width: 880px;
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 22px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(6px);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-2);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent);
  animation: pulse 2.2s infinite;
}

@keyframes pulse {
  70% { box-shadow: 0 0 0 9px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.hero-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.1rem, 6.4vw, 4.4rem);
  line-height: 1.08;
  letter-spacing: -0.01em;
  background: linear-gradient(115deg, var(--text) 55%, color-mix(in srgb, var(--accent) 75%, var(--text)) 85%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-role {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px 16px;
  font-family: var(--font-mono);
  font-size: clamp(0.86rem, 2vw, 1.05rem);

  .role-from { color: var(--muted); }
  .role-to {
    color: var(--accent);
    font-weight: 600;
    text-shadow: 0 0 24px var(--glow);
  }
}

.role-arrow {
  width: 44px;
  height: 20px;
  stroke: var(--accent-2);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;

  .ra-line {
    stroke-dasharray: 6 8;
    animation: dash-flow 1.4s linear infinite;
  }
}

@keyframes dash-flow { to { stroke-dashoffset: -14; } }

.hero-tagline {
  max-width: 640px;
  color: var(--text-2);
  font-size: clamp(1rem, 2.1vw, 1.14rem);
  text-wrap: balance;
}

.hero-cta { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin-top: 6px; }

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 26px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.98rem;
  border: 1px solid transparent;
  transition: transform 0.2s var(--ease-out), box-shadow 0.25s, border-color 0.2s, background-color 0.2s, color 0.2s;

  &:active { transform: translateY(1px) scale(0.99); }
}

.btn-primary {
  background: linear-gradient(120deg, var(--accent), var(--accent-deep));
  color: #04121a;

  &:hover { box-shadow: 0 8px 30px -6px var(--glow), 0 0 0 3px var(--glow); transform: translateY(-2px); }
}

:root[data-theme="light"] .btn-primary { color: #ffffff; }

.btn-ghost {
  border-color: var(--border-strong);
  color: var(--text);

  &:hover {
    border-color: color-mix(in srgb, var(--accent) 55%, transparent);
    color: var(--accent);
    transform: translateY(-2px);
  }
}

.btn-small { padding: 9px 16px; font-size: 0.87rem; border-radius: 10px; }

/* hero stats */
.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 720px;
  margin-top: 26px;
}

.hero-stats:empty { display: none; }

.stat {
  display: grid;
  min-width: 0;
  gap: 2px;
  padding: 16px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 66%, transparent);
  backdrop-filter: blur(8px);
  animation: rise 0.7s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 90ms + 200ms);

  .stat-value {
    min-width: 0;
    max-width: 100%;
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: clamp(1rem, 2.2vw, 1.45rem);
    line-height: 1.15;
    overflow-wrap: anywhere;
    color: var(--accent);
    order: -1;
  }

  .stat-label {
    font-size: 0.78rem;
    line-height: 1.35;
    color: var(--muted);
  }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
}

.scroll-hint {
  position: absolute;
  bottom: 22px;
  left: 50%;
  translate: -50% 0;
  display: grid;
  justify-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--muted);

  svg {
    width: 14px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    animation: nudge 1.8s ease-in-out infinite;
  }
}

@keyframes nudge { 50% { transform: translateY(5px); } }

/* --------------------------------------------------------------- sections -- */
.section {
  max-width: var(--maxw);
  margin-inline: auto;
  padding: clamp(64px, 9vh, 110px) clamp(16px, 5vw, 48px) 0;
}

/* reveal choreography — hidden state only when the JS engine is in charge */
.section, .reveal {
  transition: opacity 0.7s var(--ease-out), transform 0.7s var(--ease-out);
  transition-delay: calc(var(--i, 0) * 80ms);
}

.js-reveal :is(.section, .reveal):not(.is-visible) {
  opacity: 0;
  transform: translateY(26px);
}

.js-reveal .section.is-visible .reveal:not(.is-visible) { transition-delay: calc(var(--i, 0) * 80ms + 120ms); }

.section-head { margin-bottom: clamp(28px, 5vh, 46px); }

.kicker {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;

  .kicker-no { color: var(--muted); }

  &::after {
    content: "";
    flex: 0 1 120px;
    height: 1px;
    background: linear-gradient(90deg, var(--border-strong), transparent);
  }
}

h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.55rem, 3.6vw, 2.4rem);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

/* ------------------------------------------------------------------ about -- */
.about-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: clamp(24px, 4vw, 48px);
  align-items: start;
}

.about-text {
  display: grid;
  gap: 18px;
  color: var(--text-2);
  font-size: 1.05rem;

  p::first-letter { color: var(--text); }
}

.term-card {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 0.84rem;
}

.term-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);

  i {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--muted);
    opacity: 0.55;

    &:first-child { background: var(--anomaly); opacity: 0.8; }
    &:nth-child(2) { background: #e8b93e; opacity: 0.8; }
    &:nth-child(3) { background: var(--ok); opacity: 0.8; }
  }

  .term-title { margin-left: 8px; color: var(--muted); font-size: 0.76rem; }
}

.term-body {
  display: grid;
  gap: 10px;
  padding: 18px 16px 20px;
}

.term-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;

  dt { color: var(--muted); }
  dt::before { content: "$ "; color: var(--accent); }
  dd { color: var(--text); overflow-wrap: anywhere; }
}

/* -------------------------------------------------------------- experience -- */
.timeline {
  display: grid;
  gap: 30px;
  padding-left: 24px;
  border-left: 1px solid var(--border-strong);
  margin-left: 8px;
}

.tl-item { position: relative; }

.tl-marker {
  position: absolute;
  left: -30px;
  top: 26px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent), 0 0 18px var(--glow);
}

.tl-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 26px 28px;
  box-shadow: var(--card-shadow);
  transition: border-color 0.25s, transform 0.25s var(--ease-out);

  &:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); transform: translateY(-3px); }
}

.tl-head { display: grid; gap: 4px; margin-bottom: 14px; }

.tl-role { font-size: 1.22rem; font-weight: 700; }

.tl-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-family: var(--font-mono);
  font-size: 0.84rem;

  .tl-company { color: var(--accent); }
  .tl-period { color: var(--muted); }
}

.tl-bullets {
  display: grid;
  gap: 10px;
  color: var(--text-2);
  margin-bottom: 16px;

  li { padding-left: 20px; position: relative; }
  li::before {
    content: "▸";
    position: absolute;
    left: 0;
    color: var(--accent);
  }
}

.tag-row { display: flex; flex-wrap: wrap; gap: 8px; }

.tag {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  background: var(--surface-2);
}

.tag-big { font-size: 0.85rem; padding: 8px 16px; }

/* -------------------------------------------------------------- education -- */
.edu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr));
  gap: 20px;
}

.edu-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 26px 28px;
  box-shadow: var(--card-shadow);
  display: grid;
  gap: 12px;
  align-content: start;
  transition: border-color 0.25s, transform 0.25s var(--ease-out);

  &:hover { border-color: color-mix(in srgb, var(--accent-2) 40%, var(--border)); transform: translateY(-3px); }
}

.edu-period {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.edu-school { font-size: 1.08rem; font-weight: 700; line-height: 1.3; }

.edu-program { color: var(--accent); font-weight: 500; font-size: 0.95rem; }

.edu-details {
  display: grid;
  gap: 8px;
  color: var(--text-2);
  font-size: 0.94rem;

  li { padding-left: 18px; position: relative; }
  li::before { content: "•"; position: absolute; left: 0; color: var(--muted); }
}

.edu-highlight {
  font-size: 0.92rem;
  color: color-mix(in srgb, var(--accent) 80%, var(--text));
  border-top: 1px dashed var(--border-strong);
  padding-top: 12px;
}

/* ----------------------------------------------------------------- skills -- */
.skills-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 26px;
}

.skills-tab {
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  font-weight: 500;
  font-size: 0.92rem;
  transition: all 0.22s var(--ease-out);

  &:hover { color: var(--text); border-color: var(--border-strong); transform: translateY(-1px); }

  &[aria-selected="true"] {
    background: linear-gradient(120deg, var(--accent), var(--accent-deep));
    border-color: transparent;
    color: #04121a;
    font-weight: 600;
    box-shadow: 0 6px 22px -8px var(--glow);
  }
}

:root[data-theme="light"] .skills-tab[aria-selected="true"] { color: #fff; }

.skills-evidence {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: 12px;
  max-width: 920px;
}

.skill-evidence {
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
  padding: 17px 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(135deg, var(--surface), color-mix(in srgb, var(--surface-2) 68%, transparent));
  animation: rise 0.55s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 60ms);
}

.skill-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.skill-name { font-weight: 600; }

.skill-level {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  text-align: right;
}

.skill-hint {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.skills-tags { display: flex; flex-wrap: wrap; gap: 12px; }

.skills-note {
  margin-top: 26px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);

  &::before { content: "# "; color: var(--accent); }
}

/* --------------------------------------------------------------- projects -- */
.proj-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: 20px;
}

.proj-grid:has(> :only-child) {
  grid-template-columns: minmax(0, 840px);
}

.proj-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 28px;
  box-shadow: var(--card-shadow);
  display: grid;
  gap: 14px;
  align-content: start;
  overflow: hidden;
  transition: border-color 0.25s, transform 0.25s var(--ease-out), box-shadow 0.25s;

  &::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2), transparent 80%);
    opacity: 0;
    transition: opacity 0.3s;
  }

  &:hover {
    transform: translateY(-5px);
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
    box-shadow: 0 24px 60px -20px rgb(0 0 0 / 0.5), 0 0 0 1px var(--glow);
  }

  &:hover::before { opacity: 1; }
}

.proj-no {
  position: absolute;
  top: 12px;
  right: 18px;
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 700;
  color: color-mix(in srgb, var(--text) 7%, transparent);
  user-select: none;
}

.proj-name { font-size: 1.18rem; font-weight: 700; line-height: 1.3; padding-right: 48px; }

.proj-blurb { color: var(--text-2); font-size: 0.97rem; }

.proj-facts {
  display: grid;
  gap: 8px;
  padding: 12px 0;
  border-block: 1px dashed var(--border-strong);
}

.proj-fact {
  display: grid;
  grid-template-columns: minmax(76px, 0.42fr) 1fr;
  gap: 12px;
  align-items: baseline;

  dt {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
  }

  dd { color: var(--text); font-size: 0.88rem; }
}

.proj-points {
  display: grid;
  gap: 8px;
  color: var(--text-2);
  font-size: 0.9rem;

  li { padding-left: 18px; position: relative; }
  li::before { content: "▸"; position: absolute; left: 0; color: var(--accent-2); }
}

.proj-links { display: flex; flex-wrap: wrap; gap: 8px; }

.proj-link {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  text-underline-offset: 4px;

  &::after { content: " ↗"; }
  &:hover { color: var(--text); }
}

/* -------------------------------------------------------------------- lab -- */
.lab-section .section-head { margin-bottom: 18px; }

.lab-desc {
  max-width: 760px;
  color: var(--text-2);
  margin-bottom: 30px;
}

.lab-frame {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
  border: 1px solid var(--border-strong);
  border-radius: calc(var(--radius) + 4px);
  background: var(--surface);
  box-shadow: var(--card-shadow);
  padding: 18px;
}

.lab-canvas-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-2);
  overflow: hidden;
  min-height: 380px;
}

#lab-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: manipulation;
}

.lab-main {
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
}

.lab-state-chip {
  position: absolute;
  top: 10px;
  left: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(4px);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-2);
  pointer-events: none;

  &[data-state="active"] { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
  &[data-state="warming-up"] { color: var(--warn); }
  &[data-state="paused"] { color: var(--muted); }
  &[data-state="insufficient-variability"] { color: var(--anomaly); }
}

.lab-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-2);

  .lg { display: inline-flex; align-items: center; gap: 7px; }
  .lg-shape { width: 15px; height: 15px; flex-shrink: 0; }
}

.lab-hint {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--muted);

  &::before { content: "# "; color: var(--accent); }
}

.lab-side {
  display: grid;
  gap: 16px;
  align-content: start;
  min-width: 0;
}

.lab-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.lab-stat {
  display: grid;
  gap: 2px;
  padding: 12px 10px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);

  .lab-stat-v {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 1.15rem;
    color: var(--accent);
  }

  &.bad .lab-stat-v { color: var(--anomaly); }

  .lab-stat-l { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
}

.lab-slider {
  display: grid;
  gap: 8px;

  .lab-slider-head {
    display: flex;
    justify-content: space-between;
    font-size: 0.88rem;
    font-weight: 500;

    output { font-family: var(--font-mono); color: var(--accent); }
  }

  input[type="range"] { accent-color: var(--accent); width: 100%; cursor: ew-resize; }
}

.lab-slider-edges {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
}

.lab-thr-hint {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.lab-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.lab-baseline {
  display: grid;
  gap: 10px;
  justify-items: start;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 14px 16px 16px;
  margin: 0;

  legend {
    font-family: var(--font-mono);
    font-size: 0.74rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0 6px;
  }
}

.lab-check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.9rem;
  cursor: pointer;

  input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
  &:has(input:disabled) { color: var(--muted); cursor: not-allowed; }
  input:disabled { cursor: not-allowed; }
}

.lab-note {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.lab-metrics {
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);

  summary {
    padding: 11px 16px;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-2);

    &:hover { color: var(--text); }
  }

  dl {
    display: grid;
    gap: 7px;
    padding: 4px 16px 14px;
    margin: 0;
  }

  .metric-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.84rem;

    dt { color: var(--text-2); }
    dd { font-family: var(--font-mono); color: var(--text); }
  }
}

.lab-log {
  height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-2);
  padding: 10px 12px;
  scrollbar-width: thin;

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

  ul {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-family: var(--font-mono);
    font-size: 0.74rem;
  }

  li { display: flex; gap: 10px; }

  .log-time { color: var(--muted); flex-shrink: 0; }
  .log-msg { color: var(--text-2); overflow-wrap: anywhere; }
  .log-alert .log-msg { color: var(--anomaly); font-weight: 500; }
  .log-warn .log-msg { color: var(--warn); font-weight: 500; }
}

/* ------------------------------------------------------------------- life -- */
.life-text {
  max-width: 640px;
  color: var(--text-2);
  font-size: 1.05rem;
  margin-bottom: clamp(24px, 4vh, 40px);
}

.gallery {
  position: relative;
  margin-inline: calc(clamp(16px, 5vw, 48px) * -1); /* bleed to viewport edges */
}

.gallery-track {
  display: flex;
  gap: 14px;
  padding-inline: clamp(16px, 5vw, 48px);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-padding-inline: clamp(16px, 5vw, 48px);
}

.gallery-track::-webkit-scrollbar { display: none; }

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

.gallery-item {
  flex: 0 0 auto;
  height: clamp(280px, 46vh, 440px);
  scroll-snap-align: center;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  box-shadow: var(--card-shadow);
}

.gallery-img {
  height: 100%;
  width: auto;              /* keep the photo's natural aspect ratio */
  max-width: none;
  display: block;
  object-fit: cover;
  user-select: none;
  transition: transform 0.4s var(--ease-out);
}

.gallery-item:hover .gallery-img { transform: scale(1.04); }

.gallery-nav {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  color: var(--text);
  box-shadow: var(--card-shadow);
  transition: opacity 0.2s, color 0.2s, border-color 0.2s, transform 0.15s;

  svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

  &:hover:not(:disabled) { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
  &:active:not(:disabled) { transform: translateY(-50%) scale(0.94); }
  &:disabled { opacity: 0; pointer-events: none; }
}

.gallery-prev { left: 10px; }
.gallery-next { right: 10px; }

/* touch devices: hide the arrows, swiping is natural */
@media (hover: none) {
  .gallery-nav { display: none; }
}

/* ---------------------------------------------------------------- contact -- */
.contact-card {
  position: relative;
  border-radius: calc(var(--radius) + 4px);
  padding: clamp(30px, 5vw, 52px);
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    linear-gradient(120deg, color-mix(in srgb, var(--accent) 55%, transparent), color-mix(in srgb, var(--accent-2) 45%, transparent), color-mix(in srgb, var(--anomaly) 35%, transparent)) border-box;
  border: 1px solid transparent;
  box-shadow: var(--card-shadow);
  display: grid;
  gap: 22px;
  justify-items: start;
}

.contact-blurb { max-width: 620px; color: var(--text-2); font-size: 1.05rem; }

.contact-actions { display: flex; flex-wrap: wrap; gap: 12px; }

#contact-email { font-family: var(--font-mono); font-size: 0.92rem; overflow-wrap: anywhere; }

.contact-note {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);

  &::before { content: "// "; color: var(--accent); }
}

/* ----------------------------------------------------------------- footer -- */
.site-foot {
  max-width: var(--maxw);
  margin-inline: auto;
  padding: 70px clamp(16px, 5vw, 48px) 36px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 24px;
  color: var(--muted);
  font-size: 0.84rem;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 7px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-2);
}

/* ---------------------------------------------------------------- palette -- */
.palette {
  margin: 14vh auto auto;
  width: min(580px, calc(100vw - 32px));
  border: 0;
  padding: 0;
  background: transparent;

  &::backdrop {
    background: color-mix(in srgb, var(--bg) 55%, transparent);
    backdrop-filter: blur(6px);
  }
}

.palette-box {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 30px 90px -20px rgb(0 0 0 / 0.6);
  overflow: hidden;
  animation: pal-in 0.22s var(--ease-out);
}

@keyframes pal-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
}

.palette-input {
  width: 100%;
  padding: 18px 20px;
  font: inherit;
  font-size: 1.02rem;
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  outline: none;

  &::placeholder { color: var(--muted); }
}

.palette-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: thin;
}

.pal-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-s);
  cursor: pointer;
  color: var(--text-2);
  text-align: left;
  font-size: 1rem;

  &:hover {
    background: color-mix(in srgb, var(--accent) 8%, transparent);
    color: var(--text);
  }

  &:focus-visible {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--text);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }
}

.pal-ico {
  font-family: var(--font-mono);
  color: var(--accent);
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.pal-label { overflow-wrap: anywhere; }

.pal-empty { padding: 18px 16px; color: var(--muted); font-size: 0.92rem; }

.palette-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.76rem;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------ toast -- */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  translate: -50% 16px;
  z-index: 90;
  padding: 12px 22px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  font-size: 0.92rem;
  box-shadow: var(--card-shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, translate 0.3s var(--ease-out);

  &.show { opacity: 1; translate: -50% 0; }
}

/* --------------------------------------------------------------- noscript -- */
.noscript-note {
  max-width: 720px;
  margin: 40px auto;
  padding: 24px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

/* ------------------------------------------------------- view transitions -- */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.35s;
}

/* -------------------------------------------------------------- scrollbar -- */
@supports (scrollbar-width: thin) {
  html { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
}

/* ------------------------------------------------------------- responsive -- */
@media (max-width: 920px) {
  .site-nav { display: none; }
  .menu-btn { display: grid; }
  .about-grid { grid-template-columns: 1fr; }
  .lab-frame { grid-template-columns: 1fr; }
  .lab-canvas-wrap { min-height: 320px; }
}

@media (max-width: 640px) {
  body { font-size: 1rem; }
  .hero-stats { grid-template-columns: repeat(2, 1fr); }
  .hero-stats .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .kbd-hint { display: none; }
  .palette-btn { min-width: 38px; }
  .palette-btn::after { content: "⌘"; font-size: 0.95rem; }
  .tl-card, .edu-card, .proj-card { padding: 22px 20px; }
  .timeline { padding-left: 18px; margin-left: 4px; }
  .tl-marker { left: -24px; }
  .term-row { grid-template-columns: 96px 1fr; }
  .lab-stats { grid-template-columns: repeat(3, 1fr); gap: 7px; }
  .site-foot { flex-direction: column; }
}

/* ------------------------------------------------------------------ print -- */
@media print {
  .site-head, .scroll-progress, .scroll-hint, .lab-section, .site-foot .foot-hint,
  #net-canvas, .hero-scrim, .hero-cta, .palette, .toast { display: none !important; }

  body { background: #fff; color: #000; }
  .section, .reveal { opacity: 1; transform: none; }
  .hero { min-height: auto; padding: 40px 0 0; }
  .hero-name { color: #000; background: none; -webkit-text-fill-color: initial; }
  .tl-card, .edu-card, .proj-card, .term-card, .contact-card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}
