/* ============================================================
   Tempo meter — header trigger button + popover host + widget.
   Class-for-class sibling of assets/tuner/tuner.css; the popover
   chrome intentionally stays in lockstep with the tuner/metronome.
   ============================================================ */

/* ---- Header trigger button ----
   Same charcoal circle as the tuner/metronome triggers so the three
   utilities read as one family. Green while open. !important for the
   same theme-button-override reason as the tuner. */
.pg-tempo-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    padding: 0;
    border: none;
    border-radius: 50% !important;
    background: #2c333d !important;
    color: #f0f3f6;
    cursor: pointer;
    transition: background 0.12s ease, transform 0.1s ease;
}
.pg-tempo-trigger svg { width: 20px; height: 20px; }
.pg-tempo-trigger:hover {
    background: #3a4350 !important;
    transform: translateY(-1px);
}
.pg-tempo-trigger[aria-expanded="true"] {
    background: #2bb866 !important;
    color: #fff;
}
@media (max-width: 600px) {
    .pg-tempo-trigger { width: 30px; height: 30px; }
    .pg-tempo-trigger svg { width: 17px; height: 17px; }
}

/* ============================================================
   Popover host — desktop popover top-right under the header,
   mobile bottom sheet. Mirrors .pg-tuner-pop.
   ============================================================ */

.pg-tempo-pop {
    font-family: var(--pg-font-ui, inherit);
}

