/* Shared practice-page UI primitives: the pitch test panel rendered by
   pitch-test-panel.js, its blue launch button, the vf-btn option chip,
   and the stepper / segmented-row control language introduced on the
   Phrases page. Load this BEFORE page stylesheets so pages can override. */

/* Option chip - looks like a code snippet, acts like a button */
.vf-btn {
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.75rem;
    padding: 5px 7px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    white-space: nowrap;
}

.vf-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.35);
}

.vf-btn:active {
    transform: scale(0.97);
}

.vf-btn.selected {
    background: rgba(74, 222, 128, 0.35);
    border-color: rgba(74, 222, 128, 0.6);
    color: #fff;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.3);
}

/* Stepper field: label, minus, value, plus */
.step-field {
    display: grid;
    grid-template-columns: 58px 34px 46px 34px;
    align-items: center;
    gap: 3px;
    width: fit-content;
    max-width: 100%;
    padding: 3px;
    border: 1px solid rgba(134, 239, 172, 0.38);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.3);
}

/* Stepper without an internal label (the row provides one) */
.step-field-bare {
    grid-template-columns: 38px 54px 38px;
}

.step-label {
    padding: 0 3px 0 5px;
    color: rgba(255, 255, 255, 0.62);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}

.step-btn {
    width: 38px;
    height: 32px;
    border: 1px solid rgba(74, 222, 128, 0.32);
    border-radius: 999px;
    background: rgba(8, 47, 31, 0.9);
    color: #e8f5e9;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
}

.step-btn:hover {
    border-color: rgba(134, 239, 172, 0.64);
    background: rgba(22, 101, 52, 0.92);
}

.step-btn:disabled {
    border-color: rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.22);
    cursor: not-allowed;
}

.step-btn:active {
    transform: scale(0.94);
}

.step-btn:focus {
    outline: 2px solid rgba(74, 222, 128, 0.45);
    outline-offset: 2px;
}

.step-value {
    width: 54px;
    box-sizing: border-box;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(74, 222, 128, 0.18);
    color: #d9f99d;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    font-weight: 900;
    text-align: center;
}

/* Segmented row: mutually exclusive vf-btn options in a pill shell */
/* The group shell: every option group is one clearly bounded control.
   The border must read at a glance - groups never visually merge. */
.segment-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    width: fit-content;
    max-width: 100%;
    padding: 3px;
    gap: 3px;
    border: 1px solid rgba(134, 239, 172, 0.38);
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.3);
}

.segment-row .vf-btn {
    min-width: 82px;
    border-radius: 999px;
    text-align: center;
}

@media (max-width: 640px) {
    .step-field {
        width: auto;
        grid-template-columns: 54px 36px 54px 36px;
        justify-content: space-between;
    }

    .step-value {
        width: 54px;
    }

    .segment-row {
        width: auto;
    }

    .segment-row .vf-btn {
        flex: 0 0 auto;
        min-width: 74px;
        padding-left: 5px;
        padding-right: 5px;
    }
}

/* Compact density: put .vf-compact on a settings container to get the
   16px pill rows introduced on Phrases (12px line + 1px padding and
   1px border each side). The whole settings block shrinks so more of
   it stays on screen - the car-glance layout. */
.vf-compact .vf-btn {
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    line-height: 12px;
}

.vf-compact .segment-row {
    padding: 2px;
    gap: 2px;
}

.vf-compact .segment-row .vf-btn {
    min-width: auto;
    flex: 0 0 auto;
}

.vf-compact .vf-options {
    gap: 3px;
}

.vf-compact .step-field {
    padding: 2px;
    grid-template-columns: 52px 30px 44px 30px;
}

.vf-compact .step-field-bare {
    grid-template-columns: 30px 44px 30px;
}

.vf-compact .step-btn {
    width: 32px;
    height: 20px;
    font-size: 0.85rem;
}

.vf-compact .step-value {
    padding: 2px 6px;
    font-size: 0.78rem;
}

.vf-compact .display-toggle {
    padding: 1px 7px;
    gap: 4px;
    font-size: 0.7rem;
    line-height: 12px;
}

