/* Layout: tool rail on the left (a scrolling chip strip on phones), one working column per tool:
   inputs first, the answer in large condensed figures, then the detail and a to-scale drawing. */
:root {
  color-scheme: light;
  --bg: #eceded;
  --surface: #f8f8f8;
  --surface-2: #e2e4e4;
  --line: #d2d5d6;
  --fg: #1a1c1d;
  --muted: #5d6367;
  --accent: #36687b;
  --accent-tint: #dbe6ea;
  --on-accent: #ffffff;
  --rubber: #2b2e30;
  --rubber-line: #44494c;
  --alloy: #c3c8cb;
  --good: #2f7247;
  --good-tint: #dcebe0;
  --warn: #946112;
  --warn-tint: #f1e6d2;
  --bad: #a3392f;
  --bad-tint: #f2dcd9;
  --focus: #36687b;

  --font-display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --font-body: "Barlow", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --r: 10px;
  --r-sm: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131516; --surface: #1b1e1f; --surface-2: #24282a; --line: #33393b;
    --fg: #e6e8e9; --muted: #9aa1a5; --accent: #80b1c3; --accent-tint: #1d3038; --on-accent: #0f1a1f;
    --rubber: #0c0d0e; --rubber-line: #4a5054; --alloy: #8d9397;
    --good: #79c08f; --good-tint: #1b2f22; --warn: #d9a650; --warn-tint: #33291a; --bad: #e58a80; --bad-tint: #3a211e;
    --focus: #80b1c3;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131516; --surface: #1b1e1f; --surface-2: #24282a; --line: #33393b;
  --fg: #e6e8e9; --muted: #9aa1a5; --accent: #80b1c3; --accent-tint: #1d3038; --on-accent: #0f1a1f;
  --rubber: #0c0d0e; --rubber-line: #4a5054; --alloy: #8d9397;
  --good: #79c08f; --good-tint: #1b2f22; --warn: #d9a650; --warn-tint: #33291a; --bad: #e58a80; --bad-tint: #3a211e;
  --focus: #80b1c3;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 16px/1.5 var(--font-body);
  font-variant-numeric: tabular-nums;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg);
}
h1, h2, h3 { margin: 0; text-wrap: balance; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* Top bar */
.topbar { border-bottom: 1px solid var(--line); background: var(--bg); }
.topbar .wrap { display: flex; align-items: center; gap: 16px; padding-block: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--fg); margin-right: auto; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand b { font: 600 24px/1 var(--font-display); letter-spacing: .01em; }
.brand small { display: block; font-size: 12px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; margin-top: 2px; }
.prefs { display: flex; gap: 8px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 999px; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--muted); min-height: 32px;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

/* Shell */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 40px; padding-block: 28px 56px; align-items: start; }
.toolnav { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 20px); display: flex; flex-direction: column; gap: 2px; }
.toolnav .group { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 14px 12px 6px; }
.toolnav .group:first-child { padding-top: 0; }
.toolnav a {
  display: block; padding: 8px 12px; border-radius: var(--r-sm); text-decoration: none; color: var(--fg); font-weight: 500;
}
.toolnav a:hover { background: var(--surface-2); }
.toolnav a[aria-current="page"] { background: var(--accent-tint); color: var(--accent); }

main { min-width: 0; }
.tool-head { display: grid; gap: 6px; margin-bottom: 22px; }
.tool-head h1 { font: 600 clamp(30px, 4.4vw, 40px)/1.05 var(--font-display); letter-spacing: .005em; }
.tool-head p { color: var(--muted); max-width: 62ch; }

.stack { display: grid; gap: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; min-width: 0; }
.panel h2 { font: 600 20px/1.2 var(--font-display); margin-bottom: 14px; letter-spacing: .01em; }
.panel-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-title h2 { margin: 0; }

.inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; align-items: start; }
.inputs.two { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; }

/* Form fields */
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .field > .label { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.field input[type="text"], .field input[type="number"], .field select {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--bg); font-size: 17px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-tint); }
.field input.size { font: 500 19px/1.2 var(--font-code); letter-spacing: .02em; text-transform: uppercase; }
.field .hint { font-size: 13px; color: var(--muted); min-height: 1.4em; }
.field .hint.error { color: var(--bad); }
.field.invalid input { border-color: var(--bad); }
.field select:disabled { opacity: .5; }

