/* LEGO World workbench, laid out as a LEGO.com product page: yellow navigation
   bar, white page, the model as the product gallery and the set's facts and
   components in an information column on the right. See docs/design.md.
   Measured from lego.com/en-us (2026-10-05): yellow #ffd502, headings, navigation
   and buttons #141414 over body text #2c2c2c, links #006db7, 500-weight pill
   buttons (grey #f2f2f2; an orange #f47d20 pill with black type for
   the buying action; a 2px dark outline for the lesser ones), white product
   cards with 8px corners and a hairline edge, Cera Pro type. The orange here marks the
   building action: Build it step by step, and Play once building. */
:root {
  color-scheme: light;
  --yellow: #ffd502;
  --ink: #141414; /* headings, navigation, buttons */
  --text: #2c2c2c; /* running text */
  --ink-2: #6b6b6b;
  --paper: #fff;
  --mist: #f4f4f4;
  --pill: #f2f2f2; /* secondary buttons */
  --pill-hover: #e4e4e4;
  --outline: rgba(0, 0, 0, 0.74); /* outlined buttons */
  --line: #e0e0e0;
  --line-strong: #c4c4c4;
  --blue: #006db7;
  --blue-dark: #00508a;
  --blue-wash: #e8f2fa;
  --orange: #f47d20;
  --orange-dark: #e56f12;
  --stage: #e2e6e8;
  --radius: 8px; /* cards, the stage's callouts and the brick card */
  /* Type: five steps, close together, so the page reads as one voice (owner,
     2026-10-05, of the product column: "why is the text big and small?"). One
     size for everything a visitor reads or presses, one for captions and counts,
     one for headings and the facts' numbers, one for the set's title. */
  --t-micro: 0.8125rem; /* 13: captions, counts, tags, fine print */
  --t-body: 0.9375rem; /* 15: text, names, controls, list rows, navigation */
  --t-lead: 1.125rem; /* 18: the brand, a picked brick's name, the loading card */
  --t-head: 1.25rem; /* 20: column headings, the facts' numbers, the build step */
  --t-display: 1.625rem; /* 26: the set's title */
  /* The two side columns are one width (owner, 2026-10-05). Capped at 288px:
     at 370 the rail's set pictures were too big. */
  --side: clamp(250px, 20vw, 288px);
}
/* The reader's own default size (16px), as on LEGO.com. A root that grew with
   the window was tried on 2026-10-05 (to 18px at 2560, then 16.5) and replaced
   the same day by LEGO.com's fixed sizes at the owner's request. */
html {
  font-size: 100%;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--text);
  /* LEGO.com's own face where it is installed; Albert Sans is the closest open
     match (geometric, round C and o, double-storey a). */
  font:
    var(--t-body) / 1.5 'Cera Pro',
    'Albert Sans',
    'Avenir Next',
    'Segoe UI',
    sans-serif;
  font-variant-numeric: tabular-nums;
}
button,
input,
select {
  font: inherit;
  color: var(--ink);
}
/* Buttons are LEGO.com's pills: grey fill, medium weight, darker on hover. */
button,
select {
  cursor: pointer;
  background: var(--pill);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.5em 1.05em;
  font-weight: 500;
}
button:hover,
select:hover {
  background: var(--pill-hover);
}
button:disabled,
select:disabled,
input:disabled {
  cursor: default;
  opacity: 0.4;
}
button:disabled:hover {
  background: var(--pill);
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
#viewport:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
a {
  color: var(--blue);
}
h1,
h2 {
  margin: 0;
  color: var(--ink);
  font-weight: 700;
  line-height: 1.35;
}

/* Navigation bar, as LEGO.com's: sentence-case labels in 40px pills, the
   current one filled white (as its "New" item is). */
header {
  position: relative;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 4rem;
  flex-shrink: 0;
  padding: 0 1.5rem;
  background: var(--yellow);
  color: var(--ink);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--t-lead);
  font-weight: 700;
  white-space: nowrap;
}
.emblem {
  width: 2.25rem;
  height: 2.05rem;
  fill: var(--ink);
}
header nav,
.header-links {
  display: flex;
  align-items: center;
  gap: 4px;
}
.header-links {
  margin-left: auto;
}
.video-link {
  gap: 8px;
}
header nav button,
.header-links button,
.header-links a {
  display: inline-flex;
  align-items: center;
  height: 2.5rem;
  padding: 0 1rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink);
  font-size: var(--t-body);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.15s;
}
header nav button:hover,
.header-links button:hover,
.header-links a:hover {
  background: rgba(255, 255, 255, 0.5);
}
header nav button[aria-pressed='true'],
header nav button[aria-expanded='true'] {
  background: rgba(255, 255, 255, 0.94);
}

