/* ClickDragSnap — mobile-first styles */

/* Outfit (SIL Open Font License, see assets/fonts/OFL.txt), served from this site. */
@font-face {
  font-family: "Outfit";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../assets/fonts/outfit-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Outfit";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../assets/fonts/outfit-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --font-display: "Outfit", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-body: "Outfit", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Neutrals: near-black ink on warm paper */
  --ink: #111114;
  --ink-2: #46464e;
  --ink-3: #6b6b74;
  --line: rgba(17, 17, 20, 0.1);
  --line-strong: rgba(17, 17, 20, 0.2);
  --surface: #ffffff;
  --surface-2: #f3f2ee;
  --surface-3: #e9e8e2;
  --stage-1: #fbfaf7;
  --stage-2: #efeee9;

  /* Main buttons: ink pills */
  --primary: #111114;
  --primary-hover: #2c2c33;
  --primary-press: #000000;
  --on-primary: #ffffff;

  /* Selected and active states: iris */
  --accent: #5b55f0;
  --accent-hover: #4d47e4;
  --accent-press: #423cd6;
  --accent-ink: #ffffff;
  --accent-edge: #4a43d9;
  --accent-tint: #ecebff;
  --accent-soft: #d4d1ff;

  /* Playful pastels for shapes, cards and boxes */
  --c-lilac: #c9c5ff;
  --c-blue: #8fb0fa;
  --c-orange: #ff9f6e;
  --c-pink: #f7c6ef;
  --c-lime: #ddf27a;
  --c-yellow: #fff27a;
  --c-mint: #9de8b9;

  --callout: var(--accent-tint);
  --callout-line: var(--accent-soft);
  --highlight: #ff7a3d;
  --focus: #3d36d9;
  --success: #17955a;
  --danger: #d93a2f;
  --warn-bg: #fff8d9;
  --warn-line: #f0dd8c;
  --warn-ink: #5c4300;

  --radius-s: 12px;
  --radius-m: 16px;
  --radius-l: 28px;
  --radius-pill: 999px;
  --shadow-1: 0 1px 2px rgba(17, 17, 20, 0.06), 0 2px 8px rgba(17, 17, 20, 0.05);
  --shadow-2: 0 2px 6px rgba(17, 17, 20, 0.05), 0 16px 40px rgba(17, 17, 20, 0.14);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --gutter: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--stage-2);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

img {
  display: block;
  max-width: 100%;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.eyebrow {
  font: 700 12px/1.2 var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 22px;
  border-radius: var(--radius-pill);
  font: 600 16px/1 var(--font-display);
  letter-spacing: 0;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.985);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-lg {
  min-height: 54px;
  font-size: 17px;
  padding: 0 26px;
}

.btn-block {
  width: 100%;
}

/* The main action: an ink pill */
.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--primary-press);
}

/* Everything else: an outlined pill */
.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  min-height: 44px;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--ink);
}

.icon-btn {
  appearance: none;
  border: 0;
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line), var(--shadow-1);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, transform 0.12s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-1);
}

.icon-btn[aria-pressed="true"]:hover {
  background: var(--accent-hover);
}

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

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.stage {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(130% 85% at 50% 38%, var(--stage-1) 0%, #f5f4f0 45%, var(--stage-2) 100%);
}

.viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
  -webkit-tap-highlight-color: transparent;
}

.viewport:active {
  cursor: grabbing;
}

/* A long press on the 3D view (to add a piece to the selection) must not start iOS text
   selection or the Copy / Translate menu. Text fields keep working. */
.stage {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* The home screen is ordinary reading content: let people select and copy it. The 3D
   carousel and buttons stay unselectable so dragging and tapping them behave. */
.welcome {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

.welcome .showcase-stage,
.welcome .mode-tabs,
.welcome .btn,
.welcome .set-card-open {
  -webkit-user-select: none;
  user-select: none;
}

.stage input,
.stage textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* Visibility per view */
.app[data-view="welcome"] .topbar,
.app[data-view="welcome"] .view-tools,
.app[data-view="welcome"] .drawer,
.app[data-view="welcome"] .viewport,
.app[data-view="cover"] .view-tools,
.app[data-view="complete"] .view-tools,
.app[data-overlay="bag"] .view-tools {
  display: none;
}

/* ---------- Drawer (step list) ---------- */

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  width: min(88vw, 360px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  transform: translateX(-104%);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-left: var(--safe-left);
}

.app[data-drawer="open"] .drawer {
  transform: none;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(17, 17, 20, 0.36);
  animation: fade-in 0.2s ease;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) 14px 6px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 700 18px/1 var(--font-display);
  letter-spacing: -0.01em;
}

.brand-link {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  border-radius: 8px;
}

.brand-mark {
  width: 28px;
  height: 28px;
}

.drawer-close {
  box-shadow: none;
  background: var(--surface-2);
}

.set-summary {
  padding: 12px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.set-title {
  margin-top: 4px;
  font: 700 22px/1.2 var(--font-display);
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.set-meta {
  margin-top: 4px;
  font-size: 14px;
  color: var(--ink-2);
}

.step-nav {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 14px 12px 18px;
  overscroll-behavior: contain;
}

.bag-group + .bag-group {
  margin-top: 16px;
}

.bag-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 8px 6px;
  font: 700 15px/1 var(--font-display);
}

.bag-badge {
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: #fff;
  font: 700 13px/1 var(--font-display);
}

.bag-count {
  margin-left: auto;
  font: 500 12px/1 var(--font-body);
  color: var(--ink-3);
}

.step-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}

.step-item {
  appearance: none;
  width: 100%;
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  font: 500 15px/1.2 var(--font-body);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.step-item:hover {
  background: var(--surface-2);
}

.step-item.is-current {
  background: var(--accent-tint);
  font-weight: 700;
}

.step-dot {
  position: relative;
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--surface);
}

.step-item.is-done .step-dot {
  background: var(--success);
  border-color: var(--success);
}

.step-item.is-done .step-dot::after {
  content: "";
  position: absolute;
  left: 4.5px;
  top: 1.5px;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.step-item.is-current .step-dot {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.step-pcs {
  margin-left: auto;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
}

.drawer-foot {
  padding: 12px 16px calc(16px + var(--safe-bottom));
  border-top: 1px solid var(--line);
}

/* Which step to note down, in case the browser clears saved progress */
.save-note {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-s);
  background: var(--surface-2);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-2);
}

.save-note[hidden] {
  display: none;
}

.save-note .icon {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  color: var(--ink-3);
}

.save-note strong {
  display: block;
  color: var(--ink);
  font-weight: 700;
}

/* Sound on/off, a switch at the bottom of the step list (M toggles it too) */
.drawer-toggle {
  appearance: none;
  border: 0;
  width: 100%;
  min-height: 44px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 0 12px;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--ink-2);
  font: 700 15px/1 var(--font-display);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.drawer-toggle:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.drawer-toggle .icon {
  width: 20px;
  height: 20px;
}

.drawer-toggle-label {
  flex: 1;
  text-align: left;
}

.switch {
  position: relative;
  flex: none;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background-color 0.15s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(17, 17, 20, 0.2);
  transition: transform 0.15s ease;
}

[aria-pressed="true"] > .switch {
  background: var(--success);
}

[aria-pressed="true"] > .switch::after {
  transform: translateX(16px);
}

/* ---------- Top bar ---------- */

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 10px) calc(var(--gutter) + var(--safe-right)) 6px calc(var(--gutter) + var(--safe-left));
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