/* Size picker: one dropdown per term of the size */
.sizepick { display: grid; gap: 8px; min-width: 0; }
.sizepick-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sizepick-head .label { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.seg.small button { min-height: 28px; padding: 3px 11px; font-size: 13px; }
.pick-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 6px; }
.pick { display: grid; gap: 4px; min-width: 0; }
.pick span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick select {
  width: 100%; min-height: 50px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--bg); font: 600 19px/1.2 var(--font-code); cursor: pointer;
}
.pick select:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-tint); }
.pick-sep { font: 600 20px/1 var(--font-code); color: var(--muted); padding-bottom: 15px; }
.sizepick .hint { font-size: 13px; color: var(--muted); min-height: 1.4em; }
.sizepick .hint code { font: 600 13px var(--font-code); color: var(--fg); }
.sizepick .hint.error { color: var(--bad); }
.sizepick.invalid select { border-color: var(--bad); }

.check { display: flex; align-items: center; gap: 8px; font-size: 15px; min-height: 46px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 11px; cursor: pointer;
  font: 500 13px/1.3 var(--font-code); color: var(--fg);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chips-label { font-size: 13px; color: var(--muted); margin-right: 4px; align-self: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 16px;
  border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600;
  text-decoration: none; color: var(--fg);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); color: var(--on-accent); }
