/*
 * Slow-down and loop trainer (/tools/practice-player/). Loaded after site.css
 * and built only from its tokens. Mobile first: on phones the Play / Loop /
 * Speed bar sticks to the bottom of the screen (thumb reach); from 1100 px the
 * stage sits on the left with the settings panels on the right.
 */

/* ------------------------------------------------------------ errors and empty state */
.pp-error { margin-top: 0; }
.pp-error:empty { display: none; }

.pp-open { display: grid; gap: var(--s-3); }
.pp-drop {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s-2) var(--s-3); min-height: clamp(240px, 42vh, 30rem); padding: var(--s-6) var(--s-4);
  border: 3px dashed var(--line-strong); border-radius: var(--r-lg); background: var(--surface);
  box-shadow: var(--e-1); text-align: center; cursor: pointer; font-weight: 400;
  transition: border-color var(--t-base), background-color var(--t-base);
}
.pp-drop:hover { border-color: var(--indigo); background: var(--surface-2); }
.pp-drop.is-over { border-style: solid; border-color: var(--indigo); background: var(--indigo-soft); }
.pp-drop.is-busy { cursor: progress; }
/* The real file input covers the whole zone (invisible), so any tap opens the picker. */
.pp-drop input[type="file"], .pp-change input[type="file"] {
  position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; margin: 0; padding: 0;
  opacity: 0; cursor: pointer; font-size: 0;
}
.pp-drop:focus-within { outline: 3px solid var(--focus); outline-offset: 4px; }
@supports selector(:has(*)) {
  .pp-drop:focus-within { outline: none; }
  .pp-drop:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 4px; }
}
.pp-drop-icon { width: 56px; height: 56px; fill: none; stroke: var(--indigo); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.pp-drop-title { font-family: var(--font-display); font-weight: 600; font-size: var(--step-2); line-height: 1.2; color: var(--text); }
.pp-drop-cta { margin-top: var(--s-2); pointer-events: none; }
.pp-drop-sub { color: var(--muted); }
.pp-promise { margin: 0; text-align: center; font-weight: 600; color: var(--text); }

/* ------------------------------------------------------------ player layout */
.pp-player { display: grid; gap: var(--s-5); grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "side" "dock"; }
.pp-stage { grid-area: stage; }
.pp-side { grid-area: side; display: grid; gap: var(--s-5); align-content: start; }
.pp-dock { grid-area: dock; }

.pp-stage {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--e-1); padding: var(--s-4); min-width: 0;
}
@media (min-width: 640px) { .pp-stage { padding: var(--s-5); } }

.pp-filebar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-4); margin-bottom: var(--s-3); }
.pp-filename { margin: 0; font-size: var(--step-1); min-width: 0; flex: 1 1 14rem; overflow-wrap: anywhere; }
.pp-change { position: relative; overflow: hidden; min-height: 44px; padding: 6px 16px; font-size: var(--step--1); box-shadow: 0 3px 0 var(--line-strong); }
.pp-change:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }

.pp-notices { list-style: none; padding: 0; margin: 0 0 var(--s-3); display: grid; gap: var(--s-2); }
.pp-notices li { margin: 0; border-left: 4px solid var(--gold); background: var(--surface-2); padding: var(--s-2) var(--s-3); border-radius: 0 var(--r-sm) var(--r-sm) 0; font-size: var(--step--1); }

/* ------------------------------------------------------------ waveform */
.pp-wave {
  position: relative; height: 184px; border-radius: var(--r-md); background: var(--surface-2);
  border: 1px solid var(--line); touch-action: pan-y; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
@media (min-width: 640px) { .pp-wave { height: 224px; } }
@media (min-width: 1100px) { .pp-wave { height: clamp(240px, 17vw, 30rem); } }
.pp-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: inherit; cursor: pointer; }
.pp-canvas:focus-visible { outline-offset: 3px; }

.pp-handle {
  position: absolute; top: 0; bottom: 0; left: 0; width: 44px; margin-left: -22px; z-index: 2;
  cursor: ew-resize; touch-action: none; -webkit-tap-highlight-color: transparent;
}
.pp-handle::before { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; margin-left: -1.5px; background: var(--saffron-text); }
.pp-handle-tab {
  position: absolute; top: -1px; left: 50%; transform: translateX(-50%); display: grid; place-items: center;
  min-width: 28px; height: 28px; padding: 0 6px; border-radius: 0 0 8px 8px; background: var(--saffron);
  border: 2px solid var(--saffron-edge); border-top: 0; color: var(--saffron-ink); font-weight: 800; font-size: .9375rem; line-height: 1;
}
.pp-handle:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-radius: var(--r-sm); }
.pp-handle.is-dragging .pp-handle-tab { background: var(--saffron-edge); color: var(--indigo-ink); }
:root[data-theme="dark"] .pp-handle.is-dragging .pp-handle-tab { color: var(--saffron-ink); }

.pp-wave-status {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); margin: 0; z-index: 1;
  padding: 6px 14px; border-radius: var(--r-pill); background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); font-size: var(--step--1); font-weight: 600; white-space: nowrap; pointer-events: none;
}