main {
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr) var(--side);
  flex: 1;
  min-height: 0;
}
.rail-title {
  font-size: var(--t-head);
}

/* Sets: product tiles */
.manifest {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
}
.manifest .rail-title {
  padding: 1rem 1.05rem 0.6rem;
  text-align: center;
}
/* Sets follows the official theme-first navigation, above the stage. */
.sets-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  max-height: min(75dvh, 680px);
  padding: 24px max(24px, calc((100vw - 1440px) / 2));
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 12px 24px rgb(0 0 0 / 12%);
}
.sets-menu[hidden] { display: none; }
.sets-menu-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-shrink: 0;
}
.sets-menu-head h2 { font-size: var(--t-head); }
#close-sets { margin-left: auto; font-size: var(--t-head); padding: 0; width: 40px; height: 40px; }
.theme-library {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 24px;
  overflow-y: auto;
  min-height: 0;
  padding: 4px;
  overscroll-behavior: contain;
}
.theme-choice {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--paper);
  text-align: left;
}
.theme-choice:hover { background: var(--pill); }
.theme-choice img { width: 64px; height: 64px; object-fit: contain; flex-shrink: 0; }
.theme-choice span { min-width: 0; }
.theme-choice small { display: block; color: var(--ink-2); font-size: var(--t-micro); font-weight: 400; }
.all-sets { align-self: flex-start; margin-top: 20px; flex-shrink: 0; }
.theme-choice[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--blue); background: var(--blue-wash); }
.set-library {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 4px 1.05rem 1.05rem;
  display: grid;
  gap: 0.8rem;
  align-content: start;
}
/* A set, as LEGO.com's product leaf: a white card with 8px corners and a
   hairline edge, the picture at the card's full width, and the name. (Rows with
   an 88px picture were tried for density on 2026-10-05 and taken back the same
   day as too small; a row of piece count and set number under the name went
   then too.) */
.set-choice {
  display: block;
  width: 100%;
  padding: 8px 8px 12px;
  text-align: left;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: var(--radius);
  background: var(--paper);
  font-weight: 400;
  transition:
    border-color 0.15s,
    background-color 0.15s;
}
.set-choice:hover {
  background: var(--paper);
  border-color: var(--ink-2);
}
/* The chosen set: the card's edge in LEGO.com's selection blue, 2px, over a
   wash of it, and the name bold. */
.set-choice[aria-pressed='true'] {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
  background: var(--blue-wash);
}
.set-choice[aria-pressed='true'] strong {
  font-weight: 700;
}
.set-choice img,
.set-placeholder {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 272 / 216;
  object-fit: contain;
  border-radius: 4px;
  background: var(--stage);
}
.set-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  font-size: var(--t-body);
  font-weight: 700;
}
.set-copy {
  display: block;
  padding: 10px 2px 0;
  text-align: center; /* the rail's words are centred (owner, 2026-10-05) */
}
.set-choice strong {
  display: block;
  color: var(--ink);
  font-size: var(--t-body);
  line-height: 1.35;
  font-weight: 500;
}
/* Desktop tiles are sized for five per rail (owner, 2026-10-05): each tile
   is a fifth of its height (cqh, the rail being a size container), the picture
   taking what the name leaves. Scrolling stays continuous, without tile
   snapping (owner, 2026-10-07). Phones use a horizontal strip. */
@media (min-width: 861px) {
  .set-library {
    flex: 1;
    container-type: size;
    /* The foot's padding equals the gap, so a fifth tile starts exactly at the
       rail's edge instead of showing a sliver. */
    gap: 0.5rem;
    padding-bottom: 0.5rem;
    /* An auto track would grow to the longest one-line name's min-content and
       scroll the rail sideways on each selection; a 0 minimum lets the name's
       ellipsis take the excess instead. */
    grid-template-columns: minmax(0, 1fr);
  }
  /* cqh measures the rail inside its padding: five tiles and four gaps. */
  .set-entry {
    height: calc((100cqh - 4 * 0.5rem) / 5);
  }
  .set-choice {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 6px 6px 8px;
  }
  .set-choice img,
  .set-placeholder {
    flex: 1 1 0;
    min-height: 0;
    aspect-ratio: auto;
  }
  .set-copy {
    flex: none;
    padding-top: 6px;
  }
  /* One line, so the picture keeps the height: five tiles leave each ~140px. */
  .set-choice strong {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}
.badge {
  display: inline-block;
  margin-bottom: 6px;
  padding: 1px 7px;
  border-radius: 2px;
  background: var(--mist);
  border: 1px solid var(--line-strong);
  font-size: var(--t-micro);
  font-weight: 700;
}

/* Stage */
.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.65rem 1.1rem;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}
.toolbar .zoom {
  margin-right: auto;
}
.toolbar button,
.toolbar select {
  font-size: var(--t-body);
  padding: 0.5em 1.1em;
}
.zoom {
  display: flex;
  align-items: center;
  gap: 6px;
}
/* Zoom out and in: round outlined buttons, as LEGO.com's carousel arrows. */
.zoom button:not(#fit) {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 2px solid var(--outline);
  background: none;
  font-size: var(--t-lead);
  line-height: 1;
}
.zoom button:not(#fit):hover {
  background: var(--pill);
}
#viewport {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: var(--stage);
}
#viewport canvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
/* The stage's corner readouts, set as LEGO.com's gallery counter ("1/19"):
   white type on a dark translucent pill. */
