/* The frame shared by the configurators: header, heading, numbered steps, model and review bar.
   The pages come from different sources, so #configure outranks their own rules. */
:root {
  --cfg-header: 58px;
  --cfg-head: 48px;
  --cfg-bar: 62px;
  --cfg-side: clamp(304px, 24vw, 404px);
  --cfg-gap: clamp(12px, 1.2vw, 24px);
}

html { scroll-padding-top: calc(var(--cfg-header) + 8px); }

body[data-config] {
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, "Segoe UI", sans-serif;
  background: #f7f3ea;
  color: #2b2b22;
  font-family: var(--sans);
}
:lang(zh) > body[data-config] {
  --serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
body[data-config] > main :is(h1, h2) { font-family: var(--serif); font-weight: 500; letter-spacing: -.02em; }

/* ---- Header ---- */

.cfg-top {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 8px 18px;
  height: var(--cfg-header);
  padding-inline: var(--cfg-gap);
  border-bottom: 1px solid #ddd3c1;
  background: #fbf8f0;
  font: 400 .94rem/1.3 var(--sans);
}
.cfg-top a { color: #2d4b3b; text-decoration: none; }
.cfg-top a:hover { text-decoration: underline; text-underline-offset: 4px; }
.cfg-brand { display: flex; align-items: center; flex: none; min-height: 44px; }
.cfg-brand .brand-art { display: block; }
.cfg-brand .brand-art-en { width: 197px; }
.cfg-brand .brand-art-zh { width: 122px; }
.cfg-brand img { display: block; width: 100%; height: auto; }

.cfg-switch { position: relative; min-width: 0; }
.cfg-switch summary {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 5px 13px;
  border: 1px solid #cfc5b1;
  border-radius: 6px;
  background: #fffdf8;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.cfg-switch summary span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cfg-switch summary::-webkit-details-marker { display: none; }
.cfg-switch summary::after, .cfg-toggle::after {
  flex: none;
  width: 7px;
  height: 7px;
  margin-top: -4px;
  border: solid currentColor;
  border-width: 0 1.7px 1.7px 0;
  transform: rotate(45deg);
  content: "";
}
.cfg-switch[open] summary::after { margin-top: 4px; transform: rotate(225deg); }
.cfg-switch nav {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  display: grid;
  min-width: 250px;
  padding: 6px;
  border: 1px solid #cfc5b1;
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 0 14px 34px #2a221c2b;
}
.cfg-switch nav a { padding: 10px 12px; border-radius: 5px; }
.cfg-switch nav a:hover { background: #eef0e6; text-decoration: none; }
.cfg-switch nav a[aria-current] { background: #e5ebdf; font-weight: 650; }
.cfg-links { display: flex; align-items: center; gap: 4px 20px; margin-left: auto; white-space: nowrap; }
.cfg-links a { padding-block: 9px; font-weight: 600; }
:is(.cfg-top, .cfg-bar) :is(a, summary, button):focus-visible, .cfg-toggle:focus-visible, .cfg-next:focus-visible { outline: 2px solid #31513f; outline-offset: 2px; }

/* ---- Heading and save bar. The pages' own headings are replaced. ---- */

#configure > .cfg-head { display: flex; align-items: center; gap: 4px 20px; min-height: var(--cfg-head); padding-block: 4px; }
#configure .cfg-name { flex: none; margin: 0; max-width: none; font: 500 1.4rem/1.2 var(--serif); letter-spacing: -.02em; color: #2b2b22; }
#configure > .cfg-head .design-bar { margin: 0 0 0 auto; max-width: none; min-width: 0; padding: 0; }

#configure.box-builder > header, #configure > .coaster-heading, #configure > header.intro, #configure .tray-head, #configure > .config-head,
#configure .tray-footer, #configure > .footer, #configure .diagram > .meta, #configure .options-head, #configure .tray-settings-head,
#configure .options-foot, #configure .tray-nav, #configure #show-options, #configure #show-tray-options, #configure #result,
#configure label:has(> #extra-notes), #configure .box-view-jump { display: none !important; }

/* ---- Workspace ---- */

body > main > #configure {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  min-height: 0;
  margin: 0;
  padding: 0 var(--cfg-gap);
  border: 0;
  border-radius: 0;
  background: none;
  overflow: visible;
  scroll-margin-top: var(--cfg-header);
}
#configure :is(.tray-builder, .builder, .builder > .diagram) { display: contents; }

#configure .cfg-workspace {
  position: relative;
  display: grid;
  grid-template-columns: var(--cfg-side) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: max(430px, calc(100svh - var(--cfg-header) - var(--cfg-head) - var(--cfg-bar)));
  min-height: 0;
  margin: 0;
  border: 1px solid #d8cdb9;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: #f0eadf;
  overflow: hidden;
  isolation: isolate;
}
#configure .cfg-side:not([hidden]) {
  display: block;
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  max-height: none;
  padding: 0;
  border: 0;
  border-right: 1px solid #d8cdb9;
  background: #fffbf3;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
#configure .cfg-side .cfg-steps { min-height: 0; overflow: visible; }
#configure .step-accordion { display: block; height: auto; }

#configure .cfg-view {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 9px 10px 8px;
  background: #f0eadf;
}
#configure :is([data-options=false], [data-options-open=false]) > .cfg-view { grid-column: 1; }
#configure :is(.box-scene, .coaster-scene, #tray-scene, .model) { flex: 1 1 auto; width: 100%; height: 100%; min-height: 0; max-height: none; }
#configure .jewelry-stage { flex: 1 1 auto; min-height: 0; }
#configure .tray-stage { flex: 1 1 auto; min-height: 0; grid-template-rows: minmax(0, 1fr); }
#configure .organizer-view > .model-area { flex: 1 1 auto; height: auto; min-height: 0; margin: 0; border: 1px solid #d8cdb9; border-radius: 8px; aspect-ratio: auto; }
#configure .organizer-view > .preview-command { top: 56px; right: 20px; }
#configure .cfg-view > :is(figcaption, p) { margin: 0; color: #6a6253; font-size: .82rem; line-height: 1.4; }
#configure .cfg-view > p:empty { display: none; }
#configure .cfg-canvas-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #d8ccba;
  border-radius: 10px;
  background: radial-gradient(ellipse at 48% 42%, #fcf9f1 12%, #e4dac8 96%);
}
#configure .cfg-canvas-stage > canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline-offset: -4px;
  cursor: grab;
  touch-action: none;
}
#configure .cfg-canvas-stage > canvas[data-dragging] { cursor: grabbing; }
#configure .cfg-view > .tray-status.tray-warn { padding: 5px 9px; border-radius: 5px; color: #83392d; }
#configure .organizer-view > .ref-shelf:not(:has(#active-refs > *)) { display: none; }
#configure .organizer-view > .ref-shelf { display: flex; gap: 8px; margin: 0; overflow-x: auto; scrollbar-width: thin; }
#configure .organizer-view .ref-list { flex-wrap: nowrap; margin: 0; }
#configure .organizer-view .ref-list > * { flex: none; }

@media (min-width: 900px) { #configure .box-viewer:has(.jewelry-stage) { display: grid; } }

/* ---- Buttons above the model ---- */

#configure .cfg-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: 5px; margin: 0; padding: 0; }
#configure .cfg-tools > div { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
#configure .cfg-tools > .spacer { display: none; }
#configure .cfg-tools > div:nth-child(2) { margin-left: auto; }
#configure .cfg-tools button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 34px;
  margin: 0;
  padding: 4px 11px;
  border: 1px solid #cfc5b1;
  border-radius: 6px;
  background: #fffdf8;
  color: #2d4b3b;
  font: 600 .84rem/1.2 var(--sans);
  white-space: nowrap;
  cursor: pointer;
}
#configure .cfg-tools button svg { margin: 0; }
#configure .cfg-tools button:hover { background: #eef0e6; }
#configure .cfg-tools button[aria-pressed=true] { border-color: #344536; background: #344536; color: #fffdf8; }
#configure .cfg-tools button:disabled { opacity: .5; cursor: default; }
#configure .cfg-tools button[hidden] { display: none; }
#configure .cfg-tools #view-caption { align-self: center; margin-left: 4px; color: #6a6253; font-size: .8rem; }
#configure .cfg-tools .box-reset, #configure .cfg-tools .coaster-reset { margin-left: 0; }
#configure .cfg-tools > button[aria-controls] { margin-left: auto; }
#configure .cfg-tools > #jewelry-library-toggle { order: 0; margin-left: 0; }
#configure .organizer-view .cfg-tools > div:nth-child(2) { margin-left: 0; }

/* ---- Steps ---- */

#configure .cfg-step { display: block; min-height: 0; margin: 0; border: 0; border-bottom: 1px solid #e5dac8; }
#configure .cfg-step > h3 { margin: 0; font: inherit; letter-spacing: normal; }
#configure .cfg-toggle {
  display: grid;
  grid-template-columns: 1.6rem auto minmax(0, 1fr) 9px;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 50px;
  padding: 9px 16px 9px 14px;
  border: 0;
  border-radius: 0;
  background: none;
  color: #2b3a30;
  font: 650 .95rem/1.25 var(--sans);
  letter-spacing: normal;
  text-align: left;
  list-style: none;
  cursor: pointer;
}
#configure .cfg-toggle::-webkit-details-marker { display: none; }
#configure .cfg-toggle:hover { background: #f5eddd; }
#configure .cfg-toggle::after {
  display: block;
  width: 7px;
  height: 7px;
  margin: -4px 0 0;
  border: solid #6a6253;
  border-width: 0 1.7px 1.7px 0;
  border-radius: 0;
  background: none;
  transform: rotate(45deg);
  content: "";
}
#configure :is(.cfg-toggle[aria-expanded=true], .cfg-step[open] > .cfg-toggle) { background: #e9eee3; font-weight: 700; }
#configure :is(.cfg-toggle[aria-expanded=true], .cfg-step[open] > .cfg-toggle)::after { margin-top: 5px; transform: rotate(225deg); }
#configure .cfg-num { display: block; min-width: 0; color: #84462e; font: 650 .78rem/1 var(--sans); font-variant-numeric: tabular-nums; }
#configure .cfg-title { min-width: 0; white-space: nowrap; }
#configure .cfg-value { min-width: 0; color: #6a6253; font-size: .82rem; font-weight: 500; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#configure .cfg-value[data-state=optional] { color: #8b8371; }
#configure .cfg-value[data-state=missing] { color: #9a3f22; font-weight: 650; }

