:root {
  --bg: #12100e;
  --bg-2: #1c1814;
  --panel: #241f1a;
  --line: #3c342c;
  --text: #f4efe6;
  --muted: #b2a596;
  --brass: #e2a85a;
  --brass-deep: #a86b28;
  --ink: #1a120c;
  --danger: #e07a68;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(226, 168, 90, 0.16), transparent 50%),
    var(--bg);
  color: var(--text);
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  padding: 22px 28px 8px;
}
.brand { display: flex; gap: 14px; align-items: center; }
.mark {
  width: 48px;
  height: 48px;
  border-radius: 50% 50% 46% 46%;
  border: 3px solid var(--brass);
  display: grid;
  place-items: center;
  font-family: Palatino, "Iowan Old Style", Georgia, serif;
  letter-spacing: 0.04em;
  color: var(--brass);
  box-shadow: inset 0 0 0 4px #2a2118;
}
h1 {
  margin: 0;
  font-family: Palatino, "Iowan Old Style", Georgia, serif;
  font-weight: 600;
  font-size: 1.7rem;
  letter-spacing: -0.02em;
}
.brand p, .printer, .hint, .status, .stage-caption {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}
.printer { letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.75rem; }

main {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 18px;
  padding: 12px 28px 28px;
}
@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  .top { flex-direction: column; align-items: flex-start; }
}

.panel, .stage-wrap {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent 80px), var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.panel { padding: 8px 16px 16px; }
fieldset {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0;
  padding: 12px 0;
}
legend {
  padding-right: 8px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass);
}

.templates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.template {
  appearance: none;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 6px 10px;
  cursor: pointer;
  text-align: center;
}
.template svg { width: 100%; height: 64px; display: block; }
.template strong { display: block; font-size: 0.82rem; margin-top: 4px; }
.template.on {
  border-color: var(--brass);
  box-shadow: inset 0 0 0 1px var(--brass);
}

.upload {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--brass-deep);
  border-radius: 12px;
  min-height: 46px;
  cursor: pointer;
  background: #2a221b;
}
.upload input { display: none; }
.upload span { color: var(--brass); font-weight: 600; }

.slider { display: block; margin-top: 10px; }
.slider span { display: flex; justify-content: space-between; font-size: 0.92rem; }
.slider output { color: var(--brass); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--brass); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  cursor: pointer;
  position: relative;
  padding: 0;
}
.swatch.off { opacity: 0.35; filter: grayscale(0.4); }
.swatch.in { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--brass); }
.swatch .tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  background: #000;
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}
.swatch:hover .tip, .swatch:focus .tip { opacity: 1; }

.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.roles label { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }
select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.filaments { display: grid; gap: 10px; }
.filament {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
}
.chip {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35);
}
.chip.light { border-color: rgba(0,0,0,0.35); }
.fname { font-weight: 650; font-size: 0.92rem; }
.tlabel {
  display: grid;
  gap: 2px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: right;
}
.tlabel input {
  width: 5.2rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.95rem;
}

.download {
  width: 100%;
  margin-top: 8px;
  background: linear-gradient(180deg, #f0c27a, var(--brass) 40%, var(--brass-deep));
  color: var(--ink);
  border: 0;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
  padding: 12px 16px;
  cursor: pointer;
}
.download:disabled { opacity: 0.6; cursor: progress; }
.status { min-height: 2.4em; }
.status.err { color: var(--danger); }

.stage-wrap {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  padding: 12px;
}
#preview {
  width: 100%;
  height: auto;
  flex: 1;
  background:
    radial-gradient(circle at 50% 45%, #2a241e, #100e0c 72%);
  border-radius: 12px;
  touch-action: none;
  cursor: grab;
}
#preview:active { cursor: grabbing; }
.stage-caption { text-align: center; padding-top: 8px; }