.stage-foot {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 14px;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  pointer-events: none;
  font-size: var(--t-body);
}
.stage-foot span {
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.62);
  color: #fff;
  font-weight: 500;
}
/* Build: the step's parts, as the callout box of an instruction booklet */
.step-parts {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1;
  max-width: min(300px, calc(100% - 32px));
  padding: 10px 14px 12px;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 1px 3px #0002;
  pointer-events: none;
  font-size: var(--t-body);
}
.step-parts p {
  margin: 0 0 6px;
  font-size: var(--t-body);
  font-weight: 700;
}
.step-parts .more {
  margin: 4px 0 0;
  color: var(--ink-2);
  font-size: var(--t-micro);
  font-weight: 500;
}
.step-parts ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
.step-parts li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}
.step-parts li span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.step-parts .swatch {
  margin-right: 0;
  flex-shrink: 0;
}
.step-parts b {
  min-width: 26px;
  font-weight: 700;
}
#turntable[aria-pressed='true'] {
  background: var(--ink);
  color: var(--paper);
}
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: var(--stage);
  text-align: center;
  z-index: 2;
  font-weight: 500;
}
/* Loading: the set's catalogue picture, faint, with its name, what is
   happening and a thin bar (indeterminate while downloading, full while the
   bricks are built). */
/* Leaving: once the first frame is drawn, viewer.js fades the card off it
   (REVEAL_MS there is this duration), so the model comes up through the stage
   colour rather than appearing at a stroke. The card's own contents go faster,
   so the small picture never lingers over the full-size model as a double image.
   The transition lives on the leaving state only, so a card put back to use is
   there at once. */
#loading.is-leaving {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease-out;
}
#loading.is-leaving .loading-card {
  opacity: 0;
  transition: opacity 0.2s ease-out;
}
.loading-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(340px, 100%);
}
.loading-thumb {
  width: min(17rem, 70%);
  height: auto;
  /* Plain opacity only: the picture's baked background is the stage colour,
     and any filter or blend shifts it into a visible box. */
  opacity: 0.5;
}
.loading-title {
  font-size: var(--t-lead);
  font-weight: 700;
}
.loading-line {
  margin: 0;
  color: var(--ink-2);
  font-size: var(--t-body);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.loading-bar {
  position: relative;
  display: block;
  width: 180px;
  height: 3px;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.08);
}
.loading-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 40%;
  border-radius: inherit;
  background: var(--blue);
  animation: loading-sweep 1.1s ease-in-out infinite;
}
#loading.is-building .loading-bar::after {
  width: 100%;
  animation: none;
}
@keyframes loading-sweep {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(250%);
  }
}
@media (prefers-reduced-motion: reduce) {
  .loading-bar::after {
    animation: none;
    width: 100%;
    opacity: 0.5;
  }
}
.texture-progress {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink-2);
  font-size: var(--t-micro);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
/* The tour's progress: a hairline along the stage's foot. */
.tour-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  height: 3px;
  background: var(--blue);
  transform-origin: left;
  pointer-events: none;
}
.adjustments {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 1.25rem;
  align-items: end;
  /* On a wide stage the controls keep a readable measure, centred under it. */
  padding: 0.8rem max(1.25rem, calc((100% - 64rem) / 2));
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.adjust-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: var(--t-body);
  font-weight: 700;
}
.adjust-head select {
  min-width: 0;
  max-width: 16rem;
  padding: 0.35em 0.6em;
  font-size: var(--t-body);
}
.adjust-head output {
  margin-left: auto;
  color: var(--ink-2);
  font-weight: 500;
}
.adjust-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  grid-row: 1 / 3;
  grid-column: 2;
}
/* Explode: LEGO.com's outlined pill, the lesser action beside a filled one. */
#explode-quick {
  min-width: 96px;
  border: 2px solid var(--outline);
  background: none;
}
#explode-quick:hover {
  background: var(--pill);
}
input[type='range'] {
  display: block;
  width: 100%;
  accent-color: var(--blue);
  cursor: pointer;
  margin: 8px 0 0;
}
.help {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  color: var(--ink-2);
  font-size: var(--t-body);
}

