/* ==================================================================
   secondStack — motion lab
   Direction: technical lab sheet — hairline grid, monospaced labels,
   colour drawn only from the mark's own palette.
   ================================================================== */

:root {
  --speed: 1;

  /* The mark's palette — exact values from the source file (node 2525-9 / 2525-22) */
  --c-blue:  #2fb5f4;
  --c-lime:  #b6f500;
  --c-coral: #ff6f5e;

  --font-display: 'Space Grotesk', 'Helvetica Neue', Helvetica, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --step: 8px;
  --pad: clamp(16px, 4vw, 48px);
  --ease: cubic-bezier(.4, 0, .2, 1);
}

[data-theme="dark"] {
  --bg:      #0d0f12;
  --surface: #131619;
  --raised:  #1a1e23;
  --fg:      #f2f3f5;
  --muted:   #7d858f;
  --line:    rgba(255, 255, 255, .11);
  --line-2:  rgba(255, 255, 255, .22);
  --grain:   .028;
}

[data-theme="light"] {
  --bg:      #f2f3f5;
  --surface: #e9ebee;
  --raised:  #ffffff;
  --fg:      #101216;
  --muted:   #6d757f;
  --line:    rgba(16, 18, 22, .14);
  --line-2:  rgba(16, 18, 22, .3);
  --grain:   .02;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .5s var(--ease), color .5s var(--ease);
}

h1, h2 { font-family: var(--font-display); font-weight: 700; margin: 0; }

