body, html {
    height: 100%;
    margin: 0;
    padding: 0;
    background-color: #f5f5f5;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    color: #333;
}

/* Use consistent box-sizing so paddings don't break mobile sizing */
*, *::before, *::after {
    box-sizing: border-box;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100%;
    margin: 0;
    padding: 15px;
    box-sizing: border-box;
    overflow: hidden;
}

header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #eaeaea;
}

.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-around;
    width: 30px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1001;
    position: absolute;
    left: 0;
}

.menu-toggle span {
    width: 30px;
    height: 3px;
    background: #2c3e50;
    border-radius: 10px;
    transition: all 0.3s linear;
    position: relative;
    transform-origin: 1px;
}

h1 {
    color: #2c3e50;
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

.main-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    flex: 1;
    gap: 20px;
    min-height: 0;
    overflow: hidden;
}

/* Allow the main layout to shrink on small viewports so content fits vertically */
@media (max-width: 1024px) {
    .main-layout {
        max-height: calc(100vh - 120px);
        overflow: auto;
    }
}

/* Sidebar Styles */
.sidebar {
    background-color: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
    position: relative;
}

/* Sidebar close button - hidden by default on large screens */
.sidebar-close {
    display: none;
    background: transparent;
    border: none;
    cursor: pointer;
}

.sidebar-section h3 {
    color: #2c3e50;
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    padding-bottom: 5px;
    border-bottom: 2px solid #4a90e2;
}

/* Exercise Selector */
.exercise-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.exercise-selector label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 8px 12px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 2px solid #e9ecef;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.exercise-selector label:hover {
    background-color: #e9ecef;
    border-color: #4a90e2;
    transform: translateY(-2px);
}

.exercise-selector input[type="radio"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.option-checkbox {
    margin-top: 10px;
    padding: 8px 12px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 2px solid #e9ecef;
    transition: all 0.2s ease;
}

.option-checkbox:hover {
    background-color: #e9ecef;
    border-color: #4a90e2;
}

.option-checkbox label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.95rem;
    color: #2c3e50;
    font-weight: 600;
}

.option-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Key Selector */
.key-selector {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    padding-right: 5px;
}

.key-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background-color: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
    transition: all 0.2s ease;
}

.key-checkbox:hover {
    background-color: #e9ecef;
    border-color: #4a90e2;
}

.key-checkbox input {
    margin: 0;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.key-checkbox label {
    cursor: pointer;
    font-size: 0.95rem;
    color: #495057;
    flex: 1;
}

/* Duration Controls */
.duration-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.slider-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.slider-container label {
    font-weight: 600;
    font-size: 1rem;
    color: #2c3e50;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.slider-value {
    font-size: 1rem;
    color: #4a90e2;
    font-weight: 600;
    background-color: white;
    padding: 3px 10px;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
}

input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: #e0e0e0;
    outline: none;
    cursor: pointer;
    transition: background 0.2s ease;
}

input[type="range"]:hover {
    background: #d0d0d0;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4a90e2;
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #357abd;
    transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4a90e2;
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

input[type="range"]::-moz-range-thumb:hover {
    background: #357abd;
    transform: scale(1.1);
}

/* Main Content Area */
.content-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 30px;
    background-color: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    min-width: 0;
    width: 100%;
    max-width: 400px;
    height: 400px;
    max-height: 80vh;
    margin: auto;
}

.staff-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: auto;
    margin-bottom: 20px;
    position: relative;
    overflow: visible;
    flex-shrink: 0;
}

#staff {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    pointer-events: none;
    padding: 40px 0;
    overflow: visible;
    text-align: center;
}

#staff svg {
    margin: 0 auto !important;
    display: block;
    max-width: 100%;
    height: auto;
    overflow: visible;
}

/* Constrain rendered staff vertically on small screens so it doesn't push content off-screen */
#staff svg {
    max-height: 60vh;
    height: auto;
    width: auto;
}

.answer-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px 6px;
    background-color: transparent;
    border-radius: 0;
    border: none;
    min-height: auto;
    box-shadow: none;
}

