:root {
  --bg: #171715; --card: #201f1d; --bg3: #262523; --ink: #e2e0d8; --muted: #98968b; --faint: #93918a;
  --line: #343330; --line2: #454440; --accent: #C96B3A; --accent2: #da7c4a; --ok: #3fa06a; --fail: #cf5b40;
  --font: 'Cascadia Mono', 'SF Mono', SFMono-Regular, Consolas, monospace; --r: 3px;
  --rail: 360px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 12.5px/1.5 var(--font); }
::selection { background: var(--accent); color: #fff; }
::-webkit-scrollbar { width: 8px; height: 8px; } ::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 4px; } ::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { display: grid; grid-template-columns: 1fr var(--rail); height: 100%; position: relative; }
#viewer { position: relative; min-width: 0; }
#gl { width: 100%; height: 100%; display: block; }
#hud { position: absolute; left: 12px; top: 10px; pointer-events: none; }
#status { font-size: 11px; color: var(--muted); background: rgba(23,23,21,.75); padding: 3px 8px; border: 1px solid var(--line); border-radius: var(--r); }
#status.err { color: var(--fail); border-color: var(--fail); }
#viewbar { position: absolute; left: 12px; right: 12px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; width: max-content; max-width: calc(100% - 24px); background: rgba(23,23,21,.8); padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--r); font-size: 11px; }
#viewbar label { display: flex; gap: 6px; align-items: center; color: var(--muted); }

/* the rail grip: drag the panel's left edge; the panel's contents scale with its width */
#railGrip { position: absolute; right: calc(var(--rail) - 7px); top: 0; bottom: 0; width: 14px; cursor: col-resize; z-index: 5; }
#railGrip::after { content: ''; position: absolute; left: 5px; top: 50%; width: 4px; height: 36px; margin-top: -18px; border-radius: 2px; background: var(--line2); transition: background 150ms var(--ease-out); }
#railGrip:hover, #railGrip.on { background: rgba(201,107,58,.10); }
#railGrip:hover::after, #railGrip.on::after { background: var(--accent); }

#panel { overflow: auto; border-left: 1px solid var(--line); padding: 16px 16px 60px; background: var(--card); }
#panel header h1 { font-size: 18px; margin: 0 0 4px; font-weight: 600; }
#panel .sub { margin: 0 0 12px; color: var(--muted); }
#panel section { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 14px; }
#panel h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); margin: 0 0 8px; font-weight: 600; display: flex; align-items: baseline; gap: 8px; }
#panel h2::after { content: ''; flex: 1; border-top: 1px solid var(--line); transform: translateY(-3px); }

/* groups of settings, the long ones folded */
details.grp, details.help { border: 1px solid var(--line); border-radius: var(--r); margin: 6px 0; background: var(--bg3); }
details.grp > summary, details.help > summary { cursor: pointer; padding: 6px 10px; color: var(--muted); font-size: 12px; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.grp > summary::after, details.help > summary::after { content: '+'; color: var(--faint); }
details[open].grp > summary::after, details[open].help > summary::after { content: '−'; }
details.grp > summary::-webkit-details-marker, details.help > summary::-webkit-details-marker { display: none; }
details.grp > .body, details.help > .note, details.help > p { padding: 0 10px 8px; margin: 0; }
details.help > .note + .note { padding-top: 6px; }
details.grp > summary b { color: var(--ink); font-weight: 500; }

.row { display: flex; align-items: center; gap: 8px; padding: 4px 0; min-height: 30px; }
.row span { flex: 1; color: var(--muted); }
.row input[type=range] { flex: 1.4; accent-color: var(--accent); min-width: 0; height: 24px; }
.row output { width: 58px; text-align: right; font-variant-numeric: tabular-nums; flex: none; }
.row.check { justify-content: flex-start; } .row.check span { flex: none; color: var(--ink); }
.row[hidden] { display: none; }
.row select, #addLib { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%2398968b' stroke-width='1.5'/></svg>"); background-repeat: no-repeat; background-position: right 8px center; padding-right: 24px !important; }
.row select { flex: 1.6; min-width: 0; width: 0; background-color: var(--bg3); color: var(--ink); border: 1px solid var(--line2); border-radius: var(--r); padding: 5px 6px; font: inherit; text-overflow: ellipsis; min-height: 30px; }
.nums { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; margin: 4px 0; }
.row.num { padding: 2px 0; } .row.num span { font-size: 11px; }
.row input[type=number] { width: 72px; min-width: 0; background: var(--bg3); color: var(--ink); border: 1px solid var(--line2); border-radius: var(--r); padding: 4px 5px; font: inherit; font-variant-numeric: tabular-nums; }
i.u { font-style: normal; color: var(--faint); font-size: 11px; width: 22px; }
input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; }
.note { color: var(--faint); font-size: 12px; margin: 6px 0; }
.hint { color: var(--faint); font-size: 11px; margin: 0 0 4px; }
code { background: var(--bg3); padding: 0 4px; border-radius: var(--r); }
a { color: var(--accent); }

