/* Motion Loops: one dark page, the loops are the colour. */
@font-face { font-family: 'Instrument Sans'; src: url(../fonts/instrument-sans-regular.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Instrument Sans'; src: url(../fonts/instrument-sans-bold.ttf) format('truetype'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Instrument Serif'; src: url(../fonts/instrument-serif-regular.woff2) format('woff2'); font-weight: 400; font-display: swap; }

:root {
  color-scheme: dark;
  --bg: #0b0b0b;
  --card: #161616;
  --ink: #f2efe9;
  --muted: rgba(242, 239, 233, 0.56);
  --faint: rgba(242, 239, 233, 0.3);
  --rule: rgba(242, 239, 233, 0.1);
  --line-2: rgba(242, 239, 233, 0.22);
  --accent: #d4ff3a;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Instrument Serif', Georgia, serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --pad: clamp(1rem, 4.2vw, 3.5rem);
  --exploration-footer-bg: var(--bg);
  --exploration-footer-ink: var(--muted);
  --exploration-footer-border: var(--rule);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 1rem/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Bar */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem var(--pad);
  background: rgba(11, 11, 11, 0.86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--rule);
}
.bar-id { display: flex; align-items: center; gap: 1.1rem; min-width: 0; }
.bar-home { display: inline-flex; align-items: center; gap: 0.5rem; text-decoration: none; font-size: 0.9rem; white-space: nowrap; min-height: 44px; }
.bar-logo { width: 1.3rem; height: 1.3rem; color: var(--ink); }
.bar-slash, .bar-section { color: var(--muted); }
.bar-home:hover .bar-section { color: var(--ink); }
.bar-title { font-family: var(--serif); font-size: 1.35rem; text-decoration: none; white-space: nowrap; }
.bar-title em { font-style: normal; color: var(--accent); }
.bar-actions { display: flex; align-items: center; gap: 0.4rem; }
.bar-action {
  display: inline-flex; align-items: center; gap: 0.4rem; min-height: 44px; padding: 0 0.9rem;
  border: 1px solid var(--rule); border-radius: 999px; text-decoration: none; font-size: 0.9rem; color: var(--muted); white-space: nowrap;
}
.bar-action svg { width: 1rem; height: 1rem; stroke: currentColor; stroke-width: 1.8; }
.bar-action:hover { color: var(--ink); border-color: var(--line-2); }
.bar-make { background: var(--ink); color: var(--bg); border-color: transparent; font-weight: 700; }
.bar-make:hover { background: var(--accent); color: var(--bg); border-color: transparent; }

/* Opening */
main { padding: 0 var(--pad); }
.opening { padding: clamp(2.5rem, 7vw, 6rem) 0 1.5rem; display: grid; grid-template-columns: minmax(0, 1fr); column-gap: clamp(2rem, 5vw, 5rem); }
.opening > .controls, .opening > .jump { grid-column: 1 / -1; }
.hero-mosaic { display: none; }
@media (min-width: 64rem) {
  .opening { grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr); align-items: end; }
  .hero-mosaic { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
  .hero-mosaic .tile::after { display: none; }
}
.eyebrow { margin: 0 0 0.6rem; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.8rem; }
h1 { margin: 0; font: 400 clamp(3rem, 10vw, 7.5rem)/0.95 var(--serif); letter-spacing: -0.01em; }
.title-dot { color: var(--accent); }
.lede { max-width: 40rem; margin: 1.4rem 0 0; color: var(--muted); font-size: clamp(1.05rem, 1.6vw, 1.25rem); line-height: 1.5; }
.controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 2.4rem; border-bottom: 1px solid var(--rule); }
.packs { display: flex; gap: 1.8rem; }
.pack-tab {
  background: none; border: 0; padding: 0.9rem 0; min-height: 44px; cursor: pointer;
  font-size: 1.05rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.pack-tab[aria-selected='true'] { color: var(--ink); border-bottom-color: var(--ink); }
.pack-tab:hover { color: var(--ink); }
.motion-toggle {
  background: none; border: 1px solid var(--rule); border-radius: 999px; padding: 0 1rem; min-height: 40px; margin-bottom: 0.5rem;
  color: var(--muted); cursor: pointer; font-size: 0.9rem;
}
.motion-toggle:hover { color: var(--ink); border-color: var(--line-2); }
.jump { display: flex; flex-wrap: wrap; gap: 0.2rem 1.4rem; margin-top: 1rem; }
.jump a { font-family: var(--serif); font-size: 1.35rem; text-decoration: none; color: var(--muted); min-height: 44px; display: inline-flex; align-items: center; }
.jump a:hover { color: var(--cat, var(--ink)); }

/* Categories and cards */
.pack { padding-bottom: 4rem; }
.cat { padding-top: clamp(2rem, 5vw, 3.5rem); scroll-margin-top: 5rem; }
.cat-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; }
.cat-head h2 { margin: 0; font: 400 clamp(2rem, 4vw, 2.75rem)/1 var(--serif); color: var(--cat); }
.cat-head span { color: var(--faint); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.6rem 1.1rem; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { min-width: 0; }
.tile {
  display: block; width: 100%; padding: 0; border: 0; border-radius: 0.7rem; overflow: hidden; cursor: pointer;
  aspect-ratio: 16 / 9; background: var(--card); position: relative;
  box-shadow: inset 0 0 0 1px var(--rule);
}
.tile canvas { display: block; width: 100%; height: 100%; }
.tile::after {
  content: 'View code'; position: absolute; right: 0.6rem; bottom: 0.55rem; padding: 0.3rem 0.65rem; border-radius: 0.45rem;
  background: rgba(11, 11, 11, 0.78); color: var(--ink); font-size: 0.8rem; opacity: 0; transform: translateY(4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.tile:hover::after, .tile:focus-visible::after { opacity: 1; transform: none; }
.meta { display: flex; align-items: baseline; gap: 0.7rem; margin-top: 0.65rem; }
.meta .num { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 0.95rem; }
.meta .name { font-size: 1rem; }

@media (max-width: 75rem) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 56rem) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .bar-how span, .bar-skill span { display: none; } .bar-how, .bar-skill { padding: 0 0.75rem; } }
@media (max-width: 34rem) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .bar-brand, .bar-slash, .bar-section { display: none; }
  .packs { gap: 1.2rem; }
  .pack-tab { font-size: 0.95rem; }
}

