:root {
  --bg: #12140f;
  --panel: #1b1e16;
  --panel-2: #23271c;
  --line: #33382a;
  --text: #ecebe1;
  --muted: #a0a391;
  --accent: #ff7a1a;          /* blaze orange */
  --accent-ink: #1a0d00;
  --olive: #7d9658;
  --warn: #e7b84a;
  --bad: #ef6a5a;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex; flex-direction: column;
}
h1, h2, h3, p { margin: 0; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; justify-content: center; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── top bar ── */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark { width: 30px; height: 30px; flex: none; }
.name { font-weight: 800; letter-spacing: .22em; font-size: 18px; }
.tag { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { display: flex; align-items: center; gap: 12px; flex: none; }
.slicer { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; max-width: 320px;
}
select:focus-visible, button:focus-visible, input:focus-visible, .card:focus-visible, .pattern-card:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.banner { background: #5a1f17; color: #ffe2dc; padding: 10px 18px; text-align: center; flex: none; }

/* ── buttons ── */
.primary {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 9px 16px; font-weight: 700;
}
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.primary:disabled { background: #4a4a40; color: #8d8d80; cursor: not-allowed; }
.primary.big { padding: 13px 20px; font-size: 16px; width: 100%; }
.ghost {
  background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; color: var(--text);
}
.ghost:hover { background: var(--panel-2); }
.mini { background: none; border: 0; padding: 0; color: var(--olive); font-size: 13px; text-decoration: underline; }
.link { color: var(--olive); font-size: 14px; text-align: center; }
a.primary { display: block; text-align: center; text-decoration: none; }

/* ── layout ── */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 440px; }
.stage { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.steps {
  border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; min-height: 0;
  display: flex; flex-direction: column;
}

/* ── the 3D view ── */
.view {
  position: relative; flex: 1; min-height: 260px;
  background: radial-gradient(ellipse at 50% 38%, #2a2f22 0%, #171a12 62%, #101209 100%);
}
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#gl:active { cursor: grabbing; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; }
.empty-card {
  border: 2px dashed #4a5139; border-radius: 20px; padding: 40px 44px; text-align: center; max-width: 520px;
  background: rgba(18, 20, 15, .55);
}
.empty-card h1 { font-size: 26px; margin: 10px 0 6px; }
.empty-card p { color: var(--muted); margin-bottom: 20px; }
.drop-art { width: 64px; height: 64px; color: var(--olive); }

.chip-row { position: absolute; left: 14px; top: 14px; display: flex; gap: 8px; pointer-events: none; }
.chip { background: rgba(0, 0, 0, .5); border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; font-size: 13px; }
.chip.good { border-color: #56703a; color: #cfe6ae; }
.chip.old { border-color: #7a6223; color: #f2d589; }
.view-tools { position: absolute; right: 14px; top: 14px; display: flex; gap: 8px; }
.tool {
  background: rgba(0, 0, 0, .5); border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; font-size: 13px;
}
.tool[aria-pressed="true"] { border-color: var(--olive); color: #d9eab9; }
.view-hint {
  position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; font-size: 12px; color: #8b8e7c; pointer-events: none;
}

.busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(12, 13, 9, .72); padding: 20px; }
.busy-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px 28px; width: 340px; max-width: 100%;
  text-align: center; display: grid; gap: 10px; justify-items: center;
}
.busy-card.wide { width: 520px; text-align: left; justify-items: start; }
.busy-card p { overflow-wrap: anywhere; }
.busy-card pre {
  max-height: 220px; overflow: auto; background: #0e100b; padding: 10px; border-radius: 8px; font-size: 12px; white-space: pre-wrap;
  width: 100%; margin: 8px 0 0;
}
.busy-card details { width: 100%; }
.busy-stage { font-weight: 700; font-size: 17px; }
.busy-sub { color: var(--muted); font-size: 13px; }
.bar { width: 100%; height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 35%; background: var(--accent); border-radius: 99px; animation: slide 1.3s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
@media (prefers-reduced-motion: reduce) { .bar i { animation: none; width: 100%; opacity: .6; } }

/* ── result ── */
.result {
  flex: none; display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 20px; padding: 16px 18px;
  border-top: 1px solid var(--line); background: var(--panel); max-height: 46vh; overflow-y: auto;
}
.result-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.result h2 { font-size: 17px; }
.slots { list-style: none; margin: 0 0 10px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.slots li {
  display: grid; grid-template-columns: 38px 1fr; gap: 10px; align-items: center; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.slots .dot { width: 38px; height: 38px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .18); display: grid; place-items: center;
  font-weight: 800; font-size: 15px; }
.slots .what { font-weight: 600; text-transform: capitalize; }
.slots .sub { color: var(--muted); font-size: 12px; }
.result-actions { display: grid; gap: 8px; align-content: start; }
.saved { color: #cfe6ae; word-break: break-word; }
.notes { font-size: 13px; color: var(--muted); }
.notes summary { cursor: pointer; color: var(--warn); }
.notes ul { margin: 6px 0 0; padding-left: 18px; }
.stale {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 18px;
  border-top: 1px solid #7a6223; background: #2b2412; color: #f2d589;
}

/* ── steps ── */
.step { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.step h3 { font-size: 15px; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.step h3 b {
  width: 24px; height: 24px; border-radius: 50%; background: var(--olive); color: #10140a; display: grid; place-items: center; font-size: 13px;
}
.model-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.model-name { font-weight: 600; word-break: break-all; }
.warn { margin: 10px 0 0; padding: 8px 10px 8px 26px; background: #2b2412; border: 1px solid #7a6223; border-radius: 8px; color: #f2d589; font-size: 13px; }

.pattern-card {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
}
.pattern-card:hover { border-color: var(--olive); }
.pattern-card img { width: 84px; height: 84px; border-radius: 8px; flex: none; object-fit: cover; background: #0e100b; }
.pattern-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.pattern-name { font-weight: 700; font-size: 16px; }
.pattern-text .small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.browse { flex: none; background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 7px 12px; border-radius: 9px; font-size: 14px; }
.recent { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.recent span { font-size: 12px; color: var(--muted); }
.recent button { padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: 44px; height: 44px; background: none; }
.recent button:hover { border-color: var(--olive); }
.recent img { width: 100%; height: 100%; display: block; object-fit: cover; }

.tune-top { display: grid; grid-template-columns: 150px 1fr; gap: 14px; margin-bottom: 14px; }
.swatch-box { display: grid; gap: 4px; }
#swatch { width: 150px; height: 150px; border-radius: 10px; border: 1px solid var(--line); background: #0e100b; }
.swatch-box.loading #swatch { opacity: .55; }
.field { margin: 14px 0; }
.field.row { margin: 14px 0 4px; }
.field-label { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; margin-bottom: 6px; gap: 10px; }
.field-label output { font-weight: 400; color: var(--muted); font-size: 13px; }
.field p { margin-top: 6px; }
.slider { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; font-size: 12px; color: var(--muted); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.color-list { display: flex; flex-wrap: wrap; gap: 8px; }
.color {
  position: relative; width: 44px; height: 44px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .2); display: grid;
  place-items: center; font-weight: 800; cursor: pointer;
}
.color input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.color:hover { outline: 2px solid var(--olive); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; flex-wrap: wrap; }
.check input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }
input[type=color] { width: 34px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 7px 14px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--olive); color: #10140a; font-weight: 700; }

.more { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.more > summary { cursor: pointer; font-weight: 600; color: var(--olive); }

.go {
  position: sticky; bottom: 0; margin-top: auto; padding: 14px 18px; background: linear-gradient(to top, var(--panel) 78%, transparent);
  display: grid; gap: 6px; text-align: center;
}

/* ── sheets (pattern picker, help) ── */
.sheet { position: fixed; inset: 0; background: rgba(8, 9, 6, .78); display: grid; place-items: center; padding: 24px; z-index: 20; }
.sheet-box {
  width: min(1180px, 100%); height: min(860px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  display: flex; flex-direction: column; overflow: hidden;
}
.sheet-box.narrow { width: min(560px, 100%); height: auto; padding-bottom: 18px; }
.sheet-head { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.sheet-head h2 { font-size: 18px; margin-right: auto; }
#search {
  flex: 1 1 260px; max-width: 420px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
.fams { display: flex; gap: 8px; padding: 12px 18px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.fam {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px; font-size: 13px;
}
.fam.on { background: var(--olive); color: #10140a; border-color: var(--olive); font-weight: 700; }
.fam i { font-style: normal; opacity: .65; margin-left: 4px; }
.grid-wrap { flex: 1; overflow-y: auto; padding: 16px 18px 24px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 12px; }
.card {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 0; text-align: left; overflow: hidden;
  display: flex; flex-direction: column;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card img { width: 100%; aspect-ratio: 1; display: block; object-fit: cover; background: #0e100b; }
.card .t { padding: 8px 10px 2px; font-weight: 600; font-size: 14px; }
.card .d { padding: 0 10px 10px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.card .dots { display: inline-flex; gap: 2px; }
.card .dots i { width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .25); }
.card.own { border-style: dashed; align-items: center; justify-content: center; text-align: center; min-height: 200px; padding: 14px; gap: 8px; }
.card.own svg { width: 44px; height: 44px; color: var(--olive); }
.card.own b { font-size: 15px; }

.how { margin: 16px 18px 12px 0; padding-left: 40px; display: grid; gap: 10px; }
.sheet-box.narrow p { padding: 0 18px; margin-top: 6px; }

.dropveil {
  position: fixed; inset: 0; background: rgba(18, 20, 15, .86); display: grid; place-items: center; z-index: 30; pointer-events: none;
}
.dropveil div { border: 3px dashed var(--accent); border-radius: 24px; padding: 50px 70px; font-size: 26px; font-weight: 700; }
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: #0c0d09; border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 18px; z-index: 40; max-width: min(640px, 92vw); box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
.toast.bad { border-color: var(--bad); color: #ffd9d3; }

/* ── narrow windows: stack ── */
@media (max-width: 920px) {
  html, body { height: auto; }
  .layout { display: block; }
  .view { height: 56vh; flex: none; }
  .steps { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .result { grid-template-columns: 1fr; max-height: none; }
  .tag { display: none; }
}
@media (max-width: 520px) {
  .top { flex-wrap: wrap; }
  .top-right { width: 100%; }
  .slicer { flex: 1; min-width: 0; }
  .slicer select { width: 100%; max-width: none; }
  .slicer span { display: none; }
  .tune-top { grid-template-columns: 1fr; }
  .empty-card { padding: 26px 20px; }
}
