.metronome-app-wrapper {
    /* Map to global theme variables */
    --card-bg: var(--sidebar-bg);
    --text-primary: var(--text-main);
    --text-secondary: var(--text-muted);
    
    /* Metronome specific colors for dark mode */
    --accent-glow: rgba(88, 166, 255, 0.3);
    --accent-secondary: #79c0ff;
    --surface: #21262d;
    --surface-hover: #30363d;
    --word-default: #484f58;
    --word-highlight: var(--accent);
    --word-passed: #8b949e;

    color: var(--text-primary);
    display: flex;
    justify-content: center;
    padding: 10px 0 30px 0;
}

body.light-mode .metronome-app-wrapper {
    --accent-glow: rgba(9, 105, 218, 0.3);
    --accent-secondary: #0366d6;
    --surface: #eaeef2;
    --surface-hover: #d0d7de;
    --word-default: #d0d7de;
    --word-highlight: var(--accent);
    --word-passed: #57606a;
}

.app-container {
    width: 100%;
    max-width: 1000px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.main-header {
    text-align: center;
}

.main-header h1 {
    font-size: 36px;
    font-weight: 800;
    margin-bottom: 15px;
    color: var(--text-primary);
    text-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.intro-card {
    background: rgba(56, 189, 248, 0.05);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 16px;
    padding: 20px 25px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    text-align: left;
    max-width: 800px;
    margin: 0 auto;
}

.intro-card .info-icon {
    color: var(--accent);
    flex-shrink: 0;
    margin-top: 2px;
}

.intro-card p {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.workspace {
    flex-grow: 1;
    display: flex;
    gap: 20px;
    align-items: stretch;
}

/* Sidebar styles */
.metronome-sidebar {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 40px 30px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.2);
    text-align: center;
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.display-container {
    margin-bottom: 40px;
    position: relative;
}

.bpm-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 180px;
    height: 180px;
    margin: 0 auto;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 
        inset 5px 5px 15px rgba(0,0,0,0.1),
        inset -5px -5px 15px rgba(255,255,255,0.02),
        0 10px 20px rgba(0,0,0,0.1);
    position: relative;
    z-index: 1;
}

.bpm-display::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
    z-index: -1;
    opacity: 0.3;
    filter: blur(8px);
    transition: opacity 0.3s ease;
}

.playing .bpm-display::before {
    opacity: 0.8;
}

#bpm-value {
    font-size: 64px;
    font-weight: 800;
    line-height: 1;
    text-shadow: 0 0 20px var(--accent-glow);
}

.bpm-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 1px;
    margin-top: 5px;
}

.controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 40px;
    width: 100%;
}

.icon-btn {
    background: var(--surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--surface-hover);
    transform: scale(1.1);
}

.slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--surface-hover);
    border-radius: 3px;
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent-glow);
}

.play-container {
    display: flex;
    justify-content: center;
    margin-bottom: 25px;
}

.play-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 10px 25px var(--accent-glow);
    transition: all 0.3s ease;
}

.play-btn:hover {
    transform: scale(1.05) translateY(-3px);
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 10px 20px;
    border-radius: 20px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.secondary-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

/* Reading Pane Styles */
.reading-pane {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.level-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface);
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 15px 10px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: var(--surface);
}

.text-container {
    padding: 40px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-y: auto;
}

.text-display {
    font-size: 32px;
    line-height: 1.6;
    font-weight: 400;
    color: var(--word-default);
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px 12px;
}

.text-display .word {
    transition: color 0.1s, transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), background-color 0.1s;
    border-radius: 4px;
    padding: 0 4px;
    position: relative;
    display: inline-block;
}

.text-display .word.passed {
    color: var(--word-passed);
}

.text-display .word.highlight {
    color: var(--bg-color);
    background: var(--word-highlight);
    transform: translateY(-6px) scale(1.05);
    font-weight: 600;
    box-shadow: 0 8px 15px var(--accent-glow);
}

.breath-mark {
    font-size: 14px;
    color: var(--accent);
    opacity: 0.5;
    font-weight: 800;
    margin: 0 4px;
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: all 0.2s;
    align-self: center;
    display: inline-block;
}

.breath-mark.highlight {
    opacity: 1;
    transform: scale(1.2);
    color: var(--accent-secondary);
}

