:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #f1ede6;
  --text: #1f1d1a;
  --muted: #6d665c;
  --line: #e2dcd2;
  --accent: #e07a1f;
  --accent-ink: #ffffff;
  --danger: #c9363b;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412;
    --surface: #201d1a;
    --surface-2: #2a2622;
    --text: #f2ede6;
    --muted: #a59d91;
    --line: #38332d;
    --accent: #f08a24;
    --accent-ink: #1a1208;
    --danger: #ff6b70;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h2 { font-size: 15px; margin: 0 0 10px; font-weight: 650; }

.topbar {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand { font-weight: 750; font-size: 18px; }
.tagline { margin: 0; color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 20px;
  padding: 20px 24px 40px;
  max-width: 1500px;
  margin: 0 auto;
}

.controls { display: flex; flex-direction: column; gap: 14px; }
.views { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.panel, .card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }

.hint, .muted { color: var(--muted); font-size: 13px; }
.hint { margin: 8px 0; }

button, .upload span, .order {
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
button:hover, .upload span:hover { border-color: var(--accent); }
button.primary, .order { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.small { padding: 3px 8px; font-size: 12px; }

.upload input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.upload span { display: block; text-align: center; padding: 12px; border-style: dashed; }
.upload input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chips button { padding: 5px 10px; }

.text-row { display: flex; gap: 6px; margin-bottom: 12px; }
.text-row input { flex: 1; min-width: 0; }

input[type="text"], input[type="number"], select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
}

.mask-row { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: start; margin-bottom: 6px; }
#mask-thumb { width: 96px; height: auto; max-height: 120px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.mask-controls { display: flex; flex-direction: column; gap: 6px; }

.field {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 64px 24px;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  font-size: 13px;
}
.field.compact { grid-template-columns: 84px minmax(0, 1fr) auto; margin: 0; }
.field select { grid-column: 2 / -1; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.field input[type="number"] { width: 100%; padding: 4px 6px; }
.field-label { color: var(--muted); }
.unit { color: var(--muted); font-size: 12px; }
.check { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented label { padding: 7px 14px; font-size: 14px; cursor: pointer; background: var(--surface-2); }
.segmented label:has(input:checked) { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.segmented.small label { padding: 4px 10px; font-size: 13px; }

details summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 8px; }

.wall-wrap { display: flex; justify-content: center; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
#wall { display: block; max-width: 100%; height: auto; touch-action: none; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; padding: 0; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); }
.sw.dark { background: rgb(43, 47, 58); }
.sw.missing { background: rgb(229, 72, 77); }
.sw.extra { background: rgb(124, 138, 165); }
.sw.box { background: rgb(240, 138, 36); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.stat span { font-size: 12px; color: var(--muted); }
.stat strong { font-size: 18px; font-variant-numeric: tabular-nums; }

.warnings { margin: 0; padding: 0 0 0 18px; color: var(--danger); font-size: 13px; }
.warnings:empty { display: none; }

.three { height: 420px; border-radius: 8px; overflow: hidden; background: #1b1917; color: #ddd; display: grid; place-items: center; }
.three canvas { width: 100% !important; height: 100% !important; display: block; }

.downloads { display: flex; flex-wrap: wrap; gap: 8px; }
.order { display: inline-block; margin-top: 6px; text-decoration: none; }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.panels figure { margin: 0; }
.panels canvas { width: 100%; height: auto; image-rendering: pixelated; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.panels figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px 32px; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 4px 12px; }
  .three { height: 320px; }
}
