:root {
  /* colour */
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --text: #1c1b19;
  --muted: #6a6862;
  --border: #e2e0db;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --accent-soft: #e6ecfb;
  --ok-bg: #e7f4ec; --ok-text: #1d5c37;
  --warn-bg: #fdf3dc; --warn-text: #6b4a05;
  --err-bg: #fbe9e7; --err-text: #8a2318;
  /* spacing */
  --s-0: 0;
  --s-1: 2px;
  --s-2: 4px;
  --s-3: 6px;
  --s-4: 8px;
  --s-5: 10px;
  --s-6: 12px;
  --s-7: 16px;
  --s-8: 20px;
  --s-9: 24px;
  --s-10: 28px;
  --s-11: 40px;
  --s-12: 64px;
  /* radius, borders, focus */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 12px;
  --r-pill: 999px;
  --bw: 1px;
  --bw-2: 2px;
  --focus-offset: 2px;
  /* type */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-xs: 0.8rem;
  --fs-sm: 0.875rem;
  --fs-md: 0.95rem;
  --fs-base: 16px;
  --fs-lg: 1.1rem;
  --fs-xl: 1.3rem;
  --fs-2xl: 1.6rem;
  --fs-3xl: 2.2rem;
  --lh: 1.5;
  --fw-semibold: 600;
  --fw-bold: 700;
  /* layout */
  --w-page: 1100px;
  --w-narrow: 420px;
  --w-summary: 320px;
  --w-downloads: 340px;
  --w-thumb-min: 140px;
  --w-stat-min: 200px;
  --h-viewer: 480px;
  --h-viewer-sm: 360px;
  --h-progress: 10px;
  --control: 18px;
  --sticky-top: 16px;
  --disabled-opacity: 0.55;
  --dur: 0.4s;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514; --surface: #1f1e1c; --surface-2: #2a2926; --text: #ecebe7; --muted: #a3a09a;
    --border: #383632; --accent: #7d9cf0; --accent-text: #10131c; --accent-soft: #232c44;
    --ok-bg: #173323; --ok-text: #a6dfba; --warn-bg: #3a2f12; --warn-text: #f0d58c;
    --err-bg: #3d1b17; --err-text: #f4b3aa;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: var(--s-0); background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs-base); line-height: var(--lh); }
a { color: var(--accent); }
h1 { font-size: var(--fs-2xl); margin: var(--s-0) var(--s-0) var(--s-7); }
h2 { font-size: var(--fs-lg); margin: var(--s-0); }
.container { max-width: var(--w-page); margin: var(--s-0) auto; padding: var(--s-9) var(--s-7) var(--s-12); }
.topbar { display: flex; flex-wrap: wrap; gap: var(--s-6); align-items: center; justify-content: space-between; padding: var(--s-6) var(--s-7); background: var(--surface); border-bottom: var(--bw) solid var(--border); }
.topbar nav { display: flex; flex-wrap: wrap; gap: var(--s-7); align-items: center; }
.topbar nav a:not(.btn) { color: var(--text); text-decoration: none; }
.brand { font-weight: var(--fw-bold); color: var(--text); text-decoration: none; }
.card { background: var(--surface); border: var(--bw) solid var(--border); border-radius: var(--r-xl); padding: var(--s-8); }
.narrow { max-width: var(--w-narrow); margin: var(--s-11) auto; }
.stack { display: flex; flex-direction: column; gap: var(--s-7); }
.row { display: flex; flex-wrap: wrap; gap: var(--s-7); align-items: end; }
.inline { display: inline; margin: var(--s-0); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.page-head { display: flex; flex-wrap: wrap; gap: var(--s-6); align-items: center; justify-content: space-between; margin-bottom: var(--s-7); }
.page-head h1 { margin: var(--s-0); }

label { display: flex; flex-direction: column; gap: var(--s-3); font-size: var(--fs-md); }
input[type=text], input:not([type]), input[type=password], input[type=number] {
  font: inherit; padding: var(--s-5) var(--s-6); border: var(--bw) solid var(--border); border-radius: var(--r-md); background: var(--surface); color: var(--text);
}
input:focus-visible, button:focus-visible, a:focus-visible, .dropzone:focus-within { outline: var(--bw-2) solid var(--accent); outline-offset: var(--focus-offset); }
fieldset { border: var(--s-0); padding: var(--s-0); margin: var(--s-0); display: flex; flex-direction: column; gap: var(--s-4); }
legend { font-weight: var(--fw-semibold); margin-bottom: var(--s-2); }
.choice { flex-direction: row; align-items: center; gap: var(--s-5); cursor: pointer; }
.choice input { width: var(--control); height: var(--control); accent-color: var(--accent); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-4); font: inherit; font-weight: var(--fw-semibold); padding: var(--s-5) var(--s-7); border-radius: var(--r-md); border: var(--bw) solid transparent; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:disabled { opacity: var(--disabled-opacity); cursor: progress; }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-sm { padding: var(--s-3) var(--s-6); font-size: var(--fs-sm); }
.btn-block { width: 100%; justify-content: space-between; }
.btn-primary.btn-block { justify-content: center; }
.link { background: none; border: var(--s-0); padding: var(--s-0); font: inherit; color: var(--text); cursor: pointer; }

.alert { margin: var(--s-0); padding: var(--s-6) var(--s-7); border-radius: var(--r-md); }
.alert-ok { background: var(--ok-bg); color: var(--ok-text); }
.alert-warn { background: var(--warn-bg); color: var(--warn-text); }
.alert-error { background: var(--err-bg); color: var(--err-text); }

.badge { display: inline-block; padding: var(--s-1) var(--s-5); border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: var(--fw-semibold); background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-ready { background: var(--ok-bg); color: var(--ok-text); }
.badge-generating, .badge-paid { background: var(--warn-bg); color: var(--warn-text); }
.badge-failed { background: var(--err-bg); color: var(--err-text); }

.order-list { list-style: none; margin: var(--s-0); padding: var(--s-0); display: flex; flex-direction: column; gap: var(--s-4); }
.order-row { display: grid; grid-template-columns: 1fr auto; gap: var(--s-2) var(--s-6); color: var(--text); text-decoration: none; }
.order-row .muted { grid-column: 1 / -1; font-size: var(--fs-sm); }
.order-name { font-weight: var(--fw-semibold); }
.empty { text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--s-7); }

.order-grid { display: grid; grid-template-columns: 1fr var(--w-summary); gap: var(--s-8); align-items: start; }
.summary { position: sticky; top: var(--sticky-top); }
.price { font-size: var(--fs-3xl); font-weight: var(--fw-bold); margin: var(--s-0); }
.dropzone { position: relative; border: var(--bw-2) dashed var(--border); border-radius: var(--r-xl); padding: var(--s-10) var(--s-7); text-align: center; cursor: pointer; background: var(--surface-2); }
.dropzone.drag { border-color: var(--accent); }
.dropzone input { position: absolute; opacity: 0; width: var(--s-1); height: var(--s-1); }
.previews { list-style: none; margin: var(--s-0); padding: var(--s-0); display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--w-thumb-min), 1fr)); gap: var(--s-6); }
.previews li { border: var(--bw) solid var(--border); border-radius: var(--r-lg); padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); font-size: var(--fs-sm); }
.previews img, .previews .thumb-ph { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--r-sm); background: var(--surface-2); }
.previews .thumb-ph { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.previews li.front { border-color: var(--accent); }
.tips ul { margin: var(--s-4) var(--s-0) var(--s-0); padding-left: var(--s-8); }
.segmented { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }
.seg-label { width: 100%; font-size: var(--fs-md); }
.segmented label { position: relative; flex-direction: row; }
.segmented input { position: absolute; opacity: 0; }
.segmented label span { padding: var(--s-3) var(--s-6); border: var(--bw) solid var(--border); border-radius: var(--r-md); cursor: pointer; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.segmented input:focus-visible + span { outline: var(--bw-2) solid var(--accent); outline-offset: var(--focus-offset); }

.progress { height: var(--h-progress); background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width var(--dur) ease; }
.result-grid { display: grid; grid-template-columns: 1fr var(--w-downloads); gap: var(--s-8); align-items: start; }
model-viewer { width: 100%; height: var(--h-viewer); background: var(--surface-2); border-radius: var(--r-lg); }
.preview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
.preview-grid img { width: 100%; border-radius: var(--r-md); }
.option-list { display: flex; flex-direction: column; gap: var(--s-4); }
.option-card { display: flex; flex-direction: row; align-items: center; gap: var(--s-5); padding: var(--s-5) var(--s-6); border: var(--bw) solid var(--border); border-radius: var(--r-md); background: var(--surface); cursor: pointer; }
.option-card:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); }
.option-card input { width: var(--control); height: var(--control); flex: none; accent-color: var(--accent); }
.option-card label, .option-text { flex: 1; display: flex; flex-direction: column; gap: var(--s-0); cursor: pointer; font-weight: var(--fw-semibold); }
.option-card .btn { flex: none; }
.params { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-3) var(--s-8); margin: var(--s-6) var(--s-0) var(--s-0); }
.params dt { color: var(--muted); }
.params dd { margin: var(--s-0); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(var(--w-stat-min), 1fr)); gap: var(--s-6); margin-bottom: var(--s-8); }
.stat { display: flex; flex-direction: column; gap: var(--s-2); }
.stat strong { font-size: var(--fs-xl); }
section + section { margin-top: var(--s-8); }
.stack > section + section { margin-top: var(--s-0); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th, td { text-align: left; padding: var(--s-4) var(--s-5); border-bottom: var(--bw) solid var(--border); white-space: nowrap; }
.actions { display: flex; gap: var(--s-3); }

@media (max-width: 820px) { /* ds-allow-hardcode: media queries cannot read custom properties */
  .order-grid, .result-grid { grid-template-columns: 1fr; }
  .summary { position: static; }
  model-viewer { height: var(--h-viewer-sm); }
}