.custom-input {
    width: 100%;
    flex-grow: 1;
    min-height: 300px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 20px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
}

.custom-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

/* Animations */
@keyframes pulse-sidebar {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

@media (max-width: 800px) {
    .workspace {
        flex-direction: column;
    }
    .metronome-sidebar {
        width: 100%;
    }
    .level-tabs {
        flex-wrap: wrap;
    }
    .tab-btn {
        flex-basis: 50%;
    }
}

/* Toggle Switch Styles */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--surface-hover);
  transition: .3s;
  border-radius: 24px;
}
.switch .slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-primary);
  transition: .3s;
  border-radius: 50%;
}
.switch input:checked + .slider {
  background-color: #ff5555;
}
.switch input:checked + .slider:before {
  transform: translateX(20px);
  background-color: #ffffff;
}

/* BPM Flash Animation */
@keyframes flash-accelerate {
    0% { transform: scale(1); box-shadow: inset 5px 5px 15px rgba(0,0,0,0.1), 0 10px 20px rgba(0,0,0,0.1); }
    50% { transform: scale(1.1); box-shadow: 0 0 30px rgba(255, 85, 85, 0.6); background: rgba(255, 85, 85, 0.2); }
    100% { transform: scale(1); box-shadow: inset 5px 5px 15px rgba(0,0,0,0.1), 0 10px 20px rgba(0,0,0,0.1); }
}
.accelerating .bpm-display {
    animation: flash-accelerate 0.6s ease-out;
}

/* Toast Container */
#toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2500;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}

/* Toast Styles */
.toast {
    background: rgba(20, 20, 25, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Features Section */
.features-section {
    max-width: 1000px;
    margin: 15px auto 20px;
    padding: 0 20px;
}
.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
    margin-top: 15px;
}
.feature-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 18px 20px;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    overflow: hidden;
    z-index: 1;
}
.feature-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, rgba(88, 166, 255, 0.05), rgba(0,0,0,0));
    z-index: -1;
    transition: opacity 0.4s ease;
    opacity: 0;
}
.feature-card:hover {
    transform: translateY(-8px) scale(1.02);
    border-color: var(--accent);
    box-shadow: 0 15px 35px rgba(0,0,0,0.15);
}
.feature-card:hover::before {
    opacity: 1;
}
.feature-card h3 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}
.feature-card h3 span.emoji {
    font-size: 1.3rem;
    background: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
}
.feature-card p {
    margin: 0;
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* PM & IE Polish Features */

/* Focus Mode */
body.focus-mode .main-header,
body.focus-mode .features-section,
body.focus-mode .origin-story-section,
body.focus-mode .feedback-form-section,
body.focus-mode .level-tabs {
    opacity: 0.1;
    pointer-events: none;
    transition: opacity 0.5s ease;
}
body.focus-mode .text-container {
    box-shadow: 0 0 50px rgba(88, 166, 255, 0.15);
    transition: box-shadow 0.5s ease;
}

/* Progress Bar */
.progress-bar-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--surface);
    overflow: hidden;
    z-index: 10;
}
.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 0 10px var(--accent);
}

/* Desktop Wrapper */
.floating-controls-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
}