.kv div { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px solid var(--line); }
.kv span { color: var(--muted); } .kv b { font-weight: 500; text-align: right; }
em.bad { color: var(--fail); font-style: normal; }

.btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.btns.small button { font-size: 11px; padding: 4px 8px; }
button { background: var(--bg3); color: var(--ink); border: 1px solid var(--line2); border-radius: var(--r); padding: 7px 11px; min-height: 32px; font: inherit; cursor: pointer; transition: border-color 150ms var(--ease-out), background-color 150ms var(--ease-out), transform 120ms var(--ease-out); }
button:hover { border-color: var(--accent); }
button:active { transform: scale(0.97); }
button:disabled { opacity: .5; cursor: default; transform: none; }
button.primary { border-color: var(--accent); color: #fff; background: rgba(201,107,58,.16); }
button.primary:hover { background: rgba(201,107,58,.28); }
button.warn { border-color: var(--fail); color: var(--fail); }

/* export feedback under the buttons */
.toast { margin: 8px 0 4px; padding: 8px 10px; border: 1px solid var(--accent); border-radius: var(--r); background: rgba(201,107,58,.10); color: var(--ink); font-size: 12px; opacity: 1; transition: opacity 200ms var(--ease-out); }
.toast[hidden] { display: none; }
.toast.err { border-color: var(--fail); background: rgba(207,91,64,.10); }

/* parts list */
.items { display: flex; flex-direction: column; gap: 8px; margin: 6px 0; }
.item { background: var(--bg3); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; transition: border-color 150ms var(--ease-out); }
.item.focus { border-color: var(--accent); }
.item .ttl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.item .nm { width: 100%; margin: 4px 0 6px; background: var(--card); color: var(--ink); border: 1px solid var(--line2); border-radius: var(--r); padding: 4px 6px; font: inherit; min-height: 28px; }
.item .fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 8px; }
.item .f { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); }
.item .f input { width: 100%; background: var(--card); color: var(--ink); border: 1px solid var(--line2); border-radius: var(--r); padding: 4px 5px; font: inherit; min-height: 28px; font-variant-numeric: tabular-nums; }
.item .grid { margin-top: 6px; }
.item .grid summary { font-size: 11px; color: var(--faint); cursor: pointer; }
.item .x { margin-top: 6px; font-size: 11px; padding: 3px 8px; min-height: 26px; }
.item.bad { border-color: var(--fail); }
.item.bad .ttl::after { content: '  · outside the case'; color: var(--fail); text-transform: none; letter-spacing: 0; }
.item.clash { border-color: var(--fail); }
.item.clash .ttl::after { content: '  · runs into another part'; color: var(--fail); text-transform: none; letter-spacing: 0; }
#addLib { flex: 1; min-width: 160px; background-color: var(--bg3); color: var(--ink); border: 1px solid var(--line2); border-radius: var(--r); padding: 6px; font: inherit; min-height: 32px; }

.bom div { display: grid; grid-template-columns: 96px 1fr; gap: 0 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.bom span { color: var(--muted); } .bom b { font-weight: 500; } .bom i { grid-column: 2; font-style: normal; color: var(--faint); font-size: 11px; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 46vh 1fr; }
  #railGrip { display: none; }
  #panel { border-left: none; border-top: 1px solid var(--line); zoom: 1 !important; padding-bottom: 90px; }
  #viewbar { left: 8px; right: 8px; bottom: 8px; width: auto; }
  button, .row select, #addLib { min-height: 40px; }
  .row input[type=range] { height: 36px; }
  .row input[type=number], .item .f input, .item .nm { min-height: 36px; }
  .nums { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  button, .item, .toast, #railGrip::after { transition: none; }
  button:active { transform: none; }
}
