/* =========================================================================
   /rig — part explorer (#rig-specs): 3D stage, chips, spec panel
   Loaded after css/styles.css and css/rig.css (uses their tokens and the
   shared .rig-stage / .rig-stage__poster / .rig-stage__canvas rules).
   Behaviour: js/rig/src/specs-ui.js (chips + panel, every mode) and
   js/rig/src/specs.js (3D, full mode). Docs: docs/rig-specs.md.

   Panel: a side panel over the right of the model on desktop (the 3D
   picture slides left to stay clear of it), a bottom sheet on phones.
   ========================================================================= */

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

/* Copy that only makes sense with / without the live model. */
.rig-when-full { display: none; }
.rig-full .rig-when-full { display: inline; }
.rig-full .rig-when-static { display: none; }

/* No JS, or a browser too old for boot.js (it sets neither class): the
   chips and panel can't work, so show the plain part list instead. */
.rig-when-nojs,
.rig-specs-fallback { display: none; }
html:not(.rig-full):not(.rig-static) .rig-when-static,
html:not(.rig-full):not(.rig-static) .rig-chips,
html:not(.rig-full):not(.rig-static) .rig-panel { display: none; }
html:not(.rig-full):not(.rig-static) .rig-when-nojs { display: inline; }
html:not(.rig-full):not(.rig-static) .rig-specs-fallback { display: grid; gap: 0.9rem; }
.rig-specs-fallback dt { font-family: var(--font-head); font-weight: 600; }
.rig-specs-fallback dd { color: var(--muted); font-size: 0.92rem; }

.rig-specs__layout {
  display: grid;
  gap: 1.4rem;
  grid-template-columns: minmax(0, 1fr);
}
.rig-specs__side { min-width: 0; }

/* ---- Stage ------------------------------------------------------------- */
.rig-stage--specs {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  scroll-margin-top: calc(var(--header-h) + 0.5rem);
}
.rig-stage--specs .rig-stage__canvas { cursor: grab; }
.rig-stage--specs .rig-stage__canvas.is-pointing { cursor: pointer; }
.rig-stage--specs .rig-stage__canvas.is-grabbing { cursor: grabbing; }
.rig-stage--specs .rig-stage__canvas:focus { outline: none; }
.rig-stage--specs .rig-stage__canvas:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: -3px; border-radius: var(--radius-lg); }

/* "Drag to spin" hint: full mode only, gone after the first interaction
   or while a part is open. */
.rig-specs__hint {
  position: absolute;
  left: 1rem;
  bottom: 0.9rem;
  margin: 0;
  padding: 0.38rem 0.8rem;
  font-family: var(--font-head);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--silver);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: 2;
}
.rig-specs__hint::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 0.55rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(21, 23, 26, 0.35);
  vertical-align: middle;
}
.rig-full .rig-stage--specs.is-live .rig-specs__hint { opacity: 1; }
.rig-full .rig-stage--specs.is-touched .rig-specs__hint,
.rig-spec-open .rig-specs__hint { opacity: 0; }
.rig-specs__hint-touch { display: none; }
@media (hover: none), (pointer: coarse) {
  .rig-specs__hint-mouse { display: none; }
  .rig-specs__hint-touch { display: inline; }
}
html:not(.rig-full) .rig-specs__hint { display: none; }

/* Hover tooltip (specs.js moves it with a transform). */
.rig-tip {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  gap: 0.05rem;
  padding: 0.42rem 0.7rem 0.45rem;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px -14px rgba(21, 23, 26, 0.4);
  pointer-events: none;
  white-space: nowrap;
  z-index: 4;
}
.rig-tip[hidden] { display: none; }
.rig-tip strong {
  font-family: var(--font-head);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}
.rig-tip span { font-size: 0.72rem; color: var(--accent-ink); letter-spacing: 0.02em; }

/* ---- Chips ------------------------------------------------------------- */
.rig-chips { display: flex; flex-wrap: wrap; gap: 0.55rem; align-content: flex-start; }
.rig-chip {
  font-family: var(--font-head);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--silver);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  min-height: 44px;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.rig-chip:hover { border-color: var(--text); color: var(--text); }
.rig-chip.is-selected,
.rig-chip[aria-pressed="true"] {
  color: var(--text);
  background: var(--accent);
  border-color: var(--text);
  box-shadow: var(--shadow-glow);
}
.rig-chip:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 3px; border-radius: 999px; }



