/**
 * Tuning Guru — site styles.
 *
 * Selectors target elements and a small set of block classes. There is no
 * utility layer: the markup is semantic, so the stylesheet can be too, and a
 * guide body rendered straight out of markdown needs no classes at all.
 *
 * Section spacing is owned by `.band` alone. Nothing else sets a top or bottom
 * margin on a section, which is what stops two rules from cancelling each other.
 */

@import url('fonts.css');
@import url('tokens.css');

/* --- reset ---------------------------------------------------------------- */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--t-base);
  line-height: var(--leading-body);
  font-synthesis-weight: none;
  text-rendering: optimizeLegibility;
}

img,
svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* --- shared type ---------------------------------------------------------- */

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
  margin: 0;
}

p,
ul,
ol,
table,
blockquote {
  margin: 0;
}

a {
  color: var(--accent-ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  transition: color var(--dur-fast) var(--ease-out);
}

a:hover {
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
  border-radius: 2px;
}

/**
 * The eyebrow. One treatment, used for every label on the site: section
 * kickers, card meta, the byline strip. Mono because it is data, not prose.
 */
.label {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--t-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0;
}

/* --- layout --------------------------------------------------------------- */

.wrap {
  width: min(100% - 2.5rem, var(--page));
  margin-inline: auto;
}

/** The only thing that sets vertical rhythm between sections. */
.band {
  padding-block: var(--s-8);
  border-top: var(--border);
}

.band:first-of-type {
  border-top: 0;
}

.band > .wrap > .label {
  margin-bottom: var(--s-4);
}

.skip {
  position: absolute;
  left: -9999px;
  top: var(--s-3);
  background: var(--text);
  color: var(--paper);
  padding: var(--s-3) var(--s-4);
  font-family: var(--font-mono);
  font-size: var(--t-sm);
  z-index: 10;
}

.skip:focus {
  left: var(--s-4);
}

/* --- header --------------------------------------------------------------- */

.site-head {
  border-bottom: var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}

/**
 * The wordmark and four nav items need about 420px side by side, which is more
 * than a phone gives. Rather than hiding the navigation behind a button, the
 * row is allowed to wrap: the nav drops to its own line and stays entirely
 * visible and tappable. No JavaScript, and nothing is taken away at any width.
 */
.site-head > .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-5);
  padding-block: var(--s-3);
}

@media (min-width: 34rem) {
  .site-head > .wrap {
    flex-wrap: nowrap;
    padding-block: 0;
    min-height: 4rem;
  }
}

/**
 * The wordmark carries the redline: a short vertical mark after the name, the
 * way a tachometer prints one before the numbers stop. It is the smallest
 * possible statement of the palette's logic.
 */
.wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--t-md);
  letter-spacing: -0.03em;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: baseline;
  gap: 0.4ch;
  white-space: nowrap;
}

.wordmark::after {
  content: '';
  width: 3px;
  height: 0.9em;
  background: var(--accent);
  transform: skewX(-12deg);
  transition: height var(--dur) var(--ease-out);
}

.wordmark:hover::after {
  height: 1.15em;
}

.site-nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  margin: 0;
  padding: 0;
}

@media (min-width: 48rem) {
  .site-nav ul {
    gap: var(--s-5);
  }
}

.site-nav a {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: var(--t-sm);
  color: var(--text-muted);
  text-decoration: none;
  /* A finger is less precise than a cursor, so the row that wraps onto its own
     line on a phone also gets the taller target. */
  padding-block: var(--s-3);
  position: relative;
  display: inline-block;
}

@media (min-width: 34rem) {
  .site-nav a {
    padding-block: var(--s-2);
  }
}

.site-nav a::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--dur) var(--ease-out);
}

.site-nav a:hover,
.site-nav a[aria-current] {
  color: var(--text);
}

.site-nav a:hover::after,
.site-nav a[aria-current]::after {
  transform: scaleX(1);
}

/* --- hero ----------------------------------------------------------------- */

.hero {
  padding-block: clamp(var(--s-7), 8vw, var(--s-9)) var(--s-8);
  border-bottom: var(--border);
}

.hero > .wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-7);
  align-items: center;
}

@media (min-width: 60rem) {
  .hero > .wrap {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    gap: var(--s-8);
  }
}

.hero h1 {
  font-size: var(--t-3xl);
  margin-block: var(--s-4) var(--s-5);
}

