/* Refit: a measuring instrument on a workbench in daylight (DR-7, DR-8).
   Cool off-white ground, ink, one signal yellow. Rows, not cards. Flat, with hairlines;
   the one soft shadow sits under the phone's bottom sheet. Two motion moments only:
   the outline drawing in (240 ms) and the ± range bar settling (320 ms). */

:root {
  --ground: #F6F7F5;
  --surface: #FFFFFF;
  --ink: #15171A;
  --ink-2: #4A5058;
  --rule: #DADDE0;
  --control-border: #767C83;
  --signal: #F2C230;
  --held: #1E7A4C;
  --missed: #B3261E;
  --assumed: #8A6100;
  --link: #1F4FB8;
  --visited: #6B3FA0;

  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --t-13: 0.8125rem;
  --t-16: 1rem;
  --t-20: 1.25rem;
  --t-28: 1.75rem;
  --t-40: 2.5rem;
  --s-4: 4px; --s-8: 8px; --s-12: 12px; --s-16: 16px; --s-24: 24px; --s-32: 32px; --s-48: 48px;
  --r-control: 6px;
  --r-sheet: 10px;
  --tap: 44px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 var(--t-16)/1.5 var(--sans);
  caret-color: var(--ink);
  font-variant-numeric: tabular-nums;
}
::selection { background: var(--signal); color: var(--ink); }
a { color: var(--link); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:visited { color: var(--visited); }
:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
  box-shadow: 0 0 0 1px var(--ink);
}
.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.hidden { display: none !important; }
h1 {
  font-size: var(--t-28);
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 var(--s-8);
  text-wrap: balance;
}
p { margin: 0 0 var(--s-16); }
.lead { color: var(--ink-2); max-width: 62ch; }
.why, .hint { color: var(--ink-2); font-size: var(--t-13); line-height: 1.45; }
.hint { display: block; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pm { color: var(--ink-2); }

/* --- top bar and rail ---------------------------------------------------------------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-12);
  min-height: 52px; padding: 0 var(--s-16);
  border-bottom: 1px solid var(--rule);
  background: var(--ground);
}
.brand {
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: var(--t-20);
  letter-spacing: -0.01em;
}
.brand:visited { color: var(--ink); }
.topbar-right { display: flex; gap: var(--s-12); align-items: center; font-size: var(--t-13); color: var(--ink-2); }
.mode { font-weight: 500; color: var(--ink); }
.rail { display: none; }

.frame { max-width: 1200px; margin: 0 auto; }
.step {
  padding: var(--s-24) var(--s-16) 0;
  display: flex; flex-direction: column; min-height: calc(100dvh - 53px);
}
.step > .sheet { margin-top: auto; }
.step.solo, .landing { max-width: 880px; margin: 0 auto; padding: var(--s-32) var(--s-16) var(--s-48); }
.step > :last-child { margin-bottom: var(--s-24); }

/* --- the canvas: photo, outline, drawings --------------------------------------------- */

.canvas { margin: var(--s-16) 0; }
.canvas .photo, .canvas .drawing, .mat-preview {
  display: block; width: 100%; height: auto; max-height: 62vh;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-control);
}
.mat-preview { width: auto; max-width: 100%; margin: 0 auto; image-rendering: pixelated; padding: var(--s-16); }
.drawing { padding: var(--s-16); max-height: 260px; }
.drawing .ink-fill, .drawing .mat-ring { fill: var(--ink); }
.drawing .mat-field { fill: var(--surface); }
.drawing .part { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.drawing .part-cut { fill: var(--surface); stroke: var(--ink); stroke-width: 2; }
.drawing .hole { fill: var(--ground); stroke: var(--ink); stroke-width: 2; }
.drawing .dim { stroke: var(--ink-2); stroke-width: 1.5; fill: none; }
.drawing .dim-text { fill: var(--ink-2); font: 500 13px var(--sans); }
.drawing .jaw { stroke: var(--signal); stroke-width: 6; stroke-linecap: round; fill: none; }
.drawing .jaw-arrow { stroke: var(--ink); stroke-width: 2; fill: none; }
.drawing .mat-ring + .mat-field + .part { fill: var(--surface); }

.photo .outline, .photo .edge, .photo .other { fill: none; stroke-linejoin: round; }
.photo .edge { stroke: var(--ink); stroke-width: 4px; }
.photo .outline { stroke: var(--signal); stroke-width: 2px; }
.photo .other { stroke: var(--surface); stroke-width: 1.5px; stroke-dasharray: 6 5; }
.photo .edge, .photo .outline {
  stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: draw-in 240ms var(--ease-out) forwards;
}
@keyframes draw-in { to { stroke-dashoffset: 0; } }
.photo.tappable { cursor: crosshair; touch-action: manipulation; }
.photo .tap { fill: rgba(242, 194, 48, 0.35); stroke: var(--ink); stroke-width: 2px; }

/* --- the action sheet ------------------------------------------------------------------ */

/* On the phone the sheet sits in the thumb zone: it sticks to the bottom while the page
   above it scrolls, and nothing after it is ever hidden underneath (DR-3). */
.sheet {
  position: sticky; bottom: 0; z-index: 2;
  margin: var(--s-16) calc(-1 * var(--s-16)) 0;
  padding: var(--s-16) var(--s-16) calc(var(--s-16) + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  box-shadow: 0 -6px 24px rgba(21, 23, 26, 0.12);
}
.actions { display: flex; flex-wrap: wrap; gap: var(--s-8); align-items: center; }
.actions > form { display: contents; }
.sheet .actions.two > .btn, .sheet .actions.two > .btn.primary { flex: 1 1 0; padding: 0 var(--s-8); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-8);
  min-height: var(--tap); padding: 0 var(--s-16);
  font: 500 var(--t-16)/1 var(--sans); color: var(--ink); text-decoration: none;
  background: var(--surface); border: 1px solid var(--control-border); border-radius: var(--r-control);
  cursor: pointer; transition: background-color 150ms ease-out, border-color 150ms ease-out;
}
.btn:visited { color: var(--ink); }
.btn:hover { background: var(--ground); border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--signal); border-color: var(--signal); font-weight: 600; }
.btn.primary:hover { background: #E3B420; border-color: var(--ink); }
.sheet .actions .btn.primary { flex: 1 1 auto; }
.quiet {
  background: none; border: 0; padding: var(--s-8) 0; min-height: var(--tap);
  font: 400 var(--t-16) var(--sans); color: var(--link);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; cursor: pointer;
  display: inline-flex; align-items: center;
}
.quiet-links { margin: var(--s-8) 0 0; }
.upload { position: relative; overflow: hidden; }
.upload input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload:focus-within { outline: 2px solid var(--signal); outline-offset: 2px; box-shadow: 0 0 0 1px var(--ink); }

/* --- fields ---------------------------------------------------------------------------- */

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-12); margin-bottom: var(--s-12); }
label { display: block; font-weight: 500; }
.unit-field { display: flex; align-items: center; margin-top: var(--s-4); border: 1px solid var(--control-border); border-radius: var(--r-control); background: var(--surface); }
.unit-field:focus-within { outline: 2px solid var(--signal); outline-offset: 2px; box-shadow: 0 0 0 1px var(--ink); }
.unit-field input { flex: 1; width: 100%; min-width: 0; min-height: var(--tap); padding: 0 var(--s-12); border: 0; background: transparent; font: 400 var(--t-20) var(--mono); color: var(--ink); }
.unit-field input:focus { outline: none; }
.unit-field span { padding: 0 var(--s-12); color: var(--ink-2); font: 400 var(--t-16) var(--mono); }
input[name="typed_note"] { display: block; width: 100%; margin-top: var(--s-8); min-height: var(--tap); padding: 0 var(--s-12); border: 1px solid var(--control-border); border-radius: var(--r-control); font: 400 var(--t-16) var(--sans); }
.error { color: var(--missed); font-weight: 500; }
.ok { color: var(--held); }
.status { font-weight: 500; margin-bottom: var(--s-8); }

