/* ============================================================
   WORKS GALLERY — /works/, /works/<field>/, /works/<work>/
   ============================================================
   Loaded only on the gallery pages, after styles.css, so it reuses the
   site's tokens (colours, radii, spacing, type) and never touches the rest
   of the site. Order: tokens → head and fields → tiles → archive → shared
   blocks → work page → gallery → lightbox → diagrams → motion → print.

   Contracts kept from styles.css: no text truncation, no fixed heights on
   text, every interactive target at least 44px, both themes through tokens
   only, everything readable with motion reduced and without JavaScript.
   ============================================================ */

.page-works {
  --w-gap: clamp(16px, 2vw, 28px);
  --w-row-gap: clamp(28px, 3.4vw, 44px);
  --w-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --w-scrim: rgba(17, 17, 15, 0.66);
  --w-lift: 0 2px 4px rgba(0, 0, 0, 0.05), 0 22px 44px -26px rgba(28, 26, 23, 0.42);
}
html.dark .page-works {
  --w-lift: 0 2px 4px rgba(0, 0, 0, 0.3), 0 22px 44px -26px rgba(0, 0, 0, 0.8);
}

/* ---------------------------------------------------------- head */
.works-head { padding-block: clamp(28px, 4vw, 64px) clamp(20px, 2.6vw, 36px); }
.works-head h1 { max-width: 17ch; }
.works-head .page-head__lead { margin-bottom: 0; }
.works-head__stats { margin: var(--s-5) 0 0; color: var(--ink-3); }

/* ---------------------------------------------------------- fields */
.works-groups { border-block: var(--line-w-1) solid var(--line); }
.works-groups__row {
  display: flex; flex-wrap: wrap; gap: var(--s-2);
  padding-block: var(--s-4);
}
.works-groups a {
  flex: none;
  display: inline-flex; align-items: center; gap: var(--s-2);
  min-height: 44px; padding: 0 var(--s-4);
  border: var(--line-w-1) solid var(--line-strong); border-radius: var(--radius-pill);
  color: var(--ink-2); text-decoration: none;
  font-size: var(--text-sm); line-height: 1.2; white-space: nowrap;
  transition: border-color 160ms ease, color 160ms ease, background-color 160ms ease;
}
.works-groups a .mono { color: var(--ink-3); font-size: 0.75rem; letter-spacing: 0.04em; }
.works-groups a:hover { border-color: var(--ink); color: var(--ink); }
.works-groups a[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.works-groups a[aria-current="page"] .mono { color: color-mix(in srgb, var(--bg) 72%, transparent); }

@media (max-width: 760px) {
  /* One swipeable row on phones: seven fields would otherwise take half a screen. */
  .works-groups__row {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter);
    scroll-padding-inline: var(--gutter);
    mask-image: linear-gradient(90deg, transparent 0, #000 var(--gutter), #000 calc(100% - 28px), transparent);
  }
  .works-groups__row::-webkit-scrollbar { display: none; }
}

/* ---------------------------------------------------------- tiles */
.works-showcase { padding-block: clamp(28px, 4vw, 56px) var(--space); }
.works-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--w-row-gap) var(--w-gap);
}
.work-tile { grid-column: span 2; min-width: 0; }
.work-tile--lead { grid-column: span 3; }
/* Tiles after the two leads are laid out when they come near the viewport:
   the gallery's layout work at load halves on a phone. `auto` keeps the
   real height once a tile has been rendered, so the scrollbar stays put. */
.work-tile:not(.work-tile--lead) { content-visibility: auto; contain-intrinsic-size: auto 440px; }
.work-tile--cta { grid-column: span var(--cta-span, 2); }

@media (max-width: 1099px) {
  .works-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .work-tile, .work-tile--lead { grid-column: span 1; }
  /* The call-to-action closes the grid: it fills the last free cell, or takes
     a full row when the tiles already end on an even row. */
  .work-tile--cta { grid-column: span 1; }
  .work-tile--cta:nth-child(odd) { grid-column: 1 / -1; }
}
@media (max-width: 639px) {
  .works-grid { grid-template-columns: minmax(0, 1fr); }
  .work-tile--cta, .work-tile--cta:nth-child(odd) { grid-column: auto; }
}

.work-tile__link {
  display: grid; gap: var(--s-4); align-content: start;
  height: 100%;
  color: inherit; text-decoration: none;
  border-radius: var(--radius);
}
.work-tile__link:focus-visible { outline: none; }
.work-tile__link:focus-visible .work-tile__media { outline: 2px solid var(--focus-ring); outline-offset: 3px; }

.work-tile__media {
  position: relative; display: block;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius);
  overflow: hidden; isolation: isolate;
  background: var(--media-color, var(--bg-sunken));
  box-shadow: var(--shadow);
  transition: box-shadow 260ms var(--w-ease), transform 260ms var(--w-ease);
}
.work-tile__media picture { display: block; width: 100%; height: 100%; }
.work-tile__media img {
  width: 100%; height: 100%; max-inline-size: none;
  object-fit: cover;
  transition: transform 700ms var(--w-ease);
}
.work-tile__link:hover .work-tile__media { box-shadow: var(--w-lift); }

/* Live preview layers sit over the cover and fade in only once they can play. */
.work-tile__video,
.work-tile__frames {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0; transition: opacity 320ms ease;
  pointer-events: none;
}
.work-tile__video { object-fit: cover; }
.work-tile.is-previewing .work-tile__video.is-ready,
.work-tile.is-previewing .work-tile__frames { opacity: 1; }
.work-tile__frames picture { position: absolute; inset: 0; opacity: 0; transition: opacity 420ms ease; }
.work-tile__frames picture.is-active { opacity: 1; }

.work-tile__cue {
  position: absolute; right: var(--s-3); bottom: var(--s-3); z-index: 2;
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--w-scrim); color: #fff;
  transition: opacity 200ms ease;
}
.work-tile__cue svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.work-tile.is-previewing .work-tile__cue { opacity: 0; }
html:not(.js) .work-tile__cue { display: none; }

.work-tile__badge {
  position: absolute; left: var(--s-3); top: var(--s-3); z-index: 2;
  padding: 5px 10px; border-radius: var(--radius-pill);
  background: rgba(250, 248, 242, 0.94); color: #1c1a17;
  font: 600 0.72rem/1.2 var(--mono); letter-spacing: 0.06em; text-transform: uppercase;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.work-tile--diagram .work-tile__media { background: var(--paper); box-shadow: inset 0 0 0 1px var(--line); }
.work-tile--diagram .work-tile__link:hover .work-tile__media { box-shadow: inset 0 0 0 1px var(--line-strong), var(--w-lift); }
.work-tile__media--diagram .work-diagram { width: 100%; height: 100%; }

.work-tile__body { display: grid; gap: 6px; align-content: start; padding-inline: 2px; }
.work-tile__meta {
  display: flex; flex-wrap: wrap; gap: 2px 0;
  color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em;
}
.work-tile__meta span + span::before { content: '·'; margin-inline: 0.6em; }
.work-tile__title {
  margin: 0;
  font-size: clamp(1.14rem, 1.1vw + 0.5rem, 1.34rem); line-height: 1.22; letter-spacing: -0.016em;
  color: var(--ink);
  transition: color 160ms ease;
}
.work-tile--lead .work-tile__title { font-size: clamp(1.28rem, 1.5vw + 0.5rem, 1.7rem); line-height: 1.16; }
.work-tile__link:hover .work-tile__title { color: var(--signal-ink); }
.work-tile__hook { color: var(--ink-2); font-size: var(--text-sm); line-height: 1.5; max-width: 56ch; }

.work-tile--cta {
  display: grid; align-content: center; justify-items: start; gap: var(--s-3);
  padding: clamp(24px, 3vw, 40px);
  border: var(--line-w-1) dashed var(--line-strong); border-radius: var(--radius);
}
.work-tile__cta-title { margin: 0; font-size: clamp(1.3rem, 1.5vw + 0.4rem, 1.7rem); font-weight: 650; line-height: 1.2; letter-spacing: -0.02em; text-wrap: balance; }
.work-tile__cta-text { margin: 0; color: var(--ink-2); }
.work-tile--cta .text-link { min-height: 44px; }

/* ---------------------------------------------------------- archive */
.works-archive { padding-block: var(--space) 0; border-top: var(--line-w-1) solid var(--line); }
.works-archive .section-heading h2 { max-width: 22ch; }
.archive-group + .archive-group { margin-top: clamp(36px, 4.4vw, 60px); }
.archive-group__title {
  display: flex; align-items: baseline; gap: var(--s-3);
  margin: 0 0 var(--s-4); font-size: var(--text-xl);
}
.archive-group__title a { color: var(--ink); text-decoration: none; }
.archive-group__title a:hover { color: var(--signal-ink); }
.archive-group__title .mono { color: var(--ink-3); font-weight: 400; }
.archive-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 0 var(--w-gap);
  border-top: var(--line-w-1) solid var(--line);
}
.archive-row {
  display: grid; gap: 6px; align-content: start;
  max-width: none; padding: var(--s-5) 0;
  border-bottom: var(--line-w-1) solid var(--line);
  scroll-margin-top: 96px;
}
.archive-row:target { box-shadow: inset 3px 0 0 var(--signal); padding-left: var(--s-4); }
.archive-row__title { margin: 0; font-size: var(--text-md); font-weight: 620; line-height: 1.3; letter-spacing: -0.01em; }
.archive-row__text { margin: 0; color: var(--ink-2); font-size: var(--text-sm); line-height: 1.55; }
.archive-row__kind { margin: 0; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em; }
.archive-row__related { margin: var(--s-1) 0 0; font-size: var(--text-sm); }
.archive-row__related .text-link { display: inline; }
.archive-row__related .text-link svg { display: inline-block; vertical-align: -3px; }