/* The title is just text: let drags on it rotate the model underneath. */
.topbar .topbar-title {
  pointer-events: none;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.topbar-set {
  font: 700 16px/1.2 var(--font-display);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-step {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Step card ---------- */

.callout {
  position: absolute;
  top: calc(var(--safe-top) + 62px);
  left: calc(var(--gutter) + var(--safe-left));
  right: calc(var(--gutter) + var(--safe-right));
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 10px;
  background: var(--callout);
  border: 1.5px solid var(--callout-line);
  border-radius: 24px;
  box-shadow: var(--shadow-1);
  animation: drop-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.callout.is-done {
  background: #e3f7ea;
  border-color: var(--c-mint);
}

.callout-step {
  flex: none;
  min-width: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.callout-bag {
  /* number only: the label stays for screen readers */
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  font: 700 10px/1 var(--font-body);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
}

.callout-num {
  font: 700 32px/0.9 var(--font-display);
  letter-spacing: -0.03em;
}

.callout-body {
  flex: 1;
  min-width: 0;
}

.callout-heading {
  /* visually hidden on phones to save height; still names the section */
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  margin-bottom: 4px;
  font: 700 11px/1.2 var(--font-body);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.needed {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 2px;
}

.needed-item {
  position: relative;
  flex: none;
  width: 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.needed-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(17, 17, 20, 0.32)) drop-shadow(0 0 0.5px rgba(17, 17, 20, 0.25));
  transition: opacity 0.25s ease;
}

.needed-img-empty {
  display: block;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.6);
}

.needed-qty {
  min-height: 13px;
  font: 700 13px/1 var(--font-display);
}

.needed-item.is-done .needed-img {
  opacity: 0.3;
}

.needed-item.is-done::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  width: 24px;
  height: 24px;
  margin-left: -12px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 2px 6px rgba(30, 158, 90, 0.35);
}

.needed-item.is-done::after {
  content: "";
  position: absolute;
  top: 13px;
  left: 50%;
  width: 5px;
  height: 10px;
  margin-left: -3px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

/* Pieces in the bag inventory (bag intro) */

.part {
  flex: none;
  width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.part-img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(17, 17, 20, 0.32)) drop-shadow(0 0 0.5px rgba(17, 17, 20, 0.25));
}

.part-img-empty {
  display: block;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.6);
}

.part-qty {
  font: 700 14px/1 var(--font-display);
  color: var(--ink);
}

/* ---------- View tools ---------- */

.view-tools {
  position: absolute;
  right: calc(var(--gutter) + var(--safe-right));
  bottom: calc(var(--tray-h, 160px) + 12px);
  z-index: 11;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sound-btn .icon-sound-off,
.sound-btn[aria-pressed="false"] .icon-sound-on {
  display: none;
}

.sound-btn[aria-pressed="false"] .icon-sound-off {
  display: block;
}

.adjust-wrap {
  position: relative;
}

.view-adjust {
  position: absolute;
  bottom: 0;
  right: calc(100% + 8px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: coach-in 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.viewport:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

/* ---------- Coach (tips and feedback) ---------- */

.coach {
  position: absolute;
  left: calc(var(--gutter) + var(--safe-left));
  right: calc(var(--gutter) + var(--safe-right) + 56px);
  bottom: calc(var(--tray-h, 160px) + 12px);
  z-index: 13;
  width: fit-content;
  max-width: 460px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border-radius: 22px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow-2);
  font: 600 14px/1.35 var(--font-body);
}

.coach[data-tone="success"] {
  background: #0f6b3e;
}

.coach[data-tone="warn"] {
  background: #8a3b00;
}

.coach.is-in {
  animation: coach-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.coach-text {
  padding: 4px 0;
}

.btn-sm {
  flex: none;
  min-height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  white-space: nowrap;
}

/* ---------- Parts tray ---------- */

.tray {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  padding: 10px 0 calc(10px + var(--safe-bottom));
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -1px 0 var(--line), 0 -8px 28px rgba(17, 17, 20, 0.08);
}

.tray .progress {
  margin: 0 calc(var(--gutter) + var(--safe-right)) 8px calc(var(--gutter) + var(--safe-left));
}

.tray-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 calc(var(--gutter) + var(--safe-right) + 4px) 6px calc(var(--gutter) + var(--safe-left) + 4px);
}

.tray-title {
  font: 700 15px/1.2 var(--font-display);
}

.tray-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
}

.tray-list {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 4px calc(var(--gutter) + var(--safe-right)) 4px calc(var(--gutter) + var(--safe-left));
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  scroll-padding: 0 var(--gutter);
  scrollbar-width: none;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.tray-list::-webkit-scrollbar {
  display: none;
}

.tile-wrap {
  flex: none;
}

.tile-wrap.is-entering {
  animation: tile-in 0.36s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(var(--i, 0) * 28ms);
}

.tile {
  position: relative;
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--surface-2);
  box-shadow: none;
  cursor: grab;
  touch-action: pan-x;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.tile:hover {
  background: var(--surface-3);
}

.tile:active {
  cursor: grabbing;
}

.tile-img {
  width: 62px;
  height: 62px;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 1px 1px rgba(17, 17, 20, 0.32)) drop-shadow(0 0 0.5px rgba(17, 17, 20, 0.25));
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.tile-img-empty {
  display: block;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
}

.tile-count {
  position: absolute;
  top: 5px;
  right: 5px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--ink);
  color: #fff;
  font: 700 12px/22px var(--font-display);
  text-align: center;
}

.tile.is-selected {
  background: var(--accent-tint);
  box-shadow: inset 0 0 0 3px var(--accent);
  transform: translateY(-3px);
}

.tile.is-needed {
  box-shadow: inset 0 0 0 2.5px var(--highlight);
}

/* The glow round a needed tile pulses by fading between a tight halo and a wide, fainter one.
   Fading (opacity) runs on the graphics card; a growing box-shadow would repaint the tile every frame. */
.tile.is-needed::before,
.tile.is-needed::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}

.tile.is-needed::before {
  box-shadow: 0 0 0 4px rgba(255, 122, 61, 0.3);
  animation: tile-glow 0.9s ease-in-out infinite alternate;
}

.tile.is-needed::after {
  box-shadow: 0 0 0 7px rgba(255, 122, 61, 0.13);
  opacity: 0;
  animation: tile-glow-wide 0.9s ease-in-out infinite alternate;
}

.tile.is-lifted .tile-img {
  opacity: 0.35;
  transform: scale(0.9);
}

.tile.is-empty .tile-count {
  background: var(--ink-3);
}

.tile.is-shake {
  animation: shake 0.42s ease;
}

.progress {
  display: flex;
  gap: 4px;
}

.progress-seg {
  flex: 1 1 0;
  min-width: 0;
}

.progress-track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.drag-image {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 90;
  width: 76px;
  height: 76px;
  pointer-events: none;
  filter: drop-shadow(0 10px 14px rgba(17, 17, 20, 0.3));
  will-change: transform;
}

/* ---------- Panels (cover, bag intro, complete) ---------- */

.panel {
  position: absolute;
  left: calc(8px + var(--safe-left));
  right: calc(8px + var(--safe-right));
  bottom: calc(8px + var(--safe-bottom));
  z-index: 20;
  max-height: calc(100% - var(--safe-top) - 84px);
  overflow-y: auto;
  padding: 22px 20px 20px;
  background: var(--surface);
  border-radius: 32px;
  box-shadow: var(--shadow-2);
  animation: sheet-in 0.36s cubic-bezier(0.2, 0.8, 0.2, 1);
  overscroll-behavior: contain;
}

.panel-title {
  margin: 6px 0 12px;
  font: 700 28px/1.1 var(--font-display);
  letter-spacing: -0.03em;
  overflow-wrap: anywhere;
}

.panel-text {
  margin-bottom: 18px;
  font-size: 16px;
  color: var(--ink-2);
}

.panel-actions {
  display: grid;
  gap: 10px;
}

.stats {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  gap: 8px;
}

.stats li {
  flex: 1;
  padding: 10px 8px;
  border-radius: 20px;
  background: var(--surface-2);
  text-align: center;
  font-size: 13px;
  color: var(--ink-2);
}

.stats strong {
  display: block;
  font: 700 24px/1.1 var(--font-display);
  color: var(--ink);
}

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 16px;
  padding: 12px;
  border-radius: 18px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn-ink);
  font-size: 14px;
}