/** The one place red appears in running text, on the word the site is about. */
.hero h1 em {
  font-style: normal;
  color: var(--accent);
}

/**
 * `:not(.label)` rather than a bare `.hero p`. The eyebrow above the headline is
 * also a paragraph, and an element+class selector here would outrank `.label`
 * and quietly resize it — the two rules would cancel and only one would show.
 */
.hero p:not(.label) {
  font-size: var(--t-md);
  color: var(--graphite-80);
  max-width: 46ch;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin-top: var(--s-6);
}

/* --- dyno plot (the signature) -------------------------------------------- */

/**
 * A power and torque pair, drawn the way a rolling road prints them. It is the
 * one artefact every reader of this site recognises, and it earns its place by
 * being the thing the whole subject is measured with.
 *
 * The curves are illustrative and say so beneath the plot: this site has no
 * dyno of its own, and unlabelled numbers on a chart would be a claim.
 */
.dyno {
  border: var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  padding: var(--s-5) var(--s-5) var(--s-4);
}

.dyno svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.dyno .grid line {
  stroke: var(--rule);
  stroke-width: 1;
}

.dyno .axis {
  stroke: var(--machined);
  stroke-width: 1.5;
}

.dyno .trace {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dyno .trace-power {
  stroke: var(--redline);
}

.dyno .trace-torque {
  stroke: var(--torque);
}

/** Stock runs sit underneath, thinner and dashed — the before, not the after. */
.dyno .trace-stock {
  stroke-width: 1.5;
  stroke-dasharray: 3 4;
  opacity: 0.55;
}

.dyno .tick {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  fill: var(--text-muted);
}

.dyno .redline-band {
  fill: var(--redline);
  opacity: 0.07;
}

.dyno .redline-rule {
  stroke: var(--redline);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}

.dyno-key {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  margin-top: var(--s-4);
  padding-top: var(--s-3);
  border-top: var(--border);
}

.dyno-key li {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  color: var(--text-muted);
}

.dyno-key span {
  width: 14px;
  height: 2px;
  flex: none;
}

.dyno-key .k-power {
  background: var(--redline);
}

.dyno-key .k-torque {
  background: var(--torque);
}

.dyno-key .k-stock {
  background: repeating-linear-gradient(90deg, var(--steel) 0 3px, transparent 3px 7px);
}

.dyno-note {
  margin-top: var(--s-3);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  line-height: 1.5;
  color: var(--text-muted);
}

/**
 * Draw-on. Power leads, torque follows a beat later, so the eye tracks one line
 * at a time instead of seeing a single flash. Off entirely under reduced motion,
 * where the curves are simply already there.
 *
 * Gated behind `.anim` for the same reason as the reveals above: a dashed
 * offset with no animation to remove it is an invisible curve, so the plot must
 * never be dashed unless the script that animates it is confirmed running.
 */
@media (prefers-reduced-motion: no-preference) {
  .anim .dyno .trace {
    stroke-dasharray: var(--len, 600);
    stroke-dashoffset: var(--len, 600);
    animation: draw var(--dur-slow) var(--ease-out) forwards;
  }
  .anim .dyno .trace-power {
    animation-delay: 220ms;
  }
  .anim .dyno .trace-torque {
    animation-delay: 380ms;
  }
  .anim .dyno .trace-stock {
    animation-delay: 60ms;
    animation-duration: 420ms;
  }
}

@keyframes draw {
  to {
    stroke-dashoffset: 0;
  }
}

/* --- buttons -------------------------------------------------------------- */

.btn {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--t-sm);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  padding: var(--s-3) var(--s-5);
  border-radius: var(--radius);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  transition:
    transform var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-ink);
  color: #fff;
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-quiet {
  border-color: var(--rule);
  color: var(--text);
  background: transparent;
}

.btn-quiet:hover {
  border-color: var(--text);
  color: var(--text);
  transform: translateY(-1px);
}

/* --- card grids ----------------------------------------------------------- */

.grid {
  display: grid;
  gap: var(--s-4);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}

.card {
  background: var(--bg-raised);
  border: var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  position: relative;
  transition:
    border-color var(--dur) var(--ease-out),
    transform var(--dur) var(--ease-out);
}

.card:hover {
  border-color: var(--graphite-80);
  transform: translateY(-2px);
}