/* ---------------------------------------------------------- shared blocks */
.works-similar { padding-block: clamp(56px, 7vw, 104px); border-top: var(--line-w-1) solid var(--line); }
.works-similar__inner {
  display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 7fr);
  gap: var(--s-6) clamp(32px, 6vw, 96px); align-items: start;
}
.works-similar__inner h2 { grid-row: span 2; margin: 0; max-width: 15ch; font-size: clamp(1.7rem, 2.4vw + 0.4rem, 2.6rem); }
.works-similar__list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); }
.works-similar__list li { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: var(--s-3); max-width: none; font-size: var(--text-md); line-height: 1.5; }
.works-similar__list svg { width: 20px; height: 20px; margin-top: 3px; fill: none; stroke: var(--signal); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.works-similar__inner .btn { justify-self: start; }
@media (max-width: 860px) {
  .works-similar__inner { grid-template-columns: minmax(0, 1fr); }
  .works-similar__inner h2 { grid-row: auto; }
}

.works-custom { padding-block: var(--space); }
.works-custom__inner {
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: var(--s-6) clamp(32px, 5vw, 88px); align-items: start;
  padding: clamp(24px, 4.4vw, 64px);
  border-radius: var(--radius-lg);
  background: var(--bg-elev); box-shadow: var(--shadow);
}
.works-custom__text h2 { margin-bottom: var(--s-4); font-size: clamp(1.7rem, 2.4vw + 0.4rem, 2.6rem); max-width: 16ch; }
.works-custom__text p { color: var(--ink-2); }
.works-custom__note { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: var(--s-3); margin: var(--s-5) 0 0; font-size: var(--text-sm); line-height: 1.5; }
.works-custom__note svg { width: 18px; height: 18px; margin-top: 2px; fill: none; stroke: var(--outcome); stroke-width: 2; }
.works-custom__form { display: grid; gap: var(--s-5); }
.works-custom__form .btn { justify-self: start; }
.works-custom__noscript { margin: 0; }
html:not(.js) .works-custom__form { display: none; }
.works-field { display: grid; gap: var(--s-2); }
.works-field label { font-size: var(--text-sm); font-weight: 600; }
.works-field select,
.works-field textarea,
.works-field input {
  width: 100%; min-height: 48px;
  padding: 12px 14px;
  border: var(--line-w-1) solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--ink);
  font: inherit; font-size: 1rem; line-height: 1.45;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.works-field textarea { resize: vertical; min-height: 120px; }
.works-field select {
  appearance: none; padding-right: 44px; cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
    linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 22px) 52%, calc(100% - 16px) 52%;
  background-size: 6px 6px, 6px 6px; background-repeat: no-repeat;
}
.works-field select:hover, .works-field textarea:hover, .works-field input:hover { border-color: var(--ink-3); }
.works-field select:focus-visible, .works-field textarea:focus-visible, .works-field input:focus-visible {
  outline: none; border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft);
}
.works-field textarea[aria-invalid="true"] { border-color: var(--signal-ink); }
.works-field__error { margin: 0; color: var(--signal-ink); font-size: var(--text-sm); }
@media (max-width: 860px) {
  .works-custom__inner { grid-template-columns: minmax(0, 1fr); }
}

.works-cases { padding-block: 0 var(--space); }
.works-cases__link {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--s-4) var(--s-6);
  padding: clamp(20px, 3vw, 32px);
  border: var(--line-w-1) solid var(--line); border-radius: var(--radius);
  color: inherit; text-decoration: none;
  transition: border-color 160ms ease, background-color 160ms ease;
}
.works-cases__link:hover { border-color: var(--signal); background: var(--signal-soft); }
.works-cases__text { display: grid; gap: var(--s-2); max-width: 72ch; }
.works-cases__text strong { font-size: var(--text-lg); line-height: 1.3; letter-spacing: -0.01em; }
.works-cases__text span { color: var(--ink-2); font-size: var(--text-sm); line-height: 1.55; }

/* ---------------------------------------------------------- work page */
.work-head { padding-block: clamp(28px, 4vw, 56px) clamp(28px, 3.4vw, 48px); }
.work-head__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-4); margin: 0 0 var(--s-5); max-width: none; }
.work-head__meta a { color: var(--ink-2); text-decoration: none; text-transform: uppercase; letter-spacing: 0.08em; min-height: 32px; display: inline-flex; align-items: center; }
.work-head__meta a:hover { color: var(--signal-ink); }
.work-kind {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 12px;
  border-radius: var(--radius-pill);
  font: 600 0.72rem/1 var(--mono); letter-spacing: 0.07em; text-transform: uppercase; white-space: nowrap;
}
.work-kind--client { background: var(--ink); color: var(--bg); }
.work-kind--own { background: var(--signal-soft); color: var(--signal-ink); }
.work-kind--demo { border: var(--line-w-1) solid var(--line-strong); color: var(--ink); }
.work-head__title { max-width: 22ch; margin-bottom: var(--s-5); font-size: clamp(2.1rem, 3.6vw + 0.6rem, 3.9rem); }
.work-head__lead { max-width: 66ch; margin: 0; color: var(--ink-2); font-size: var(--text-md); }
.work-facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: var(--s-4) var(--s-5);
  max-width: 1000px; margin: clamp(28px, 3.4vw, 44px) 0 0; padding: 0;
}
.work-facts > div { padding-left: var(--s-4); border-left: 2px solid var(--line-strong); min-width: 0; }
.work-facts > div:first-child { border-left-color: var(--signal); }
.work-facts dt { font-size: clamp(1.5rem, 1.6vw + 0.8rem, 2.15rem); font-weight: 680; line-height: 1.1; letter-spacing: -0.03em; }
.work-facts dd { margin: 6px 0 0; color: var(--ink-2); font-size: var(--text-sm); line-height: 1.4; }
.work-head__actions { display: flex; flex-wrap: wrap; gap: var(--s-3); margin-top: clamp(28px, 3.4vw, 40px); }
@media (max-width: 560px) {
  .work-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .work-head__actions .btn { flex: 1 1 100%; justify-content: center; }
}