.notice .icon {
  width: 20px;
  height: 20px;
  margin-top: 1px;
}

.bag-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.bag-hero .panel-title {
  margin: 4px 0 2px;
}

.bag-badge-lg {
  position: relative;
  flex: none;
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  border-radius: 26px;
  background: var(--c-lilac);
  color: var(--ink);
}

.bag-badge-lg .icon {
  width: 58px;
  height: 58px;
  stroke-width: 1.4;
}

.bag-badge-lg span {
  position: absolute;
  left: 0;
  right: 0;
  top: 41%;
  text-align: center;
  font: 700 22px/1 var(--font-display);
  color: var(--ink);
}

.bag-meta {
  font-size: 15px;
  color: var(--ink-2);
}

.inventory-label {
  margin-bottom: 8px;
  font: 700 12px/1.2 var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.inventory {
  list-style: none;
  margin: 0 0 16px;
  padding: 10px 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px 4px;
  max-height: 34vh;
  overflow-y: auto;
  background: var(--surface-2);
  border: 0;
  border-radius: 20px;
}

.inventory .part {
  width: auto;
}

/* ---------- Welcome ---------- */

.welcome {
  position: absolute;
  inset: 0;
  z-index: 30;
  overflow-y: auto;
  background: var(--stage-1);
}

.welcome-inner {
  min-height: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 24px) calc(20px + var(--safe-right)) calc(var(--safe-bottom) + 28px) calc(20px + var(--safe-left));
}

.brand-lg {
  font-size: 20px;
}

.brand-lg .brand-mark {
  width: 34px;
  height: 34px;
}

.welcome .welcome-brand {
  margin: 0;
  font: 700 20px/1 var(--font-display);
  letter-spacing: -0.02em;
}

/* One line under the logo saying what the site is, for visitors who arrive from a link */
.welcome-lead {
  margin: 10px 0 0;
  max-width: 34ch;
  font: 500 16px/1.4 var(--font-body);
  color: var(--ink-2);
  text-wrap: balance;
}

/* ---------- Home: example set showcase ---------- */

/* Phones: the 3D view, its dots right below, then the set's details. */
.showcase {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "stage"
    "dots"
    "slide";
  justify-items: center;
}

.showcase-stage {
  grid-area: stage;
  position: relative;
  width: calc(100% + 40px);
  height: clamp(250px, 66vw, 360px);
  margin: 0 -20px;
}

.showcase-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 28px;
  touch-action: none; /* a finger turns the model any way; the page scrolls from the text below */
  cursor: grab;
  outline: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  /* fade the model's shadow out at the bottom instead of cutting it off */
  -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
}

.showcase-canvas:active {
  cursor: grabbing;
}

.showcase-canvas:focus-visible {
  box-shadow: inset 0 0 0 3px var(--focus);
}

.showcase[data-switching="next"] .showcase-canvas {
  opacity: 0;
  transform: translateX(-28px);
}

.showcase[data-switching="prev"] .showcase-canvas {
  opacity: 0;
  transform: translateX(28px);
}

.showcase-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -13px 0 0 -13px;
  pointer-events: none;
}

.showcase-nav {
  position: absolute;
  top: 50%;
  margin-top: -22px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

.showcase-prev {
  left: 16px;
}

.showcase-next {
  right: 16px;
}

.showcase[data-failed] .showcase-stage::after {
  content: "Couldn’t load this set. Check your connection.";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0 72px;
  text-align: center;
  font-size: 14px;
  color: var(--ink-2);
  pointer-events: none;
}

.showcase-slide {
  grid-area: slide;
  width: 100%;
  display: grid;
  justify-items: start;
  gap: 6px;
  text-align: left;
  touch-action: pan-y;
}

.showcase-slide[data-enter] {
  animation: fade-in 0.25s ease;
}

.showcase-name {
  font: 700 32px/1.05 var(--font-display);
  letter-spacing: -0.035em;
}

.showcase-meta {
  font-size: 14px;
  color: var(--ink-2);
}

.showcase-progress {
  width: min(100%, 340px);
  display: grid;
  justify-items: start;
  gap: 6px;
  margin-top: 4px;
}

.showcase-bar {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}

.showcase-bar-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.4s ease;
}

.showcase[data-state="new"] .showcase-bar {
  display: none;
}

.showcase[data-state="done"] .showcase-bar-fill {
  background: var(--success);
}

