@font-face {
  font-family: 'Archivo RB';
  src: url('../fonts/archivo-wdth.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

:root {
  --ground: #e4e6e9;      /* grey PLA */
  --panel: #f4f5f6;
  --sheet: #fbfbfc;
  --ink: #22262b;         /* graphite */
  --ink-2: #4d5560;
  --ink-3: #7d8691;
  --slate: #5f6b7a;       /* the base colour in the viewer */
  --rule: #cdd1d6;
  --orange: #d9682c;      /* latch orange: the one action, and latches in the plan */
  --orange-ink: #a8481a;
  --warn: #9a5b00;
  --warn-bg: #fbf1df;
  --bad: #a3271d;
  --bad-bg: #fbe6e3;
  --good: #2f6b4f;
  --stage: #1d2125;
  --r-sm: 4px;
  --r-md: 7px;
  --wide: 118%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 15px; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: 'Archivo RB', system-ui, sans-serif; font-stretch: 100%; line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------------------------------------------------------------- header */
.top {
  display: flex; align-items: center; gap: 1.5rem; padding: 0.9rem 2rem;
  border-bottom: 1px solid var(--rule); background: var(--panel);
}
.mark {
  font-stretch: 125%; font-weight: 800; font-size: 1.35rem; letter-spacing: 0.02em; text-decoration: none;
  display: flex; align-items: baseline; gap: 0.6rem;
}
.mark small { font-stretch: 100%; font-weight: 450; font-size: 0.9rem; color: var(--ink-3); letter-spacing: 0; }
.top nav { margin-left: auto; display: flex; gap: 1.2rem; align-items: center; }
.top nav a { text-decoration: none; color: var(--ink-2); }
.top nav a:hover, .top nav a[aria-current] { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--ink-2); cursor: pointer; }
.linkbtn:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }

main { padding: 1.6rem 2rem 4rem; max-width: 1480px; margin: 0 auto; }
h1, h2, h3 { font-stretch: var(--wide); margin: 0; }
h1 { font-size: 1.6rem; font-weight: 750; letter-spacing: -0.005em; }
h2 { font-size: 1.12rem; font-weight: 700; }
h3 { font-size: 0.98rem; font-weight: 650; }
.muted { color: var(--ink-3); }

/* ---------------------------------------------------------------- buttons */
.btn {
  font: inherit; font-weight: 600; border-radius: var(--r-sm); cursor: pointer; padding: 0.55rem 1rem;
  border: 1px solid var(--rule); background: var(--sheet); color: var(--ink); text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--ink-3); }
.btn.go {
  background: var(--orange); border-color: var(--orange); color: #fff; font-stretch: var(--wide);
  font-size: 1.05rem; padding: 0.8rem 1.4rem; width: 100%;
}
.btn.go:hover { background: var(--orange-ink); border-color: var(--orange-ink); }
.btn.go:disabled { background: #c9b5a9; border-color: #c9b5a9; cursor: not-allowed; }
.btn.small { padding: 0.3rem 0.65rem; font-size: 0.9rem; font-weight: 550; }
.btn.danger { color: var(--bad); }

/* ---------------------------------------------------------------- generator page */
.gen { display: grid; grid-template-columns: minmax(420px, 1fr) minmax(420px, 1.05fr); gap: 2rem; align-items: start; }
.formcol { min-width: 0; }
.edition { display: flex; gap: 0; border: 1px solid var(--rule); border-radius: var(--r-md); overflow: hidden; background: var(--sheet); }
.edition button {
  flex: 1; font: inherit; border: 0; background: none; padding: 0.7rem 0.5rem; cursor: pointer; color: var(--ink-2);
  font-stretch: var(--wide); font-weight: 600; border-right: 1px solid var(--rule);
}
.edition button:last-child { border-right: 0; }
.edition button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.edtitle { margin: 0.7rem 0 1.2rem; color: var(--ink-2); max-width: 62ch; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; margin-bottom: 1rem; }
label.free { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.93rem; }
label.free input, label.free select {
  font: inherit; font-weight: 450; padding: 0.5rem 0.6rem; border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--sheet);
}

details.group { border-top: 1px solid var(--rule); }
details.group:last-of-type { border-bottom: 1px solid var(--rule); }
details.group > summary {
  list-style: none; cursor: pointer; padding: 0.8rem 0; display: flex; align-items: baseline; gap: 0.7rem;
}
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::before {
  content: ''; width: 0.5rem; height: 0.5rem; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3);
  transform: rotate(-45deg); transition: transform 0.15s; flex: none; position: relative; top: -0.1rem;
}
details.group[open] > summary::before { transform: rotate(45deg); }
details.group > summary h2 { font-size: 1.02rem; }
.changed-count { color: var(--orange-ink); font-size: 0.85rem; }
.params { padding: 0 0 1rem 1.2rem; display: flex; flex-direction: column; gap: 0.15rem; }