.work-stage-wrap { margin-bottom: clamp(48px, 6vw, 96px); }
.work-stage { margin: 0; }
.work-stage__frame {
  position: relative; display: block;
  border-radius: var(--radius-lg); overflow: hidden;
  background: var(--media-color, var(--bg-sunken));
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06), 0 34px 70px -40px rgba(0, 0, 0, 0.5);
}
.work-stage__frame picture, .work-stage__frame img, .work-stage__frame video { display: block; width: 100%; height: auto; }
.work-stage__frame--zoom { cursor: zoom-in; }
.work-stage__frame--zoom:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 4px; }
.work-stage--video .work-stage__frame { background: #0d0d0c; }
.work-stage__video { width: 100%; height: 100%; object-fit: contain; }
.work-stage--diagram .work-stage__frame { background: var(--paper); box-shadow: inset 0 0 0 1px var(--line); }
.work-stage--diagram .work-diagram { width: 100%; height: auto; }
.work-stage__scroll-hint { display: none; }
@media (max-width: 760px) {
  /* Scaled to a phone, the labels would be 5–8 px. The diagram keeps a
     legible width instead and scrolls sideways inside its frame. */
  .work-stage--diagram .work-stage__frame { overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: thin; }
  .work-stage--diagram .work-diagram { width: 760px; max-inline-size: none; }
  .work-stage__scroll-hint { display: block; margin: var(--s-2) 0 0; color: var(--ink-3); font-size: var(--text-sm); }
}

.work-stage__frame--demo { aspect-ratio: 16 / 10; }
.work-stage__frame--demo .work-stage__poster,
.work-stage__frame--demo .work-stage__poster img { width: 100%; height: 100%; object-fit: cover; }
.work-stage__frame--demo.is-launchable { cursor: pointer; }
.work-stage__frame--demo.is-launchable::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 40%, rgba(0, 0, 0, 0.32));
}
.work-stage__launch {
  position: absolute; left: 50%; top: 50%; z-index: 2;
  translate: -50% -50%; white-space: nowrap;
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.6);
}
.work-stage__launch[aria-busy="true"] { cursor: progress; }
/* Mounted demos bring their own surface (the avatar adds its button row). */
.work-stage__frame--demo[data-mounted] { aspect-ratio: auto; background: transparent; box-shadow: none; overflow: visible; border-radius: 0; }
.work-stage__frame--demo[data-mounted="house-viewer"] { aspect-ratio: 16 / 10; overflow: hidden; border-radius: var(--radius-lg); background: #1a1a18; }
/* The 3D viewer fills the 16:10 frame; it measures its container on mount. */
.work-stage__demo--house-viewer { position: absolute; inset: 0; }
.work-stage__frame--demo[data-mounted="house-viewer"]:has(canvas:focus-visible) { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
/* The drawing viewer brings its own toolbar, layer list and status bar. */
.work-stage__frame--demo[data-mounted="cad-viewer"] { overflow: hidden; border-radius: var(--radius-lg); background: var(--bg-elev); box-shadow: var(--shadow); }
/* The editor desk is a dark app window: monitor, inspector, transport, timeline. */
.work-stage__frame--demo[data-mounted="video-editor"] { overflow: hidden; border-radius: var(--radius-lg); background: #101215; box-shadow: var(--shadow); }
.work-stage__frame--demo[data-mounted] .work-stage__poster,
.work-stage__frame--demo[data-mounted] .work-stage__launch { display: none; }
.work-stage__frame--demo[data-mounted]::after { display: none; }
.work-stage__hint { margin: var(--s-3) 0 0; color: var(--ink-3); font-size: var(--text-sm); line-height: 1.5; max-width: 90ch; }
html:not(.js) .work-stage__hint { display: none; }
.work-stage__fallback { margin: var(--s-2) 0 0; color: var(--risk); font-size: var(--text-sm); }
@media (max-width: 639px) {
  .work-stage__frame { border-radius: var(--radius); }
  .work-stage__launch { font-size: var(--text-sm); }
}

.work-body { padding-block: 0 clamp(56px, 7vw, 104px); }
.work-body__grid {
  display: grid; grid-template-columns: minmax(0, 7fr) minmax(260px, 4fr);
  gap: var(--s-7) clamp(40px, 6vw, 112px); align-items: start;
}
.work-block + .work-block { margin-top: clamp(36px, 4vw, 56px); }
.work-block h2 { margin-bottom: var(--s-4); font-size: clamp(1.4rem, 1.2vw + 0.8rem, 1.85rem); }
.work-block > p { margin: 0; font-size: var(--text-md); }
.work-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); }
.work-list > li { position: relative; padding-left: 28px; font-size: var(--text-md); line-height: 1.55; }
.work-list > li::before {
  content: ''; position: absolute; left: 3px; top: 0.62em;
  width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid var(--signal);
}
.work-list--proof > li { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: var(--s-3); padding-left: 0; }
.work-list--proof > li::before { display: none; }
.work-list--proof svg { width: 20px; height: 20px; margin-top: 4px; fill: none; stroke: var(--outcome); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.work-body__aside { display: grid; gap: var(--s-6); position: sticky; top: 96px; }
.work-aside__item h2 {
  margin: 0 0 var(--s-3);
  font-family: var(--mono); font-size: 0.75rem; font-weight: 500; line-height: 1.4;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3);
}
.work-aside__item p { margin: 0; font-size: var(--text-base); line-height: 1.55; }
.work-tools { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2); }
.work-tools li { padding: 4px 10px; border: var(--line-w-1) solid var(--line-strong); border-radius: var(--radius-sm); font-size: var(--text-sm); line-height: 1.4; }
.work-files, .work-links { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); }
.work-file {
  display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: var(--s-3); align-items: center;
  padding: 10px 14px 10px 10px;
  border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow);
  color: inherit; text-decoration: none;
  transition: box-shadow 200ms ease;
}
.work-file:hover { box-shadow: var(--w-lift); }
.work-file__icon {
  display: grid; place-items: center; height: 52px;
  border-radius: var(--radius-sm); background: var(--signal-soft); color: var(--signal-ink);
  font-weight: 700; letter-spacing: 0.04em;
}
.work-file__text { display: grid; gap: 2px; min-width: 0; }
.work-file__text strong { font-size: var(--text-sm); line-height: 1.35; }
.work-file__text .mono { color: var(--ink-3); }
.work-file:hover strong { color: var(--signal-ink); }
.work-links .text-link { min-height: 44px; }
.work-aside__note {
  display: grid; gap: var(--s-2);
  padding: var(--s-4); border-left: 2px solid var(--line-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--bg-sunken); color: var(--ink-2); font-size: var(--text-sm); line-height: 1.55;
}
.work-aside__note p { margin: 0; }
@media (max-width: 960px) {
  .work-body__grid { grid-template-columns: minmax(0, 1fr); }
  .work-body__aside { position: static; }
}

.work-excerpt { padding-block: clamp(48px, 6vw, 88px); background: var(--bg-sunken); }
.work-excerpt h2 { margin-bottom: var(--s-6); font-size: clamp(1.6rem, 2vw + 0.6rem, 2.4rem); }
.work-excerpt__list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: var(--w-gap); }
.work-excerpt blockquote { margin: 0; padding: var(--s-5); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow); }
.work-excerpt blockquote .mono { margin: 0 0 var(--s-3); color: var(--signal-ink); text-transform: uppercase; letter-spacing: 0.08em; }
.work-excerpt blockquote p:last-child { margin: 0; font-size: var(--text-md); line-height: 1.6; }

/* Justified rows: every item is as wide as its aspect ratio allows at one
   shared row height, so pictures keep their proportions and read in order. */
