/* The stage is what you read while singing: it stays pinned under the
   transport row so scrolling the controls never hides the phrase. */
body[data-page="phrases"] .voice-controls-row {
    justify-content: flex-start;
    min-height: 72px;
    padding-left: 8px;
}

body[data-page="phrases"] .voice-controls-row .stop-button,
body[data-page="phrases"] .voice-controls-row .play-button,
body[data-page="phrases"] .voice-controls-row .next-button,
body[data-page="phrases"] .voice-controls-row .repeat-button {
    height: 72px;
    padding-top: 14px;
    padding-bottom: 14px;
}

.phrase-stage {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 0;
    min-height: 0;
    margin: 6px 0 2px;
    padding: 8px 8px 4px;
    background: rgba(13, 40, 24, 0.93);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(134, 239, 172, 0.24);
    border-radius: 14px;
    position: sticky;
    top: 48px;
    z-index: 40;
}

@media (max-width: 768px) {
    .phrase-stage {
        top: 72px;
    }
}

.phrase-staff {
    width: 100%;
    min-height: 0;
}

.phrase-staff-empty {
    display: none;
}

.phrase-staff-scroll {
    /* Shrink to the drawn staff: a short phrase should not leave a long
       empty white band to its right. */
    width: fit-content;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    background: rgba(248, 250, 252, 0.96);
    border: 1px solid rgba(148, 163, 184, 0.35);
    padding: 2px 0;
    line-height: 0;
}

.phrase-staff-surface {
    min-width: 100%;
}

.phrase-staff-surface svg {
    display: block;
    height: auto;
    max-width: none;
}

.phrase-hear-options {
    display: flex;
    flex-wrap: wrap;
    gap: 3px 8px;
}

.phrase-stage-meta {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px 14px;
    width: 100%;
}