/* Code view dialog */
.code-view {
  width: min(96vw, 90rem); max-height: 92vh; padding: 0; border: 1px solid var(--line-2); border-radius: 1rem;
  background: #101010; color: var(--ink); overflow: hidden;
}
.code-view[open] { display: flex; flex-direction: column; }
.code-view::backdrop { background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(4px); }
.cv-top { display: flex; align-items: baseline; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--rule); }
.cv-kicker { margin: 0; color: var(--faint); font-variant-numeric: tabular-nums; }
.cv-top h2 { margin: 0; font: 400 1.6rem/1.1 var(--serif); flex: 1; min-width: 0; }
.cv-close { background: none; border: 1px solid var(--rule); border-radius: 999px; min-height: 40px; padding: 0 0.9rem; color: var(--muted); cursor: pointer; }
.cv-close:hover { color: var(--ink); border-color: var(--line-2); }
.cv-body { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); min-height: 0; flex: 1; }
.cv-stage { padding: 1.25rem; border-right: 1px solid var(--rule); display: flex; flex-direction: column; gap: 1.1rem; }
.cv-howto { margin: 0; padding-left: 1.2rem; color: var(--muted); display: grid; gap: 0.45rem; font-size: 0.95rem; }
.cv-howto code { font: 0.85em var(--mono); color: var(--ink); }
.cv-stage canvas { width: 100%; aspect-ratio: 16 / 9; border-radius: 0.6rem; display: block; background: var(--card); }
.cv-code { display: flex; flex-direction: column; min-height: 0; }
.cv-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; padding: 0.9rem 1.25rem; border-bottom: 1px solid var(--rule); }
.cv-btn { min-height: 40px; padding: 0 1rem; border-radius: 999px; border: 1px solid var(--line-2); background: none; color: var(--ink); cursor: pointer; font-size: 0.92rem; }
.cv-btn:hover { border-color: var(--ink); }
.cv-primary { background: var(--ink); color: var(--bg); border-color: transparent; font-weight: 700; }
.cv-primary:hover { background: var(--accent); }
.cv-meta { color: var(--faint); font-size: 0.88rem; margin-left: auto; }
.cv-status { color: var(--accent); font-size: 0.88rem; min-width: 4.5rem; }
.cv-pre { margin: 0; padding: 1rem 1.25rem 1.5rem; overflow: auto; flex: 1; min-height: 12rem; max-height: 70vh; font: 0.8rem/1.6 var(--mono); tab-size: 2; color: #d9d5cc; }
.cv-pre .ln { display: inline-block; width: 2.6em; color: rgba(242, 239, 233, 0.2); user-select: none; text-align: right; margin-right: 1.1em; }
.tk-k { color: #ff8db5; } .tk-n { color: #ffc861; } .tk-s { color: #b5e86f; } .tk-c { color: rgba(242, 239, 233, 0.38); font-style: italic; } .tk-f { color: #8fd3ff; }
@media (max-width: 56rem) {
  .cv-body { grid-template-columns: minmax(0, 1fr); overflow: auto; }
  .cv-stage { border-right: 0; border-bottom: 1px solid var(--rule); }
  .cv-pre { max-height: none; }
  .code-view { max-height: 94vh; }
}

.how-body { padding: 1.25rem 1.5rem 1.75rem; overflow: auto; max-width: 52rem; color: var(--muted); font-size: 1.02rem; }
.how-body p:first-child { color: var(--ink); font-size: 1.12rem; }
.how-list { padding-left: 1.1rem; display: grid; gap: 0.7rem; }
.how-list b { color: var(--ink); font-weight: 700; }
.how-skill a { color: var(--accent); }

/* Footer */
.foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.4rem;
  padding: 1.4rem var(--pad); border-top: 1px solid var(--rule); background: var(--exploration-footer-bg); color: var(--muted); font-size: 0.85rem;
}
.foot-id { letter-spacing: 0.08em; text-transform: uppercase; }
.foot-link { min-height: 44px; display: inline-flex; align-items: center; text-decoration: none; color: var(--ink); }
.foot-link:hover { color: var(--accent); }
.foot [data-exploration-controls] { flex: 1 1 20rem; display: flex; justify-content: flex-end; border-top: 0; background: none; }
.noscript { color: var(--muted); padding: 2rem 0; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .tile::after { transition: none; }
}

/* The dialog itself takes focus on open; its controls show the ring, not the frame. */
dialog:focus-visible { outline: none; }
.code-view.how { width: min(96vw, 52rem); }

/* Narrow screens: the title keeps its room, and the dialog leads with Copy. */
.bar-title { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
@media (max-width: 26rem) { .bar-skill { display: none; } }
@media (max-width: 40rem) {
  .cv-top { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; row-gap: 0.25rem; }
  .cv-kicker { grid-row: 1; grid-column: 1; }
  .cv-close { grid-row: 1; grid-column: 2; }
  .cv-top h2 { grid-row: 2; grid-column: 1 / -1; }
}
@media (max-width: 56rem) {
  .cv-body { display: flex; flex-direction: column; }
  .cv-stage, .cv-code { display: contents; }
  .cv-stage canvas { order: 1; margin: 1rem 1rem 0; width: calc(100% - 2rem); }
  .cv-actions { order: 2; border-bottom: 0; padding: 0.9rem 1rem; }
  .cv-howto { order: 3; padding: 0 1rem 0.9rem 2.2rem; border-bottom: 1px solid var(--rule); }
  .cv-pre { order: 4; }
  .cv-meta { margin-left: 0; }
}
@media (max-height: 30rem) and (max-width: 56rem) {
  .cv-stage canvas { width: auto; height: 46vh; align-self: center; margin-left: 0; margin-right: 0; }
}
@media (max-width: 22rem) { .bar-title { display: none; } }