.work-gallery { padding-block: clamp(48px, 6vw, 96px); }
.work-gallery__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s-2) var(--s-5); margin-bottom: var(--s-5); }
.work-gallery__head h2 { margin: 0; font-size: clamp(1.6rem, 2vw + 0.6rem, 2.4rem); }
.work-gallery__head .mono { margin: 0; color: var(--ink-3); }
.work-gallery__grid {
  --row: clamp(110px, 15vw, 210px);
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: var(--s-3);
}
.work-gallery__grid::after { content: ''; flex: 999 1 0; }
.work-gallery__item { flex: var(--ar) 1 calc(var(--ar) * var(--row)); min-width: 0; max-width: 100%; }
.work-gallery__item a {
  position: relative; display: block;
  aspect-ratio: var(--ar);
  border-radius: var(--radius-sm); overflow: hidden;
  background: var(--media-color, var(--bg-sunken));
  cursor: zoom-in;
}
.work-gallery__item a:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
.work-gallery__item picture { display: block; width: 100%; height: 100%; }
.work-gallery__item img { width: 100%; height: 100%; max-inline-size: none; object-fit: cover; transition: transform 600ms var(--w-ease); }
.work-gallery__item a:hover img { transform: scale(1.035); }
.work-gallery__item--crop img { object-position: top center; }
.work-gallery__item--letterbox a { background: var(--paper); }
.work-gallery__item--letterbox img { object-fit: contain; }
.work-gallery__item--video a { cursor: pointer; }
.work-gallery__play {
  position: absolute; inset: 0; margin: auto;
  display: grid; place-items: center;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--w-scrim); color: #fff;
  transition: transform 200ms var(--w-ease), background-color 200ms ease;
}
.work-gallery__play svg { width: 22px; height: 22px; margin-left: 3px; fill: currentColor; }
.work-gallery__item a:hover .work-gallery__play { transform: scale(1.08); background: var(--signal); }
.work-gallery__badge {
  position: absolute; left: var(--s-2); bottom: var(--s-2);
  padding: 3px 8px; border-radius: var(--radius-pill);
  background: var(--w-scrim); color: #fff;
}
@media (max-width: 640px) {
  .work-gallery__badge-text { display: none; }
}

.works-related { padding-block: clamp(56px, 7vw, 104px); border-top: var(--line-w-1) solid var(--line); }
.works-related__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s-3) var(--s-6); margin-bottom: var(--s-6); }
.works-related__head h2 { margin: 0; font-size: clamp(1.6rem, 2vw + 0.6rem, 2.4rem); }

