/* Timing screen: setup, count-in, running, result, stopped (spec 5.11-5.13, chart 8.4). */

#mode-timing .tm { padding-bottom: var(--s4); }
#mode-timing:is([data-state="countin"], [data-state="running"]) .tm { gap: var(--s2); }

/* ------------------------------------------------- visibility per run state */
#mode-timing .tm-lockstrip,
#mode-timing .tm-sumbtn,
#mode-timing .tm-countin,
#mode-timing .tm-monitor,
#mode-timing .tm-avgline,
#mode-timing .tm-tiles { display: none; }

#mode-timing:is([data-state="countin"], [data-state="running"]) .tm-lockstrip { display: flex; }
#mode-timing[data-state="result"] .tm-sumbtn { display: flex; }
#mode-timing[data-state="countin"] .tm-countin { display: flex; }
#mode-timing[data-state="running"] .tm-monitor { display: grid; }
#mode-timing[data-state="running"] .tm-avgline { display: block; }
/* the AVG line's slot is held through the count-in, so the chart and tiles
   do not jump down when playing starts */
#mode-timing[data-state="countin"] .tm-avgline { display: block; visibility: hidden; }
#mode-timing:is([data-state="countin"], [data-state="running"]) .tm-tiles { display: grid; }
#mode-timing:is([data-state="countin"], [data-state="running"]) .tm-title { display: none; }
#mode-timing[data-state="result"] :is(.tm-setup, .tm-chart-home) { display: none; }

/* ----------------------------------------------------------------- title */
.tm-title__slot { display: flex; justify-content: flex-end; min-width: 0; }

/* ------------------------------------------------------ summary strip */
.tm-lockstrip, .tm-sumbtn { padding: 0 10px; letter-spacing: .03em; }
.tm-sum { flex: 1 1 auto; display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; }
.tm-sum > * { flex: none; }
.tm-sumbtn { cursor: pointer; }
.tm-sumbtn:active { transform: translate(1px, 1px); }
.tm-lockstrip .summary__lock .icon { width: 18px; height: 18px; }

/* ------------------------------------------- #tm-final: notice + result */
.tm-final { display: flex; flex-direction: column; gap: var(--s3); }
.tm-final > :empty { display: none; }
.tm-notice { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s2); }
.tm-notice__line { font: 400 var(--t-body)/1.4 var(--mono-font); color: var(--paper); }
.tm-result, .tm-result-foot { display: flex; flex-direction: column; gap: var(--s3); }

/* ------------------------------------------------------------ setup cards */
.tm-setup { display: flex; flex-direction: column; gap: var(--s3); }
.tc-card {
  display: block; width: 100%;
  padding: var(--s3) 14px;
  background: var(--white); color: var(--ink);
  border: var(--border);
  box-shadow: var(--sh-card);
  text-align: left;
}
.tc-cap {
  font: 600 var(--t-label)/1 var(--label-font);
  letter-spacing: .08em;
  color: var(--ink60);
}

.tc-tempo {
  display: grid; grid-template-columns: auto var(--hit) minmax(0, 1fr) var(--hit);
  align-items: center; column-gap: var(--s3);
  padding-block: 10px;
}
.tc-step {
  display: grid; place-items: center;
  width: var(--hit); height: var(--hit);
  border: var(--border);
  background: var(--white);
  box-shadow: var(--sh-ctl);
  font: 700 22px/1 var(--mono-font);
}
.tc-step:active { transform: translate(2px, 2px); box-shadow: none; }
.tc-step:disabled { background: var(--cream3); color: var(--ink60); border-style: dashed; box-shadow: none; transform: none; cursor: default; }
.tc-tempo .tc-val { min-width: 0; text-align: center; white-space: nowrap; }
.tc-tempo .tc-val b { font: 700 40px/1 var(--mono-font); letter-spacing: -.03em; }
.tc-unit { font: 600 var(--t-control)/1 var(--label-font); letter-spacing: .05em; }
/* 320 px: "120 BPM" clear of the + stepper, QUARTERS clear of its borders */
@media (max-width: 359px) {
  .tc-tempo { column-gap: var(--s2); }
  .tc-tempo .tc-val b { font-size: 32px; }
  #tm-grid > button { padding: var(--s1) 2px; font-size: var(--t-label); letter-spacing: .02em; }
}

.tc-hold { display: flex; flex-direction: column; gap: 6px; }
.tc-hold .seg + .tc-cap { margin-top: 6px; }

