:root {
  color-scheme: dark;
  --ink: #f4f0e8;
  --muted: #c0b8ab;
  --ground: #181714;
  --panel: #23211d;
  --control: #302d28;
  --line: #514b42;
  --gold: #ffc768;
  --mint: #9ee7bf;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.45 Inter, system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
a { color: var(--gold); text-underline-offset: 3px; }
h1, h2, p { margin: 0; }
button, .button, input, select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--control);
  color: var(--ink);
  font: inherit;
  padding: 7px 11px;
}
button, .button { cursor: pointer; font-weight: 650; }
button:hover, .button:hover { background: #403a30; }
button:disabled { opacity: .48; cursor: default; }
button[aria-pressed="true"], button[aria-selected="true"] {
  color: var(--gold);
  background: #44351e;
  border-color: #bd8c41;
}
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.primary, .primary:hover { background: var(--gold); color: #251a0b; border-color: var(--gold); }
.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 9px 20px;
  border-bottom: 1px solid #3d382e;
}
.top h1 { font-size: 25px; font-weight: 850; letter-spacing: -.03em; }
.top h1 span { color: var(--gold); }
.home { justify-self: start; color: var(--ink); font-weight: 650; font-size: .88rem; }
#mode { color: var(--muted); font-size: .83rem; }
.room-actions { justify-self: end; display: flex; align-items: center; gap: 10px; }
.workbench {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(290px, 26vw, 388px);
  gap: 10px;
  padding: 10px;
  min-height: 490px;
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px);
  background: var(--ground);
}
.workbench:fullscreen {
  width: 100%;
  height: 100%;
  min-height: 0;
}
.workbench.is-expanded {
  position: fixed;
  z-index: 10;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
}
body.workspace-expanded { overflow: hidden; }
.stage, .drawer {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.stage { position: relative; background: #34312d; }
.move-handles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.move-handles button {
  position: absolute;
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  display: grid;
  place-content: center;
  grid-auto-flow: column;
  align-items: center;
  gap: 4px;
  transform: translate(-50%, -50%);
  touch-action: none;
  user-select: none;
  cursor: grab;
  color: var(--axis-ink);
  background: #222520;
  border: 1px solid var(--axis-ink);
  border-radius: 50%;
  font-size: .76rem;
}
.move-handles button::before {
  content: "";
  width: 11px;
  height: 11px;
  background: currentColor;
  clip-path: polygon(0 40%, 65% 40%, 44% 15%, 57% 0, 100% 50%, 57% 100%, 44% 85%, 65% 60%, 0 60%);
  transform: rotate(var(--axis-angle, 0rad));
}
.move-handles [data-axis="0"] { --axis-ink: #ffb2a1; }
.move-handles [data-axis="1"] { --axis-ink: #b3efb8; }
.move-handles [data-axis="2"] { --axis-ink: #a9dcff; }
.move-handles button:hover, .move-handles button:active { background: #373b32; }
.move-handles button:active { cursor: grabbing; }
#view, #view canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.stage-top, .stage-bottom, .camera-tools {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.stage-top, .stage-bottom { inset-inline: 12px; }
.stage-top { top: 12px; justify-content: space-between; }
.stage-bottom { bottom: 12px; justify-content: space-between; flex-wrap: wrap; }
.stage button, .stage .button { pointer-events: auto; }
.stage-top .tools, .stage-bottom .actions, .camera-tools {
  gap: 2px;
  padding: 3px;
  background: #25231ff5;
  border: 1px solid #6a6253;
  border-radius: 10px;
}
.stage .tools button, .stage .actions button, .camera-tools button {
  border-color: transparent;
  background: transparent;
}
.stage .tools button:hover, .stage .actions button:hover, .camera-tools button:hover {
  background: #403a30;
}
.stage .tools button[aria-pressed="true"] {
  color: #251a0b;
  background: var(--gold);
}
.stage .actions .primary, .stage .actions .primary:hover {
  color: #251a0b;
  background: var(--gold);
}
.stage .tools button, .stage .actions button { font-size: .83rem; }
.camera-tools { right: 12px; top: 72px; flex-direction: column; }
.camera-tools button { width: 44px; padding: 4px; font-size: .82rem; }
.build-move {
  position: absolute;
  inset: auto 12px 87px auto;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 5px;
  border: 1px solid #6a6253;
  border-radius: 12px;
  background: #25231f;
}
.build-dpad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-areas: ". up ." "left down right";
  gap: 3px;
}
.build-dpad button { padding: 0; display: grid; place-items: center; }
.build-dpad button span {
  width: 9px;
  height: 9px;
  border: solid currentColor;
  border-width: 2px 0 0 2px;
  transform: rotate(45deg);
}
[data-build-move="up"] { grid-area: up; }
[data-build-move="left"] { grid-area: left; }
[data-build-move="down"] { grid-area: down; }
[data-build-move="right"] { grid-area: right; }
[data-build-move="left"] span { rotate: -90deg; }
[data-build-move="down"] span { rotate: 180deg; }
[data-build-move="right"] span { rotate: 90deg; }
.build-height { display: grid; gap: 3px; padding-left: 5px; border-left: 1px solid var(--line); }
.build-height button { padding-inline: 8px; font-size: .79rem; }
.build-lesson {
  position: absolute;
  inset: 71px auto auto 12px;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: min(370px, calc(100% - 86px));
  padding: 13px;
  border: 1px solid #a77a3c;
  border-radius: 12px;
  background: var(--panel);
}
.lesson-copy { flex: 1; min-width: 0; }
#guide-progress { color: var(--gold); font-size: .73rem; font-weight: 700; font-variant-numeric: tabular-nums; }
#guide-title { margin: 2px 0 4px; font-size: 1.02rem; }
#guide-copy { color: var(--muted); font-size: .82rem; }
#guide-close { padding-inline: 9px; font-size: .79rem; }
#guide-target {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 2px solid var(--gold);
  border-radius: 50%;
  background: #30291ccc;
}
#guide-target span {
  width: 12px;
  height: 12px;
  border: 2px solid var(--gold);
  border-radius: 50%;
}
.stage [data-guide-focus] { outline: 2px solid var(--gold); outline-offset: 3px; }
.tools, .actions, .transform, .place-row, .color-row, .pagination, .join-row, .file-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.tools, .actions, .transform, .place-row { flex-wrap: wrap; }
#count, #status {
  width: fit-content;
  background: #211e18;
  border-radius: 7px;
  padding: 6px 9px;
  color: #f8eedc;
  font-size: .8rem;
}
#status { flex: 0 0 auto; }
#count { margin-left: auto; border-color: #6a6253; font-variant-numeric: tabular-nums; }
#count:hover { background: #403a30; }
#status { max-width: 100%; }
.terrain-menu { position: relative; z-index: 1; pointer-events: auto; }
.terrain-menu summary {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 7px 10px;
  list-style: none;
  border: 1px solid #6a6253;
  border-radius: 9px;
  background: #25231ff5;
  cursor: pointer;
  font-size: .83rem;
  font-weight: 700;
}
.terrain-menu summary::-webkit-details-marker { display: none; }
.terrain-swatch {
  flex: none;
  width: 13px;
  height: 13px;
  border: 1px solid #f4f0e840;
  border-radius: 3px;
}
.terrain-panel {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  width: min(250px, calc(100vw - 26px));
  padding: 8px;
  background: var(--panel);
  border: 1px solid #746a5c;
  border-radius: 10px;
}
#terrains { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
#terrains button { display: flex; align-items: center; gap: 6px; text-align: left; font-size: .81rem; }
.grid-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 4px 2px;
  font-size: .82rem;
}
#open-baseplates { width: 100%; margin-top: 4px; font-size: .81rem; }
.button { display: inline-flex; align-items: center; }
.button input, .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  overflow: hidden;
  clip-path: inset(50%);
}
.button:focus-within { outline: 2px solid var(--gold); }
.drawer {
  background: var(--panel);
  display: flex;
  flex-direction: column;
}
.drawer-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  justify-content: space-between;
  padding: 13px 12px 8px;
}
.drawer h2, dialog h2 { font-size: 20px; letter-spacing: -.02em; }
#catalog-count, #part-id, .pagination span, footer { font-size: .8rem; color: var(--muted); }
.drawer-switch { display: flex; gap: 6px; padding: 0 12px 10px; }
.drawer-switch button { flex: 1; min-width: 0; padding-inline: 4px; font-size: .84rem; }
.filters { display: grid; gap: 6px; padding: 0 12px 8px; }
input, select { max-width: 100%; min-width: 0; }
input[type="search"], input[type="text"], select { width: 100%; font-size: 16px; background: #1b1916; }
input::placeholder { color: var(--muted); }
#close-parts, #open-parts { display: none; }
#quick-categories {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  flex: 0 0 auto;
  gap: 5px;
  padding: 0 12px 8px;
}
#quick-categories button { min-height: 34px; padding-inline: 3px; font-size: .76rem; }
#results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(132px, max-content);
  align-content: start;
  gap: 7px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 2px 12px 10px;
  scrollbar-color: #807463 var(--panel);
}
#results p { grid-column: 1 / -1; padding: 10px 0; color: var(--muted); }
.part-option {
  display: grid;
  grid-template-rows: 66px auto auto;
  width: 100%;
  min-width: 0;
  align-content: start;
  gap: 4px;
  padding: 7px;
  text-align: left;
  background: #2d2923;
  font-size: .77rem;
}
.part-option .thumbnail {
  display: grid;
  place-items: center;
  background: #1e1c19;
  border-radius: 5px;
  overflow: hidden;
}
.thumbnail img { display: block; width: 100%; height: 66px; object-fit: contain; }
.thumbnail img:not([src]) { visibility: hidden; }
.thumbnail-unavailable img { display: none; }
.thumbnail-unavailable::after { content: "No preview"; color: var(--muted); font-size: .72rem; }
#results.text-only-parts { grid-auto-rows: auto; }
.text-only-parts .part-option { grid-template-rows: auto auto; }
.text-only-parts .thumbnail { display: none; }
.part-option .part-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  min-height: 2.7em;
}
.part-option small { color: var(--muted); font-weight: 550; }
.part-option[data-current] { border-color: var(--gold); }
.pagination { justify-content: space-between; padding: 6px 12px 10px; }
.pagination button { font-size: .8rem; }
.properties { overflow: auto; padding: 4px 12px 14px; display: grid; align-content: start; gap: 13px; }
.used-parts { overflow: auto; min-height: 0; padding: 0 12px 14px; }
#used-summary, #used-empty { color: var(--muted); font-size: .83rem; padding: 7px 0; }
.used-parts table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: .81rem; }
.used-parts th { position: sticky; top: 0; background: var(--panel); color: var(--muted); text-align: left; }
.used-parts th, .used-parts td { padding: 9px 5px; border-bottom: 1px solid var(--line); }
.used-parts th:nth-child(2) { width: 86px; }
.used-parts th:last-child { width: 45px; }
.used-parts td:last-child, .used-parts th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.used-parts small { display: block; margin-top: 3px; color: var(--muted); }
.used-parts td { overflow-wrap: anywhere; }
.used-swatch { display: inline-block; width: 12px; height: 12px; margin-right: 5px; border: 1px solid #aaa192; border-radius: 3px; vertical-align: -2px; }
#natural-color { font-size: .8rem; }
.part-header { display: flex; gap: 10px; align-items: center; min-width: 0; }
.part-header h2 { font-size: .98rem; overflow-wrap: anywhere; }
#part-preview { width: 92px; height: 74px; flex: none; border-radius: 7px; background: #1e1c19; overflow: hidden; }
#part-preview canvas { display: block; width: 100%; height: 100%; }
.color-row input { width: 44px; padding: 4px; }
#swatches { display: flex; flex-wrap: wrap; gap: 4px; }
#swatches button { width: 32px; min-height: 36px; padding: 0; border-color: #a79a85; }
.transform button, .place-row button { font-size: .81rem; flex: 1; white-space: nowrap; }
.place-row label { font-size: .82rem; white-space: nowrap; }
.file-actions { border-top: 1px solid var(--line); padding-top: 12px; }
input[type="checkbox"] { min-height: 0; accent-color: var(--gold); }
footer { padding: 4px 20px 18px; display: grid; gap: 5px; }
dialog {
  width: min(440px, calc(100% - 24px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
}
dialog::backdrop { background: #141210ca; }
dialog p { margin: 10px 0; color: var(--muted); }
dialog label { display: block; margin: 10px 0 5px; }
dialog .actions { margin-top: 10px; }
dialog .close { float: right; }

@media (max-width: 1020px) {
  .workbench { grid-template-columns: minmax(0, 1fr); }
  #open-parts, #close-parts { display: inline-block; }
  .drawer {
    display: none;
    position: absolute;
    z-index: 2;
    right: 10px;
    top: 66px;
    bottom: 70px;
    width: min(370px, calc(100% - 20px));
    border-color: #746a5c;
  }
  .drawer.is-open { display: flex; }
  .workbench:has(.drawer.is-open) .stage-bottom .actions { visibility: hidden; }
  .workbench:has(.drawer.is-open) :is(.build-lesson, .build-move, #guide-target) { visibility: hidden; }
  .drawer-top { align-items: center; }
  .drawer-top h2 { margin-right: auto; }
}
@media (min-width: 700px) and (max-width: 1020px) {
  .filters { grid-template-columns: minmax(0, 1fr) 133px; }
  .filters select { font-size: .85rem; }
}
@media (max-width: 540px) {
  .top { padding: 7px 9px; gap: 6px; }
  .top h1 { font-size: 20px; white-space: nowrap; }
  .home, #mode { font-size: .73rem; }
  .room-actions { gap: 5px; }
  .room-actions button { font-size: .75rem; padding-inline: 7px; }
  #mode { display: none; }
  .workbench { padding: 5px; height: calc(100vh - 59px); height: calc(100dvh - 59px); min-height: 425px; }
  .workbench:fullscreen { height: 100%; min-height: 0; }
  .workbench.is-expanded { height: 100%; min-height: 0; }
  .stage-top, .stage-bottom { inset-inline: 5px; }
  .stage-top { top: 5px; }
  .stage-bottom { bottom: 5px; }
  .build-move { right: auto; bottom: 111px; left: 5px; }
  .build-lesson { top: 58px; left: 5px; }
  .stage button, .stage .button, .stage .tools button, .stage .actions button { font-size: .74rem; padding-inline: 6px; }
  .stage-bottom .actions { gap: 1px; padding: 2px; }
  .stage-top .tools { gap: 0; padding: 2px; }
  .terrain-menu summary { font-size: .74rem; padding-inline: 6px; }
  .terrain-menu summary .terrain-swatch { width: 10px; height: 10px; }
  .camera-tools { right: 5px; top: 60px; }
  .camera-tools button { width: 42px; }
  #count { font-size: .72rem; padding: 5px; }
  .stage-bottom:has(#selection-tools:not([hidden])) #count { margin-left: 0; }
  #status { flex-basis: 100%; width: auto; }
  .drawer { right: 6px; width: calc(100% - 12px); bottom: 85px; }
  footer { padding-inline: 10px; }
}
@media (max-height: 480px) {
  .drawer { top: 8px; bottom: 8px; }
  .build-move { bottom: 87px; }
}