.work-pager { border-top: var(--line-w-1) solid var(--line); }
.work-pager__inner { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.work-pager__link {
  display: grid; gap: var(--s-2); align-content: start;
  padding: var(--s-6) var(--s-5) var(--s-6) 0;
  color: inherit; text-decoration: none; min-width: 0;
}
.work-pager__link--next { padding: var(--s-6) 0 var(--s-6) var(--s-5); text-align: right; box-shadow: inset 1px 0 0 var(--line); }
.work-pager__link .mono { color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em; }
.work-pager__link strong { font-size: var(--text-lg); line-height: 1.25; letter-spacing: -0.012em; transition: color 160ms ease; }
.work-pager__link:hover strong { color: var(--signal-ink); }
@media (max-width: 640px) {
  .work-pager__inner { grid-template-columns: minmax(0, 1fr); }
  .work-pager__link, .work-pager__link--next { padding: var(--s-5) 0; text-align: left; }
  .work-pager__link--next { box-shadow: inset 0 1px 0 var(--line); }
}

/* ---------------------------------------------------------- lightbox */
.lightbox {
  position: fixed; inset: 0;
  width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0;
  background: #0d0d0c; color: #f2f0ec;
  overscroll-behavior: contain;
}
.lightbox[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.lightbox::backdrop { background: rgba(12, 12, 11, 0.6); }
.lightbox__bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: 10px 12px 10px 20px; }
.lightbox__counter { font: 500 0.82rem/1 var(--mono); letter-spacing: 0.06em; color: rgba(242, 240, 236, 0.72); }
.lightbox__actions { display: flex; gap: var(--s-2); }
.lightbox__btn {
  display: grid; place-items: center;
  width: 44px; height: 44px; padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 50%;
  background: rgba(255, 255, 255, 0.06); color: #fff; cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease;
}
.lightbox__btn:hover { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.32); }
.lightbox__btn:focus-visible { outline: 2px solid #ff8b73; outline-offset: 2px; }
.lightbox__btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.lightbox__btn[aria-pressed="true"] { background: #f2f0ec; color: #11110f; }
.lightbox__stage {
  position: relative; min-height: 0;
  display: grid; place-items: center;
  padding: 0 clamp(8px, 7vw, 96px);
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
}
.lightbox__media { display: grid; place-items: center; max-width: 100%; max-height: 100%; min-height: 0; }
.lightbox__media picture { display: contents; }
.lightbox__media img,
.lightbox__media video {
  display: block; width: auto; height: auto;
  max-width: 100%; max-height: calc(100dvh - 148px);
  border-radius: 6px;
  background-color: rgba(255, 255, 255, 0.04);
  background-position: center; background-size: cover; background-repeat: no-repeat;
  box-shadow: 0 30px 80px -24px rgba(0, 0, 0, 0.7);
}
.lightbox__media video { background: #000; }
.lightbox__nav {
  position: absolute; top: 50%; z-index: 2; translate: 0 -50%;
  width: 52px; height: 52px;
}
.lightbox__nav--prev { left: 12px; }
.lightbox__nav--next { right: 12px; }
.lightbox__caption {
  margin: 0 auto; padding: 12px 20px 20px; max-width: 86ch;
  text-align: center; color: rgba(242, 240, 236, 0.84); font-size: var(--text-sm); line-height: 1.5;
}
/* Actual size: the picture at its own pixel width, panned by scroll or drag. */
.lightbox.is-zoomed .lightbox__stage { display: block; overflow: auto; padding: 0; cursor: grab; touch-action: pan-x pan-y pinch-zoom; }
.lightbox.is-zoomed .lightbox__stage.is-dragging { cursor: grabbing; }
.lightbox.is-zoomed .lightbox__media { display: block; max-width: none; max-height: none; width: max-content; margin: auto; }
.lightbox.is-zoomed .lightbox__media img { max-width: none; max-height: none; width: var(--zoom-w); border-radius: 0; box-shadow: none; }
.lightbox.is-zoomed .lightbox__nav { display: none; }
/* Long page captures scroll vertically at a readable width. */
.lightbox.is-tall .lightbox__stage { display: block; overflow-y: auto; padding-block: 0 24px; }
.lightbox.is-tall .lightbox__media { display: block; margin-inline: auto; width: min(100%, 1100px); max-height: none; }
.lightbox.is-tall .lightbox__media img { width: 100%; max-height: none; }
.lightbox.is-tall .lightbox__nav { position: fixed; }
@media (max-width: 640px) {
  .lightbox__stage { padding: 0 6px; }
  .lightbox__nav { top: auto; bottom: 8px; translate: none; width: 44px; height: 44px; }
  .lightbox.is-tall .lightbox__nav { bottom: 76px; }
  .lightbox__media img, .lightbox__media video { max-height: calc(100dvh - 190px); }
  .lightbox__caption { padding-inline: 60px; }
}

/* ---------------------------------------------------------- diagrams */
/* Solution diagrams are inline SVG: colours come from the theme tokens. */
.work-diagram {
  display: block; font-family: var(--font);
  /* Text tones for green/amber labels: the stroke colours themselves are too
     light for small text on paper (3.6:1), these keep 5:1 and more. */
  --wd-outcome-ink: color-mix(in srgb, var(--outcome) 70%, var(--ink));
  --wd-risk-ink: color-mix(in srgb, var(--risk) 70%, var(--ink));
}
html.dark .work-diagram { --wd-outcome-ink: var(--outcome); --wd-risk-ink: var(--risk); }
.work-diagram .wd-dot { fill: var(--line); }
.work-diagram .wd-node rect { fill: var(--bg-elev); stroke: var(--line-strong); stroke-width: 2; }
.work-diagram .wd-node--accent rect { stroke: var(--signal); stroke-width: 2.5; }
.work-diagram .wd-node--outcome rect { stroke: var(--outcome); stroke-width: 2.5; fill: color-mix(in srgb, var(--outcome) 10%, var(--bg-elev)); }
.work-diagram .wd-node--risk rect { stroke: var(--risk); stroke-width: 2.5; fill: color-mix(in srgb, var(--risk) 10%, var(--bg-elev)); }
.work-diagram .wd-node--dashed rect { fill: transparent; stroke-dasharray: 9 9; }
.work-diagram .wd-title { fill: var(--ink); font-weight: 650; letter-spacing: -0.01em; }
.work-diagram .wd-display { fill: var(--ink); font-weight: 700; letter-spacing: -0.035em; }
.work-diagram .wd-sub { fill: var(--ink-2); }
.work-diagram .wd-mono { fill: var(--ink-3); font-family: var(--mono); letter-spacing: 0.06em; }
.work-diagram .wd-mono--accent,
.work-diagram .wd-node--accent .wd-mono { fill: var(--signal-ink); }
.work-diagram .wd-node--outcome .wd-mono { fill: var(--wd-outcome-ink); }
.work-diagram .wd-node--risk .wd-mono { fill: var(--wd-risk-ink); }
.work-diagram .wd-edge path { fill: none; stroke: var(--line-strong); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.work-diagram .wd-edge--accent path { stroke: var(--signal); }
.work-diagram .wd-edge--outcome path { stroke: var(--outcome); }
.work-diagram .wd-edge--risk path { stroke: var(--risk); }
.work-diagram .wd-edge--dashed path:not(.wd-head) { stroke-dasharray: 10 10; }
.work-diagram .wd-edge--soft path { stroke-width: 2; }
.work-diagram .wd-edge-label text { paint-order: stroke; stroke: var(--paper); stroke-width: 12px; stroke-linejoin: round; }
.work-diagram .wd-edge-label--accent text { fill: var(--signal-ink); }
.work-diagram .wd-edge-label--outcome text { fill: var(--wd-outcome-ink); }
.work-diagram .wd-edge-label--risk text { fill: var(--wd-risk-ink); }
.work-diagram .wd-chip rect { fill: var(--bg); stroke: var(--line-strong); stroke-width: 2; }
.work-diagram .wd-break path { fill: none; stroke: var(--risk); stroke-width: 4; stroke-linecap: round; }

/* ---------------------------------------------------------- motion */
@media (prefers-reduced-motion: no-preference) {
  /* Cross-document view transitions between gallery pages only: the rest of
     the site does not load this file, so it keeps its plain navigation. The
     opened tile's picture morphs into the stage of the work page and back. */
  @view-transition { navigation: auto; }
  .work-stage__frame { view-transition-name: var(--vt-name, none); view-transition-class: work-media; }
  .work-tile__media { view-transition-class: work-media; }
  ::view-transition-group(.work-media) { animation-duration: 380ms; animation-timing-function: var(--w-ease, ease); }
  ::view-transition-old(.work-media),
  ::view-transition-new(.work-media) { height: 100%; object-fit: cover; }
  ::view-transition-old(root),
  ::view-transition-new(root) { animation-duration: 200ms; }

  .work-tile__link:hover .work-tile__media img { transform: scale(1.03); }

  /* Tiles rise in as they enter the viewport — CSS only, and only where the
     browser supports scroll-driven animations; elsewhere they simply show. */
  @supports (animation-timeline: view()) {
    .works-grid > .work-tile,
    .work-gallery__item {
      animation: works-rise linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 36%;
    }
  }
  @keyframes works-rise {
    from { opacity: 0; transform: translateY(28px); }
    to { opacity: 1; transform: none; }
  }
}
@media (prefers-reduced-motion: reduce) {
  .work-tile__media img, .work-gallery__item img { transition: none; }
  .work-tile__cue { display: none; }
}

/* ---------------------------------------------------------- print */
@media print {
  .works-groups, .works-custom, .works-cases, .work-head__actions, .works-similar .btn, .work-pager,
  .work-tile__video, .work-tile__frames, .work-tile__cue, .work-stage__launch, .work-stage__hint, .lightbox { display: none !important; }
  .work-tile, .archive-row, .work-gallery__item { break-inside: avoid; }
  .work-body__aside { position: static; }
}

/* ---------- drawing viewer (cad-viewer demo) ---------- */
/* AutoCAD's model-space background; layer colours come from the DXF (ACI). */
.cadv {
  --cad-bg: #212830;
  position: relative;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  height: clamp(480px, 76vh, 840px);
  background: var(--bg-elev); color: var(--ink);
  font-size: var(--text-sm);
}
.cadv button { font: inherit; color: inherit; }
.cadv__bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3);
  padding: 10px 12px; border-bottom: var(--line-w-1) solid var(--line);
}
.cadv__tabs { display: flex; gap: 2px; flex: 1 1 420px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.cadv__tabs::-webkit-scrollbar { display: none; }
.cadv__tab {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  min-height: 38px; padding: 6px 12px;
  border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--ink-2); white-space: nowrap; cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease;
}
.cadv__tab:hover { background: var(--bg-sunken); color: var(--ink); }
.cadv__tab[aria-selected="true"] { background: var(--ink); color: var(--bg); }
.cadv__tab:focus-visible, .cadv__mode:focus-visible, .cadv__lbtn:focus-visible, .cadv__zbtn:focus-visible,
.cadv__file:focus-visible, .cadv__showall:focus-visible, .cadv__layers-toggle:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.cadv__tab-no { font-family: var(--mono); font-size: var(--text-xs); opacity: 0.65; }
.cadv__modes { display: inline-flex; flex: none; padding: 3px; border-radius: var(--radius-pill); background: var(--bg-sunken); }
.cadv__mode {
  min-height: 32px; padding: 4px 14px; border: 0; border-radius: var(--radius-pill);
  background: transparent; color: var(--ink-2); font-weight: 600; cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
.cadv__mode[aria-pressed="true"] { background: var(--bg-elev); color: var(--ink); box-shadow: var(--shadow); }
.cadv[data-mode="cad"] .cadv__mode[aria-pressed="true"] { background: var(--cad-bg); color: #e9eef3; }
.cadv__layers-toggle {
  display: none; align-items: center; gap: 6px; flex: none;
  min-height: 38px; padding: 6px 12px; border: var(--line-w-1) solid var(--line-strong); border-radius: var(--radius-pill);
  background: transparent; cursor: pointer;
}
.cadv__layers-toggle[aria-expanded="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.cadv__body { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 288px; min-height: 0; }
.cadv__canvas {
  position: relative; min-width: 0; overflow: hidden;
  background: var(--bg-sunken); touch-action: none; cursor: grab; outline: none;
  transition: background-color 240ms ease;
}
.cadv.is-grabbing .cadv__canvas { cursor: grabbing; }
.cadv__canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--focus-ring); }
.cadv[data-mode="cad"] .cadv__canvas { background: var(--cad-bg); }
.cadv__stage { position: absolute; inset: 0; }
.cadv__stage > svg { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; }
.cadv__veil {
  position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; padding: var(--s-5);
  background: color-mix(in srgb, var(--bg-sunken) 82%, transparent); color: var(--ink-2); text-align: center;
}
.cadv__veil[hidden] { display: none; }
.cadv__hint {
  position: absolute; left: 50%; bottom: 70px; z-index: 3;
  max-width: calc(100% - 32px); padding: 8px 14px; border-radius: var(--radius-pill);
  background: rgba(20, 22, 26, 0.9); color: #fff; font-size: var(--text-sm); text-align: center;
  opacity: 0; translate: -50% 8px; pointer-events: none;
  transition: opacity 180ms ease, translate 180ms ease;
}
.cadv__hint.is-on { opacity: 1; translate: -50% 0; }
.cadv__zoom { display: inline-flex; gap: 4px; }
.cadv__zbtn {
  display: grid; place-items: center; width: 34px; height: 32px;
  border: var(--line-w-1) solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-elev); color: var(--ink); cursor: pointer;
}
.cadv__zbtn:hover { border-color: var(--line-strong); background: var(--bg-sunken); }
.cadv__icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.cadv__panel {
  display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0;
  border-left: var(--line-w-1) solid var(--line); background: var(--bg-elev);
}
.cadv__panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); padding: 12px 14px 6px; }
.cadv__panel-title { margin: 0; font-family: var(--mono); font-size: var(--text-xs); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.cadv__showall { min-height: 32px; padding: 4px 6px; border: 0; background: none; color: var(--signal-ink); font-size: var(--text-xs); font-weight: 600; cursor: pointer; }
.cadv__showall:disabled { color: var(--ink-3); opacity: 0.55; cursor: default; }
.cadv__list { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.cadv__layer--paper:not(.cadv__layer--paper ~ .cadv__layer--paper) { margin-top: 6px; padding-top: 6px; border-top: var(--line-w-1) solid var(--line); }
.cadv__lbtn {
  display: grid; grid-template-columns: 14px minmax(0, 1fr) 18px; column-gap: 10px; align-items: center;
  width: 100%; padding: 7px 8px; border: 0; border-radius: var(--radius-sm);
  background: transparent; text-align: left; cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}
.cadv__lbtn:hover { background: var(--bg-sunken); }
.cadv__swatch { grid-row: 1 / span 2; width: 14px; height: 14px; border-radius: 3px; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.28); }
.cadv__lname { font-family: var(--mono); font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
.cadv__lnote { grid-column: 2; font-size: 12px; line-height: 1.3; color: var(--ink-3); }
.cadv__eye { grid-column: 3; grid-row: 1 / span 2; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; opacity: 0.6; }
.cadv__lbtn[aria-pressed="false"] { color: var(--ink-3); }
.cadv__lbtn[aria-pressed="false"] .cadv__lname { text-decoration: line-through; text-decoration-thickness: 1px; }
.cadv__lbtn[aria-pressed="false"] .cadv__swatch { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
.cadv__lbtn[aria-pressed="false"] .cadv__eye { opacity: 0.22; }

.cadv__status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 8px 12px; border-top: var(--line-w-1) solid var(--line);
  font-family: var(--mono); font-size: var(--text-xs); color: var(--ink-2);
}
.cadv__space { padding: 3px 8px; border-radius: 4px; background: var(--bg-sunken); letter-spacing: 0.08em; text-transform: uppercase; }
.cadv__xy { min-width: 24ch; font-variant-numeric: tabular-nums; white-space: pre; }
.cadv__files { display: flex; gap: 6px; margin-left: auto; }
.cadv__file {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 4px 10px;
  border-radius: var(--radius-sm); background: var(--signal-soft); color: var(--signal-ink);
  font-weight: 700; text-decoration: none;
}
.cadv__file:hover { background: color-mix(in srgb, var(--signal) 22%, transparent); }
.cadv__file .cadv__icon { width: 16px; height: 16px; }
.cadv__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* sheet SVG: paper colours are attributes; the CAD screen repaints by class */
.cadsheet text { font-variant-numeric: lining-nums tabular-nums; }
.cadsheet .ko, .cadsheet .vp { stroke: none; }
.cadsheet .vp { display: none; }
.cadsheet g[data-ly] { transition: opacity 160ms ease; }
.cadsheet.is-solo g[data-ly] { opacity: 0.1; }
.cadsheet.is-solo g[data-ly].is-hl { opacity: 1; }
.cadsheet.is-cad .bg, .cadsheet.is-cad .m { fill: var(--cad-bg); }
.cadsheet.is-cad .tt { fill: none; }
.cadsheet.is-cad .s, .cadsheet.is-cad .x { fill: var(--c); }
.cadsheet.is-cad .h { stroke: var(--cad-bg); }
.cadsheet.is-cad .k, .cadsheet.is-cad .ko, .cadsheet.is-cad .vp { stroke: var(--c); stroke-width: 1px; vector-effect: non-scaling-stroke; }
.cadsheet.is-cad .tc { stroke: #8d97a3; stroke-width: 1px; vector-effect: non-scaling-stroke; }
.cadsheet.is-cad text:not(.x) { fill: #a4adb8; }
.cadsheet.is-cad .kw { stroke-width: 2px; }
/* 1 px strokes take their dashes in screen pixels */
.cadsheet.is-cad .lt-ax { stroke-dasharray: 18 4 3 4; }
.cadsheet.is-cad .lt-bd { stroke-dasharray: 16 4 3 4 3 4; }
.cadsheet.is-cad .lt-da { stroke-dasharray: 7 4; }
.cadsheet.is-cad .lt-do { stroke-dasharray: 2 3; }
.cadsheet.is-cad .vp { display: inline; stroke-dasharray: 6 4; }

@media (max-width: 760px) {
  /* on a phone the sheet gets a landscape-ish canvas, not a tall empty one */
  .cadv { height: auto; grid-template-rows: auto auto auto; }
  .cadv__canvas { height: clamp(260px, 84vw, 62vh); }
  .cadv__tabs { flex-basis: 100%; }
  .cadv__space { display: none; }
  .cadv__layers-toggle { display: inline-flex; margin-left: auto; }
  .cadv__body { grid-template-columns: minmax(0, 1fr); }
  .cadv__panel {
    position: absolute; top: 0; right: 0; bottom: 0; z-index: 4;
    width: min(88%, 320px); border-left: var(--line-w-1) solid var(--line);
    box-shadow: -18px 0 36px -24px rgba(0, 0, 0, 0.45);
    translate: 104% 0; visibility: hidden;
    transition: translate 220ms ease, visibility 0s linear 220ms;
  }
  .cadv.is-panel-open .cadv__panel { translate: 0 0; visibility: visible; transition: translate 220ms ease; }
  .cadv__xy { display: none; }
  .cadv__zoom { right: 8px; bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .cadv *, .cadsheet g[data-ly] { transition: none !important; }
}

/* ---------- editor desk (video-editor demo) ---------- */
.vedit {
  --ve-bg: #101215; --ve-panel: #161a1f; --ve-panel-2: #1c2027; --ve-line: #2a2f38; --ve-line-2: #353b45;
  --ve-text: #ebe8e2; --ve-text-2: #a9afb9; --ve-text-3: #8d95a1;
  --ve-head: 164px; --ve-ruler: 28px; --ve-titles: 30px; --ve-video: 56px; --ve-music: 46px; --ve-amb: 40px; --ve-sfx: 40px;
  --ve-playhead: #ff6a55; --ve-accent: #f2a65a;
  --ve-titles-c: #b9a2ff; --ve-video-c: #6ea8ff; --ve-music-c: #5fd3a0; --ve-amb-c: #59c3d8; --ve-sfx-c: #f2a65a;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(250px, 27%, 330px);
  grid-template-areas: "monitor inspector" "bar bar" "timeline timeline" "hint hint";
  background: var(--ve-bg); color: var(--ve-text);
  font-size: var(--text-sm); line-height: 1.4;
  outline: none;
}
.vedit :where(button) { font: inherit; color: inherit; }
.vedit p { max-width: none; }
.vedit [hidden] { display: none !important; }
.vedit :focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* program monitor */
.vedit__monitor { grid-area: monitor; position: relative; background: #000; aspect-ratio: 16 / 9; overflow: hidden; --split: 0.5; }
.vedit__video, .vedit__raw { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.vedit__video { cursor: pointer; }
.vedit__before { position: absolute; inset: 0; pointer-events: none; display: none; clip-path: inset(0 calc((1 - var(--split)) * 100%) 0 0); }
.vedit.is-compare .vedit__before { display: block; }
.vedit__split {
  position: absolute; top: 0; bottom: 0; left: calc(var(--split) * 100%); width: 44px; margin-left: -22px;
  cursor: ew-resize; touch-action: none; z-index: 2;
}
.vedit__split::before { content: ''; position: absolute; top: 0; bottom: 0; left: 21px; width: 2px; background: rgba(255, 255, 255, 0.92); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25); }
.vedit__split-grip {
  position: absolute; left: 50%; top: 50%; width: 36px; height: 36px; translate: -50% -50%;
  border-radius: 50%; background: rgba(16, 18, 21, 0.72); border: 2px solid #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.vedit__split-grip::before, .vedit__split-grip::after {
  content: ''; position: absolute; top: 50%; width: 0; height: 0; translate: 0 -50%;
  border-top: 5px solid transparent; border-bottom: 5px solid transparent;
}
.vedit__split-grip::before { left: 7px; border-right: 6px solid #fff; }
.vedit__split-grip::after { right: 7px; border-left: 6px solid #fff; }
.vedit__split:focus-visible { outline: none; }
.vedit__split:focus-visible .vedit__split-grip { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
.vedit__tag {
  position: absolute; top: 12px; z-index: 1; padding: 4px 10px; border-radius: var(--radius-pill);
  background: rgba(16, 18, 21, 0.72); color: #fff; font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.04em;
  pointer-events: none;
}
.vedit__tag--before { left: 12px; }
.vedit__tag--after { right: 12px; }
.vedit__big {
  position: absolute; left: 50%; top: 50%; width: 76px; height: 76px; translate: -50% -50%; z-index: 2;
  display: grid; place-items: center; border: 0; border-radius: 50%;
  background: rgba(16, 18, 21, 0.62); color: #fff; cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); backdrop-filter: blur(6px);
  transition: background-color 160ms ease, scale 160ms ease;
}
.vedit__big svg { width: 34px; height: 34px; }
.vedit__big:hover { background: rgba(16, 18, 21, 0.8); scale: 1.05; }

/* inspector */
.vedit__inspector {
  grid-area: inspector; min-width: 0; display: flex; flex-direction: column; gap: 12px;
  padding: 16px; background: var(--ve-panel); border-left: 1px solid var(--ve-line); overflow: auto;
}
.vedit__ins-head { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ve-text-3); }
.vedit__ins-foot { margin: auto 0 0; padding-top: 10px; border-top: 1px solid var(--ve-line); color: var(--ve-text-3); font-size: var(--text-xs); }
.vedit__ins-thumb {
  display: block; flex: none; height: 74px; border-radius: 6px; background-color: #000;
  background-size: auto 100%; background-repeat: repeat-x; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.vedit__ins-body { display: grid; gap: 8px; min-width: 0; }
.vedit__ins-body p { margin: 0; }
.vedit__ins-body p:empty { display: none; }
.vedit__ins-title { font-size: var(--text-base); font-weight: 650; color: #fff; }
.vedit__ins-meta { color: var(--ve-text-2); font-size: var(--text-xs); font-family: var(--mono); letter-spacing: -0.01em; }
.vedit__ins-note { color: var(--ve-text); }
.vedit__ins-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.vedit__ins-chip {
  padding: 3px 8px; border-radius: var(--radius-pill); font-size: var(--text-xs);
  background: rgba(242, 166, 90, 0.12); color: #f6c08c; box-shadow: inset 0 0 0 1px rgba(242, 166, 90, 0.28);
}
.vedit__inspector[data-kind="titles"] .vedit__ins-title { color: var(--ve-titles-c); }
.vedit__inspector[data-kind="music"] .vedit__ins-title { color: var(--ve-music-c); }
.vedit__inspector[data-kind="amb"] .vedit__ins-title { color: var(--ve-amb-c); }
.vedit__inspector[data-kind="sfx"] .vedit__ins-title { color: var(--ve-sfx-c); }

/* transport */
.vedit__bar {
  grid-area: bar; display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--ve-panel-2); border-top: 1px solid var(--ve-line); border-bottom: 1px solid var(--ve-line);
}
.vedit__btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; flex: none;
  min-width: 38px; height: 38px; padding: 0 9px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--ve-text); cursor: pointer; transition: background-color 140ms ease, color 140ms ease;
}
.vedit__btn:hover { background: rgba(255, 255, 255, 0.07); }
.vedit__btn[aria-pressed="true"] { background: rgba(242, 166, 90, 0.16); color: #f8c896; }
.vedit__btn--play { width: 42px; height: 42px; border-radius: 50%; background: var(--ve-text); color: #111; }
.vedit__btn--play:hover { background: #fff; }
.vedit__btn--text { padding: 0 12px; font-weight: 600; }
.vedit__clock { display: inline-flex; align-items: baseline; gap: 6px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.vedit__tc { font-size: 1.125rem; font-weight: 600; letter-spacing: 0.02em; }
.vedit__tc--total { font-size: var(--text-xs); font-weight: 500; color: var(--ve-text-2); }
.vedit__meter { display: inline-flex; align-items: center; gap: 8px; color: var(--ve-text-2); font-size: var(--text-xs); white-space: nowrap; }
.vedit__beats { display: inline-flex; gap: 4px; }
.vedit__beats i { width: 7px; height: 7px; border-radius: 50%; background: var(--ve-line-2); transition: background-color 80ms linear; }
.vedit__beats i.is-on { background: var(--ve-accent); box-shadow: 0 0 8px rgba(242, 166, 90, 0.7); }
.vedit__beats i:first-child.is-on { background: #fff; box-shadow: 0 0 8px rgba(255, 255, 255, 0.6); }
.vedit__chips { display: inline-flex; gap: 6px; }
.vedit__chip { padding: 2px 8px; border-radius: var(--radius-pill); background: rgba(255, 255, 255, 0.06); color: var(--ve-text-2); font-size: var(--text-xs); white-space: nowrap; }
.vedit__spacer { flex: 1 1 auto; }

/* timeline */
.vedit__timeline { grid-area: timeline; display: grid; grid-template-columns: var(--ve-head) minmax(0, 1fr); background: var(--ve-panel); min-width: 0; }
.vedit__heads { display: flex; flex-direction: column; border-right: 1px solid var(--ve-line); background: var(--ve-panel-2); }
.vedit__head {
  display: flex; align-items: center; gap: 6px; padding: 0 8px; border-bottom: 1px solid var(--ve-line);
  font-size: var(--text-xs); color: var(--ve-text-2); white-space: nowrap; overflow: hidden;
}
.vedit__head-id { font-family: var(--mono); font-weight: 700; color: var(--ve-text); }
.vedit__head-name { overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; }
.vedit__head--ruler { height: var(--ve-ruler); }
.vedit__head--titles, .vedit__lane--titles { height: var(--ve-titles); }
.vedit__head--video, .vedit__lane--video { height: var(--ve-video); }
.vedit__head--music, .vedit__lane--music { height: var(--ve-music); }
.vedit__head--amb, .vedit__lane--amb { height: var(--ve-amb); }
.vedit__head--sfx, .vedit__lane--sfx { height: var(--ve-sfx); }
.vedit__head--titles .vedit__head-id { color: var(--ve-titles-c); }
.vedit__head--video .vedit__head-id { color: var(--ve-video-c); }
.vedit__head--music .vedit__head-id { color: var(--ve-music-c); }
.vedit__head--amb .vedit__head-id { color: var(--ve-amb-c); }
.vedit__head--sfx .vedit__head-id { color: var(--ve-sfx-c); }
.vedit__head.is-silent .vedit__head-name { color: var(--ve-text-3); text-decoration: line-through; text-decoration-color: rgba(141, 149, 161, 0.6); }
.vedit__ms-group { display: inline-flex; gap: 3px; flex: none; }
.vedit__ms {
  width: 20px; height: 20px; padding: 0; border: 0; border-radius: 4px; cursor: pointer;
  background: rgba(255, 255, 255, 0.08); color: var(--ve-text-2); font-family: var(--mono); font-size: 11px; font-weight: 700;
}
.vedit__ms:hover { background: rgba(255, 255, 255, 0.16); color: #fff; }
.vedit__ms[aria-pressed="true"] { background: #e2584a; color: #fff; }
.vedit__ms--solo[aria-pressed="true"] { background: #e8c547; color: #111; }
.vedit.is-stems-loading .vedit__ms { cursor: progress; opacity: 0.6; }
.vedit__scroll { overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; scrollbar-color: var(--ve-line-2) transparent; min-width: 0; }
.vedit__lanes { position: relative; min-width: 100%; cursor: text; touch-action: pan-y; --p: 0; }
.vedit.is-scrubbing .vedit__lanes { cursor: ew-resize; }
.vedit__ruler { position: relative; height: var(--ve-ruler); background: #13161a; border-bottom: 1px solid var(--ve-line); cursor: ew-resize; }
.vedit__tick { position: absolute; bottom: 0; width: 1px; height: 6px; background: var(--ve-line-2); }
.vedit__tick--major { height: 11px; background: var(--ve-text-3); }
.vedit__tick b { position: absolute; left: 4px; bottom: 0; font-weight: 500; font-size: 10px; color: var(--ve-text-3); font-family: var(--mono); }
.vedit__barmark { position: absolute; top: 1px; translate: -50% 0; font-size: 9px; font-family: var(--mono); color: rgba(242, 166, 90, 0.75); }
.vedit__grid { position: absolute; left: 0; right: 0; top: var(--ve-ruler); bottom: 0; pointer-events: none; z-index: 2; }
.vedit__barline { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(242, 166, 90, 0.16); }
.vedit__barline.is-hit { animation: vedit-hit 600ms ease-out; }
@keyframes vedit-hit { from { background: rgba(255, 220, 170, 0.95); box-shadow: 0 0 10px 2px rgba(242, 166, 90, 0.55); } to { background: rgba(242, 166, 90, 0.16); box-shadow: none; } }
.vedit__lane { position: relative; border-bottom: 1px solid var(--ve-line); background: #12151a; }
.vedit__lane:nth-of-type(even) { background: #14171c; }
/* a muted track: the sound fades out of the picture, its labels stay readable */
.vedit__lane.is-silent .vedit__wave { opacity: 0.22; filter: grayscale(1); }
.vedit__lane.is-silent .vedit__clip { background: transparent; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14); }
.vedit__lane.is-silent .vedit__clip-label { color: var(--ve-text-3); text-shadow: none; }
.vedit__clip {
  position: absolute; top: 3px; bottom: 3px; min-width: 2px; overflow: hidden; border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.vedit__clip-label {
  position: absolute; left: 6px; right: 4px; top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em; color: #fff; pointer-events: none;
}
.vedit__lane--video .vedit__clip { background-color: #20304a; background-size: auto 100%; background-repeat: repeat-x; background-position: 0 0; }
.vedit__lane--video .vedit__clip::before { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(10, 12, 16, 0.72), rgba(10, 12, 16, 0) 55%); pointer-events: none; }
.vedit__lane--video .vedit__clip-label { text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.vedit__lane--video .vedit__clip.is-current { box-shadow: inset 0 0 0 2px var(--ve-accent); }
.vedit__lane--titles .vedit__clip { background: rgba(185, 162, 255, 0.2); box-shadow: inset 2px 0 0 var(--ve-titles-c), inset 0 0 0 1px rgba(185, 162, 255, 0.35); }
.vedit__lane--titles .vedit__clip-label { top: 50%; translate: 0 -50%; color: #e1d6ff; }
.vedit__wave { position: absolute; inset: 2px 0; width: 100%; height: calc(100% - 4px); pointer-events: none; }
.vedit__lane--music .vedit__wave path { fill: rgba(95, 211, 160, 0.55); }
.vedit__lane--amb .vedit__wave path { fill: rgba(89, 195, 216, 0.5); }
.vedit__lane--sfx .vedit__wave path { fill: rgba(242, 166, 90, 0.6); }
.vedit__lane--music .vedit__clip { box-shadow: inset 0 0 0 1px rgba(95, 211, 160, 0.45); background: rgba(95, 211, 160, 0.06); }
.vedit__lane--amb .vedit__clip { box-shadow: inset 0 0 0 1px rgba(89, 195, 216, 0.45); background: rgba(89, 195, 216, 0.06); }
.vedit__lane--sfx .vedit__clip { box-shadow: inset 0 0 0 1px rgba(242, 166, 90, 0.5); background: rgba(242, 166, 90, 0.07); }
.vedit__lane--sfx .vedit__clip--fx { box-shadow: inset 0 0 0 1px rgba(255, 106, 85, 0.6); background: rgba(255, 106, 85, 0.1); }
/* overlapping sounds share the lane: the second row takes the lower half */
.vedit__lane.has-rows .vedit__clip { top: 2px; bottom: auto; height: calc(50% - 3px); }
.vedit__lane.has-rows .vedit__clip.is-row-1 { top: auto; bottom: 2px; }
.vedit__lane.has-rows .vedit__clip-label { top: 1px; font-size: 10px; }
.vedit__lane--music .vedit__clip-label, .vedit__lane--amb .vedit__clip-label, .vedit__lane--sfx .vedit__clip-label { font-weight: 500; color: rgba(255, 255, 255, 0.9); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); }
.vedit__trans {
  position: absolute; top: 3px; bottom: 3px; min-width: 9px; z-index: 1; border-radius: 3px; pointer-events: auto;
  background: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.85) 0 2px, rgba(255, 255, 255, 0.25) 2px 5px);
  box-shadow: 0 0 0 1px rgba(16, 18, 21, 0.6);
}
.vedit__trans--fade { background: linear-gradient(90deg, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0)); box-shadow: none; }
.vedit__trans--fade:last-child { background: linear-gradient(90deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.85)); }
.vedit__playhead { position: absolute; top: 0; bottom: 0; left: calc(var(--p) * 100%); width: 2px; margin-left: -1px; background: var(--ve-playhead); z-index: 3; pointer-events: none; box-shadow: 0 0 8px rgba(255, 106, 85, 0.5); }
.vedit__playhead::before {
  content: ''; position: absolute; top: 0; left: 50%; translate: -50% 0; width: 12px; height: 12px;
  background: var(--ve-playhead); clip-path: polygon(0 0, 100% 0, 100% 55%, 50% 100%, 0 55%);
}
.vedit__hint { grid-area: hint; margin: 0; padding: 8px 14px 10px; color: var(--ve-text-3); font-size: var(--text-xs); background: var(--ve-panel); border-top: 1px solid var(--ve-line); }
.vedit__live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* full screen: the monitor takes the free height */
.vedit.is-fullscreen { height: 100vh; grid-template-rows: minmax(0, 1fr) auto auto auto; }
.vedit.is-fullscreen .vedit__monitor { aspect-ratio: auto; height: 100%; }

@media (max-width: 960px) {
  .vedit { grid-template-columns: minmax(0, 1fr); grid-template-areas: "monitor" "bar" "timeline" "inspector" "hint"; }
  .vedit__inspector { border-left: 0; border-top: 1px solid var(--ve-line); flex-direction: row; align-items: flex-start; }
  .vedit__ins-thumb { width: 38%; max-width: 220px; height: 64px; }
  .vedit__ins-body { flex: 1 1 auto; }
  .vedit.is-fullscreen { grid-template-rows: minmax(0, 1fr) auto auto auto auto; }
}
@media (max-width: 640px) {
  .vedit { --ve-head: 44px; --ve-video: 48px; --ve-music: 40px; --ve-amb: 34px; --ve-sfx: 34px; }
  .vedit__head { flex-direction: column; justify-content: center; gap: 2px; padding: 0 4px; }
  .vedit__head-name { display: none; }
  .vedit__ms { width: 18px; height: 15px; font-size: 9px; }
  .vedit__lanes { min-width: 720px; }
  .vedit__chips, .vedit__meter-text, .vedit__hint, .vedit__barmark { display: none; }
  .vedit__bar { gap: 6px 8px; padding: 8px 10px; }
  .vedit__btn--text span { display: none; }
  .vedit__inspector { flex-direction: column; }
  .vedit__ins-thumb { width: 100%; max-width: none; height: 56px; }
  .vedit__big { width: 60px; height: 60px; }
}
@media (prefers-reduced-motion: reduce) {
  .vedit *, .vedit *::before { transition: none !important; animation: none !important; }
}