.tc-click {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: var(--s3);
  min-height: 72px;
}
.tc-click:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.tc-click__text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tc-hint { font: 400 var(--t-body)/1.35 var(--mono-font); color: var(--ink); }
.tc-click .tc-val { display: flex; align-items: center; gap: 10px; }
.tc-click .tc-val b { min-width: 30px; font: 700 var(--t-control)/1 var(--label-font); letter-spacing: .05em; }
.tc-switch {
  position: relative; flex: none;
  width: 52px; height: 30px;
  border: var(--border);
  background: var(--white);
  box-shadow: var(--sh-ctl);
}
.tc-switch i {
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: var(--white);
  border: var(--border);
}
.tc-click.on .tc-switch { background: var(--ink); }
.tc-click.on .tc-switch i { left: auto; right: 3px; background: var(--amber); border-color: var(--amber); }

.tm-latency { font: 400 var(--t-caption)/1.35 var(--mono-font); color: var(--ink60); }

/* ------------------------------------------------------ count-in + monitor */
.tm-countin { position: relative; }
.tm-countin__cap {
  position: absolute; left: 12px; top: 10px;
  font: 700 var(--t-label)/1 var(--label-font); letter-spacing: .08em;
}
.tm-countin .countin__dots { display: grid; grid-template-columns: repeat(2, 20px); gap: var(--s2); }
.tm-monitor { min-height: 124px; align-content: end; }
.tm-monitor .monitor__cap { margin: 0 0 6px; }
/* size by glyph count (monitorSize via --mon-fs), so short screens can scale it */
.tm-monitor #tm-steadiness { display: block; font-size: var(--mon-fs, var(--t-monitor)); }
.tm-monitor .monitor__side { margin: 0; }
/* until hit 6: LISTENING alone on the value baseline, caption on top (no
   "—" beside it); the box keeps its height, so nothing moves at hit 6 */
.tm-monitor.is-idle { align-content: space-between; }
.tm-monitor.is-idle #tm-steadiness { display: none; }
.tm-avgline { font: 700 var(--t-avg)/1.1 var(--label-font); letter-spacing: .02em; }

/* ------------------------------------------------------- drift chart (8.4) */
.tm-chart { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px 10px; }
.tm-chart .sec-head__aside { font-family: var(--label-font); font-weight: 600; letter-spacing: .06em; }
.tm-legend {
  display: flex; flex-wrap: wrap; align-items: center; column-gap: 12px; row-gap: 2px;
  font: 400 var(--t-axis)/1.3 var(--mono-font); color: var(--ink60);
}
.tm-legend > span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.lg-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ink); }
.lg-dot--in { width: 6px; height: 6px; background: var(--dot-strong); }
.lg-line { display: inline-block; width: 14px; height: 2px; background: var(--ink); }
.lg-band { display: inline-block; width: 14px; height: 9px; background: var(--tint); border-block: 1px solid rgba(20, 18, 16, .3); }
.tm-plot { position: relative; height: var(--h-chart); }
.tm-plot canvas { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; }
/* near the top of the plot, so the first view at 390 x 763 keeps it clear of the bar */
.tm-plot__hint {
  position: absolute; left: 50%; top: var(--s2); /* high in the plot: clear of the bar top on 700-760 px tall screens */
  transform: translateX(-50%);
  width: max-content; max-width: 76%;
  padding: 6px 10px;
  background: var(--white);
  border: var(--border);
  font: 400 var(--t-body)/1.4 var(--mono-font);
  text-align: center;
  pointer-events: none;
}

/* ------------------------------------------------------------ live tiles */
#mode-timing .statbox b .unit { margin-left: 2px; }
#mode-timing .statbox b.tm-drift .unit { font-size: var(--t-caption); letter-spacing: 0; }
#mode-timing .statbox b.tm-drift.is-long { font-size: 22px; }
#mode-timing .statbox em { margin-top: 2px; white-space: nowrap; }
/* live tiles carry no sub-line, so they stay the 76 px of Rudiments' live
   tiles and clear STOP; the signed ms/min carries the drift's direction and
   the result tiles add "later" / "earlier" */
.tm-tiles .statbox em { display: none; }
/* 320 px: a 3-glyph drift ("−20 ms/min") and "105 of 115" fit their tiles */
@media (max-width: 359px) {
  #mode-timing .stat-strip .statbox { padding-inline: 6px; }
  #mode-timing .statbox b.tm-drift.is-long { font-size: 20px; }
}

