/* General parts demo: the viewer fills the window; the choices float over it and the rest sits in a drawer.
   It reuses the tokens of demo.css. Floating surfaces use a translucent panel so the model stays visible. */
html,
body.pd-page {
  height: 100%;
  overflow: hidden;
}
/* The viewer's stage is dark in every scheme, so the page around it is too: one palette, always. */
.pd-page {
  --bg: #0b0f17;
  --surface: #121826;
  --text: #e6e9ef;
  --muted: #a3acbd;
  --border: #273044;
  --accent: #3fd0e0;
  --accent-contrast: #06232a;
  --code-bg: #060a12;
  --code-text: #e2e8f0;
  --pd-glass: color-mix(in srgb, var(--surface) 82%, transparent);
  --pd-shadow: 0 6px 24px rgb(0 0 0 / 0.35);
  --pd-gap: 12px;
  color-scheme: dark;
  background: var(--bg);
}

.pd-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* The stage: the viewer takes the whole window, everything else is positioned over it. A lit studio backdrop sits
   behind a transparent viewer, so the model, its soft shadow and its reflections read against the gradient and not
   against flat black. */
.pd-stage {
  position: fixed;
  inset: 0;
  height: 100dvh;
  background: radial-gradient(ellipse 80% 70% at 50% 48%, #5a6882 0%, #2a3344 50%, #0e131c 100%);
}
.pd-stage contrast-viewer {
  --contrast-viewer-bg: transparent;
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* Top bar: brand on the left, actions on the right. */
.pd-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  /* The viewer keeps a panel button in each top corner: the actions start beside the left one. */
  padding: max(var(--pd-gap), env(safe-area-inset-top)) 0 0
    calc(max(var(--pd-gap), env(safe-area-inset-left)) + 48px);
  pointer-events: none;
}
.pd-top > * {
  pointer-events: auto;
}
/* The brand sits at the bottom left on a wide window and is read by screen readers only on a narrow one. */
.pd-top .brand {
  position: fixed;
  left: max(var(--pd-gap), env(safe-area-inset-left));
  bottom: max(var(--pd-gap), env(safe-area-inset-bottom));
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--pd-glass);
  backdrop-filter: blur(8px);
  font-size: 0.9rem;
  pointer-events: none;
}
@media (max-width: 1100px) {
  .pd-top .brand {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}
/* The accent colour of the shared brand is too light over a changing background: keep the text colour. */
.pd-top .brand span {
  color: inherit;
  font-weight: 400;
}
.pd-top .env-banner {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  white-space: nowrap;
}
.pd-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pd-language {
  display: inline-flex;
  border-radius: 999px;
  background: var(--pd-glass);
  backdrop-filter: blur(8px);
  overflow: hidden;
}
.pd-language button {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.pd-language button[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-contrast);
}

.pd-icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--pd-glass);
  backdrop-filter: blur(8px);
  color: var(--text);
  cursor: pointer;
}
.pd-icon-button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}
.pd-icon-button[aria-expanded='true'] {
  background: var(--accent);
  color: var(--accent-contrast);
}

.pd-language button:focus-visible,
.pd-icon-button:focus-visible,
.pd-tile:has(input:focus-visible),
.pd-dot:has(input:focus-visible),
.pd-json:focus-visible,
.pd-section summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Caption: reference, name, finish and chosen part on one line, under the brand. */
.pd-caption {
  position: absolute;
  top: calc(max(var(--pd-gap), env(safe-area-inset-top)) + 60px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 10px;
  width: max-content;
  max-width: calc(100vw - 2 * var(--pd-gap));
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--pd-glass);
  backdrop-filter: blur(8px);
  font-size: 0.9rem;
  pointer-events: none;
}
.pd-caption div {
  display: flex;
  gap: 10px;
  min-width: 0;
}
.pd-caption dd {
  margin: 0;
  overflow-wrap: anywhere;
}
.pd-caption div:first-child dd {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.pd-caption div:nth-child(2) dd {
  font-weight: 700;
}
.pd-caption div + div::before {
  content: '·';
  color: var(--muted);
}

.pd-status {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 10;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--pd-glass);
  backdrop-filter: blur(8px);
}

.pd-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 10;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border: 4px solid color-mix(in srgb, var(--text) 25%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: pd-spin 0.9s linear infinite;
  pointer-events: none;
}
.pd-spinner[hidden],
.pd-caption div[hidden] {
  display: none;
}
@keyframes pd-spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .pd-spinner {
    animation-duration: 3s;
  }
}
.pd-icon-button svg.pd-stroke {
  fill: none;
}

