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

:root {
  /* Palette */
  --ink-900: #06141b;
  --ink-800: #11212d;
  --slate-700: #253745;
  --slate-600: #4a5c6a;
  --mist-300: #9ba8ab;
  --mist-100: #ccd0cf;
  /* Roles: darkest two = background and blocks, middle two = accents,
     lightest two = text */
  --page-bg: var(--ink-900);
  --surface: var(--ink-800);
  --surface-hover: var(--slate-700);
  --accent: var(--slate-600);
  --accent-soft: rgba(74, 92, 106, 0.5);  /* hairlines and borders */
  /* text runs one step lighter than the palette's mist tones, so smaller
     copy holds up against the dark panels */
  --text: #dfe3e2;                        /* body copy, headings, buttons */
  --text-muted: #adb8bb;                  /* collapsed titles, labels */

  --inset: clamp(10px, 3.5vw, 48px);
  --gap: clamp(6px, 0.8vw, 12px);
  --radius: clamp(14px, 1.6vw, 22px);
  --pad: clamp(16px, 3vw, 30px);
  --ease: cubic-bezier(0.65, 0, 0.35, 1);
}

html {
  overflow-x: hidden;
  scrollbar-gutter: stable;
  /* thin slate scrollbar (inherited by the gallery strips too) */
  scrollbar-width: thin;
  scrollbar-color: var(--slate-600) var(--page-bg);
}
.gallery {
  scrollbar-width: thin;
}
/* Safari, and Chromium before scrollbar-color (v121) */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--page-bg);
}
::-webkit-scrollbar-thumb {
  background: var(--slate-600);
  border-radius: 999px;
  border: 2px solid var(--page-bg);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--mist-300);
}
body {
  background: var(--page-bg);
  font-family: 'Open Sans', Helvetica, Arial, sans-serif;
  color: var(--text);
}

#wind {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: -1;
  background: var(--page-bg);
  pointer-events: none;
}

/* ==== Panels ====
   Without JS, or with reduced motion, this is a plain page: four stacked
   sections, all open, in normal document flow. js/index.js upgrades it to
   the scroll-driven stage (html.is-stage, further down). */
.stage {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--inset);
}
.panel {
  position: relative;
  scroll-margin-top: var(--inset);
}
.panel__frame {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--accent-soft);
  transition: background-color 0.4s;
}
.panel__clip {
  position: relative;
}
.panel__title {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: clamp(24px, 3vw, 40px);
  line-height: 1;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  padding: var(--pad);
  color: var(--text);
}
.panel__title a {
  color: inherit;
  text-decoration: none;
  border-radius: 6px;
}
.panel__body {
  padding: 0 var(--pad) calc(var(--pad) * 1.5);
}

/* ---- Panel content ---- */
/* readable measure for long text, centred in wide panels */
.panel__body > * {
  max-width: 46rem;
  margin-left: auto;
  margin-right: auto;
}
.panel__body > * + * {
  margin-top: 1.5em;
}
.panel__body p,
.panel__body li {
  font-size: clamp(15px, 1.1vw, 17px);
  line-height: 1.65;
}
.panel__body a {
  color: var(--text);
  text-decoration-color: var(--accent);
  text-underline-offset: 3px;
}
.panel__body a:hover {
  text-decoration-color: var(--text-muted);
}
.panel__lede {
  font-size: clamp(17px, 1.5vw, 21px) !important;
  color: var(--text);
}

