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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #191919;
    color: #ffffff;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.container {
    max-width: 800px;
    width: 100%;
}

header {
    text-align: center;
    margin-bottom: 30px;
    position: relative;
}

.menu-btn {
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(255, 25, 25, 0.2);
    border: 2px solid #ff1919;
    color: #ff1919;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.3s ease;
}

.menu-btn:hover {
    background: #ff1919;
    color: #ffffff;
}

.game-mode-display {
    display: none;
    color: #ff1919;
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 10px;
    text-shadow: 0 0 10px rgba(255, 25, 25, 0.3);
}

h1 {
    color: #ff1919;
    font-size: 3rem;
    font-weight: bold;
    text-shadow: 0 0 20px rgba(255, 25, 25, 0.5);
    margin-bottom: 20px;
    letter-spacing: 2px;
}

.scores {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
}

.score-box {
    background: rgba(255, 25, 25, 0.1);
    border: 2px solid #ff1919;
    border-radius: 12px;
    padding: 15px 30px;
    min-width: 150px;
    box-shadow: 0 0 20px rgba(255, 25, 25, 0.2);
}

.score-box .label {
    display: block;
    font-size: 0.9rem;
    color: #ff1919;
    margin-bottom: 5px;
    font-weight: 600;
}

.score-box .value {
    display: block;
    font-size: 2rem;
    font-weight: bold;
    color: #ffffff;
}

.game-wrapper {
    position: relative;
    margin: 0 auto;
    max-width: 600px;
    width: 100%;
    touch-action: none;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    background: #0a0a0a;
    border: 3px solid #ff1919;
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(255, 25, 25, 0.3);
    touch-action: none;
    -webkit-touch-callout: none;
}

.start-screen,
.game-over {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(25, 25, 25, 0.98);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    overflow-y: auto;
    max-height: 600px;
}

.start-screen {
    justify-content: flex-start;
    padding-top: 10px;
}

.start-screen h2,
.game-over h2 {
    color: #ff1919;
    font-size: 2rem;
    margin-bottom: 15px;
    text-shadow: 0 0 15px rgba(255, 25, 25, 0.5);
}

.game-mode-selector {
    width: 100%;
    max-width: 500px;
    margin: 15px 0;
}

.game-mode-selector label {
    display: block;
    color: #ff1919;
    font-weight: 600;
    margin-bottom: 10px;
}

.mode-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 10px;
}

.mode-btn {
    background: rgba(255, 25, 25, 0.1);
    border: 2px solid #ff1919;
    color: #ffffff;
    padding: 12px 15px;
    font-size: 0.95rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.mode-btn:hover {
    background: rgba(255, 25, 25, 0.2);
    transform: translateY(-2px);
}

.mode-btn.active {
    background: #ff1919;
    color: #ffffff;
    box-shadow: 0 0 15px rgba(255, 25, 25, 0.5);
}

.mode-description {
    font-size: 0.9rem;
    color: #ccc;
    line-height: 1.5;
    padding: 10px;
    background: rgba(255, 25, 25, 0.05);
    border-radius: 6px;
}

.achievements-section {
    width: 100%;
    max-width: 500px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 25, 25, 0.3);
}

.achievements-section h3 {
    color: #ff1919;
    font-size: 1.2rem;
    margin-bottom: 15px;
}

.achievements-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.achievement-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: rgba(255, 25, 25, 0.05);
    border: 1px solid rgba(255, 25, 25, 0.2);
    border-radius: 6px;
    font-size: 0.85rem;
}

.achievement-item.unlocked {
    background: rgba(255, 25, 25, 0.15);
    border-color: #ff1919;
}

.achievement-item.locked {
    opacity: 0.5;
}

.achievement-icon {
    font-size: 1.5rem;
}

.achievement-info {
    flex: 1;
    text-align: left;
}

.achievement-name {
    font-weight: bold;
    color: #ff1919;
    font-size: 0.85rem;
}

.achievement-desc {
    font-size: 0.75rem;
    color: #aaa;
}

.new-achievements {
    margin: 15px 0;
    padding: 15px;
    background: rgba(255, 215, 0, 0.1);
    border: 2px solid #ffd700;
    border-radius: 8px;
}

.new-achievements h4 {
    color: #ffd700;
    margin-bottom: 10px;
}

.achievement-unlock {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    margin: 5px 0;
    background: rgba(255, 25, 25, 0.1);
    border-radius: 6px;
    color: #ffffff;
    font-weight: bold;
}

.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn-secondary {
    background: rgba(255, 25, 25, 0.2);
    border: 2px solid #ff1919;
}

.btn-secondary:hover {
    background: rgba(255, 25, 25, 0.4);
}

.final-time {
    color: #ff1919;
    font-size: 1.2rem;
    font-weight: bold;
    margin: 10px 0;
}

.instructions {
    background: rgba(255, 25, 25, 0.1);
    border: 1px solid #ff1919;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
    max-width: 400px;
}

.instructions p {
    margin: 10px 0;
    line-height: 1.6;
}

.instructions strong {
    color: #ff1919;
}