/* Dock: the finishes above the pieces, at the bottom, within reach of a thumb. */
.pd-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 max(var(--pd-gap), env(safe-area-inset-right))
    max(var(--pd-gap), env(safe-area-inset-bottom)) max(var(--pd-gap), env(safe-area-inset-left));
  pointer-events: none;
}
.pd-dock fieldset {
  min-width: 0;
  /* Leave the corners to the viewer's own navigation buttons. */
  max-width: min(100%, 1000px);
  margin: 0;
  padding: 6px;
  border: 0;
  border-radius: 999px;
  background: var(--pd-glass);
  backdrop-filter: blur(8px);
  box-shadow: var(--pd-shadow);
  pointer-events: auto;
}
.pd-swatches,
.pd-pills {
  display: flex;
  gap: 6px;
}
.pd-pills {
  position: relative;
  overflow-x: auto;
  scrollbar-width: none;
}

.pd-pieces {
  border-radius: 20px;
}
.pd-tile,
.pd-dot {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 44px;
  cursor: pointer;
}
.pd-dot {
  width: 44px;
  border-radius: 999px;
}
/* A piece is its picture: a small 4:3 render of its own model. */
.pd-tile {
  width: 84px;
  height: 63px;
  overflow: hidden;
  border-radius: 14px;
  background: var(--code-bg);
  opacity: 0.72;
  transition:
    opacity 0.15s,
    transform 0.15s;
}
.pd-tile:hover {
  opacity: 1;
}
.pd-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.pd-tile-name {
  padding: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
}
.pd-tile:has(input:checked) {
  opacity: 1;
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}
.pd-tile input,
.pd-dot input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.pd-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgb(127 127 127 / 0.55);
}
.pd-dot:has(input:checked) .pd-swatch {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.pd-gesture {
  position: absolute;
  left: 50%;
  bottom: calc(max(var(--pd-gap), env(safe-area-inset-bottom)) + 150px);
  z-index: 10;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--pd-glass);
  backdrop-filter: blur(8px);
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  pointer-events: none;
}
.pd-gesture[hidden],
.pd-drawer[hidden] {
  display: none;
}

/* Drawer: result, tools and project items. A side panel on wide windows, a bottom sheet on narrow ones. */
.pd-drawer {
  position: fixed;
  z-index: 25;
  /* Below the top bar, so the drawer button and the language switch stay reachable while it is open. */
  top: calc(max(var(--pd-gap), env(safe-area-inset-top)) + 56px);
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  overflow-y: auto;
  padding: var(--pd-gap) 16px 24px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--pd-shadow);
}
.pd-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.pd-drawer-head h2 {
  margin: 0;
  font-size: 1.1rem;
}
.pd-section {
  border-top: 1px solid var(--border);
  padding: 4px 0;
}
.pd-section summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-weight: 700;
}
.pd-hint {
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
}
.pd-quantity {
  display: flex;
  gap: 8px;
  margin: 8px 0 0;
}
.pd-quantity dt {
  color: var(--muted);
}
.pd-quantity dd {
  margin: 0;
  font-weight: 600;
}
.pd-json {
  margin: 0;
  padding: 12px;
  overflow: auto;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.pd-cards {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.pd-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: default;
}
.pd-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}
.pd-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.pd-cards-mockup .pd-card {
  border-style: dashed;
}
.pd-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border: 1px solid var(--muted);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  vertical-align: middle;
}
.pd-footer {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 640px) {
  .pd-drawer {
    top: auto;
    width: 100vw;
    max-height: 72dvh;
    border-radius: 16px 16px 0 0;
  }
  /* The viewer's toolbar wraps on a narrow window: the actions go to a second row. */
  .pd-top {
    padding-top: calc(max(var(--pd-gap), env(safe-area-inset-top)) + 52px);
    padding-left: max(var(--pd-gap), env(safe-area-inset-left));
  }
  .pd-caption {
    top: calc(max(var(--pd-gap), env(safe-area-inset-top)) + 108px);
    border-radius: 14px;
    font-size: 0.8rem;
  }
  .pd-gesture {
    white-space: normal;
    text-align: center;
    max-width: calc(100vw - 2 * var(--pd-gap));
  }
  /* The swatches stand at the left edge, and the strip stops short of the viewer's navigation buttons. */
  .pd-dock {
    align-items: flex-start;
  }
  .pd-finishes {
    position: fixed;
    left: max(var(--pd-gap), env(safe-area-inset-left));
    top: 50%;
    transform: translateY(-50%);
    border-radius: 999px;
  }
  .pd-finishes .pd-swatches {
    flex-direction: column;
  }
  .pd-dock .pd-pieces {
    max-width: calc(100vw - 112px);
  }
  .pd-gesture {
    bottom: calc(max(var(--pd-gap), env(safe-area-inset-bottom)) + 96px);
  }
}
/* A low window (a phone held sideways): the swatches go to a column at the left, the tiles shrink and the hint goes,
   so the model keeps most of the height. */
@media (max-height: 480px) {
  .pd-finishes {
    position: fixed;
    left: max(var(--pd-gap), env(safe-area-inset-left));
    top: 50%;
    transform: translateY(-50%);
    border-radius: 999px;
  }
  .pd-finishes .pd-swatches {
    flex-direction: column;
  }
  .pd-tile {
    width: 64px;
    height: 48px;
    min-height: 0;
  }
  .pd-gesture {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
  }
}