.pp-under { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-4); margin-top: var(--s-3); }
.pp-view { margin: 0; }
.pp-time { margin: 0; font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.375rem; line-height: 1.2; }
.pp-total { color: var(--muted); font-weight: 600; font-size: .8em; }
@media (min-width: 1100px) { .pp-time { font-size: 1.75rem; } }

/* ------------------------------------------------------------ loop controls */
.pp-loop-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); margin-top: var(--s-4); }
.pp-skip { width: 48px; height: 48px; font-size: 1rem; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.pp-set { min-width: 6.5rem; flex: 1 1 auto; max-width: 11rem; }
@media (min-width: 640px) { .pp-set { flex: 0 0 auto; } }
.pp-loop-info { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-4); margin-top: var(--s-2); }
.pp-loop-text { margin: 0; flex: 1 1 16rem; min-height: 3.2em; }
.pp-loop-text .num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700; }
.pp-loop-text .gap { color: var(--saffron-text); font-weight: 700; }
.pp-move { display: inline-flex; align-items: center; gap: var(--s-1); }
.pp-move-btn { border-color: var(--line-strong); }
.pp-move-btn svg { fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------ speed */
.pp-speed-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3) var(--s-5); margin-top: var(--s-4); padding-top: var(--s-4); border-top: 1px solid var(--line); }
.pp-quick { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.pp-chip {
  min-width: 64px; min-height: 44px; padding: 6px 14px; border-radius: var(--r-pill);
  border: 2px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 700; font-family: var(--font-num); font-variant-numeric: tabular-nums;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.pp-chip:hover { background: var(--surface-2); }
.pp-chip[aria-pressed="true"] { background: var(--indigo); border-color: var(--indigo); color: var(--indigo-ink); }
.pp-speed-field { flex: 1 1 16rem; }
.pp-pitch-note { margin: var(--s-3) 0 0; }

/* ------------------------------------------------------------ side panels */
.pp-panel h2 { margin: 0 0 var(--s-3); font-size: var(--step-1); }
.pp-panel > p { margin-bottom: var(--s-3); }
.pp-panel { display: flex; flex-direction: column; align-items: stretch; }
.pp-panel > button, .pp-panel > .button { align-self: flex-start; }
.pp-h3 { font-size: 1.125rem; margin: var(--s-5) 0 var(--s-1); }
.pp-pause .chip span { min-width: 56px; }
.pp-ladder { display: grid; gap: var(--s-3); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pp-ladder input { width: 100%; }
.pp-ladder label { font-size: .95rem; }
.pp-trainer-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-4); margin-top: var(--s-4); }
.pp-trainer-state { margin: 0; flex: 1 1 12rem; }
.pp-trainer-state .num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700; }
#pp-trainer-go[aria-pressed="true"] { background: var(--surface); color: var(--text); border-color: var(--line-strong); box-shadow: 0 4px 0 var(--line-strong); }

.pp-markers { list-style: none; padding: 0; margin: var(--s-4) 0 0; display: grid; gap: var(--s-3); }
.pp-markers:empty { display: none; }
.pp-marker {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--s-2); align-items: center;
  padding: var(--s-2); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface);
}
.pp-marker.is-current { border-color: var(--teal); box-shadow: inset 4px 0 0 var(--teal); }
.pp-mk-time {
  min-height: 44px; min-width: 5.5rem; padding: 4px 12px; border-radius: var(--r-pill);
  border: 2px solid var(--teal); background: var(--surface); color: var(--text);
  font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700;
}
.pp-mk-time:hover { background: var(--surface-2); }
.pp-mk-name { width: 100%; min-height: 44px !important; padding: 6px 10px !important; }
.pp-mk-del { border-color: var(--line-strong); font-size: 1.5rem; line-height: 1; }
.pp-mk-loop { grid-column: 1 / -1; justify-self: start; min-height: 44px !important; padding: 4px 14px !important; font-size: var(--step--1); box-shadow: 0 3px 0 var(--line-strong) !important; margin-bottom: 3px !important; }

.pp-mix { display: flex; width: 100%; margin: 0 0 var(--s-1); }

.pp-mix .seg { flex: 1 1 0; }
.pp-mix .seg span { width: 100%; padding-left: 6px; padding-right: 6px; }
.pp-mix-label { font-weight: 650; margin: 0 0 var(--s-2); }
.pp-mix-hint { margin: var(--s-1) 0 var(--s-4); }
.pp-cents-field { margin-bottom: var(--s-4); }
.pp-cents-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); }
.pp-cents-row input[type="range"] { flex: 1 1 10rem; width: auto; }
.pp-cents-out { min-width: 6.5em; font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700; }
.pp-cents-reset { min-height: 44px; padding: 4px 14px; font-size: var(--step--1); }
.pp-cents-note.is-paused, #pp-cents-note.is-paused { color: var(--rose); font-weight: 600; }
.pp-forget-status { margin: var(--s-2) 0 0; min-height: 1.4em; }