.showcase-status {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.showcase-note {
  display: none;
  font-size: 12px;
  color: var(--ink-3);
}

.showcase[data-state="building"] .showcase-note {
  display: block;
}

.showcase[data-state="done"] .showcase-status {
  color: var(--success);
}

.showcase-actions {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.showcase-actions .btn {
  flex: 1 1 180px;
}

/* "Use as template" sits under the main button as a quieter text button */
.showcase-actions .showcase-template {
  flex: 1 1 100%;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.showcase-dots {
  grid-area: dots;
  display: flex;
  justify-content: center;
  margin: 6px 0 18px;
}

.showcase-dot {
  appearance: none;
  border: 0;
  width: 30px;
  height: 30px;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.showcase-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--line-strong);
  transition: width 0.2s ease, background-color 0.2s ease;
}

.showcase-dot[aria-current="true"]::before {
  width: 26px;
  background: var(--ink);
}

/* Opening your own .glb: a card above the sets (a file can also be dropped anywhere on the page) */
.open-file {
  margin-top: 32px;
  padding: 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 32px;
  border-radius: 32px;
  background: var(--c-yellow);
  color: var(--ink);
}

.open-file-text {
  flex: 1 1 240px;
  display: grid;
  gap: 6px;
}

.open-file-title {
  font: 700 24px/1.1 var(--font-display);
  letter-spacing: -0.03em;
}

.open-file-sub {
  font-size: 16px;
  line-height: 1.5;
}

.open-file .btn {
  flex: 1 1 auto;
}

@media (min-width: 560px) {
  .open-file {
    padding: 32px 40px;
  }

  .open-file .btn {
    flex: 0 0 auto;
  }
}

@media (hover: none), (pointer: coarse) {
  .dropzone-or {
    display: none;
  }
}

.privacy {
  margin-top: 4px;
  font-size: 13px;
  color: var(--ink-2);
  text-wrap: balance;
}

.privacy .icon {
  display: inline-block;
  width: 15px;
  height: 15px;
  margin-right: 5px;
  vertical-align: -2px;
}

.examples {
  margin-top: 32px;
}

/* One heading style for every section of the Build and Create tabs */
.section-title {
  margin: 0 0 14px;
  font: 700 22px/1.15 var(--font-display);
  letter-spacing: -0.025em;
  color: var(--ink);
}

code {
  font: 600 0.9em/1 var(--font-mono);
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
}

/* ---------- Overlays ---------- */

.drop-overlay {
  position: absolute;
  inset: 12px;
  z-index: 70;
  display: grid;
  place-items: center;
  border: 3px dashed var(--accent);
  border-radius: 32px;
  background: rgba(236, 235, 255, 0.92);
  pointer-events: none;
  animation: fade-in 0.15s ease;
}

.drop-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  font: 700 20px/1.2 var(--font-display);
}

.drop-card .icon {
  width: 40px;
  height: 40px;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(251, 250, 247, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in 0.2s ease;
}

.loading-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 22px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  font-weight: 600;
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3.5px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

.toast {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: calc(var(--gutter) + var(--safe-left));
  right: calc(var(--gutter) + var(--safe-right));
  z-index: 80;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 8px 14px 14px;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  border-left: 5px solid var(--danger);
  animation: drop-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.toast-icon {
  margin-top: 1px;
  color: var(--danger);
}

.toast[data-tone='success'] {
  border-left-color: var(--success);
}

.toast[data-tone='success'] .toast-icon {
  color: var(--success);
}

.toast-body {
  flex: 1;
  min-width: 0;
}

.toast-title {
  font: 700 16px/1.3 var(--font-display);
}

.toast-text {
  margin-top: 4px;
  font-size: 14px;
  color: var(--ink-2);
}

.toast-close {
  width: 36px;
  height: 36px;
  margin-top: -6px;
  box-shadow: none;
}

.confetti {
  position: absolute;
  inset: 0;
  z-index: 25;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  left: var(--x);
  width: 12px;
  height: 8px;
  border-radius: 3px;
  background: var(--c);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
  animation: confetti-fall var(--t) cubic-bezier(0.3, 0.6, 0.4, 1) var(--d) both;
}

/* ---------- Animations ---------- */

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(24px); }
}

@keyframes drop-in {
  from { opacity: 0; transform: translateY(-10px); }
}

@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes tile-in {
  from { opacity: 0; transform: translateY(18px) scale(0.9); }
}

@keyframes tile-glow {
  to { opacity: 0; }
}

@keyframes tile-glow-wide {
  to { opacity: 1; }
}

@keyframes shake {
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@keyframes coach-in {
  from { opacity: 0; transform: translateY(8px); }
}

@keyframes confetti-fall {
  from { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 1; }
  85% { opacity: 1; }
  to { transform: translate3d(var(--dx), 105vh, 0) rotate(var(--r)); opacity: 0; }
}

/* ---------- Larger phones / small tablets ---------- */

@media (min-width: 600px) {
  :root {
    --gutter: 18px;
  }

  .panel {
    left: 0;
    right: 0;
    width: 440px;
    margin: 0 auto;
    bottom: calc(18px + var(--safe-bottom));
  }

  .tile {
    width: 86px;
    height: 86px;
  }

  .tile-img {
    width: 68px;
    height: 68px;
  }

  .callout {
    right: auto;
    max-width: min(620px, calc(100% - 2 * var(--gutter)));
  }

  .toast {
    left: auto;
    width: 420px;
  }
}

/* ---------- Side tray: desktop and landscape phones ---------- */

@media (min-width: 960px), (max-height: 520px) and (orientation: landscape) {
  .tray {
    left: auto;
    top: 0;
    width: var(--side-tray, 304px);
    border-radius: 0;
    box-shadow: -1px 0 0 var(--line), -8px 0 24px rgba(17, 17, 20, 0.06);
    padding: calc(var(--safe-top) + 18px) 0 calc(14px + var(--safe-bottom));
  }

  .tray .progress {
    margin: 0 16px 10px;
  }

  .tray-head {
    padding: 0 18px 8px;
  }

  .tray-list {
    flex: 1;
    min-height: 0;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 10px;
    padding: 4px calc(16px + var(--safe-right)) 16px 16px;
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: pan-y;
    scroll-snap-type: none;
  }

  .tile {
    width: 84px;
    height: 84px;
    touch-action: pan-y;
  }

  .tile-img {
    width: 66px;
    height: 66px;
  }

  .view-tools {
    right: calc(var(--tray-w, 304px) + 20px);
  }

  .coach {
    left: 20px;
    right: calc(var(--tray-w, 304px) + 76px);
    bottom: 20px;
  }

  .topbar {
    right: var(--tray-w, 0px);
  }
}

/* ---------- Desktop ---------- */

@media (min-width: 960px) and (max-width: 1199px) {
  :root {
    --side-tray: 212px; /* two columns of pieces, so the step card has room */
  }
}

@media (min-width: 960px) {
  .view-adjust {
    top: 0;
    bottom: auto;
  }

  .app:not([data-view="welcome"]) {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .drawer {
    position: relative;
    z-index: 2;
    min-height: 0;
    width: auto;
    transform: none;
    transition: none;
    box-shadow: 1px 0 0 var(--line);
    padding-left: var(--safe-left);
  }

  .drawer-close,
  .scrim,
  .topbar {
    display: none !important;
  }

  .callout {
    top: 24px;
    left: 24px;
    right: auto;
    max-width: calc(100% - var(--tray-w, 304px) - 148px); /* room for the view tools and their rotate/zoom stack */
    padding: 10px 10px 10px 16px;
  }

  .callout-step {
    min-width: 56px;
  }

  .callout-heading {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
  }

  .callout-num {
    font-size: 52px;
  }

  .needed-item {
    width: 66px;
  }

  .needed-img {
    width: 60px;
    height: 60px;
  }

  .needed-item.is-done::before {
    top: 18px;
  }

  .needed-item.is-done::after {
    top: 23px;
  }

  .view-tools {
    top: 24px;
    bottom: auto;
  }

  .panel {
    left: 24px;
    right: auto;
    margin: 0;
    bottom: 24px;
    width: 420px;
    max-height: calc(100% - 48px);
  }

  .part {
    width: 72px;
  }

  .part-img {
    width: 64px;
    height: 64px;
  }

  .toast {
    top: 24px;
    right: calc(var(--tray-w, 0px) + 24px);
    max-width: calc(100% - var(--tray-w, 0px) - 48px);
  }

  /* The example sets are the hero, the full width of the page; the rest follows below in one column, as on phones. */
  .welcome-inner {
    max-width: 1240px;
    justify-content: flex-start;
    padding: calc(var(--safe-top) + 28px) 48px 56px;
  }

  /* The 3D view and its dots on the left, the set's details on the right. */
  .showcase {
    width: 100%;
    grid-template-columns: minmax(0, 3fr) minmax(320px, 2fr);
    grid-template-areas:
      "stage slide"
      "dots  slide";
    column-gap: 72px;
  }

  .showcase-stage {
    width: 100%;
    height: clamp(380px, 58vh, 600px);
    margin: 0;
  }

  .showcase-slide {
    align-self: center;
  }

  .showcase-prev {
    left: 24px;
  }

  .showcase-next {
    right: 24px;
  }

  .showcase-name {
    font-size: 40px;
  }

  .showcase-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    max-width: 420px;
  }

  .welcome-copy,
  .welcome-inner > .community,
  .welcome-inner > .about,
  .welcome-inner > .legal {
    width: 100%;
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
  }

  .welcome-copy {
    margin-top: 8px;
  }

  .mode-tabs {
    margin-top: 56px;
  }

  .welcome .community {
    margin-top: 96px;
  }

  .section-title {
    font-size: 24px;
  }

  .welcome .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
  }
}

/* ---------- Short landscape phones ---------- */

@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --side-tray: calc(206px + var(--safe-right));
  }

  .topbar {
    padding-top: calc(var(--safe-top) + 6px);
  }

  .callout {
    top: calc(var(--safe-top) + 54px);
    right: auto;
    max-width: calc(100% - var(--tray-w, 206px) - 2 * var(--gutter) - var(--safe-left));
    padding: 6px 6px 6px 10px;
  }

  .callout-num {
    font-size: 30px;
  }

  .callout-heading {
    display: none;
  }

  .needed-item {
    width: 46px;
  }

  .needed-img {
    width: 40px;
    height: 40px;
  }

  .needed-item.is-done::before {
    top: 8px;
  }

  .needed-item.is-done::after {
    top: 13px;
  }

  .tray-list {
    gap: 8px;
    padding: 4px calc(12px + var(--safe-right)) 12px 12px;
  }

  .tile {
    width: 82px;
    height: 74px;
  }

  .tile-img {
    width: 58px;
    height: 58px;
  }

  .view-tools {
    top: auto;
    bottom: calc(12px + var(--safe-bottom));
    gap: 8px;
  }

  .view-adjust {
    top: auto;
    bottom: 0;
  }

  .coach {
    bottom: calc(12px + var(--safe-bottom));
  }

  .panel {
    max-height: calc(100% - 24px);
  }

  .welcome-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "show ."
      "show brand"
      "show copy"
      "show .";
    grid-template-rows: 1fr auto auto 1fr;
    column-gap: 24px;
    row-gap: 4px;
    max-width: none;
  }

  .welcome-head {
    grid-area: brand;
    margin-bottom: 8px;
  }

  .showcase {
    grid-area: show;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "stage"
      "dots"
      "slide";
  }

  .showcase-actions {
    display: flex;
  }

  .showcase-stage {
    width: 100%;
    height: 200px;
    margin: 0;
  }

  .welcome-copy {
    grid-area: copy;
  }
}