.btn {
    background: #ff1919;
    color: #ffffff;
    border: none;
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    margin: 10px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 25, 25, 0.3);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn:hover {
    background: #cc1414;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 25, 25, 0.5);
}

.btn:active {
    transform: translateY(0);
    background: #aa1111;
}

.difficulty-selector {
    margin-top: 20px;
}

.difficulty-selector label {
    display: block;
    margin-bottom: 10px;
    color: #ff1919;
    font-weight: 600;
}

.difficulty-selector select {
    background: #0a0a0a;
    color: #ffffff;
    border: 2px solid #ff1919;
    padding: 10px 20px;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    outline: none;
}

.difficulty-selector select:focus {
    box-shadow: 0 0 10px rgba(255, 25, 25, 0.5);
}

.new-record {
    color: #ffd700;
    font-size: 1.5rem;
    font-weight: bold;
    margin: 10px 0;
    animation: pulse 1s infinite;
}

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

.hidden {
    display: none !important;
}

.mobile-controls {
    display: none !important;
}

footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 25, 25, 0.3);
    color: #888;
}

footer a {
    color: #ff1919;
    text-decoration: none;
    transition: color 0.3s ease;
}

footer a:hover {
    color: #cc1414;
}

/* Tablet optimization */
@media (max-width: 1024px) and (min-width: 769px) {
    .container {
        max-width: 700px;
    }

    .scores {
        gap: 20px;
    }
}

/* Mobile optimization */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 2rem;
        margin-bottom: 10px;
    }

    .start-screen h2,
    .game-over h2 {
        font-size: 1.5rem;
        margin-bottom: 10px;
    }

    .score-box {
        min-width: 100px;
        padding: 8px 15px;
    }

    .score-box .value {
        font-size: 1.3rem;
    }

    .score-box .label {
        font-size: 0.8rem;
    }

    .btn {
        padding: 14px 28px;
        font-size: 1rem;
        min-height: 48px;
    }

    .menu-btn {
        position: static;
        margin: 10px auto;
        display: block;
        min-height: 44px;
        padding: 12px 20px;
    }

    .mode-buttons {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .mode-btn {
        padding: 14px 15px;
        font-size: 1rem;
        min-height: 48px;
    }

    .achievements-list {
        grid-template-columns: 1fr;
        max-height: 180px;
    }

    .achievement-item {
        padding: 10px;
    }

    .start-screen,
    .game-over {
        padding: 15px;
        max-height: 90vh;
    }

    .game-mode-selector {
        margin: 10px 0;
    }

    .difficulty-selector select {
        min-height: 44px;
        font-size: 1rem;
    }

    .control-row {
        gap: 15px;
    }

    header {
        margin-bottom: 15px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    body {
        padding: 5px;
    }

    h1 {
        font-size: 1.5rem;
        letter-spacing: 1px;
    }

    .scores {
        gap: 8px;
        flex-wrap: wrap;
    }

    .control-btn {
        width: 65px;
        height: 65px;
        font-size: 1.8rem;
    }

    .score-box {
        min-width: 85px;
        padding: 6px 10px;
    }

    .score-box .label {
        font-size: 0.7rem;
    }

    .score-box .value {
        font-size: 1.1rem;
    }

    .btn {
        padding: 12px 20px;
        font-size: 0.95rem;
        min-height: 48px;
        width: 100%;
        max-width: 280px;
    }

    .button-group {
        flex-direction: column;
        width: 100%;
    }

    .start-screen h2,
    .game-over h2 {
        font-size: 1.3rem;
    }

    .mode-btn {
        font-size: 0.9rem;
        padding: 12px 10px;
    }

    .mode-description {
        font-size: 0.85rem;
    }

    .achievements-section h3 {
        font-size: 1rem;
    }

    .achievement-item {
        font-size: 0.8rem;
        padding: 8px;
    }

    .achievement-icon {
        font-size: 1.3rem;
    }

    .achievement-name {
        font-size: 0.8rem;
    }

    .achievement-desc {
        font-size: 0.7rem;
    }

    .game-wrapper {
        margin-bottom: 10px;
    }

    footer {
        font-size: 0.85rem;
        margin-top: 20px;
    }
}

/* Very small devices / landscape phones */
@media (max-width: 360px) {
    h1 {
        font-size: 1.3rem;
    }

    .score-box {
        min-width: 75px;
        padding: 5px 8px;
    }

    .score-box .value {
        font-size: 1rem;
    }

    .control-btn {
        width: 55px;
        height: 55px;
        font-size: 1.5rem;
    }

    .btn {
        font-size: 0.9rem;
        padding: 10px 18px;
    }
}

/* Landscape mode optimization */
@media (max-height: 600px) and (orientation: landscape) {
    body {
        padding: 5px;
    }

    header {
        margin-bottom: 10px;
    }

    h1 {
        font-size: 1.5rem;
        margin-bottom: 5px;
    }

    .scores {
        gap: 10px;
    }

    .score-box {
        padding: 5px 10px;
    }

    .start-screen,
    .game-over {
        padding: 10px;
        font-size: 0.9rem;
    }

    .achievements-list {
        max-height: 120px;
    }

    footer {
        margin-top: 10px;
        padding-top: 10px;
    }
}
