:root {
  color-scheme: dark;
  --ground: #101820;
  --panel: #16212b;
  --readout: #111b24;
  --input: #101820;
  --ink: #edf1f3;
  --muted: #a7b6c0;
  --line: #344551;
  --line-strong: #627887;
  --amber: #ffc475;
  --error: #ff9b88;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--ground); color: var(--ink); font-size: 1rem; line-height: 1.55; }
h1, h2, h3, p, dl, dd { margin: 0; }
a { color: inherit; }
button, input { font: inherit; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
[id] { scroll-margin-top: 1.25rem; }
.shell { width: min(calc(100% - 4rem), 72rem); margin-inline: auto; }

.visually-hidden, .skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link:focus { position: absolute; z-index: 2; top: .75rem; left: .75rem; padding: .65rem 1rem; background: var(--panel); }
.site-header { border-bottom: 1px solid var(--line); }

.topbar {
  min-height: 4.15rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .45rem 1.15rem;
  padding-block: .55rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .58rem;
  font-size: 1.12rem;
  font-weight: 740;
  letter-spacing: -.025em;
  text-decoration: none;
}

.brand-mark {
  width: 1.15rem;
  aspect-ratio: 1;
  flex: none;
  border: 1px solid var(--line-strong);
  background: linear-gradient(var(--amber), var(--amber)) center / 65% 1px no-repeat,
              linear-gradient(var(--amber), var(--amber)) center / 1px 65% no-repeat;
}

.topbar nav { display: flex; flex-wrap: wrap; gap: .15rem clamp(.8rem, 2.2vw, 1.7rem); }
.topbar nav a, .site-footer a { color: var(--muted); font-size: .92rem; text-decoration-thickness: 1px; text-underline-offset: .28em; }
.topbar nav a { padding-block: .4rem; text-decoration: none; }
.topbar nav a:hover, .topbar nav .current, .site-footer a:hover { color: var(--ink); text-decoration: underline; }

.workshop {
  display: grid;
  grid-template-columns: minmax(14rem, .75fr) minmax(0, 1.25fr);
  align-items: start;
  gap: clamp(1.5rem, 5.25vw, 4.5rem);
  padding-block: clamp(1.85rem, 4.6vw, 3.85rem);
}

.workshop-header { padding-top: .14rem; }
.workshop-header h1 { max-width: 11ch; }
.workshop-intro { max-width: 34ch; margin-top: .92rem; color: var(--muted); }
.workshop-index { display: grid; margin-top: clamp(1.1rem, 3vw, 2rem); border-top: 1px solid var(--line-strong); }

.workshop-index a {
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  padding-block: .4rem;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: .94rem;
  text-decoration: none;
}

.workshop-index a:hover { color: var(--amber); text-decoration: underline; text-underline-offset: .25em; }
.guides { min-width: 0; border-top: 1px solid var(--line-strong); }
.guide { padding-block: clamp(1.04rem, 2.5vw, 1.72rem); border-bottom: 1px solid var(--line); }
.guide h2 { font-size: clamp(1.32rem, 2.7vw, 1.86rem); font-weight: 710; letter-spacing: -.035em; }
.guide p { max-width: 66ch; margin-top: .59rem; color: var(--muted); }
.guide ol { max-width: 65ch; margin: .68rem 0 0; padding-inline-start: 1.35rem; }
.guide li { padding-inline-start: .23rem; }
.guide li + li { margin-top: .48rem; }
.guide li::marker { color: var(--amber); font-family: var(--mono); font-size: .9rem; }

.guide .guide-sources {
  display: flex;
  flex-wrap: wrap;
  gap: .26rem 1rem;
  margin-top: .74rem;
  font-size: .9rem;
}

.guide-sources a, .test-route-list a, .route-index-link a { color: var(--amber); text-decoration-thickness: 1px; text-underline-offset: .25em; }
.guide-sources a:hover, .test-route-list a:hover, .route-index-link a:hover { color: var(--ink); }
.guide-media { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, .85fr); gap: 1rem; margin-top: .75rem; }
.inspection { display: grid; gap: .55rem; }
.inspection dt { font-weight: 680; }
.inspection dd, .guide-note { color: var(--muted); }
.guide .guide-note { margin-top: .65rem; }
.cassette-photo { margin: 0; }
.cassette-photo img { display: block; width: 100%; height: auto; border: 1px solid var(--line); }
.cassette-photo figcaption { margin-top: .34rem; color: var(--muted); font-size: .82rem; }
.cassette-photo a { text-decoration-thickness: 1px; text-underline-offset: .22em; }

.test-routes {
  padding: clamp(1.15rem, 3.5vw, 2.15rem) clamp(1rem, 3vw, 2rem);
  border-block: 1px solid var(--line-strong);
  background: var(--panel);
}

.test-routes .section-heading { margin-bottom: clamp(1.05rem, 3vw, 1.55rem); }
.test-route-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(1.1rem, 3.5vw, 2.5rem); }
.test-route-list article { display: flex; flex-direction: column; align-items: flex-start; padding-top: .8rem; border-top: 1px solid var(--line); }
.test-route-list h3 { font-size: 1.12rem; font-weight: 680; letter-spacing: -.02em; }
.test-route-list p { max-width: 56ch; margin: .5rem 0 .75rem; color: var(--muted); }
.test-route-list a { margin-top: auto; font-size: .94rem; }
.route-index-link { margin-top: 1.05rem; }

