/* ==========================================================================
   Layout — responsive shell, works grid, work detail, about
   (Figma: "Portfolio" › responsive board, node 1393:52960)

   < 45em   (720)   top bar + menu, 1 column, content max 560
   ≥ 45em   (720)   top bar + menu, 2 columns, content max 960
   ≥ 69em   (1104)  sidebar; content max 960, centered in the area right of
                    the sidebar with ≥ 48px on each side
   ≥ 110em  (1760)  content centered on the whole screen (the gap to the
                    sidebar is ≥ 80px from here on)  — measured on `.main`
   Text/details sit side by side once the page is ≥ 59em (944) wide.
   ========================================================================== */

.site {
  min-height: 100vh;
  padding-top: 3.5rem; /* the fixed top bar's height */
}

/* Top bar + menu (narrow screens) ----------------------------------------- */

/* Fixed, not sticky: on iOS a sticky bar is dragged down by the rubber-band
   overscroll at the top of the page (while the fixed menu button stays put),
   and lags behind when Safari's toolbar collapses or expands, letting the
   page show through above it. .site reserves its height instead. */
.topbar {
  position: fixed;
  top: 0;
  inset-inline: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  height: 3.5rem;      /* 56px */
  padding-inline: var(--space-4);
  background: var(--bg-sidebar);
  view-transition-name: topbar;
}

/* Paint the bar's color above it too, so any gap that opens between the
   browser's toolbar and the bar (overscroll, toolbar animation) is filled
   with the bar instead of showing the page underneath. */
.topbar::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: 100%;
  height: 100vh;
  background: inherit;
  pointer-events: none;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;        /* 12px */
}

.topbar__name {
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

.menu-button {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 40;         /* above the drawer and the scrim, like the frames */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;
  background: var(--bg-sidebar);
  color: var(--text-secondary);
  transition: color var(--dur-fast) var(--ease-out);
  view-transition-name: menu-button;
}

.menu-button:hover {
  color: var(--text-primary);
}

.menu-button svg {
  width: var(--icon);
  height: var(--icon);
}

/* ☰ → ✕ morph. Each bar is 13.33px long, exactly the length of a ✕ diagonal
   (9.43px across × 9.43px down), so the outer bars move to the centre line and
   turn ±45° about the icon's centre (10, 10); the middle bar shrinks away.
   Transforms read right-to-left: translate to y = 10 first, then rotate. */
.menu-icon__bar {
  stroke: currentColor;
  stroke-width: 1.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform-box: view-box;
  transform-origin: 10px 10px;
  transition:
    transform var(--dur) var(--ease-morph),
    opacity var(--dur-fast) var(--ease-out);
}

:root.menu-open .menu-icon__bar--top {
  transform: rotate(45deg) translateY(5.8333px);
}

:root.menu-open .menu-icon__bar--bottom {
  transform: rotate(-45deg) translateY(-5.8333px);
}

:root.menu-open .menu-icon__bar--mid {
  opacity: 0;
  transform: scaleX(0);
}

@media (prefers-reduced-motion: reduce) {
  .menu-icon__bar {
    transition: none;
  }
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgb(0 0 0 / 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease-out);
}

:root.menu-open .scrim {
  opacity: 1;
  pointer-events: auto;
}

/* Lock the page behind the open menu */
:root.menu-open {
  overflow: hidden;
}

/* Sidebar: an off-canvas drawer on narrow screens -------------------------- */

.sidebar {
  position: fixed;
  inset-block: 0;
  left: 0;
  z-index: 30;
  width: min(var(--sidebar-width), 100vw - 3.5rem); /* always leave the close button clear */
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--scrollbar-thumb-sidebar) transparent;
  display: flex;
  flex-direction: column;
  justify-content: space-between; /* social + theme at the bottom when there's room */
  gap: var(--space-12);           /* …and at least 48px below the nav when there isn't */
  padding: var(--space-4) var(--space-12) var(--space-12);
  background: var(--bg-sidebar);
  transform: translateX(-100%);
  visibility: hidden;  /* closed menu is out of the tab order */
  transition:
    transform var(--dur) var(--ease-out),
    visibility 0s linear var(--dur);
}

