:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #1d1f23;
  --muted: #6b6f78;
  --line: #e2dfd8;
  --soft: #f0eee9;
  --accent: #2f5fd0;
  --accent-ink: #ffffff;
  --good: #1f8a4c;
  --warn: #b7791f;
  --bad: #c0392b;
  --stage: #e9e6e0;
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171b; --panel: #1d2026; --ink: #e8e9ec; --muted: #9aa0ab; --line: #2d3139;
    --soft: #252931; --accent: #6d95ff; --accent-ink: #0d1430; --stage: #101215;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171b; --panel: #1d2026; --ink: #e8e9ec; --muted: #9aa0ab; --line: #2d3139;
  --soft: #252931; --accent: #6d95ff; --accent-ink: #0d1430; --stage: #101215;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }

.bar { height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .01em; }
.logo { width: 22px; height: 22px; border-radius: 5px; background:
  radial-gradient(circle at 25% 25%, var(--accent) 22%, transparent 23%),
  radial-gradient(circle at 75% 75%, var(--accent) 22%, transparent 23%),
  radial-gradient(circle at 75% 25%, var(--muted) 14%, transparent 15%),
  radial-gradient(circle at 25% 75%, var(--muted) 14%, transparent 15%), var(--soft); }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.status.ready .dot { background: var(--good); }
.status.error .dot { background: var(--bad); }
.status.loading .dot { animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }

.layout { display: grid; grid-template-columns: 360px 1fr; height: calc(100% - 52px); }
.panel { overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); padding-bottom: 24px; }
.tabs { display: flex; gap: 4px; padding: 12px 14px 0; position: sticky; top: 0; background: var(--panel); z-index: 2; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: 0; background: none; padding: 9px 6px 11px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 550; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

.group { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.group h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }
.opt { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); opacity: .8; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > label { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; }
.field output { color: var(--ink); font-variant-numeric: tabular-nums; }
.field input[type=number], .field input[type=text], .field select, .tool select {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seed { flex-direction: row; align-items: center; gap: 8px; }
.seed label { flex: 0 0 auto; }
.seed input { flex: 1; }
.colour { flex-direction: row; align-items: center; justify-content: space-between; }
input[type=color] { width: 44px; height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: var(--soft); cursor: pointer; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.drop { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 18px 12px; border: 1.5px dashed var(--line); border-radius: var(--radius); background: var(--soft); text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.drop span { color: var(--muted); font-size: 12.5px; }
.drop.small { padding: 12px; }
.drop.over, .drop:hover { border-color: var(--accent); }

.thumbs { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.thumbs li { display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center; padding: 6px; border: 1px solid var(--line); border-radius: 8px; }
.thumbs img, .texture-thumb img { width: 52px; height: 52px; object-fit: contain; border-radius: 5px; background: repeating-conic-gradient(#d6d6d6 0 25%, #fff 0 50%) 0 0 / 12px 12px; }
.thumbs .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.thumbs .sub { color: var(--muted); font-size: 12px; }
.thumbs .sub.warn { color: var(--warn); }
.thumbs .btns { display: flex; gap: 4px; }
.texture-thumb { margin-top: 10px; display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 12.5px; }
.texture-thumb img { width: 72px; height: 72px; object-fit: cover; }

.note { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--soft); font-size: 12.5px; }
.note.err { color: var(--bad); }
.note dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; }
.note dt { color: var(--muted); }
.note dd { margin: 0; font-variant-numeric: tabular-nums; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; border: 1px solid var(--line); }

button.primary, button.ghost { border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 550; }
button.primary { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.ghost.mini { padding: 3px 8px; font-size: 12px; font-weight: 500; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.wide { width: 100%; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar, .actions { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); flex-wrap: wrap; }
.toolbar { border-bottom: 1px solid var(--line); }
.actions { border-top: 1px solid var(--line); }
.tool { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; color: var(--muted); }
.tool select { width: auto; padding: 5px 8px; }
.tool input[type=range] { width: 140px; accent-color: var(--accent); }
.grow { flex: 1; }
.meta { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.seam { font-size: 12.5px; padding: 4px 10px; border-radius: 999px; background: var(--soft); font-variant-numeric: tabular-nums; }
.seam.good { color: var(--good); }
.seam.warn { color: var(--warn); }
.seam.bad { color: var(--bad); }

.viewport { position: relative; flex: 1; min-height: 0; background: var(--stage); overflow: hidden; }
.viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); padding: 24px; }
.empty p { margin: 4px 0; }
.busy { position: absolute; top: 12px; right: 12px; display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--panel); box-shadow: 0 2px 10px rgba(0,0,0,.12); font-size: 12.5px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.log { margin: 0; max-height: 120px; overflow: auto; padding: 8px 16px; font: 12px/1.5 var(--mono); color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); white-space: pre-wrap; }

[hidden] { display: none !important; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; max-height: none; }
  .stage { order: -1; height: 62vh; position: sticky; top: 0; z-index: 3; border-bottom: 1px solid var(--line); }
  .toolbar, .actions { gap: 10px; padding: 8px 12px; }
  .tool input[type=range] { width: 96px; }
  .bar { padding: 0 16px; }
  #status-text { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
