:root {
  --bg: #120e0b;
  --panel: rgba(22, 17, 13, 0.8);
  --panel-solid: #1b1511;
  --line: rgba(244, 228, 204, 0.1);
  --line-2: rgba(244, 228, 204, 0.2);
  --text: #f2e9dc;
  --muted: #a8998a;
  --dim: #75685b;
  --gold: #dcab52;
  --gold-2: #f0c878;
  --terra: #cf5b3f;
  --sky-top: #86a9c4;
  --sky-bot: #efe5d3;
  --r: 14px;
  --left-w: 268px;
  --right-w: 300px;
  --gap: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 13px/1.45 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* ── Viewport ─────────────────────────────── */
#viewport {
  position: fixed; inset: 0;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bot) 58%, #8a7862 100%);
  transition: background 0.4s;
}
body.blueprint #viewport { background: radial-gradient(ellipse at 50% 38%, #18385a 0%, #0b1a2b 75%); }
#viewport canvas { display: block; outline: none; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.tag {
  pointer-events: auto; cursor: pointer;
  padding: 3px 9px; border-radius: 99px;
  background: rgba(20, 15, 11, 0.82); border: 1px solid var(--line-2);
  color: var(--text); font-size: 11.5px; font-weight: 500; white-space: nowrap;
  backdrop-filter: blur(6px);
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.tag::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--c, var(--gold)); margin-right: 6px; vertical-align: 1px; }
.tag:hover, .tag.on { background: rgba(60, 40, 18, 0.95); border-color: var(--gold); transform: scale(1.06); }

/* ── Brand ────────────────────────────────── */
.brand {
  position: fixed; top: var(--gap); left: var(--gap); right: var(--gap);
  display: flex; align-items: center; gap: 12px; pointer-events: none; z-index: 5;
}
.brand > * { pointer-events: auto; }
.mark { width: 44px; height: 30px; color: var(--gold); filter: drop-shadow(0 2px 6px rgba(0,0,0,.35)); }
.brand h1 {
  margin: 0; font: 600 25px/1 'Cormorant Garamond', serif; letter-spacing: 0.01em;
  color: #fff8ec; text-shadow: 0 1px 12px rgba(0,0,0,.45);
}
.brand p { margin: 3px 0 0; font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: rgba(255,248,236,.8); text-shadow: 0 1px 8px rgba(0,0,0,.5); }
.mobile-toggles { display: none; margin-left: auto; gap: 6px; }
.chip { border: 1px solid var(--line-2); background: var(--panel); border-radius: 99px; padding: 6px 12px; backdrop-filter: blur(10px); cursor: pointer; }