/* =====================================================================
   Home: Build / Create switch
   ===================================================================== */

.mode-tabs {
  margin-top: 40px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

.mode-tab {
  appearance: none;
  border: 0;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-2);
  font: 600 16px/1 var(--font-display);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mode-tab:hover {
  color: var(--ink);
}

.mode-tab[aria-selected="true"] {
  background: var(--ink);
  color: var(--on-primary);
}

.create-card {
  margin-top: 32px;
  display: grid;
  gap: 10px;
  padding: 20px;
  background: var(--c-lilac);
  border-radius: var(--radius-l);
}

.create-card-text {
  margin-bottom: 4px;
  font-size: 16px;
  color: var(--ink);
}

.create-card .privacy {
  text-align: center;
}

.creations {
  margin-top: 40px;
}

/* Your creations come first, then the example sets to start from. */
.creations:not([hidden]) + .examples {
  margin-top: 40px;
}

/* Example sets and your creations: cards with a picture of the model */

.card-grid {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

/* Backup and restore: a quiet note at the end of each tab, out of the way of the sets */
.backup {
  display: grid;
  gap: 16px;
  margin-top: 24px;
  padding: 20px;
  font-size: 14px;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
}

.examples + .backup {
  margin-top: 40px;
}

.backup + .credit {
  margin-top: 24px;
}

.backup-text {
  margin: 0;
}

.backup-text strong {
  color: var(--ink);
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.set-divider {
  grid-column: 1 / -1;
  height: 1px;
  margin: 6px 0;
  background: var(--line, rgba(128, 128, 128, 0.3));
}

.set-card {
  position: relative;
  min-width: 0;
}

.set-card-open {
  appearance: none;
  border: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.set-card-open:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-2), inset 0 0 0 1px var(--line);
}

.set-card-open:active {
  transform: translateY(0) scale(0.985);
}

.set-card-pic {
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  overflow: hidden;
  margin: 6px 6px 0;
  border-radius: 18px;
  background: var(--surface-2);
  color: var(--ink-3);
}

/* Each example set has its own pastel, the same as its box */
.set-card-example .set-card-pic {
  background: var(--card-top, var(--c-lilac));
  color: rgba(17, 17, 20, 0.45);
}

.set-card-pic .icon {
  width: 36px;
  height: 36px;
}

.set-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.set-card-example .set-card-img {
  object-fit: contain;
  padding: 6px;
}

.set-card-text {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px 12px;
}

.set-card-name {
  font: 600 16px/1.2 var(--font-display);
  letter-spacing: -0.01em;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.set-card-meta {
  font-size: 12px;
  color: var(--ink-2);
}

.set-card.is-building .set-card-meta,
.set-card.is-done .set-card-meta {
  color: var(--ink);
  font-weight: 600;
}

#buildSets {
  margin-top: 18px;
}

.set-card-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  min-height: 36px;
  background: var(--surface);
  color: var(--ink-2);
  box-shadow: var(--shadow-1);
}

.set-card-delete .icon {
  width: 18px;
  height: 18px;
}

.set-card-delete:hover {
  color: var(--danger);
}

.credit,
.legal {
  margin-top: 14px;
  font-size: 12px;
  color: var(--ink-2);
  text-align: center;
  text-wrap: balance;
}

.credit a {
  color: inherit;
}

.legal {
  margin-top: 10px;
}

.site-links {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 20px;
  font-size: 14px;
  font-weight: 600;
}

.site-links a {
  color: var(--ink-2);
  text-underline-offset: 2px;
}

.site-links a:hover {
  color: var(--ink);
}

/* The links to each set's page, under the site links (written by tools/set-pages.js) */
.set-links {
  margin-top: 12px;
  padding-top: 0;
  border-top: 0;
  gap: 4px 14px;
  font-size: 13px;
  font-weight: 400;
}

.set-links span {
  color: var(--ink-3);
}

.community {
  margin-top: 64px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
  border-radius: 32px;
  background: var(--c-lime);
  color: var(--ink);
  text-align: left;
}

.community-logo {
  flex: none;
  width: 96px;
  height: auto;
  align-self: center;
}

.community-body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.community-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.035em;
  color: var(--ink);
}

.community-body p {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  max-width: 46ch;
}

.community-btn {
  margin-top: 14px;
  text-decoration: none;
  justify-content: center;
}

.about {
  margin-top: 16px;
  padding: 32px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: var(--ink-2);
  text-align: left;
  font-size: 16px;
  line-height: 1.5;
}

.about p,
.about-list {
  margin: 0;
  max-width: 56ch;
}

.about-list {
  padding-left: 22px;
  display: grid;
  gap: 6px;
}

.about a {
  color: var(--ink);
  font-weight: 600;
}

.about strong {
  color: var(--ink);
}

.install {
  margin-top: 0;
}

.install-sub {
  margin: 8px 0 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}

.about-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.035em;
  color: var(--ink);
}

@media (min-width: 560px) {
  .about {
    padding-top: 40px;
  }

  .about-title {
    font-size: 32px;
  }
}

.community p a,
.sheet-text a {
  color: var(--ink);
  font-weight: 600;
}

@media (min-width: 560px) {
  .community {
    flex-direction: row;
    align-items: center;
    gap: 40px;
    padding: 40px;
  }

  .community-logo {
    width: 133px;
  }

  .community-title {
    font-size: 32px;
  }

  .community-btn {
    align-self: flex-start;
  }
}

/* =====================================================================
   Create: the brick editor
   ===================================================================== */

.c-bar,
.c-target,
.c-tools,
.c-tray,
.c-actions,
.c-layers,
.c-scrim {
  display: none;
}

.app[data-view="create"] {
  grid-template-columns: minmax(0, 1fr);
}

.app[data-view="create"] .drawer,
.app[data-view="create"] .topbar,
.app[data-view="create"] .view-tools,
.app[data-view="create"] .scrim {
  display: none !important;
}

.app[data-view="create"] .stage {
  --c-tray-h: 168px;
}

.app[data-view="create"] .coach {
  bottom: calc(var(--c-tray-h) + 12px);
}

/* Top bar */

.app[data-view="create"] .c-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 14;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 10px) calc(var(--gutter) + var(--safe-right)) 6px calc(var(--gutter) + var(--safe-left));
  pointer-events: none;
}

.c-bar > * {
  pointer-events: auto;
}

.c-name {
  appearance: none;
  border: 0;
  flex: 1;
  min-width: 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 0 0 1px var(--line);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--ink);
  font: 700 16px/1.2 var(--font-display);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.c-name:hover {
  background: var(--surface);
}