/* Build: the step number is set like an instruction booklet's */
#build-controls {
  padding: 0.9rem max(1.25rem, calc((100% - 64rem) / 2)) 0.8rem;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.build-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
#step-label {
  min-width: 132px;
  margin-right: 8px;
  font-size: var(--t-head);
  font-weight: 700;
  line-height: 1;
}
/* Play is the building action once Build is open, so it takes the orange. */
#play {
  min-width: 112px;
  background: var(--orange);
  color: #000;
}
#play:hover {
  background: var(--orange-dark);
}
#build-controls p {
  font-size: var(--t-body);
  color: var(--ink-2);
  margin: 6px 0 0;
}
#build-controls #assembly-status {
  color: var(--ink);
  font-weight: 500;
}
.speed-control,
.follow-control {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: var(--t-body);
  font-weight: 500;
}
.speed-control {
  margin-left: auto;
}
.speed-control select {
  padding: 6px 8px;
}
.follow-control input {
  accent-color: var(--blue);
}

/* Information column */
.details {
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Short of room (a long title on a low window), the column scrolls and
     Components keeps a usable list instead of being squeezed to nothing with
     its foot pushing the page past the window. */
  overflow-y: auto;
  scrollbar-width: thin;
  border-left: 1px solid var(--line);
}
.product {
  flex-shrink: 0;
  padding: 1.45rem 1.45rem 1.2rem;
  border-bottom: 1px solid var(--line);
}
/* Above the title: the series (where the set has one) and, at the right, the
   set number. */
.item-number {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 4px;
  color: var(--ink-2);
  font-size: var(--t-micro);
  font-weight: 500;
}
/* The number goes right only when a series stands at the left; alone it
   starts the line, over the title, as LEGO.com's item number does. */
.item-number span:last-child:not(:first-child) {
  margin-left: auto;
}
h1 {
  font-size: var(--t-display);
  font-weight: 700;
  line-height: 1.2;
}
h1.is-long {
  font-size: var(--t-head);
  line-height: 1.3;
}
/* The set's description as LEGO.com-style badges. */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
.tags li {
  padding: 0 0.8em;
  border-radius: 4px;
  background: var(--pill);
  color: var(--ink);
  font-size: var(--t-micro);
  font-weight: 500;
  line-height: 2;
}
/* LEGO.com's stats row: the number large, its label small beneath. */
.facts {
  display: flex;
  gap: 2.1rem;
  margin: 1.3rem 0 0;
}
.facts div {
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
}
.facts dt {
  color: var(--ink-2);
  font-size: var(--t-body);
}
.facts dd {
  margin: 0;
  font-size: var(--t-head);
  font-weight: 700;
  line-height: 1.15;
}
/* The page's one main action, in LEGO.com's buying orange. */
.build-cta {
  display: block;
  width: 100%;
  margin-top: 1.3rem;
  padding: 0.8em 1.2em;
  background: var(--orange);
  color: #000;
  font-size: var(--t-body);
  font-weight: 500;
}
.build-cta:hover {
  background: var(--orange-dark);
}
body.building .build-cta {
  display: none;
}
.display-size {
  margin: 10px 0 0;
  font-size: var(--t-body);
}
.instructions-link {
  display: inline-block;
  margin-top: 14px;
  font-weight: 500;
  text-underline-offset: 3px;
}
.accuracy {
  margin: 10px 0 0;
  color: var(--ink-2);
  font-size: var(--t-body);
  line-height: 1.5;
}
.accuracy summary {
  cursor: pointer;
  color: var(--ink);
  font-size: var(--t-body);
  font-weight: 500;
}
.accuracy p {
  margin: 6px 0 0;
}
.inspection {
  display: none;
}
body.inspecting .accuracy {
  display: none;
}
body.inspecting .inspection {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  max-height: 46%;
  margin: 14px 16px 0;
  border: 2px solid var(--blue);
  border-radius: var(--radius);
  background: var(--paper);
  overflow: hidden;
}
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 8px 14px;
  background: var(--blue-wash);
  font-size: var(--t-body);
  font-weight: 700;
}
#inspection-content {
  padding: 4px 14px 14px;
  overflow-y: auto;
  min-height: 0;
}
.brick-number {
  margin: 8px 0 2px;
  color: var(--ink-2);
  font-size: var(--t-body);
}
.selected-name {
  font-size: var(--t-lead);
  line-height: 1.25;
}
.color-chip {
  height: 22px;
  border-radius: 2px;
  border: 1px solid #0002;
  margin: 12px 0 8px;
}
#inspection-content p:not(.brick-number) {
  margin: 0;
  font-size: var(--t-body);
}
.part-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}
.part-actions button {
  font-size: var(--t-body);
  padding: 5px 8px;
}
.components {
  display: flex;
  flex-direction: column;
  flex: 1 0 auto;
  /* Its heading, tabs, search and foot, and about five rows of the list. */
  height: 0;
  min-height: 25rem;
  padding: 1.2rem 1.05rem 0.8rem;
}
.components .rail-title {
  padding: 0 6px;
}
/* LEGO.com's tabs ("Featured", "Popular"): plain words, the chosen one bold
   over a 2px dark rule. */