/* --- photos list ----------------------------------------------------------------------- */

.shots { list-style: none; padding: 0; margin: 0 0 var(--s-12); }
.shot { display: flex; align-items: center; gap: var(--s-12); padding: var(--s-8) 0; border-top: 1px solid var(--rule); }
.shot img { width: 64px; height: 48px; object-fit: cover; border-radius: 4px; background: var(--ground); }
.shot-text { flex: 1; font-size: var(--t-13); color: var(--ink-2); }
.shot form { margin: 0; }
.shot .btn { min-height: 36px; font-size: var(--t-13); }
.shot.sending .shot-text::after { content: ""; display: block; height: 2px; margin-top: var(--s-4); background: var(--signal); transform: scaleX(var(--p, 0)); transform-origin: left; transition: transform 150ms linear; }
.shot.failed .shot-text { color: var(--missed); }

.howto { margin: 0 0 var(--s-16); padding-left: 1.2em; }
.howto li { margin-bottom: var(--s-4); }

/* --- tables and the ± readout (DR-9) --------------------------------------------------- */

.dims { width: 100%; border-collapse: collapse; margin: var(--s-16) 0; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-control); }
.dims th, .dims td { text-align: left; padding: var(--s-12); border-top: 1px solid var(--rule); vertical-align: top; }
.dims thead th { border-top: 0; font-size: var(--t-13); font-weight: 500; color: var(--ink-2); }
.dims tbody th { font-weight: 500; width: 36%; }
@media (max-width: 639px) {
  .dims th, .dims td { padding: 10px 8px; }
}
.tag {
  display: inline-block; padding: 1px var(--s-8); border-radius: 4px; border: 1px solid currentColor;
  font: 500 var(--t-13)/1.5 var(--sans); white-space: nowrap;
}
.tag.measured { color: var(--ink-2); }
.tag.caliper { color: var(--ink); }
.tag.assumed { color: var(--assumed); }
.tag.recovered { color: var(--held); }
.tag.asked { background: var(--signal); border-color: var(--signal); color: var(--ink); }

