:root {
  --bg: #f4f2ed;
  --panel: #fffdf8;
  --ink: #23271f;
  --muted: #6b6f64;
  --line: #e2ddd1;
  --accent: #b4532a;
  --accent-ink: #fff;
  --moss: #596b5b;
  --field: #f1eee6;
  --viewer: #e9e6de;
  --danger: #b42318;
  --clay: #c98a6a;
  --clay-deep: #8f4f33;
  --model: #dcd6c8;
  --relief-3d: #c9774f;
  --cutter-3d: #7d8f7f;
  --radius: 12px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161815;
    --panel: #1e211d;
    --ink: #ecebe5;
    --muted: #9da196;
    --line: #30342e;
    --accent: #e07a4f;
    --accent-ink: #1a1a1a;
    --moss: #8fa58f;
    --field: #262a25;
    --viewer: #121411;
    --danger: #ff8a7a;
    --clay: #a9705a;
    --clay-deep: #5e3324;
    --model: #b9b3a4;
    --relief-3d: #c26a45;
    --cutter-3d: #6f856f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; min-height: 100vh; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; }
svg { display: block; }
.plate { fill: var(--moss); }
.relief { fill: var(--accent); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 28px; height: 28px; }
.brand .name { font-weight: 700; font-size: 19px; letter-spacing: -0.01em; }
.brand .tag { color: var(--muted); font-size: 14px; }

.layout { flex: 1; display: grid; grid-template-columns: 360px 1fr; gap: 20px; padding: 20px 24px; min-height: 0; }
.panel { display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 861px) {
  body { height: 100vh; }
  .panel { overflow-y: auto; min-height: 0; margin: -4px -8px -4px -4px; padding: 4px 8px 0 4px; scrollbar-width: thin; }
}
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }

.drop { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 20px 12px; border: 1.5px dashed var(--line); border-radius: 10px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--field); }
.drop svg { width: 26px; height: 26px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 4px; }
.drop small { color: var(--muted); }
.source-info { display: grid; gap: 2px; }
.source-name { font-weight: 650; font-size: 16px; overflow-wrap: anywhere; }
.source-meta { color: var(--muted); font-size: 14px; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; justify-self: start; }

.field { display: grid; gap: 6px; margin-top: 12px; }
.card > .field:first-of-type, .card > div:first-of-type > .field:first-child { margin-top: 0; }
.label { font-weight: 550; }
.field .help { color: var(--muted); font-size: 13px; }
.slide { display: flex; align-items: center; gap: 12px; }
.slide .range { flex: 1; min-width: 0; display: flex; align-items: center; }
.touch .slide .range { touch-action: pan-y; padding: 8px 0; }
.touch .slide input[type=range] { pointer-events: none; }
.val { flex: none; display: flex; align-items: baseline; gap: 4px; color: var(--muted); font-size: 13px; }
.val input { width: 64px; text-align: right; font: inherit; font-size: 14px; color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 0; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--field); border-radius: 8px; padding: 3px; gap: 3px; }
.seg button { white-space: nowrap; border: 0; background: transparent; padding: 6px 4px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 14px; }
.seg button[aria-checked=true] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .15); font-weight: 600; }

