/**
 * Interactive Song Player UI
 * Styles the frontend tab player control bar, navigation, section replay,
 * playback highlight and the non-owner preview lock/unlock state.
 * Matches the site's Material Design 3 tokens and glass styling.
 */

.tab-player-section .tfp-web3-container {
    margin-top: 0 !important;
    overflow: visible;
}

.tab-player-section {
    overflow: visible;
}

#tfp-song-renderer {
    overflow: visible;
}

.tfp-player {
    --tfp-pl-primary: var(--md-sys-color-primary, #0D2A57);
    --tfp-pl-accent: var(--tfp-accent-primary, #4facfe);
    --tfp-pl-surface: rgba(255, 255, 255, 0.85);
    --tfp-pl-border: rgba(13, 42, 87, 0.12);
    font-family: var(--tfp-font-family, 'Inter', sans-serif);
    margin-bottom: 18px;
}

.tfp-player .material-symbols-rounded {
    font-family: 'Material Symbols Rounded';
    font-weight: normal;
    font-style: normal;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    direction: ltr;
    -webkit-font-feature-settings: 'liga';
    font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
    user-select: none;
}

/* ---- Control bar shell ---- */
.tfp-player-bar {
    position: sticky;
    top: 70px;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    padding: 12px 14px;
    border-radius: 16px;
    background: var(--tfp-pl-surface);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--tfp-pl-border);
    box-shadow: 0 8px 28px rgba(13, 42, 87, 0.12);
}

/* ---- Transport buttons ---- */
.tfp-player-transport {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tfp-pl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--tfp-pl-primary);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease, color 0.15s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.tfp-pl-btn .material-symbols-rounded {
    font-size: 24px;
}

.tfp-pl-btn:hover {
    background: rgba(13, 42, 87, 0.08);
}

.tfp-pl-btn:active {
    transform: scale(0.92);
}

.tfp-pl-btn:disabled {
    opacity: 0.35;
    cursor: default;
    background: transparent;
}

.tfp-pl-play {
    width: 48px;
    height: 48px;
    background: var(--tfp-pl-primary);
    color: #fff;
    box-shadow: 0 4px 14px rgba(13, 42, 87, 0.35);
}

.tfp-pl-play .material-symbols-rounded {
    font-size: 28px;
}

.tfp-pl-play:hover {
    background: #123a73;
}

.tfp-pl-loop.active {
    background: var(--tfp-pl-accent);
    color: #fff;
}

/* ---- Progress / scrubber ---- */
.tfp-player-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1 1 260px;
    min-width: 220px;
}

.tfp-pl-time {
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: rgba(13, 42, 87, 0.7);
    min-width: 34px;
    text-align: center;
}

.tfp-pl-scrub {
    position: relative;
    flex: 1;
    height: 26px;
    display: flex;
    align-items: center;
    cursor: pointer;
    touch-action: none;
}

.tfp-pl-scrub-track {
    position: relative;
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: rgba(13, 42, 87, 0.14);
    overflow: visible;
}

.tfp-pl-scrub-preview {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 999px;
    background: repeating-linear-gradient(
        45deg,
        rgba(13, 42, 87, 0.18),
        rgba(13, 42, 87, 0.18) 5px,
        rgba(13, 42, 87, 0.08) 5px,
        rgba(13, 42, 87, 0.08) 10px
    );
    display: none;
}

.tfp-pl-scrub-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: var(--tfp-pl-primary);
}

.tfp-pl-scrub-handle {
    position: absolute;
    top: 50%;
    left: 0;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--tfp-pl-primary);
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 6px rgba(13, 42, 87, 0.3);
}

/* ---- Section indicator ---- */
.tfp-player-section-ind {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--tfp-pl-primary);
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(13, 42, 87, 0.06);
    white-space: nowrap;
}

.tfp-player-section-ind .material-symbols-rounded {
    font-size: 18px;
}

/* ---- Tempo + volume knobs ---- */
.tfp-player-knobs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
}

