/* Общие стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #ffffff;
    min-height: 100vh;
    padding: 16px;
    overflow-x: hidden;
}

.container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Экраны */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 10;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    padding: 16px;
}

.screen.active {
    opacity: 1;
    visibility: visible;
    z-index: 20;
}

/* Карточка */
.card {
    background: rgba(22, 33, 62, 0.95);
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(0, 255, 136, 0.2);
    max-width: min(560px, 92vw);
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    text-align: center;
    animation: slideDown 0.5s ease;
}

/* Menu-specific centering inside the card */
#menuScreen .card {
    /* keep card sizing but ensure enough vertical space for visual centering */
    min-height: 360px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#menuScreen .menu-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    box-sizing: border-box;
    padding: 8px 6px;
}

#menuScreen .menu-actions {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    width: 100%;
}

#menuScreen .menu-actions .btn {
    width: min(420px, 90%);
    max-width: 100%;
}

#menuScreen .controls-hint { margin-top: 8px; }

/* Mode select centering (same as menu) */
#modeScreen .card {
    min-height: 360px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#modeScreen .mode-content { width: 100%; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:20px; padding:8px 6px; }
#modeScreen .mode-content .menu-actions { width:100%; display:flex; flex-direction:column; gap:16px; align-items:center; }
#modeScreen .mode-content .menu-actions .btn { width: min(420px,90%); max-width:100%; }

/* Game Over centering */
#gameOverScreen .card {
    min-height: 360px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gameover-content {
    width: min(520px, 92vw);
    max-width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 14px;
    padding: 8px;
}

.gameover-content .title { margin-bottom: 0; }
.gameover-content .reason { margin: 0; color: #ff6b5b; font-weight: 600; }
.gameover-content .score { margin: 0; color: #b0b0b0; font-size: 1.2rem; }

.gameover-content .reason { margin-bottom: 12px; }
.gameover-content .score { margin-bottom: 24px; }

.gameover-content .actions {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    align-items: center;
}

.gameover-content .actions .btn {
    width: min(420px, 90%);
    max-width: 100%;
}

@media (max-width: 480px) {
    .gameover-content { gap: 12px; }
    .gameover-content .actions .btn { width: 100%; }
}

.title {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 30px;
    color: #00ff88;
    text-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
    letter-spacing: 2px;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.controls-hint {
    font-size: 0.9rem;
    color: #888;
    font-style: italic;
}

/* Кнопки */
.btn {
    padding: 14px 32px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: system-ui, -apple-system, sans-serif;
    text-transform: uppercase;
    letter-spacing: 1px;
    width: 100%;
    max-width: 300px;
}

.btn-primary {
    background: linear-gradient(135deg, #00ff88 0%, #00cc6f 100%);
    color: #000;
    box-shadow: 0 4px 15px rgba(0, 255, 136, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 255, 136, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(0, 255, 136, 0.3);
}

.btn-secondary {
    background: linear-gradient(135deg, #ff6b5b 0%, #ff5544 100%);
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 107, 91, 0.3);
}

.btn-secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 91, 0.5);
}

.btn-secondary:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(255, 107, 91, 0.3);
}

/* ИГРА */
#gameScreen {
    background: transparent;
    position: fixed;
    padding: 0;
    z-index: 20;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    background: rgba(22, 33, 62, 0.95);
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(0, 255, 136, 0.2);
    animation: slideDown 0.5s ease;
}

.game-header {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    max-width: 640px;
    padding: 0 16px;
    gap: 20px;
}

.score {
    display: flex;
    align-items: center;
    gap: 8px;
}

.score .label {
    font-size: 1rem;
    color: #b0b0b0;
}

.score #scoreValue {
    font-size: 1.5rem;
    font-weight: 700;
    color: #00ff88;
    text-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
    min-width: 40px;
}

.mode-name {
    font-size: 1rem;
    color: #b0b0b0;
    font-style: italic;
}

.bomb-timer {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bomb-timer .label {
    font-size: 0.9rem;
    color: #ff6b5b;
}

.bomb-timer #bombValue {
    font-size: 1.2rem;
    font-weight: 700;
    color: #ff6b5b;
    text-shadow: 0 0 10px rgba(255, 107, 91, 0.5);
}