/* With a mouse, the sidebar's scrollbar only shows while the pointer is over
   the sidebar (or keyboard focus is in it — not mouse focus, which would
   keep it showing after a click on the theme toggle). The thumb just turns transparent,
   so its space stays reserved and nothing shifts when it appears. */
@media (hover: hover) {
  .sidebar:not(:hover, :has(:focus-visible)) {
    scrollbar-color: transparent transparent;
  }
}

:root.menu-open .sidebar {
  transform: none;
  visibility: visible;
  transition: transform var(--dur) var(--ease-out);
}

.sidebar__top {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.brand__logo {
  width: 1.5rem;
  height: 1.5rem;
  color: var(--accent);
}

.brand__logo svg {
  width: 1.5rem;
  height: 1.5rem;
}

.brand__text {
  display: flex;
  flex-direction: column;
}

.brand__name {
  font-weight: 500;
  color: var(--text-primary);
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.nav-group__label {
  color: var(--text-tertiary);
}

.nav-group__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.nav-link {
  position: relative;
  display: block;
  color: var(--text-secondary);
  transition: color var(--dur-fast) var(--ease-out);
}

.nav-link:hover {
  color: var(--text-primary);
}

.nav-link[aria-current="page"] {
  font-weight: 600;
  color: var(--text-primary);
}

/* Active marker: 4×20px bar sitting in the sidebar padding, 16px left of the text */
.nav-indicator {
  position: absolute;
  left: -1rem;     /* -16px */
  top: 0.125rem;   /* 2px */
  width: 0.25rem;  /* 4px */
  height: 1.25rem; /* 20px */
  background: var(--text-primary);
  view-transition-name: nav-indicator;
}

.sidebar__bottom {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

.social-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.social-list li {
  display: flex;
}

.icon-row {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out);
}

.icon-row:hover {
  color: var(--text-primary);
}

.icon-box {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--icon-box);
  height: var(--icon-box);
}

.icon-box svg {
  width: var(--icon);
  height: var(--icon);
}

.social-list .icon-box {
  color: var(--text-tertiary);
  transition: color var(--dur-fast) var(--ease-out);
}

.social-list .icon-row:hover .icon-box,
.social-list .icon-row:focus-visible .icon-box {
  color: var(--text-secondary);
}

/* Brand color on hover/focus (per-theme shades in tokens.css) */
.social-list .icon-row--dribbble:is(:hover, :focus-visible) .icon-box { color: var(--brand-dribbble); }
.social-list .icon-row--twitter:is(:hover, :focus-visible) .icon-box  { color: var(--brand-twitter); }
.social-list .icon-row--linkedin:is(:hover, :focus-visible) .icon-box { color: var(--brand-linkedin); }

/* Theme toggle: icon + label follow the active theme, no JS needed for display */
.theme-toggle {
  align-self: flex-start;
  /* Rapid clicking shouldn't select the label */
  -webkit-user-select: none;
  user-select: none;
}

.theme-toggle .when-light,
:root[data-theme="dark"] .theme-toggle .when-dark {
  display: contents;
}

.theme-toggle .when-dark,
:root[data-theme="dark"] .theme-toggle .when-light {
  display: none;
}

/* Main column -------------------------------------------------------------- */

.main {
  /* Size container for the widest rule: measures the real page width without
     the scrollbar (100vw would include it). Kept off .site because a size
     container also anchors position: fixed children (the menu, scrim, button). */
  container: main / inline-size;
  min-width: 0;
  /* Opaque, so a page sliding in during a transition covers the one beneath */
  background: var(--bg-main);
  padding: var(--space-12) var(--space-2); /* 48 below the bar (as on desktop), 8px gutters */
}

.page {
  container-type: inline-size; /* text/details layout depends on the page's own width */
  max-width: 35rem;            /* 560: one column */
  margin-inline: auto;
}

/* Homepage introduction above the works: text measure, 48px down to "Works" */
.intro {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: calc(var(--col-text) + 2 * var(--text-inset)); /* 544px of text */
  margin-bottom: var(--space-12);
  padding-inline: var(--text-inset);
  color: var(--text-primary);
}

.intro p {
  text-wrap: balance; /* over base.css's "pretty" for paragraphs */
}

.intro__greeting {
  font-weight: 600;
}

/* A full-width divider between the intro and the works, 48px either side */
.intro + .page-title {
  padding-top: calc(var(--space-12) - 1px); /* the 1px rule sits inside the 48px */
  border-top: 1px solid var(--border);
}

.page-title {
  padding-inline: var(--text-inset);
  margin-bottom: var(--space-6);
  font-size: var(--text-md);
  line-height: var(--text-md-lh);
  font-weight: 600;
  color: var(--text-primary);
}

/* Shrink-wrapped title so card caption and page heading can morph into each other */
.vt-title {
  display: inline-block;
  view-transition-class: work-title;
}

.media {
  position: relative;
  overflow: hidden;
  background: var(--media-placeholder);
}

.media > img,
.media > video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* The hover video sits UNDER the poster at full opacity; the poster fades out
   once the video is playing. Not the other way round: Firefox on macOS moves a
   video to the system video layer (slightly different colours) only once it is
   fully opaque, so a video fading in visibly shifts brightness a moment into
   playback. Under the poster that switch happens unseen. */
.media > .hover-video {
  position: absolute;
  inset: 0;
}

.media > img {
  position: relative;
  z-index: 1;
  transition: opacity 240ms var(--ease-out);
}

.media.is-playing > img {
  opacity: 0;
}

/* Play button on work-page hero videos — touch screens only (no hover there).
   Created by transitions.js; hidden while the video plays. */
.video-play {
  position: absolute;
  z-index: 2; /* above the poster */
  inset: 0;
  margin: auto;
  display: grid;
  place-items: center;
  width: var(--space-12);
  height: var(--space-12);
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--white);
  background: rgb(34 36 34 / 0.55); /* moss-950 */
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity var(--dur) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.video-play svg {
  width: var(--space-6);
  height: var(--space-6);
  margin-left: 2px; /* optical centre of the triangle */
}

.video-play:active {
  transform: scale(0.92);
}

.video-play:focus-visible {
  outline: 2px solid var(--white);
  outline-offset: 2px;
}

.work-hero.is-active .video-play {
  opacity: 0;
  pointer-events: none;
}

@media (hover: hover) {
  .video-play {
    display: none;
  }
}

/* During a media handoff the incoming element must be see-through until its
   first frame is decoded, so the outgoing frozen frame shows beneath it. */
.media.is-handoff,
:root.vt .media:has(> img, > video) {
  background: transparent;
  transition: none;
}

.media.is-handoff > img {
  visibility: hidden;
  transition: none;
}

/* Works grid (home) -------------------------------------------------------- */

.works-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-6);
}