.tabs {
  display: flex;
  gap: 20px;
  margin-top: 10px;
  padding: 0 6px;
}
.tabs button {
  padding: 4px 0 6px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  font-size: var(--t-body);
  font-weight: 400;
  color: var(--text);
}
.tabs button:hover {
  background: none;
  border-bottom-color: var(--line-strong);
}
.tabs button[aria-pressed='true'] {
  color: var(--ink);
  font-weight: 700;
  border-bottom-color: var(--ink);
}
.search {
  display: block;
  margin: 12px 0 8px;
}
/* LEGO.com's search: a white pill with a grey edge. */
.search input {
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0.65em 1.15em;
  font-size: var(--t-body);
}
.whole {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.6em 1.15em;
  font-size: var(--t-body);
}
.whole span {
  color: var(--ink-2);
  font-weight: 500;
}
.list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  margin: 6px 0;
}
.list button {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 6px;
  background: none;
  padding: 0.5em 6px;
  font-size: var(--t-body);
  font-weight: 500;
}
.list button:hover {
  background: var(--mist);
}
.list button[aria-pressed='true'] {
  background: var(--blue-wash);
  color: var(--blue-dark);
  font-weight: 700;
}
.list button > span:last-child {
  flex-shrink: 0;
  color: var(--ink-2);
  font-size: var(--t-micro);
  font-weight: 500;
}
.manifest-subsection h3 {
  margin: 14px 6px 4px;
  font-size: var(--t-body);
  font-weight: 700;
}
.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 8px;
  border: 1px solid #0003;
  vertical-align: -1px;
}
.manifest-foot {
  flex-shrink: 0;
  padding: 8px 6px 0;
  border-top: 1px solid var(--line);
  font-size: var(--t-micro);
  color: var(--ink-2);
}