/* ----------------------------------------------------------- result */
.tm-hero .hero__cap { display: block; }
.tm-hero__num { display: flex; align-items: baseline; gap: 6px; }
.tm-hero__num b { font: 700 var(--t-hero)/.86 var(--mono-font); letter-spacing: -.03em; white-space: nowrap; }
.tm-hero__num--long b { font-size: 72px; }
.tm-hero__num .unit { margin-left: 0; font-size: 28px; }
.tm-vs { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); }
.tm-vs__delta { font: 700 18px/1.1 var(--label-font); letter-spacing: .03em; }
/* a baseline from another tempo carries it in the chip ("… AT 60 BPM · 16THS"):
   let that longer chip wrap on narrow phones instead of overflowing */
.tm-vs__chip { height: auto; min-height: 28px; padding-block: 4px; white-space: normal; line-height: 1.2; }
.tm-note { padding: 10px 12px; }
/* never cut a fact short: factLine() already caps it at 100 characters, which
   a mixed entrance ("ran from 30 ms early to 5 ms late…") can need on a
   320 px phone, where a line clamp would hide the end of it */
#mode-timing .fact { display: block; overflow: visible; -webkit-line-clamp: none; line-clamp: none; }
.tm-foot { font: 400 var(--t-axis)/1.3 var(--mono-font); color: var(--ink60); }

/* ------------------------------------------------------------- bar
   Result: baseline + START AGAIN. Fixed shares (no auto minimum): the
   SET BASELINE / HOLD / SET states keep one width, so START AGAIN never
   moves or leaves the screen. Under 375 px the labels step down; the primary
   stays at 24 px (white on red floor). */
#mode-timing .bar:has(> .btn ~ .btn) { grid-template-columns: minmax(0, 1fr) minmax(0, 1.9fr); }
#mode-timing .bar > .btn { min-width: 0; }
@media (max-width: 374px) {
  #mode-timing .bar:has(> .btn ~ .btn) > .btn--primary { gap: 6px; padding-inline: 10px; font-size: 24px; letter-spacing: .02em; }
  #mode-timing .bar > .tm-baseline { font-size: 16px; }
}
.tm-baseline { padding: 0 var(--s2); white-space: normal; line-height: 1; }
.tm-baseline__main { display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center; }
/* the sub-line wraps (HOLD TO / REPLACE) rather than run into the borders */
.tm-baseline .btn__sub { white-space: normal; text-align: center; line-height: 1.15; letter-spacing: .06em; }
@media (max-width: 359px) { .tm-baseline .btn__sub { letter-spacing: .02em; } }
#tm-baseline.is-set,
#tm-baseline.is-set:active {
  background: var(--white); color: var(--ink);
  border-style: solid;
  box-shadow: none; transform: none;
  cursor: default;
}
#tm-baseline.is-set .btn__sub { display: inline-flex; align-items: center; gap: 4px; color: var(--ink60); }
#tm-baseline.is-set .btn__sub .icon { width: 12px; height: 12px; color: var(--green-ink); }

/* ------------------------------------------- short phones (640-700 tall)
   iPhone SE installed (375 x 647) and 640-tall Androids, while live: the
   count-in panel and monitor step down, the plot shrinks and the chart's
   title row goes (the plot carries EARLY / LATE, the legend the units), so
   the tiles clear the STOP bar. */
/* 701-760 px tall (a 360x740 Android, say): the live chart gives up height as
   the screen shrinks, so the tiles clear STOP at every height down to the
   700 px step instead of sitting under it */
@media (max-height: 760px) {
  #mode-timing:is([data-state="countin"], [data-state="running"]) .tm-plot {
    height: clamp(120px, calc(100vh - 560px), 200px);
    height: clamp(120px, calc(100dvh - 560px), 200px);
  }
}
@media (max-height: 700px) {
  .tm-countin { height: 88px; }
  .tm-countin b { font-size: 72px; }
  .tm-monitor { min-height: 88px; }
  .tm-monitor #tm-steadiness { font-size: calc(var(--mon-fs, var(--t-monitor)) * .66); }
  #mode-timing:is([data-state="countin"], [data-state="running"]) .tm-chart > .sec-head { display: none; }
  #mode-timing:is([data-state="countin"], [data-state="running"]) .tm-plot { height: 120px; }
}
