/*
  Layout, smallest first:
    phone    one column that fills the screen
    tablet   the same column, centred, with more breathing room (>= 640px)
    laptop   a web page: controls in a side panel, the bar in a wide card (>= 960px)
  Colours and shapes are shared with Simple Tuner.
*/

:root {
  color-scheme: light dark;
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #ebebe7;
  --text: #121214;
  --muted: #6d6d73;
  --line: #d9d9d4;
  --good: #0a9d68;
  --good-tint: rgba(10, 157, 104, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c0e;
    --surface: #17171a;
    --surface-2: #222226;
    --text: #f4f4f5;
    --muted: #8c8c95;
    --line: #2d2d33;
    --good: #34d399;
    --good-tint: rgba(52, 211, 153, 0.16);
    --shadow: none;
    --card-shadow: none;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p {
  margin: 0;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

button:focus-visible,
.pad:focus-visible,
input:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* ---------- Page frame ---------- */

.page {
  min-height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 20px)
    calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + 20px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 32px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark {
  width: 24px;
  height: 24px;
  flex: none;
}

.tagline {
  display: none;
  font-size: 14px;
  color: var(--muted);
}

.site-footer {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  font-size: 13px;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 2px 6px;
  margin-left: 14px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface);
  font: 600 11px/1.3 ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  color: var(--text);
  text-align: center;
}

.shortcuts kbd:first-child {
  margin-left: 0;
}

.shortcuts kbd + kbd {
  margin-left: 3px;
}

/* ---------- App ---------- */

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 12px;
}

.segmented button {
  height: 36px;
  border-radius: 9px;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.segmented button[aria-selected='true'] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ---------- The bar ---------- */

.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.signature {
  display: grid;
  gap: 4px;
}

.sig-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sig-rule {
  width: 108px;
  height: 2px;
  border-radius: 1px;
  background: var(--text);
}

.sig-words {
  font-size: 14px;
  line-height: 1.25;
  color: var(--muted);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

.step {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 18px;
  line-height: 1;
  color: var(--text);
  transition: transform 0.1s;
}

.step:active {
  transform: scale(0.92);
}

.step-num {
  width: 44px;
  text-align: center;
  font-size: 26px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stepper.small .step {
  width: 28px;
  height: 28px;
  font-size: 16px;
}

.stepper.small {
  gap: 6px;
}

.counter {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 64px;
}

.count {
  font-size: 84px;
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  transition: color 0.08s;
}

.count[data-state='idle'] {
  color: var(--line);
}

.count[data-state='one'] {
  color: var(--good);
}

.caption {
  min-height: 16px;
  font-size: 13px;
  color: var(--muted);
}

/* Rows of squares: the note ladder in Click, the drums elsewhere. */

.rows {
  display: grid;
  gap: 4px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-name {
  flex: none;
  width: 100px;
  height: 28px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
}

.rows:not([data-mode='click']) .row-name {
  width: 54px;
}

.row-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line);
  transition: background 0.15s;
}

.row[data-on='true'] .row-name {
  color: var(--text);
  font-weight: 650;
}

.row[data-on='true'] .row-dot {
  background: var(--good);
}

.cells {
  position: relative;
  flex: 1;
  height: 28px;
  min-width: 0;
}

.cell {
  position: absolute;
  top: 0;
  bottom: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 5px;
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.row[data-on='true'] .cell {
  background: var(--surface);
  box-shadow: inset 0 0 0 1.5px var(--text);
  color: var(--text);
}

.cell.current {
  background: var(--line);
}

.row[data-on='true'] .cell.current {
  background: var(--good-tint);
  box-shadow: inset 0 0 0 1.5px var(--good);
  color: var(--good);
}

.row[data-kind='count'] .cell {
  background: none;
}

.row[data-kind='count'] .cells,
.row[data-kind='count'] .row-name {
  height: 22px;
}

.row[data-kind='count'] .cell.on-beat {
  color: var(--text);
  font-weight: 650;
}

.row[data-kind='count'] .cell.current {
  background: var(--good-tint);
  color: var(--good);
}

.row[data-kind='drum'] .cells {
  height: 32px;
}

.row[data-kind='drum'] .cell.on-group {
  background: var(--line);
}

.row[data-kind='drum'] .cell.current {
  background: var(--muted);
}

.row[data-kind='drum'] .cell.hit {
  background: var(--text);
}

.row[data-kind='drum'] .cell.hit.soft {
  background: var(--muted);
}

.row[data-kind='drum'] .cell.hit.current {
  background: var(--good);
}

.rows[data-mode='feel'] .row[data-kind='drum'] .cells,
.rows[data-mode='feel'] .row-name {
  height: 20px;
}

.rows[data-mode='feel'] .cell {
  border-radius: 4px;
}

.hint {
  font-size: 13px;
  color: var(--muted);
}

/* Bars: which bar the grid is showing, and how many there are. */

.bars-row {
  display: none;
  align-items: center;
  gap: 10px;
}

.app[data-mode='drums'] .bars-row {
  display: flex;
}

.bars-row .chips {
  flex: 1;
}

.label {
  font-size: 14px;
  color: var(--muted);
}

.label .sub {
  display: block;
  font-size: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  height: 30px;
  padding: 0 12px;
  border-radius: 15px;
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chip[aria-pressed='true'] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.bar-chip {
  min-width: 30px;
  padding: 0 8px;
}

.bar-chip.playing {
  background: var(--good);
  border-color: var(--good);
}

/* ---------- The Feel pad ---------- */

.pad {
  display: none;
  position: relative;
  height: min(46vw, 230px);
  border-radius: 20px;
  background: var(--surface-2);
  touch-action: none;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
}

.app[data-mode='feel'] .pad {
  display: block;
}

.pad::before,
.pad::after {
  content: '';
  position: absolute;
  background: var(--line);
}

.pad::before {
  left: 50%;
  top: 30px;
  bottom: 30px;
  width: 1px;
}

.pad::after {
  top: 50%;
  left: 70px;
  right: 80px;
  height: 1px;
}

.pad-label {
  position: absolute;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  pointer-events: none;
}

.pad-top {
  top: 9px;
  left: 50%;
  transform: translateX(-50%);
}

.pad-bottom {
  bottom: 9px;
  left: 50%;
  transform: translateX(-50%);
}

.pad-left {
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.pad-right {
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.pad-dot {
  position: absolute;
  z-index: 1;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 0 0 6px var(--bg);
  pointer-events: none;
  transition: background 0.2s;
}

.app[data-playing='true'] .pad-dot {
  background: var(--good);
}

/* ---------- Controls ---------- */

.controls {
  display: grid;
  gap: 12px;
}

.control-block {
  display: none;
  gap: 8px;
}

.app[data-mode='drums'] .control-block {
  display: grid;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 36px;
}

.tempo {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type='range'] {
  flex: 1;
  max-width: 240px;
  margin: 0;
  accent-color: var(--text);
}

.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 54px;
  margin-top: auto;
  border-radius: 16px;
  background: var(--text);
  color: var(--bg);
  font-size: 17px;
  font-weight: 600;
  transition: background 0.2s, color 0.2s, transform 0.1s;
}

.primary:active {
  transform: scale(0.985);
}

.primary .dot {
  display: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
}

.primary.playing {
  background: var(--surface-2);
  color: var(--text);
}

.primary.playing .dot {
  display: block;
}

.fine {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ---------- Privacy page ---------- */

.text-link {
  font-size: 14px;
  color: var(--muted);
}

.prose {
  max-width: 62ch;
  padding: 16px 0 40px;
  font-size: 16px;
  line-height: 1.6;
}

.prose h1 {
  font-size: 32px;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}

.prose h2 {
  font-size: 18px;
  margin: 28px 0 6px;
}

.prose p {
  margin-bottom: 10px;
}

.prose .lede {
  font-size: 18px;
  color: var(--muted);
}

.prose ul {
  margin: 0 0 10px;
  padding-left: 20px;
}

.prose .updated {
  margin-top: 28px;
  font-size: 14px;
  color: var(--muted);
}

/* ---------- Pointer devices ---------- */

@media (hover: hover) {
  .segmented button:hover,
  .row-name:is(button):hover {
    color: var(--text);
  }

  .step:hover {
    background: var(--line);
  }

  .chip:hover {
    border-color: var(--muted);
  }

  button.cell:hover {
    box-shadow: inset 0 0 0 1.5px var(--muted);
  }

  .primary:hover {
    opacity: 0.9;
  }
}

/* ---------- Tablet ---------- */

@media (min-width: 640px) {
  .page {
    padding-top: calc(env(safe-area-inset-top) + 20px);
    padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
    gap: 18px;
  }

  .tagline {
    display: block;
  }

  .app {
    gap: 18px;
  }

  .count {
    font-size: 104px;
  }

  .cells {
    height: 32px;
  }

  .row[data-kind='drum'] .cells {
    height: 38px;
  }

  .pad {
    height: 260px;
  }
}

/* ---------- Laptop ---------- */

@media (min-width: 960px) {
  .page {
    max-width: 1120px;
    padding-left: 32px;
    padding-right: 32px;
    gap: 24px;
  }

  .brand {
    font-size: 17px;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
  }

  .site-footer {
    display: flex;
  }

  .fine {
    display: none;
  }

  .app {
    flex: none;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    grid-template-areas:
      'modes stage'
      'controls stage'
      'play stage';
    grid-template-rows: auto auto 1fr;
    align-items: start;
    gap: 16px 24px;
  }

  .modes {
    grid-area: modes;
  }

  .stage {
    grid-area: stage;
    gap: 18px;
    padding: 32px;
    border-radius: 28px;
    background: var(--surface);
    box-shadow: var(--card-shadow);
    min-height: 520px;
  }

  .controls {
    grid-area: controls;
    gap: 16px;
    padding: 20px;
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--card-shadow);
  }

  .primary {
    grid-area: play;
    margin-top: 0;
  }

  .sig-words {
    font-size: 15px;
  }

  .count {
    font-size: 128px;
  }

  .row-name {
    width: 116px;
    font-size: 14px;
  }

  .rows:not([data-mode='click']) .row-name {
    width: 70px;
  }

  .cells {
    height: 38px;
  }

  .cell {
    border-radius: 7px;
    font-size: 12px;
  }

  .row[data-kind='drum'] .cells {
    height: 44px;
  }

  .rows[data-mode='feel'] .row[data-kind='drum'] .cells,
  .rows[data-mode='feel'] .row-name {
    height: 24px;
  }

  .pad {
    height: 280px;
    background: var(--bg);
  }

  .pad-dot {
    box-shadow: 0 0 0 6px var(--surface);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