.tfp-pl-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--tfp-pl-primary);
}

.tfp-pl-group > .material-symbols-rounded {
    font-size: 20px;
    color: rgba(13, 42, 87, 0.7);
}

.tfp-pl-step {
    width: 26px;
    height: 26px;
    border: 1px solid var(--tfp-pl-border);
    border-radius: 8px;
    background: #fff;
    color: var(--tfp-pl-primary);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.tfp-pl-step:hover {
    background: rgba(13, 42, 87, 0.06);
}

.tfp-pl-bpm {
    width: 56px;
    height: 30px;
    text-align: center;
    border: 1px solid var(--tfp-pl-border);
    border-radius: 8px;
    background: #fff;
    color: var(--tfp-pl-primary);
    font-size: 14px;
    font-weight: 600;
    -moz-appearance: textfield;
}

.tfp-pl-bpm::-webkit-outer-spin-button,
.tfp-pl-bpm::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.tfp-pl-bpm-unit {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: rgba(13, 42, 87, 0.55);
}

.tfp-pl-speed-val {
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    min-width: 38px;
    color: rgba(13, 42, 87, 0.7);
}

/* Range inputs */
.tfp-player input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 999px;
    background: rgba(13, 42, 87, 0.18);
    cursor: pointer;
}

.tfp-pl-speed {
    width: 96px;
}

.tfp-pl-vol {
    width: 90px;
}

.tfp-player input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--tfp-pl-primary);
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(13, 42, 87, 0.4);
}

.tfp-player input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--tfp-pl-primary);
    border: 2px solid #fff;
}

.tfp-pl-mute {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--tfp-pl-primary);
    cursor: pointer;
}

.tfp-pl-mute:hover {
    background: rgba(13, 42, 87, 0.08);
}

.tfp-pl-mute.active {
    color: #c1373d;
}

.tfp-pl-mute .material-symbols-rounded {
    font-size: 22px;
}

/* ---- Per-row replay control ---- */
.tfp-renderer-row {
    position: relative;
}