.pg-tempo-pop-backdrop {
    position: fixed;
    inset: 0;
    z-index: 99999999;
    background: transparent;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.pg-tempo-pop[data-pg-tempo-pop="open"] .pg-tempo-pop-backdrop { opacity: 1; }
.pg-tempo-pop[data-pg-tempo-pop="closed"] .pg-tempo-pop-backdrop { pointer-events: none; }

.pg-tempo-pop-panel {
    position: fixed;
    z-index: 100000000;
    top: 66px;
    right: 14px;
    width: 340px;
    max-width: calc(100vw - 24px);
    background: var(--pg-surface, #fdfdfd);
    border: 1px solid var(--pg-border, #e5e7eb);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
    transform-origin: top right;
    transition: opacity 0.16s ease, transform 0.16s ease;
}
body.admin-bar .pg-tempo-pop-panel { top: 98px; }
.pg-tempo-pop[data-pg-tempo-pop="closed"] .pg-tempo-pop-panel {
    opacity: 0;
    transform: scale(0.96) translateY(-6px);
    pointer-events: none;
}
.pg-tempo-pop[data-pg-tempo-pop="open"] .pg-tempo-pop-panel {
    opacity: 1;
    transform: none;
}

@media (max-width: 600px) {
    .pg-tempo-pop[data-pg-tempo-pop="open"] .pg-tempo-pop-backdrop {
        background: rgba(0, 0, 0, 0.45);
    }
    .pg-tempo-pop-panel {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        border-bottom: none;
        transition: transform 0.24s ease;
    }
    body.admin-bar .pg-tempo-pop-panel { top: auto; }
    .pg-tempo-pop[data-pg-tempo-pop="closed"] .pg-tempo-pop-panel {
        opacity: 1;
        transform: translateY(100%);
    }
    .pg-tempo-pop[data-pg-tempo-pop="open"] .pg-tempo-pop-panel {
        transform: translateY(0);
    }
}

/* ============================================================
   Widget
   ============================================================ */

.pg-tempo {
    padding: 14px 16px 16px;
}

/* ---- Top bar: power · target · close ---- */
.pg-tempo-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pg-tempo-power {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    padding: 0;
    border: 1.5px solid var(--pg-border, #d7dbe0);
    border-radius: 50% !important;
    background: var(--pg-surface, #fdfdfd) !important;
    color: #6b7280;
    cursor: pointer;
    transition: color 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.pg-tempo-power svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
}
.pg-tempo-power:hover { color: #374151; border-color: #b9c0c9; }
.pg-tempo[data-pg-tempo-state="listening"] .pg-tempo-power,
.pg-tempo[data-pg-tempo-state="locked"] .pg-tempo-power {
    color: #2bb866;
    border-color: #2bb866;
    box-shadow: 0 0 0 3px rgba(43, 184, 102, 0.15);
}
.pg-tempo[data-pg-tempo-state="error"] .pg-tempo-power {
    color: #d64545;
    border-color: #d64545;
}

/* Target BPM chip — number input + clear ✕. */
.pg-tempo-target {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    padding: 4px 8px;
    border: 1px solid var(--pg-border, #e5e7eb);
    border-radius: 999px;
    background: var(--pg-surface-2, #f4f5f7);
}
.pg-tempo-target-lbl {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6b7280;
}
.pg-tempo-target-input {
    width: 52px;
    padding: 2px 4px;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--pg-text, #1f2937);
    text-align: center;
    -moz-appearance: textfield;
    appearance: textfield;
}
.pg-tempo-target-input::-webkit-outer-spin-button,
.pg-tempo-target-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pg-tempo-target-input:focus { outline: none; }
.pg-tempo-target-input::placeholder { color: #9ca3af; font-weight: 400; }
.pg-tempo-target-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    font-size: 0.8rem;
    line-height: 1;
}
.pg-tempo-target-clear:hover { color: #4b5563; background: #e5e7eb; }

.pg-tempo-pop-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    padding: 0;
    border: none;
    border-radius: 50% !important;
    background: transparent !important;
    color: #6b7280;
    cursor: pointer;
}
.pg-tempo-pop-close:hover {
    background: #eceef1 !important;
    color: #111827;
}
.pg-tempo-standalone .pg-tempo-pop-close { display: none; }

/* ---- Readout ---- */
.pg-tempo-screen {
    margin-top: 14px;
    padding: 18px 14px 14px;
    border-radius: 12px;
    background: #10151c;
    color: #e8edf3;
    text-align: center;
}
.pg-tempo-caption {
    min-height: 1.2em;
    font-size: 0.8rem;
    color: #8b97a5;
}
.pg-tempo[data-pg-tempo-state="locked"] .pg-tempo-caption { color: #2bb866; }
.pg-tempo[data-pg-tempo-state="error"] .pg-tempo-caption { color: #e58c8c; }

.pg-tempo-readout {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
    margin: 6px 0 2px;
}
.pg-tempo-bpm {
    font-size: 3.4rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    color: #f4f7fa;
    transition: color 0.15s ease;
}
.pg-tempo[data-pg-tempo-state="locked"] .pg-tempo-bpm { color: #6fd398; }
.pg-tempo-bpm-lbl {
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: #8b97a5;
}

/* Drift word — colored by rushing/dragging/on-tempo. */
.pg-tempo-drift {
    min-height: 1.3em;
    font-size: 0.92rem;
    font-weight: 600;
}
.pg-tempo-drift.is-on       { color: #6fd398; }
.pg-tempo-drift.is-rushing  { color: #e8b84d; }
.pg-tempo-drift.is-dragging { color: #7db3e8; }

/* ×2 / ÷2 fold row. Disabled (dimmed) while a target is set — the
   target auto-folds the reading. */
.pg-tempo-fold {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}
.pg-tempo-fold button {
    padding: 3px 12px;
    border: 1px solid #2e3947;
    border-radius: 999px;
    background: transparent;
    color: #8b97a5;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}
.pg-tempo-fold button:hover:not(:disabled) { border-color: #4a586a; color: #c6cfd9; }
.pg-tempo-fold button.is-active {
    border-color: #2bb866;
    color: #6fd398;
}
.pg-tempo-fold button:disabled { opacity: 0.35; cursor: default; }

/* ---- Record row ---- */
.pg-tempo-rec-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
}
.pg-tempo-rec {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border: 1px solid var(--pg-border, #d7dbe0);
    border-radius: 999px;
    background: var(--pg-surface, #fdfdfd);
    color: var(--pg-text, #1f2937);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.12s ease, color 0.12s ease;
}
.pg-tempo-rec:hover:not(:disabled) { border-color: #b9c0c9; }
.pg-tempo-rec:disabled { opacity: 0.45; cursor: default; }
.pg-tempo-rec-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #d64545;
    flex-shrink: 0;
}
.pg-tempo-rec.is-recording {
    border-color: #d64545;
    color: #d64545;
}
.pg-tempo-rec.is-recording .pg-tempo-rec-dot {
    animation: pg-tempo-rec-pulse 1.2s ease-in-out infinite;
}
@keyframes pg-tempo-rec-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}
.pg-tempo-rec-time {
    font-size: 0.85rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: #d64545;
}

/* ---- Take review (tempo graph over waveform + scrub) ---- */
.pg-tempo-review {
    margin-top: 12px;
}
.pg-tempo-review-canvas {
    display: block;
    width: 100%;
    height: 150px;
    border-radius: 8px;
    background: var(--pg-surface-2, #f4f5f7);
    border: 1px solid var(--pg-border, #e5e7eb);
    cursor: pointer;
    touch-action: none;   /* the canvas IS the scrubber — no scroll steal */
}
.pg-tempo-review-ctrls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}
.pg-tempo-review-play {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    padding: 0;
    border: none;
    border-radius: 50% !important;
    background: #2c333d !important;
    color: #f0f3f6;
    cursor: pointer;
}
.pg-tempo-review-play:hover { background: #3a4350 !important; }
.pg-tempo-review-play .pg-tempo-review-ic--stop { display: none; }
.pg-tempo-review-play.is-playing .pg-tempo-review-ic--play { display: none; }
.pg-tempo-review-play.is-playing .pg-tempo-review-ic--stop { display: inline; }
.pg-tempo-review-time {
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    color: #6b7280;
}
.pg-tempo-review-dl {
    margin-left: auto;
    padding: 6px 12px;
    border: 1px solid var(--pg-border, #d7dbe0);
    border-radius: 999px;
    background: var(--pg-surface, #fdfdfd);
    color: var(--pg-text, #1f2937);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}
.pg-tempo-review-dl:hover { border-color: #b9c0c9; }
.pg-tempo-review-discard {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
}
.pg-tempo-review-discard:hover { background: #eceef1; color: #111827; }

/* ---- Drift strip (tempo-over-time sparkline) ---- */
.pg-tempo-strip-wrap {
    margin-top: 12px;
}
.pg-tempo-strip {
    display: block;
    width: 100%;
    height: 56px;
    border-radius: 8px;
    background: var(--pg-surface-2, #f4f5f7);
    border: 1px solid var(--pg-border, #e5e7eb);
}
.pg-tempo-strip-lbl {
    margin-top: 4px;
    font-size: 0.72rem;
    color: #9ca3af;
    text-align: center;
}

/* ---- Footer hint ---- */
.pg-tempo-hint {
    margin-top: 10px;
    font-size: 0.78rem;
    line-height: 1.45;
    color: #6b7280;
    text-align: center;
}

/* ---- Standalone page surface ---- */
.pg-tempo-standalone {
    max-width: 420px;
    margin: 0 auto 2rem;
    background: var(--pg-surface, #fdfdfd);
    border: 1px solid var(--pg-border, #e5e7eb);
    border-radius: 14px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
}