.vf-compact .display-toggle input[type="checkbox"] {
    width: 12px;
    height: 12px;
    margin: 0;
}

.pitch-test-panel {
    margin: 0 0 14px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.34);
    border: 1px solid rgba(14, 165, 233, 0.36);
    border-radius: 14px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22);
}

/* Actions on top (always reachable), compact titles underneath */
.pitch-test-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}

.pitch-test-titles h2 {
    margin: 0;
    color: #bae6fd;
    font-size: 1rem;
}

.pitch-test-titles p {
    margin: 2px 0 0;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.55);
}

/* Pinned while the panel is in use: Restart/Guide/Close stay visible
   and reachable mid-take, below the page's sticky stack. Pages set
   --pitch-test-actions-top to their transport(+stage) height. */
.pitch-test-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    position: sticky;
    top: var(--pitch-test-actions-top, 4px);
    z-index: 30;
    background: rgba(7, 26, 16, 0.92);
    backdrop-filter: blur(6px);
    border-radius: 10px;
    padding: 6px;
}

.pitch-test-btn {
    padding: 7px 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.85);
    font-weight: 700;
    cursor: pointer;
}

.pitch-test-btn.selected {
    border-color: rgba(74, 222, 128, 0.7);
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    box-shadow: 0 4px 15px rgba(74, 222, 128, 0.25);
}

.pitch-test-btn.listening {
    border-color: rgba(245, 158, 11, 0.85);
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    box-shadow: 0 4px 18px rgba(245, 158, 11, 0.32);
}

.pitch-test-options {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 10px;
}

.pitch-test-readout {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 10px;
    color: rgba(255, 255, 255, 0.74);
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
}

.pitch-test-readout span:first-child {
    color: #e0f2fe;
    font-weight: 800;
}

.pitch-test-canvas-wrap {
    width: 100%;
    overflow: hidden;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.4);
}

.pitch-test-canvas {
    display: block;
    width: 100%;
    height: 380px;
}

.pitch-test-legend {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 10px;
    color: rgba(255, 255, 255, 0.58);
    font-size: 0.82rem;
}

.pitch-test-legend i {
    display: inline-block;
    width: 18px;
    height: 4px;
    margin-right: 6px;
    border-radius: 999px;
    vertical-align: middle;
}

.legend-target {
    background: #60a5fa;
}

.legend-sung {
    background: #facc15;
}

.legend-scale {
    background: rgba(134, 239, 172, 0.65);
}

.legend-scored {
    background: linear-gradient(90deg, #4ade80 33%, #facc15 33%, #facc15 66%, #fb7185 66%);
}

.pitch-test-key {
    color: #86efac;
    font-weight: 700;
}

.pitch-test-score {
    color: #bbf7d0;
    font-weight: 800;
}

/* Trend line shown by scored tools ("Progress: Today 62% (5 takes) ...") */
.progress-summary {
    margin: 2px 0 10px;
    color: rgba(255, 255, 255, 0.6);
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.8rem;
    text-align: center;
}

.progress-summary:empty {
    display: none;
}

/* Blue launch control that toggles the pitch panel (Test / Sing).
   Lives in the bottom dock, not in the transport row. */
.pitch-test-launch-button {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%) !important;
    color: #fff !important;
    border: none;
    border-radius: 10px;
    min-height: 48px;
    min-width: 100px;
    padding: 10px 18px;
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
}

/* Latched while the panel is open */
.pitch-test-launch-button.selected {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%) !important;
    box-shadow: 0 4px 15px rgba(74, 222, 128, 0.25);
}

/* Bottom dock: Test/Sing is an independent sheet, not transport.
   Bar stays fixed; the panel expands upward when open. */
.pitch-test-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: flex;
    flex-direction: column-reverse;
    max-height: min(72vh, 680px);
    pointer-events: none;
}

.pitch-test-dock > * {
    pointer-events: auto;
}

.pitch-test-dock-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(7, 26, 16, 0.97);
    border-top: 1px solid rgba(14, 165, 233, 0.42);
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.28);
}