.tfp-row-replay {
    position: absolute;
    top: -14px;
    left: -14px;
    z-index: 6;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: var(--tfp-pl-primary, #0D2A57);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(13, 42, 87, 0.35);
    opacity: 0;
    transform: scale(0.85);
    transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.tfp-renderer-row:hover .tfp-row-replay,
.tfp-renderer-row.tfp-row-active .tfp-row-replay {
    opacity: 1;
    transform: scale(1);
}

.tfp-row-replay .material-symbols-rounded {
    font-size: 18px;
}

.tfp-row-replay:hover {
    background: #123a73;
}

.tfp-row-replay-locked {
    background: #6b7280;
}

/* ---- Active section + playing note highlight ---- */
.tfp-renderer-row.tfp-row-active {
    outline: 3px solid var(--tfp-accent-primary, #4facfe);
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgba(79, 172, 254, 0.12);
}

.tfp-renderer-note.is-playing {
    box-shadow: 0 0 0 2px #fff, 0 0 14px 3px var(--tfp-note-color, #4facfe);
    filter: brightness(1.12) saturate(1.12);
    z-index: 5;
}

.tfp-renderer-note.tfp-renderer-trill.is-playing {
    box-shadow: none;
    filter: brightness(1.15) saturate(1.15);
}

.tfp-renderer-note.tfp-renderer-trill.is-playing .tfp-trill-ribbon-box {
    box-shadow: 0 0 12px 2px var(--tfp-note-color, #4facfe);
    border-radius: 6px;
}

/* ---- Synced lyric highlight ---- */
.tfp-renderer-lyric-text {
    transition: color 0.12s;
}

.tfp-renderer-lyric-text.is-current {
    color: var(--tfp-pl-accent, #4facfe);
    font-weight: 700;
}

/* ---- Finger badge on pressed piano keys ---- */
.tfp-key-badge {
    position: absolute;
    left: 50%;
    bottom: 38px;
    transform: translateX(-50%) scale(0.5);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    z-index: 6;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    transition: opacity 0.08s, transform 0.08s;
}

.tfp-key-badge.is-on {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

.tfp-key-badge.right {
    background: #4A90E2;
}

.tfp-key-badge.left {
    background: #E24A4A;
}

.piano-key.black .tfp-key-badge {
    width: 16px;
    height: 16px;
    font-size: 10px;
    bottom: 6px;
    border: 1px solid rgba(255, 255, 255, 0.75);
    box-sizing: border-box;
}

/* ---- Hand mute toggles ---- */
.tfp-pl-hand {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid var(--tfp-pl-border);
    background: #fff;
    color: rgba(13, 42, 87, 0.45);
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.tfp-pl-hand.active[data-hand="right"] {
    background: #4A90E2;
    border-color: #4A90E2;
    color: #fff;
}

.tfp-pl-hand.active[data-hand="left"] {
    background: #E24A4A;
    border-color: #E24A4A;
    color: #fff;
}

/* ---- Count-in ---- */
.tfp-pl-countin.active {
    background: var(--tfp-pl-accent);
    color: #fff;
}

.tfp-player.is-counting .tfp-pl-play {
    animation: tfpCountPulse 0.5s ease-in-out infinite alternate;
}

@keyframes tfpCountPulse {
    from { box-shadow: 0 4px 14px rgba(13, 42, 87, 0.35); }
    to { box-shadow: 0 0 0 6px rgba(79, 172, 254, 0.45); }
}

/* ---- Tempo reset ---- */
.tfp-pl-step .material-symbols-rounded {
    font-size: 16px;
}

.tfp-pl-step:disabled {
    opacity: 0.35;
    cursor: default;
    background: #fff;
}

/* ---- Preview gating (non-owners) ---- */
.tfp-renderer-row.tfp-row-locked {
    filter: blur(4px) grayscale(0.25);
    opacity: 0.55;
    pointer-events: none;
    user-select: none;
}

.tfp-player-unlock {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 28px 0;
    padding: 18px 20px;
    border-radius: 16px;
    background: var(--tfp-glass-bg, rgba(255, 255, 255, 0.85));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--tfp-pl-border, rgba(13, 42, 87, 0.12));
    box-shadow: 0 10px 30px rgba(13, 42, 87, 0.16);
}

.tfp-unlock-icon {
    font-size: 34px;
    color: var(--md-sys-color-primary, #0D2A57);
    flex-shrink: 0;
}

.tfp-unlock-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

.tfp-unlock-text strong {
    font-size: 16px;
    color: var(--md-sys-color-primary, #0D2A57);
}

.tfp-unlock-text span {
    font-size: 13px;
    color: rgba(13, 42, 87, 0.7);
}

.tfp-unlock-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    padding: 11px 18px;
    border-radius: 999px;
    background: var(--md-sys-color-primary, #0D2A57);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(13, 42, 87, 0.32);
    transition: transform 0.12s ease, background 0.15s ease;
}

.tfp-unlock-btn:hover {
    background: #123a73;
    transform: translateY(-1px);
}

.tfp-unlock-btn .material-symbols-rounded {
    font-size: 20px;
}

.tfp-unlock-btn-secondary {
    background: var(--md-sys-color-secondary-container, #e8eef6);
    color: var(--md-sys-color-on-secondary-container, #0D2A57);
    box-shadow: none;
}

.tfp-unlock-btn-secondary:hover {
    background: #d8e3f0;
}

@keyframes tfpUnlockFlash {
    0%, 100% { box-shadow: 0 10px 30px rgba(13, 42, 87, 0.16); }
    35% { box-shadow: 0 0 0 4px rgba(79, 172, 254, 0.55), 0 10px 30px rgba(13, 42, 87, 0.22); }
}

.tfp-player-unlock.tfp-unlock-flash {
    animation: tfpUnlockFlash 0.9s ease;
}

/* ---- Responsive (mobile / tablet) ---- */
@media (max-width: 1024px) {
    .tfp-player {
        margin-bottom: 14px;
        min-width: 0;
        max-width: 100%;
    }

    .tfp-player-bar {
        position: static;
        display: grid;
        grid-template-columns: 1fr;
        grid-template-areas:
            "transport"
            "section"
            "progress"
            "knobs";
        gap: 12px;
        padding: 14px 12px;
        border-radius: 14px;
    }

    .tfp-player-transport {
        grid-area: transport;
        justify-content: center;
        width: 100%;
        gap: 2px;
    }

    .tfp-player-section-ind {
        grid-area: section;
        justify-content: center;
        width: 100%;
        font-size: 12px;
        padding: 7px 12px;
    }

    .tfp-player-progress {
        grid-area: progress;
        width: 100%;
        min-width: 0;
        flex: none;
        gap: 8px;
    }

    .tfp-player-knobs {
        grid-area: knobs;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        width: 100%;
    }

    .tfp-pl-group {
        width: 100%;
        padding: 10px 12px;
        border-radius: 12px;
        background: rgba(13, 42, 87, 0.04);
        border: 1px solid rgba(13, 42, 87, 0.08);
        box-sizing: border-box;
    }

    .tfp-pl-group.tfp-pl-tempo {
        flex-wrap: wrap;
        row-gap: 10px;
        column-gap: 8px;
    }

    .tfp-pl-group.tfp-pl-tempo .tfp-pl-speed {
        flex: 1 1 100%;
        width: 100%;
        min-width: 0;
        order: 10;
    }

    .tfp-pl-group.tfp-pl-tempo .tfp-pl-speed-val {
        order: 11;
        margin-left: auto;
        font-size: 11px;
    }

    .tfp-pl-group.tfp-pl-volume {
        justify-content: flex-start;
        gap: 10px;
    }

    .tfp-pl-group.tfp-pl-volume .tfp-pl-vol {
        flex: 1;
        width: auto;
        min-width: 0;
    }

    .tfp-pl-speed {
        width: auto;
    }

    .tfp-pl-vol {
        width: auto;
    }

    .tfp-pl-btn {
        width: 44px;
        height: 44px;
    }

    .tfp-pl-play {
        width: 52px;
        height: 52px;
    }

    .tfp-pl-scrub {
        height: 32px;
    }

    .tfp-pl-scrub-handle {
        width: 18px;
        height: 18px;
    }

    .tfp-pl-step {
        width: 32px;
        height: 32px;
    }

    .tfp-pl-hand {
        width: 36px;
        height: 36px;
    }

    .tfp-pl-bpm {
        width: 52px;
        height: 34px;
    }

    .tfp-pl-mute {
        width: 40px;
        height: 40px;
        flex-shrink: 0;
    }

    .tfp-row-replay {
        opacity: 1;
        transform: scale(1);
        top: -14px;
        left: -14px;
        right: auto;
        width: 34px;
        height: 34px;
        z-index: 8;
    }

    #tfp-song-renderer {
        padding: 18px 6px 0 18px;
        box-sizing: border-box;
    }

    .tfp-player-unlock {
        flex-direction: column;
        text-align: center;
        align-items: stretch;
    }

    .tfp-unlock-btn {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .tfp-player-bar {
        padding: 12px 10px;
        gap: 10px;
    }

    .tfp-player-transport {
        gap: 0;
    }

    .tfp-pl-btn {
        width: 40px;
        height: 40px;
    }

    .tfp-pl-btn .material-symbols-rounded {
        font-size: 22px;
    }

    .tfp-pl-play {
        width: 48px;
        height: 48px;
    }

    .tfp-pl-play .material-symbols-rounded {
        font-size: 26px;
    }

    .tfp-pl-time {
        font-size: 11px;
        min-width: 30px;
    }

    .tfp-player-section-ind {
        font-size: 11px;
    }

    .tfp-pl-bpm-unit {
        display: none;
    }
}