/* ---- Spec panel -------------------------------------------------------- */
.rig-panel {
  position: absolute;
  top: 1rem;
  right: 1rem;
  bottom: 1rem;
  width: min(360px, 40%);
  display: flex;
  flex-direction: column;
  padding: 1.15rem 1.2rem 0.9rem;
  background: rgba(255, 255, 255, 0.95);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateX(14px);
  transition: opacity 0.28s ease, transform 0.32s cubic-bezier(0.2, 0.7, 0.2, 1);
  z-index: 3;
}
.rig-panel.is-open { opacity: 1; transform: none; }
.rig-panel[hidden] { display: none; }
.rig-panel__grab { display: none; }
.rig-panel__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.8rem; flex: none; }
.rig-panel__kicker {
  font-family: var(--font-head);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-bright);
}
.rig-panel__title { font-size: 1.38rem; line-height: 1.2; margin-top: 0.3rem; }
.rig-panel__title:focus { outline: none; }
.rig-panel__title:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 4px; border-radius: 4px; }
.rig-panel__close {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.rig-panel__close:hover { border-color: var(--text); background: var(--surface-2); }
.rig-panel__close:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 2px; }

.rig-panel__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin-top: 0.2rem;
  padding-right: 0.2rem;
  scrollbar-width: thin;
}
.rig-panel__benefit { color: var(--silver); margin-top: 0.6rem; font-size: 0.98rem; line-height: 1.5; }
.rig-panel__specs { margin-top: 0.9rem; display: grid; }
.rig-panel__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}
.rig-panel__row:last-child { border-bottom: 1px solid var(--border); }
.rig-panel__row dt { color: var(--muted); flex: none; max-width: 45%; }
.rig-panel__row dd { margin: 0; text-align: right; color: var(--text); font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.rig-panel__why {
  margin-top: 0.95rem;
  padding: 0.7rem 0.85rem;
  border-left: 3px solid var(--accent);
  background: rgba(243, 196, 50, 0.1);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.rig-panel__why h4 {
  font-family: var(--font-head);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-bright);
}
.rig-panel__why p { margin-top: 0.3rem; color: var(--silver); font-size: 0.9rem; line-height: 1.5; }

/* Prev / next part */
.rig-panel__nav {
  flex: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.8rem;
}
.rig-panel__step {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  min-height: 40px;
  padding: 0.4rem 0.65rem;
  font-family: var(--font-head);
  font-size: 0.8rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: left;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.rig-panel__step--next { justify-content: flex-end; text-align: right; }
.rig-panel__step:hover { color: var(--text); border-color: var(--text); }
.rig-panel__step:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 2px; }
.rig-panel__navname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rig-panel__dir { flex: none; color: var(--accent-ink); }

/* ---- Desktop: a wide stage, the chips in a row under it ---------------- */
@media (min-width: 900px) {
  .rig-stage--specs {
    aspect-ratio: 16 / 9;
    max-height: calc(100svh - var(--header-h) - 8.5rem);
    min-height: 420px;
  }
  .rig-specs__side {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem 2rem;
  }
  .rig-chips { flex: 1 1 36rem; }
}

/* ---- Phones / tablets -------------------------------------------------- */
@media (max-width: 899px) {
  /* One swipeable row of chips right under the model, so the model, the
     chips and the bottom sheet fit on one screen. */
  .rig-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    margin-inline: -1.25rem;
    padding: 0.2rem 1.25rem 0.6rem;
    scrollbar-width: none;
  }
  .rig-chips::-webkit-scrollbar { display: none; }
  .rig-chips li { flex: none; scroll-snap-align: start; scroll-margin-inline: 1.25rem; }
  .rig-specs__layout { gap: 0.9rem; }

  /* Bottom sheet, sized to leave the model (scrolled up under the header)
     visible above it. */
  .rig-panel {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: max(42svh, calc(100svh - var(--header-h) - 75vw));
    padding: 0.35rem 1rem calc(0.9rem + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 0;
    box-shadow: 0 -18px 40px -20px rgba(21, 23, 26, 0.45);
    transform: translateY(32px);
    z-index: 60;
  }
  .rig-panel__grab {
    display: block;
    flex: none;
    height: 22px;
    margin: 0 -1rem 0.2rem;
    touch-action: none;
    cursor: grab;
  }
  .rig-panel__grab::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    margin: 9px auto 0;
    border-radius: 2px;
    background: var(--border-strong);
  }
  .rig-panel__title { font-size: 1.22rem; }
  .rig-panel__benefit { font-size: 0.94rem; margin-top: 0.4rem; }
  .rig-specs__hint { left: 0.7rem; bottom: 0.65rem; font-size: 0.74rem; }
}

@media (max-width: 400px) {
  .rig-panel__row { font-size: 0.86rem; gap: 0.7rem; }
  .rig-panel__step { font-size: 0.76rem; padding: 0.4rem 0.5rem; }
}

/* ---- Reduced motion ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .rig-panel,
  .rig-chip,
  .rig-specs__hint { transition: none; }
}
