/* Beat Lab styles. Phone first: everything below is for a narrow screen,
   and the @media block near the end spreads it out from 760 px wide. */

:root {
  --bg: #0b0f1e;
  --panel: #151b33;
  --cell: #232b4d;
  --cell-beat: #2e3866;
  --line: #2f3a66;
  --text: #eef1ff;
  --dim: #9aa3c7;
  --accent: #7fe8ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body.covered { overflow: hidden; }   /* the lab can't scroll behind a game screen */

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;        /* no double-tap zoom on the buttons */
}
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.4; cursor: default; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 8px 24px;
}

/* ---- top bar ---- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
h1 { font-size: 1.4rem; margin: 6px 0; }
.top-buttons { display: flex; gap: 8px; }

.small {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.accent { background: var(--accent); color: #062430; border-color: var(--accent); font-weight: 600; }

/* ---- play, tempo, swing ---- */
.transport {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px 12px;
  align-items: center;
  margin: 8px 0;
}
.play {
  grid-row: span 2;
  height: 88px;
  border: 0;
  border-radius: 16px;
  background: #3ddc97;
  color: #062b1b;
  font-size: 1.2rem;
  font-weight: 700;
}
.play[aria-pressed="true"] { background: #ff6b6b; color: #2b0606; }

.slider { display: flex; flex-direction: column; gap: 2px; font-size: 0.9rem; color: var(--dim); }
.slider output { color: var(--text); font-weight: 600; }
input[type="range"] { width: 100%; min-width: 0; height: 32px; margin: 0; accent-color: var(--accent); }

.hint { color: var(--dim); font-size: 0.9rem; margin: 6px 2px; overflow-wrap: anywhere; }

/* ---- the grid ---- */
/* On a phone each row wraps into two lines of 8 steps, so all 16 fit
   at 360 px with every button at least 40 px wide. */
.track {
  background: var(--panel);
  border-radius: 12px;
  padding: 6px 4px;
  margin-bottom: 8px;
}
.track-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.name {
  width: 76px;
  height: 40px;
  flex: none;
  border: 0;
  border-left: 6px solid var(--c);
  border-radius: 8px;
  background: var(--cell);
  font-weight: 600;
  text-align: left;
  padding-left: 10px;
}
.mute {
  width: 44px;
  height: 40px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cell);
  font-weight: 700;
}
.mute[aria-pressed="true"] { background: #ff6b6b; color: #2b0606; border-color: #ff6b6b; }
.vol { flex: 1; accent-color: var(--c); }

.steps {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 2px;
}
.step {
  height: 44px;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: var(--cell);
}
.step.beat { background: var(--cell-beat); }   /* steps 1, 5, 9, 13: the beats */
.step[aria-pressed="true"] { background: var(--c); }
.step.now { box-shadow: inset 0 0 0 3px #fff; filter: brightness(1.35); }

/* ---- game screens ---- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-width: 640px;
  margin: 0 auto;
}
.screen[hidden] { display: none; }
.screen h2 { margin: 4px 0; }
.screen p { margin: 0; line-height: 1.45; }
.big { min-height: 56px; border-radius: 14px; border: 0; font-size: 1.1rem; }

.row-pick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.row-pick button {
  min-height: 52px;
  border: 2px solid var(--line);
  border-left: 8px solid var(--c);
  border-radius: 10px;
  background: var(--panel);
  font-weight: 600;
}
.row-pick button[aria-pressed="true"] { border-color: var(--c); background: var(--cell-beat); }

.calib-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--dim); }
.calib-line strong { color: var(--text); }

.game { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.game-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 1.1rem; }
.lane { position: relative; flex: 1; min-height: 200px; border-radius: 14px; background: var(--panel); overflow: hidden; }
.lane canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.judge {
  position: absolute;
  left: 0;
  right: 0;
  top: 30%;
  text-align: center;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--dim);
  pointer-events: none;
}
.judge.perfect { color: #3ddc97; }
.judge.good { color: var(--accent); }
.judge.miss { color: #ff6b6b; }

.pad {
  flex: none;
  height: min(28vh, 170px);
  min-height: 96px;
  border: 0;
  border-radius: 18px;
  background: var(--cell-beat);
  font-size: 1.5rem;
  font-weight: 700;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pad:active { background: var(--accent); color: #062430; }
#calib .pad { margin-top: auto; }

.score { font-size: 1.2rem; }
.score strong { font-size: 3rem; display: block; }
.counts { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin: 0; font-size: 1.1rem; }
.counts dt { color: var(--dim); }
.counts dd { margin: 0; font-weight: 700; text-align: right; }

/* ---- wider screens: one line of 16 per row ---- */
@media (min-width: 760px) {
  main { padding: 16px 20px 32px; }
  h1 { font-size: 1.8rem; }
  .transport { grid-template-columns: 120px 1fr 1fr; }
  .play { grid-row: auto; height: 64px; }
  .track {
    display: grid;
    grid-template-columns: 230px 1fr;
    gap: 12px;
    align-items: center;
    padding: 8px 10px;
  }
  .track-head { margin: 0; }
  .steps { grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 4px; }
  .step:nth-child(4n + 1) { margin-left: 4px; }   /* a little gap before each beat */
  .step:first-child { margin-left: 0; }
  .step { height: 48px; }
}
