:root {
  --bg: #f2f5f9;
  --panel: #ffffff;
  --ink: #10151c;
  --ink-2: #3f4756;
  --muted: #5d6675;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --accent: #1f5fd8;
  --accent-2: #17439c;
  --ok: #0f7a52;
  --ok-bg: #e7f6ef;
  --bad: #c22a2a;
  --bad-bg: #fbeaea;
  --cell: #e8edf4;
  --cell-on: #10151c;
  --mono: "SF Mono", "Cascadia Code", Consolas, "Roboto Mono", ui-monospace, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 12px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- masthead ---------- */
.masthead {
  padding: 22px 24px 16px;
  max-width: 920px;
  margin: 0 auto;
}
.wordmark {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1;
}
.wordmark em { font-style: normal; color: var(--accent); }
.masthead-meta {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(15,122,82,0.5);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(15,122,82,0.5); }
  70% { box-shadow: 0 0 0 7px rgba(15,122,82,0); }
  100% { box-shadow: 0 0 0 0 rgba(15,122,82,0); }
}

main { max-width: 920px; margin: 0 auto; padding: 0 24px 40px; }

/* ---------- trainer ---------- */
.trainer {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 2px rgba(16,21,28,.05), 0 12px 28px -18px rgba(16,21,28,.18);
}

.setup {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.setup-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
  font-weight: 600;
}
.seg { display: flex; gap: 4px; background: var(--cell); padding: 4px; border-radius: 8px; }
.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: 13px/1 var(--sans);
  font-weight: 600;
  padding: 8px 4px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
  white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(26,29,35,0.14); }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.stage { padding: 20px 0 4px; }