.btn.icon { width: 46px; padding: 0; min-height: 46px; }
.btn svg { width: 18px; height: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* Results */
.answer { display: grid; gap: 4px; }
.answer .k { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.answer .v { font: 600 clamp(48px, 9vw, 72px)/0.95 var(--font-display); letter-spacing: -.005em; }
.answer .v .u { font-size: .42em; font-weight: 500; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.answer .sub { color: var(--muted); }
.answer .sub code { font-family: var(--font-code); font-size: 15px; color: var(--fg); }

.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 24px; align-items: center; }
.specs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; margin-top: 18px; border-top: 1px solid var(--line); }
.specs div { padding: 12px 0; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
.specs div:nth-child(odd) { padding-right: 12px; }
.specs div:nth-child(even) { padding-left: 12px; border-left: 1px solid var(--line); }
.specs dt { font-size: 13px; color: var(--muted); }
.specs dd { margin: 0; font: 600 22px/1.2 var(--font-display); }
.specs dd .u, td .u { font-family: var(--font-body); font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }

.figure { min-width: 0; }
.figure svg { display: block; width: 100%; height: auto; max-width: 100%; }
.figure figcaption { font-size: 13px; color: var(--muted); margin-top: 6px; display: flex; flex-wrap: wrap; gap: 14px; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.key i { width: 18px; height: 10px; border-radius: 3px; display: inline-block; }
.key i.a { border: 1.5px dashed var(--muted); }
.key i.b { background: var(--accent-tint); border: 1.5px solid var(--accent); }

svg text { fill: var(--muted); font: 500 17px var(--font-body); }
svg .dim { stroke: var(--muted); stroke-width: 1; fill: none; }
svg .ground { stroke: var(--line); stroke-width: 2; }
svg .rubber { fill: var(--rubber); stroke: var(--rubber-line); stroke-width: 1; }
svg .alloy { fill: var(--alloy); }
svg .hub { fill: var(--rubber); }
svg .tread { stroke: var(--rubber-line); stroke-width: 2; }
svg .ghost { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
svg .new { fill: var(--accent-tint); fill-opacity: .55; stroke: var(--accent); stroke-width: 2; }
svg .new-solid { fill: var(--accent-tint); stroke: var(--accent); stroke-width: 2; }
svg .ghost-solid { fill: var(--surface-2); stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
svg .face { stroke: var(--fg); stroke-width: 2; }
svg text.strong { fill: var(--fg); font-weight: 600; }
svg .new-line { fill: none; stroke: var(--accent); stroke-width: 2.5; }
svg .spacer { fill: var(--surface-2); stroke: var(--muted); stroke-width: 1; }
svg .susp { fill: var(--surface-2); stroke: var(--muted); stroke-width: 1.2; }
svg .strut { stroke: var(--muted); stroke-opacity: .45; stroke-linecap: round; }
svg .coil { fill: none; stroke: var(--muted); stroke-width: 2.5; stroke-linejoin: round; }
svg .body { fill: var(--surface-2); stroke: var(--muted); stroke-width: 1.2; }
svg .hubface { stroke: var(--fg); stroke-width: 1.2; stroke-dasharray: 3 3; }
svg .ground-new { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 6 4; }

/* Offset tool */
.seg.tabs { margin-bottom: 18px; max-width: 100%; }
.seg.tabs button { padding: 6px 16px; }
.inputs.three { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.inputs.three .field select { font-size: 16px; padding-inline: 8px; }
.fit-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 22px; align-items: center; }
.fit-grid .figure svg { max-height: 460px; margin-inline: auto; }
.fit-cards { display: grid; gap: 10px; }
.fit-cards .stat { background: var(--bg); }
.key i.solid { background: var(--rubber); }
.tone-more { color: var(--good); }
.tone-less { color: var(--warn); }
table.chart { font-size: 13px; }
table.chart th, table.chart td { padding: 7px 8px; text-align: center; }
table.chart td:first-child, table.chart th:first-child { position: sticky; left: 0; background: var(--surface); text-align: left; font-weight: 600; z-index: 1; }
table.chart tr.hl-row td { background: var(--accent-tint); }
table.chart td.hl { background: var(--accent); color: var(--on-accent); font-weight: 700; border-radius: 4px; }

/* Verdict banner */
.verdict { display: flex; gap: 14px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r); }
.verdict.good { background: var(--good-tint); }
.verdict.warn { background: var(--warn-tint); }
.verdict.bad { background: var(--bad-tint); }
.pill { flex: none; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 3px 9px; border-radius: 999px; color: var(--surface); margin-top: 2px; }
.good .pill, .pill.good { background: var(--good); }
.warn .pill, .pill.warn { background: var(--warn); }
.bad .pill, .pill.bad { background: var(--bad); }
.verdict strong { display: block; font-size: 17px; }
.verdict p { color: var(--fg); opacity: .85; font-size: 15px; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: right; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
thead th { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
td.code, .code { font-family: var(--font-code); font-size: 14px; }
.delta-pos { color: var(--warn); }
.delta-neg { color: var(--accent); }
.delta-zero { color: var(--muted); }
th button { all: unset; cursor: pointer; }
th button:focus-visible { outline: 2px solid var(--focus); }
th[aria-sort] button::after { content: " ↓"; }
th[aria-sort="ascending"] button::after { content: " ↑"; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.hl td { background: var(--accent-tint); }

/* Stat pair */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
td .pct { display: block; font-size: 13px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 14px 16px; display: grid; gap: 2px; }
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font: 600 30px/1.1 var(--font-display); }
.stat .v .u { font: 500 14px var(--font-body); color: var(--muted); margin-left: 3px; }
.stat p { font-size: 14px; color: var(--muted); }

.note { font-size: 14px; color: var(--muted); max-width: 70ch; }
.note strong { color: var(--fg); }

/* Sidewall decoder */
.code-strip { display: flex; flex-wrap: wrap; gap: 4px 2px; align-items: flex-start; padding: 6px 0 4px; }
.seg-code { display: grid; justify-items: center; gap: 6px; cursor: default; }
.seg-code b {
  font: 600 clamp(28px, 6vw, 44px)/1 var(--font-code); padding: 6px 6px 8px; border-bottom: 3px solid var(--line); letter-spacing: -.01em;
}
.seg-code span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; text-align: center; max-width: 11ch; line-height: 1.25; }
.seg-code.on b { border-color: var(--accent); color: var(--accent); }
.seg-code.gap b { border-color: transparent; padding-inline: 4px; }
.decode-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.decode-list .stat .v { font-size: 24px; }

details { border-top: 1px solid var(--line); padding-top: 12px; }
summary { cursor: pointer; font-weight: 600; }
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 18px; margin-top: 12px; }
.ref-grid div { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.ref-grid div b { font-family: var(--font-code); }

/* Footer */
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; background: var(--surface); }
.footer .wrap { padding-block: 32px 24px; display: grid; gap: 28px; }
.foot-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(0, 1fr)); gap: 28px; }
.foot-brand { display: grid; gap: 10px; align-content: start; }
.foot-brand .brand b { font-size: 22px; }
.foot-brand p { max-width: 36ch; }
.footer nav { display: grid; gap: 6px; align-content: start; }
.footer nav h2 { font: 600 12px/1.4 var(--font-body); letter-spacing: .08em; text-transform: uppercase; color: var(--fg); margin-bottom: 4px; }
.footer nav a { color: var(--muted); text-decoration: none; }
.footer nav a:hover { color: var(--accent); text-decoration: underline; }
.foot-bottom { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 20px; border-top: 1px solid var(--line); padding-top: 16px; font-size: 13px; }
@media (max-width: 760px) {
  .foot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .foot-brand { grid-column: 1 / -1; }
}

/* Breadcrumbs, guides and article pages */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.crumbs a { color: var(--muted); }
.crumbs [aria-current] { color: var(--fg); font-weight: 600; }
.guide { margin-top: 36px; display: grid; gap: 10px; max-width: 70ch; }
.guide h2, .prose h2 { font: 600 22px/1.2 var(--font-display); margin-top: 12px; }
.guide p, .prose p { color: var(--fg); }
.prose { display: grid; gap: 12px; max-width: 70ch; }
.prose .tool-head { margin-bottom: 4px; }
.panel h2 a { color: inherit; text-decoration: none; }
.panel h2 a:hover { color: var(--accent); }
a.chip { text-decoration: none; display: inline-block; }
a.chip[aria-current] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
td a { color: var(--accent); font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }
.decode-rows { display: grid; gap: 0; margin: 0; }
.decode-rows div { display: grid; grid-template-columns: 4.5em minmax(0, 1fr); gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.decode-rows div:last-child { border-bottom: 0; }
.decode-rows dt { font: 600 20px/1.3 var(--font-code); color: var(--accent); }
.decode-rows dd { margin: 0; }

a.chip small { color: var(--muted); font-size: 11px; margin-left: 3px; }
a.chip[aria-current] small { color: inherit; }
.qa h3 { font: 600 17px/1.3 var(--font-body); margin: 14px 0 4px; }
.qa h3:first-of-type { margin-top: 0; }
.qa p { max-width: 70ch; }

/* Shop box */
.shop { display: grid; gap: 12px; }
.panel .shop { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.shop .panel-title { margin-bottom: 0; flex-wrap: wrap; }
.shop h3 { font: 600 20px/1.2 var(--font-display); margin: 0; }
.shop-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.shop-btn { justify-content: space-between; }

/* Tablet and down: tools become a sticky scrolling strip */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); gap: 0; padding-block: 0 40px; }
  .toolnav {
    position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; flex-direction: row; overflow-x: auto; gap: 6px;
    margin: 0 calc(-1 * max(16px, env(safe-area-inset-right, 0px))) 20px calc(-1 * max(16px, env(safe-area-inset-left, 0px)));
    padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
    background: var(--bg); border-bottom: 1px solid var(--line); scrollbar-width: none;
  }
  .toolnav::-webkit-scrollbar { display: none; }
  .toolnav .group { display: none; }
  .toolnav a { white-space: nowrap; padding: 7px 13px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 15px; }
  .toolnav a[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
  .tool-head { margin-top: 4px; }
  .result-grid, .fit-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .panel { padding: 16px; }
  .inputs.two { grid-template-columns: minmax(0, 1fr); }
  .inputs.two .swap { justify-self: center; transform: rotate(90deg); }
  .prefs .seg button { padding: 5px 10px; }
  .pick select { font-size: 17px; padding: 8px 4px 8px 8px; }
  .pick-row { gap: 4px; }
  .brand small { display: none; }
  th, td { padding: 9px 7px; font-size: 14px; }
}
@media (prefers-reduced-motion: no-preference) {
  .toolnav a, .chip, .btn, .seg button { transition: background-color .15s, color .15s, border-color .15s; }
}