#configure .cfg-panel:not([hidden]) { min-height: 0; margin: 0; padding: 13px 16px 16px 14px; border: 0; overflow: visible; font-size: .88rem; }
#configure .cfg-panel > fieldset { margin: 0 0 12px; }
#configure .cfg-panel > fieldset:last-of-type { margin-bottom: 0; }
#configure .cfg-panel .engraving-kit { margin: 0; padding: 0; border: 0; border-radius: 0; background: none; }
#configure .engraving-kit .mark-settings { grid-template-columns: minmax(0, 1fr); }
#configure .cfg-panel .drawer-editor { border-top: 0; padding-top: 0; }
#configure .cfg-panel > .box-wood-samples { margin: 0; }
#configure .dimension-deck { max-width: none; grid-template-columns: minmax(0, 1fr); gap: 6px; }
#configure .size-card { grid-template-columns: 3.4rem minmax(0, 1fr) 4.4rem; align-items: center; gap: 2px 8px; padding: 6px 9px; }
#configure .size-card :is(.read-size, .size-slider) { grid-row: 1; width: 100%; margin: 0; }
#configure .size-card .size-slider { grid-column: 2; }
#configure .size-card .read-size { grid-column: 3; }
#configure .size-card .size-caption { grid-column: 2 / 4; }
:lang(en) #configure .cfg-panel .row { grid-template-columns: 6.3rem minmax(0, 1fr) 58px; }
#configure .cfg-note { margin: 6px 0 0; color: #6a6253; font-size: .82rem; }
#configure .coaster-fit .coaster-toggle { display: flex; align-items: center; gap: 8px; }
#configure .cfg-next {
  display: block;
  width: 100%;
  min-height: 42px;
  margin: 15px 0 0;
  padding: 7px 14px;
  border: 1px solid #b9c2b0;
  border-radius: 6px;
  background: #fffdf8;
  color: #2d4b3b;
  font: 650 .88rem/1.25 var(--sans);
  text-align: center;
  cursor: pointer;
}
#configure .cfg-next:hover { background: #eef0e6; }
#configure .tray-cup-library:not([hidden]) { max-height: none; overflow: visible; }

