.jewelry-stage {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
}
.jewelry-library {
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid #d8ccba;
  border-radius: 7px;
  background: #fffaf2;
  font-size: .86rem;
}
.jewelry-library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  flex-wrap: wrap;
}
.jewelry-library-head label { display: inline-flex; align-items: center; gap: 7px; }
.jewelry-library-head select {
  max-width: 100%;
  padding: 4px 6px;
  border: 1px solid #cfc5b4;
  border-radius: 5px;
  background: #fffdf7;
}
.jewelry-library p { color: var(--muted); margin: 5px 0; }
.jewelry-library p[role=status]:empty { display: none; }
.jewelry-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit,minmax(min(108px,100%),1fr));
  gap: 6px;
}
.jewelry-cards button {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 2px;
  padding: 5px;
  border: 1px solid #d7cbbb;
  border-radius: 6px;
  background: #f5eee1;
  cursor: grab;
}
.jewelry-cards button:hover { border-color: var(--moss); background: #e7ebdf; }
.jewelry-cards button:active { cursor: grabbing; }
.jewelry-cards svg { width: 48px; height: 31px; pointer-events: none; }
.jewelry-cards img { width: 100%; max-width: 148px; height: auto; aspect-ratio: 148 / 92; border-radius: 5px; background: radial-gradient(ellipse at 50% 42%, #4d4641, #2c2723); pointer-events: none; }
.jewelry-cards strong { line-height: 1.25; }
.jewelry-cards small { color: var(--muted); font-variant-numeric: tabular-nums; }
.jewelry-placed { margin-top: 6px; }
.jewelry-placed summary { cursor: pointer; }
.jewelry-placed ul { list-style: none; margin: 5px 0; padding: 0; }
.jewelry-placed li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px 8px;
  flex-wrap: wrap;
  padding: 4px 0;
  border-bottom: 1px solid #e9e0d2;
}
.jewelry-placed li div { display: flex; gap: 4px; }
/* The photographic pieces sit above the drawing. The drawing keeps the pointer. */
.jewelry-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 7px;
  pointer-events: none;
}
.box-scene [data-jewelry-item] { cursor: grab; }
.box-scene[data-jewelry-dragging] { cursor: grabbing; }
.jewelry-stage .box-scene { min-height: 0; height: clamp(340px, 55svh, 680px); }
.box-viewer:has(.jewelry-library:not([hidden])) .jewelry-stage { flex: 0 0 auto; }
.box-viewer:has(.jewelry-library:not([hidden])) .jewelry-stage .box-scene {
  flex: 0 0 auto;
  height: clamp(290px, 46svh, 540px);
}
.box-viewer:has(.jewelry-stage) #jewelry-library-toggle[aria-expanded=true] {
  color: var(--white);
  background: var(--moss);
}
@media (max-width: 750px) {
  .jewelry-stage .box-scene { height: max(270px, 42svh); }
}

/* On a wide screen the library stands beside the preview instead of above it. */
@media (min-width: 900px) {
  .box-viewer:has(.jewelry-stage),
  [data-preview-immersive] .box-viewer:has(.jewelry-stage) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "tools tools" "stage library" "hint hint";
  }
  .box-viewer:has(.jewelry-stage) > .box-tools { grid-area: tools; }
  .box-viewer:has(.jewelry-stage) > figcaption { grid-area: hint; }
  .box-viewer .jewelry-stage { grid-area: stage; min-height: 0; }
  .box-viewer .jewelry-library {
    grid-area: library;
    width: clamp(250px, 17vw, 310px);
    margin: 0 0 0 10px;
    overflow-y: auto;
    scrollbar-width: thin;
  }
  .jewelry-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .box-viewer:has(.jewelry-library:not([hidden])) .jewelry-stage { flex: 1 1 auto; }
  .box-viewer:has(.jewelry-library:not([hidden])) .jewelry-stage .box-scene { flex: 1 1 auto; height: 100%; }
}

/* Below that width the library is one row to swipe, so the drawer stays in view. */
@media (max-width: 899px) {
  .jewelry-library { flex: none; }
  .jewelry-cards {
    grid-template-columns: none;
    grid-auto-columns: 106px;
    grid-auto-flow: column;
    padding-bottom: 5px;
    overflow-x: auto;
    scrollbar-width: thin;
  }
}