/* ---- Keyboard focus ---- */
:focus-visible {
  outline: 2px solid var(--text-muted); /* the slate accents are too dark for a focus ring */
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Panel content blocks ---- */
.panel__h3 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(20px, 1.8vw, 26px);
  color: var(--text);
  margin-bottom: 0.5em;
}
.panel__body section > * + * {
  margin-top: 0.75em;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.panel__body .btn {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 18px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  /* every button is the same slate blue (palette #253745) */
  background: var(--slate-700);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.2s, border-color 0.2s;
}
.panel__body .btn:hover {
  background: var(--accent);
  border-color: var(--text-muted);
}
.entry__head,
.entry__sub {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 16px;
}
.entry__head span,
.entry__sub span {
  color: var(--text-muted);
}
.entry__sub {
  font-style: italic;
  color: var(--text-muted);
}
.entry ul,
.resume-projects {
  padding-left: 1.2em;
}
.entry ul {
  margin-top: 0.5em;
}
.resume-projects span {
  color: var(--text-muted);
  font-size: 0.9em;
}
.skills {
  display: grid;
  grid-template-columns: minmax(0, 13em) 1fr;
  gap: 8px 18px;
  font-size: clamp(15px, 1.1vw, 17px);
  line-height: 1.55;
}
.skills dt {
  color: var(--text-muted);
}
@media (max-width: 560px) {
  .skills {
    grid-template-columns: 1fr;
    gap: 2px;
  }
  .skills dd {
    margin-bottom: 10px;
  }
}

/* ---- Projects: jump list, then one article per project laid out as
   gallery -> overview -> methodology -> results -> links ---- */
.project-index ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
/* same slate blue as the buttons */
.project-index a {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--slate-700);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.2s, border-color 0.2s;
}
.project-index a:hover {
  background: var(--accent);
  border-color: var(--text-muted);
}
.project {
  padding-top: 1.5em;
  border-top: 1px solid var(--accent-soft);
  scroll-margin-top: 12px;
}
.project__title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(22px, 2.2vw, 30px);
  color: var(--text);
  margin-bottom: 0.25em;
}
.project__meta {
  color: var(--text-muted);
  font-size: 14px !important;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
/* swipeable strip on phones, wraps into a grid when there's room */
.gallery {
  list-style: none;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(78%, 1fr);
  gap: 10px;
  margin: 1em 0 1.5em;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
}
@media (min-width: 700px) {
  .gallery {
    grid-auto-flow: row;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    overflow: visible;
  }
}
.gallery li {
  scroll-snap-align: start;
}
.gallery figure {
  margin: 0;
}
.gallery__link {
  display: block;
  border-radius: 10px;
}
.gallery__media {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: contain; /* charts: show the whole figure, never crop */
  padding: 6px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--accent-soft);
  transition: transform 0.3s var(--ease);
}
.gallery__link:hover .gallery__media {
  transform: scale(1.02);
}
.gallery figcaption {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
.project__meta + .project__section,
.project__section + .project__section {
  margin-top: 1.25em;
}
.project__section h4,
.project__section h5 {
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.4em;
}
.project__section ul {
  padding-left: 1.2em;
}
.project__links ul {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}

/* ---- Currently Building: same article styling, plus a status badge ---- */
.wip {
  padding-top: 1.5em;
  border-top: 1px solid var(--accent-soft);
  scroll-margin-top: 12px;
}
.wip > p {
  color: var(--text-muted);
}
.wip .project {
  margin-top: 1.5em;
}
.badge {
  display: inline-block;
  margin-right: 8px;
  padding: 2px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--surface-hover);
  color: var(--text);
  font-size: 12px;
  letter-spacing: 0.06em;
  vertical-align: 1px;
}
/* prerecorded output, labelled as a sample */
.sample {
  margin: 1em 0 1.5em;
}
.sample__output {
  overflow-x: auto;
  padding: 14px 16px;
  border: 1px solid var(--accent-soft);
  border-radius: 10px;
  background: var(--page-bg);
  color: var(--text);
  font: 13px/1.5 ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace;
}
.sample figcaption {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---- Embedded demo: preview + "Load Interactive Demo" first ---- */
.demo {
  margin: 1em 0 1.5em;
}
.demo__stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--accent-soft);
  border-radius: 10px;
  background: var(--page-bg);
}
.demo__preview {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: linear-gradient(135deg, var(--slate-700), var(--ink-800));
}
.demo__frame {
  display: block;
  width: 100%;
  height: var(--demo-h, 560px);
  border: 0;
  background: #fff;
}
.demo .actions {
  margin-top: 10px;
}
/* Over a loaded demo, the wheel and touch keep scrolling the page until the
   visitor clicks in to use it; moving the pointer away hands it back. */
.demo__shield {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.demo__shield span {
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(6, 20, 27, 0.85);
  border: 1px solid var(--accent);
  font-size: 13px;
}
.demo.is-active .demo__shield {
  display: none;
}
.demo__status {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

/* Home: selected work, one result per line */
.selected-work {
  list-style: none;
}
.selected-work li {
  padding: 10px 0;
  border-top: 1px solid var(--accent-soft);
}
.selected-work li:last-child {
  border-bottom: 1px solid var(--accent-soft);
}
.selected-work a {
  font-weight: 600;
}
/* the headline numbers, for scanning */
.selected-work strong {
  font-weight: 700;
  color: #f2f4f3;
}

/* Home's opening line */
.display {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: clamp(30px, 4.4vw, 56px) !important;
  line-height: 1.1 !important;
  color: var(--text);
}

/* ==== Scroll-driven stage ====
   The panels sit in a fixed stage; the page scrolls over an invisible
   runway. js/index.js maps the scroll position onto every panel each frame:
   its position, open height (clip-path, no re-layout), the title moving
   from the centre of a collapsed card to the top-left of an open panel, and
   the content offset - so the open panel's content scrolls 1:1 with the
   page, and nothing has its own scrollbar. */
html.is-stage .stage {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  padding: 0;
  z-index: 1;
  animation: stage-in 0.9s var(--ease) both;
}
@keyframes stage-in {
  from { opacity: 0; transform: translate3d(0, 14px, 0); }
}
html.is-stage .panel {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}
html.is-stage .panel__frame {
  bottom: auto; /* height is set per frame */
}
html.is-stage .panel__clip {
  position: absolute;
  inset: 0;
  overflow: clip; /* clip, not hidden: focus can't scroll it behind our back */
  will-change: clip-path;
}
/* hairline under the open panel's title */
html.is-stage .panel__clip:before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: var(--head-h);
  height: 1px;
  background: var(--accent-soft);
  opacity: var(--e, 0);
}
html.is-stage .panel__title {
  position: absolute;
  left: 0;
  top: 0;
  padding: 0;
  white-space: nowrap;
  font-size: var(--title-size);
  transform-origin: 0 0;
  will-change: transform;
  /* grey while collapsed, full text colour once open */
  color: color-mix(in srgb, var(--text) calc(var(--e, 1) * 100%), var(--text-muted));
  transition: color 0.3s;
}
html.is-stage .panel__viewport {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--head-h);
  bottom: 0;
  overflow: clip;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 20px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 20px);
}
html.is-stage .panel__body {
  padding-top: 20px;
  will-change: transform, opacity;
}
html.is-stage .panel.is-collapsed {
  cursor: pointer;
}
html.is-stage .panel.is-collapsed:hover .panel__frame {
  background: var(--surface-hover);
}
html.is-stage .panel.is-collapsed:hover .panel__title {
  color: var(--text);
}
.stage-runway {
  pointer-events: none;
}
