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

html, body {
    height: 100%;
    height: 100dvh;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

body {
    overflow: hidden;
    background: #4a3a2a;
    font-family: 'Courier New', monospace;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: visible;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
}

#ui-overlay {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    gap: 16px;
    z-index: 10;
    pointer-events: none;
}

#ui-overlay > * {
    pointer-events: auto;
}

#score-display, #best-score-display {
    background: rgba(20, 40, 60, 0.75);
    border: 1px solid rgba(120, 180, 220, 0.3);
    border-radius: 6px;
    padding: 8px 16px;
    color: #e8d8c0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.label {
    font-size: 10px;
    letter-spacing: 2px;
    opacity: 0.7;
}

#score-value, #best-value {
    font-size: 24px;
    font-weight: bold;
}

#ranking-toggle {
    position: absolute;
    top: 16px;
    right: 52px;
    background: rgba(20, 40, 60, 0.75);
    border: 1px solid rgba(120, 180, 220, 0.3);
    border-radius: 4px;
    padding: 4px 10px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    color: #e8d8c0;
    z-index: 10;
    user-select: none;
    pointer-events: auto;
}

#ranking-toggle:hover {
    border-color: #7bb8d9;
}

#settings-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 24px;
    cursor: pointer;
    color: #e8d8c0;
    z-index: 10;
    user-select: none;
    pointer-events: auto;
}

#ranking-panel {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 85%;
    max-width: 360px;
    max-height: 70%;
    background: rgba(20, 40, 60, 0.95);
    border: 1px solid rgba(120, 180, 220, 0.3);
    border-radius: 8px;
    color: #e8d8c0;
    display: none;
    flex-direction: column;
    z-index: 50;
    pointer-events: auto;
    overflow: hidden;
}

#ranking-panel.open {
    display: flex;
}

#ranking-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(120, 180, 220, 0.2);
}

#ranking-header h3 {
    font-size: 14px;
    margin: 0;
}

#ranking-close {
    cursor: pointer;
    font-size: 18px;
    opacity: 0.7;
}

#ranking-close:hover {
    opacity: 1;
}

#ranking-my {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(120, 180, 220, 0.2);
    background: rgba(80, 160, 200, 0.1);
}

.ranking-my-label {
    font-size: 10px;
    letter-spacing: 2px;
    opacity: 0.7;
    margin-bottom: 6px;
}

#ranking-my-info {
    font-size: 13px;
}

#ranking-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}

.ranking-row {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    font-size: 12px;
    gap: 8px;
}

.ranking-row:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

.ranking-row.me {
    background: rgba(80, 160, 200, 0.15);
}

.ranking-rank {
    width: 28px;
    font-weight: bold;
    color: #ffdd66;
}

.ranking-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ranking-score {
    width: 70px;
    text-align: right;
    color: #ffdd66;
}

.ranking-block {
    width: 45px;
    text-align: right;
    opacity: 0.7;
    font-size: 11px;
}

.ranking-table-header {
    border-bottom: 1px solid rgba(120, 180, 220, 0.2);
    opacity: 0.6;
    font-size: 10px;
    padding: 6px 16px;
}

.ranking-loading {
    text-align: center;
    padding: 20px;
    opacity: 0.6;
}

#settings-panel {
    position: absolute;
    top: 50px;
    right: 16px;
    background: rgba(20, 40, 60, 0.9);
    border: 1px solid rgba(120, 180, 220, 0.3);
    border-radius: 6px;
    padding: 16px;
    color: #ccc;
    display: none;
    flex-direction: column;
    gap: 10px;
    z-index: 10;
    pointer-events: auto;
}

#settings-panel.open {
    display: flex;
}

#settings-panel h3 {
    color: #e8d8c0;
    font-size: 14px;
    margin-bottom: 4px;
}

#settings-panel label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    cursor: pointer;
}

.settings-btn {
    background: none;
    border: 1px solid rgba(120, 180, 220, 0.5);
    color: #e8d8c0;
    padding: 6px 12px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    cursor: pointer;
    margin-top: 8px;
    border-radius: 4px;
}

.settings-btn:hover {
    background: rgba(120, 180, 220, 0.2);
}

#camera-controls {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10;
    pointer-events: auto;
}

#camera-controls button {
    background: rgba(20, 40, 60, 0.75);
    border: 1px solid rgba(120, 180, 220, 0.3);
    border-radius: 4px;
    color: #ccc;
    padding: 8px 16px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
}

#camera-controls button.active {
    background: rgba(80, 160, 200, 0.3);
    border-color: #7bb8d9;
    color: #e8d8c0;
}

#camera-controls button:hover {
    border-color: #7bb8d9;
}

#game-over {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    pointer-events: auto;
}

#game-over-content {
    text-align: center;
    color: #ff4400;
}

#game-over-content h2 {
    font-size: 48px;
    letter-spacing: 8px;
    margin-bottom: 16px;
    text-shadow: 0 0 20px rgba(255, 68, 0, 0.8);
}

#game-over-content p {
    font-size: 14px;
    color: #999;
}

#final-score {
    display: block;
    font-size: 36px;
    color: #ffcc00;
    margin: 8px 0 24px;
}

#restart-btn {
    background: none;
    border: 2px solid #ff6600;
    color: #ff6600;
    padding: 10px 24px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    cursor: pointer;
    letter-spacing: 2px;
}

#restart-btn:hover {
    background: #ff6600;
    color: #000;
}

.gameover-explosion {
    position: absolute;
    top: 50%;
    left: 45%;
    transform: translate(-50%, -50%) scale(0);
    font-size: min(96vw, 360px);
    line-height: 1;
    z-index: 200;
    pointer-events: none;
    animation: explode-in 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.gameover-explosion.fade-out {
    animation: explode-fade 1s ease-out forwards;
}

@keyframes explode-in {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    60% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes explode-fade {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

.gameover-title {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 201;
    animation: fade-in 0.8s ease-out forwards;
    opacity: 0;
}

.gameover-title h1 {
    font-family: 'Black Ops One', Impact, sans-serif;
    font-size: 44px;
    color: #ffffff;
    letter-spacing: 4px;
    text-shadow: 0 0 20px rgba(255, 200, 100, 0.8), 0 4px 8px rgba(0, 0, 0, 0.9);
    margin-bottom: 16px;
}

.gameover-score {
    font-family: 'Courier New', monospace;
    font-size: 18px;
    color: #ffdd66;
    margin-bottom: 24px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.gameover-restart {
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid #ffffff;
    color: #ffffff;
    padding: 12px 28px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    cursor: pointer;
    letter-spacing: 2px;
    pointer-events: auto;
}

.gameover-restart:hover {
    background: #ffffff;
    color: #1a0a00;
}

@keyframes fade-in {
    from { opacity: 0; transform: translate(-50%, -40%); }
    to { opacity: 1; transform: translate(-50%, -50%); }
}

@media (max-width: 600px) {
    #ui-overlay {
        gap: 8px;
        top: 10px;
        left: 10px;
    }

    #score-display, #best-score-display {
        padding: 6px 10px;
    }

    .label {
        font-size: 8px;
    }

    #score-value, #best-value {
        font-size: 18px;
    }

    #camera-controls {
        gap: 4px;
    }

    #camera-controls button {
        padding: 6px 10px;
        font-size: 10px;
    }
}