.stage-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; gap: 10px; }
.qtype { font: 11px var(--mono); color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.qtune {
  font: 11px var(--mono);
  color: var(--ink-2);
  letter-spacing: 0.02em;
  margin-left: 8px;
  margin-right: auto;
  white-space: nowrap;
  background: var(--cell);
  border-radius: 4px;
  padding: 2px 7px;
}
.qtune b { font-weight: 600; color: var(--ink); }
.qcount { font: 13px var(--mono); color: var(--ink-2); }
.qprompt {
  margin: 0 0 16px;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
  min-height: 28px;
}

.answers {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.answer {
  border: 1.5px solid var(--line-2);
  background: var(--panel);
  border-radius: 9px;
  padding: 14px 14px;
  text-align: left;
  font: 600 15px var(--sans);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.08s ease;
}
.answer .key {
  font: 11px var(--mono);
  color: var(--muted);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 2px 6px;
  min-width: 16px;
  text-align: center;
}
.answer:hover { border-color: var(--ink-2); }
.answer:active { transform: translateY(1px); }
.answer:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.answer.is-correct { border-color: var(--ok); background: var(--ok-bg); color: #12703a; }
.answer.is-correct .key { border-color: var(--ok); color: var(--ok); }
.answer.is-wrong { border-color: var(--bad); background: var(--bad-bg); color: #9a1f1f; }
.answer.is-wrong .key { border-color: var(--bad); color: var(--bad); }
.answer.is-disabled { cursor: default; opacity: 0.92; }

.feedback {
  margin: 14px 0 0;
  min-height: 22px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
}
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

.transport {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.play {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font: 650 15px var(--sans);
  padding: 11px 18px;
  cursor: pointer;
  transition: background-color 0.14s ease, border-color 0.14s ease, transform 0.1s ease;
}
.play:hover { background: #242931; }
.play:active { transform: translateY(1px); }
.play.is-playing { background: var(--accent); border-color: var(--accent); }
.play.is-playing:hover { background: var(--accent-2); }
.play:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.play-glyph { width: 18px; height: 18px; fill: currentColor; }

.ghost {
  border: 1.5px solid var(--line-2);
  background: var(--panel);
  color: var(--ink-2);
  border-radius: 10px;
  font: 600 14px var(--sans);
  padding: 10px 14px;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.ghost:hover { background: var(--cell); }
.ghost:disabled { opacity: 0.45; cursor: not-allowed; }
.ghost:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.score { margin-left: auto; text-align: right; font-family: var(--mono); }
.score-num { display: block; font: 700 18px var(--mono); color: var(--ink); }
.score-acc { font: 11px var(--mono); color: var(--muted); }

.hint {
  margin: 12px 0 0;
  font: 11px var(--mono);
  color: var(--muted);
}

/* ---------- generic sections ---------- */
.section { padding: 46px 0; border-bottom: 1px solid var(--line); }
.section:last-of-type { border-bottom: 0; }
.eyebrow { font: 11px var(--mono); color: var(--accent-2); letter-spacing: 0.08em; text-transform: uppercase; margin: 0 0 8px; }
.section h2 { margin: 0 0 14px; font-size: 25px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.lede { margin: 0 0 18px; font-size: 15px; color: var(--ink-2); max-width: 62ch; }

.spec-list { margin: 0; display: grid; gap: 14px; }
.spec-list > div { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.spec-list > div:last-child { border-bottom: 0; padding-bottom: 0; }
.spec-list dt { font: 600 12px var(--mono); text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 3px; }
.spec-list dd { margin: 0; font-size: 14.5px; color: var(--ink); }
.practice-link { margin-top: 20px; font-size: 14px; color: var(--ink-2); max-width: 60ch; }
.practice-link a { color: var(--accent-2); font-weight: 600; text-decoration: none; border-bottom: 1px solid rgba(210,63,25,0.35); }
.practice-link a:hover { color: var(--ink); border-bottom-color: var(--ink); }

/* ---------- timing / measurement ---------- */
.timing { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.fingerprint { margin-bottom: 18px; }
.fingerprint-head { display: flex; justify-content: space-between; font: 11px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.fingerprint-note { margin: 0 0 8px; font: 11.5px/1.7 var(--mono); color: var(--muted); }

.method h3 { font-size: 15px; font-weight: 700; margin: 0 0 10px; }
.method p { margin: 0 0 12px; font-size: 14px; color: var(--ink-2); max-width: 70ch; }
.method ul { margin: 0 0 14px; padding-left: 20px; }
.method li { margin-bottom: 6px; font-size: 13.5px; color: var(--ink-2); }
.method code { font-family: var(--mono); font-size: 12.5px; background: var(--cell); padding: 1px 4px; border-radius: 3px; color: var(--ink); }

.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 6px 0 14px;
}

.meas-table {
  width: 100%;
  border-collapse: collapse;
  font: 13px var(--mono);
  font-variant-numeric: tabular-nums;
}
.meas-table th {
  text-align: right;
  font: 600 11px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 2px solid var(--ink);
  white-space: nowrap;
}
.meas-table th:first-child { text-align: left; }
.meas-table td {
  text-align: right;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
}
.meas-table td:first-child { text-align: left; font-weight: 600; color: var(--ink); }
.meas-table tbody tr:hover { background: var(--cell); }
.meas-table .dev-flat { color: var(--muted); }
.meas-table .dev-sharp { color: var(--muted); }

.measure-out { min-height: 18px; font: 12px var(--mono); color: var(--muted); }
.run-test {
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: #fff;
  border-radius: 9px;
  font: 600 13px var(--sans);
  padding: 9px 14px;
  cursor: pointer;
  margin-bottom: 12px;
  transition: background-color 0.14s ease;
}
.run-test:hover { background: #242931; }
.run-test:disabled { opacity: 0.6; cursor: wait; }
.run-test:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- faq + footer ---------- */
.faq-list { display: grid; gap: 16px; }
.faq-list > div { border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.faq-list > div:last-child { border-bottom: 0; padding-bottom: 0; }
.faq-list h3 { margin: 0 0 5px; font-size: 14.5px; font-weight: 700; }
.faq-list p { margin: 0; font-size: 14px; color: var(--ink-2); }

.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 26px 4px 10px;
  font: 11px var(--mono);
  color: var(--muted);
  flex-wrap: wrap;
}

/* ---------- mobile ---------- */
@media (max-width: 620px) {
  .masthead { padding: 22px 16px 12px; }
  main { padding: 0 16px 32px; }
  .setup { grid-template-columns: 1fr; gap: 10px; }
  .answers { grid-template-columns: 1fr; }
  .answer { padding: 15px 14px; }
  .transport { gap: 8px; }
  .play { flex: 1; justify-content: center; }
  .score { margin-left: 0; text-align: right; width: 100%; }
  .qtune { margin-right: auto; }
  .section { padding: 34px 0; }
  .section h2 { font-size: 21px; }
  .timing { padding: 18px; }
  .meas-table { font-size: 11px; }
  .meas-table th, .meas-table td { padding: 6px 6px; }
  .meas-table th { white-space: normal; line-height: 1.25; }
  .footer { flex-direction: column; }
}

/* ---------- site chrome (matches audiotomidiconverter.com topbar/footer) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255,255,255,.86);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-in {
  max-width: 920px; margin: 0 auto; height: 56px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 24px;
}
.topbar-brand {
  font-size: 15px; font-weight: 700; letter-spacing: -.015em;
  color: var(--ink); text-decoration: none;
}
.topbar-brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 20px; }
.topbar nav a { font-size: 14px; color: var(--ink-2); text-decoration: none; }
.topbar nav a:hover { color: var(--accent); }
.foot-nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; margin-top: 10px; width: 100%; }
.foot-nav a { color: var(--accent); text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.foot-nav a:hover { text-decoration: underline; }
@media (max-width: 620px) {
  .topbar-in { height: 48px; padding: 0 14px; gap: 10px; }
  .topbar-brand { white-space: nowrap; font-size: 14px; }
  .topbar nav { gap: 12px; }
  .topbar nav a { font-size: 12.5px; white-space: nowrap; }
  /* 390px cannot hold four labels next to the wordmark without wrapping;
     the metronome link lives in the footer and in the body copy instead. */
  .topbar nav a[href="/online-metronome"] { display: none; }
}