.check { display: flex; align-items: center; gap: 8px; font-weight: 550; cursor: pointer; }
.check input { flex: none; width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.check.spaced { margin-top: 14px; }
#cutter-body, #corner-controls { margin-top: 12px; }
#corner-controls:empty { display: none; }
.area-note { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.area-note .link { font-size: 13px; }

.advanced summary { cursor: pointer; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.advanced[open] summary { margin-bottom: 12px; }

.actions { display: grid; gap: 8px; position: sticky; bottom: 0; background: var(--bg); padding: 10px 0 12px; margin-top: auto; box-shadow: 0 -10px 10px -6px var(--bg); }
.status { color: var(--muted); font-size: 13px; min-height: 1.45em; }
.progress .bar { height: 6px; background: var(--field); border-radius: 3px; overflow: hidden; }
.progress .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.error { color: var(--danger); font-size: 14px; background: color-mix(in srgb, var(--danger) 10%, transparent); padding: 10px 12px; border-radius: 8px; }

.stage { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.viewer { position: relative; flex: 1; min-height: 420px; background: var(--viewer); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.viewer > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; color: var(--muted); text-align: center; padding: 16px; pointer-events: none; }
.empty svg { width: 72px; height: 72px; opacity: .6; }
.viewer.has-source .empty { display: none; }
.viewer-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.viewer-tools button { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.viewer-tools svg { width: 18px; height: 18px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.legend { position: absolute; right: 12px; bottom: 10px; font-size: 12px; color: var(--muted); text-align: right; }
.viewer:not(.has-model) .viewer-tools, .viewer:not(.has-model) .legend { display: none; }
.no-gl { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); padding: 16px; }

/* the 2D design, as it will read in the clay, in a corner of the viewer */
.inset { position: absolute; left: 12px; top: 12px; margin: 0; padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 1px 4px rgb(0 0 0 / .12); }
.inset canvas { display: block; width: auto; height: auto; max-width: 200px; max-height: 200px; border-radius: 4px; }
.inset figcaption { margin-top: 6px; font-size: 12px; color: var(--muted); text-align: center; }
.viewer:not(.has-model) .inset { left: 50%; top: 50%; transform: translate(-50%, -50%); }
.viewer:not(.has-model) .inset canvas { max-width: min(420px, 70vw); max-height: 340px; }

.result { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stats { display: flex; flex-wrap: wrap; gap: 6px 28px; margin: 0; }
.stats div { display: grid; }
.stats dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.primary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 12px 18px; font-weight: 650; font-size: 16px; cursor: pointer; transition: filter .15s, opacity .15s; }
.primary:hover:not(:disabled) { filter: brightness(1.07); }
.primary:disabled { opacity: .45; cursor: default; }
.primary svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.download span { font-weight: 400; opacity: .8; font-size: 14px; }
.notes { grid-column: 1 / -1; margin: 0; padding-left: 18px; color: var(--danger); font-size: 13px; }

.foot { padding: 12px 24px 20px; color: var(--muted); font-size: 13px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .viewer { min-height: 320px; aspect-ratio: 4 / 3; flex: none; }
  .actions { position: static; }
  .brand .tag { display: none; }
  .topbar, .foot { padding-left: 16px; padding-right: 16px; }
  .inset { left: 8px; top: 8px; padding: 5px; }
  .inset canvas { max-width: 84px; max-height: 84px; }
  .viewer.has-model .inset figcaption { display: none; }
  .legend { display: none; }
  .result { grid-template-columns: 1fr; }
}

.reset { display: inline-flex; align-items: center; gap: 6px; flex: none; border: 1px solid var(--line); background: var(--field); border-radius: 8px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.reset:hover { border-color: var(--accent); }
.top-actions { display: flex; gap: 8px; flex: none; }
.reset.done { border-color: var(--accent); color: var(--accent); }
@media (max-width: 440px) { .reset .wide { display: none; } }
.reset svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.viewer-status { display: none; }

/* phones: the viewer sticks to the bottom of the screen, so changes show while the settings scroll above it */
@media (max-width: 860px) {
  .stage { display: contents; }
  .viewer { position: sticky; bottom: 0; z-index: 10; height: min(40svh, 80vw); min-height: 220px; aspect-ratio: auto;
            box-shadow: 0 -6px 16px rgb(0 0 0 / .18); }
  .viewer-status { display: block; position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); max-width: calc(100% - 24px);
                   background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 12px;
                   color: var(--muted); text-align: center; box-shadow: 0 1px 4px rgb(0 0 0 / .12); }
  .viewer-status[hidden] { display: none; }
  .viewer-status.bad { color: var(--danger); }
  .viewer:not(.has-source) { position: relative; height: auto; min-height: 180px; box-shadow: none; }
  .viewer:not(.has-model) .inset canvas { max-width: 70vw; max-height: calc(min(40svh, 80vw) - 70px); }
  .viewer-tools button { width: 30px; height: 30px; }
  .reset { padding: 5px 10px; font-size: 13px; }
}
