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

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #FF6B35;
    --secondary-color: #F7931E;
    --accent-color: #FEC601;
    --bg-color: #FFE5D4;
    --text-dark: #2D3142;
    --success-color: #4ECDC4;
    --danger-color: #E63946;
    --shadow: 0 8px 0 rgba(0, 0, 0, 0.2);
}

body {
    font-family: 'Fredoka', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    padding: 10px;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(255, 255, 255, 0.03) 2px,
            rgba(255, 255, 255, 0.03) 4px
        );
    pointer-events: none;
    animation: scanlines 8s linear infinite;
}

body.dark-mode {
    background: linear-gradient(135deg, #111827 0%, #0b1224 100%);
    color: #E5E7EB;
}

body.dark-mode::before {
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(255, 255, 255, 0.02) 2px,
            rgba(255, 255, 255, 0.02) 4px
        );
}

@keyframes scanlines {
    0% { transform: translateY(0); }
    100% { transform: translateY(4px); }
}

.game-container {
    position: relative;
    width: min(1100px, 96vw);
    max-width: 1200px;
    min-height: 620px;
    max-height: 90vh;
    background: var(--bg-color);
    border-radius: 20px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.3),
        0 0 0 8px rgba(255, 255, 255, 0.1),
        inset 0 0 100px rgba(255, 255, 255, 0.2);
    overflow: hidden;
    padding: 60px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.home-button {
    position: absolute;
    top: 16px;
    left: 16px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #ffffff, #f3f4f6);
    color: var(--text-dark);
    font-weight: 700;
    border-radius: 12px;
    text-decoration: none;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border: 2px solid rgba(0, 0, 0, 0.05);
    z-index: 140;
    transition: transform 0.2s, box-shadow 0.2s;
}

body.dark-mode .home-button {
    background: linear-gradient(135deg, #111827, #0f172a);
    color: #E5E7EB;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.home-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.2);
}

.home-button:active {
    transform: translateY(1px);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
}

body.dark-mode .game-container {
    background: #0f172a;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.5),
        0 0 0 8px rgba(255, 255, 255, 0.05),
        inset 0 0 100px rgba(255, 255, 255, 0.05);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 15px;
    box-shadow: var(--shadow);
    color: white;
}

body.dark-mode .game-header {
    background: linear-gradient(135deg, #1f2937, #0f172a);
    color: #E5E7EB;
}

.title {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(12px, 3vw, 20px);
    text-shadow:
        3px 3px 0 rgba(0, 0, 0, 0.3),
        0 0 20px rgba(255, 255, 255, 0.5);
    animation: pulse 2s ease-in-out infinite;
}

body.dark-mode .title {
    color: #E5E7EB;
    text-shadow:
        2px 2px 0 rgba(0, 0, 0, 0.6),
        0 0 16px rgba(255, 255, 255, 0.3);
}

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

.score-display, .highscore-display {
    text-align: center;
}

.label {
    font-size: 10px;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

body.dark-mode .label {
    color: #cbd5e1;
}

#score, #highscore {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(16px, 4vw, 24px);
    font-weight: bold;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
}

body.dark-mode #score,
body.dark-mode #highscore {
    color: #f8fafc;
    text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: clamp(380px, 60vh, 540px);
    background: linear-gradient(to bottom, #87CEEB 0%, #E0F6FF 100%);
    border-radius: 15px;
    box-shadow:
        inset 0 -5px 20px rgba(0, 0, 0, 0.1),
        0 5px 15px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    aspect-ratio: 16 / 9;
}

body.dark-mode #gameCanvas {
    background: linear-gradient(to bottom, #0b1224 0%, #0f172a 100%);
    box-shadow:
        inset 0 -5px 20px rgba(255, 255, 255, 0.06),
        0 5px 15px rgba(0, 0, 0, 0.5);
}

.mobile-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 28px;
    margin-top: 14px;
    padding: 0 12px;
    width: 100%;
}

.control-btn {
    flex: 1 0 170px;
    min-width: 140px;
    max-width: 220px;
    padding: 15px;
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
    font-weight: 700;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    pointer-events: auto;
}

.control-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s;
}

