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

body {
    font-family: 'Courier New', monospace;
    background: linear-gradient(180deg, #0a0a1a 0%, #1a0a2e 100%);
    color: #a855f7;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

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

header {
    text-align: center;
    margin-bottom: 20px;
    text-shadow: 0 0 10px #a855f7, 0 0 20px #a855f7;
    position: relative;
}

.how-to-play-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(168, 85, 247, 0.3);
    border: 2px solid #a855f7;
    color: #a855f7;
    font-size: 1.2em;
    font-weight: bold;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.how-to-play-btn:hover {
    background: rgba(168, 85, 247, 0.6);
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.5);
}

.leaderboard-btn {
    right: 55px;
}

h1 {
    font-size: 3em;
    letter-spacing: 0.2em;
    color: #a855f7;
    margin-bottom: 5px;
}

.subtitle {
    font-size: 1em;
    color: #00aaff;
    letter-spacing: 0.1em;
}

.game-wrapper {
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #a855f7;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 0 30px rgba(168, 85, 247, 0.3);
}

.hud {
    display: flex;
    justify-content: space-around;
    margin-bottom: 15px;
    padding: 10px;
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid #a855f7;
    border-radius: 5px;
}

.hud-item {
    display: flex;
    gap: 8px;
    align-items: center;
}

.hud-label {
    color: #00aaff;
    font-size: 0.9em;
}

.hud-value {
    color: #a855f7;
    font-size: 1.2em;
    font-weight: bold;
    text-shadow: 0 0 5px #a855f7;
}

#gameCanvas {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    background: #000;
    border: 2px solid #a855f7;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.5), inset 0 0 50px rgba(168, 85, 247, 0.1);
    cursor: crosshair;
}

.stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid #a855f7;
    border-radius: 5px;
}

.stat-row {
    display: flex;
    justify-content: space-around;
    gap: 10px;
}

.stat-item {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 5px 10px;
    border-radius: 3px;
}

.stat-item.destroyed {
    background: rgba(255, 0, 0, 0.1);
    border: 1px solid #ff5370;
}

.stat-item.insecure {
    background: rgba(255, 165, 0, 0.1);
    border: 1px solid #ffaa00;
}

.stat-item.malware {
    background: rgba(255, 0, 100, 0.1);
    border: 1px solid #ff0064;
}

.stat-item.secure-good {
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid #a855f7;
}

.stat-item.insecure-missed {
    background: rgba(255, 100, 0, 0.15);
    border: 1px solid #ff6400;
}

.stat-item.malware-missed {
    background: rgba(255, 0, 0, 0.15);
    border: 1px solid #ff0000;
}

.stat-icon {
    font-size: 1.2em;
}

.stat-label {
    font-size: 0.85em;
    color: #999;
}

.stat-value {
    font-weight: bold;
    font-size: 1.1em;
}

.stat-item.destroyed .stat-value {
    color: #ff5370;
}

.stat-item.secure-good .stat-value {
    color: #a855f7;
}

.stat-item.insecure .stat-value {
    color: #ffaa00;
}

.stat-item.malware .stat-value {
    color: #ff0064;
}

.stat-item.insecure-missed .stat-value {
    color: #ff6400;
}

.stat-item.malware-missed .stat-value {
    color: #ff0000;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid #00aaff;
    border-radius: 5px;
    flex-wrap: wrap;
}

.control-group {
    color: #00aaff;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 5px;
}

.key {
    background: rgba(0, 170, 255, 0.2);
    border: 1px solid #00aaff;
    padding: 3px 8px;
    border-radius: 3px;
    color: #fff;
    font-weight: bold;
    box-shadow: 0 0 5px rgba(0, 170, 255, 0.3);
}

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

.overlay.hidden {
    display: none;
}

.overlay-content {
    background: rgba(10, 10, 26, 0.95);
    border: 3px solid #a855f7;
    border-radius: 10px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 0 50px rgba(168, 85, 247, 0.5);
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
}

#overlayTitle {
    font-size: 2.5em;
    margin-bottom: 20px;
    text-shadow: 0 0 15px #a855f7;
}

#overlayMessage {
    font-size: 1.2em;
    color: #00aaff;
    margin-bottom: 20px;
}

.final-stats {
    margin-top: 20px;
    padding: 20px;
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid #a855f7;
    border-radius: 5px;
}

.final-stats h3 {
    margin-bottom: 15px;
    color: #00aaff;
}

.final-stats p {
    margin: 8px 0;
    font-size: 1.1em;
}

.code-modal-content {
    background: rgba(10, 10, 26, 0.98);
    border: 3px solid #a855f7;
    border-radius: 10px;
    padding: 0;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 50px rgba(168, 85, 247, 0.5);
}

.code-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid #a855f7;
    background: rgba(168, 85, 247, 0.1);
}

.code-modal-header h3 {
    color: #a855f7;
    margin: 0;
    font-size: 1.5em;
}

.close-button {
    background: rgba(255, 0, 100, 0.3);
    border: 2px solid #ff0064;
    color: #fff;
    font-size: 1.5em;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.close-button:hover {
    background: rgba(255, 0, 100, 0.6);
    transform: scale(1.1);
}

.code-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: rgba(0, 20, 40, 0.95);
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    color: #fff;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.code-modal-footer {
    padding: 15px;
    text-align: center;
    border-top: 2px solid #a855f7;
    background: rgba(168, 85, 247, 0.1);
    color: #999;
    font-size: 0.9em;
}

.welcome-content {
    max-width: 450px;
}

.welcome-body {
    padding: 25px;
    background: rgba(0, 20, 40, 0.95);
    color: #fff;
    text-align: center;
}

