/* Character Lab — responsive shell (Games site.css tokens) */

.lab {
  --lab-pad-x: clamp(12px, 2.5vw, 20px);
  --lab-pad-bottom: clamp(24px, 5vw, 56px);
  --lab-viewer-scale: 0.9;
  --lab-viewer-h: clamp(260px, 46dvh, 560px);
  --lab-gap: clamp(14px, 2vw, 24px);
  padding:
    calc(var(--header-h) + env(safe-area-inset-top, 0px) + 16px)
    max(var(--lab-pad-x), env(safe-area-inset-right, 0px))
    calc(var(--lab-pad-bottom) + env(safe-area-inset-bottom, 0px))
    max(var(--lab-pad-x), env(safe-area-inset-left, 0px));
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

/* site.css .btn { display:inline-flex } overrides UA [hidden] */
.lab [hidden] {
  display: none !important;
}

.lab-banner {
  background: #3a1520;
  border: 1px solid rgba(255, 107, 53, 0.45);
  color: #ffd7c8;
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.lab-banner[data-kind="dns"] {
  background: #3a3010;
  border-color: rgba(240, 180, 41, 0.5);
  color: #ffe9b0;
}

.lab-banner .lab-reconnect-btn {
  display: inline-flex;
  align-items: center;
  margin-top: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.35);
  color: inherit;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.lab-banner .lab-reconnect-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* —— Hero —— */
.lab-hero {
  margin-bottom: clamp(14px, 2.5vw, 24px);
}

.lab-hero .section-label {
  margin: 0;
}

.lab-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(1.45rem, 4.2vw, 2.6rem);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin: 6px 0 8px;
  line-height: 1.15;
}

.lab-hero-copy > p:last-child {
  color: var(--text-muted);
  max-width: 36rem;
  margin: 0;
  font-size: clamp(0.88rem, 0.82rem + 0.3vw, 1rem);
  line-height: 1.5;
}

/* —— Layout —— */
.lab-layout {
  display: grid;
  gap: var(--lab-gap);
  grid-template-columns: 1fr;
  align-items: start;
}

.lab-controls {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(12px, 2vw, 18px);
  display: grid;
  gap: 0;
  min-width: 0;
}

/* —— Steps bar: shared .pipe-* styles live in ../assets/css/site.css —— */
.lab-progress-board.pipe-board {
  margin: 0 0 var(--lab-gap);
}

.lab.is-busy .pipe-kicker {
  color: #f0b429;
}

/* Hide create / upload controls while mesh, remesh, or rig is running */
.lab.is-busy .lab-form,
.lab.is-busy .lab-hero,
.lab.is-rig .lab-form,
.lab.is-rig .lab-hero,
.lab.is-rig .lab-joints,
.lab.is-rig .lab-detail,
.lab.is-rig .lab-ready,
.lab-form[hidden] {
  display: none !important;
}

.lab.is-rig .lab-status {
  display: grid;
  margin-top: 4px;
}

/* —— Saved projects (IndexedDB) —— */
.lab-projects {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  padding: 0;
  margin: 0 0 var(--lab-gap);
  min-width: 0;
}

.lab-projects-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  font-family: var(--font-display);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: var(--text-muted);
  user-select: none;
}

.lab-projects-summary::-webkit-details-marker {
  display: none;
}

.lab-projects-summary-label {
  min-width: 0;
}

.lab-projects-summary-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.lab-projects-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: var(--font-body, inherit);
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  text-transform: none;
}

.lab-projects-chevron {
  width: 0.45em;
  height: 0.45em;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  margin-top: -0.15em;
}

.lab-projects[open] .lab-projects-chevron {
  transform: rotate(-135deg);
  margin-top: 0.12em;
}

.lab-projects[open] .lab-projects-toggle-text {
  font-size: 0;
}

.lab-projects[open] .lab-projects-toggle-text::after {
  content: "Hide";
  font-size: 0.68rem;
}

.lab-projects-summary:hover .lab-projects-toggle {
  border-color: rgba(125, 211, 199, 0.45);
  color: var(--accent-2);
}

