/*
  Draft without design direction. Dials: ENERGY 1 / RHYTHM 1 / MOTION 1.
  Decisions:
  - Paper and ink palette: echoes a printed fit sheet, which is what fitters hand riders.
  - One accent (signal red): reserved for the measurement points BRP/HB and their lines,
    the numbers the rider must transfer to the bike.
  - System font stack: a workshop tool should load instantly and work offline; numbers use
    tabular figures so columns of mm values line up.
  - Identity motif: the dimension-line rule under key numbers, borrowed from technical drawings.
  - No shadows: everything sits on one plane except the toast, which floats above content.
  - Motion: hover and the toast fade only.
*/

:root {
  color-scheme: light;
  --paper: #f5f4ef;
  --surface: #ffffff;
  --ink: #1c1b19;
  --ink-2: #55524b;
  --line: #dcd8cd;
  --line-strong: #8b877c;
  --accent: #b5301b;
  --ok: #2c6a37;
  --warn: #855500;
  --bad: #b5301b;
  --ok-bg: #e9f2e8;
  --warn-bg: #f7efdc;
  --bad-bg: #f8e6e2;
  --radius: 4px;
  --radius-lg: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #161614;
    --surface: #1f1e1b;
    --ink: #edeae2;
    --ink-2: #b4b0a5;
    --line: #36342f;
    --line-strong: #7d796f;
    --accent: #f0806b;
    --ok: #86c98f;
    --warn: #e2b55c;
    --bad: #f0806b;
    --ok-bg: #1e2a1f;
    --warn-bg: #2d2516;
    --bad-bg: #2f1c18;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #161614;
  --surface: #1f1e1b;
  --ink: #edeae2;
  --ink-2: #b4b0a5;
  --line: #36342f;
  --line-strong: #7d796f;
  --accent: #f0806b;
  --ok: #86c98f;
  --warn: #e2b55c;
  --bad: #f0806b;
  --ok-bg: #1e2a1f;
  --warn-bg: #2d2516;
  --bad-bg: #2f1c18;
}

*, *::before, *::after { box-sizing: border-box; }

/* Components set display: grid/flex, which would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0; }
ul { margin: 0; padding-left: 1.2rem; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[tabindex="-1"]:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: 1rem; top: -100px; z-index: 10;
  background: var(--ink); color: var(--paper); padding: .75rem 1rem; border-radius: var(--radius);
}
.skip:focus { top: 1rem; }

.muted { color: var(--ink-2); }

.banner {
  background: var(--warn-bg); color: var(--ink); border-bottom: 1px solid var(--line);
  padding: .75rem 1rem; font-size: .95rem;
}

.boot { padding: 3rem 1rem; text-align: center; color: var(--ink-2); }

/* ---------- buttons and inputs ---------- */
button, .ghost, .primary, .secondary {
  font: inherit; cursor: pointer; border-radius: var(--radius);
  min-height: 44px; padding: .55rem 1rem; display: inline-flex; align-items: center;
  justify-content: center; gap: .4rem; text-decoration: none; line-height: 1.2;
}
button:disabled { cursor: progress; opacity: .7; }

.primary { background: var(--ink); color: var(--paper); border: 1px solid var(--ink); font-weight: 600; }
.primary:hover { background: var(--ink-2); border-color: var(--ink-2); }

.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line-strong); }
.secondary:hover { border-color: var(--ink); }

.ghost { background: transparent; color: var(--ink); border: 1px solid transparent; }
.ghost:hover { background: var(--line); }
.ghost[aria-pressed="true"] { border-color: var(--line-strong); }
.ghost.danger { color: var(--bad); }

.linklike {
  background: none; border: 0; padding: 0; min-height: 0; color: var(--ink);
  text-decoration: underline; text-underline-offset: 2px; font-weight: 600;
}

.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field label { font-size: .9rem; font-weight: 600; }
.req { font-weight: 400; color: var(--ink-2); font-size: .8rem; }

