/* Layout: a three-pane counter. Menu board on the left, the print bed in the
   middle, the build ticket on the right. Stacks to one column on phones. */
:root {
  --bg: #e6e8e3;
  --surface: #f7f8f5;
  --surface-2: #eceee8;
  --ink: #1d211f;
  --muted: #5b645e;
  --line: #d2d6cf;
  --accent: #e2a11b;
  --accent-soft: #f6e3b6;
  --accent-ink: #1d1a10;
  --warn: #b93a2a;
  --ok: #4a7a2c;
  --stage-hi: #f5f6f2;
  --stage-lo: #d6dad2;
  --bed: #2f3431;
  --bed-line: #737b75;
  --display: "Bowlby One", "Arial Black", "Helvetica Neue", sans-serif;
  --body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111412;
    --surface: #191d1a;
    --surface-2: #222723;
    --ink: #eceeea;
    --muted: #9aa39c;
    --line: #2e3430;
    --accent: #f0b12e;
    --accent-soft: #3d3218;
    --accent-ink: #1a1505;
    --warn: #e7735f;
    --ok: #93c165;
    --stage-hi: #252a26;
    --stage-lo: #121513;
    --bed: #2b302c;
    --bed-line: #59625b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111412;
  --surface: #191d1a;
  --surface-2: #222723;
  --ink: #eceeea;
  --muted: #9aa39c;
  --line: #2e3430;
  --accent: #f0b12e;
  --accent-soft: #3d3218;
  --accent-ink: #1a1505;
  --warn: #e7735f;
  --ok: #93c165;
  --stage-hi: #252a26;
  --stage-lo: #121513;
  --bed: #2b302c;
  --bed-line: #59625b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--body);
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}
.hint { margin: 0; font-size: 13px; color: var(--muted); }

.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 340px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top top" "menu stage panel";
  gap: 0 16px;
  height: 100%;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 16px;
}

/* Top bar ---------------------------------------------------------------- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: baseline;
  gap: 8px 20px;
  flex-wrap: wrap;
  padding-block: 14px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-family: var(--display); font-size: clamp(18px, 5vw, 24px); letter-spacing: 0.01em; line-height: 1; }
.brand-mark {
  width: 26px; height: 22px; position: relative; align-self: center;
  background:
    linear-gradient(var(--accent), var(--accent)) 0 0 / 100% 9px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 0 11px / 100% 4px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 0 17px / 100% 5px no-repeat;
  border-radius: 13px 13px 4px 4px;
}
.tagline { margin: 0; color: var(--muted); font-size: 14px; }

/* Menu ------------------------------------------------------------------- */
.menu {
  grid-area: menu;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
}
.menu-head {
  display: flex; justify-content: space-between;
  padding: 2px 10px 6px;
  border-bottom: 2px solid var(--ink);
}
.menu-cat { padding-top: 14px; }
.menu-cat h2 { margin: 0 0 4px; padding: 0 10px; }
.menu-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.menu-item {
  width: 100%;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item[aria-pressed="true"] { background: var(--accent-soft); }
.thumb {
  width: 52px; height: 52px;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 40%, var(--stage-hi), var(--stage-lo));
  display: grid; place-items: center;
  overflow: hidden;
}
.thumb img { width: 52px; height: 52px; display: block; }
.thumb img:not([src]) { visibility: hidden; }
.menu-text { display: grid; min-width: 0; }
.menu-name { font-weight: 600; line-height: 1.25; }
.menu-meta { font: 11px/1.4 var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-grams { font: 500 13px var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); }

/* Stage ------------------------------------------------------------------ */
.stage-wrap { grid-area: stage; min-width: 0; min-height: 0; }
.stage {
  position: relative;
  height: 100%;
  border-radius: var(--radius);
  background: radial-gradient(120% 90% at 50% 30%, var(--stage-hi), var(--stage-lo));
  overflow: hidden;
}
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#view:active { cursor: grabbing; }

.item-card {
  position: absolute; top: 18px; left: 20px; right: 20px;
  pointer-events: none;
  max-width: 440px;
}
.item-card h1 {
  margin: 2px 0 4px;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.02;
  text-wrap: balance;
}
.item-card p { margin: 0; color: var(--muted); max-width: 40ch; }