.range { margin-top: var(--s-8); max-width: 260px; }
.range-track { position: relative; height: 10px; background: var(--ground); border-radius: 2px; }
.range-need, .range-got { position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%); }
.range-need { width: var(--w); border: 1.5px solid var(--ink); border-radius: 2px; }
.range-got { width: var(--w); height: 4px; top: 3px; background: var(--missed); animation: settle 320ms var(--ease-out) both; }
.range-got.held { background: var(--held); }
.range-mid { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--ink); }
@keyframes settle { from { transform: translateX(-50%) scaleX(3); opacity: 0.4; } }
.range-text { margin: var(--s-4) 0 0; font-size: var(--t-13); color: var(--ink-2); font-family: var(--mono); }

.explain { margin: var(--s-8) 0; font-size: var(--t-13); color: var(--ink-2); }
.explain summary { cursor: pointer; color: var(--link); min-height: var(--tap); display: inline-flex; align-items: center; }

/* --- caliper request (DR-13) ----------------------------------------------------------- */

.controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-12); }
.controls > * { min-width: 0; }
.talk {
  border-radius: 999px; min-height: 56px; font-weight: 600;
  background: var(--surface); border: 2px solid var(--ink); touch-action: none; user-select: none; -webkit-user-select: none;
}
.talk-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--missed); opacity: 0.35; }
.talk.listening { background: var(--signal); border-color: var(--ink); }
.talk.listening .talk-dot { opacity: 1; animation: pulse 900ms ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.6); } }
.type-it { display: flex; gap: var(--s-8); align-items: flex-end; }
.type-it label { flex: 1; min-width: 0; }
.type-it .btn { flex: 0 0 auto; }
.recorded { font-weight: 500; }
.big-number { font: 500 var(--t-40)/1.1 var(--mono); margin: var(--s-24) 0; }

/* --- recovery choices ------------------------------------------------------------------- */

.choices { list-style: none; margin: 0 0 var(--s-12); padding: 0; }
.choices li { border-top: 1px solid var(--rule); padding: var(--s-8) 0; }
.choice { display: flex; gap: var(--s-12); align-items: center; min-height: var(--tap); font-weight: 400; cursor: pointer; }
.choice input { width: 20px; height: 20px; accent-color: var(--ink); }
.typed { display: block; padding-left: 32px; }

/* --- progress --------------------------------------------------------------------------- */