.lab-projects[open] .lab-projects-summary {
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.lab-projects-count {
  min-width: 1.4em;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(125, 211, 199, 0.18);
  color: var(--accent-2);
  font-size: 0.7rem;
  text-align: center;
}

.lab-projects-hint {
  margin: 0;
  padding: 8px 12px 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.lab-projects-list {
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
  max-height: min(28vh, 220px);
  overflow: auto;
}

.lab-projects-empty {
  margin: 0;
  padding: 8px 12px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.lab-projects-empty[hidden] {
  display: none !important;
}

.lab-project-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
}

.lab-project-row.is-current {
  border-color: rgba(125, 211, 199, 0.35);
  background: rgba(125, 211, 199, 0.06);
}

.lab-project-thumbs {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.lab-project-thumb {
  width: 40px;
  height: 52px;
  border-radius: 6px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.lab-project-thumb.is-empty {
  opacity: 0.55;
}

.lab-project-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lab-project-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.lab-project-meta strong {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lab-project-meta span {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lab-project-open,
.lab-project-del {
  min-height: 34px !important;
  padding: 4px 10px !important;
  font-size: 0.75rem !important;
  width: auto !important;
}

/* —— Form —— */
.lab-form {
  display: grid;
  gap: 12px;
}

.lab.is-joints .lab-form,
.lab.is-detail .lab-form {
  display: none;
}

.lab.is-ready .lab-form > :not(.lab-ready):not(.lab-status):not(.lab-refs) {
  display: none !important;
}

.lab.is-ready .lab-ready {
  display: grid;
}

.lab.is-ready .lab-refs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 0;
}

.lab.is-ready .lab-ref-clear {
  display: none !important;
}

.lab.is-ready .lab-ref-slot {
  pointer-events: none;
}

.lab.is-detail .lab-hero,
.lab.is-joints .lab-hero,
.lab.is-ready .lab-hero {
  display: none;
}

.lab-detail {
  display: grid;
  gap: 12px;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.lab-detail[hidden] {
  display: none;
}

.lab.is-detail .lab-detail {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.lab-detail-options {
  border: 0;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

#btn-detail-download,
#btn-detail-regenerate {
  width: 100%;
}

#btn-detail-download {
  text-align: center;
}

#btn-detail-regenerate {
  margin-top: 4px;
}

#detail-regen-hint {
  margin-top: 8px;
}

.lab.is-joints .lab-detail,
.lab.is-detail .lab-joints,
.lab.is-detail .lab-ready {
  display: none !important;
}

@media (min-width: 480px) {
  .lab-detail-options {
    grid-template-columns: 1fr 1fr;
  }
}

.lab-field {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
}

.lab-field input[type="text"],
.lab-field select {
  font: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 44px;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}

.lab-field select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%239aa3b5' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.lab-role {
  border: 0;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr 1fr;
}

.lab-pose {
  grid-template-columns: 1fr;
  margin-top: 4px;
}

@media (min-width: 420px) {
  .lab-pose {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.lab-role legend {
  font-size: 0.8rem;
  margin-bottom: 2px;
  padding: 0;
  color: var(--text-muted);
}

.lab-role-card {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  cursor: pointer;
  min-height: 0;
  -webkit-tap-highlight-color: transparent;
}

.lab-role-card:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

.lab-role-card input {
  margin: 0;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
}

.lab-role-card span {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.lab-role-card strong {
  display: block;
  line-height: 1.2;
  font-size: 0.9rem;
}

.lab-role-card small {
  color: var(--text-muted);
  font-size: 0.72rem;
  line-height: 1.25;
  display: block;
}

.lab-role .lab-role-card {
  padding: 6px 8px;
}

.lab-role .lab-role-card small {
  font-size: 0.65rem;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lab-detail-options .lab-role-card {
  padding: 9px 11px;
}

.lab-detail-options .lab-role-card small {
  white-space: normal;
  font-size: 0.75rem;
}

.lab-refs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lab-or {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 2px;
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lab-or::before,
.lab-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.lab-mesh-slot {
  position: relative;
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 14px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease;
}

.lab-mesh-slot.is-drag,
.lab-mesh-slot.is-filled {
  border-style: solid;
  border-color: rgba(125, 211, 199, 0.45);
}

.lab-mesh-empty,
.lab-mesh-name {
  display: grid;
  gap: 2px;
  pointer-events: none;
}

.lab-mesh-empty strong,
.lab-mesh-name strong {
  font-size: 0.88rem;
  color: var(--text);
}

.lab-mesh-empty small,
.lab-mesh-name small {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.lab-mesh-slot.is-filled .lab-mesh-empty {
  display: none;
}

.lab-mesh-slot .lab-ref-clear {
  position: absolute;
  top: 6px;
  right: 6px;
}

.lab-form.is-mesh-mode .lab-pose,
.lab-form.is-mesh-mode #photo-hint,
.lab-form.is-mesh-mode .lab-hint.lab-hint-tight:not(#mesh-hint) {
  opacity: 0.4;
  pointer-events: none;
}

.lab-form.is-mesh-mode .lab-refs {
  opacity: 0.35;
  pointer-events: none;
}

.lab-form.is-photo-mode #mesh-hint {
  opacity: 0.55;
}

.lab-ref-slot {
  position: relative;
  display: grid;
  place-items: center;
  margin: 0;
  min-height: 0;
  aspect-ratio: 3 / 4;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(45, 212, 191, 0.06), transparent 55%),
    rgba(0, 0, 0, 0.2);
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease;
}

.lab-ref-slot.is-drag {
  border-color: var(--accent);
  border-style: solid;
}

.lab-ref-slot.is-filled {
  border-style: solid;
  border-color: var(--border);
}

.lab-ref-empty {
  display: grid;
  gap: 4px;
  justify-items: center;
  text-align: center;
  padding: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

.lab-ref-empty strong {
  font-size: 0.85rem;
  color: var(--text);
}

.lab-ref-empty small {
  font-size: 0.68rem;
  line-height: 1.25;
}

.lab-ref-slot > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
}

.lab-ref-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  z-index: 1;
  font-size: 0.6rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  pointer-events: none;
}

.lab-ref-clear {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.lab-ref-clear:hover {
  background: #c44;
}

.lab-ref-slot.is-filled .lab-ref-empty {
  display: none;
}

.lab-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.lab-submit {
  width: 100%;
}

.lab-controls .btn {
  width: 100%;
}

/* —— Status / ready —— */
.lab-status {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  min-height: 1.2em;
}

.lab-status-text {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.lab-status.is-error .lab-status-text {
  color: #ff8f8f;
}

.lab-status-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--accent-2);
  opacity: 0.95;
  font-variant-numeric: tabular-nums;
}

.lab-mesh-info {
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--muted, #9aa3b2);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.lab-status-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.lab-status-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #7dd3c7);
  transition: width 0.6s ease;
}

.lab-status.is-busy .lab-status-fill {
  background-size: 200% 100%;
  animation: lab-shimmer 1.4s linear infinite;
}

@keyframes lab-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.lab-ready {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.lab.is-joints .lab-ready {
  display: none !important;
}

/* Viewport display modes (ready / rig preview) */
.lab-view-modes {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 8;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.lab-view-modes[hidden] {
  display: none !important;
}

.lab-view-modes-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 5px;
  border-radius: 10px;
  background: rgba(8, 10, 16, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.lab-view-mode {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 7px 10px;
  border-radius: 7px;
  background: transparent;
  color: rgba(232, 236, 244, 0.78);
  font: 600 0.7rem/1 Sora, system-ui, sans-serif;
  letter-spacing: 0.02em;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.lab-view-mode:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.lab-view-mode.is-active {
  color: #041016;
  background: #3d9ead;
}

.lab-view-bones {
  padding: 7px 12px;
  border-radius: 10px;
  background: rgba(8, 10, 16, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

.lab-view-modes-end {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
  margin-left: auto;
}

.lab-anim-bar {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border-radius: 10px;
  background: rgba(8, 10, 16, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.lab-anim-bar[hidden] {
  display: none !important;
}

.lab-anim-label {
  display: inline-flex;
  margin: 0;
}

.lab-anim-clip {
  appearance: none;
  max-width: 9.5rem;
  margin: 0;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(232, 236, 244, 0.92);
  font: 600 0.68rem/1.1 Sora, system-ui, sans-serif;
  cursor: pointer;
}

.lab-anim-play.is-active,
.lab-anim-stop.is-active {
  color: #041016;
  background: #3d9ead;
}

.lab-view-bones.is-active {
  color: #041016;
  background: #ff8a3d;
  border-color: transparent;
}

/* —— Viewer —— */
.lab-viewer-wrap {
  position: relative;
  min-height: calc(var(--lab-viewer-h) * var(--lab-viewer-scale));
  height: calc(var(--lab-viewer-h) * var(--lab-viewer-scale));
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background:
    radial-gradient(ellipse at 50% 20%, rgba(61, 158, 173, 0.18), transparent 55%),
    linear-gradient(180deg, #10131c, #07080c);
  overflow: hidden;
  min-width: 0;
}

.lab-joint-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 6;
  max-width: min(320px, calc(100% - 24px));
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(8, 10, 14, 0.72);
  border: 1px solid rgba(94, 234, 212, 0.28);
  backdrop-filter: blur(8px);
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.lab-joint-hud[hidden] {
  display: none !important;
}

.lab-joint-hud-name {
  margin: 0;
  font-family: Oswald, sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #5eead4;
  line-height: 1.2;
}

.lab-joint-hud-hint {
  margin: 6px 0 0;
  font-size: 0.82rem;
  line-height: 1.35;
  color: rgba(232, 236, 244, 0.88);
}

.lab-viewer {
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: transparent;
  display: block;
}

.lab-viewer-empty {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.92rem;
  text-align: center;
}

.lab-progress {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 20px;
  background: rgba(7, 8, 12, 0.72);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.lab-progress[hidden] {
  display: none;
}

.lab-progress-orb {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid rgba(125, 211, 199, 0.22);
  border-top-color: var(--accent);
  animation: lab-spin 0.9s linear infinite;
}

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

.lab-progress-label {
  margin: 0;
  font-family: var(--font-display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.9rem;
  color: var(--text);
  text-align: center;
}

.lab-progress-bar {
  width: min(260px, 78%);
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.lab-progress-fill {
  height: 100%;
  width: 8%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #7dd3c7, var(--accent));
  background-size: 200% 100%;
  animation: lab-shimmer 1.4s linear infinite;
  transition: width 0.7s ease;
}

.lab-progress-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* —— Joints —— */
.lab-joints {
  display: grid;
  gap: 8px;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.lab-joints .lab-role {
  margin: 0;
}

.lab-joints .lab-role-compact .lab-role-card {
  padding: 6px 8px;
}

.lab-joints .lab-role-compact .lab-role-card small {
  font-size: 0.65rem;
}

.lab-joints[hidden] {
  display: none;
}

.lab.is-joints .lab-joints {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.lab-joints-list {
  display: none !important;
}

.lab-joints-title {
  margin: 0;
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: clamp(0.85rem, 2.2vw, 0.98rem);
  line-height: 1.2;
}

.lab-joints-list {
  display: none !important;
}

.lab-joints-list button {
  display: none !important;
}

.lab-joints-actions {
  display: grid;
  gap: 8px;
}

.lab-mirror-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.lab-mirror {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1.2;
  -webkit-tap-highlight-color: transparent;
}

.lab-mirror input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.lab-hint-tight {
  margin-top: -2px;
  font-size: 0.72rem;
  line-height: 1.35;
}

.lab-landmark-stage {
  position: absolute;
  inset: 0;
  z-index: 3;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  background: #0b0d12;
}

.lab-landmark-stage[hidden] {
  display: none !important;
}

.lab-landmark-stage canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: crosshair;
}

.lab-viewer-wrap.is-landmarks {
  touch-action: none;
}

.lab-viewer-wrap.is-landmarks .lab-viewer {
  visibility: hidden;
  pointer-events: none;
  position: absolute;
}

.lab-viewer-wrap.is-landmarks .lab-progress {
  z-index: 4;
}

/* Hide site footer during active Character Lab work — viewport needs the space */
body:has(.lab.is-joints) .site-footer,
body:has(.lab.is-detail) .site-footer,
body:has(.lab.is-ready) .site-footer {
  display: none;
}

/* —— Phone —— */
@media (max-width: 767px) {
  .lab {
    --lab-viewer-h: clamp(240px, 40dvh, 360px);
    padding-top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 10px);
  }

  .lab-layout {
    gap: 12px;
  }

  /* Preview first so users see the 3D stage immediately */
  .lab-viewer-wrap {
    order: -1;
  }

  .lab.is-joints {
    --lab-viewer-h: clamp(280px, 48dvh, 440px);
  }

  .lab.is-detail {
    --lab-viewer-h: clamp(260px, 44dvh, 400px);
  }

  .lab.is-joints .lab-viewer-wrap,
  .lab.is-detail .lab-viewer-wrap {
    position: sticky;
    top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 6px);
    z-index: 2;
  }

  .lab.is-joints .lab-joints-actions {
    position: sticky;
    bottom: 0;
    z-index: 3;
    margin: 4px -12px -12px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, transparent, var(--bg-elevated) 18%);
    border-top: 1px solid var(--border);
  }

  .lab-hero-copy > p:last-child {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

@media (min-width: 768px) and (max-width: 899px) {
  .lab {
    --lab-viewer-h: clamp(300px, 42dvh, 460px);
  }

  .lab-viewer-wrap {
    order: -1;
  }

  .lab.is-joints {
    --lab-viewer-h: clamp(340px, 50dvh, 520px);
  }

  .lab.is-detail {
    --lab-viewer-h: clamp(320px, 46dvh, 480px);
  }

  .lab-joints-list {
    grid-template-columns: 1fr 1fr;
    max-height: min(280px, 36dvh);
  }

  .lab-joints-actions {
    grid-template-columns: 1fr 1.4fr;
  }
}

/* —— Tablet landscape / small laptop —— */
@media (min-width: 768px) and (max-width: 899px) and (orientation: landscape) {
  .lab {
    --lab-viewer-h: min(520px, calc(100dvh - var(--header-h) - 48px));
  }

  .lab.is-joints,
  .lab.is-detail,
  .lab.is-ready {
    --lab-viewer-h: min(560px, calc(100dvh - var(--header-h) - 40px));
  }

  .lab-layout {
    grid-template-columns: minmax(240px, 32vw) minmax(0, 1fr);
    align-items: stretch;
  }

  .lab-viewer-wrap {
    order: 0;
    height: calc(var(--lab-viewer-h) * var(--lab-viewer-scale));
    min-height: calc(var(--lab-viewer-h) * var(--lab-viewer-scale));
    position: sticky;
    top: calc(var(--header-h) + 12px);
  }

  .lab-controls {
    max-height: calc(var(--lab-viewer-h) * var(--lab-viewer-scale));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .lab-joints-actions {
    grid-template-columns: 1fr;
  }
}

/* —— Desktop —— */
@media (min-width: 900px) {
  .lab {
    --lab-viewer-h: calc(100dvh - var(--header-h) - env(safe-area-inset-top, 0px) - 168px);
    padding-top: calc(var(--header-h) + 20px);
    padding-bottom: 12px;
  }

  .lab.is-joints,
  .lab.is-detail,
  .lab.is-ready {
    --lab-viewer-h: calc(100dvh - var(--header-h) - env(safe-area-inset-top, 0px) - 118px);
  }

  .lab-layout {
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    align-items: start;
  }

  .lab-controls {
    position: sticky;
    top: calc(var(--header-h) + 16px);
    max-height: calc(var(--lab-viewer-h) * var(--lab-viewer-scale));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
  }

  .lab-viewer-wrap {
    height: calc(var(--lab-viewer-h) * var(--lab-viewer-scale));
    min-height: calc(var(--lab-viewer-h) * var(--lab-viewer-scale));
    position: sticky;
    top: calc(var(--header-h) + 16px);
  }

  .lab-hero {
    margin-bottom: 20px;
  }

  .lab-joints-list {
    grid-template-columns: 1fr 1fr;
    max-height: min(320px, 42dvh);
  }

  .lab-controls .btn {
    width: 100%;
  }
}

@media (min-width: 1200px) {
  .lab-layout {
    grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  }

  .lab {
    --lab-viewer-h: calc(100dvh - var(--header-h) - env(safe-area-inset-top, 0px) - 160px);
  }

  .lab.is-joints,
  .lab.is-detail,
  .lab.is-ready {
    --lab-viewer-h: calc(100dvh - var(--header-h) - env(safe-area-inset-top, 0px) - 110px);
  }
}

/* —— Short laptop screens —— */
@media (min-width: 900px) and (max-height: 760px) {
  .lab {
    --lab-viewer-h: calc(100dvh - var(--header-h) - 88px);
  }

  .lab.is-joints,
  .lab.is-detail,
  .lab.is-ready {
    --lab-viewer-h: calc(100dvh - var(--header-h) - 72px);
  }

  .lab-hero h1 {
    font-size: 1.7rem;
  }

  .lab-hero {
    margin-bottom: 12px;
  }

  .lab-hero-copy > p:last-child {
    font-size: 0.88rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lab-status-fill,
  .lab-progress-fill,
  .lab-progress-orb {
    animation: none !important;
  }
}
