@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: #1a1a2e;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    font-family: 'Press Start 2P', monospace;
    touch-action: none;
}

#game-container {
    position: relative;
    width: 800px;
    max-width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

#help-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.6);
    background: rgba(0, 0, 0, 0.4);
    color: white;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

#help-btn:hover {
    background: rgba(0, 0, 0, 0.7);
    border-color: white;
}

/* Fullscreen button */
#fullscreen-btn {
    display: none;
    position: absolute;
    top: 8px;
    left: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.6);
    background: rgba(0, 0, 0, 0.4);
    color: white;
    font-size: 16px;
    cursor: pointer;
    z-index: 10;
    align-items: center;
    justify-content: center;
}

#fullscreen-btn:hover {
    background: rgba(0, 0, 0, 0.7);
    border-color: white;
}

/* On-screen controls - below canvas, not overlaid. Driven by pointer events,
   so they work with a mouse, a pen or a finger; shown on every device. */
#touch-controls {
    display: flex;
    width: 100%;
    padding: 8px 12px;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 10;
}

.touch-dpad, .touch-actions {
    display: flex;
    gap: 8px;
    pointer-events: auto;
    align-items: center;
}

#touch-controls button {
    touch-action: none;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.7);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    transition: background 0.1s ease, transform 0.1s ease;
}

#touch-controls button:active,
#touch-controls button.pressed {
    background: rgba(255, 255, 255, 0.3);
    border-color: white;
    transform: scale(0.93);
}

/* Down button style - slightly smaller, different color hint */
#btn-down {
    border-color: rgba(255, 136, 0, 0.7);
}
#btn-down:active, #btn-down.pressed {
    border-color: #ff8800;
    background: rgba(255, 136, 0, 0.3);
}

#btn-swing {
    font-size: 28px;
}

/* Jump button accent */
#btn-jump {
    border-color: rgba(68, 219, 251, 0.7);
}
#btn-jump:active, #btn-jump.pressed {
    border-color: #48dbfb;
    background: rgba(68, 219, 251, 0.3);
}

/* Swing button accent */
#btn-swing {
    border-color: rgba(255, 107, 107, 0.7);
}
#btn-swing:active, #btn-swing.pressed {
    border-color: #ff6b6b;
    background: rgba(255, 107, 107, 0.3);
}

/* Landscape orientation hint */
#rotate-hint {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 26, 0.95);
    z-index: 2000;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    text-align: center;
    gap: 16px;
}

#rotate-hint .rotate-icon {
    font-size: 64px;
    animation: rotate-phone 2s ease-in-out infinite;
}

@keyframes rotate-phone {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

#rotate-hint p {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    line-height: 1.8;
    padding: 0 20px;
}

#rotate-dismiss {
    margin-top: 12px;
    padding: 12px 24px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: white;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    border-radius: 8px;
    cursor: pointer;
}

#rotate-dismiss:active {
    background: rgba(255, 255, 255, 0.3);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #1a1a2e;
    border: 2px solid #4169E1;
    border-radius: 12px;
    padding: 24px;
    max-width: 420px;
    width: 90%;
    color: white;
    position: relative;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-content h2 {
    font-family: 'Press Start 2P', monospace;
    font-size: 16px;
    text-align: center;
    margin-bottom: 16px;
    color: #CCFF00;
}

.rules-section {
    margin-bottom: 14px;
}

.rules-section h3 {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    margin-bottom: 6px;
    color: #87CEEB;
}

.rules-section p {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    line-height: 2;
    color: #ccc;
}

.rules-section p.green { color: #4CAF50; }
.rules-section p.gold { color: #FFD700; }
.rules-section p.red { color: #FF4444; }

/* On-screen control legend in the help modal - shown everywhere now */
.touch-only-section {
    display: block;
}

.close-btn {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
}

.got-it-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-top: 12px;
    background: #4169E1;
    color: white;
    border: none;
    border-radius: 8px;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    cursor: pointer;
}

.got-it-btn:hover {
    background: #5179F1;
}

/* ============ MOBILE / TABLET ============ */
@media (max-width: 850px), (pointer: coarse) {
    body {
        align-items: flex-start;
        padding-top: 0;
    }

    #fullscreen-btn {
        display: flex;
    }

    /* Hide keyboard controls hint in help modal on touch */
    .rules-section:first-child p:nth-child(n+4) {
        display: none;
    }
}

/* Tablet landscape */
@media (min-width: 600px) and (max-width: 1024px) and (pointer: coarse) {
    #touch-controls button {
        width: 72px;
        height: 72px;
        font-size: 26px;
    }

    #btn-swing {
        font-size: 30px;
    }
}

/* Phone portrait - show rotate hint */
@media (max-width: 600px) and (orientation: portrait) and (pointer: coarse) {
    #rotate-hint {
        display: flex;
    }

    #rotate-hint.dismissed {
        display: none;
    }
}

/* Phone - smaller buttons, tighter layout */
@media (max-width: 700px) and (pointer: coarse) {
    #touch-controls {
        padding: 6px 8px;
    }

    #touch-controls button {
        width: 56px;
        height: 56px;
        font-size: 20px;
        border-width: 2px;
    }

    #btn-swing {
        font-size: 24px;
    }

    .touch-dpad, .touch-actions {
        gap: 6px;
    }
}

/* Very small phones */
@media (max-width: 400px) and (pointer: coarse) {
    #touch-controls button {
        width: 48px;
        height: 48px;
        font-size: 18px;
    }

    #btn-swing {
        font-size: 20px;
    }

    .touch-dpad, .touch-actions {
        gap: 4px;
    }
}

/* Landscape phones - optimize vertical space */
@media (max-height: 500px) and (pointer: coarse) {
    body {
        align-items: flex-start;
    }

    #game-container {
        max-height: 100dvh;
    }

    #gameCanvas {
        border-radius: 0;
        max-height: calc(100dvh - 70px);
        width: auto;
        max-width: 100vw;
    }

    #touch-controls {
        padding: 4px 12px;
    }

    #touch-controls button {
        width: 52px;
        height: 52px;
        font-size: 18px;
    }

    #btn-swing {
        font-size: 22px;
    }
}

/* Fullscreen mode adjustments */
#game-container:fullscreen,
#game-container:-webkit-full-screen {
    background: #1a1a2e;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    width: 100%;
    height: 100%;
}

#game-container:fullscreen #gameCanvas,
#game-container:-webkit-full-screen #gameCanvas {
    flex: 1;
    max-height: calc(100% - 80px);
    width: auto;
    max-width: 100%;
    border-radius: 0;
}

#game-container:fullscreen #touch-controls,
#game-container:-webkit-full-screen #touch-controls {
    flex-shrink: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