.readout {
  position: absolute; left: 16px; bottom: 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(6px);
  max-width: calc(100% - 32px);
}
.readout div { display: flex; align-items: baseline; gap: 5px; }
.readout dt { font: 600 10px var(--body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.readout dd { margin: 0; font: 500 14px var(--mono); font-variant-numeric: tabular-nums; }
.readout small { font-size: 10px; color: var(--muted); margin-left: 2px; }
.chip {
  font: 600 11px var(--body);
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.chip[data-state="ok"] { color: var(--ok); }
.chip[data-state="warn"] { color: var(--warn); }

.toolbar {
  position: absolute; right: 16px; top: 18px;
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
}
.tool {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.tool:hover { border-color: var(--muted); }
.tool[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.tool-range { cursor: default; }
.tool-range input { width: 90px; accent-color: var(--accent); }

/* Panel ------------------------------------------------------------------ */
.panel {
  grid-area: panel;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px 18px 18px;
}
.block { display: grid; gap: 12px; padding-block: 16px; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: 0; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; }
.block-title { margin: 0; font-family: var(--display); font-weight: 400; font-size: 17px; letter-spacing: 0.01em; }
.options { display: grid; gap: 12px; }

.field { display: grid; gap: 6px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.field-head label, .field-label { font-weight: 600; font-size: 14px; }
.field output { font-size: 13px; color: var(--muted); }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.toggle { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  background: var(--surface);
}
.segmented label:hover { border-color: var(--muted); }
.segmented input:checked + label { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatches label { padding: 4px; border-radius: 50%; display: grid; place-items: center; }
.swatches input:checked + label { background: var(--surface); border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.swatch { width: 22px; height: 22px; border-radius: 50%; display: block; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.15); }

.parts { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.part {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
}
.part input[type="checkbox"] { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.part input[type="color"] {
  width: 26px; height: 26px; padding: 0;
  border: 1px solid var(--line); border-radius: 7px;
  background: none; cursor: pointer;
}
.part input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.part input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }
.part input[type="color"]::-moz-color-swatch { border: 0; border-radius: 5px; }
.part-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.part-tris { font-size: 11px; color: var(--muted); }
.part:has(input[type="checkbox"]:not(:checked)) .part-name { color: var(--muted); text-decoration: line-through; }

.formats { display: grid; gap: 6px; }
.formats input { position: absolute; opacity: 0; pointer-events: none; }
.format {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 8px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.format:hover { border-color: var(--muted); }
.formats input:checked + .format { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.formats input:focus-visible + .format { outline: 2px solid var(--accent); outline-offset: 2px; }
.format-name { font-weight: 700; }
.format-axis { font-size: 11px; color: var(--muted); align-self: center; }
.format-note { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); }

.btn-primary {
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--display);
  font-size: 16px;
  letter-spacing: 0.02em;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }
.btn-quiet {
  justify-self: start;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.btn-quiet:hover { border-color: var(--muted); }
.btn-link { border: 0; background: none; padding: 0; color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: underline; cursor: pointer; }
.status { margin: 0; min-height: 1.4em; font-size: 13px; }
.status[data-state="ok"] { color: var(--ok); }
.status[data-state="warn"] { color: var(--warn); }

/* Phones and narrow windows --------------------------------------------- */
@media (max-width: 980px) {
  body { overflow: auto; }
  html, body { height: auto; }
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "top" "stage" "menu" "panel";
    gap: 14px;
    height: auto;
  }
  .topbar { padding-bottom: 0; }
  .stage { height: min(68vh, 560px); min-height: 380px; }
  .menu { overflow: visible; padding-right: 0; }
  .menu-head { display: none; }
  #menu-list { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x proximity; }
  .menu-cat { padding-top: 0; flex: none; }
  .menu-items { display: flex; gap: 6px; }
  .menu-item {
    width: 124px;
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 4px;
    padding: 8px;
    background: var(--surface);
    scroll-snap-align: start;
  }
  .thumb, .thumb img { width: 72px; height: 72px; }
  .menu-meta { display: none; }
  .menu-name { font-size: 13px; }
  .menu-grams { font-size: 11px; color: var(--muted); }
  .toolbar { top: auto; bottom: 64px; right: 12px; left: 12px; flex-direction: row; flex-wrap: wrap; justify-content: flex-end; }
  .tool { min-height: 32px; padding: 5px 10px; font-size: 12px; }
  .tool-range input { width: 70px; }
  .readout { left: 12px; bottom: 12px; gap: 4px 10px; padding: 6px 10px; }
  .item-card { right: 12px; left: 16px; top: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
