/* Labs – layered on top of /styles.css, which owns the tokens and the reset. */

/* Registered so Motion can interpolate it; the transform formula that reads
   it stays declarative in CSS. */
@property --depth {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}

:root {
  --surface: #f2efec;
  --surface-behind: #e8e4e0;
  --thumb: #ffffff;
  --thumb-shadow: 0 1px 2px rgba(18, 18, 18, 0.12), 0 1px 6px -2px rgba(18, 18, 18, 0.18);
  --code-bg: rgba(18, 18, 18, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #1b1b1b;
    --surface-behind: #232323;
    --thumb: #2b2b2b;
    --thumb-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 2px 10px -4px rgba(0, 0, 0, 0.7);
    --code-bg: rgba(245, 245, 245, 0.08);
  }
}

:root[data-theme="light"] {
  --surface: #f2efec;
  --surface-behind: #e8e4e0;
  --thumb: #ffffff;
  --thumb-shadow: 0 1px 2px rgba(18, 18, 18, 0.12), 0 1px 6px -2px rgba(18, 18, 18, 0.18);
  --code-bg: rgba(18, 18, 18, 0.05);
}

:root[data-theme="dark"] {
  --surface: #1b1b1b;
  --surface-behind: #232323;
  --thumb: #2b2b2b;
  --thumb-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 2px 10px -4px rgba(0, 0, 0, 0.7);
  --code-bg: rgba(245, 245, 245, 0.08);
}

/* Plenty of elements here set display, which outranks the UA rule behind
   the hidden attribute. Close the whole class of bug once. */
[hidden] {
  display: none !important;
}

/* ---------------------------------------------------------------- shell */

.labs-shell {
  width: min(calc(100% - 3rem), 44rem);
  margin-inline: auto;
  padding-block: 5rem 10rem;
}

.labs-header {
  margin-bottom: 3.5rem;
  animation: content-in 520ms var(--ease) both;
}

.labs-title {
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.375;
}

.labs-paragraph {
  max-width: 32rem;
  margin-top: 1rem;
}

@media (min-width: 40rem) {
  .labs-shell {
    padding-top: 4rem;
  }

  .labs-header {
    margin-bottom: 5rem;
  }
}

/* ---------------------------------------------------------------- entry */

.lab {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  animation: content-in 520ms var(--ease) both;
  animation-delay: 80ms;
}

.lab + .lab {
  margin-top: 6rem;
}

.lab-number {
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  line-height: 1.6;
  text-decoration: none;
  transition: color 160ms var(--ease);
}

.lab-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin-top: 0.125rem;
}

.lab-title {
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.lab-meta {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.lab-status[data-status="idea"],
.lab-status[data-status="rough"],
.lab-status[data-status="progress"] {
  color: var(--accent);
}

.lab-copy {
  max-width: 32rem;
  margin-top: 0.625rem;
  font-size: 0.9375rem;
}

.lab-copy code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--code-bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
}

/* The demo breaks out past the reading column – that tension is the point. */
.lab-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 8.5rem;
  margin-top: 1.75rem;
  padding: 2rem 1.5rem;
  border-radius: 0.75rem;
  background: var(--surface);
}

@media (min-width: 48rem) {
  .lab {
    grid-template-columns: 3.5rem minmax(0, 1fr);
  }

  .lab-number {
    grid-row: 1;
  }

  .lab-head,
  .lab-copy {
    grid-column: 2;
  }

  /* The gallery wrapper is the grid item now, so it carries the span. */
  .lab-iterations,
  .lab-stage {
    grid-column: 1 / -1;
  }

  .lab-stage {
    min-height: 10rem;
  }
}

@media (hover: hover) {
  .lab-number:hover {
    color: var(--accent);
  }
}

/* --------------------------------------------------- iteration gallery */

.lab-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
  margin-top: 1.75rem;
  margin-bottom: 0.5rem;
}