#gameCanvas {
    width: 100%;
    height: auto;
    max-width: min(640px, 90vw);
    display: block;
    border: 2px solid rgba(0, 255, 136, 0.3);
    border-radius: 8px;
    background: #0a0a0a;
    box-shadow: 0 0 30px rgba(0, 255, 136, 0.1);
}

.game-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    width: 100%;
}

.game-controls .btn {
    padding: 10px 24px;
    font-size: 0.9rem;
    max-width: none;
    flex: 1;
    min-width: 100px;
}

/* GAME OVER */
#gameOverScreen {
    z-index: 20;
}

.game-over-content {
    text-align: center;
    animation: slideDown 0.5s ease;
}

.death-reason {
    font-size: 1.2rem;
    color: #ff6b5b;
    margin-bottom: 20px;
    font-weight: 600;
}

.final-score {
    font-size: 1.5rem;
    color: #b0b0b0;
    margin-bottom: 30px;
}

.final-score .label {
    color: #b0b0b0;
}

.final-score #finalScore {
    color: #00ff88;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
    margin-left: 8px;
}

/* RECORDS */
.records-list {
    text-align: left;
    margin-bottom: 30px;
    max-height: 300px;
    overflow-y: auto;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.record-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid rgba(0, 255, 136, 0.2);
    color: #b0b0b0;
}

.record-item:last-child {
    border-bottom: none;
}

.record-name {
    color: #00ff88;
    font-weight: 600;
}

.record-score {
    color: #ffffff;
    font-weight: 700;
}

.no-records {
    color: #888;
    font-style: italic;
}

/* SETTINGS */
.settings-content {
    font-size: 1.1rem;
    color: #b0b0b0;
    margin-bottom: 30px;
}

/* Ensure all children inside settings respect container */
.settings-content *, .settings-content *:before, .settings-content *:after {
    box-sizing: inherit;
    max-width: 100%;
}

/* Generic slider row used for audio and gameplay */
.setting-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    justify-content: space-between;
}

.setting-row label { flex: 0 0 auto; color: #b0b0b0; }
.setting-row input[type="range"] { flex: 1 1 auto; width: 100%; max-width: 100%; }

/* Ensure .btn default doesn't force full width inside rows */
.control-btn { width: auto; max-width: none; }


/* Controls list styling */
.controls-list {
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: min(560px, 92vw);
    padding: 8px;
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255,255,255,0.03);
    padding: 12px 14px;
    border-radius: 10px;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
}

.control-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0; /* allow ellipsis */
    flex: 1 1 auto;
}

.control-name {
    color: #00ff88;
    font-weight: 700;
    margin-right: 8px;
    flex: 0 0 auto;
}

.control-key {
    color: #b0b0b0;
    background: rgba(0,0,0,0.15);
    padding: 6px 10px;
    border-radius: 6px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.control-right {
    flex: 0 0 auto;
    margin-left: 12px;
}

.control-btn {
    min-width: 120px;
    padding: 8px 12px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

@media (max-width: 480px) {
    .control-btn { min-width: 100%; height: 40px; }
    .control-key { max-width: 100%; }
    .control-row { flex-direction: column; align-items: stretch; }
    .control-right { margin-left: 0; }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

.pulse {
    animation: pulse 0.2s ease;
}

/* Адаптив */
@media (max-width: 768px) {
    .title {
        font-size: 2.5rem;
    }

    .card {
        padding: 40px 30px;
    }

    .game-container {
        padding: 20px;
        gap: 15px;
    }

    .game-controls {
        gap: 10px;
    }

    .game-controls .btn {
        padding: 10px 16px;
        font-size: 0.85rem;
    }

    .game-header {
        flex-direction: column;
        gap: 10px;
    }
}

@media (max-width: 480px) {
    .title {
        font-size: 2rem;
        margin-bottom: 25px;
    }

    .card {
        padding: 30px 20px;
    }

    .game-container {
        padding: 15px;
        border-radius: 12px;
    }

    .btn {
        padding: 12px 24px;
        font-size: 0.9rem;
    }

    .game-header {
        font-size: 0.9rem;
    }

    #gameCanvas {
        border-radius: 6px;
    }
}
