/* MachQuote: minimal and precise, in a dark, high-contrast theme.
   One neutral palette, hairline rules, square corners, tabular numerals, and registration marks (the corner ticks on
   a technical drawing) as the single recurring motif. Colour is kept for meaning: red = can't be made, orange =
   selected, pink/blue/green = surface marks. */
:root {
  color-scheme: dark;
  --bg: #16181c;            /* page: dark grey, not black, so it's easy on the eyes */
  --stage: #1d2025;
  --ink: #e9ebee;           /* text: soft white, never pure #fff */
  --on-ink: #14161a;        /* text on top of an ink-coloured button */
  --dim: #aab0b8;           /* secondary text, still ~8:1 against the page */
  --rule: #343840;          /* hairline */
  --faint: #22262c;         /* hover and selected fills */
  --line: #4a4f58; --hover: #ffffff; --over: rgba(255,255,255,.05); --bar: #272b32;
  --p1: #4a4f58; --p2: #30343b; --p3: #23262c;
  --cross: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='25' height='25'%3E%3Cpath d='M12.5 1v23M1 12.5h23' stroke='%23000' stroke-width='4'/%3E%3Cpath d='M12.5 1v23M1 12.5h23' stroke='%23ffd23f' stroke-width='1.6'/%3E%3C/svg%3E");
  --grab: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='25' height='25'%3E%3Ccircle cx='12.5' cy='12.5' r='6' fill='none' stroke='%23000' stroke-width='4'/%3E%3Ccircle cx='12.5' cy='12.5' r='6' fill='none' stroke='%23ffd23f' stroke-width='1.8'/%3E%3C/svg%3E");
  --focus: #7ea2ff;
  --bad: #ff8d84;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7; --stage: #e6e8ec; --ink: #16181c; --on-ink: #f4f5f7; --dim: #4a515b; --rule: #cfd3d9; --faint: #eceef1;
  --focus: #1d4ed8; --bad: #b3261e;
  --line: #8a909a; --hover: #000000; --over: rgba(0,0,0,.05); --bar: #e6e8ec;
  --p1: #8a909a; --p2: #b4b9c1; --p3: #cfd3d9;
  --cross: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='25' height='25'%3E%3Cpath d='M12.5 1v23M1 12.5h23' stroke='%23fff' stroke-width='4'/%3E%3Cpath d='M12.5 1v23M1 12.5h23' stroke='%23000' stroke-width='1.6'/%3E%3C/svg%3E");
  --grab: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='25' height='25'%3E%3Ccircle cx='12.5' cy='12.5' r='6' fill='none' stroke='%23fff' stroke-width='4'/%3E%3Ccircle cx='12.5' cy='12.5' r='6' fill='none' stroke='%23000' stroke-width='1.8'/%3E%3C/svg%3E");
}
.theme-btn { position: absolute; top: 14px; right: 16px; z-index: 30; width: 36px; height: 36px; display: grid; place-items: center;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 0; cursor: pointer; padding: 0; }
.theme-btn:hover { background: var(--faint); }
.theme-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.theme-btn .sun { display: none; } :root[data-theme="light"] .theme-btn .sun { display: block; } :root[data-theme="light"] .theme-btn .moon { display: none; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.6 var(--font); -webkit-text-size-adjust: 100%;
  font-feature-settings: "tnum" 1, "cv11" 1; -webkit-font-smoothing: antialiased; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--ink); color: var(--on-ink); }

.layout { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(380px, 1fr); min-height: 100vh; }

/* ---------- viewer ---------- */
.stage { position: sticky; top: 0; height: 100vh; height: 100dvh; background: var(--stage); border-right: 1px solid var(--rule); }
#view { position: absolute; inset: 0; }
#view canvas { display: block; width: 100%; height: 100%; }
.brand { position: absolute; left: 32px; top: 28px; font: 600 14px/1 var(--font); letter-spacing: -.01em; z-index: 1; }