.param { display: grid; grid-template-columns: 1fr 9.5rem; gap: 0.4rem 1rem; align-items: center; padding: 0.38rem 0; }
.param .what { min-width: 0; }
.param .what > span { display: block; }
.param .hint { font-size: 0.82rem; color: var(--ink-3); }
.param.auto input[type=number] { color: var(--ink-3); background: transparent; border-style: dashed; }
.param .autotag { display: none; font-size: 0.78rem; color: var(--slate); }
.param.auto .autotag { display: inline; margin-left: 0.4rem; color: var(--ink-2); font-weight: 600; }
.param .desc { font-size: 0.93rem; }
.param .name { font-size: 0.78rem; color: var(--ink-3); font-stretch: 90%; }
.param .star { color: var(--orange); margin-right: 0.25rem; }
.param .val { display: flex; align-items: center; gap: 0.35rem; justify-content: flex-end; }
.param input[type=number] {
  width: 6rem; font: inherit; text-align: right; padding: 0.38rem 0.5rem; border: 1px solid var(--rule);
  border-radius: var(--r-sm); background: var(--sheet);
}
.param .unit { width: 2rem; color: var(--ink-3); font-size: 0.85rem; }
.param.changed input[type=number] { border-color: var(--orange); background: #fff; }
.param .reset { visibility: hidden; border: 0; background: none; color: var(--ink-3); cursor: pointer; font: inherit; font-size: 0.8rem; padding: 0; }
.param.changed .reset { visibility: visible; }
.param .reset:hover { color: var(--ink); text-decoration: underline; }

/* toggle */
.switch { position: relative; width: 2.6rem; height: 1.45rem; flex: none; margin-right: 2.35rem; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: #c3c8ce; border-radius: 1rem; transition: background 0.15s; }
.switch span::after {
  content: ''; position: absolute; width: 1.05rem; height: 1.05rem; left: 0.2rem; top: 0.2rem; background: #fff; border-radius: 50%;
  transition: transform 0.15s;
}
.switch input:checked + span { background: var(--slate); }
.switch input:checked + span::after { transform: translateX(1.15rem); }
.switch input:focus-visible + span { outline: 2px solid var(--orange); outline-offset: 2px; }
.param.changed .switch span { box-shadow: 0 0 0 2px var(--orange); }

/* ---------------------------------------------------------------- plan (live drawing) */
.plancol { position: sticky; top: 1rem; }
.sheet {
  background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 1.2rem 1.3rem 1.3rem;
}
.sheet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.4rem; }
.plan { width: 100%; height: auto; display: block; aspect-ratio: 4 / 3.1; }
.plan .outer { fill: #e9ebee; stroke: var(--ink-2); stroke-width: 1.2; }
.plan .cavity { fill: #f6f7f8; stroke: var(--ink-3); stroke-width: 0.8; }
.plan .pocket { fill: #d7dbe0; stroke: var(--slate); stroke-width: 0.9; }
.plan .pocket.slot { fill: #dfe2e6; }
.plan .latch { fill: var(--orange); }
.plan .hinge { fill: var(--slate); }
.plan .dim { stroke: var(--ink-3); stroke-width: 0.7; fill: none; }
.plan .dimtext { fill: var(--ink-2); font-size: 11px; font-family: 'Archivo RB', sans-serif; font-variant-numeric: tabular-nums; }
.plan .side { fill: var(--ink-3); font-size: 10.5px; font-family: 'Archivo RB', sans-serif; }
.plan .itemtext { fill: var(--ink-2); font-size: 9px; font-family: 'Archivo RB', sans-serif; }

.figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.2rem 1rem; margin: 0.8rem 0 0; }
.figures div { padding: 0.45rem 0; border-top: 1px solid var(--rule); }
.figures dt { font-size: 0.8rem; color: var(--ink-3); }
.figures dd { margin: 0; font-weight: 600; font-size: 1.02rem; }
.msgs { list-style: none; padding: 0; margin: 0.9rem 0 0; display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.92rem; }
.msgs li { padding: 0.5rem 0.7rem; border-radius: var(--r-sm); background: #eceef1; }
.msgs li.problem { background: var(--bad-bg); color: var(--bad); }
.msgs li.warn { background: var(--warn-bg); color: var(--warn); }
.gobar { margin-top: 1.1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.gobar .opts { display: flex; gap: 1.2rem; font-size: 0.92rem; color: var(--ink-2); }
.gobar .opts label { display: flex; gap: 0.4rem; align-items: center; cursor: pointer; }
.formerr { color: var(--bad); font-size: 0.92rem; min-height: 1.2em; }

.recent { margin-top: 1.4rem; }
.recent ul { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.recent li a { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0; border-top: 1px solid var(--rule); text-decoration: none; }
.recent li a:hover .rname { text-decoration: underline; }

/* ---------------------------------------------------------------- job page */
.jobhead { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.jobhead .meta { color: var(--ink-3); }
.jobgrid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1.5rem; align-items: start; }
.stagewrap { position: relative; }
.stage { position: relative; height: min(72vh, 760px); min-height: 420px; background: var(--stage); border-radius: var(--r-md); overflow: hidden; }
.stage canvas { display: block; }
.stagebar {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.2rem; align-items: center; padding: 0.7rem 0 0; font-size: 0.92rem;
}
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--r-sm); overflow: hidden; background: var(--sheet); }
.seg button { font: inherit; border: 0; padding: 0.35rem 0.75rem; background: none; cursor: pointer; color: var(--ink-2); border-right: 1px solid var(--rule); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.stagebar label { display: flex; gap: 0.4rem; align-items: center; color: var(--ink-2); }
.stagebar input[type=range] { width: 9rem; accent-color: var(--slate); }

.waiting { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; color: #cfd5dc; }
.waiting .bar { width: min(420px, 70%); height: 6px; background: #343a41; border-radius: 3px; overflow: hidden; }
.waiting .bar i { display: block; height: 100%; width: 0; background: var(--orange); transition: width 0.6s ease; }
.waiting .step { font-size: 0.95rem; }
.waiting.failed { color: #f2c4bd; padding: 2rem; text-align: center; }

.side h2 { margin-bottom: 0.6rem; }
.side section { margin-bottom: 1.4rem; }
.dl { display: flex; flex-direction: column; gap: 0.4rem; }
.dl .btn { width: 100%; text-align: center; }
.dl .btn.main { background: var(--ink); color: #fff; border-color: var(--ink); text-align: center; font-stretch: var(--wide); }
.dl .btn.main:hover { background: #000; }
.files { list-style: none; padding: 0; margin: 0.4rem 0 0; font-size: 0.9rem; }
.files li { display: flex; justify-content: space-between; gap: 0.6rem; padding: 0.3rem 0; border-top: 1px solid var(--rule); }
.files li a { text-decoration: none; overflow-wrap: anywhere; }
.files li a:hover { text-decoration: underline; }
.files .sz { color: var(--ink-3); white-space: nowrap; }
.parts { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.parts td { padding: 0.32rem 0; border-top: 1px solid var(--rule); }
.parts td.num { text-align: right; color: var(--ink-2); }
.parts td.bad { color: var(--bad); }
.checks { font-size: 0.86rem; color: var(--ink-2); }
.checks dt { margin-top: 0.4rem; font-weight: 600; color: var(--ink); }
.checks dd { margin: 0; }
.actions:not(td) { display: flex; gap: 0.6rem; flex-wrap: wrap; }
td.actions { white-space: nowrap; text-align: right; }

/* ---------------------------------------------------------------- history */
.hist { width: 100%; border-collapse: collapse; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r-md); overflow: hidden; }
.hist th, .hist td { text-align: left; padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--rule); }
.hist th { font-weight: 600; color: var(--ink-3); font-size: 0.86rem; background: var(--panel); }
.hist tr:last-child td { border-bottom: 0; }
.hist td a { text-decoration: none; font-weight: 600; }
.hist td a:hover { text-decoration: underline; }
.state { font-size: 0.85rem; padding: 0.1rem 0.45rem; border-radius: 3px; background: #e3e6ea; color: var(--ink-2); }
.state.done { background: #e1eee7; color: var(--good); }
.state.failed { background: var(--bad-bg); color: var(--bad); }
.state.running, .state.queued { background: var(--warn-bg); color: var(--warn); }
.empty { padding: 2.5rem; text-align: left; background: var(--sheet); border: 1px dashed var(--rule); border-radius: var(--r-md); }

/* ---------------------------------------------------------------- login */
.loginpage { min-height: 100vh; display: grid; place-items: center; padding: 2rem; }
.loginbox { width: min(380px, 100%); }
.loginbox .mark { font-size: 2.3rem; margin-bottom: 0.3rem; }
.loginbox p { color: var(--ink-2); margin: 0 0 1.6rem; }
.loginbox form { display: flex; flex-direction: column; gap: 0.8rem; }
.loginbox input[type=password] { font: inherit; padding: 0.7rem 0.8rem; border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--sheet); }
.loginbox .err { color: var(--bad); }

@media (max-width: 1080px) {
  .gen, .jobgrid { grid-template-columns: 1fr; }
  .plancol { position: static; order: -1; }
}
@media (max-width: 560px) {
  main, .top { padding-left: 1rem; padding-right: 1rem; }
  .param { grid-template-columns: 1fr; }
  .param .val { justify-content: flex-start; }
  .field-row { grid-template-columns: 1fr; }
  .figures { grid-template-columns: repeat(2, 1fr); }
  .top nav { gap: 0.8rem; }
  .mark small { display: none; }
}