.pitch-test-dock-hint {
    color: rgba(186, 230, 253, 0.72);
    font-size: 0.82rem;
    font-weight: 600;
}

.pitch-test-dock .pitch-test-panel,
.pitch-test-dock > [id$="Panel"].pitch-test-panel {
    margin: 0;
    border-radius: 14px 14px 0 0;
    border-bottom: none;
    max-height: calc(min(72vh, 680px) - 64px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Inside the dock sheet, actions pin to the top of the sheet — not
   under the page transport/stage sticky stack. */
.pitch-test-dock .pitch-test-actions {
    top: 0;
}

/* Keep page content clear of the always-visible dock bar. */
body:has(.pitch-test-dock) {
    padding-bottom: 72px;
}

@media (max-width: 640px) {
    .pitch-test-dock-hint {
        display: none;
    }
}

@media (max-width: 640px) {
    .pitch-test-canvas {
        height: 330px;
    }
}

/* ============================================
   SHARED PRACTICE-PAGE BLOCKS (display toggles,
   transport buttons, option rows, history list)
   ============================================ */

.display-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    padding: 5px 7px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    white-space: nowrap;
}

.display-toggle:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.35);
}

.display-toggle input[type="checkbox"] {
    display: none;
}

.display-toggle:has(input:checked) {
    background: rgba(74, 222, 128, 0.35);
    border-color: rgba(74, 222, 128, 0.6);
    color: #fff;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.3);
}

.display-toggle span {
    font-weight: 500;
}

/* ============================================
   TRANSPORT BUTTONS (one vocabulary, every page)
   stop = red, play = teal, next = orange, repeat = indigo.
   Unscoped so the same button works in the sticky voice
   row and inside panels (pitch-meter, trace).
   ============================================ */

.stop-button,
.play-button,
.next-button,
.repeat-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px 20px;
    min-width: 80px;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    margin: 0;
}

