/*
 * The free tools: the groove player (any page with a .groove), the groove builder and the timing test.
 * Builds on style.css's tokens and falls back to the app's colours (Badum/Views/Theme.swift) when one is missing.
 * Dark like the app by default; a light version when the system asks for it.
 */
:root {
  /* From style.css, which follows the system between dark and light; the app's colours as the fallback. */
  --tk-ground: var(--ground, #0f1113);
  --tk-panel: var(--panel, #181b1f);
  --tk-lane: color-mix(in srgb, var(--tk-panel), var(--tk-text) 4%);
  --tk-line: var(--line, #2a2e35);
  --tk-bar-line: color-mix(in srgb, var(--tk-line), var(--tk-text) 22%);
  --tk-text: var(--text, #f3f0ea);
  --tk-muted: var(--muted, #a2a9b3);
  --tk-action: var(--hat, #f2c43d);
  --tk-action-text: var(--hat-text, #f2c43d);
  --tk-on-action: var(--on-hat, #15181c);
  --tk-good: var(--good, #57d68d);
  --tk-warn: #ff9a30;
  --tk-bad: #ff4d4f;
  --tk-miss: color-mix(in srgb, var(--tk-line), var(--tk-text) 12%);
  --tk-now: color-mix(in srgb, transparent, var(--tk-text) 8%);
  --tk-focus: var(--focus, #5b9bff);
  /* The kit, as the app colours it */
  --c-cr: #c4a8ff;
  --c-rd: #6fd3c0;
  --c-hh: #f2c43d;
  --c-oh: #f2c43d;
  --c-sn: var(--snare, #ff7a59);
  --c-t1: #f7b8e8;
  --c-t2: #e58ad0;
  --c-ft: #b85aa6;
  --c-bd: var(--kick, #5b9bff);
  --tk-mono: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  --tk-round: var(--round, ui-rounded, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
}

@media (prefers-color-scheme: light) {
  :root {
    --tk-warn: #c46200;
    --tk-bad: #d92d2f;
    /* Deeper versions of the kit's colours, to read on white */
    --c-cr: #7c58d6;
    --c-rd: #158a76;
    --c-hh: #b88a00;
    --c-oh: #b88a00;
    --c-t1: #d06ab6;
    --c-t2: #b44d9c;
    --c-ft: #8a347b;
  }
}

.tool-page h1 { overflow-wrap: anywhere; }
.tool-label {
  font: 700 12px/1.2 var(--tk-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tk-muted);
  margin: 0 0 10px;
}

/* ---------------------------------------------------------------- the groove player */

.gp {
  --gp-label: 52px;
  --gp-row: 34px;
  --gp-glyph: 17px;
  background: var(--tk-panel);
  border: 1px solid var(--tk-line);
  border-radius: 22px;
  padding: 16px 14px 12px;
  margin: 28px 0 10px;
  color: var(--tk-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  max-width: 100%;
}
.gp--large { --gp-label: 60px; --gp-row: 42px; --gp-glyph: 22px; padding: 22px 18px 16px; }
@media (max-width: 480px) {
  .gp { --gp-label: 44px; padding: 14px 10px 10px; }
  .gp--large { --gp-label: 46px; --gp-row: 36px; --gp-glyph: 18px; }
}

.gp-bars { display: grid; gap: 14px; }
.gp-bars.gp-two { display: flex; gap: 0; }
.gp-bars.gp-two .gp-bar:first-child { flex: 0 0 calc(var(--gp-label) + (100% - var(--gp-label)) / 2); }
.gp-bars.gp-two .gp-bar + .gp-bar { flex: 1 1 0; --gp-label: 0px; }
.gp-bars.gp-two .gp-bar + .gp-bar .gp-label { display: none; }
.gp-bars.gp-two .gp-bar + .gp-bar .gp-row:not(.gp-count) .gp-cell:nth-child(2),
.gp-bars.gp-two .gp-bar + .gp-bar .gp-num:nth-child(2) { box-shadow: inset 2px 0 0 var(--tk-bar-line); }

.gp-bar { position: relative; min-width: 0; }
.gp-bar-name {
  height: 20px;
  padding-left: var(--gp-label);
  font: 700 10px/20px var(--tk-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tk-muted);
}
.gp-bars.gp-two .gp-bar + .gp-bar .gp-bar-name { padding-left: 6px; }

.gp-row {
  display: grid;
  grid-template-columns: var(--gp-label) repeat(16, minmax(0, 1fr));
  align-items: stretch;
  height: var(--gp-row);
  margin-bottom: 4px;
}
.gp-label {
  font: 700 11px/var(--gp-row) var(--tk-round);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  padding-right: 4px;
}
.gp-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--tk-lane);
  color: inherit;
  font: inherit;
}
.gp-cell.gp-beat { box-shadow: inset 1px 0 0 var(--tk-line); }
.gp-row .gp-cell:nth-child(2) { border-radius: 9px 0 0 9px; box-shadow: none; }
.gp-row .gp-cell:last-child { border-radius: 0 9px 9px 0; }
.gp-bars.gp-two .gp-bar:first-child .gp-row .gp-cell:last-child { border-radius: 0; }
.gp-bars.gp-two .gp-bar + .gp-bar .gp-row .gp-cell:nth-child(2) { border-radius: 0; }

.gp-glyph {
  width: calc(var(--gp-glyph) * var(--gp-scale, 1));
  height: calc(var(--gp-glyph) * var(--gp-scale, 1));
  max-width: 70%;
  overflow: visible;
  transition: transform 0.12s ease-out, filter 0.12s;
  pointer-events: none;
}
.gp-soft .gp-glyph { opacity: 0.72; }
.gp-hit .gp-glyph { transform: scale(1.22); filter: brightness(1.25); }

.gp-lane-cr { color: var(--c-cr); }
.gp-lane-rd { color: var(--c-rd); }
.gp-lane-hh { color: var(--c-hh); }
.gp-lane-oh { color: var(--c-oh); }
.gp-lane-sn { color: var(--c-sn); }
.gp-lane-t1 { color: var(--c-t1); }
.gp-lane-t2 { color: var(--c-t2); }
.gp-lane-ft { color: var(--c-ft); }
.gp-lane-bd { color: var(--c-bd); }

.gp--editable .gp-cell { cursor: pointer; }
.gp--editable .gp-cell:hover { background: color-mix(in srgb, var(--tk-lane), var(--tk-text) 7%); }
.gp--editable .gp-cell:focus-visible { outline: 2px solid var(--tk-action); outline-offset: -2px; z-index: 2; }

.gp-count { height: auto; margin: 6px 0 0; }
.gp-num {
  text-align: center;
  font: 500 11px/1.4 var(--tk-round);
  color: var(--tk-muted);
  font-variant-numeric: tabular-nums;
}
.gp-num-beat { font-weight: 800; font-size: 14px; color: var(--tk-text); }
.gp-num.gp-now { color: var(--tk-action-text); }

/* The playhead: the step's column lit, and a line that moves through it. */
.gp-column, .gp-playhead {
  position: absolute;
  top: 0;
  bottom: 28px;
  pointer-events: none;
  opacity: 0;
  z-index: 1;
}
.gp-bars:not(.gp-stacked) .gp-bar-name ~ .gp-column,
.gp-bar-name ~ .gp-column, .gp-bar-name ~ .gp-playhead { top: 20px; }
.gp-column {
  left: calc(var(--gp-label) + (100% - var(--gp-label)) * var(--gp-step, 0) / 16);
  width: calc((100% - var(--gp-label)) / 16);
  background: var(--tk-now);
  border-radius: 6px;
}
.gp-playhead {
  left: calc(var(--gp-label) + (100% - var(--gp-label)) * var(--gp-pos, 0));
  width: 2px;
  margin-left: -1px;
  background: var(--tk-action);
  border-radius: 1px;
}
.gp-active .gp-column, .gp-active .gp-playhead { opacity: 1; }

.gp-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.gp button { font: inherit; }
.gp-play {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 22px 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--tk-action);
  color: var(--tk-on-action);
  font-weight: 700 !important;
  font-size: 16px !important;
  cursor: pointer;
}
.gp-play-icon {
  width: 0;
  height: 0;
  border-left: 13px solid currentColor;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}
.gp-playing .gp-play-icon { width: 13px; height: 13px; border: 0; background: currentColor; border-radius: 2px; }
.gp-tempo {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--tk-line);
  border-radius: 999px;
  min-height: 44px;
}
.gp-step {
  width: 44px;
  height: 42px;
  border: 0;
  background: none;
  color: var(--tk-text);
  font-size: 22px !important;
  line-height: 1;
  cursor: pointer;
  border-radius: 999px;
  touch-action: manipulation;
}
.gp-step:hover { background: var(--tk-now); }
.gp-bpm {
  min-width: 62px;
  text-align: center;
  font-family: var(--tk-round);
  font-variant-numeric: tabular-nums;
  border-radius: 8px;
  line-height: 1.05;
}
.gp-bpm b { display: block; font-size: 18px; }
.gp-bpm small { display: block; font: 700 9px/1.2 var(--tk-mono); letter-spacing: 0.08em; color: var(--tk-muted); }
.gp-loop {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px 0 12px;
  border: 1px solid var(--tk-line);
  border-radius: 999px;
  background: none;
  color: var(--tk-muted);
  font-size: 15px !important;
  cursor: pointer;
}
.gp-loop svg { width: 20px; height: 20px; }
.gp-loop[aria-pressed="true"] { color: var(--tk-text); border-color: var(--tk-bar-line); background: var(--tk-now); }
.gp-credit {
  margin-left: auto;
  font: 800 14px/1 var(--tk-round);
  color: var(--tk-muted) !important;
  text-decoration: none;
}
.gp-status { margin: 8px 0 0; min-height: 0; font-size: 14px; color: var(--tk-muted); }
.gp-status:empty { display: none; }
.gp :focus-visible { outline: 2px solid var(--tk-focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .gp-glyph { transition: none; }
  .gp-hit .gp-glyph { transform: none; }
}

/* ---------------------------------------------------------------- shared bits */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip, .pill, .seg button {
  font: 600 15px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--tk-line);
  background: var(--tk-panel);
  color: var(--tk-text);
  cursor: pointer;
}
.chip:hover, .pill:hover, .seg button:hover { border-color: var(--tk-bar-line); }
.chip[aria-pressed="true"] { background: var(--tk-text); color: var(--tk-ground); border-color: var(--tk-text); }
.pill-strong { border-color: var(--tk-bar-line); }
.go {
  font: 700 18px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 54px;
  padding: 0 30px;
  border: 0;
  border-radius: 999px;
  background: var(--tk-action);
  color: var(--tk-on-action);
  cursor: pointer;
}
.go:hover { filter: brightness(1.05); }
.chip:focus-visible, .pill:focus-visible, .seg button:focus-visible, .go:focus-visible {
  outline: 2px solid var(--tk-action);
  outline-offset: 2px;
}
.seg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--tk-line);
  border-radius: 999px;
}
.seg-name { font: 700 11px/1 var(--tk-mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--tk-muted); padding: 0 8px 0 10px; }
.seg button { border: 0; min-height: 34px; padding: 0 14px; background: none; }
.seg button[aria-pressed="true"] { background: var(--tk-text); color: var(--tk-ground); }

.cta-card {
  margin: 48px 0 8px;
  padding: 24px 22px;
  border-radius: 22px;
  background: var(--tk-panel);
  border: 1px solid var(--tk-line);
}
.cta-card h2 { margin: 0 0 8px; font-size: 22px; }
.cta-card p { color: var(--tk-muted); margin-bottom: 18px; }

/* ---------------------------------------------------------------- groove builder */

.gb-presets { margin: 28px 0 0; }
.gb-about { margin: 12px 0 0; color: var(--tk-muted); font-size: 16px; min-height: 1.5em; }
.gb-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 4px; }
.gb-note { min-height: 1.5em; font-size: 15px; color: var(--tk-muted); margin: 10px 0 0; overflow-wrap: anywhere; }
.tool-how h2 { margin-top: 40px; }
.legend { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 10px; }
.legend li { display: flex; align-items: center; gap: 14px; }
.lg { flex: 0 0 28px; height: 22px; display: inline-block; background-repeat: no-repeat; background-position: center; }
.lg-hh { color: var(--c-hh); }
.lg-hh, .lg-sn, .lg-bd, .lg-size { position: relative; }
.lg-hh::before, .lg-hh::after {
  content: ""; position: absolute; left: 3px; right: 3px; top: 50%; height: 4px; margin-top: -2px;
  background: var(--c-hh); border-radius: 2px; transform: rotate(45deg);
}
.lg-hh::after { transform: rotate(-45deg); }
.lg-sn::before { content: ""; position: absolute; inset: 1px 4px; border-radius: 50%; background: var(--c-sn); }
.lg-bd::before { content: ""; position: absolute; inset: 2px 0; border-radius: 6px; background: var(--c-bd); }
.lg-size::before, .lg-size::after { content: ""; position: absolute; border-radius: 50%; background: var(--c-sn); }
.lg-size::before { width: 20px; height: 20px; left: 0; top: 1px; }
.lg-size::after { width: 10px; height: 10px; right: 0; top: 6px; opacity: 0.72; }

/* ---------------------------------------------------------------- timing test */

.tt-card { padding-top: 32px; margin-bottom: 40px; }
.tt-card[hidden] { display: none; }
.tt-challenge {
  display: inline-block;
  margin: 4px 0 20px;
  padding: 10px 16px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--tk-action) 16%, var(--tk-panel));
  border: 1px solid color-mix(in srgb, var(--tk-action) 45%, var(--tk-line));
  font-weight: 600;
}
.tt-challenge[hidden] { display: none; }
.tt-steps { list-style: none; padding: 0; margin: 24px 0 28px; counter-reset: s; border-top: 1px solid var(--tk-line); }
.tt-steps li { counter-increment: s; position: relative; padding: 14px 0 14px 46px; border-bottom: 1px solid var(--tk-line); }
.tt-steps li::before {
  content: counter(s); position: absolute; left: 0; top: 14px; width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--tk-line); text-align: center; font: 700 14px/30px var(--tk-mono); color: var(--tk-muted);
}
.tt-steps strong { display: block; }
.tt-steps span { color: var(--tk-muted); font-size: 16px; }
.tt-small { font-size: 14px; }

.tt-run { padding-top: 40px; user-select: none; -webkit-user-select: none; touch-action: none; }
.tt-top { display: flex; align-items: center; gap: 12px; }
.tt-top .tool-label { margin: 0; color: var(--tk-action-text); }
.tt-seconds { margin-left: auto; font: 700 15px/1 var(--tk-round); font-variant-numeric: tabular-nums; color: var(--tk-muted); }
.tt-stop { min-height: 34px; padding: 0 14px; font-size: 14px; }
.tt-seconds:empty + .tt-stop { margin-left: auto; }
.tt-prompt { font-size: 19px; min-height: 3.2em; margin: 14px 0 12px; }
.tt-progress { height: 6px; border-radius: 3px; background: var(--tk-line); overflow: hidden; }
.tt-progress span {
  display: block; height: 100%; width: 100%; background: var(--tk-action);
  transform-origin: left; transform: scaleX(var(--done, 0));
}
.tt-pad {
  position: relative;
  display: grid;
  place-items: center;
  width: min(78vw, 320px);
  aspect-ratio: 1;
  margin: 34px auto 30px;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 50% 42%, #3b4048 0%, #24282e 62%, #1b1e22 100%);
  box-shadow: inset 0 0 0 10px #2b3037, 0 10px 40px rgba(0, 0, 0, 0.35);
  color: #f3f0ea;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.tt-pad:focus-visible { outline: 3px solid var(--tk-action); outline-offset: 6px; }
.tt-pad-text { font: 800 clamp(40px, 12vw, 64px)/1 var(--tk-round); font-variant-numeric: tabular-nums; z-index: 1; }
.tt-beat {
  position: absolute; inset: 0; border-radius: 50%;
  box-shadow: 0 0 0 0 var(--tk-action);
  transition: box-shadow 0.08s;
}
.tt-beat.tt-on { box-shadow: 0 0 0 6px var(--tk-action); }
.tt-pad::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid #f3f0ea; opacity: 0; transform: scale(0.6);
}
.tt-pad.tt-tap::after { animation: tt-ring 0.35s ease-out; }
@keyframes tt-ring { from { opacity: 0.55; transform: scale(0.7); } to { opacity: 0; transform: scale(1.05); } }
@media (prefers-reduced-motion: reduce) { .tt-pad.tt-tap::after { animation: none; } }

.tt-dots { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px 10px; max-width: 360px; margin: 0 auto; }
.tt-dots-warm { grid-template-columns: repeat(5, 22px); justify-content: center; }
.tt-dot { aspect-ratio: 1; width: 100%; max-width: 26px; justify-self: center; border-radius: 50%; background: var(--tk-line); }
.tt-dot-good { background: var(--tk-good); }
.tt-dot-close { background: var(--tk-warn); }
.tt-dot-off { background: var(--tk-bad); }
.tt-dot-miss { background: var(--tk-miss); box-shadow: inset 0 0 0 2px var(--tk-bar-line); }
.tt-dot-todo { background: none; box-shadow: inset 0 0 0 2px var(--tk-line); }

.tt-result { padding-top: 40px; }
.tt-result .eyebrow { margin-top: 0; }
.tt-score-line { display: flex; align-items: baseline; gap: 14px; margin: 0; outline: none; }
.tt-score { font: 800 clamp(88px, 26vw, 140px)/0.95 var(--tk-round); font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.tt-outof { font-size: 18px; color: var(--tk-muted); font-weight: 600; }
.tt-title { font-size: 28px; font-weight: 800; margin: 10px 0 4px; }
.tt-lean { font-size: 20px; margin-bottom: 18px; }
.tt-versus { font-weight: 700; color: var(--tk-action-text); }
.tt-dots-result { margin: 8px 0 14px; justify-items: start; max-width: 300px; gap: 6px 8px; }
.tt-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0 6px; }
.tt-board { margin-top: 26px; }
.tt-board ol { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--tk-line); }
.tt-board li { display: flex; align-items: baseline; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--tk-line); }
.tt-board li b { margin-left: auto; font: 800 22px/1 var(--tk-round); font-variant-numeric: tabular-nums; }
.tt-board-tries { color: var(--tk-muted); font-size: 14px; }
.tt-board li.tt-lead b { color: var(--tk-good); }
.tt-honest { margin-top: 24px; }
.key { white-space: nowrap; margin-right: 10px; }
.key::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.key-good::before { background: var(--tk-good); }
.key-close::before { background: var(--tk-warn); }
.key-off::before { background: var(--tk-bad); }
.key-miss::before { background: var(--tk-miss); box-shadow: inset 0 0 0 1.5px var(--tk-bar-line); }
body[data-phase="warmup"] .cta-card, body[data-phase="countin"] .cta-card, body[data-phase="test"] .cta-card { display: none; }
/* On a phone the loop button is its arrows only, so the controls stay on one line. */
@media (max-width: 420px) {
  .gp-loop { padding: 0 12px; }
  .gp-loop span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .gp-controls { gap: 8px; }
  .gp-play { padding: 0 18px 0 16px; }
}