.progress { height: 4px; background: var(--ground); border-radius: 2px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 30%; background: var(--signal); animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.runid { font: 400 var(--t-13) var(--mono); color: var(--ink-2); }

/* --- the fit report ---------------------------------------------------------------------- */

.verdict { font-size: var(--t-28); line-height: 1.2; font-weight: 600; margin: var(--s-8) 0; }
.verdict.held { color: var(--held); }
.verdict.assumed { color: var(--assumed); }
.verdict.missed { color: var(--missed); }
.pairs, .facts { list-style: none; padding: 0; margin: 0 0 var(--s-16); }
.pairs li, .facts li { padding: var(--s-8) 0; border-top: 1px solid var(--rule); }
.result { font-weight: 600; }
.result.fits { color: var(--held); }
.result.tight, .result.loose, .result.outside { color: var(--missed); }
.result.inside { color: var(--held); }
.result.not-checked { color: var(--ink-2); font-weight: 500; }
.need { display: block; margin-top: var(--s-4); font: 400 var(--t-13) var(--mono); color: var(--ink-2); }
.changes { margin: 0 0 var(--s-16); }
.changes p { margin-bottom: var(--s-4); font-weight: 500; }
.changes ul { margin: 0; padding-left: 1.2em; }
.drawing .part.print { fill: var(--signal); }
.photo .part-label {
  fill: var(--ink); stroke: var(--surface); stroke-width: 0.18em; paint-order: stroke;
  font-family: var(--sans); font-weight: 600; pointer-events: none;
}
.assumptions { margin: 0 0 var(--s-16); color: var(--assumed); }
.assumptions ul { margin: 0; padding-left: 1.2em; color: var(--ink); }
.tabs {
  display: flex; gap: var(--s-4); border-bottom: 1px solid var(--rule); margin: var(--s-24) 0 0;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.tab {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 var(--s-16);
  color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; font-weight: 500;
  white-space: nowrap;
}
.tab:visited { color: var(--ink-2); }
.tab.current { color: var(--ink); border-bottom-color: var(--ink); }
.tabpanel { padding-top: var(--s-8); }
.views { display: grid; grid-template-columns: 1fr; gap: var(--s-16); margin-top: var(--s-16); }
.views figure { margin: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-control); padding: var(--s-12); }
.views img { width: 100%; height: auto; display: block; }
.views figcaption { font-size: var(--t-13); color: var(--ink-2); margin-top: var(--s-8); }

.landing h1 { font-size: var(--t-28); max-width: 18ch; }
.landing-action { margin: var(--s-24) 0; }

/* --- tablet: phone layout, centred ---------------------------------------------------------- */

@media (min-width: 640px) {
  .step { max-width: 640px; margin: 0 auto; }
  .controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: end; }
  .views { grid-template-columns: repeat(3, 1fr); }
}

/* --- desktop: two panes (DR-3) ---------------------------------------------------------------- */

@media (min-width: 1024px) {
  .frame { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: var(--s-32); padding: 0 var(--s-24); }
  .stepcount { display: none; }
  .rail { display: block; padding: var(--s-32) 0; position: sticky; top: 0; align-self: start; }
  .rail ol { list-style: none; margin: 0; padding: 0; }
  .rail li { display: flex; align-items: center; gap: var(--s-12); min-height: 40px; color: var(--ink-2); }
  .rail .n {
    display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;
    border: 1px solid var(--control-border); border-radius: 4px; font: 500 var(--t-13) var(--mono);
  }
  .rail .tick { width: 14px; height: 14px; fill: none; stroke: var(--surface); stroke-width: 2.2; }
  .rail .done .n { background: var(--held); border-color: var(--held); }
  .rail .current { color: var(--ink); font-weight: 600; }
  .rail .current .n { background: var(--signal); border-color: var(--ink); }
  .step { max-width: none; margin: 0; padding: var(--s-32) 0 var(--s-48); display: block; min-height: 0; }
  .sheet {
    position: static; padding: 0; margin: var(--s-16) 0;
    background: none; box-shadow: none; border-radius: 0;
  }
  .sheet .actions .btn.primary { flex: 0 0 auto; }
  .sheet .actions.two > .btn { flex: 0 0 200px; }
  .canvas .photo { max-height: 58vh; }
  .canvas .drawing { max-height: 280px; }
  .landing h1 { font-size: var(--t-40); }
  .verdict { font-size: var(--t-40); }
}

@media (prefers-reduced-motion: reduce) {
  .photo .edge, .photo .outline { animation: none; stroke-dashoffset: 0; }
  .range-got { animation: none; }
  .progress span, .talk.listening .talk-dot { animation: none; }
  .btn { transition: none; }
}