.stop-button {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.stop-button:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.play-button {
    background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
    box-shadow: 0 4px 15px rgba(20, 184, 166, 0.3);
}

.play-button:hover {
    background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
    box-shadow: 0 6px 20px rgba(20, 184, 166, 0.4);
}

/* Mic-toggle play buttons (trace Start) go amber while listening */
.play-button.listening {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.next-button {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.next-button:hover {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

.repeat-button {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.repeat-button:hover {
    background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

/* Latching repeat (phrases): green while repeat mode is on */
.repeat-button.selected {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    box-shadow: 0 4px 15px rgba(74, 222, 128, 0.25);
}

.stop-button:active,
.play-button:active,
.next-button:active,
.repeat-button:active {
    transform: scale(0.98);
}

.stop-button:disabled,
.play-button:disabled,
.next-button:disabled,
.repeat-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.stop-button .button-icon,
.play-button .button-icon,
.next-button .button-icon,
.repeat-button .button-icon {
    font-size: 1.2rem;
}

/* The sticky voice row: layout and responsive sizing */
.voice-controls-row {
    display: flex;
    justify-content: center;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 10px;
    min-height: 120px;

    /* Keep primary controls reachable while scrolling */
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.22);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(6px);
}

.voice-controls-row .listen-button {
    flex: 1;
    height: 120px;
}

.voice-controls-row .stop-button,
.voice-controls-row .play-button,
.voice-controls-row .next-button,
.voice-controls-row .repeat-button {
    height: 120px;
}

/* Desktop: compact voice controls - the big buttons are for driving */
@media (min-width: 769px) {
    .voice-controls-row {
        min-height: 48px;
    }

    .voice-controls-row .listen-button {
        height: 48px;
    }

    .voice-controls-row .stop-button,
    .voice-controls-row .play-button,
    .voice-controls-row .next-button,
    .voice-controls-row .repeat-button {
        height: 48px;
    }
}

/* Tablet: moderate sizing */
@media (min-width: 481px) and (max-width: 768px) {
    .voice-controls-row {
        min-height: 80px;
    }

    .voice-controls-row .listen-button {
        height: 80px;
    }
}

/* Rows without the big mic bar (phrases, intervals) are pure transport;
   they don't need driving height, so give the page back vertical space */
@media (max-width: 768px) {
    .voice-controls-row:not(:has(.listen-button)) {
        min-height: 72px;
    }

    .voice-controls-row:not(:has(.listen-button)) .stop-button,
    .voice-controls-row:not(:has(.listen-button)) .play-button,
    .voice-controls-row:not(:has(.listen-button)) .next-button,
    .voice-controls-row:not(:has(.listen-button)) .repeat-button {
        height: 72px;
        padding: 8px 10px;
        min-width: 0;
        font-size: 1rem;
    }

    .voice-controls-row:not(:has(.listen-button)) .button-text {
        font-size: 1rem;
    }

    .voice-controls-row:not(:has(.listen-button)) .button-icon {
        font-size: 1.1rem;
    }
}

.command-history {
    margin-top: 20px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 12px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.history-header h3 {
    margin: 0;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.9);
}

/* Text fields: one base look everywhere. Pages may size them
   (width, font-size, resize) but never re-skin them. */
.text-input {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid rgba(74, 222, 128, 0.3);
    background: rgba(0, 0, 0, 0.3);
    color: #e8f5e9;
    font: inherit;
}

.text-input:focus {
    outline: none;
    border-color: rgba(74, 222, 128, 0.6);
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.12);
}

.text-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

/* Small utility chip for panel corners and inline actions:
   Copy All, Clear, Save, Apply, Delete, Reset, Random, Test, Show... */
.panel-action-btn {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
}

.panel-action-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
}

.panel-action-btn:active {
    transform: scale(0.98);
}

/* Destructive chip actions (Clear, Delete, Reset stats) hover red */
.panel-action-btn.danger:hover {
    background: rgba(239, 68, 68, 0.3);
    border-color: rgba(239, 68, 68, 0.5);
}

/* Mid-size primary action (Books import/generate/play-from-progress):
   the green "do the thing" button, one look everywhere */
.primary-btn {
    padding: 8px 16px;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    border: none;
    border-radius: 8px;
    color: #06240f;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
}

.primary-btn:hover {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
}

.primary-btn:active {
    transform: scale(0.98);
}

.panel-action-btn:disabled,
.secondary-btn:disabled,
.primary-btn:disabled {
    opacity: 0.48;
    cursor: not-allowed;
    transform: none;
}

/* Mid-size neutral action button (trace Reset, ears sing controls) */
.secondary-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.85rem;
    cursor: pointer;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.35);
}

.secondary-btn:active {
    transform: scale(0.98);
}

.secondary-btn.danger:hover {
    background: rgba(239, 68, 68, 0.3);
    border-color: rgba(239, 68, 68, 0.5);
}

.history-list {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-empty {
    color: rgba(255, 255, 255, 0.4);
    font-style: italic;
    font-size: 0.85rem;
    margin: 0;
    padding: 8px 0;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.12);
}

.history-play-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.history-play-btn:hover {
    box-shadow: 0 2px 8px rgba(74, 222, 128, 0.4);
}

.history-text {
    flex: 1;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.9);
}

.history-transcript {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    font-style: italic;
}

.history-time {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.4);
    flex-shrink: 0;
}

.voice-first-ui {
    margin: 8px 0;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 10px;
}

.vf-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 3px;
    flex-wrap: wrap;
}

.vf-row .vf-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 0;
    text-align: left;
    min-width: 85px;
    flex-shrink: 0;
}

.vf-row .vf-label-inline {
    min-width: auto;
    margin-left: 12px;
}

.vf-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Option container: used inside labeled vf-rows and standalone
   (phrases/trace chip rows). Canonical chip gap is 5px (phrases). */
.vf-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
}

@media (max-width: 600px) {
    .vf-btn {
        padding-left: 4px;
        padding-right: 4px;
    }
}

@media (max-width: 400px) {
    .vf-btn {
        font-size: 0.7rem;
        padding: 4px 2px;
    }
}