#answer {
    font-size: 3rem;
    font-weight: 700;
    color: #2c3e50;
    text-align: center;
    padding: 6px 8px;
    background-color: transparent;
    border-radius: 0;
    border: none;
    min-width: 0;
    box-shadow: none;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .menu-toggle {
        display: flex;
    }

    /* Make space for the hamburger so the centered title doesn't overlap it */
    header {
        padding-left: 60px;
    }

    .main-layout {
        grid-template-columns: 1fr;
        overflow: visible;
    }
    
    .app-container {
        overflow-y: auto;
        height: auto;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -300px;
        width: 280px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        border-radius: 0 12px 12px 0;
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.1);
    }

    /* Modal-style sidebar for small screens */
    .sidebar {
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%) scale(0.95);
        width: min(92%, 360px);
        height: auto;
        max-height: 90vh;
        border-radius: 12px;
        transition: opacity 0.22s ease, transform 0.22s ease;
        opacity: 0;
        visibility: hidden;
        overflow-y: auto;
        padding-bottom: 20px;
    }

    /* Show a prominent close control inside sidebar on small screens */
    .sidebar-close {
        display: inline-flex;
        position: absolute;
        right: 12px;
        top: 12px;
        background: #2c3e50;
        color: #fff;
        width: 38px;
        height: 38px;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        font-size: 1.2rem;
        line-height: 1;
        z-index: 1002;
        box-shadow: 0 6px 18px rgba(0,0,0,0.12);
        border: none;
        transition: transform 0.12s ease, background 0.12s ease;
    }

    .sidebar-close:hover,
    .sidebar-close:focus {
        background: #1f2b3a;
        transform: translateY(-1px) scale(1.03);
        outline: none;
    }

    .sidebar.active {
        opacity: 1;
        visibility: visible;
        transform: translate(-50%, -50%) scale(1);
        z-index: 1001;
    }

    /* Backdrop */
    .modal-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.22s ease;
    }

    .modal-backdrop.active {
        opacity: 1;
        visibility: visible;
    }
    
    .content-area {
        min-height: 400px;
    }
}

/* About modal (global) */
.about-modal {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.98);
    width: min(720px, 92%);
    max-width: 720px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
    z-index: 1002;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.18s ease, transform 0.18s ease;
    max-height: 90vh;
    overflow: hidden;
}

.about-modal.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.about-modal-content {
    padding: 22px 26px;
    color: #24303b;
}

/* Make modal content scroll if it exceeds the viewport height */
.about-modal-content {
    overflow-y: auto;
    max-height: calc(90vh - 60px);
}

.about-modal h2 {
    margin-top: 0;
    margin-bottom: 8px;
    font-size: 1.4rem;
    color: #2c3e50;
}

.about-modal p {
    margin: 8px 0;
    line-height: 1.4;
}

.modal-close {
    position: absolute;
    right: 12px;
    top: 8px;
    background: #2c3e50;
    border: none;
    color: #ffffff;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(44,62,80,0.18);
    transition: transform 0.12s ease, background 0.12s ease, opacity 0.12s ease;
}

.modal-close:hover,
.modal-close:focus {
    background: #1f2b3a;
    transform: translateY(-1px) scale(1.03);
    outline: none;
}

/* Slightly move the close button inward on very small screens so it's comfortably tappable */
@media (max-width: 420px) {
    .modal-close {
        right: 10px;
        top: 10px;
        width: 42px;
        height: 42px;
    }
}

.about-link a {
    display: inline-block;
    color: #2c6cdf;
    font-weight: 700;
    text-decoration: none;
}

.about-link a:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .app-container {
        padding: 10px;
    }
    
    header {
        margin-bottom: 15px;
        padding-bottom: 10px;
    }

    h1 {
        font-size: 1.8rem;
    }
    
    .staff-container {
        min-height: unset;
        max-height: 55vh;
        margin-bottom: 20px;
    }

    #staff {
        padding: 20px 0;
    }

    #staff svg {
        transform: none;
        max-height: 50vh;
    }
    
    #answer {
        font-size: 3rem;
        min-width: 150px;
    }
    
    .sidebar {
        padding: 15px;
        gap: 10px;
    }
    
    .content-area {
        padding: 15px;
        min-height: unset;
        max-height: calc(100vh - 140px);
        overflow: auto;
        width: 100%;
        max-width: unset;
        height: auto;
    }

    .sidebar-section h3 {
        font-size: 1rem;
        margin-bottom: 8px;
    }
}