/**
 * A card's heading takes whatever rank the surrounding document needs — h2 when
 * the grid follows the page's h1 directly, h3 when a section heading sits
 * between. The styling is the same either way, so the level stays free to be
 * chosen for the outline rather than for the look.
 */
.card :is(h2, h3) {
  font-size: var(--t-lg);
  font-weight: 600;
}

/** Stretched link: the whole card is the target, the anchor is still the name. */
.card :is(h2, h3) a {
  color: inherit;
  text-decoration: none;
}

.card :is(h2, h3) a::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.card :is(h2, h3) a:focus-visible {
  outline: none;
}

.card:has(a:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

/* Same reason as `.hero p:not(.label)`: the count is a paragraph too. */
.card p:not(.card-count) {
  color: var(--text-muted);
  font-size: var(--t-sm);
  line-height: 1.55;
}

/** The count is the honest measure of a hub — how much is actually in there. */
.card-count {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--t-xs);
  color: var(--accent-ink);
  letter-spacing: 0.06em;
  margin-top: auto;
  padding-top: var(--s-3);
}

/* Guide list: denser than a card grid, because a hub can hold twenty-two. */
.guide-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: var(--border);
}

.guide-list li {
  border-bottom: var(--border);
}

.guide-list a {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-2) var(--s-4);
  padding: var(--s-4) var(--s-2);
  text-decoration: none;
  color: var(--text);
  transition: background-color var(--dur-fast) var(--ease-out), padding-left var(--dur) var(--ease-out);
}

.guide-list a:hover {
  background: var(--bg-raised);
  padding-left: var(--s-4);
}

.guide-list :is(h2, h3) {
  font-size: var(--t-md);
  font-weight: 600;
  letter-spacing: -0.01em;
  flex: 1 1 22rem;
}

.guide-list .meta {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

/* --- guide ---------------------------------------------------------------- */

.guide {
  padding-block: var(--s-7) var(--s-8);
}

.guide-head {
  max-width: var(--measure);
  margin-bottom: var(--s-6);
  padding-bottom: var(--s-5);
  border-bottom: var(--border);
}

.guide-head h1 {
  font-size: var(--t-2xl);
  margin-block: var(--s-3);
}

.guide-head .standfirst {
  font-size: var(--t-md);
  color: var(--graphite-80);
  max-width: 56ch;
}

.breadcrumb {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  color: var(--text-muted);
  margin-bottom: var(--s-3);
}

.breadcrumb ol {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin: 0;
  padding: 0;
}

.breadcrumb li + li::before {
  content: '/';
  margin-right: var(--s-2);
  color: var(--rule);
}

.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--accent-ink);
  text-decoration: underline;
}

.guide-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  margin-top: var(--s-4);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  color: var(--text-muted);
}

/**
 * The editor's note. Three guides lost a ranking or a set of dated picks in the
 * migration; saying so where the reader can see it is the difference between an
 * edit and a quiet deletion.
 */
.note {
  border-left: 3px solid var(--accent);
  background: var(--bg-raised);
  padding: var(--s-4) var(--s-5);
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: var(--s-6);
  max-width: var(--measure);
}

.note p:not(.label) {
  font-size: var(--t-sm);
  line-height: 1.6;
  color: var(--graphite-80);
}

.note .label {
  margin-bottom: var(--s-2);
  color: var(--accent-ink);
}

/* Body copy — everything below comes straight from markdown, unclassed. */

.prose {
  max-width: var(--measure);
}

.prose > * + * {
  margin-top: var(--s-4);
}

.prose h2 {
  font-size: var(--t-xl);
  margin-top: var(--s-7);
  padding-top: var(--s-2);
}

.prose h3 {
  font-size: var(--t-lg);
  font-weight: 600;
  margin-top: var(--s-6);
}

.prose h4 {
  font-family: var(--font-mono);
  font-size: var(--t-sm);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: var(--s-5);
}

.prose ul,
.prose ol {
  padding-left: var(--s-5);
}

.prose li + li {
  margin-top: var(--s-2);
}

.prose li::marker {
  color: var(--accent);
}

.prose ol li::marker {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

.prose strong {
  font-weight: 600;
}

.prose blockquote {
  border-left: 3px solid var(--rule);
  padding-left: var(--s-4);
  font-style: italic;
  color: var(--graphite-80);
}

/** Wide spec tables scroll inside their own box; the page never does. */
.table-scroll {
  overflow-x: auto;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
}

.prose table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  line-height: 1.5;
}