input[type="text"], input[type="date"], select {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  min-height: 44px; padding: .5rem .65rem; width: 100%; min-width: 0;
}
input:hover, select:hover { border-color: var(--ink-2); }
input[aria-invalid="true"] { border-color: var(--bad); border-width: 2px; }
input[type="radio"], input[type="checkbox"] { accent-color: var(--ink); width: 1.1rem; height: 1.1rem; margin: 0; flex: none; }

.field-error { color: var(--bad); font-size: .85rem; font-weight: 600; }
.hint { color: var(--ink-2); font-size: .875rem; }

.grid { display: grid; gap: .9rem 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.choice { display: flex; flex-wrap: wrap; gap: .5rem; }
.choice legend { font-size: .9rem; font-weight: 600; margin-bottom: .4rem; padding: 0; }
.choice label, .check {
  display: inline-flex; align-items: center; gap: .5rem; min-height: 44px;
  padding: .4rem .8rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
}
.choice label:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.check { width: fit-content; }

details.more { border-top: 1px dashed var(--line); padding-top: .75rem; }
details > summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
details.more[open] > summary { margin-bottom: .5rem; }

/* ---------- app shell ---------- */
.wordmark { font-weight: 800; letter-spacing: -.01em; }
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem;
  padding: .5rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface);
}
.topnav { display: flex; gap: .25rem; }
.navbtn { background: none; border: 0; color: var(--ink-2); font-weight: 600; border-radius: var(--radius); }
.navbtn:hover { color: var(--ink); background: var(--line); }
.navbtn[aria-current="page"] { color: var(--ink); text-decoration: underline; text-underline-offset: 6px; text-decoration-thickness: 2px; }
.topbar-end { margin-left: auto; }
@media (max-width: 560px) {
  .topbar .wordmark { flex-basis: 100%; }
}

.workspace {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 2rem;
  max-width: 1400px; margin: 0 auto; padding: 1.5rem 1rem 3rem;
}
@media (min-width: 1024px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); align-items: start; padding: 2rem; }
  .result-col { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
  .to-result { display: none; }
}

.form-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; }
.form-head-actions { display: flex; flex-wrap: wrap; gap: .25rem; margin-left: -1rem; }
@media (min-width: 560px) { .form-head-actions { margin-left: 0; } }

.steps {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .25rem;
  margin: 1.25rem 0 .5rem; border-bottom: 1px solid var(--line);
}
.steps button {
  background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  color: var(--ink-2); font-weight: 600; padding-inline: .25rem; text-align: center;
}
.steps button:hover { color: var(--ink); }
.steps button[aria-current="step"] { color: var(--ink); border-bottom-color: var(--ink); }
.step-n {
  display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  border: 1px solid currentColor; font-size: .8rem;
}
.steps button[aria-current="step"] .step-n { background: var(--ink); color: var(--paper); border-color: var(--ink); }

#fit-form:focus { outline: none; }
.group { display: grid; gap: .9rem; padding: 1.5rem 0; border-bottom: 1px solid var(--line); }
.group:last-of-type { border-bottom: 0; }

.feet {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: .5rem .75rem; align-items: center;
}
.feet-h { font-size: .85rem; font-weight: 700; color: var(--ink-2); }
.feet-l { font-size: .9rem; font-weight: 600; }

.pain-list { list-style: none; padding: 0; display: grid; gap: .75rem; }
.pain-row {
  display: grid; gap: .75rem; align-items: end; padding: .75rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr));
}
.pain-row .field:first-child { grid-column: span 2; }
@media (max-width: 400px) { .pain-row .field:first-child { grid-column: auto; } }
.empty-inline { color: var(--ink-2); font-size: .95rem; }
#add-pain { width: fit-content; }