.phrase-degrees-large {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: var(--phrase-staff-note-step, var(--phrase-note-cell-width, 21px));
    align-items: stretch;
    justify-content: start;
    gap: 0;
    width: min(100%, 100vw - 16px);
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    color: #86efac;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: clamp(0.84rem, 3.3vw, 1.45rem);
    font-weight: 800;
    line-height: 1.05;
    padding: 1px 1px 0 var(--phrase-staff-grid-pad, 1px);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.phrase-degrees-empty {
    display: none;
}

.phrase-note-column {
    display: grid;
    grid-template-rows: 31px 1.05em 1.1em;
    align-items: center;
    justify-items: center;
    gap: 0;
    min-width: 0;
}

.phrase-degrees-large:not(.phrase-degrees-show-names) .phrase-note-column {
    grid-template-rows: 31px 1.05em;
}

.phrase-degrees-large:not(.phrase-degrees-show-play).phrase-degrees-show-names .phrase-note-column {
    grid-template-rows: 1.05em 1.1em;
}

.phrase-degrees-large:not(.phrase-degrees-show-play):not(.phrase-degrees-show-names) .phrase-note-column {
    grid-template-rows: 1.05em;
}

.phrase-degree-token {
    width: auto;
    min-width: 0;
    padding: 0 1px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: center;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    touch-action: none;
    transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.phrase-degree-token:hover {
    background: rgba(134, 239, 172, 0.16);
    color: #bbf7d0;
}

.phrase-degree-token:active {
    transform: scale(0.94);
}

.phrase-note-play-token {
    width: min(30px, calc(100% - 2px));
    height: 29px;
    padding: 0;
    border: 0;
    border-radius: 11px;
    background: rgba(22, 101, 52, 0.74);
    color: #dcfce7;
    font-size: 0.82rem;
    line-height: 1;
    cursor: pointer;
    transition: background-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.phrase-note-play-token:hover {
    background: rgba(34, 197, 94, 0.78);
    box-shadow: 0 0 0 2px rgba(134, 239, 172, 0.16);
    transform: translateY(-1px);
}

.phrase-note-name-token {
    width: 100%;
    min-width: 0;
    overflow: hidden;
    color: rgba(255, 255, 255, 0.66);
    font-size: clamp(0.58rem, 1.9vw, 0.82rem);
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
    text-overflow: clip;
    white-space: nowrap;
}

/* Long phrases scale down so the sticky stage stays a readable band
   instead of covering the controls. */
.phrase-degrees-large.phrase-degrees-many {
    font-size: clamp(0.58rem, 1.45vw, 0.74rem);
}

.phrase-note-column.inactive {
    color: rgba(255, 255, 255, 0.18);
    opacity: 0.55;
}

.phrase-note-column.inactive .phrase-degree-token {
    text-decoration: line-through;
}

.phrase-note-column.inactive .phrase-note-play-token {
    background: rgba(255, 255, 255, 0.08);
}

.phrase-notes-line {
    display: none;
    color: rgba(255, 255, 255, 0.64);
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
    min-height: 1.2em;
}

.phrase-notes-line:empty {
    display: none;
}

.phrase-controls {
    /* The stage above owns the (small) separation; the shared
       voice-first-ui top margin would double it. */
    margin-top: 0;
    margin-bottom: 8px;
}

.phrase-control-grid {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px;
}

.phrase-control-card {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px;
    min-width: 0;
    max-width: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
}

.phrase-control-card-shape {
    order: 2;
}

.phrase-control-card-series {
    order: 0;
    flex-basis: 100%;
    gap: 4px 8px;
}

.phrase-control-card-numbers {
    order: 1;
    flex-basis: 100%;
}

.phrase-control-card-output {
    order: 3;
}

.phrase-control-card-scale {
    order: 4;
    flex-basis: 100%;
}

/* Sizing only; the look comes from the shared .text-input */
.phrase-series-input {
    flex: 1 1 220px;
    min-width: 160px;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
}

.phrase-series-error {
    flex-basis: 100%;
    color: #fca5a5;
    font-size: 0.78rem;
}

.phrase-lesson-row[hidden] {
    display: none;
}

.phrase-algo-row,
.phrase-scale-row,
.phrase-genre-row {
    max-width: min(100%, 430px);
}

.phrase-algo-row .vf-btn,
.phrase-scale-row .vf-btn,
.phrase-genre-row .vf-btn,
.phrase-control-card-output .vf-btn {
    min-width: 64px;
    padding-left: 8px;
    padding-right: 8px;
}

.lesson-locked {
    position: relative;
    box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.46);
}

.lesson-locked::after {
    content: "lesson";
    position: absolute;
    right: 4px;
    top: -7px;
    padding: 0 4px;
    border-radius: 999px;
    background: rgba(14, 116, 144, 0.92);
    color: #cffafe;
    font-size: 9px;
    line-height: 13px;
    pointer-events: none;
}

.phrase-control-card-output .segment-row {
    max-width: min(100%, 430px);
}

.phrase-toggle-btn {
    border-radius: 999px;
    min-width: auto;
}

.phrase-anchor-row {
    max-width: min(100%, 430px);
}

.phrase-anchor-row .phrase-toggle-btn {
    flex: 1 1 0;
}

.phrase-toggle-btn[aria-pressed="true"] {
    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);
}

.phrase-length-step-field {
    grid-template-columns: 34px 30px 34px 30px;
}

.phrase-length-step-field .step-btn {
    width: 30px;
}

.phrase-length-step-field .step-value {
    width: 34px;
    padding-left: 4px;
    padding-right: 4px;
}

.phrase-accidental-step-field {
    grid-template-columns: 66px 30px 46px 30px;
}

.phrase-accidental-step-field .step-btn {
    width: 30px;
}

.phrase-accidental-step-field .step-label {
    padding-left: 6px;
    font-size: 0.62rem;
}

.phrase-history-degrees {
    color: #86efac;
    font-weight: 700;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
}

.phrase-stage-actions {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
}

.phrase-stage-btn {
    /* 14px line + 1px border each side = 16px total height */
    min-height: 0;
    padding: 0 9px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 14px;
    cursor: pointer;
}

.phrase-stage-btn:disabled {
    cursor: default;
    opacity: 0.45;
}

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

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

/* Dense control stack itself comes from the shared .vf-compact class
   (practice-controls.css); only phrase-specific layout stays here. */

@media (max-width: 640px) {
    .phrase-control-grid {
        gap: 5px;
        padding: 4px;
    }

    .phrase-control-card .segment-row .vf-btn {
        min-width: auto;
    }

    .phrase-algo-row,
    .phrase-scale-row,
    .phrase-control-card-output .segment-row {
        width: auto;
    }

    .phrase-algo-row .vf-btn,
    .phrase-scale-row .vf-btn,
    .phrase-control-card-output .vf-btn {
        min-width: 58px;
    }
}