/* Mobile Controls & Downscaling */
@media (max-width: 768px) {
    .workspace {
        flex-direction: column;
        padding-bottom: 120px;
        gap: 20px;
    }
    
    .metronome-sidebar {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--card-bg);
    }
    
    .main-header {
        margin-bottom: 20px;
    }
    
    .main-header h1 {
        font-size: 2rem;
        margin-bottom: 10px;
    }
    
    .intro-card {
        padding: 15px;
    }
    
    .intro-row {
        gap: 12px;
    }
    
    .text-container {
        padding: 20px;
    }
    
    .text-display {
        font-size: 24px;
        line-height: 1.5;
    }
    
    .features-section {
        margin: 20px auto 10px;
    }
    
    .origin-story-section {
        margin: 20px auto 20px;
        padding: 0 10px;
    }
    
    .story-card {
        padding: 20px;
    }
    .story-card h2 {
        font-size: 1.5rem !important;
    }
    
    /* Compact Features & Story on Mobile */
    .feature-card {
        padding: 15px;
    }
    .feature-card h3 {
        font-size: 1.1rem;
    }
    .story-card {
        padding: 15px !important;
    }
    .story-card h4 {
        font-size: 1.05rem !important;
    }
    .story-card p {
        font-size: 0.95rem !important;
    }

    .floating-controls-wrapper {
        background: var(--card-bg);
        padding: 15px;
        border-radius: 20px;
        border: 1px solid var(--border-color);
        display: flex;
        flex-direction: column;
        gap: 15px;
    }
    
    .bpm-display {
        width: 140px;
        height: 140px;
    }
    
    #bpm-value {
        font-size: 56px;
    }
    
    .floating-controls-wrapper.is-sticky {
        position: fixed;
        /* top is set dynamically via JS */
        left: 50%;
        transform: translateX(-50%);
        width: 92%;
        max-width: 400px;
        border-radius: 24px; /* Fully rounded */
        border: 1px solid var(--border-color);
        box-shadow: 0 10px 40px rgba(0,0,0,0.4);
        z-index: 1000;
        flex-direction: row;
        flex-wrap: wrap; /* Allows two lines */
        align-items: center;
        justify-content: space-between;
        padding: 8px 12px;
        animation: slideDown 0.3s ease;
        gap: 6px;
        margin-top: 10px; /* Gap from the header */
    }
    
    @keyframes slideDown {
        from { transform: translate(-50%, -100%); }
        to { transform: translate(-50%, 0); }
    }
    
    .floating-controls-wrapper.is-sticky .display-container {
        margin-bottom: 0 !important;
        flex-shrink: 0;
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
    }
    .floating-controls-wrapper.is-sticky .bpm-display {
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
        width: auto;
        height: auto;
        min-width: 36px;
    }
    .floating-controls-wrapper.is-sticky #bpm-value {
        font-size: 20px;
    }
    .floating-controls-wrapper.is-sticky .bpm-label {
        font-size: 9px;
        margin-top: -2px;
    }


    /* Mode Selector on second row for sticky */
    .floating-controls-wrapper.is-sticky .mode-selector {
        width: 100% !important;
        margin: 4px 0 0 0 !important;
        order: 10; /* Force to bottom row */
    }
    .floating-controls-wrapper.is-sticky .custom-dropdown {
        margin-bottom: 0 !important;
    }
    .floating-controls-wrapper.is-sticky .dropdown-header {
        padding: 8px 15px !important;
    }

    .floating-controls-wrapper.is-sticky .controls {
        flex-direction: row;
        margin: 0;
        padding: 0;
        background: transparent;
        flex: 1;
        min-width: 0;
        box-shadow: none;
        gap: 8px;
    }
    
    .floating-controls-wrapper.is-sticky .slider {
        flex: 1;
        min-width: 0;
        width: 100%;
    }
    
    .floating-controls-wrapper.is-sticky .icon-btn {
        flex-shrink: 0;
        width: 36px;
        height: 36px;
    }
    
    #toast-container {
        bottom: 100px !important;
    }
    
    .floating-controls-wrapper.is-sticky .play-container {
        margin: 0;
    }
    
    .floating-controls-wrapper.is-sticky .play-btn {
        width: 50px;
        height: 50px;
    }
    .floating-controls-wrapper.is-sticky .play-icon, .floating-controls-wrapper.is-sticky .pause-icon {
        width: 24px;
        height: 24px;
    }
}

/* Custom Dropdown Styles (Global) */
.custom-dropdown {
    position: relative;
    width: 100%;
    margin-bottom: 20px;
}
.custom-dropdown .dropdown-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}
.custom-dropdown .dropdown-header:hover {
    border-color: rgba(255,255,255,0.1);
}
.custom-dropdown .dropdown-list {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    list-style: none;
    padding: 5px 0;
    margin: 0;
    z-index: 2500;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    display: none;
}
.custom-dropdown .dropdown-list.show {
    display: block;
    animation: fadeIn 0.15s ease-out;
}
.custom-dropdown .dropdown-list li {
    padding: 12px 15px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-secondary);
    transition: 0.2s;
    text-align: left;
}
.custom-dropdown .dropdown-list li:hover, .custom-dropdown .dropdown-list li.active {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}
