:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #202923;
  background: #f7f7f1;
  font-size: 16px;
  --line: #d8ddd3;
  --ink: #202923;
  --muted: #59665d;
  --accent: #18583e;
  --surface: #fffef9;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, h3, p { margin: 0; }
button, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid #a35a23;
  outline-offset: 3px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 19px clamp(20px, 5vw, 74px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 760; letter-spacing: -.04em; }
.mark { display: grid; grid-template-columns: repeat(2, 5px); gap: 3px; background: var(--accent); padding: 5px; border-radius: 4px; }
.mark i { height: 5px; border-radius: 50%; background: #d3ebd4; }
.edition, .eyebrow { color: var(--accent); font-size: 11px; font-weight: 730; letter-spacing: .1em; text-transform: uppercase; }

main { max-width: 1370px; margin: 0 auto; padding: 37px clamp(20px, 5vw, 74px) 64px; }
.intro, .section-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.intro { margin-bottom: 24px; }
h1 { font-size: clamp(36px, 5vw, 61px); line-height: 1.08; letter-spacing: -.06em; margin: 8px 0 9px; }
h2 { font-size: 21px; letter-spacing: -.025em; }
h3 { font-size: 17px; line-height: 1.25; }
.hint { color: var(--muted); font-size: 14px; line-height: 1.45; }
.actions, .editor-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.primary, .secondary, .quiet {
  min-height: 39px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 13px;
  color: var(--ink);
  font-weight: 630;
  font-size: 13px;
  transition: background-color 150ms, border-color 150ms;
}
.primary { color: white; background: var(--accent); }
.primary:hover:not(:disabled) { background: #10442f; }
.secondary { background: var(--surface); border-color: var(--line); }
.secondary:hover:not(:disabled), .secondary[aria-pressed="true"] { background: #e5eee3; border-color: #afc2ae; }
.quiet { background: transparent; color: var(--muted); padding-inline: 5px; }
.quiet:hover:not(:disabled) { color: #942729; }

.results { margin-top: 24px; }
.section-head { margin-bottom: 12px; }
.section-head h2 { font-size: clamp(22px, 3vw, 30px); }
.result-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.meta { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
#status { max-width: 48ch; margin-bottom: 12px; }
#status:empty { display: none; }
.model-list { border-top: 1px solid var(--line); }
.model-list:empty { border: 0; }
.model {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  align-items: center;
  gap: 15px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  animation: reveal 180ms ease-out;
}
.model-art { display: grid; place-items: center; height: 86px; background: #e9ede4; border-radius: 5px; }
.model-art svg, .model-art img { width: 85%; height: 72px; object-fit: contain; }
.model-info p { margin-top: 4px; font-size: 13px; }

dialog {
  max-width: min(550px, calc(100vw - 24px));
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 20px;
  color: var(--ink);
  background: var(--surface);
}
dialog::backdrop { background: #17281f94; }
.dialog-head, .step-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h2 { margin-top: 4px; }
#model-catalog { max-width: min(980px, calc(100vw - 24px)); }
.model-catalog-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 14px;
}
.model-catalog-filter select { min-width: 0; max-width: 100%; }
.model-catalog-list {
  max-height: min(63dvh, calc(100dvh - 200px));
  overflow-y: auto;
  padding: 2px 4px;
  margin: 12px 0 0;
}
.model-catalog-group + .model-catalog-group {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.model-catalog-group h3 { margin: 0 0 8px; }
.model-catalog-group h3 .hint { margin-inline-start: 6px; font-weight: 400; }
.model-catalog-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(128px, 100%), 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.model-catalog-cards > li { display: grid; grid-template-rows: 1fr auto; gap: 4px; }
#model-catalog-status { margin-top: 8px; }
.catalog-model-delete { justify-self: start; min-height: 34px; font-size: 13px; color: #8b352b; }
.catalog-model {
  display: grid;
  align-content: start;
  gap: 5px;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: inherit;
  background: var(--surface);
  text-align: left;
}
.catalog-model:hover { border-color: var(--accent); }
.catalog-model-name { font-weight: 630; line-height: 1.25; }
.catalog-model .hint { font-size: 12px; }
.catalog-model .model-art { height: 104px; margin-bottom: 3px; }
.catalog-model .model-art svg, .catalog-model .model-art img { height: 96px; }
#parts-dialog { max-width: min(820px, calc(100vw - 24px)); }
.parts-search { display: grid; gap: 6px; margin-block: 16px 8px; font-size: 14px; }
.parts-search input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: inherit;
  background: var(--surface);
  font: inherit;
}
.parts-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  align-content: start;
  gap: 8px;
  max-height: 49dvh;
  overflow: auto;
  list-style: none;
  padding: 0;
  margin-block: 12px;
}
.parts-list li {
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
  overflow-wrap: anywhere;
  font-size: 13px;
}
.parts-list img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; margin-bottom: 5px; }
.parts-credit { margin-top: 12px; font-size: 12px; }
.parts-credit a { color: var(--accent); }
.step-graphic { display: grid; place-items: center; height: 215px; margin: 13px 0; border-radius: 6px; background: #e9ede4; }
.step-graphic svg, .step-graphic img { width: 95%; height: 205px; object-fit: contain; animation: reveal 180ms ease-out; }
.assembly-view { position: relative; height: clamp(220px, 40dvh, 400px); margin: 13px 0; overflow: hidden; border-radius: 6px; background: #e9ede4; }
.assembly-view canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.assembly-view canvas:focus-visible { outline: 3px solid #a35a23; outline-offset: -4px; }
.assembly-view[aria-busy="true"] canvas { opacity: 0.35; pointer-events: none; }
#step-view-status { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; pointer-events: none; }
.assembly-hint { margin: 4px 0 10px; font-size: 12px; }
#step-view-toggle { min-width: 44px; }
#step-view-toggle[aria-pressed="true"] { background: #deebe1; color: var(--accent); }
.step-links { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 16px; font-size: 13px; }
.step-links a { color: var(--accent); }
#step-caption:empty { display: none; }
.build-source { font-size: 12px; margin-top: 10px; }
.build-source a { color: var(--accent); }
@keyframes reveal { from { opacity: .5; transform: translateY(3px); } }
.step-parts { padding-left: 17px; font-size: 13px; color: var(--muted); }
.substitution { display: block; margin-top: 3px; }
.photo-viewer {
  max-width: min(1100px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
}
.photo-viewer .eyebrow { overflow-wrap: anywhere; }
.photo-layout { display: grid; gap: 12px; margin-top: 13px; }
.photo-layout:has(.inventory:not([hidden])) { grid-template-columns: minmax(0, 1fr) minmax(180px, 245px); }
.location {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 4px;
  border-radius: 6px;
  background: #e9ede4;
}
.location svg { display: block; width: 100%; height: min(62dvh, 640px); }
.inventory { min-width: 0; padding: 6px 0 0; }
.inventory .hint { margin-top: 8px; }
.recognized { list-style: none; padding: 0 4px; margin: 8px 0; max-height: 54dvh; overflow: auto; }
.recognized-piece {
  width: 100%;
  min-height: 38px;
  margin-bottom: 3px;
  padding: 6px 9px;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--ink);
  background: transparent;
  text-align: start;
  font-size: 13px;
}
.recognized-piece:hover, .recognized-piece[aria-pressed="true"] { border-color: var(--line); background: #e5eee3; }
.photo-controls { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; }
.photo-controls button { flex-shrink: 0; }
.bill { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.bill summary { cursor: pointer; }
.bill ul { margin: 6px 0; padding-left: 18px; }
.step-controls { border-top: 1px solid var(--line); padding-top: 12px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; }
}
@media (max-width: 780px) {
  main { padding-top: 25px; }
  .intro { flex-direction: column; align-items: start; gap: 10px; }
  .section-head { align-items: start; flex-direction: column; gap: 8px; }
  .photo-layout:has(.inventory:not([hidden])) { grid-template-columns: minmax(0, 1fr); }
  .photo-layout:has(.inventory:not([hidden])) .location svg { height: 40dvh; }
  .recognized { max-height: 20dvh; }
}
@media (max-width: 410px) {
  main { padding-inline: 12px; }
  .top { padding-inline: 12px; }
  .model { grid-template-columns: 70px minmax(0, 1fr) auto; gap: 8px; }
  .model-art { height: 66px; }
  .model-art svg, .model-art img { height: 57px; }
  .model button { padding-inline: 8px; }
}

.label-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); gap: 16px; margin-top: 12px; }
.label-layout .location svg { height: min(70dvh, 720px); }
.label-panel { display: grid; align-content: start; gap: 10px; min-width: 0; }
.candidates { display: grid; gap: 6px; list-style: none; padding: 0; margin: 0; }
.candidate {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 60px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  text-align: start;
  font-size: 14px;
}
.candidate:hover, .candidate[aria-pressed="true"] { background: #e5eee3; border-color: #afc2ae; }
.candidate img { width: 64px; height: 48px; object-fit: contain; }
.candidate span { display: grid; gap: 2px; min-width: 0; }
.custom-article { display: grid; gap: 6px; font-size: 14px; }
.custom-article div { display: flex; gap: 6px; }
.custom-article input {
  flex: 1;
  min-width: 0;
  min-height: 39px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: inherit;
  background: var(--surface);
  font: inherit;
}
.top a.edition { text-decoration: none; }
#sets { min-height: 32px; margin-left: 4px; }
@media (max-width: 780px) {
  .label-layout { grid-template-columns: minmax(0, 1fr); }
  .label-layout .location svg { height: 42dvh; }
}