/* registration marks: four corner ticks instead of a dashed box */
.drop {
  --t: linear-gradient(var(--ink), var(--ink));
  position: absolute; inset: 32px; margin-top: 72px; display: grid; place-items: center; text-align: center; cursor: pointer; padding: 24px;
  background:
    var(--t) 0 0 / 18px 1px no-repeat, var(--t) 0 0 / 1px 18px no-repeat,
    var(--t) 100% 0 / 18px 1px no-repeat, var(--t) 100% 0 / 1px 18px no-repeat,
    var(--t) 0 100% / 18px 1px no-repeat, var(--t) 0 100% / 1px 18px no-repeat,
    var(--t) 100% 100% / 18px 1px no-repeat, var(--t) 100% 100% / 1px 18px no-repeat;
  transition: background-color .15s;
}
.drop:focus-within { outline: 2px solid var(--focus); outline-offset: 4px; }
.drop.over { background-color: var(--over); }
.drop.has-part { inset: auto 32px 28px auto; margin: 0; padding: 9px 14px; background: var(--bg); border: 1px solid var(--line); }
.drop strong { display: block; font: 500 22px/1.2 var(--font); letter-spacing: -.02em; margin-bottom: 6px; }
.drop span { color: var(--dim); font-size: 14px; }
.drop.has-part strong { display: none; }
.drop.has-part span { color: var(--ink); }
#file { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.hint { position: absolute; left: 32px; bottom: 28px; color: var(--dim); font-size: 13px; }
.hint[hidden], .nogl[hidden] { display: none; }
.nogl { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--dim); }

/* ---------- sheet ---------- */
.sheet { padding: 28px 48px 64px; max-width: 600px; }
h1 { font: 500 22px/1.2 var(--font); letter-spacing: -.02em; margin: 0 0 4px; overflow-wrap: anywhere; }
.sub { color: var(--dim); margin: 0 0 28px; }
form.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 16px; margin-bottom: 32px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--dim); }
select, input[type=number], input[type=text] {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 0;
  height: 42px; padding: 0 12px; width: 100%; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 17px) 18px, calc(100% - 12px) 18px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
select:hover, input:hover { border-color: var(--ink); }
select:focus, input:focus, textarea:focus { border-color: var(--ink); outline: 2px solid var(--focus); outline-offset: 1px; }
textarea { border-radius: 0; }

.block { border-top: 1px solid var(--rule); padding-top: 20px; margin-top: 28px; }
.block h2 { font: 600 14px/1.3 var(--font); margin: 0 0 12px; letter-spacing: 0; }

/* price: the one large thing on the page */
.price { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.price .big { font: 400 72px/1 var(--font); letter-spacing: -.045em; color: var(--ink); }
.price .each { color: var(--dim); font-size: 14px; }
.num, .tot, td, th, .facts dd { font-variant-numeric: tabular-nums; }
.tot { color: var(--dim); margin: 6px 0 0; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 8px 0; border-bottom: 1px solid var(--rule); }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 500; color: var(--dim); font-size: 13px; }
tr.sel td { font-weight: 600; background: var(--faint); }
tr.sel td:first-child { box-shadow: inset 2px 0 0 var(--ink); padding-left: 10px; }

.facts { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 0 24px; margin: 0; }
.facts dt, .facts dd { padding: 8px 0; border-bottom: 1px solid var(--rule); }
.facts dt { color: var(--dim); }
.facts dd { margin: 0; }

.warn { border-left: 2px solid var(--ink); padding: 2px 0 2px 12px; margin: 0 0 10px; }
.err { border-left: 2px solid var(--bad); color: var(--bad); padding: 2px 0 2px 12px; margin-top: 20px; }
.note { color: var(--dim); font-size: 13px; margin-top: 24px; }
.busy { opacity: .4; transition: opacity .15s; }
.empty { color: var(--dim); }
.working::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; vertical-align: -1px;
  border: 1.5px solid var(--ink); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.beta { margin: 8px 0 0; font-size: 13px; line-height: 1.45; color: var(--dim); }

.foot { border-top: 1px solid var(--rule); margin-top: 48px; padding-top: 16px; color: var(--dim); font-size: 13px; }
.foot p { margin: 0 0 8px; }