.calculator { padding-block: clamp(1.9rem, 4.85vw, 4.12rem) clamp(1.65rem, 3.55vw, 2.7rem); }
.section-heading { position: relative; margin-bottom: clamp(1.3rem, 3.2vw, 2.1rem); padding-inline-start: clamp(.8rem, 2.5vw, 1.25rem); }
.section-heading::before { content: ""; position: absolute; inset: .3rem auto .25rem 0; width: 2px; background: var(--amber); }
h1, h2, h3 { line-height: 1.1; }
h1 { max-width: 20ch; font-size: clamp(2rem, 4.7vw, 4rem); font-weight: 740; letter-spacing: -.058em; }
.section-heading h2 { font-size: clamp(1.55rem, 3.4vw, 2.45rem); font-weight: 720; letter-spacing: -.043em; }
.section-heading p { margin-top: .5rem; color: var(--muted); }

.calculator-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.14fr) minmax(0, 1fr);
  grid-template-areas: "readout controls" "comparison controls";
  border-block: 1px solid var(--line-strong);
  border-inline: 1px solid var(--line);
}

.gear-form, .results { min-width: 0; padding: clamp(1.12rem, 3vw, 2rem); }
.gear-form { grid-area: controls; border-inline-start: 1px solid var(--line); background: var(--panel); }
.presets { min-width: 0; margin: 0 0 clamp(1rem, 2.4vw, 1.45rem); padding: 0; border: none; }
.presets legend { margin-bottom: .55rem; padding: 0; color: var(--muted); }
.presets legend, .form-fields label { font-size: .91rem; font-weight: 620; }
.preset-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; }

.preset-list button {
  min-width: 0;
  min-height: 3.15rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0 .4rem;
  padding: .4rem .62rem;
  border: 1px solid var(--line-strong);
  background: var(--input);
  color: var(--ink);
  font-size: .9rem;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}

.preset-list button span { color: var(--muted); font: .86rem var(--mono); white-space: nowrap; }
.preset-list button:hover { border-color: var(--amber); }
.preset-list button[aria-pressed="true"] { border-color: var(--amber); box-shadow: inset 0 -2px var(--amber); }
.preset-list button[aria-pressed="true"] span { color: var(--amber); }
.form-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .78rem 1.05rem; }
.form-fields label { display: grid; align-content: end; gap: .32rem; }

.field {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .3rem;
  padding-inline: .7rem;
  border: 1px solid var(--line-strong);
  background: var(--input);
  color: var(--muted);
  font: .87rem var(--mono);
  white-space: nowrap;
}

.field input { width: 100%; min-width: 0; min-height: 2.78rem; appearance: textfield; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 1.17rem; }
.field input::-webkit-inner-spin-button, .field input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.field:focus-within { outline: 2px solid var(--amber); outline-offset: 2px; }
.field:has([aria-invalid="true"]) { border-color: var(--error); }
.validation { margin-top: .82rem; color: var(--error); font-size: .94rem; }

.results { grid-area: readout; display: grid; grid-template-rows: 1fr auto; align-content: space-between; gap: 1rem; background: var(--readout); }
.result-top { display: flex; align-items: center; justify-content: space-between; gap: .75rem; align-self: center; }
.result-top > div:first-child { min-width: 0; }
.result-top h3 { margin-bottom: .62rem; color: var(--muted); font-size: .92rem; line-height: 1.3; font-weight: 640; }
.speed { display: flex; align-items: baseline; flex-wrap: wrap; gap: .18rem .48rem; color: var(--amber); font-family: var(--mono); line-height: .98; }
.speed > span:first-child { font-size: clamp(2.65rem, 6.85vw, 5.35rem); font-weight: 550; letter-spacing: -.081em; }
.speed-unit { font-size: clamp(1rem, 2vw, 1.28rem); white-space: nowrap; }