.work-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.work-card__media {
  aspect-ratio: 464 / 261; /* 16:9 */
  view-transition-class: work-media;
}

.work-card__title {
  padding-inline: var(--text-inset);
  color: var(--text-secondary);
  transition: color var(--dur-fast) var(--ease-out);
}

.work-card:hover .work-card__title {
  color: var(--text-primary);
}

/* Work detail -------------------------------------------------------------- */

.work-hero {
  aspect-ratio: 16 / 9; /* 960 × 540 */
  margin-bottom: var(--space-6);
  view-transition-class: work-media;
}

/* Stacked: details (or photo) first, text below */
.split {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
  padding-inline: var(--text-inset);
}

.split > * {
  max-width: var(--col-text); /* 544 */
}

.split--about {
  gap: var(--space-6);
}

.work-body {
  color: var(--text-primary);
}

.meta {
  display: flex;
  flex-direction: column;
  gap: 1.5rem; /* 24px */
}

/* Each group: 4px top padding (optically aligns the small caption with the
   text column's first line), caption label, 4px gap, value */
.meta > div {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);       /* 4px */
  padding-top: var(--space-1);
}

/* Label in the caption style (same as the sidebar's section labels) */
.meta dt {
  font-size: var(--caption);
  line-height: var(--caption-lh);
  letter-spacing: var(--caption-tracking);
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.meta dd {
  font-weight: 500;
  color: var(--text-primary);
}

/* "More works" at the end of a work page: the previous and next work in the
   sidebar order, as homepage cards (without the hover video). A full-width
   divider 48px below the last section, then 48px to the heading. */
.more-works {
  margin-top: var(--space-12);
  padding-top: var(--space-12);
  border-top: 1px solid var(--border);
}

.ext-link {
  display: inline-flex;
  align-items: center;
  gap: 0; /* the icon's 24px box already gives it room */
  color: var(--link);
  transition: color var(--dur-fast) var(--ease-out);
}

/* Hover: a step deeper in light mode, a step brighter in dark */
.ext-link:hover {
  color: var(--link-hover);
}

/* Links inside running text and captions (also when a caption is shown in the
   image viewer): the same link colours, eased the same way */
:is(.page :is(p, figcaption), .lightbox__caption) a:not([class]) {
  color: var(--link);
  transition: color var(--dur-fast) var(--ease-out);
}
:is(.page :is(p, figcaption), .lightbox__caption) a:not([class]):hover {
  color: var(--link-hover);
}

/* The outgoing-link icon is 16px inside its 24px box, smaller than other icons */
.ext-link .icon-box svg {
  width: 1rem;
  height: 1rem;
}

/* Several links on one line, separated by a 1px divider with 8px either side */
.link-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  list-style: none;
  margin: 0;
  padding: 0;
}