/* ---- Review bar ---- */

#configure > .cfg-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px 20px;
  min-height: var(--cfg-bar);
  margin-inline: calc(-1 * var(--cfg-gap));
  padding: 7px var(--cfg-gap) calc(7px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #d8cdb9;
  background: #fffdf8;
  box-shadow: 0 -5px 18px #2a221c12;
}
.cfg-sum { display: grid; flex: 1 1 auto; gap: 2px; min-width: 0; font: 400 .84rem/1.35 var(--sans); color: #6a6253; }
.cfg-sum > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cfg-sum strong { color: #2b2b22; font-size: .95rem; font-weight: 650; }
.cfg-problem:empty, .cfg-sum:has(.cfg-problem:not(:empty)) .cfg-quote { display: none; }
.cfg-sum .cfg-problem { color: #93381f; font-weight: 650; white-space: normal; }
.cfg-more { flex: none; color: #2d4b3b; font: 600 .9rem/1.3 var(--sans); text-underline-offset: 4px; }
.cfg-review {
  flex: none;
  min-height: 46px;
  padding: 8px 24px;
  border: 0;
  border-radius: 6px;
  background: #344536;
  color: #fffdf8;
  font: 680 1rem/1.2 var(--sans);
  cursor: pointer;
}
.cfg-review:hover { background: #28372b; }

.cfg-credits { padding-block: 26px 40px; font-size: .86rem; color: #6a6253; }
.cfg-credits .ref-sources { margin: 0; }

/* ---- Narrow windows: the model stays on top while the steps scroll under it. ---- */

@media (max-width: 899px) {
  :root { --cfg-header: 54px; --cfg-gap: 12px; --cfg-stage: clamp(200px, 36svh, 430px); }

  body > main > #configure { padding: 0; }
  /* The name is already in the header. */
  #configure > .cfg-head { min-height: 0; padding: 4px var(--cfg-gap); }
  #configure .cfg-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #configure > .cfg-head .design-bar { flex: 1 1 auto; gap: 0 12px; margin: 0; }
  #configure > .cfg-head .design-status { flex: 1 0 100%; order: 1; padding-bottom: 5px; }
  #configure > .cfg-head .design-status[data-quiet] { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); }
  #configure > .cfg-head .design-actions { flex: 0 1 auto; margin-left: auto; flex-wrap: nowrap; gap: 0 14px; overflow-x: auto; scrollbar-width: none; }
  #configure > .cfg-head .design-action { flex: none; min-height: 36px; }

  #configure .cfg-workspace { display: flex; flex-direction: column; height: auto; border-inline: 0; border-radius: 0; overflow: visible; }
  #configure .cfg-view {
    position: sticky;
    top: var(--cfg-header);
    z-index: 6;
    order: -1;
    gap: 6px;
    padding: 7px 8px 8px;
    border-bottom: 1px solid #d8cdb9;
    box-shadow: 0 6px 14px #2a221c14;
  }
  #configure .cfg-side:not([hidden]) { max-height: none; border-right: 0; overflow: visible; }
  #configure :is(.box-scene, .coaster-scene, #tray-scene, .model, .organizer-view > .model-area, .cfg-canvas-stage) { flex: none; height: var(--cfg-stage); aspect-ratio: auto; }
  #configure :is(.jewelry-stage, .tray-stage) { flex: none; min-height: 0; }
  #configure .cfg-view > figcaption, #configure .cfg-view > .model-help { display: none; }
  /* Choosing jewelry needs the whole window. */
  #configure .cfg-view:has(.jewelry-library:not([hidden])) { position: relative; top: auto; }

  #configure .cfg-tools, #configure .cfg-tools > div { flex-wrap: nowrap; }
  #configure .cfg-tools { overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
  #configure .cfg-tools > div { flex: none; }
  #configure .cfg-tools button { flex: none; min-height: 38px; }
  #configure .cfg-tools > div:nth-child(2), #configure .cfg-tools > button[aria-controls] { margin-left: 0; }
  #configure .cfg-tools #view-caption { display: none; }
  /* The steps are always below the model here. */
  #configure .cfg-tools button.preview-expand[aria-controls] { display: none; }
  #configure [data-preview-immersive] .cfg-tools button.preview-expand[aria-controls] { display: inline-flex; }

  #configure .cfg-toggle { min-height: 52px; padding-inline: 14px; }
  #configure .cfg-panel:not([hidden]) { padding: 13px 14px 18px; font-size: .92rem; }
  #configure > .cfg-bar { margin-inline: 0; }
  /* Small controls from the pages' compact layouts get a comfortable touch size. */
  #configure .cfg-panel :is(select, input[type=number], input[type=text], textarea) { min-height: 42px; font-size: 1rem; }
  #configure .cfg-panel input[type=range] { min-height: 34px; }
  #configure .cfg-panel :is(.btn, .tray-control, .model-tool, .filter) { min-height: 40px; }
}

@media (max-width: 599px) {
  .cfg-more { display: none; }
  .cfg-brand .brand-art { width: 34px; }
  .cfg-brand img { height: 34px; object-fit: contain; }
  .cfg-top { gap: 8px 10px; font-size: .88rem; }
  .cfg-links { gap: 14px; }
  .cfg-switch summary { max-width: 46vw; padding-inline: 10px; }
  .cfg-switch nav { position: fixed; top: calc(var(--cfg-header) + 4px); left: 12px; right: 12px; }
  #configure > .cfg-bar { gap: 8px 12px; }
  .cfg-review { padding-inline: 17px; }
  .cfg-quote { display: none; }
  .cfg-sum strong { display: -webkit-box; font-size: .84rem; line-height: 1.3; white-space: normal; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
}

/* A phone on its side has no room for a fixed model. */
@media (max-width: 899px) and (max-height: 520px) {
  :root { --cfg-stage: 62svh; }
  #configure .cfg-view { position: relative; top: auto; }
}
