/* =========================================
   SAFARI FONT OVERRIDE
   Forces Safari to use the WOFF2 file and ignore the missing WOFF 404
   ========================================= */
@font-face {
    font-family: 'Bravura';
    src: url('../fonts/Bravura.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: block;
}

/* Also cover lowercase just in case alphaTab references it differently */
@font-face {
    font-family: 'bravura';
    src: url('../fonts/Bravura.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: block;
}

/* =========================================
   THEME INTEGRATION VARIABLES (FIXED)
   ========================================= */
:root {
    /* Deep fallback chain: WP Block Theme -> Astra -> Elementor -> Hardcoded Hex */
    /* This checks each theme's variable. If it doesn't exist, it moves to the next. */
    --at-primary: var(--wp--preset--color--primary, var(--ast-global-color-0, var(--e-global-color-primary, #0073aa)));
    --at-bg: var(--wp--preset--color--background, var(--ast-bg-color, var(--e-global-color-background, #ffffff)));
    --at-text: var(--wp--preset--color--foreground, var(--ast-text-color, var(--e-global-color-text, #333333)));
    --at-border: var(--wp--preset--color--border, rgba(0, 0, 0, 0.12));
    --at-sidebar-bg: var(--wp--preset--color--secondary, #f7f7f7);
    --at-danger: #d63638;

    /* Derived variables */
    --at-controls-bg: var(--at-primary);
    --at-controls-text: #ffffff;

    /* Hover state (darkens the primary color by 15%) */
    --at-primary-hover: color-mix(in srgb, var(--at-primary) 85%, black);
}

/* Apply base typography and colors to the wrapper */
.at-wrap,
.at-modal-overlay,
.at-modal-trigger-wrapper {
    font-family: inherit;
    color: var(--at-text);
    background: var(--at-bg);
}

/* =========================================
   BASE & LAYOUT
   ========================================= */

.at-modal-open-btn i,
.at-controls .btn i {
    min-width: 16px;
    text-align: center;
    display: inline-flex;
    justify-content: center;
    align-items: center;
}

.at-wrap {
    width: 80vw;
    height: 80vh;
    margin: 0 auto;
    border: 1px solid var(--at-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.at-content {
    position: relative;
    overflow: hidden;
    flex: 1 1 auto;
}

/* --- Sidebar (Collapsible) --- */
.at-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 0; /* Start collapsed */
    max-width: 0;
    display: flex;
    align-content: stretch;
    z-index: 1001;
    overflow: hidden;
    border-right: 1px solid var(--at-border);
    background: var(--at-sidebar-bg);
    transition: width 0.3s ease, max-width 0.3s ease;
}

.at-sidebar.open {
    width: 177px;
    max-width: 177px;
    overflow-y: auto;
}

.at-viewport {
    overflow-y: auto;
    position: absolute;
    top: 0;
    left: 0; /* No offset when collapsed */
    right: 0;
    bottom: 0;
    transition: left 0.3s ease;
}

.at-sidebar.open ~ .at-viewport {
    left: 177px; /* Push viewport when sidebar is open */
}

/* --- Sidebar Heading --- */
.at-sidebar-heading {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--at-text);
    opacity: 0.5;
    padding: 12px 12px 8px;
    margin: 0;
    
    /* Pins the heading to the top of the sidebar when scrolling */
    position: sticky;
    top: 0;
    background: var(--at-sidebar-bg);
    z-index: 10;
}

/* --- Track Selector --- */
.at-track {
    display: flex;
    position: relative;
    padding: 10px 20px; /* Adjusted padding for cleaner look */
    transition: background 0.2s;
    cursor: pointer;
    align-items: center;
}

.at-track:hover {
    background: color-mix(in srgb, var(--at-text) 10%, transparent);
}

/* Removed .at-track-icon references entirely */
.at-track > .at-track-details {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 1; /* Take up remaining space */
}

.at-track-name {
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* Truncates long track names cleanly */
}

.at-track.active {
    background: color-mix(in srgb, var(--at-primary) 10%, transparent);
}

.at-track.active > .at-track-name {
    color: var(--at-primary);
    font-weight: bold;
}

/* =========================================
   OVERLAYS & CURSORS
   ========================================= */
.at-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1002;
    backdrop-filter: blur(3px);
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.at-overlay-content {
    margin-top: 20px;
    background: var(--at-bg);
    color: var(--at-text);
    box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.3);
    padding: 10px 15px;
    border-radius: 4px;
    border: 1px solid var(--at-border);
}

.at-cursor-bar {
    background: color-mix(in srgb, var(--at-primary) 25%, transparent);
}

.at-selection div {
    background: color-mix(in srgb, var(--at-primary) 15%, transparent);
}

.at-cursor-beat {
    background: var(--at-primary);
    width: 3px;
    opacity: 0.75;
}

.at-highlight * {
    fill: var(--at-primary);
    stroke: var(--at-primary);
}

/* =========================================
   FOOTER & CONTROLS
   ========================================= */
.at-controls {
    flex: 0 0 auto;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    background: var(--at-controls-bg);
    color: var(--at-controls-text);
    padding: 0 15px;
    flex-wrap: wrap;
}

.at-controls>div {
    display: flex;
    align-items: center;
}

/* All direct children of the groups */
.at-controls>div>* {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    height: 40px;
    padding: 0 12px;
    border-left: 1px solid rgba(255, 255, 255, 0.15);
    box-sizing: border-box;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.at-controls>div>*:first-child {
    border-left: none;
}

/* Text-based buttons (Count In, Click, Loop) */
.at-controls .btn-text {
    padding: 0 14px;
    color: var(--at-controls-text);
    text-decoration: none !important;
    background: transparent;
    border: none;
    transition: background 0.2s;
}

.at-controls .btn-text:hover,
.at-controls .btn-text.active {
    background: var(--at-primary-hover);
}

/* Icon-based buttons (Play, Return to Start) */
.at-controls .btn {
    width: 40px;
    padding: 0;
    flex-shrink: 0;
    color: var(--at-controls-text);
    border-radius: 0;
    font-size: 16px;
    text-decoration: none !important;
}

.at-controls a.active,
.at-controls a:hover {
    background: var(--at-primary-hover);
    text-decoration: none;
}

.at-controls .btn.disabled {
    cursor: progress;
    opacity: 0.5;
}

/* Song Info */
.at-song-info {
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
    min-width: 120px;
    margin: 0 4px;
    justify-content: flex-start;
    padding: 0 12px;
}

.at-song-title {
    font-weight: bold;
}

/* Tempo Control */
.at-tempo-control {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px !important;
}

.at-tempo-label {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.at-tempo-input {
    width: 45px !important;
    padding: 0px !important;
    text-align: center;
    border: none !important;
    border-radius: 3px;
    font-size: 13px;
    font-weight: bold;
    background: none !important;
    color: var(--at-controls-text) !important;
    -moz-appearance: textfield;
    appearance: textfield;
}

.at-tempo-input::-webkit-outer-spin-button,
.at-tempo-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.at-tempo-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    cursor: pointer;
    color: var(--at-controls-text);
    transition: all 0.2s;
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
}

.at-tempo-btn:hover {
    background: var(--at-primary-hover);
    border-color: transparent;
}

.at-tempo-btn:active {
    transform: scale(0.95);
}

/* Volume Control */
.at-volume-control {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px !important;
}

.at-volume-slider {
    flex-grow: 1;
    cursor: pointer;
}

/* Zoom Control */
.at-zoom {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px !important;
}

.at-zoom-label {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

/* Remove border from the select so it doesn't double up with the container's border */
.at-zoom select {
    border-left: none !important;
}

/* (Optional) Layout Control - matches Zoom for symmetry */
.at-layout {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px !important;
}

.at-layout-label {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.at-layout select {
    border-left: none !important;
}

/* Base Select Styling */
.at-controls select {
    -moz-appearance: none;
    -webkit-appearance: none;
    appearance: none;
    border: none;
    width: auto;
    min-width: 80px;
    height: 40px;
    background: var(--at-controls-bg);
    padding: 4px 10px;
    color: var(--at-controls-text);
    font-size: 13px;
    font-weight: 500;
    text-align-last: center;
    text-align: center;
    cursor: pointer;
    /* border-left is now handled by the parent container, removed from here */
}

/* --- Track Mixer --- */
.at-track-mixer {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.at-track-mute-btn {
    background: none;
    border: none;
    padding: 0;
    width: 20px;
    height: 20px;
    color: var(--at-primary, #0073aa);
    /* Default color */
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: color 0.2s, background 0.2s;
}

.at-track-mute-btn:hover {
    background: color-mix(in srgb, var(--at-text, #333) 10%, transparent);
}

/* FIX: Change the text color, not the SVG fill. 
   currentColor inside the SVG will automatically turn red! */
.at-track-mute-btn.muted {
    color: var(--at-danger, #d63638);
}

.at-track-mute-btn svg {
    width: 14px;
    height: 14px;
    /* Removed 'fill: currentColor' from here to prevent it from overriding the SVG's internal fill="none" attributes */
}

.at-track-vol-slider,
.at-volume-slider {
    flex-grow: 1;
    height: 4px;
    cursor: pointer;
    accent-color: var(--at-primary);
    max-width: 110px;
}

/* =========================================
   MODAL SPECIFIC
   ========================================= */
.at-modal-trigger-wrapper {
    text-align: center;
    margin: 20px 0;
}

.at-modal-open-btn {
    background: var(--at-primary);
    color: var(--at-controls-text);
    border: none;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
    font-family: inherit;
}

.at-modal-open-btn:hover {
    background: var(--at-primary-hover);
}

.at-modal-open-btn i {
    font-size: 18px;
}

.at-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    overflow: hidden;
}

.at-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.at-modal-overlay[aria-hidden="true"] {
    pointer-events: none;
}

.at-modal-content {
    position: relative;
    background: var(--at-bg);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    width: 90vw;
    max-width: 1200px;
    height: 90vh;
    max-height: 800px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: auto;
}

.at-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.2s;
}

.at-modal-close:hover {
    background: var(--at-danger);
}

.at-modal-player {
    width: 100% !important;
    height: 100% !important;
    border: none;
    display: flex;
    flex-direction: column;
}

.at-modal-player .at-content {
    flex-grow: 1;
    height: calc(100% - 60px) !important;
    min-height: 0;
}

.at-modal-player .at-viewport {
    flex-grow: 1;
    overflow: auto;
}

/* =========================================
   THEME OVERRIDES & FIXES
   ========================================= */
/* Fix for Astra / Theme max-width conflicts */
.entry-content[data-ast-blocks-layout]>.at-modal-overlay,
.entry-content .at-modal-overlay {
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
}

/* Force Modal Behavior */
body .at-modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.85) !important;
    z-index: 999999 !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    margin: 0 !important;
    padding: 0 !important;
}

body .at-modal-overlay[aria-hidden="true"] {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

body .at-modal-overlay.active {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

body .at-modal-overlay .at-modal-content {
    position: relative !important;
    width: 90vw !important;
    max-width: 1200px !important;
    height: 90vh !important;
    max-height: 800px !important;
    margin: auto !important;
    background: var(--at-bg) !important;
    z-index: 1000000 !important;
}

body.modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
}

/* Inline Player Fixes */
.at-wrap.at-inline {
    min-height: 600px !important;
    min-width: 300px !important;
    display: block !important;
}

.at-wrap.at-inline .at-content {
    min-height: 640px !important;
}

.at-modal-player {
    min-height: auto !important;
}

@media (max-width: 600px) {
    .at-tempo-value {
        display: none;
    }

    .at-tempo-slider {
        width: 60px;
    }
}

/* Fallback for missing FontAwesome icons */
.at-track-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Universal SVG Icon Styling --- */
.at-controls .btn svg,
.at-controls .at-zoom svg,
.at-tempo-control svg,
/* 👈 Added: Fixes Tempo icon size */
.at-volume-control svg {
    /* 👈 Added: Fixes Volume icon size (Bonus fix!) */
    width: 16px;
    height: 16px;
    fill: currentColor;
    pointer-events: none;
}

.at-modal-open-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* --- Loading Spinner Animation --- */
.at-spinner {
    animation: at-spin 1.5s linear infinite;
    margin-right: 8px;
    fill: var(--at-primary, #0073aa);
}

@keyframes at-spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* --- Sidebar Mixer SVGs --- */
.at-track-mute-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.at-track-mute-btn.muted svg {
    fill: var(--at-danger, #d63638);
}

/* Target Input */
.at-volume-slider {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    cursor: pointer;
}

/* --- Webkit Browsers --- */
.at-volume-slider::-webkit-slider-runnable-track {
    height: 12px;
    background: #ffffff;
    border-radius: 20px;
    border: 0px solid #cbd5e1;
    box-shadow: 0px 2px 0px rgba(0, 0, 0, 0.1);
}

.at-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 30px;
    width: 30px;
    background: #ffffff;
    border-radius: 30px;
    border: 4px solid #0284c7;
    box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.3);
    margin-top: -9px;
}

/* --- Firefox --- */
.at-volume-slider::-moz-range-track {
    height: 12px;
    background: #ffffff;
    border-radius: 20px;
    border: 0px solid #cbd5e1;
    box-shadow: 0px 2px 0px rgba(0, 0, 0, 0.1);
}

.at-volume-slider::-moz-range-thumb {
    height: 30px;
    width: 30px;
    background: #ffffff;
    border-radius: 30px;
    border: 4px solid #0284c7;
    box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.3);
}

/* =========================================
   CUSTOM SONG DETAILS
   ========================================= */
.at-custom-song-details {
    text-align: center;
    padding: 30px 20px 10px 20px;
    font-family: inherit;
    /* Inherits your theme's font, or change to 'Georgia', serif */
    color: var(--at-text);
}

.at-custom-song-details h1,
.at-custom-song-details h2 {
    margin: 0 0 8px 0;
    font-weight: bold;
    line-height: 1.3;
}

.at-custom-song-details h1 {
    font-size: 26px;
}

.at-custom-song-details h2 {
    font-size: 18px;
    opacity: 0.8;
    font-weight: 500;
}

/* Hide empty elements so we don't get blank space */
.at-custom-song-details>*:empty {
    display: none !important;
}

/* Restore original .at-content */
.at-content {
    position: relative;
    overflow: hidden;
    flex: 1 1 auto;
}

/* =========================================
   MOBILE RESPONSIVE CONTROLS
   ========================================= */
@media (max-width: 768px) {
    /* Stack the left and right groups vertically */
    .at-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 0;
    }
    
    /* Make each group take full width and center its items */
    .at-controls > div {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        border-top: 1px solid rgba(255, 255, 255, 0.15);
        padding: 8px 10px;
    }
    
    .at-controls > div:first-child {
        border-top: none;
    }
    
    /* Remove vertical dividers on mobile for a cleaner look */
    .at-controls > div > * {
        border-left: none !important;
    }
    
    /* Slightly larger touch targets for fingers */
    .at-controls .btn {
        width: 48px;
        height: 48px;
    }
    
    /* Center the song info on its own line */
    .at-song-info {
        width: 100%;
        justify-content: center;
        margin: 5px 0;
    }
    
    /* Adjust spacing for dropdowns and inputs */
    .at-tempo-control, .at-volume-control, .at-zoom, .at-layout {
        padding: 4px 10px !important;
    }
    
    /* Ensure select dropdowns don't overflow */
    .at-controls select {
        min-width: 70px;
        padding: 4px 6px;
    }
}