html, body {
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

body {
    min-height: 100vh;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: background 0.3s ease-in-out;
    overflow: hidden;
    /* Handle iPhone notch and Dynamic Island */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

@media (max-width: 576px) {
    body {
        align-items: flex-start;
        padding-top: max(6rem, env(safe-area-inset-top));
    }
}

body.target-window-active {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
}

#landing-screen {
    text-align: center;
    color: white;
}

#landing-screen img {
    max-width: 300px;
    width: 80vw;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
    margin-bottom: 2rem;
}

@media (orientation: landscape) and (max-height: 500px) {
    #landing-screen img {
        display: none;
    }
}

#landing-screen h1 {
    font-size: 3rem;
    font-weight: bold;
    margin-bottom: 2rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

#start-btn {
    font-size: 1.5rem;
    padding: 1rem 3rem;
    border-radius: 50px;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}

#start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

#start-btn:active {
    transform: translateY(0);
}

@media (max-width: 576px) {
    #landing-screen h1 {
        font-size: 2rem;
    }

    #start-btn {
        font-size: 1.2rem;
        padding: 0.8rem 2rem;
    }
}

.midi-link {
    margin-top: 1.5rem;
    font-size: 0.9rem;
}

.midi-link a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
}

.midi-link a:hover {
    color: white;
    text-decoration: underline;
}

#midi-status {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
}

#midi-status .midi-on {
    color: #2ecc71;
    font-weight: bold;
}

#landing-screen img.midi-pulse {
    animation: midiPulse 0.15s ease-out;
}

@keyframes midiPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

#countdown-screen {
    text-align: center;
    color: white;
}

#countdown-screen img {
    max-width: 300px;
    width: 80vw;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
    margin-bottom: 3rem;
}

@media (orientation: landscape) and (max-height: 500px) {
    #countdown-screen img {
        display: none;
    }
}

#countdown-number {
    font-size: 10rem;
    font-weight: bold;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.4);
    animation: pulse 1s ease-in-out;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@media (max-width: 576px) {
    #countdown-screen img {
        margin-bottom: 2rem;
    }

    #countdown-number {
        font-size: 4rem;
    }
}

#game-screen {
    text-align: center;
    color: white;
}

#game-screen h2 {
    font-size: 2rem;
    font-weight: bold;
    margin-bottom: 2rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

@media (max-width: 576px) {
    #game-screen h2 {
        font-size: 1.5rem;
    }
}

#drum-button {
    width: 60vw;
    max-width: 300px;
    aspect-ratio: 1;
    background: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(60vw * 0.5);
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
    transition: transform 0.1s, box-shadow 0.1s;
    margin: 0 auto;
}

#drum-button:hover {
    transform: scale(1.05);
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

#drum-button:active {
    transform: scale(0.95);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

#drum-button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.game-controls {
    margin-top: 3rem;
}

.game-controls button {
    font-size: 1.5rem;
    padding: 0.75rem 1.5rem;
}

#refresh-btn.bounce {
    animation: bounceButton 1s ease-in-out infinite;
}

@keyframes bounceButton {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-15px);
    }
}

#menu-button {
    position: fixed;
    top: max(20px, env(safe-area-inset-top, 20px));
    right: max(20px, env(safe-area-inset-right, 20px));
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 10px;
    padding: 0.75rem 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 2000;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    transition: transform 0.2s;
}

#menu-button:hover {
    transform: scale(1.1);
}

#menu-dropdown {
    position: fixed;
    top: max(70px, calc(env(safe-area-inset-top, 20px) + 50px));
    right: max(20px, env(safe-area-inset-right, 20px));
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 0.5rem 0;
    z-index: 1999;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    min-width: 200px;
}

#menu-dropdown a,
#menu-dropdown button {
    display: block;
    width: 100%;
    padding: 0.75rem 1.5rem;
    text-align: left;
    border: none;
    background: none;
    color: #333;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 1rem;
}