footer {
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 16px;
  padding: 0.6rem 1.5rem;
  background: var(--paper);
  font-size: var(--t-micro);
  color: var(--ink-2);
}
dialog {
  width: min(620px, calc(100% - 32px));
  max-height: 85dvh;
  overflow: auto;
  border: 0;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  padding: 28px 32px;
  line-height: 1.6;
  box-shadow: 0 12px 48px #0004;
}
dialog h2 {
  font-size: var(--t-head);
  margin-bottom: 8px;
}
dialog::backdrop {
  background: #0008;
}
#close-credits,
#close-inspection {
  float: right;
  margin-left: 12px; /* clear of the heading it floats beside */
  padding: 0 8px;
  font-size: var(--t-head);
  line-height: 28px;
  border: 0;
  border-radius: 999px;
  background: none;
}
#close-inspection {
  float: none;
}
.pending-model {
  max-width: 460px;
  text-align: left;
}
.pending-model h2 {
  font-size: var(--t-head);
  line-height: 1.2;
}
.pending-model p {
  color: var(--ink-2);
  font-weight: 400;
}
.pending-model a {
  display: inline-block;
  margin-top: 8px;
  padding: 10px 20px;
  border: 2px solid var(--outline);
  border-radius: 999px;
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.skip {
  position: absolute;
  top: -100px;
  z-index: 9;
  padding: 10px;
  background: var(--paper);
}
.skip:focus {
  top: 0;
}
[hidden] {
  display: none !important;
}
noscript {
  position: absolute;
  top: 40%;
  left: 35%;
  z-index: 4;
  background: var(--paper);
  padding: 20px;
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}


/* Phones and narrow windows: one scrolling column (its order is set out below).
   The brick inspector becomes a bottom sheet. */
@media (max-width: 860px) {
  body {
    height: auto;
    min-height: 100dvh;
  }
  header {
    position: sticky;
    top: 0;
    z-index: 6;
    display: grid;
    grid-template-columns: auto 1fr;
    height: auto;
    min-height: 96px;
    gap: 4px 10px;
    padding: 8px 12px;
  }
  header nav { grid-row: 2; grid-column: 1 / -1; flex-wrap: wrap; }
  .header-links { grid-row: 1; grid-column: 2; }
  header nav button,
  .header-links button {
    height: 36px;
    padding: 0 12px;
    font-size: var(--t-body);
  }
  .brand span,
  .header-links a {
    display: none;
  }
  .header-links .video-link {
    display: inline-flex;
    padding-inline: 8px;
  }
  .video-link span {
    display: none;
  }
  main {
    display: flex;
    flex-direction: column;
  }
  /* One column, in the order a thumb wants it: the sets as a strip to switch
     between, the stage, the Build button, the stage's controls, then the set's
     title and facts, then Components. The wrappers dissolve so their children
     can take that order; only the Build button leaves its place in the markup. */
  .workspace,
  .details,
  .product,
  .model-info {
    display: contents;
  }
  .manifest {
    order: 1;
    border: 0;
    border-bottom: 1px solid var(--line);
  }
  .toolbar {
    order: 2;
  }
  #viewport {
    order: 3;
  }
  .build-cta {
    order: 4;
    width: auto;
    margin: 12px 16px;
    padding: 12px 20px;
  }
  .adjustments,
  #build-controls {
    order: 5;
  }
  .item-number,
  h1,
  .tags,
  .facts,
  .display-size,
  .instructions-link,
  .accuracy {
    order: 6;
    margin-left: 16px;
    margin-right: 16px;
  }
  .item-number {
    margin: 0;
    padding: 18px 16px 4px;
    border-top: 1px solid var(--line);
  }
  .instructions-link {
    align-self: flex-start;
  }
  .accuracy {
    margin-bottom: 16px;
  }
  .components {
    order: 7;
    flex: none;
    height: auto;
    min-height: 0;
    padding: 18px 10px 12px;
    border-top: 1px solid var(--line);
  }
  /* The sets: small pictures with one line of name, scrolled sideways. The
     heading stays for assistive technology only. */
  .manifest .rail-title {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .sets-menu { padding: 16px; max-height: calc(100dvh - 112px); }
  .sets-menu-head { gap: 10px; margin-bottom: 12px; }
  .theme-library { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .theme-choice { flex-direction: column; gap: 8px; text-align: center; }
  .set-library {
    grid-auto-flow: column;
    grid-auto-columns: 96px;
    gap: 10px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 10px 16px;
  }
  .set-choice,
  .set-choice[aria-pressed='true'] {
    display: block;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: none;
  }
  .set-choice img,
  .set-placeholder {
    outline: 2px solid transparent;
    outline-offset: 2px;
  }
  .set-choice[aria-pressed='true'] img,
  .set-choice[aria-pressed='true'] .set-placeholder {
    outline-color: var(--blue);
  }
  .set-copy {
    padding: 5px 0 0;
  }
  .set-choice strong {
    display: block;
    overflow: hidden;
    font-size: var(--t-micro);
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  h1 {
    font-size: var(--t-head);
  }
  #viewport {
    flex: none;
    height: min(54vh, 480px);
  }
  /* Camera actions wrap on phones, keeping Free explore in view. */
  .toolbar {
    padding: 8px 10px;
    gap: 5px;
    flex-wrap: wrap;
  }
  .toolbar > * {
    flex-shrink: 0;
  }
  /* Compact camera controls leave a second row for Free explore. */
  .toolbar button,
  .toolbar select {
    padding: 7px 8px;
    font-size: 13px; /* off the scale on purpose: the largest that fits 360px */
  }
  .zoom {
    gap: 4px;
  }
  .zoom button:not(#fit) {
    width: 30px;
    height: 30px;
    padding: 0;
    font-size: var(--t-body);
  }
  #capture {
    display: none;
  }
  .stage-foot {
    left: 14px;
    right: 14px;
    bottom: 12px;
    font-size: var(--t-micro);
  }
  .adjustments,
  #build-controls {
    padding: 12px 16px;
  }
  .speed-control {
    margin-left: 0;
  }
  /* The Explode menu keeps a readable width; the readout moves beside it. */
  .adjustments {
    grid-template-columns: 1fr;
  }
  .adjust-head select {
    flex: 1;
    max-width: none;
  }
  .adjust-actions {
    grid-row: auto;
    grid-column: 1;
    margin-top: 10px;
  }
  .adjust-actions button {
    flex: 1;
  }
  /* The step number takes its own line, so the four buttons stay together. */
  #step-label {
    flex-basis: 100%;
    margin: 0 0 2px;
  }
  #play {
    flex: 1;
    min-width: 0;
  }
  .list {
    flex: none;
    max-height: 50vh;
  }
  body.inspecting .inspection {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 7;
    max-height: 52dvh;
    margin: 0;
    border-width: 2px 0 0;
    border-radius: 0;
    box-shadow: 0 -8px 32px #0003;
  }
  footer {
    flex-direction: column;
    gap: 2px;
    padding: 10px 16px;
  }
}