.control-btn:hover::before {
    left: 100%;
}

.control-btn span:first-child {
    font-size: 32px;
}

.jump-btn {
    background: linear-gradient(135deg, var(--success-color), #45B7AA);
    color: white;
}

.duck-btn {
    background: linear-gradient(135deg, var(--accent-color), var(--secondary-color));
    color: var(--text-dark);
}

.control-btn:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}

.main-menu-screen,
.game-over-screen, .highscore-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(45, 49, 66, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    border-radius: 20px;
    padding: 24px;
}

body.dark-mode .main-menu-screen,
body.dark-mode .game-over-screen,
body.dark-mode .highscore-screen {
    background: rgba(15, 23, 42, 0.92);
}

.main-menu-screen.active,
.game-over-screen.active, .highscore-screen.active {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.main-menu-content,
.game-over-content, .highscore-content {
    background: white;
    padding: clamp(28px, 3vw, 48px);
    border-radius: 20px;
    text-align: center;
    max-width: 560px;
    width: min(92vw, 560px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.4s ease-out;
}

body.dark-mode .main-menu-content,
body.dark-mode .game-over-content,
body.dark-mode .highscore-content {
    background: #111827;
    color: #E5E7EB;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.game-over-content h2, .highscore-content h2 {
    font-family: 'Press Start 2P', cursive;
    color: var(--primary-color);
    font-size: clamp(18px, 4.5vw, 28px);
    margin-bottom: 30px;
    text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.1);
}

body.dark-mode .game-over-content h2,
body.dark-mode .highscore-content h2 {
    color: #E5E7EB;
}

.menu-title {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(24px, 6vw, 36px);
    margin-bottom: 16px;
    color: var(--primary-color);
    text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.1);
}

body.dark-mode .menu-title {
    color: #38bdf8;
}

.menu-subtitle {
    font-size: clamp(14px, 4vw, 18px);
    color: #4B5563;
    margin-bottom: 26px;
}

body.dark-mode .menu-subtitle {
    color: #cbd5e1;
}

.main-menu-buttons {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.final-score {
    margin-bottom: 30px;
}

.final-score p {
    font-size: 14px;
    color: #666;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

body.dark-mode .final-score p {
    color: #cbd5e1;
}

.score-value {
    font-family: 'Press Start 2P', cursive;
    font-size: 48px;
    color: var(--secondary-color);
    text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.1);
    animation: scoreReveal 0.6s ease-out;
}

body.dark-mode .score-value {
    color: #38bdf8;
}

@keyframes scoreReveal {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.2) rotate(10deg);
    }
    100% {
        transform: scale(1) rotate(0);
        opacity: 1;
    }
}

.name-input-container {
    margin-bottom: 30px;
}

#playerName {
    width: 100%;
    padding: 15px;
    font-family: 'Fredoka', sans-serif;
    font-size: 16px;
    border: 3px solid #e0e0e0;
    border-radius: 10px;
    margin-bottom: 15px;
    transition: all 0.3s;
}

body.dark-mode #playerName {
    background: #0b162f;
    color: #E5E7EB;
    border-color: #1f2937;
}

#playerName:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

body.dark-mode #playerName:focus {
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.submit-btn {
    width: 100%;
    padding: 15px;
    font-family: 'Fredoka', sans-serif;
    font-size: 16px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--success-color), #45B7AA);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 0 #3BA89D;
    position: relative;
    overflow: hidden;
}

body.dark-mode .submit-btn {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    box-shadow: 0 4px 0 #1e3a8a;
}

.submit-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.submit-btn:hover::before {
    width: 300px;
    height: 300px;
}

.submit-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #3BA89D;
}

.submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.game-over-buttons {
    display: flex;
    gap: 15px;
}