.link-list > li + li {
  padding-inline-start: var(--space-2);
  border-inline-start: 1px solid var(--border);
}

/* About -------------------------------------------------------------------- */

.about-photo {
  /* Stacked: flush with the media edge (not the text inset), up to 344px */
  width: calc(100% + 2 * var(--text-inset));
  max-width: 21.5rem;
  margin-inline-start: calc(-1 * var(--text-inset));
  height: auto; /* the width/height attributes would otherwise pin it at 304 */
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--media-placeholder);
}

/* Responsive ---------------------------------------------------------------- */

/* Two columns (still with the top bar) */
@media (min-width: 45em) {
  .page {
    max-width: var(--content-max); /* 960 */
  }

  .works-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-8);
  }

  .work-hero {
    margin-bottom: var(--space-8);
  }
}

/* Text and details side by side when the page fits 544 + 96 + 304 (+ insets) */
@container (min-width: 59em) {
  .work-hero {
    margin-bottom: var(--space-12);
  }

  /* 8 | 544 text | 96 | 304 details/photo | 8  (= 960) */
  .split {
    display: grid;
    grid-template-columns: minmax(0, 544fr) minmax(0, 304fr);
    column-gap: var(--col-gap);
    align-items: start;
  }

  .split > * {
    max-width: none;
    grid-row: 1;
  }

  .split > .meta,
  .split > .about-photo {
    grid-column: 2;
  }

  .about-photo {
    width: 100%;
    max-width: none;
    margin-inline-start: 0;
  }
}

/* Sidebar layout */
@media (min-width: 69em) {
  .site {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

  .topbar,
  .menu-button,
  .scrim {
    display: none;
  }

  /* Two independent scroll areas: the window itself never scrolls; the sidebar
     and the content column each scroll on their own (scrollbar only when they
     overflow), and scrolling one never chains into the other. */
  :root {
    overflow: hidden;
    scrollbar-gutter: auto; /* nothing to reserve: the window doesn't scroll */
  }

  .site {
    height: 100vh;
    height: 100dvh;
    padding-top: 0; /* no top bar here */
  }

  .sidebar {
    position: relative;
    z-index: auto;
    width: auto;
    height: 100%;
    padding: var(--space-12);
    transform: none;
    visibility: visible;
    transition: none;
  }

  /* 48px around the content; it centers in what's left (80px at 1440) */
  .main {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable; /* content doesn't shift when a page is short */
    padding: var(--space-12);
  }
}

/* From 1760px the content is centered on the whole screen, ignoring the
   sidebar: x = (screen − 960) / 2, i.e. 400 at 1760.
   Measured on .main's content box (C = screen − 320 − 2×48), so
   screen ≥ 1760  ⇔  C ≥ 1344 (84em), and the left margin inside .main is
   (screen − 960) / 2 − 320 − 48  =  C / 2 − 640  =  50cqw − 40rem. */
@media (min-width: 69em) {
  @container main (min-width: 84em) {
    .page {
      margin-left: calc(50cqw - 40rem);
      margin-right: auto;
    }
  }
}

/* ---------------------------------------------------------------------------
   Image viewer (assets/js/lightbox.js). Opt in with <img data-zoom> (or, for an
   in-page video, <div class="shot__video media" data-zoom>): the image, in its
   matte, grows out of the page together with its caption, over the page
   background; several on a page become a set with previous / next.
   --------------------------------------------------------------------------- */
img[data-zoom],
.shot__video[data-zoom],
.work-hero.has-viewer {
  cursor: zoom-in;
}

:root.lightbox-open {
  overflow: hidden; /* html keeps scrollbar-gutter: stable, so nothing shifts */
}

.lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-primary);
  overflow: hidden;
}
.lightbox:focus {
  outline: none;
}
.lightbox[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.lightbox::backdrop {
  background: none;
}

/* The content background, faded in over the page */
.lightbox__scrim {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg-main);
}