.c-name-text {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.c-name .icon {
  width: 16px;
  height: 16px;
  color: var(--ink-3);
}

.c-bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

.c-export-btn {
  min-height: 44px;
}

.c-export-btn .icon {
  width: 20px;
  height: 20px;
}

/* Narrow phones, and short landscape phones where the bar sits beside the tray: icon only, so the name fits. */
@media (max-width: 400px), (max-height: 520px) and (orientation: landscape) and (max-width: 959px) {
  .c-export-btn {
    width: 44px;
    padding: 0;
  }

  .c-export-btn span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
}

/* "Adding to Bag 1 · Step 2" */

.app[data-view="create"] .c-target {
  position: absolute;
  top: calc(var(--safe-top) + 62px);
  left: 50%;
  z-index: 13;
  transform: translateX(-50%);
  max-width: calc(100% - 2 * var(--gutter));
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px 0 14px;
  border: 1.5px solid var(--callout-line);
  border-radius: var(--radius-pill);
  background: var(--callout);
  color: var(--ink);
  font: 600 14px/1.2 var(--font-body);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.c-target:hover {
  background: var(--accent-soft);
}

.c-target .icon {
  width: 18px;
  height: 18px;
}

.c-target-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.c-target-label {
  color: var(--ink-2);
}

.c-target strong {
  font-family: var(--font-display);
  font-weight: 700;
}

.c-target.is-none {
  background: var(--warn-bg);
  border-color: var(--warn-line);
}

/* Very narrow phones: keep the bag and step readable, drop the words around them. */
@media (max-width: 359px) {
  .c-target-label {
    display: none;
  }
}

/* Floating tools on the right */

.app[data-view="create"] .c-tools {
  position: absolute;
  right: calc(var(--gutter) + var(--safe-right));
  bottom: calc(var(--c-tray-h) + 12px);
  z-index: 11;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Parts tray (bottom sheet on phones) */

.app[data-view="create"] .c-tray,
.app[data-view="create"] .c-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  padding: 10px 0 calc(10px + var(--safe-bottom));
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -1px 0 var(--line), 0 -8px 28px rgba(17, 17, 20, 0.08);
}

.c-tray-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 calc(var(--gutter) + var(--safe-right)) 8px calc(var(--gutter) + var(--safe-left));
}

.c-color-btn {
  appearance: none;
  flex: none;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink);
  font: 700 13px/1 var(--font-body);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.c-color-btn:hover {
  background: var(--surface-3);
}

.c-swatch {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--swatch, #ccc);
  box-shadow: inset 0 0 0 1.5px rgba(0, 0, 0, 0.18), inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}

.c-swatch.is-trans {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.6) 0 30%, transparent 30%),
    var(--swatch, #ccc);
}

.c-cats {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior: contain;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent);
  padding-right: 20px;
}

.c-cats::-webkit-scrollbar {
  display: none;
}

.c-cat {
  appearance: none;
  flex: none;
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--line-strong);
  color: var(--ink-2);
  font: 600 13px/1 var(--font-body);
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.c-cat:hover {
  color: var(--ink);
  background: var(--surface-2);
}

.c-cat[aria-selected="true"] {
  background: var(--ink);
  box-shadow: none;
  color: #fff;
}

/* The category and action rows scroll, which clips anything outside them: draw focus rings inside. */
.c-cat:focus-visible,
.c-act:focus-visible {
  outline-offset: -3px;
}

.c-search-btn {
  width: 40px;
  height: 40px;
  box-shadow: inset 0 0 0 1px var(--line);
  background: var(--surface-2);
}

.c-search-btn[aria-expanded="true"] {
  background: var(--ink);
  color: #fff;
}

.c-search {
  padding: 0 calc(var(--gutter) + var(--safe-right)) 8px calc(var(--gutter) + var(--safe-left));
}

.c-input {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  font: 500 16px/1.2 var(--font-body);
}

.c-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.c-parts {
  list-style: none;
  margin: 0;
  padding: 4px calc(var(--gutter) + var(--safe-right)) 4px calc(var(--gutter) + var(--safe-left));
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  scroll-padding: 0 var(--gutter);
  scrollbar-width: none;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.c-parts::-webkit-scrollbar {
  display: none;
}

.c-parts .tile {
  grid-template-rows: 1fr auto;
  padding: 4px 2px 5px;
}

.c-parts .tile-img {
  width: 54px;
  height: 54px;
}

.c-tile-cap {
  max-width: 72px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font: 700 11px/1.1 var(--font-body);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

.c-parts-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.c-parts-empty {
  padding: 18px calc(var(--gutter) + 4px);
  font-size: 14px;
  color: var(--ink-2);
  text-align: center;
}

/* Phones and tablets: the pull tab at the top of a parts tray (Build and Create) pulls it up
   into a taller grid of parts; tray-sheet.js moves it */

.tray-grip {
  display: none;
}

@media (max-width: 959px) {
  .tray-grip {
    appearance: none;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    position: relative;
    height: 44px; /* a full-size touch target; the visible bar stays small */
    margin: -20px 0 -2px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: row-resize;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }

  .tray-grip-bar {
    width: 40px;
    height: 5px;
    border-radius: 3px;
    background: var(--line-strong);
    transition: background-color 0.15s ease, transform 0.15s ease;
  }

  .tray-grip:hover .tray-grip-bar,
  .tray-grip:focus-visible .tray-grip-bar,
  .tray-grip:active .tray-grip-bar {
    background: var(--ink-3);
  }

  .tray-grip:active .tray-grip-bar {
    transform: scaleX(1.15);
  }

  /* As tall as the parts need, up to about two thirds of the screen (then the grid scrolls) */
  .tray.is-expanded,
  .app[data-view="create"] .c-tray.is-expanded {
    max-height: min(64%, 600px);
  }

  .tray.is-expanded .tray-list,
  .c-tray.is-expanded .c-parts {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
    justify-items: center;
    align-content: start;
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: pan-y;
    scroll-snap-type: none;
  }

  .tray.is-expanded .tile,
  .c-tray.is-expanded .c-parts .tile {
    touch-action: pan-y;
  }

  /* The floating view tools step aside while the tray is open */
  .stage.tray-expanded .view-tools,
  .app[data-view="create"] .stage.c-tray-expanded .c-tools {
    display: none;
  }
}

@media (min-width: 600px) and (max-width: 959px) {
  .tray.is-expanded .tray-list,
  .c-tray.is-expanded .c-parts {
    grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  }
}

/* Short landscape phones keep the trays at the side, with no pull tab */
@media (max-height: 520px) and (orientation: landscape) and (max-width: 959px) {
  .tray-grip {
    display: none;
  }
}

/* Selection actions (replace the tray on phones) */

.c-actions-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 calc(var(--gutter) + var(--safe-right)) 6px calc(var(--gutter) + var(--safe-left) + 4px);
}

.c-sel-text {
  min-width: 0;
  font: 700 15px/1.2 var(--font-display);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.c-actions-head .btn-sm {
  min-height: 40px;
}

.c-actions-row {
  display: flex;
  gap: 4px;
  padding: 2px calc(var(--gutter) + var(--safe-right)) 2px calc(var(--gutter) + var(--safe-left));
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior: contain;
}

.c-actions-row::-webkit-scrollbar {
  display: none;
}

.c-act {
  appearance: none;
  flex: 1 0 58px;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 4px;
  border: 0;
  border-radius: 18px;
  background: var(--surface-2);
  color: var(--ink);
  font: 700 12px/1 var(--font-body);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, transform 0.12s ease;
}

.c-act:hover {
  background: var(--surface-3);
}

.c-act:active {
  transform: scale(0.95);
}

.c-act-step {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  font: 700 19px/1 var(--font-display);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.c-act .c-swatch {
  width: 22px;
  height: 22px;
}

.c-act[aria-pressed="true"],
.c-act.is-on {
  background: var(--accent);
  color: var(--accent-ink);
}

.c-act[aria-pressed="true"]:hover,
.c-act.is-on:hover {
  background: var(--accent-hover);
}

/* Rotate rings and move arrows, drawn over the 3D view (create.js draws them; the canvas handles the pointer) */

.c-gizmo {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.c-gizmo.is-on {
  display: block;
}

.c-gizmo-ring {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.c-gizmo-dot {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 1.5px;
}

.c-gizmo-wedge {
  stroke: none;
}

.c-gizmo-label {
  font: 700 15px/1 var(--font-display);
  fill: var(--ink);
  stroke: #fff;
  stroke-width: 4px;
  stroke-linejoin: round;
  paint-order: stroke;
}

.viewport.is-gizmo-hover {
  cursor: pointer;
}

/* Select an area: the box being dragged out over the 3D view */

.viewport.is-box-tool,
.viewport.is-box-tool:active {
  cursor: crosshair;
}

.c-marquee {
  position: absolute;
  pointer-events: none;
  border: 1.5px solid var(--accent);
  border-radius: 2px;
  background: rgba(91, 85, 240, 0.12); /* --accent, see-through */
}

.btn-danger {
  color: var(--danger);
}

.c-act-danger {
  color: #b42318; /* --danger is too light for small text on the grey buttons */
}

/* Portrait phones: two rows (four, then three), so Delete and Step are never off-screen. */
@media (max-width: 599px) {
  .c-actions-row {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .c-act {
    flex: 1 0 calc(25% - 3px);
    min-height: 56px;
  }
}

/* Bags & steps (slide-in panel on phones, sidebar on wide screens) */

.app[data-view="create"] .c-scrim:not([hidden]) {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 35;
  background: rgba(17, 17, 20, 0.36);
  animation: fade-in 0.2s ease;
}

.app[data-view="create"] .c-layers {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: 40;
  width: min(92vw, 380px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  transform: translateX(104%);
  visibility: hidden;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.3s;
  padding-right: var(--safe-right);
}

.app[data-layers="open"] .c-layers {
  transform: none;
  visibility: visible;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.c-layers-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--safe-top) + 14px) 14px 8px 20px;
}

.c-layers-title {
  font: 700 20px/1.2 var(--font-display);
}

.c-layers-close {
  box-shadow: none;
  background: var(--surface-2);
}

.c-layers-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px 8px 20px;
}

.c-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
}

.c-check input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--ink);
}

.c-layers-help {
  padding: 0 20px 10px;
  font-size: 13px;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line);
}