#menu-dropdown a:hover,
#menu-dropdown button:hover {
    background: rgba(0, 0, 0, 0.1);
}

#timer-display {
    position: fixed;
    top: max(20px, env(safe-area-inset-top, 20px));
    left: max(20px, env(safe-area-inset-left, 20px));
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 10px;
    font-size: 1.5rem;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    z-index: 1000;
}

#timer-display.target-window {
    background: rgba(34, 139, 34, 0.9);
    animation: pulse 0.3s ease-in-out infinite;
}

@media (min-width: 750px) {
    #drum-button {
        font-size: 150px;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    #drum-button {
        width: 30vh;
        max-width: 200px;
        font-size: calc(30vh * 0.5);
    }

    #game-screen h2 {
        font-size: 1.2rem;
        margin-bottom: 1rem;
    }

    .game-controls {
        margin-top: 1.5rem;
    }
}

#success-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 215, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: successPulse 0.5s ease-out;
}

@keyframes successPulse {
    0% { transform: scale(0); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

#success-message {
    text-align: center;
    color: #fff;
}

#success-message h1 {
    font-size: 5rem;
    font-weight: bold;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.3);
    margin-bottom: 1rem;
    animation: bounce 1s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

#success-message p {
    font-size: 2rem;
    font-weight: bold;
}

#success-message button {
    margin-top: 2rem;
    font-size: 1.5rem;
    padding: 0.75rem 2rem;
}

@media (max-width: 576px) {
    #success-message h1 {
        font-size: 3rem;
    }
    #success-message p {
        font-size: 1.5rem;
    }
    #success-message button {
        font-size: 1.2rem;
        padding: 0.6rem 1.5rem;
    }
}

#failure-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(220, 20, 60, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: shake 0.5s ease-out;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}

#failure-overlay.fade-out {
    opacity: 0;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-10px); }
    20%, 40%, 60%, 80% { transform: translateX(10px); }
}

#failure-message {
    text-align: center;
    color: #fff;
}

#failure-message h1 {
    font-size: 5rem;
    font-weight: bold;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.5);
    margin-bottom: 1rem;
    animation: shakeText 0.3s ease-in-out infinite;
}

@keyframes shakeText {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

#failure-message p {
    font-size: 2rem;
    font-weight: bold;
}

@media (max-width: 576px) {
    #failure-message h1 {
        font-size: 3rem;
    }
    #failure-message p {
        font-size: 1.5rem;
    }
}

#highscores-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow-y: auto;
    z-index: 3000;
    /* Handle iPhone notch and Dynamic Island */
    padding-top: max(2rem, env(safe-area-inset-top));
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
}

#highscores-screen h1 {
    color: white;
    text-align: center;
    font-size: 3rem;
    margin-bottom: 2rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

#highscores-list {
    max-width: 600px;
    margin: 0 auto 2rem;
}

.score-item {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 1rem 1.5rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.score-item.win {
    border-left: 5px solid #2ecc71;
}

.score-item.perfect {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    border-left: 5px solid #DAA520;
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.5);
}

.score-item.early {
    border-left: 5px solid #f39c12;
}

.score-item.late {
    border-left: 5px solid #e74c3c;
}

.score-item .result {
    font-weight: bold;
    font-size: 1.25rem;
}

.score-item.win .result {
    color: #2ecc71;
}

.score-item.perfect .result {
    color: #8B4513;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.5);
}

.score-item.early .result {
    color: #f39c12;
}

.score-item.late .result {
    color: #e74c3c;
}

.score-item .datetime {
    font-size: 0.9rem;
    color: #666;
}

.score-item.perfect .datetime {
    color: #8B4513;
}

#back-to-game-btn-top {
    display: block;
    margin: 0 auto 1rem auto;
}

#back-to-game-btn {
    display: block;
    margin: 2rem auto;
}

@media (max-width: 576px) {
    #highscores-screen h1 {
        font-size: 2rem;
    }

    .score-item {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
    }

    .score-item .datetime {
        margin-top: 0.5rem;
    }
}
