:root {
  color-scheme: light;
  --page: #f5f5f7;
  --surface: #fff;
  --ink: #1d1d1f;
  --secondary: #626268;
  --line: #ebebee;
  --control: #f1f1f4;
  --accent: #0071e3;
  --radius: 21px;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--page);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, p { margin: 0; }
button, input, select { color: inherit; font: inherit; }
button, select, input[type=range] { cursor: pointer; }
button:disabled, a[aria-disabled=true] { cursor: wait; opacity: .6; }
:where(button, a, input, select):focus-visible, .toggle:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  display: inline-block;
  flex: none;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.shell { width: min(1232px, calc(100% - 72px)); margin-inline: auto; }
.header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-inner, .brand, .actions, .preview-header, .toggle, .preview-foot, .fit {
  display: flex;
  align-items: center;
}
.header-inner { justify-content: space-between; min-height: 56px; gap: 10px; }
.brand { gap: 8px; font-weight: 650; font-size: 14px; line-height: 1.3; white-space: nowrap; }
.brand-icon { display: grid; flex: none; place-items: center; width: 27px; height: 27px; border-radius: 8px; background: var(--ink); color: #fff; }
.brand-icon .icon { width: 16px; height: 16px; fill: currentColor; stroke-width: 1; }
.actions { gap: 8px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 35px;
  padding: 0 13px;
  border: 0;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.button .icon { width: 15px; height: 15px; }
.quiet { color: var(--secondary); background: transparent; }
.quiet:hover { color: var(--ink); background: var(--control); }
.secondary { color: var(--ink); background: var(--control); }
.secondary:hover { background: #e7e7ec; }
.primary { color: #fff; background: var(--accent); }
.primary:hover { background: #0064ca; }

main.shell { padding-block: clamp(14px, 2vw, 24px) 28px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 350px); align-items: start; gap: 20px; }
.preview, .inspector { min-width: 0; border-radius: var(--radius); background: var(--surface); box-shadow: 0 0 0 1px #1d1d1f0a; }
.preview { padding: clamp(14px, 1.7vw, 22px); }
.preview-header { justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 14px; }
.preview-header h2 { font-size: 18px; font-weight: 650; letter-spacing: -.02em; }
.toggle {
  position: relative;
  gap: 7px;
  min-height: 33px;
  padding-inline: 3px;
  border-radius: 6px;
  color: var(--secondary);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}
.toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.track { flex: none; width: 31px; height: 18px; border-radius: 20px; padding: 2px; background: #babac1; }
.track::before { display: block; content: ""; width: 14px; height: 14px; border-radius: 50%; background: #fff; }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::before { transform: translateX(13px); }
.stage {
  position: relative;
  overflow: hidden;
  height: clamp(340px, 37vw, 492px);
  border-radius: 14px;
  background: #eeeff1;
}
#preview { display: block; width: 100%; height: 100%; }
.placement {
  position: absolute;
  z-index: 1;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: transparent;
  transform: translate(-50%, -50%);
  touch-action: none;
  cursor: grab;
}
.placement:active { cursor: grabbing; }
.placement:focus-visible { outline-color: var(--accent); outline-offset: 4px; }
.measurements { display: grid; grid-template-columns: 1fr 1fr .72fr; margin-top: 15px; border-radius: 11px; background: var(--page); }
.metric { min-width: 0; padding: 11px 13px; }
.metric > span { display: block; color: var(--secondary); font-size: 12px; }
.metric strong { display: block; margin-top: 3px; font-size: clamp(15px, 1.75vw, 23px); font-weight: 650; line-height: 1.15; letter-spacing: -.028em; font-variant-numeric: tabular-nums; }
.metric small { color: var(--secondary); font-size: 11px; font-weight: 500; letter-spacing: 0; white-space: nowrap; }
.preview-foot { justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; min-height: 24px; margin-top: 9px; }
.fit { gap: 5px; color: #28764a; font-size: 12px; }
.fit .icon { width: 15px; height: 15px; }
.fit.warning { color: #a33c28; }
.fit.empty, .preview-note { color: var(--secondary); }
.preview-note { font-size: 11px; }
#center, .image-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
}
#center { padding-inline: 5px; }
#center:hover, .image-action:hover { color: #0059b2; }

.controls { min-width: 0; }
.panel { padding: 18px 19px; }
.panel + .panel { border-top: 1px solid var(--line); }
.panel h2 { margin-bottom: 12px; font-size: 16px; font-weight: 650; }
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
}
.field-note { color: var(--secondary); font-size: 11px; font-weight: 400; }
input[type=text], .unit { border: 1px solid transparent; border-radius: 8px; background: var(--control); }
input[type=text] { width: 100%; min-height: 37px; padding: 7px 10px; margin-bottom: 12px; }
input[type=text]::placeholder { color: var(--secondary); }
.choices { display: grid; gap: 2px; padding: 3px; margin-bottom: 12px; border-radius: 9px; background: var(--control); }
.styles { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.motifs, .shapes { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.choices button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  min-height: 31px;
  padding: 3px 2px;
  border: 0;
  border-radius: 6px;
  color: var(--secondary);
  background: transparent;
  white-space: nowrap;
  font-size: 12px;
}
.choices button:hover { color: var(--ink); background: #ffffff8a; }
.choices button[aria-pressed=true] { color: var(--ink); background: var(--surface); box-shadow: 0 1px 2px #1d1d1f15; font-weight: 650; }
.styles button { min-height: 36px; }
.styles button:focus-visible { outline-offset: -2px; }
.choices .icon { width: 15px; height: 15px; }
.size-label { margin-bottom: 1px; }
.unit { display: flex; align-items: center; gap: 5px; min-width: 0; min-height: 34px; padding: 0 7px; color: var(--secondary); font-size: 11px; }
.unit:focus-within { border-color: var(--accent); }
.unit label { flex: none; }
.unit input {
  appearance: textfield;
  width: 100%;
  min-width: 0;
  padding: 3px 0;
  border: 0;
  outline: 0;
  background: none;
  color: var(--ink);
  font-size: 13px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.unit input::-webkit-inner-spin-button, .unit input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.height-unit { width: 106px; }
.unit select {
  appearance: none;
  min-width: 0;
  min-height: 30px;
  padding: 2px 12px 2px 3px;
  border: 0;
  border-radius: 4px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 5'%3E%3Cpath d='m1 1 3 3 3-3' fill='none' stroke='%23626268' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 2px center / 8px 5px no-repeat;
  font-size: 12px;
}
.unit select:hover { background-color: #e7e7ec; }
.length-unit { flex: none; }
.diameter-unit { position: relative; padding: 0; }
.diameter-unit select {
  width: 100%;
  padding-inline: 11px 43px;
  background-position: right 10px center;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.diameter-unit span { position: absolute; inset-inline-end: 24px; pointer-events: none; }
input[type=range] { display: block; width: 100%; height: 23px; margin: 3px 0 0; accent-color: var(--accent); }
.dimension-inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.dimension-inputs.single { grid-template-columns: minmax(0, 1fr); }
.swatch-row { margin-bottom: 10px; }
.swatch-row .field { justify-content: flex-start; }
.swatches { display: flex; align-items: center; gap: 5px; }
.swatches button { width: 30px; height: 30px; padding: 3px; border: 1px solid transparent; border-radius: 50%; background: transparent; }
.swatches button::after { display: block; content: ""; width: 100%; height: 100%; border-radius: 50%; background: var(--swatch); box-shadow: inset 0 0 0 1px #1d1d1f17; }
.swatches button:hover { border-color: #bdbdc5; }
.swatches button[aria-pressed=true] { border-color: var(--accent); }
.water-field, .water-controls { display: grid; grid-template-columns: minmax(0, 1fr) 106px; align-items: center; gap: 8px; }
.water-field { margin: 10px 0 3px; }
.image-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 12px; margin-bottom: 10px; }
.image-controls > .field-note { flex-basis: 100%; overflow-wrap: anywhere; }
.image-action { padding: 0; cursor: pointer; }

dialog {
  width: min(680px, calc(100% - 28px));
  max-height: calc(100% - 28px);
  padding: 18px;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 80px #1d1d1f38;
}
dialog::backdrop { background: #1d1d1f70; }
dialog h2 { margin-bottom: 12px; font-size: 19px; }
dialog img { display: block; width: 100%; height: auto; max-height: 68dvh; object-fit: contain; border-radius: 10px; background: var(--page); }
.export-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 13px; }
#engraving-dialog { width: min(400px, calc(100% - 28px)); }
#engraving-note { color: var(--secondary); font-size: 13px; }
.engraving-details { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); margin: 13px 0 0; border-radius: 10px; background: var(--page); }
.engraving-details > div { padding: 9px 10px; }
.engraving-details dt { color: var(--secondary); font-size: 12px; }
.engraving-details dd { margin: 2px 0 0; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
#engraving-status:not(:empty) { margin-top: 10px; color: var(--secondary); font-size: 12px; }
#engraving-status.warning { color: #a33c28; }

@media (min-width: 841px) and (min-height: 740px) {
  .preview { position: sticky; top: 16px; }
}
@media (max-width: 1050px) {
  .shell { width: calc(100% - 48px); }
  .workspace { gap: 14px; }
}
@media (max-width: 840px) {
  .shell { width: calc(100% - 34px); }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .stage { height: clamp(236px, 63vw, 480px); }
  .metric strong { font-size: clamp(16px, 3.15vw, 22px); }
}
@media (max-width: 520px) {
  .shell { width: calc(100% - 28px); }
  .header-inner { min-height: 52px; flex-wrap: wrap; gap: 4px 8px; padding-block: 5px; }
  .brand { font-size: 13px; }
  .actions { gap: 3px; margin-inline-start: auto; }
  .actions .quiet span { display: none; }
  .actions .quiet { width: 33px; padding: 0; }
  .actions .button { min-height: 34px; font-size: 12px; }
  #engraving, #download { padding-inline: 8px; }
  #download .icon { display: none; }
  .preview, .inspector { border-radius: 16px; }
  .preview { padding: 11px; }
  .preview-header { margin-bottom: 9px; }
  .preview-header h2 { font-size: 16px; }
  .stage { border-radius: 10px; }
  .measurements { margin-top: 10px; }
  .metric { padding: 9px 7px; }
  .metric > span { font-size: 11px; }
  .metric small { font-size: 10px; }
  .panel { padding: 17px 15px; }
  input[type=text], .unit input, .unit select { font-size: 16px; }
}
@media (max-width: 355px) {
  .shell { width: calc(100% - 20px); }
  .metric strong { font-size: 15px; }
  .motifs button, .shapes button { gap: 3px; font-size: 11px; }
}
@media (forced-colors: active) {
  .unit select { appearance: auto; padding-inline: 2px; background-image: none; }
}