.c-tree {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 10px 10px calc(24px + var(--safe-bottom));
  overscroll-behavior: contain;
}

.c-bag + .c-bag,
.c-loose {
  margin-top: 12px;
}

.c-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 4px 0 6px;
  border-radius: 12px;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.c-grip {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--ink-3);
  cursor: grab;
}

.c-row-main {
  appearance: none;
  flex: 1;
  min-width: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.c-row-main:hover {
  background: var(--surface-2);
}

.c-row-label {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.c-row-count {
  margin-left: auto;
  flex: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
}

.c-row-menu {
  width: 38px;
  height: 38px;
  box-shadow: none;
  background: transparent;
  color: var(--ink-2);
}

.c-bag-head {
  font: 700 15px/1.2 var(--font-display);
}

.c-chev {
  width: 18px;
  height: 18px;
  color: var(--ink-3);
  transition: transform 0.15s ease;
}

.c-bag-head [aria-expanded="false"] .c-chev {
  transform: rotate(-90deg);
}

.c-bag-head .bag-badge {
  flex: none;
}

.c-steps {
  list-style: none;
  margin: 2px 0 0;
  padding: 0 0 0 14px;
  display: grid;
  gap: 2px;
}

.c-step-head .c-row-main {
  font-weight: 700;
}

.c-step-dot {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--surface);
}

.c-step.is-active > .c-step-head {
  background: var(--accent-tint);
}

.c-step.is-active .c-step-dot {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.c-here {
  flex: none;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font: 700 11px/1.2 var(--font-body);
  letter-spacing: 0.02em;
}

.c-pieces {
  list-style: none;
  margin: 0;
  padding: 0 0 4px 22px;
  display: grid;
  gap: 1px;
}

.c-piece-row {
  min-height: 40px;
  font-size: 14px;
}

.c-piece-row .c-row-main {
  min-height: 40px;
  gap: 8px;
}

.c-piece-img {
  flex: none;
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.c-piece-img-empty {
  border-radius: 8px;
  background: var(--surface-2);
}

.c-piece-row.is-selected,
.c-piece-row.is-selected .c-row-main:hover {
  background: #ffece2;
}

.c-piece-row.is-selected {
  box-shadow: inset 0 0 0 2px var(--highlight);
}

.c-piece-row.is-selected .c-row-count {
  color: var(--ink-2);
}

.c-empty-step {
  padding: 4px 8px 8px 30px;
  font-size: 13px;
  color: var(--ink-3);
}

.c-add-step {
  margin: 2px 0 4px 14px;
  min-height: 38px;
  font-size: 14px;
}

.c-loose-head {
  font: 700 15px/1.2 var(--font-display);
  color: var(--ink-2);
}

/* Drag and drop in the panel */

.c-drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 95;
  max-width: 300px;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: #fff;
  font: 700 14px/1.2 var(--font-body);
  box-shadow: var(--shadow-2);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  will-change: transform;
}

.c-tree.is-dragging .c-row {
  cursor: grabbing;
}

.c-row.is-lifted {
  opacity: 0.4;
}

.c-drop-target > .c-row,
.c-drop-target.c-loose {
  background: var(--accent-tint);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.c-drop-line {
  position: absolute;
  left: 12px;
  right: 12px;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 2px;
  background: var(--accent);
  pointer-events: none;
}

/* Sheets: native <dialog>, a bottom sheet on phones and a card on larger screens */

.sheet {
  position: fixed;
  inset: auto 0 var(--keyboard, 0px) 0; /* just above the on-screen keyboard (see watchKeyboard in app.js) */
  width: 100%;
  max-width: none;
  max-height: min(86vh, 720px, calc(var(--vv-height, 100vh) - 16px));
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 28px 28px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-2);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet[open] {
  animation: sheet-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sheet::backdrop {
  background: rgba(17, 17, 20, 0.4);
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 14px 8px 22px;
  background: var(--surface);
}

.sheet-title {
  font: 700 20px/1.2 var(--font-display);
}

.sheet-close {
  box-shadow: none;
  background: var(--surface-2);
}

.sheet-body {
  /* The keyboard covers the home indicator, so no extra room for it then */
  padding: 4px 20px max(20px, calc(20px + var(--safe-bottom) - var(--keyboard, 0px)));
}

@media (prefers-reduced-motion: no-preference) {
  .sheet {
    transition: bottom 0.2s ease;
  }
}

/* A small dialog (naming a set) is a card in the middle of the space above the keyboard, on phones too */
.sheet.sheet-modal {
  inset: 0 0 var(--keyboard, 0px) 0;
  width: min(400px, calc(100% - 32px));
  max-height: calc(var(--vv-height, 100vh) - 32px);
  margin: auto;
  border-radius: 28px;
}

.sheet.sheet-modal[open] {
  animation: modal-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

.sheet-modal .sheet-body {
  padding-bottom: 20px;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.94); }
}

.sheet-text {
  margin-bottom: 14px;
  font-size: 15px;
  color: var(--ink-2);
}

.sheet-actions {
  display: grid;
  gap: 10px;
  margin-top: 6px;
}

.sheet .credit {
  margin-top: 16px;
}

.stats-compact strong {
  font-size: 22px;
}

.c-color-group + .c-color-group {
  margin-top: 16px;
}

.c-color-group-title {
  margin: 0 2px 8px;
}

.c-swatches {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 8px;
}

.c-swatch-btn {
  appearance: none;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.c-swatch-btn .c-swatch {
  width: 40px;
  height: 40px;
  transition: transform 0.12s ease;
}

.c-swatch-btn:hover .c-swatch {
  transform: scale(1.08);
}

.c-swatch-btn[aria-pressed="true"] {
  box-shadow: inset 0 0 0 3px var(--ink);
}

.c-color-current {
  margin: 0 2px 14px;
  font-weight: 700;
}

.c-move-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  gap: 4px;
}

.c-move-bag {
  margin: 12px 4px 4px;
}

.c-move-opt {
  appearance: none;
  width: 100%;
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink);
  font: 600 15px/1.2 var(--font-body);
  text-align: left;
  cursor: pointer;
}

.c-move-opt:hover {
  background: var(--surface-3);
}

.c-move-opt[aria-current="true"] {
  box-shadow: inset 0 0 0 2px var(--ink);
}

.c-move-opt .icon {
  width: 18px;
  height: 18px;
}

/* Tablets and up */

@media (min-width: 600px) {
  .sheet {
    inset: 0 0 var(--keyboard, 0px) 0; /* centred in the space above the keyboard */
    width: min(440px, calc(100% - 32px));
    max-height: min(86vh, 720px, calc(var(--vv-height, 100vh) - 32px));
    margin: auto;
    border-radius: 28px;
  }

  .sheet[open] {
    animation: pop 0.25s cubic-bezier(0.2, 1.2, 0.4, 1);
  }

  .c-parts .tile {
    width: 86px;
    height: 86px;
  }

  .c-parts .tile-img {
    width: 60px;
    height: 60px;
  }
}

/* Desktop: parts panel on the left, bags & steps on the right */

@media (min-width: 960px) {
  .app[data-view="create"] .stage {
    --c-side: 300px;
  }

  .app[data-view="create"] .c-tray {
    top: 0;
    right: auto;
    width: var(--c-side);
    border-radius: 0;
    box-shadow: 1px 0 0 var(--line), 8px 0 24px rgba(17, 17, 20, 0.06);
    padding: calc(var(--safe-top) + 16px) 0 14px;
  }

  .c-tray-head {
    flex-wrap: wrap;
    padding: 0 16px 10px;
  }

  .c-cats {
    order: 3;
    flex: 1 0 100%;
  }

  .c-search {
    padding: 0 16px 10px;
  }

  .c-parts {
    flex: 1;
    min-height: 0;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px;
    padding: 4px 16px 16px;
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: pan-y;
    scroll-snap-type: none;
  }

  .c-parts .tile {
    width: 84px;
    height: 84px;
    touch-action: pan-y;
  }

  .app[data-view="create"] .c-actions {
    left: calc(var(--c-side) + 24px);
    right: calc(var(--c-right, 0px) + 24px);
    bottom: 24px;
    width: auto;
    max-width: 640px;
    margin: 0 auto;
    padding: 10px 0 12px;
    border-radius: 28px;
    box-shadow: var(--shadow-2);
  }

  .app[data-view="create"] .c-bar {
    left: var(--c-side);
    right: var(--c-right, 0px);
    padding: 16px 20px 6px;
  }

  .c-bar #cHomeBtn {
    order: -1;
  }

  .app[data-view="create"] .c-target {
    left: calc(var(--c-side) + (100% - var(--c-side) - var(--c-right, 0px)) / 2);
    top: 70px;
  }

  .app[data-view="create"] .c-tools {
    right: calc(var(--c-right, 0px) + 20px);
    top: 128px;
    bottom: auto;
  }

  .app[data-view="create"] .coach {
    left: calc(var(--c-side) + 20px);
    right: calc(var(--c-right, 0px) + 76px);
    bottom: calc(var(--c-actions-h, 0px) + 24px);
  }

  .app[data-view="create"] .toast {
    right: calc(var(--c-right, 0px) + 24px);
  }
}

@media (min-width: 1200px) {
  .app[data-view="create"] .stage {
    --c-right: 320px;
  }

  .app[data-view="create"] .c-layers {
    width: var(--c-right);
    transform: none;
    visibility: visible;
    transition: none;
    z-index: 12;
    box-shadow: -1px 0 0 var(--line), -8px 0 24px rgba(17, 17, 20, 0.06);
  }

  .app[data-view="create"] .c-layers-close,
  .app[data-view="create"] .c-scrim {
    display: none !important;
  }
}

/* Short landscape phones: tray on the left like desktop, but compact */

@media (max-height: 520px) and (orientation: landscape) and (max-width: 959px) {
  .app[data-view="create"] .stage {
    --c-side: calc(220px + var(--safe-left));
  }

  .app[data-view="create"] .c-tray {
    top: 0;
    right: auto;
    width: var(--c-side);
    border-radius: 0;
    padding: calc(var(--safe-top) + 10px) 0 10px var(--safe-left);
  }

  .c-tray-head {
    flex-wrap: wrap;
  }

  .c-cats {
    order: 3;
    flex: 1 0 100%;
  }

  .c-parts {
    flex: 1;
    min-height: 0;
    flex-wrap: wrap;
    align-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: pan-y;
  }

  .c-parts .tile {
    width: 80px;
    height: 74px;
    touch-action: pan-y;
  }

  .app[data-view="create"] .c-actions {
    left: var(--c-side);
    right: calc(var(--gutter) + var(--safe-right) + 52px);
  }

  .app[data-view="create"] .c-bar {
    left: var(--c-side);
    padding-top: calc(var(--safe-top) + 6px);
  }

  .app[data-view="create"] .c-target {
    top: calc(var(--safe-top) + 56px);
    left: calc(var(--c-side) + (100% - var(--c-side)) / 2);
  }

  .app[data-view="create"] .c-tools {
    top: calc(var(--safe-top) + 62px);
    bottom: auto;
    gap: 8px;
  }
}

/* Back to editing after a test build */

.from-create-only {
  display: none;
}

.app[data-from-create] .from-create-only {
  display: grid;
}

.app[data-from-create] .btn.from-create-only {
  display: inline-flex;
  margin-bottom: 10px;
}

.app[data-from-create] .not-from-create {
  display: none;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Accessibility: bigger pieces (switch at the bottom of the step list) ----------
   Step card pictures at the top and tray pictures at the bottom, much larger.
   Placed last so it wins over the screen-size rules above. */

.app[data-big-parts] .needed {
  gap: 6px;
}

.app[data-big-parts] .needed-item {
  width: 88px;
}

.app[data-big-parts] .needed-img {
  width: 80px;
  height: 80px;
}

.app[data-big-parts] .needed-qty {
  min-height: 20px;
  font-size: 18px;
}

.app[data-big-parts] .needed-item.is-done::before {
  top: 28px;
}

.app[data-big-parts] .needed-item.is-done::after {
  top: 33px;
}

.app[data-big-parts] .tray .tile {
  width: 132px;
  height: 132px;
}

.app[data-big-parts] .tray .tile-img {
  width: 116px;
  height: 116px;
}

.app[data-big-parts] .tray .tile-count {
  min-width: 28px;
  height: 28px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 28px;
}

@media (max-width: 959px) {
  .app[data-big-parts] .tray.is-expanded .tray-list {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  }
}

@media (min-width: 960px), (max-height: 520px) and (orientation: landscape) {
  .app[data-big-parts] {
    --side-tray: 376px;
  }

  .app[data-big-parts] .needed-item {
    width: 120px;
  }

  .app[data-big-parts] .needed-img {
    width: 112px;
    height: 112px;
  }

  .app[data-big-parts] .needed-item.is-done::before {
    top: 44px;
  }

  .app[data-big-parts] .needed-item.is-done::after {
    top: 49px;
  }

  .app[data-big-parts] .tray .tile {
    width: 150px;
    height: 150px;
  }

  .app[data-big-parts] .tray .tile-img {
    width: 132px;
    height: 132px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .app[data-big-parts] {
    --side-tray: calc(300px + var(--safe-right));
  }

  .app[data-big-parts] .needed-item {
    width: 76px;
  }

  .app[data-big-parts] .needed-img {
    width: 68px;
    height: 68px;
  }

  .app[data-big-parts] .needed-item.is-done::before {
    top: 22px;
  }

  .app[data-big-parts] .needed-item.is-done::after {
    top: 27px;
  }

  .app[data-big-parts] .tray .tile {
    width: 112px;
    height: 100px;
  }

  .app[data-big-parts] .tray .tile-img {
    width: 88px;
    height: 88px;
  }
}

/* Bigger pieces: the step card is a row and a half tall (the step number stays put);
   the pieces scroll up and down inside it */
.app[data-big-parts] .callout {
  --needed-h: 150px; /* a row and a half of big pieces, so the next row peeks out */
}

.app[data-big-parts] .callout-body {
  align-self: center;
  max-height: var(--needed-h);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 960px) {
  .app[data-big-parts] .callout {
    --needed-h: 215px; /* a row and a half of the larger desktop pieces, plus the heading */
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .app[data-big-parts] .callout {
    --needed-h: 132px; /* a row and a half of the landscape-phone pieces (no heading) */
  }
}