.lab-count {
  margin-right: auto;
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.lab-step {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 9999px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition:
    color 160ms var(--ease),
    background-color 160ms var(--ease);
}

.lab-step svg {
  width: 1rem;
  height: 1rem;
}

/* Hidden, but still holding its space – collapsing the row would shove the
   whole card upward and fight the title's rise. */
.lab-iterations[data-focused] .lab-controls {
  visibility: hidden;
}

/* Padding reserves the room the topmost card peeks into. */
.lab-deck {
  --peek: 0.9rem;

  position: relative;
  display: grid;
  overflow: hidden;
  padding-top: calc(var(--peek) + 0.35rem);
}

/* Every card shares one grid cell. */
.lab-deck .lab-stage {
  grid-area: 1 / 1;
  overflow: hidden;
  margin-top: 0;
  transform:
    translateY(calc(var(--depth, 0) * -1 * var(--peek)))
    scale(calc(1 - var(--depth, 0) * 0.035));
  transform-origin: 50% 0;
  z-index: calc(8 - var(--depth, 0));
  transition: background-color 240ms var(--ease);
}

/* Stacked cards are lifted out of flow, so the deck's height follows the
   card you are actually looking at – including when its content expands. */
.lab-deck .lab-stage[data-state="behind"] {
  position: absolute;
  inset: 0;
  background: var(--surface-behind);
  pointer-events: none;
}

/* Only the plate of a stacked card shows, never its contents. */
.lab-deck .lab-stage > * {
  transition: opacity 240ms var(--ease);
}

.lab-deck .lab-stage[data-state="behind"] > * {
  opacity: 0;
}

/* ----------------------------------------------------------- 002 · copy */

.copy {
  position: relative;
  overflow: hidden;
  padding: 0.5rem 1.125rem;
  border: 0;
  border-radius: 9999px;
  background: var(--bg);
  box-shadow: var(--thumb-shadow);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 450;
  line-height: 1.5;
  cursor: pointer;
  transition:
    color 160ms var(--ease),
    background-color 160ms var(--ease);
}

.copy-track {
  position: relative;
  display: grid;
  overflow: hidden;
}

/* Every face occupies the same cell, so the button keeps one width. */
.copy-face {
  display: flex;
  grid-area: 1 / 1;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(120%);
  transition:
    opacity 220ms var(--ease-out),
    transform 320ms var(--ease);
}

.copy[data-state="idle"] .copy-face[data-face="idle"],
.copy[data-state="done"] .copy-face[data-face="done"],
.copy[data-state="error"] .copy-face[data-face="error"] {
  opacity: 1;
  transform: translateY(0);
}

/* The outgoing face leaves upward, the incoming one arrives from below. */
.copy[data-state="done"] .copy-face[data-face="idle"],
.copy[data-state="error"] .copy-face[data-face="idle"] {
  transform: translateY(-120%);
}

.copy[data-state="done"] .copy-face[data-face="done"] {
  color: var(--accent);
}

.copy[data-state="error"] .copy-face[data-face="error"] {
  color: var(--muted);
}

.copy-check {
  width: 1em;
  height: 1em;
  stroke-dasharray: 16;
  stroke-dashoffset: 16;
}

.copy[data-state="done"] .copy-check {
  animation: check-draw 320ms var(--ease-out) 80ms forwards;
}

@keyframes check-draw {
  to {
    stroke-dashoffset: 0;
  }
}

@media (hover: hover) {
  .copy:hover {
    color: var(--accent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .copy-check {
    stroke-dashoffset: 0;
  }
}

/* ------------------------------------------------------- 003 · timeline */

/* styles.css resets ul, h1 and h2 only – these need their own reset. */
.timeline,
.tl-roles {
  margin: 0;
  padding: 0;
  list-style: none;
}

.tl-title,
.tl-role-title {
  margin: 0;
}

.tl-view {
  width: 100%;
  max-width: 25rem;
  margin-inline: auto;
}

/* v2's yearline should match its own 26rem column, not v1's tighter one. */
.lab-stage[data-version="2"] .tl-view {
  max-width: 26rem;
}

.timeline {
  --tl-gap: 1.75rem;
  --tl-dot: 7px;
  --tl-dot-top: 8px;
  --tl-rail: 2px;

  width: 100%;
  max-width: 24rem;
}

.tl-org {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  column-gap: 0.875rem;
}

.tl-org + .tl-org {
  margin-top: 2.25rem;
}

.tl-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  background: var(--bg);
  box-shadow: var(--thumb-shadow);
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.tl-title {
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.tl-org-name,
.tl-meta {
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.tl-org-name {
  color: var(--soft);
}

/* Nested roles ------------------------------------------------------- */

.tl-roles {
  margin-top: 1.25rem;
}

.tl-role {
  position: relative;
  padding-left: 1.25rem;
}

.tl-role + .tl-role {
  margin-top: var(--tl-gap);
}

.tl-role::after {
  position: absolute;
  top: var(--tl-dot-top);
  left: 0;
  width: var(--tl-dot);
  height: var(--tl-dot);
  border-radius: 50%;
  background: var(--muted);
  content: "";
}

/* Connector runs from this dot down into the next one, so the rail can
   never extend past the final role. */
.tl-role:has(~ .tl-role:not([hidden]))::before {
  position: absolute;
  top: calc(var(--tl-dot-top) + var(--tl-dot));
  bottom: calc(-1 * (var(--tl-gap) + var(--tl-dot-top)));
  left: calc((var(--tl-dot) - var(--tl-rail)) / 2);
  width: var(--tl-rail);
  border-radius: 9999px;
  background: var(--line);
  content: "";
}

.tl-role-title {
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

/* Focused year ------------------------------------------------------- */

.tl-focus {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.375rem 0.5rem;
  margin-bottom: 1.75rem;
}

/* Back and the year read as one thing – leaving this year – so they share
   the top line, with the position below them. */
.tl-back {
  grid-area: 1 / 1;
}

.tl-focus-year {
  grid-area: 1 / 2;
  justify-self: start;
}

.tl-focus-title {
  grid-area: 2 / 1 / 2 / -1;
}

.tl-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  margin-left: -0.375rem;
  padding: 0;
  border: 0;
  border-radius: 9999px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition:
    color 160ms var(--ease),
    background-color 160ms var(--ease);
}

.tl-back svg {
  width: 1rem;
  height: 1rem;
}

.tl-focus-year {
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.tl-focus-title {
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

/* Disclosure --------------------------------------------------------- */

.tl-detail {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 320ms var(--ease);
}

.tl-detail-inner {
  overflow: hidden;
  visibility: hidden;
  transition: visibility 0s linear 320ms;
}

[data-open="true"] .tl-detail {
  grid-template-rows: 1fr;
}

[data-open="true"] .tl-detail-inner {
  visibility: visible;
  transition-delay: 0s;
}

.tl-note {
  padding-top: 0.75rem;
  color: var(--soft);
  font-size: 0.875rem;
  line-height: 1.6;
}

.tl-skills {
  padding-top: 0.5rem;
  color: var(--muted);
  font-size: 0.8125rem;
}

.tl-toggle {
  margin-top: 0.5rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.8125rem;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
  cursor: pointer;
  transition:
    color 160ms var(--ease),
    text-decoration-color 160ms var(--ease);
}

@media (hover: hover) {
  .yl-row:hover .yl-open,
  .tl-back:hover {
    color: var(--accent);
  }

  .lab-step:hover {
    background: var(--row-hover);
    color: var(--text);
  }

  .tl-toggle:hover {
    color: var(--text);
    text-decoration-color: var(--accent);
  }
}

/* ---------------------------------------- 003 · v2, flat year gutter */

.yearline {
  --yl-gap: 2rem;
  --yl-dot: 7px;
  --yl-dot-top: 7px;
  --yl-rail: 2px;
  --yl-lane: 3rem;
  --yl-lane-w: 0.75rem;

  width: 100%;
  max-width: 26rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.yl-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.yl-open {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: color 160ms var(--ease);
}

/* Stretched link: the button's accessible name stays the position, but the
   whole row is the hit area. */
.yl-open::after {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  content: "";
}

.yl-row {
  position: relative;
  display: grid;
  grid-template-columns: 2.5rem var(--yl-lane-w) minmax(0, 1fr);
  column-gap: 0.5rem;
}

.yl-row + .yl-row {
  margin-top: var(--yl-gap);
}

.yl-year {
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.55;
  text-align: right;
}

.yl-row::after {
  position: absolute;
  top: var(--yl-dot-top);
  left: calc(var(--yl-lane) + (var(--yl-lane-w) - var(--yl-dot)) / 2);
  width: var(--yl-dot);
  height: var(--yl-dot);
  border-radius: 50%;
  background: var(--muted);
  content: "";
}

.yl-row:not(:last-child)::before {
  position: absolute;
  top: calc(var(--yl-dot-top) + var(--yl-dot));
  bottom: calc(-1 * (var(--yl-gap) + var(--yl-dot-top)));
  left: calc(var(--yl-lane) + (var(--yl-lane-w) - var(--yl-rail)) / 2);
  width: var(--yl-rail);
  border-radius: 9999px;
  background: var(--line);
  content: "";
}

.yl-body {
  grid-column: 3;
}

.yl-org {
  color: var(--soft);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.yl-meta {
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.5;
}