/* ── Panels ───────────────────────────────── */
.panel {
  position: fixed; top: 72px; bottom: var(--gap);
  background: var(--panel); backdrop-filter: blur(16px) saturate(1.15);
  border: 1px solid var(--line); border-radius: var(--r);
  display: flex; flex-direction: column; overflow: hidden; z-index: 4;
  box-shadow: 0 24px 60px -24px rgba(0,0,0,.7);
}
.panel.left { left: var(--gap); width: var(--left-w); }
.panel.right { right: var(--gap); width: var(--right-w); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 16px 8px; }
.panel-head h2 { margin: 0; font: 600 19px/1 'Cormorant Garamond', serif; letter-spacing: .02em; }
.kbd-hint { font-size: 11px; cursor: pointer; }
.scroll { flex: 1; overflow-y: auto; padding: 0 10px 12px; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.panel-foot { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.panel-foot .btn { flex: 1; }

.search { padding: 0 12px 8px; }
.search input {
  width: 100%; padding: 8px 10px; border-radius: 9px;
  background: rgba(255,255,255,.05); border: 1px solid var(--line); outline: none;
}
.search input:focus { border-color: var(--gold); }

.cat-head {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 6px 4px; font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.cat-head i { font-style: normal; color: var(--dim); letter-spacing: .04em; text-transform: none; font-size: 11px; }
.part {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 9px; cursor: pointer; border: 1px solid transparent;
  transition: background .12s, border-color .12s;
}
.part:hover { background: rgba(255,255,255,.05); }
.part.active { background: rgba(220,171,82,.13); border-color: rgba(220,171,82,.45); }
.part.off .pname { opacity: .4; }
.part .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent); }
.pname { flex: 1; min-width: 0; line-height: 1.25; }
.pname b { display: block; font-weight: 500; }
.pname small { color: var(--muted); font-size: 11.5px; }
.eye { border: 0; background: none; padding: 4px; border-radius: 6px; cursor: pointer; color: var(--muted); opacity: .55; display: grid; }
.eye:hover { opacity: 1; background: rgba(255,255,255,.06); }
.part.off .eye { opacity: 1; color: var(--terra); }
.eye svg { width: 16px; height: 16px; }

/* ── Controls ─────────────────────────────── */
details { border-bottom: 1px solid var(--line); padding: 4px 6px 12px; }
details:last-child { border-bottom: 0; }
summary {
  list-style: none; cursor: pointer; padding: 10px 0 8px;
  font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  display: flex; align-items: center; justify-content: space-between;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: '+'; font-size: 15px; color: var(--dim); }
details[open] summary::after { content: '–'; }
.label { font-size: 11.5px; color: var(--muted); margin: 10px 0 4px; }

.seg { display: flex; gap: 2px; padding: 3px; background: rgba(0,0,0,.28); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.seg button {
  flex: 1; border: 0; background: none; padding: 6px 4px; border-radius: 7px; cursor: pointer;
  font-size: 12px; color: var(--muted); white-space: nowrap; transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: linear-gradient(180deg, #e2b762, #c8963c); color: #24170a; font-weight: 600; }
.seg.small { margin: 0; }
.seg.small button { padding: 5px 9px; font-size: 11.5px; }

.switch { display: flex; align-items: center; gap: 10px; padding: 5px 0; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch span { width: 30px; height: 17px; border-radius: 99px; background: rgba(255,255,255,.14); position: relative; flex: none; transition: background .15s; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #efe6d8; transition: transform .15s; }
.switch input:checked + span { background: var(--gold); }
.switch input:checked + span::after { transform: translateX(13px); background: #24170a; }

.range-row { display: flex; align-items: center; gap: 10px; }
.range-row output { width: 44px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
input[type=range] { flex: 1; -webkit-appearance: none; appearance: none; height: 22px; background: none; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--gold) var(--p, 0%), rgba(255,255,255,.14) var(--p, 0%)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; margin-top: -5.5px; border-radius: 50%; background: #fff4e0; border: 3px solid var(--gold); box-shadow: 0 1px 4px rgba(0,0,0,.4); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255,255,255,.14); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--gold); }
input[type=range]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; background: #fff4e0; border: 3px solid var(--gold); }
input[type=range]:disabled { opacity: .35; }

.row { display: flex; gap: 6px; margin-top: 6px; }
.row .btn { flex: 1; }
.btn {
  border: 1px solid rgba(220,171,82,.55); background: rgba(220,171,82,.14); color: var(--gold-2);
  padding: 7px 12px; border-radius: 9px; cursor: pointer; font-weight: 500; transition: background .15s;
}
.btn:hover { background: rgba(220,171,82,.26); }
.btn.ghost { border-color: var(--line-2); background: rgba(255,255,255,.04); color: var(--text); }
.btn.ghost:hover { background: rgba(255,255,255,.09); }

select {
  width: 100%; padding: 8px 10px; border-radius: 9px; margin-bottom: 10px;
  background: rgba(0,0,0,.28); border: 1px solid var(--line-2); outline: none; cursor: pointer;
}
select option { background: var(--panel-solid); }
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 6px; }
.sw { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10.5px; color: var(--muted); cursor: pointer; }
.sw input { -webkit-appearance: none; appearance: none; width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line-2); padding: 0; background: none; cursor: pointer; }
.sw input::-webkit-color-swatch-wrapper { padding: 0; }
.sw input::-webkit-color-swatch { border: 0; border-radius: 50%; }
.sw input::-moz-color-swatch { border: 0; border-radius: 50%; }
.sw:hover input { border-color: var(--gold); }

/* ── Info card ────────────────────────────── */
.info {
  position: fixed; z-index: 6;
  left: calc(var(--gap) * 2 + var(--left-w)); right: calc(var(--gap) * 2 + var(--right-w) + 52px);
  bottom: var(--gap); margin: 0 auto; max-width: 620px;
  background: var(--panel); backdrop-filter: blur(16px) saturate(1.15);
  border: 1px solid var(--line-2); border-radius: var(--r); padding: 14px 18px 14px;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.75);
  max-height: 52vh; overflow-y: auto;
  transition: opacity .2s, transform .2s;
}
.info.hidden { opacity: 0; transform: translateY(12px); pointer-events: none; }
.info-top { display: flex; align-items: center; gap: 8px; }
.cat-chip { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; padding: 3px 9px; border-radius: 99px; background: color-mix(in srgb, var(--c) 22%, transparent); color: var(--c); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); }
.info h3 { margin: 6px 0 0; font: 600 30px/1.05 'Cormorant Garamond', serif; color: #fff6e6; }
.alias { margin: 2px 0 8px; color: var(--gold-2); font-size: 12.5px; }
.alias em { color: var(--muted); }
.info p { margin: 0 0 8px; }
#infoDesc { color: #e6dccd; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 6px; }
.cols h4, #about h4 { margin: 0 0 3px; font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.cols p { color: #cfc3b3; font-size: 12.5px; }
.info-foot { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.specs { display: flex; gap: 6px; flex-wrap: wrap; }
.specs span { font-size: 11.5px; padding: 3px 8px; border-radius: 6px; background: rgba(255,255,255,.06); border: 1px solid var(--line); color: #dccfbd; }
.icon {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line-2); background: rgba(255,255,255,.04); font-size: 16px; line-height: 1;
}
.icon:hover { background: rgba(255,255,255,.1); border-color: var(--gold); }

/* ── Dock, hint, tooltip ──────────────────── */
.dock {
  position: fixed; z-index: 4; bottom: var(--gap); right: calc(var(--gap) * 2 + var(--right-w));
  display: flex; flex-direction: column; gap: 4px; padding: 5px;
  background: var(--panel); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 12px;
}
.dock .icon { width: 34px; height: 34px; border-color: transparent; background: none; }
.dock .icon:hover { border-color: var(--line-2); background: rgba(255,255,255,.08); }
.dock .icon.on { color: var(--gold); }
.hint {
  position: fixed; z-index: 3; bottom: 22px; left: 50%; transform: translateX(-50%);
  padding: 7px 14px; border-radius: 99px; font-size: 12px; color: #fff8ec;
  background: rgba(20,15,11,.55); backdrop-filter: blur(8px); white-space: nowrap; transition: opacity .3s;
}
.hint b { color: var(--gold-2); font-weight: 600; }
body.has-selection .hint { opacity: 0; }
#tooltip {
  position: fixed; z-index: 7; pointer-events: none; padding: 5px 10px; border-radius: 8px;
  background: rgba(20,15,11,.9); border: 1px solid var(--line-2); font-size: 12px; white-space: nowrap;
  opacity: 0; transition: opacity .12s;
}
#tooltip.on { opacity: 1; }
#tooltip small { color: var(--muted); margin-left: 6px; }

/* ── About dialog ─────────────────────────── */
dialog {
  max-width: 560px; width: calc(100vw - 32px); border: 1px solid var(--line-2); border-radius: 16px;
  background: var(--panel-solid); color: var(--text); padding: 22px 24px;
  box-shadow: 0 40px 100px -20px rgba(0,0,0,.8);
}
dialog::backdrop { background: rgba(8,6,4,.55); backdrop-filter: blur(3px); }
dialog h3 { margin: 0 0 10px; font: 600 30px/1.1 'Cormorant Garamond', serif; color: #fff6e6; }
#aboutBody p { color: #d9cdbc; margin: 0 0 10px; }
#about h4 { margin-top: 16px; }
.keys { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 6px 0 18px; color: var(--muted); font-size: 12px; }
kbd { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line-2); border-bottom-width: 2px; background: rgba(255,255,255,.06); color: var(--text); font: 11px/1.5 'Inter', sans-serif; text-align: center; }

.credit { margin: 0; padding: 0 12px 10px; font-size: 11.5px; color: var(--muted); text-align: center; }
.credit a { color: var(--gold-2); text-decoration: none; border-bottom: 1px solid rgba(240,200,120,.35); }
.credit a:hover { border-bottom-color: var(--gold-2); }
.about-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.about-foot .credit { padding: 0; }

/* ── Loading ──────────────────────────────── */
#loading {
  position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: var(--bg); color: var(--muted); font: 500 italic 18px 'Cormorant Garamond', serif;
  transition: opacity .6s;
}
#loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--gold); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ───────────────────────────── */
@media (max-width: 1180px) {
  :root { --left-w: 236px; --right-w: 276px; }
  .info { left: var(--gap); right: calc(var(--gap) * 2 + var(--right-w) + 52px); }
  body.has-selection .panel.left { opacity: 0; pointer-events: none; }
}
@media (max-width: 860px) {
  .mobile-toggles { display: flex; }
  .brand h1 { font-size: 21px; }
  .brand p { display: none; }
  .panel { top: 64px; bottom: auto; max-height: calc(100dvh - 80px); left: 12px !important; right: 12px !important; width: auto !important;
    opacity: 0; pointer-events: none; transform: translateY(-8px); transition: opacity .2s, transform .2s; }
  body.show-left .panel.left, body.show-right .panel.right { opacity: 1; pointer-events: auto; transform: none; }
  .info { left: 12px; right: 12px; bottom: 12px; max-height: 46vh; padding: 12px 14px; }
  .info h3 { font-size: 25px; }
  .cols { grid-template-columns: 1fr; gap: 4px; }
  .dock { right: 12px; bottom: auto; top: 64px; }
  body.show-left .dock, body.show-right .dock { display: none; }
  .hint { display: none; }
}