/* Top: counter and close. Bottom: previous / next. Fixed heights, whatever the caption. */
.lightbox__top,
.lightbox__bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
}
.lightbox__count {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.lightbox__btn {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: 0; /* square, in the matte's tone, like the image frames */
  background: var(--media-placeholder);
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.lightbox__top .lightbox__btn {
  margin-left: auto;
}
@media (hover: hover) {
  .lightbox__btn:hover {
    background: color-mix(in srgb, var(--text-primary) 8%, var(--media-placeholder));
  }
}
.lightbox__btn:active {
  background: color-mix(in srgb, var(--text-primary) 14%, var(--media-placeholder));
  transition-duration: 0s; /* instant on press, eases back on release */
}

.is-single .lightbox__count,
.is-single .lightbox__bottom {
  visibility: hidden;
}

/* Previous, current and next side by side, the current one in view */
.lightbox__stage {
  position: relative;
  min-width: 0; /* stays the screen's width when its overflow opens up during the morph */
  min-height: 0;
  overflow: hidden;
  touch-action: pan-y pinch-zoom; /* sideways swipes move between images */
}
.lightbox__track {
  display: flex;
  height: 100%;
  translate: -100% 0;
}
.is-single .lightbox__track {
  translate: none;
}
.lightbox__slide {
  flex: 0 0 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding-inline: var(--space-2); /* the page's own gutter on phones, so the caption wraps the same */
}

/* The figure as on the page: image in its matte, caption below, left-aligned with
   the same inset. lightbox.js sets the width so the whole figure fits. */
.lightbox__figure {
  flex: none;
  max-width: 100%;
}
.lightbox__matte {
  position: relative;
  padding: var(--matte, var(--space-2));
  background: var(--media-placeholder);
}
/* The full-size image, laid over the one on screen once it's decoded (lightbox.js) */
.lightbox__matte img.lightbox__hi {
  position: absolute;
  top: var(--matte, var(--space-2));
  left: var(--matte, var(--space-2));
  width: calc(100% - 2 * var(--matte, var(--space-2)));
  height: calc(100% - 2 * var(--matte, var(--space-2)));
  aspect-ratio: auto;
}
/* The hero video (moved in from the page) and a still of its frame, over its poster */
.lightbox__matte .lightbox__still,
.lightbox__matte video {
  position: absolute;
  top: var(--matte, var(--space-2));
  left: var(--matte, var(--space-2));
  width: calc(100% - 2 * var(--matte, var(--space-2)));
  height: calc(100% - 2 * var(--matte, var(--space-2)));
  object-fit: cover;
}
.lightbox__matte video {
  cursor: pointer;
}
.lightbox__matte img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: var(--ratio, 16 / 9);
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}
.lightbox__caption {
  max-width: var(--col-text);
  margin-top: var(--space-4);
  padding-inline: var(--text-inset);
  color: var(--text-secondary);
}
.lightbox__caption:empty {
  display: none;
}
.lightbox__caption .shot__title {
  font-weight: 600;
  color: var(--text-primary);
}

/* While growing out of / shrinking into the page, the figure may sit anywhere on screen */
.lightbox.is-morphing,
.lightbox.is-morphing .lightbox__stage {
  overflow: visible;
}
.lightbox.is-morphing .lightbox__slide:not(.is-current) {
  visibility: hidden;
}

@media (min-width: 45em) {
  .lightbox__top,
  .lightbox__bottom {
    padding: var(--space-6);
  }
  .lightbox__slide {
    padding-inline: var(--space-6);
  }
}
