/* Layout: a craftsman's bench — the stave stands in a lit viewing well on the left, the tool rack of parameters hangs on the right (stacks on phones). Single dark workshop look by choice. */
:root {
  --bench: #1a1613;
  --rack: #221d19;
  --rack-2: #2a241f;
  --line: #3b332c;
  --ink: #ede4d6;
  --muted: #a6978a;
  --brass: #d4ab5c;
  --brass-dim: #8f733f;
  --on-brass: #1a1613;
  --well-hi: #2e2620;
  --well-lo: #120f0d;
  --ok: #8fc48a;
  --warn: #e0b25a;
  --f-display: "IM Fell English SC", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --f-body: "Alegreya Sans", "Gill Sans", "Segoe UI", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: dark;
}
html, body { height: 100%; }
body {
  background: var(--bench);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
}
.app {
  height: 100%;
  box-sizing: border-box;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding-inline: 16px;
  padding-block: 12px;
}
header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; margin-right: auto; }
.brand h1 {
  font-family: var(--f-display);
  font-weight: 400;
  font-size: 26px;
  letter-spacing: 0.02em;
  margin: 0;
  color: var(--ink);
  white-space: nowrap;
}
.brand .mark { color: var(--brass); }
.brand small {
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.btn {
  font: 500 14px/1 var(--f-body);
  border: 1px solid var(--line);
  background: var(--rack-2);
  color: var(--ink);
  padding: 9px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.brand small a.home { color: var(--brass); text-decoration: none; }
.brand small a.home:hover { text-decoration: underline; }
.btn:hover:not(:disabled) { border-color: var(--brass-dim); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.icon { padding-inline: 11px; font-size: 16px; }
.history { display: flex; gap: 4px; }
.btn.primary { background: var(--brass); color: var(--on-brass); border-color: var(--brass); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
}
.well {
  position: relative;
  min-height: 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: radial-gradient(ellipse at 50% 42%, var(--well-hi), var(--well-lo) 75%);
  overflow: hidden;
}
.well canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.views {
  position: absolute; top: 10px; left: 10px;
  display: flex; gap: 4px;
  background: color-mix(in srgb, var(--bench) 70%, transparent);
  border: 1px solid var(--line);
  border-radius: 6px; padding: 3px;
}
.views button {
  font: 500 12px/1 var(--f-body);
  letter-spacing: 0.04em;
  background: none; border: 0; color: var(--muted);
  padding: 6px 10px; border-radius: 4px; cursor: pointer;
}
.views button[aria-pressed="true"] { background: var(--rack-2); color: var(--ink); }
.readout {
  position: absolute; left: 10px; bottom: 10px; right: 10px;
  display: flex; gap: 16px; flex-wrap: wrap;
  font-family: var(--f-mono); font-size: 12px; color: var(--muted);
  pointer-events: none;
}
.readout b { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
.hint {
  position: absolute; top: 12px; right: 12px;
  font-size: 12px; color: var(--muted);
}
.fail {
  position: absolute; inset: 0; margin: 0;
  display: grid; place-items: center; padding: 24px; text-align: center;
  color: var(--ink); font-size: 15px;
}

.rack {
  min-height: 0;
  overflow-y: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--rack);
}
details { border-bottom: 1px solid var(--line); }
details:last-child { border-bottom: 0; }
summary {
  list-style: none;
  cursor: pointer;
  display: flex; align-items: baseline; gap: 10px;
  padding: 12px 16px;
}
summary::-webkit-details-marker { display: none; }
summary h2 {
  font-family: var(--f-display);
  font-weight: 400;
  font-size: 19px;
  margin: 0;
  letter-spacing: 0.02em;
}
summary .sub { font-size: 12px; color: var(--muted); margin-left: auto; }
summary::after { content: "+"; font-family: var(--f-mono); color: var(--brass-dim); width: 10px; text-align: right; }
details[open] > summary::after { content: "−"; }
.ctrls { display: grid; gap: 12px; padding: 2px 16px 16px; }
.ctrl { display: grid; gap: 4px; }
.ctrl .top { display: flex; align-items: baseline; gap: 8px; }
.ctrl label { font-size: 13.5px; color: var(--ink); }
.ctrl .val {
  margin-left: auto;
  font-family: var(--f-mono); font-size: 12px; color: var(--brass);
  font-variant-numeric: tabular-nums;
}
input[type="range"] { width: 100%; accent-color: var(--brass); margin: 0; height: 18px; }
select, .ctrl input[type="text"] {
  width: 100%; min-width: 0; box-sizing: border-box;
  font: 14px var(--f-body);
  background: var(--rack-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 8px;
}
.ctrl input[type="text"] { font-family: var(--f-display); font-size: 16px; letter-spacing: 0.02em; }
.ctrl input[type="text"]:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.toggle input { accent-color: var(--brass); width: 16px; height: 16px; }
input[type="color"] {
  width: 100%; height: 34px; padding: 2px;
  background: var(--rack-2); border: 1px solid var(--line); border-radius: 6px;
}
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line); cursor: pointer; padding: 0;
}
.swatches button[aria-pressed="true"] { border-color: var(--ink); }

.note { font-size: 12.5px; color: var(--muted); margin: 0; }
.note.ok { color: var(--ok); }
.note.warn { color: var(--warn); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; }

.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--rack-2); color: var(--ink);
  border: 1px solid var(--brass-dim);
  padding: 9px 14px; border-radius: 6px; font-size: 14px;
  max-width: calc(100% - 32px);
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100%; grid-template-rows: auto auto; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .well { height: 58vh; min-height: 340px; }
  .rack { overflow: visible; }
  .brand h1 { font-size: 22px; }
  .hint { display: none; }
  /* Header: title on its own line, then every action on one row. */
  .brand { flex-basis: 100%; }
  header { gap: 8px; }
  header > .btn { flex: 1 1 auto; padding-inline: 10px; }
  .wide-only { display: none; }
  /* The readout sits under the view rather than over the foot. */
  .well { display: flex; flex-direction: column; }
  .well canvas { flex: 1 1 auto; min-height: 0; height: auto; }
  .readout { position: static; padding: 8px 12px; gap: 4px 14px; border-top: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

[hidden] { display: none !important; }

/* Across the benches: the way back to the workshop, which part this is, and the notice on a part the project can't take. */
.brand a.back { color: var(--brass); text-decoration: none; font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.brand a.back:hover { text-decoration: underline; }
.brand h1 a { color: inherit; text-decoration: none; }
.blocked {
  position: absolute; inset: 0; margin: 0;
  display: grid; place-content: center; gap: 12px; padding: 24px; text-align: center;
  background: color-mix(in srgb, var(--bench) 82%, transparent);
}
.blocked p { margin: 0; max-width: 34em; }
.blocked a { color: var(--brass); }
.rack[inert] { opacity: 0.4; }
.parts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.parts li { display: flex; align-items: baseline; gap: 10px; }
.parts li a { font-family: var(--f-display); font-size: 18px; color: var(--ink); text-decoration: none; }
.parts li a:hover { color: var(--brass); }
.parts li span { margin-left: auto; font-size: 13px; color: var(--muted); text-align: right; }
.parts li.off a { color: var(--muted); }
.empty { position: absolute; inset: 0; margin: 0; display: grid; place-content: center; padding: 24px; text-align: center; color: var(--muted); }
.empty a { color: var(--brass); }

/* Handles on the model: brass grips laid over the view that change a setting when dragged. */
.handles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 1; }
/* The view's own buttons stay on top of any handle that drifts under them. */
.views, .well-tools { z-index: 2; }
.handles .guide { position: absolute; inset: 0; width: 100%; height: 100%; }
.handles .guide line { stroke: var(--brass); stroke-width: 1.5; stroke-dasharray: 3 5; stroke-linecap: round; opacity: 0.75; }
.handle {
  position: absolute; left: 0; top: 0;
  width: 34px; height: 34px; margin: -17px 0 0 -17px;
  padding: 0; border: 0; background: none; cursor: grab;
  pointer-events: none; touch-action: none;
  display: grid; place-items: center;
  opacity: 0; transition: opacity 0.15s ease;
}
.handle.near, .handle:focus-visible { opacity: 1; pointer-events: auto; }
.handle::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f6dc9c, var(--brass) 55%, var(--brass-dim));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--bench) 75%, transparent), 0 1px 4px rgba(0, 0, 0, 0.6);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
/* Handles that slide along the wood are lozenges; the ones that set a width are round. */
.handle.axial::before { border-radius: 3px; transform: rotate(45deg); width: 11px; height: 11px; }
.handle.on::before, .handle.lit::before, .handle:focus-visible::before { box-shadow: 0 0 0 2px var(--bench), 0 0 0 4px var(--brass), 0 0 14px color-mix(in srgb, var(--brass) 70%, transparent); }
.handle.on::before { transform: scale(1.25); }
.handle.axial.on::before { transform: rotate(45deg) scale(1.25); }
.handle:focus-visible { outline: none; }
.handle.drag { cursor: grabbing; }
.handles.dragging, .handles.dragging .handle { cursor: grabbing; }
.handles.dragging .handle:not(.drag) { opacity: 0; pointer-events: none; }
.handles .chip {
  position: absolute; left: 0; top: 0;
  display: flex; align-items: baseline; gap: 8px;
  padding: 5px 6px 5px 10px; border-radius: 6px;
  background: color-mix(in srgb, var(--bench) 88%, transparent);
  border: 1px solid var(--brass-dim);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  pointer-events: auto; white-space: nowrap;
  font-size: 12.5px; color: var(--muted);
}
.chip-val {
  font: 500 12.5px/1 var(--f-mono); color: var(--brass); font-variant-numeric: tabular-nums;
  background: none; border: 0; border-bottom: 1px dashed var(--brass-dim); padding: 2px 2px; cursor: text;
}
.chip-val:hover { color: var(--ink); }
.chip-in {
  width: 7ch; font: 500 12.5px/1 var(--f-mono); color: var(--ink);
  background: var(--rack-2); border: 1px solid var(--brass); border-radius: 4px; padding: 3px 5px;
}
.well-tools { position: absolute; top: 10px; right: 10px; display: flex; align-items: center; gap: 10px; }
.well-tools .hint { position: static; }
.well-btn {
  font: 500 12px/1 var(--f-body); letter-spacing: 0.04em;
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--muted); cursor: pointer;
  background: color-mix(in srgb, var(--bench) 70%, transparent);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px;
}
.well-btn .dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--muted); }
.well-btn[aria-pressed="true"] { color: var(--ink); }
.well-btn[aria-pressed="true"] .dot { background: var(--brass); border-color: var(--brass); }
.well-btn:hover { border-color: var(--brass-dim); }
.well-btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
/* The slider a handle stands for lights while the handle is in use. */
.ctrl { border-radius: 6px; transition: background-color 0.15s ease, box-shadow 0.15s ease; }
.ctrl.lit { background: color-mix(in srgb, var(--brass) 10%, transparent); box-shadow: 0 0 0 6px color-mix(in srgb, var(--brass) 10%, transparent); }
.ctrl.lit label { color: var(--brass); }
@media (max-width: 820px) {
  .well-tools .hint { display: none; }
  .handle { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
  .handle::before { width: 15px; height: 15px; }
  .handle.axial::before { width: 13px; height: 13px; }
}
@media (prefers-reduced-motion: reduce) { .handle, .handle::before, .ctrl { transition: none; } }
@media (hover: none) { #btn-handles { display: none; } }