/* Play stays beside the model as a compact, touch-friendly control shelf. */
#drive-controls, #tour-controls, #explore-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  order: 5;
}
#drive-controls[hidden], #tour-controls[hidden], #explore-controls[hidden] { display: none; }
.drive-main { display: flex; align-items: center; gap: 20px; min-width: 0; }
.drive-copy { display: flex; flex-direction: column; gap: 3px; font-size: var(--t-micro); color: var(--ink-2); max-width: 230px; }
.drive-copy strong { color: var(--ink); font-size: var(--t-body); }
.drive-pad { display: grid; flex: 0 0 auto; grid-template-columns: repeat(3, 40px); gap: 4px; }
.drive-pad button { height: 38px; min-height: 38px; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); touch-action: none; user-select: none; }
.drive-pad button:first-child { grid-column: 2; }
.drive-pad button:nth-child(2) { grid-column: 1; }
.drive-pad [data-drive="down"] { grid-area: 1 / 1; }
.drive-pad [data-drive="up"] { grid-area: 1 / 3; }
.drive-pad button[hidden] { display: none; }
.drive-pad button span { color: var(--ink-2); }
.drive-pad .is-held { background: var(--yellow); border-color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); }
#lamp-head-controls { display: flex; align-items: center; gap: 10px; max-width: 100%; font-size: var(--t-micro); }
#lamp-head-controls[hidden] { display: none; }
#lamp-head-controls label { white-space: nowrap; }
#lamp-head-turn { width: 120px; min-width: 70px; min-height: 44px; }
#lamp-head-center { min-height: 44px; }
#mechanism, #room-doors, #explore-mechanism { background: var(--yellow); color: var(--ink); min-width: 100px; min-height: 44px; flex-shrink: 0; }
/* In Explore, opening controls share Reset's natural pill sizing. */
.adjust-actions #room-doors,
.adjust-actions #explore-mechanism {
  min-width: 0;
  min-height: 0;
}
#mechanism:hover, #room-doors:hover, #explore-mechanism:hover { box-shadow: inset 0 0 0 2px var(--ink); }
.drive-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.drive-actions button { min-height: 40px; white-space: nowrap; padding-inline: 14px; }
#drive-exit { background: transparent; border: 1px solid var(--line); }
#drive-exit:hover { border-color: var(--ink); }
body.walking .build-cta, body.touring .build-cta { display: none; }
@media (max-width: 1500px) and (min-width: 1101px) {
  #drive-controls, #tour-controls, #explore-controls { gap: 12px; padding-inline: 16px; }
  .drive-main { gap: 12px; }
  .drive-copy { max-width: 185px; }
  .drive-actions button { padding-inline: 11px; }
}
@media (max-width: 1100px) {
  #drive-controls, #tour-controls, #explore-controls { flex-wrap: wrap; padding: 14px 16px; gap: 12px; }
  .drive-main { width: 100%; justify-content: space-between; }
  .drive-actions { width: 100%; justify-content: flex-start; padding-top: 12px; border-top: 1px solid var(--line); }
}
@media (max-width: 400px) {
  .drive-main { gap: 10px; }
  .drive-copy { max-width: 174px; }
  .drive-actions { gap: 5px; }
  .drive-actions button { padding-inline: 11px; }
  header { gap: 4px; }
  header nav button, .header-links button { padding-inline: 10px; }
}
.drive-copy[hidden], .drive-pad[hidden] { display: none; }