.prose caption {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  padding: var(--s-3) var(--s-4);
  border-bottom: var(--border);
}

.prose th,
.prose td {
  padding: var(--s-2) var(--s-4);
  text-align: left;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  white-space: nowrap;
}

.prose thead th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text);
  position: sticky;
  top: 0;
}

.prose tbody tr:last-child td {
  border-bottom: 0;
}

/** An outbound video, styled as the deliberate departure from the site it is. */
.video-link a {
  font-family: var(--font-mono);
  font-size: var(--t-sm);
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  border: var(--border);
  border-radius: var(--radius);
  padding: var(--s-3) var(--s-4);
  color: var(--text);
  transition: border-color var(--dur-fast) var(--ease-out);
}

.video-link a::before {
  content: '';
  width: 0;
  height: 0;
  border-left: 8px solid var(--accent);
  border-block: 5px solid transparent;
}

.video-link a:hover {
  border-color: var(--accent);
}

.video-link__host {
  color: var(--text-muted);
}

/* --- forms ---------------------------------------------------------------- */

label {
  font-family: var(--font-mono);
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--text);
  display: inline-block;
  margin-bottom: var(--s-2);
}

input[type='text'],
input[type='email'],
textarea {
  width: 100%;
  max-width: 34rem;
  font-family: var(--font-body);
  font-size: var(--t-base);
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--s-3);
  transition: border-color var(--dur-fast) var(--ease-out);
}

input[type='text']:hover,
input[type='email']:hover,
textarea:hover {
  border-color: var(--graphite-80);
}

input[type='text']:focus,
input[type='email']:focus,
textarea:focus {
  border-color: var(--focus);
}

textarea {
  resize: vertical;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid transparent;
}

/**
 * The note under a field. It exists to remove the specific hesitation that
 * stops people writing in — so it sits where the doubt is, not in a paragraph
 * further up the page.
 */
.field-note {
  display: block;
  max-width: 34rem;
  margin-top: var(--s-2);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  line-height: 1.55;
  color: var(--text-muted);
}

/* --- related -------------------------------------------------------------- */

.related {
  margin-top: var(--s-8);
  padding-top: var(--s-6);
  border-top: var(--border);
}

.related > .label {
  margin-bottom: var(--s-4);
}

/* --- footer --------------------------------------------------------------- */

.site-foot {
  border-top: var(--border);
  background: var(--graphite);
  color: var(--machined);
  padding-block: var(--s-7) var(--s-6);
  margin-top: var(--s-8);
}

.site-foot a {
  color: var(--machined);
  text-decoration: none;
}

.site-foot a:hover {
  color: #fff;
  text-decoration: underline;
}

.foot-cols {
  display: grid;
  gap: var(--s-6);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
}

.foot-cols h2 {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--steel-light);
  margin-bottom: var(--s-3);
}

.foot-cols ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: var(--t-sm);
}

.foot-cols li + li {
  margin-top: var(--s-2);
}

.foot-base {
  margin-top: var(--s-7);
  padding-top: var(--s-4);
  border-top: 1px solid var(--graphite-80);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3) var(--s-5);
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  color: var(--steel-light);
}

/* --- reveal --------------------------------------------------------------- */

/**
 * Cards arrive a beat apart rather than all at once, so the eye is led through
 * the grid in reading order.
 *
 * Every rule that hides something is gated behind `.anim` on <html>, which
 * site.js sets as its first statement. Nothing on this page may depend on
 * JavaScript to become visible: if the script is blocked, errors, or never
 * runs, the class is absent, none of these rules apply, and the content is
 * simply there. Hiding first and revealing later is only safe when the thing
 * doing the revealing has already proved it is running.
 */
@media (prefers-reduced-motion: no-preference) {
  .anim .reveal > * {
    opacity: 0;
    transform: translateY(10px);
  }

  .anim .reveal.is-in > * {
    opacity: 1;
    transform: none;
    transition:
      opacity var(--dur) var(--ease-out),
      transform var(--dur) var(--ease-out);
    transition-delay: calc(var(--i, 0) * 55ms);
  }
}

/* --- utility -------------------------------------------------------------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.lede {
  font-size: var(--t-md);
  color: var(--graphite-80);
  max-width: 56ch;
}

.stack > * + * {
  margin-top: var(--s-4);
}