.gear-diagram {
  --front: 100%;
  --rear: 34%;
  position: relative;
  width: 28%;
  max-width: 8.25rem;
  min-width: 3.9rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  justify-items: center;
  flex: none;
  aspect-ratio: 1.66;
  border-block: 1px solid var(--line);
  background: repeating-linear-gradient(to right, transparent 0 7px, #4a65732e 7px 8px);
}

.gear-diagram[data-invalid] { visibility: hidden; }
.gear-diagram::before { content: ""; position: absolute; inset: 50% 2px auto; border-top: 1px dashed var(--line-strong); }
.gear { position: relative; max-width: calc(100% - 2px); aspect-ratio: 1; border: 1px solid var(--line-strong); border-radius: 50%; background: var(--readout); }
.gear-front { width: var(--front); }
.gear-rear { width: var(--rear); }
.gear::before { content: ""; position: absolute; inset: 14%; border: 1px dashed var(--line-strong); border-radius: 50%; }
.gear::after { content: ""; position: absolute; inset: 40%; border: 1px solid var(--line-strong); border-radius: 50%; }

.other-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .72rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.other-results > div { display: flex; flex-direction: column-reverse; gap: .26rem; }
.other-results dt { color: var(--muted); font-size: .87rem; line-height: 1.35; }
.other-results dd { font: 1.15rem var(--mono); }

.cadence-table { grid-area: comparison; min-width: 0; padding: 1rem clamp(1.12rem, 3vw, 2rem) 1.2rem; border-top: 1px solid var(--line); background: var(--readout); }
.cadence-table table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: .93rem; }
.cadence-table caption { padding-bottom: .64rem; text-align: left; font-weight: 680; }
.cadence-table thead { border-top: 1px solid var(--line-strong); }
.cadence-table :is(th, td) { padding: .62rem .4rem; text-align: right; }
.cadence-table :is(th, td):first-child { text-align: left; }
.cadence-table th { color: var(--muted); font-weight: 540; }
.cadence-table td { font-family: var(--mono); }
.calculator noscript p { margin-top: 1rem; }

.tips { padding-block: .6rem clamp(1.85rem, 4.6vw, 3.4rem); }
.tips h2 { font-size: clamp(1.35rem, 2.8vw, 1.85rem); font-weight: 690; letter-spacing: -.035em; }
.tips-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.3rem; margin-top: 1rem; }
.tips-grid article { padding-top: .8rem; border-top: 1px solid var(--line-strong); }
.tips h3 { font-size: 1rem; font-weight: 680; }
.tips-grid p { margin-top: .37rem; color: var(--muted); font-size: .94rem; }
.site-footer { border-top: 1px solid var(--line); }
.site-footer .topbar { min-height: 3.75rem; }
.site-footer span { font-size: .93rem; font-weight: 670; }

@media (max-width: 57rem) {
  .guide-media { grid-template-columns: 1fr; }
  .cassette-photo { width: min(100%, 17rem); }
}

@media (max-width: 47rem) {
  .shell { width: calc(100% - 2rem); }
  .topbar { min-height: 3.55rem; }
  .workshop, .test-route-list { grid-template-columns: 1fr; }
  .workshop-header h1 { max-width: none; }
  .workshop-index { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: .8rem; }
  .calculator-grid { grid-template-columns: 1fr; grid-template-areas: "controls" "readout" "comparison"; }
  .gear-form { border-inline-start: 0; }
  .results { border-top: 1px solid var(--line); }
  .speed > span:first-child { font-size: clamp(2.8rem, 10vw, 4.6rem); }
  .tips-grid { grid-template-columns: 1fr; gap: .85rem; }
}

@media (max-width: 24rem) {
  .gear-form, .results, .cadence-table { padding-inline: .8rem; }
  .form-fields { gap: .55rem .5rem; }
  .field { padding-inline: .45rem; }
  .preset-list { gap: .24rem; }
  .preset-list button { padding-inline: .38rem; }
  .cadence-table :is(th, td) { padding-inline: .17rem; }
  .cadence-table table { font-size: .84rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