/* Two playable keyboard banks stay below the model and stack on phones. */
#drive-controls.has-piano { flex-wrap: wrap; }
#drive-controls.has-piano .drive-main { display: none; }
#piano-panel { width: 100%; max-width: 1100px; min-width: 0; }
#piano-panel[hidden] { display: none; }
.piano-heading, .piano-settings { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; }
.piano-heading { justify-content: space-between; margin-bottom: 12px; }
.piano-heading strong { font-size: var(--t-body); }
#piano-status { margin-left: 12px; color: var(--ink-2); font-size: var(--t-micro); }
.piano-hint { color: var(--ink-2); font-size: var(--t-micro); }
.piano-scroll {
  padding-bottom: 4px;
}
.piano-keys {
  display: grid;
  grid-template-columns: 7fr 8fr;
  gap: 18px;
}
.piano-bank {
  min-width: 0;
}
.piano-bank-heading {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: var(--t-micro);
  color: var(--ink-2);
}
.piano-bank-heading span:first-child {
  font-weight: 700;
  color: var(--ink);
}
.piano-board {
  position: relative;
  height: 122px;
  border-top: 5px solid var(--ink);
}
@media (max-width: 700px) {
  .piano-keys {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .piano-board {
    height: 112px;
  }
  .piano-board .piano-key {
    height: 106px;
  }
  .piano-board .piano-key.is-black {
    height: 59px;
  }
}
/* Key colours are the instrument's own (ivory, ebony, their edges), not page
   tokens; a held key lights in the page yellow. */
.piano-key {
  position: absolute;
  left: var(--key-left);
  top: 0;
  width: calc(100% / var(--white-keys) - 2px);
  height: 116px;
  border: 1px solid #b5b8bb;
  border-bottom: 4px solid #c7cace;
  border-radius: 0 0 5px 5px;
  background: var(--paper);
  color: #444;
  padding: 0 0 9px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 2px;
  touch-action: none;
}
.piano-key kbd {
  font: inherit;
  font-size: var(--t-body);
  font-weight: 500;
  line-height: 1.2;
}
.piano-key.is-black {
  z-index: 1;
  width: calc(100% / var(--white-keys) * 0.64);
  height: 63px;
  color: var(--paper);
  background: #25272a;
  border-color: #111;
  border-bottom-color: #070707;
}
.piano-key:hover {
  background: #f0f1f2;
}
.piano-key.is-black:hover {
  background: #414449;
}
.piano-key.is-held {
  background: var(--yellow);
  border-bottom-width: 1px;
  transform: translateY(3px);
  color: var(--ink);
}
.piano-key.is-black.is-held {
  background: #d7af00;
}
.piano-settings {
  margin-top: 10px;
}
.piano-settings button {
  min-height: 36px;
  padding: 7px 12px;
  font-size: var(--t-micro);
}
.piano-settings label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--t-micro);
}
.piano-settings input {
  width: 90px;
  accent-color: var(--ink);
}
.piano-settings button[aria-pressed="true"] {
  background: var(--yellow);
}
.has-piano .drive-actions {
  margin-left: auto;
}

.drive-pad [data-drive="jump"] { grid-area: 1 / 3; }
/* Phones: the pad floats over the stage's lower right, above the readouts. */
.drive-pad.is-overlay { position: absolute; right: 12px; bottom: 52px; z-index: 2; grid-template-columns: repeat(3, 52px); gap: 6px; }
.drive-pad.is-overlay button { height: 52px; min-height: 52px; background: color-mix(in srgb, var(--paper) 86%, transparent); box-shadow: 0 1px 4px #0003; }
.drive-pad.is-overlay .is-held { background: var(--yellow); }

.piano-player {
  display: flex;
  align-items: center;
  gap: 8px 12px;
  flex-wrap: wrap;
  padding: 10px 0 14px;
  border-top: 1px solid var(--line);
}
.piano-player label {
  font-size: var(--t-body);
  font-weight: 500;
}
.piano-player label span {
  display: block;
  color: var(--ink-2);
  font-size: var(--t-micro);
  font-weight: 400;
}
.piano-player select {
  max-width: 100%;
  min-width: 0;
  font: inherit;
  font-size: var(--t-body);
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}
#piano-song-play {
  background: var(--yellow);
  min-width: 96px;
}
.piano-player progress {
  width: 72px;
  height: 5px;
  accent-color: var(--ink);
}
#piano-song-time {
  font-size: var(--t-micro);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
@media (max-width: 600px) {
  .piano-player label {
    width: 100%;
  }
  .piano-player select {
    flex: 1 1 100%;
  }
}

#drive-controls { flex-wrap: wrap; }
.play-scene-picker { flex: 1 0 100%; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
#play-scene-status, #play-scene-credit { font-size: var(--t-micro); color: var(--ink-2); }
#play-scene-credit { margin-left: auto; }
@media (max-width: 600px) { #play-scene-status { flex-basis: 100%; } #play-scene-credit { margin-left: 0; } }

#piano-song-credit { flex-basis: 100%; font-size: var(--t-micro); color: var(--ink-2); }

.play-scene-picker select { max-width: 100%; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--paper); color: var(--ink); font: inherit; font-size: var(--t-body); }

/* Free flight uses the same shelf as Play, with its own input ownership. */
#free-explore { background: var(--yellow); }
.drive-pad [data-explore="down"] { grid-area: 1 / 1; }
.drive-pad [data-explore="up"] { grid-area: 1 / 3; }
.explore-speed { display: flex; align-items: center; gap: 8px; font-size: var(--t-micro); }
.explore-speed select { min-height: 40px; }
body.free-exploring .toolbar .zoom,
body.free-exploring .toolbar > label,
body.free-exploring #turntable,
body.free-exploring #free-explore,
body.free-exploring .build-cta { display: none; }
body.free-exploring #viewport canvas { cursor: crosshair; touch-action: none; }
#explore-controls .drive-main { flex: 1 1 auto; }
#explore-controls .drive-actions { flex: 0 1 360px; }
@media (max-width: 1100px) {
  #explore-controls .drive-actions { flex-basis: 100%; }
}

@media (max-width: 860px) {
  #explore-controls .drive-copy { max-width: none; }
}