.options { display: grid; gap: .5rem; }
.option {
  display: grid; grid-template-columns: auto 1fr; gap: .15rem .75rem; align-items: center;
  padding: .85rem 1rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
}
.option input { grid-row: span 2; }
.option-t { font-weight: 700; }
.option-d { grid-column: 2; color: var(--ink-2); font-size: .92rem; }
.option:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }

.step-nav { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; padding-top: 1.25rem; }

/* ---------- result ---------- */
.result-col {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 1.25rem; scroll-margin-top: 1rem;
}
.result-col:focus { outline: none; }

.r-state { display: grid; gap: .75rem; justify-items: start; padding: 1rem 0; }
.r-state p { color: var(--ink-2); max-width: 48ch; }
.r-error h2 { color: var(--bad); }
.r-error ul { display: grid; gap: .35rem; }

.r-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.r-head h2 { font-size: 1.4rem; overflow-wrap: anywhere; }
.r-meta { color: var(--ink-2); font-size: .92rem; margin-top: .2rem; }

.r-figure { margin: 1rem 0 0; }
.r-figure figcaption { color: var(--ink-2); font-size: .85rem; margin-top: .4rem; }

.r-key {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.25rem; margin: 1.25rem 0 .5rem;
}
@media (min-width: 560px) { .r-key { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.r-key > div { display: flex; flex-direction: column; justify-content: space-between; }
.r-key dt { font-size: .82rem; color: var(--ink-2); font-weight: 600; }
.r-key dd {
  margin: .15rem 0 0; font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; position: relative;
  padding-bottom: .35rem;
}
/* Dimension-line rule: the identity motif. */
.r-key dd::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 8px;
  border-left: 1.5px solid var(--accent); border-right: 1.5px solid var(--accent);
  background: linear-gradient(var(--accent), var(--accent)) center / 100% 1.5px no-repeat;
}
.r-key small { font-size: .9rem; font-weight: 600; color: var(--ink-2); letter-spacing: 0; }
.dim-l { font-style: italic; color: var(--accent); font-weight: 700; margin-left: .15rem; }
.r-coords { color: var(--ink-2); font-size: .85rem; }

.r-sec { padding-top: 1.25rem; margin-top: 1.25rem; border-top: 1px solid var(--line); }
.r-sec h3 { margin-bottom: .6rem; }
.r-hint { color: var(--ink-2); font-size: .88rem; margin-top: .6rem; }

.spec { margin: 0; display: grid; }
.spec-row {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: .1rem; padding: .55rem 0;
  border-bottom: 1px dashed var(--line);
}
.spec-row:last-child { border-bottom: 0; }
@media (min-width: 560px) { .spec-row { grid-template-columns: 10.5rem minmax(0, 1fr); gap: 1rem; } }
.spec dt { color: var(--ink-2); font-size: .92rem; }
.spec dd { margin: 0; display: grid; gap: .15rem; }
.spec-v { font-weight: 650; overflow-wrap: anywhere; }
.spec-n { color: var(--ink-2); font-size: .86rem; }

.verdict {
  margin-top: .75rem; padding: .75rem 1rem; border-radius: var(--radius);
  border: 1px solid; display: grid; gap: .35rem;
}
.verdict-t { font-weight: 700; }
.verdict-ok { border-color: var(--ok); background: var(--ok-bg); }
.verdict-ok .verdict-t { color: var(--ok); }
.verdict-warn { border-color: var(--warn); background: var(--warn-bg); }
.verdict-warn .verdict-t { color: var(--warn); }
.verdict-bad { border-color: var(--bad); background: var(--bad-bg); }
.verdict-bad .verdict-t { color: var(--bad); }
.verdict + .pains { margin-top: 1rem; }

.pains { list-style: none; padding: 0; display: grid; gap: 1rem; }
.pain-t { font-weight: 650; }
.pain-vas { font-weight: 700; padding: 0 .35rem; border: 1px solid var(--line-strong); border-radius: var(--radius); font-size: .85rem; }
.pains ul { color: var(--ink-2); font-size: .92rem; margin-top: .3rem; display: grid; gap: .2rem; }
.pain-adj { font-size: .85rem; font-weight: 600; margin-top: .3rem; }

.r-method { margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: .5rem; }
.r-method ul { color: var(--ink-2); font-size: .9rem; display: grid; gap: .35rem; }

/* bike drawing */
.bike { width: 100%; height: auto; display: block; }
.bk-tire { fill: none; stroke: var(--ink); stroke-width: 10; }
.bk-rim { fill: none; stroke: var(--line-strong); stroke-width: 4; }
.bk-hub { fill: var(--ink); }
.bk-tube { stroke: var(--ink); stroke-width: 14; stroke-linecap: round; }
.bk-head { stroke-width: 22; }
.bk-part { stroke: var(--ink-2); stroke-width: 9; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.bk-spacer { stroke-width: 18; }
.bk-saddle { stroke: var(--ink); stroke-width: 20; stroke-linecap: round; fill: none; }
.bk-ring { fill: none; stroke: var(--ink-2); stroke-width: 5; }
.bk-dim { stroke: var(--accent); stroke-width: 6; stroke-dasharray: 16 10; }
.bk-dim-thin { stroke-width: 4; }
.bk-guide { stroke: var(--line-strong); stroke-width: 3; stroke-dasharray: 4 10; }
.bk-point { fill: var(--accent); stroke: var(--surface); stroke-width: 6; }
.bk-bb { fill: var(--ink); stroke: var(--surface); stroke-width: 5; }
.bk-label, .bk-letter {
  paint-order: stroke; stroke: var(--surface); stroke-width: 14px; stroke-linejoin: round;
}
.bk-label { font: 700 44px var(--font); fill: var(--ink); }
.bk-letter { font: italic 700 64px var(--font); fill: var(--accent); }

/* ---------- history ---------- */
.history { max-width: 860px; margin: 0 auto; padding: 2rem 1rem 3rem; }
.history h1 { margin-bottom: 1rem; }
.hist { list-style: none; padding: 0; border-top: 1px solid var(--line); }
.hist-item {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem 1rem;
  padding: 1rem 0; border-bottom: 1px solid var(--line);
}
.hist-title { font-weight: 700; overflow-wrap: anywhere; }
.hist-meta { font-size: .92rem; }
.hist-date { color: var(--ink-2); font-size: .85rem; }
.hist-actions { display: flex; gap: .25rem; }

.foot { max-width: 1400px; margin: 0 auto; padding: 1rem 1rem 2rem; color: var(--ink-2); font-size: .85rem; border-top: 1px solid var(--line); }
@media (min-width: 1024px) { .foot { padding-inline: 2rem; } }
.foot p + p { margin-top: .4rem; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%);
  max-width: min(92vw, 30rem); background: var(--ink); color: var(--paper);
  padding: .75rem 1rem; border-radius: var(--radius); font-weight: 600;
  box-shadow: 0 6px 18px rgb(0 0 0 / .18);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* ---------- print ---------- */
@media print {
  :root, :root[data-theme] {
    --paper: #fff; --surface: #fff; --ink: #000; --ink-2: #333; --line: #bbb;
    --line-strong: #777; --accent: #b5301b; --ok: #1f5a2a; --warn: #6b4400; --bad: #b5301b;
    --ok-bg: #fff; --warn-bg: #fff; --bad-bg: #fff;
  }
  body { background: #fff; }
  .topbar, .form-col, .foot, .skip, .toast, .banner, .r-actions, #view-history { display: none !important; }
  .workspace { display: block; padding: 0; }
  .result-col { position: static; max-height: none; overflow: visible; border: 0; padding: 0; }
  .r-method[open] ul, .r-method ul { display: grid; }
  .r-sec { break-inside: avoid; }
}