::selection { background: var(--c-lime); color: #101216; }

/* Grain: a thin film over everything so the flat dark field doesn't read
   as pure digital black. */
.grain {
  position: fixed;
  inset: -50%;
  z-index: 999;
  pointer-events: none;
  opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ============================== THE MARK ========================== */

/* No colour of its own on purpose: the mark inherits currentColor, so it
   works on a button, in a status line, anywhere. */
.mark {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* These two rules are the whole trick: they put the transform origin at
   the centre of the mark, in both the rotating group and each arm. */
.mark .rot {
  transform-box: view-box;
  transform-origin: 100px 100px;
}

.mark .blade {
  transform-box: view-box;
  transform-origin: 0 0;
  fill: var(--ac, currentColor);
  will-change: transform, opacity;
}

/* Colourways -------------------------------------------------------- */

/* "prism" repeats the source file arm for arm: 15° blue, 60° lime,
   105° coral, 150°+330° the solid bar, 195°/240°/285° outlined. */
[data-colorway="prism"] [data-role="blue"]  { --ac: var(--c-blue); }
[data-colorway="prism"] [data-role="lime"]  { --ac: var(--c-lime); }
[data-colorway="prism"] [data-role="coral"] { --ac: var(--c-coral); }
[data-colorway="prism"] [data-role="ink"]   { --ac: var(--fg); }

[data-colorway="prism"] [data-role="ghost"] .blade {
  fill: var(--bg);
  stroke: var(--fg);
  stroke-width: 2.2;   /* the source outline is 1.64 at a reach of 47.6 — same weight */
}

[data-colorway="outline"] .blade {
  fill: none;
  stroke: var(--ac, currentColor);
  stroke-width: 3;
}

[data-mark] { display: block; }

/* Paused ------------------------------------------------------------ */

[data-play="off"] .mark .rot,
[data-play="off"] .mark .blade { animation-play-state: paused; }

/* ============================== MASTHEAD ========================== */

.masthead {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: clamp(12px, 3vw, 40px);
  padding: 14px var(--pad);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand__mark { width: 26px; height: 26px; flex: none; }

.brand__name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 16px;
  letter-spacing: -.02em;
}

.masthead__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.masthead__meta .dot { width: 3px; height: 3px; background: currentColor; border-radius: 50%; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.seg {
  display: flex;
  border: 1px solid var(--line);
}

.seg button,
.btn {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 6px 10px;
  cursor: pointer;
  transition: color .2s var(--ease), background .2s var(--ease);
}

.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover, .btn:hover { color: var(--fg); }
.seg button.is-on { background: var(--fg); color: var(--bg); }

.btn { border: 1px solid var(--line); }
.btn--ghost { border-color: transparent; }
.btn--icon { padding: 6px 9px; font-size: 13px; letter-spacing: 0; }

:where(button, a, input):focus-visible {
  outline: 2px solid var(--c-lime);
  outline-offset: 2px;
}

/* ================================ HERO ============================ */

.hero {
  display: grid;
  grid-template-columns: minmax(280px, .85fr) minmax(320px, 1.15fr);
  align-items: center;
  gap: clamp(24px, 6vw, 80px);
  padding: clamp(40px, 9vw, 110px) var(--pad) clamp(40px, 8vw, 96px);
}

.hero__stage {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
}

.hero__mark {
  position: relative;
  z-index: 1;
  width: min(62%, 300px);
  aspect-ratio: 1;
}

/* The hero's only motion: the arms assemble once on load and stop in the
   mark's exact canonical position. After that it does not move. */
.hero__mark .blade {
  animation: ss-intro .75s cubic-bezier(.2, 1.15, .35, 1) both;
  animation-delay: calc(var(--i) * 55ms);
}

@keyframes ss-intro {
  from { transform: scaleY(0); }
  to   { transform: scaleY(1); }
}

/* When paused, the mark must stay a mark rather than vanish on frame zero. */
[data-play="off"] .hero__mark .blade { animation: none; }

.hero__cap {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  white-space: nowrap;
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* The masthead mark is static and only comes alive under the cursor. */
.brand:hover .blade {
  animation: ss-pulse 1.6s cubic-bezier(.45, 0, .2, 1) infinite; /* keyframes live in anims.js */
}

/* A crosshair ring: the one piece of decoration, holding the mark in the
   optical centre of its stage. */
.hero__ring {
  position: absolute;
  inset: 8%;
  border: 1px solid var(--line);
  border-radius: 50%;
}
.hero__ring::before,
.hero__ring::after {
  content: '';
  position: absolute;
  background: var(--line);
}
.hero__ring::before { inset: 50% -8% auto -8%; height: 1px; }
.hero__ring::after  { inset: -8% 50% -8% auto; width: 1px; }

.kicker {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.hero h1 {
  font-size: clamp(40px, 6.6vw, 88px);
  line-height: .94;
  letter-spacing: -.035em;
  margin-bottom: 24px;
}

.hero h1 em {
  font-style: normal;
  color: var(--c-lime);
}

[data-theme="light"] .hero h1 em { color: #7ba800; }

.lede {
  max-width: 46ch;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.75;
  margin: 0 0 28px;
}

.hero__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero__legend b { color: var(--fg); font-weight: 500; }

/* A divider with a measuring-scale tick */
.rule {
  display: flex;
  gap: 4px;
  padding: 0 var(--pad);
}
.rule span { height: 1px; background: var(--line); }
.rule span:nth-child(1) { flex: 6; }
.rule span:nth-child(2) { flex: 1; background: var(--c-lime); }
.rule span:nth-child(3) { flex: 3; }

/* =============================== GRID ============================= */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(224px, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  margin: clamp(32px, 6vw, 64px) var(--pad) 0;
}

.tile {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  aspect-ratio: 1 / .96;
  padding: 16px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .35s var(--ease), opacity .35s var(--ease);
}

.grid:hover .tile:not(:hover) { opacity: .42; }
.tile:hover, .tile:focus-visible { background: var(--surface); }

.tile__stage {
  display: grid;
  place-items: center;
  padding: 6px;
}

.tile__mark { width: min(58%, 132px); aspect-ratio: 1; }

.tile__index {
  position: absolute;
  top: 14px;
  left: 16px;
  font-size: 10px;
  letter-spacing: .1em;
  color: var(--muted);
}

.tile__foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.tile__name {
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: -.01em;
}

.tile__open {
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}

.tile:hover .tile__open,
.tile:focus-visible .tile__open { opacity: 1; transform: none; }

/* Accent corner on hover */
.tile::after {
  content: '';
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 0;
  height: 1px;
  background: var(--c-lime);
  transition: width .35s var(--ease);
}
.tile:hover::after, .tile:focus-visible::after { width: 32px; }

.reduced-note {
  margin: 24px var(--pad) 0;
  color: var(--muted);
  font-size: 12px;
}

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--c-lime);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ============================== FOOTER ============================ */

.footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 32px;
  justify-content: space-between;
  padding: 40px var(--pad);
  margin-top: clamp(48px, 8vw, 96px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
}

/* =========================== DETAIL PANEL ========================= */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 40px);
}

.sheet[hidden] { display: none; }

.sheet__scrim {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(10px);
  animation: fade .3s var(--ease);
}

.sheet__panel {
  position: relative;
  width: min(1020px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--raised);
  border: 1px solid var(--line-2);
  animation: rise .35s var(--ease);
}

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

.sheet__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 24px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
}

.sheet__head .kicker { margin-bottom: 8px; }

#sheetName {
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: -.03em;
  line-height: 1;
}

.sheet__note {
  max-width: 58ch;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}

.sheet__stage {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 32px;
  padding: clamp(24px, 5vw, 56px) clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 100% 40px,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 40px 100%;
  background-color: var(--surface);
}

.sheet__mark {
  justify-self: center;
  width: min(300px, 46vw);
  aspect-ratio: 1;
}

/* The mark checked at real sizes — from a button down to a favicon. */
.sheet__scale {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding-left: 32px;
  border-left: 1px solid var(--line);
}
.sheet__scale span { display: block; flex: none; }
.sheet__scale span:nth-child(1) { width: 72px; height: 72px; }
.sheet__scale span:nth-child(2) { width: 40px; height: 40px; }
.sheet__scale span:nth-child(3) { width: 24px; height: 24px; }
.sheet__scale span:nth-child(4) { width: 16px; height: 16px; }

/* --- The mark as an inline loader --------------------------------- */

.sheet__inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 28px;
  padding: 20px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
}

.sheet__inline-label {
  margin: 0;
  width: 100%;
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Sized in em and painted with currentColor, so one mark serves every
   context: it inherits the type size and the text colour around it. */
.mark-inline {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -.15em;
  flex: none;
}

.demo-line {
  margin: 0;
  font-size: 15px;
  color: var(--fg);
}

.demo-line--small { font-size: 11px; color: var(--muted); }

.demo-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13px;
  background: var(--fg);
  color: var(--bg);
}

.sheet__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
}

.ctl {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.ctl input[type="range"] {
  appearance: none;
  width: clamp(120px, 26vw, 240px);
  height: 1px;
  background: var(--line-2);
  cursor: pointer;
}
.ctl input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 12px;
  height: 12px;
  background: var(--c-lime);
  border-radius: 50%;
}
.ctl input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border: 0;
  background: var(--c-lime); border-radius: 50%;
}
.ctl output { color: var(--fg); min-width: 44px; }

.sheet__nav { display: flex; gap: 8px; }

.code__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px clamp(16px, 3vw, 32px);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.code pre {
  margin: 0;
  padding: 0 clamp(16px, 3vw, 32px) 32px;
  overflow-x: auto;
}

.code code {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  color: var(--muted);
  white-space: pre;
}

/* ============================ RESPONSIVE ========================== */

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .hero__stage { order: -1; max-width: 340px; margin-inline: auto; }
  .sheet__stage { grid-template-columns: 1fr; }
  .sheet__scale {
    flex-direction: row;
    justify-content: center;
    align-items: flex-end;
    padding: 24px 0 0;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .masthead { flex-wrap: wrap; }
  .masthead__meta { order: 3; width: 100%; }
  .toolbar { width: 100%; margin-left: 0; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