/* ---------- buttons: one family ---------- */
.fix, .tbtn, .mini, .builder-row button, .pickbar button, .preset {
  font: inherit; font-size: 15px; border-radius: 0; cursor: pointer; transition: background-color .12s, color .12s, border-color .12s;
}
.builder-row button, .pickbar button { background: var(--ink); color: var(--on-ink); border: 1px solid var(--ink); height: 42px; padding: 0 18px; font-weight: 600; }
.builder-row button:hover, .pickbar button:hover { background: var(--hover); }
.builder-row .secondary, .tbtn, .mini, .fix { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.builder-row .secondary:hover, .tbtn:hover, .mini:hover:not(:disabled), .fix:hover { border-color: var(--ink); background: var(--bg); }
.tbtn[aria-pressed="true"], .selrow button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); font-weight: 600; }
.mini { height: 34px; padding: 0 12px; font-size: 14px; }
.mini:disabled { opacity: .4; cursor: default; }
.linkbtn { font: inherit; background: none; border: 0; padding: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.linkbtn:hover { text-decoration-thickness: 2px; }
.cnt { color: var(--dim); font-size: 13px; min-width: 70px; }
.check { display: flex; align-items: center; gap: 8px; grid-column: 1 / -1; }
.check input { width: auto; }

.fixes { display: grid; gap: 8px; margin-top: 12px; }
.fix { display: grid; gap: 2px; text-align: left; padding: 12px 14px; height: auto; }
.fix strong { font-weight: 600; }
.fix span { color: var(--dim); font-size: 14px; }
.fix.cancel { text-align: center; color: var(--dim); }

/* ---------- surface marks ---------- */
.marks { border-top: 1px solid var(--rule); margin: 28px 0 32px; padding-top: 20px; }
.marks h2 { font: 600 13px/1.3 var(--font); margin: 0 0 4px; }
.marks .note { margin: 0 0 12px; }
.tool { display: grid; grid-template-columns: 168px minmax(0, 1fr) 128px; align-items: center; gap: 8px; margin: 8px 0; }
.tool .cnt { grid-column: 2 / -1; margin-top: -4px; min-width: 0; }
.tool .cnt:empty { display: none; }
.tbtn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; }
.tool select { min-width: 0; height: 36px; font-size: 14px; padding-left: 10px; }
.tool .mini { white-space: nowrap; }
.sw { width: 10px; height: 10px; flex: none; }
.sw.pink { background: #e0529c; } .sw.blue { background: #2f6fd6; } .sw.green { background: #2a9d5c; }
.mk { margin: 0 0 4px; }
.stage.picking canvas { cursor: var(--cross) 12 12, crosshair; }
.stage canvas { cursor: var(--grab) 12 12, grab; }
.stage canvas:active { cursor: var(--grab) 12 12, grabbing; }
#clearMarks { margin: 8px 0 0; }
.pickbar[hidden], .pricebar[hidden] { display: none !important; }

/* ---------- make / change a part ---------- */
.maker, .builder { margin: 0 0 32px; padding: 20px 0 0; border-top: 1px solid var(--rule); }
.maker h2 { font: 600 13px/1.3 var(--font); margin: 0 0 4px; }
.maker .note { margin: 0 0 14px; }
.builder > label { display: block; font: 600 13px/1.3 var(--font); color: var(--ink); margin-bottom: 4px; }
.builder .note { margin: 0 0 10px; }
.builder textarea, .maker textarea { width: 100%; font: 14px/1.5 var(--mono); padding: 10px 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); resize: vertical; min-height: 4.5em; }
.builder-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.builder-hint { color: var(--dim); font-size: 13px; flex: 1 1 220px; }
.builder-help { margin-top: 12px; font-size: 13px; color: var(--dim); }
.builder-help summary { cursor: pointer; }
.builder-help summary:hover { color: var(--ink); }
.builder-help ul { margin: 8px 0 0; padding-left: 16px; }
.builder-help li { margin-bottom: 4px; }
.builder-msg { margin-top: 12px; font-size: 13px; color: var(--ink); }
.builder-msg:empty { display: none; }
.builder-msg.bad { color: var(--bad); }
.builder-note { color: var(--dim); }
.changer[hidden] { display: none; }
.builder-row a.linkbtn { align-self: center; margin-left: 4px; font-size: 13px; }
.selrow { margin: 10px 0; }
.maker .typed { margin-top: 14px; }
.maker .typed textarea { margin-top: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px 12px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); font-weight: 500; }
.preset svg { width: 100%; max-width: 92px; height: auto; }
.preset .f1, .preset .f2, .preset .f3 { stroke: var(--ink); stroke-width: 1.1; stroke-linejoin: round; }
.preset .f1 { fill: var(--p1); } .preset .f2 { fill: var(--p2); } .preset .f3 { fill: var(--p3); }
.preset:hover { border-color: var(--ink); }
.preset[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.preset-form { margin-top: 14px; }
.preset-form[hidden] { display: none; }
.preset-fields { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.preset-fields label { display: flex; flex-direction: column; gap: 6px; flex: 1 1 90px; }

/* ---------- phones and tablets ---------- */
@media (max-width: 900px) {
  /* The model stays pinned at the top while you scroll the options and price below it. */
  .layout { display: block; }
  .stage { position: sticky; top: 0; z-index: 5; height: 40vh; height: 40dvh; min-height: 240px; border-right: 0; border-bottom: 1px solid var(--rule); transition: height .2s ease, min-height .2s ease; }
  .brand { left: 16px; top: 14px; }
  .sheet { padding: 24px 16px calc(84px + env(safe-area-inset-bottom)); max-width: none; }
  .drop { inset: 16px; margin-top: 40px; padding: 16px; }
  .drop.has-part { inset: auto 16px 16px auto; margin: 0; }
  .drop strong { font-size: 20px; }
  .hint { left: 16px; bottom: 16px; }
  .price .big { font-size: 60px; }
  h1 { font-size: 20px; }
  /* 16px inputs stop iOS from zooming the page on focus; 44px targets for fingers */
  select, input[type=number], input[type=text] { font-size: 16px; height: 46px; }
  select { background-position: calc(100% - 17px) 20px, calc(100% - 12px) 20px; }
  .tbtn, .fix, .mini, .builder-row button { min-height: 44px; }
  .mini { padding: 0 14px; }
  .tool { grid-template-columns: 1fr auto; }
  .tbtn { grid-column: 1 / -1; }
  .tool select { height: 44px; }
  .tool .cnt { grid-column: 1 / -1; }
  .stage.picking .drop.has-part, .stage.picking .hint { display: none; }
  /* Keyboard up before any model exists: the empty viewer shrinks to a slim bar so the fields stay in view. */
  .stage.compact { height: 52px; min-height: 52px; overflow: hidden; }
  .stage.compact .drop, .stage.compact .hint, .stage.compact .nogl, .stage.compact #view { display: none; }
  .pickbar { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 10px; justify-content: space-between;
    background: var(--bg); border: 1px solid var(--ink); padding: 6px 6px 6px 12px; font-size: 13px; z-index: 2; }
  .pickbar button { height: 40px; }
  .pricebar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; align-items: baseline; justify-content: space-between;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--bar); color: var(--ink); border-top: 1px solid var(--line); cursor: pointer; }
  .pricebar #pbPrice { font: 400 22px/1 var(--font); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
  .pricebar #pbNote { font-size: 13px; opacity: .75; }
}
@media (max-width: 480px) {
  form.opts { grid-template-columns: 1fr; }
}
@media (min-width: 901px) { .pickbar, .pricebar { display: none !important; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Loading veil: blurs the viewer while a part is being read or built */
.loading { position: absolute; inset: 0; z-index: 8; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: color-mix(in srgb, var(--stage) 55%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  color: var(--ink); font-size: 15px; letter-spacing: .01em; }
.loading[hidden] { display: none; }
.spin { width: 34px; height: 34px; border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: mqspin .8s linear infinite; }
@keyframes mqspin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2.4s; } }
.stage.compact .loading { display: none; }

/* Units toggle: two squares, the selected one filled */
.units { display: flex; align-items: center; gap: 0; margin: -4px 0 22px; font-size: 13px; color: var(--dim); }
.units[hidden] { display: none; }
.units span { margin-right: 10px; }
.units button { height: 28px; min-width: 44px; padding: 0 12px; font: 500 13px var(--font); background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 0; cursor: pointer; }
.units button + button { margin-left: -1px; }
.units button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

/* Section titles: a solid rule above, generous space, and a heading you can find at a glance */
.block, .marks, .maker, .builder { border-top: 1px solid var(--ink); margin: 44px 0 0; padding-top: 16px; }
.block h2, .marks h2, .maker h2, .builder > label { display: block; font: 650 17px/1.3 var(--font); letter-spacing: -.005em; color: var(--ink); margin: 0 0 10px; }
.opts + .marks, .opts + .maker { margin-top: 36px; }
.builder.changer { margin-bottom: 8px; }

.builder-row .mini { background: var(--bg); color: var(--ink); border: 1px solid var(--line); font-weight: 500; }
.builder-row .mini:hover:not(:disabled) { border-color: var(--ink); background: var(--bg); }
.builder-row .mini:disabled { color: var(--dim); opacity: .6; cursor: default; }
.builder.changer { margin-bottom: 40px; }