/* ------------------------------------------------------------ dock: Play, Loop, Speed */
.pp-dock {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-2);
  position: sticky; bottom: 0; z-index: 10;
  margin: 0 calc(-1 * var(--gutter)); padding: var(--s-2) var(--gutter);
  padding-bottom: max(var(--s-2), env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line-strong);
  box-shadow: 0 -8px 24px rgb(31 26 23 / .10);
}
.pp-dock button { margin-bottom: 0; }
/* Play and Loop sizes are scoped to .pp-dock: site.css styles button.primary / button.secondary
   (specificity 0,1,1), which beat plain .pp-play / .pp-loop, so until 5 Nov 2026 these paddings and
   heights never applied and the dock ran 7 px past a 375 px screen. */
.pp-dock .pp-play { flex: 1 1 auto; min-width: 5.5rem; min-height: 56px; padding: 8px 14px; font-size: 1.125rem; white-space: nowrap; }
.pp-play svg { width: 22px; height: 22px; fill: currentColor; flex: none; }
.pp-play .pp-ico-pause { display: none; }
.pp-play[aria-pressed="true"] .pp-ico-pause { display: block; }
.pp-play[aria-pressed="true"] .pp-ico-play { display: none; }
.pp-dock .pp-loop { flex: 0 0 auto; min-height: 56px; padding: 6px 14px; gap: 6px; white-space: nowrap; }
.pp-loop svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.pp-loop-state { font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 1px 6px; border-radius: var(--r-pill); border: 1.5px solid currentColor; }
.pp-loop[aria-pressed="true"] { background: var(--saffron); border-color: var(--saffron-edge); color: var(--saffron-ink); box-shadow: 0 4px 0 var(--saffron-edge); }
.pp-loop[aria-pressed="true"]:hover { background: var(--saffron); color: var(--saffron-ink); filter: brightness(1.05); }
.pp-speed { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.pp-speed-cap { font-weight: 700; font-size: var(--step--1); color: var(--muted); margin-right: var(--s-1); }
.pp-step { width: 46px; height: 46px; font-size: 1.5rem; margin-bottom: 4px; }
.pp-speed-val {
  min-width: 3.3em; text-align: center; font-family: var(--font-num); font-variant-numeric: tabular-nums;
  font-weight: 800; font-size: 1.375rem; line-height: 1; white-space: nowrap;
}
@media (max-width: 639px) {
  .pp-speed-cap { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
}
@media (max-width: 400px) {
  /* Fits a 360 px screen with "Pause" showing; min-width auto so Play is never squeezed below its label. */
  .pp-dock { gap: 6px; }
  .pp-loop svg { display: none; }
  .pp-dock .pp-loop { flex-direction: column; gap: 0; padding: 4px 10px; line-height: 1.1; }
  .pp-dock .pp-play { padding: 8px; gap: 4px; min-width: auto; }
  .pp-speed { gap: 2px; }
  .pp-step { width: 44px; height: 44px; }
  .pp-speed-val { font-size: 1.125rem; min-width: 3em; }
}

/* Wide screens: stage left (with the dock as its bottom edge), settings right. */
@media (min-width: 1100px) {
  .pp-player {
    grid-template-columns: minmax(0, 1.75fr) minmax(21rem, 1fr);
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "stage side" "dock side" ". side";
    column-gap: var(--s-6); row-gap: 0;
  }
  .pp-stage { border-bottom: 0; border-radius: var(--r-lg) var(--r-lg) 0 0; padding: var(--s-5) var(--s-6) var(--s-4); }
  .pp-dock {
    position: static; margin: 0; padding: var(--s-4) var(--s-6) var(--s-5); justify-content: flex-start; gap: var(--s-4);
    border: 1px solid var(--line); border-top: 1px solid var(--line); border-radius: 0 0 var(--r-lg) var(--r-lg); box-shadow: var(--e-1);
  }
  .pp-dock .pp-play { flex: 0 1 14rem; min-height: 64px; font-size: 1.25rem; }
  .pp-play svg { width: 26px; height: 26px; }
  .pp-dock .pp-loop { min-height: 64px; padding: 6px 20px; font-size: 1.0625rem; }
  .pp-speed { margin-left: auto; gap: var(--s-2); }
  .pp-step { width: 56px; height: 56px; }
  .pp-speed-val { font-size: clamp(1.75rem, 1.2rem + .9vw, 2.5rem); min-width: 3.4em; } /* round 5: was clamp(2rem, 1.2rem + 1.2vw, 3rem) */
  .pp-side { gap: var(--s-5); }
}
@media (min-width: 1800px) {
  .pp-player { grid-template-columns: minmax(0, 2.1fr) minmax(24rem, 1fr); }
}
@media print { .pp-dock { position: static; } }

/* small state touches */
.pp-stage.is-over { outline: 3px dashed var(--indigo); outline-offset: 4px; }
.pp-flash { animation: pp-flash 900ms var(--ease-out) 1; border-radius: var(--r-sm); }
@keyframes pp-flash { from { background: var(--indigo-soft); } to { background: transparent; } }