.menu-btn {
    flex: 1;
    padding: 15px 25px;
    font-family: 'Fredoka', sans-serif;
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.play-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    box-shadow: 0 4px 0 #D85A2A;
}

.play-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #D85A2A;
}

.play-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #D85A2A;
}

.highscore-btn, .back-btn {
    background: linear-gradient(135deg, #9B59B6, #8E44AD);
    color: white;
    box-shadow: 0 4px 0 #7A3A94;
}

.highscore-btn:hover, .back-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #7A3A94;
}

.highscore-btn:active, .back-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #7A3A94;
}

.back-btn {
    width: 100%;
    margin-top: 20px;
}

.highscore-list {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 20px;
}

.highscore-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 10px;
    transition: all 0.3s;
    animation: slideInRight 0.5s ease-out backwards;
}

.highscore-item:nth-child(1) { animation-delay: 0.1s; }
.highscore-item:nth-child(2) { animation-delay: 0.2s; }
.highscore-item:nth-child(3) { animation-delay: 0.3s; }
.highscore-item:nth-child(4) { animation-delay: 0.4s; }
.highscore-item:nth-child(5) { animation-delay: 0.5s; }

@keyframes slideInRight {
    from {
        transform: translateX(-50px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.highscore-item:hover {
    transform: translateX(5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.highscore-item.top-3 {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    font-weight: bold;
}

.highscore-rank {
    font-family: 'Press Start 2P', cursive;
    font-size: 20px;
    min-width: 40px;
    color: var(--primary-color);
}

.highscore-name {
    flex: 1;
    text-align: left;
    margin: 0 15px;
    font-size: 18px;
}

.highscore-score {
    font-family: 'Press Start 2P', cursive;
    font-size: 16px;
    color: var(--secondary-color);
}

.loading {
    padding: 40px;
    font-size: 18px;
    color: #666;
}

/* Tablet styles (601px to 900px) */
@media (min-width: 601px) and (max-width: 900px) {
    .game-container {
        width: 95vw;
        max-height: 88vh;
    }

    #gameCanvas {
        height: clamp(360px, 55vh, 500px);
    }

    .control-btn {
        max-width: 150px;
        padding: 15px;
        font-size: 16px;
    }
}

@media (min-width: 901px) {
    body {
        padding: 30px;
    }

    .game-container {
        gap: 20px;
    }

    #gameCanvas {
        height: clamp(420px, 58vh, 580px);
    }

    .game-over-content, .highscore-content {
        max-width: 600px;
    }
}

@media (max-width: 600px) {
    body {
        padding: env(safe-area-inset-top, 0px) 8px env(safe-area-inset-bottom, 0px);
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }

    .game-container {
        padding: 60px 10px 16px;
        width: 100%;
        max-width: 560px;
        height: auto;
        min-height: auto;
        max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        border-radius: 16px;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .game-header {
        padding: 8px 12px;
        margin-bottom: 10px;
        flex-shrink: 0;
    }

    .title {
        font-size: 10px;
    }

    #gameCanvas {
        flex: 0 1 auto;
        width: 100%;
        aspect-ratio: 16 / 9;
        height: auto;
        max-height: 62vh;
        min-height: 260px;
    }

    .mobile-controls {
        gap: 16px;
        margin-top: 6px;
        padding: 0;
        flex-shrink: 0;
    }

    .control-btn {
        flex: 1 0 44%;
        min-width: 0;
        max-width: none;
        padding: 12px;
        font-size: 15px;
        gap: 6px;
        border-radius: 12px;
    }

    .control-btn span:first-child {
        font-size: 24px;
    }

    .btn-label {
        font-size: 11px;
    }

    .game-over-content, .highscore-content {
        padding: 30px 20px;
    }

    .score-value {
        font-size: 36px;
    }

    .game-over-buttons {
        flex-direction: column;
    }

    .highscore-item {
        padding: 12px 15px;
    }

    .highscore-name {
        font-size: 16px;
    }

    .highscore-score {
        font-size: 14px;
    }
}