.welcome-body p {
    color: #ccc;
    margin-bottom: 20px;
    line-height: 1.5;
}

.welcome-body .text-input {
    width: 100%;
    margin-bottom: 10px;
    text-align: center;
}

.welcome-error {
    min-height: 1.2em;
    color: #ff5370;
    font-size: 0.9em;
    margin-bottom: 10px;
}

.welcome-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.leaderboard-content {
    max-width: 500px;
}

.leaderboard-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: rgba(0, 20, 40, 0.95);
    color: #fff;
    min-height: 100px;
}

.leaderboard-loading,
.leaderboard-empty {
    text-align: center;
    color: #999;
    padding: 20px 0;
}

.leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 5px;
    border-bottom: 1px solid rgba(168, 85, 247, 0.2);
}

.leaderboard-row:last-child {
    border-bottom: none;
}

.leaderboard-rank {
    color: #a855f7;
    font-weight: bold;
    width: 3em;
    flex-shrink: 0;
}

.leaderboard-name {
    flex: 1;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-score {
    color: #00ff41;
    font-weight: bold;
}

#leaderboardSubmit {
    margin: 20px 0;
    padding: 15px;
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid #a855f7;
    border-radius: 5px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: center;
}

.text-input {
    padding: 10px 14px;
    background: rgba(0, 20, 40, 0.95);
    border: 2px solid #a855f7;
    border-radius: 5px;
    color: #fff;
    font-family: 'Courier New', monospace;
    font-size: 1em;
    min-width: 160px;
}

.text-input:focus {
    outline: none;
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.5);
}

.btn-primary {
    padding: 10px 20px;
    background: linear-gradient(135deg, #a855f7 0%, #8b3fd8 100%);
    border: 2px solid #a855f7;
    color: #fff;
    font-size: 1em;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.4);
    font-family: 'Courier New', monospace;
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #b66fff 0%, #9c4fe8 100%);
    transform: scale(1.05);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: default;
}

.btn-secondary {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid #666;
    color: #ccc;
    font-size: 1em;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Courier New', monospace;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: #999;
    color: #fff;
}

#submitResult {
    width: 100%;
    text-align: center;
    color: #00aaff;
    font-size: 0.9em;
}

.how-to-play-content {
    background: rgba(10, 10, 26, 0.98);
    border: 3px solid #a855f7;
    border-radius: 10px;
    padding: 0;
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 50px rgba(168, 85, 247, 0.5);
}

.how-to-play-body {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    background: rgba(0, 20, 40, 0.95);
    color: #fff;
}

.how-to-play-body section {
    margin-bottom: 25px;
}

.how-to-play-body h4 {
    color: #a855f7;
    font-size: 1.3em;
    margin-bottom: 12px;
    text-shadow: 0 0 10px rgba(168, 85, 247, 0.5);
}

.how-to-play-body ul {
    list-style: none;
    padding-left: 0;
}

.how-to-play-body li {
    margin: 10px 0;
    padding-left: 20px;
    position: relative;
    line-height: 1.6;
}

.how-to-play-body li:before {
    content: "▸";
    position: absolute;
    left: 0;
    color: #00aaff;
}

.how-to-play-body p {
    line-height: 1.6;
    color: #ccc;
}

.score-positive {
    color: #00ff41;
    font-weight: bold;
}

.score-negative {
    color: #ff5370;
    font-weight: bold;
}

.restart-button {
    margin-top: 10px;
    margin-bottom: 20px;
    padding: 15px 40px;
    background: linear-gradient(135deg, #a855f7 0%, #8b3fd8 100%);
    border: 2px solid #a855f7;
    color: #fff;
    font-size: 1.2em;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.5);
    font-family: 'Courier New', monospace;
}

.restart-button:hover {
    background: linear-gradient(135deg, #b66fff 0%, #9c4fe8 100%);
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(168, 85, 247, 0.8);
}

.restart-button:active {
    transform: scale(0.98);
}

.end-game-container {
    text-align: center;
    margin-top: 20px;
    padding: 15px;
}

.end-game-button {
    padding: 12px 30px;
    background: rgba(255, 83, 112, 0.3);
    border: 2px solid #ff5370;
    color: #ff5370;
    font-size: 1em;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 0 15px rgba(255, 83, 112, 0.3);
    font-family: 'Courier New', monospace;
}

.end-game-button:hover {
    background: rgba(255, 83, 112, 0.5);
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(255, 83, 112, 0.6);
}

.end-game-button:active {
    transform: scale(0.98);
}

.mobile-only {
    display: none;
}

.desktop-only {
    display: flex;
}

@media (max-width: 768px) {
    h1 {
        font-size: 2em;
    }
    
    .hud {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .stats {
        flex-direction: column;
        gap: 10px;
    }
    
    #gameCanvas {
        max-width: 100%;
        height: auto;
        touch-action: none;
        cursor: pointer;
    }

    .mobile-only {
        display: flex;
    }

    .desktop-only {
        display: none;
    }

    .container {
        padding: 0;
    }

    .game-wrapper {
        padding: 10px;
    }

    .stat-row {
        flex-direction: column;
        gap: 5px;
    }

    .controls {
        gap: 10px;
        padding: 10px;
    }

    .control-group {
        font-size: 0.8em;
    }

    .leaderboard-content,
    .welcome-content {
        max-width: 95vw;
    }

    .welcome-actions {
        flex-direction: column;
    }

    .welcome-actions .btn-primary,
    .welcome-actions .btn-secondary {
        width: 100%;
    }

    #leaderboardSubmit {
        flex-direction: column;
        align-items: stretch;
    }

    #usernameInput,
    #submitScoreBtn {
        width: 100%;
    }
}
