* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: #1a1a1a;
    font-family: 'Courier New', monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: #7fbf3f;
    user-select: none;
}

.game-wrapper {
    background: #2b2b2b;
    padding: 16px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    max-width: 100vw;
}

.company-title {
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 2px;
    color: #7fbf3f;
    text-align: center;
    width: 100%;
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid #3b3b3b;
    text-transform: uppercase;
}

.score-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
}

#btnSound {
    background: #3b3b3b;
    color: #7fbf3f;
    border: 2px solid #5a7a08;
    border-radius: 4px;
    font-size: 14px;
    padding: 2px 8px;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.4;
}

#btnSound.muted {
    opacity: 0.4;
}

canvas {
    background: #8a6a3b;
    border: 3px solid #5a7a08;
    image-rendering: pixelated;
    display: block;
    width: 480px;
    height: 480px;
    max-width: 85vw;
    max-height: 85vw;
}

.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
}

.controls .row {
    display: flex;
    gap: 4px;
}

.controls button {
    width: 48px;
    height: 48px;
    background: #3b3b3b;
    color: #7fbf3f;
    border: 2px solid #5a7a08;
    border-radius: 4px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
}

.controls button:active {
    background: #5a7a08;
    color: #1a1a1a;
}

/* ====== Оверлей (стартовый экран + проигрыш + пауза) ====== */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 14px;
    z-index: 10;
    padding: 20px;
    overflow-y: auto;
}

.overlay.hidden { display: none; }

#overlay-text {
    font-size: 22px;
    letter-spacing: 2px;
    color: #7fbf3f;
    text-align: center;
}

#btnRestart,
#btnStart {
    padding: 12px 24px;
    background: #3b3b3b;
    color: #7fbf3f;
    border: 2px solid #5a7a08;
    font-size: 16px;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    letter-spacing: 1px;
    border-radius: 4px;
}

#btnRestart:hover,
#btnStart:hover {
    background: #5a7a08;
    color: #1a1a1a;
}

/* ====== Стартовый экран: ввод имени ====== */
.overlay-sub {
    font-size: 16px;
    color: #9bbc0f;
    letter-spacing: 2px;
    margin-top: -6px;
}

.name-label {
    font-size: 14px;
    color: #7fbf3f;
    letter-spacing: 1px;
    margin-top: 4px;
}

#nameInput {
    width: 240px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 16px;
    background: #1a1a1a;
    color: #7fbf3f;
    border: 2px solid #5a7a08;
    border-radius: 4px;
    text-align: center;
    letter-spacing: 1px;
    outline: none;
}

#nameInput:focus {
    border-color: #9bbc0f;
    box-shadow: 0 0 8px rgba(155, 188, 15, 0.4);
}

/* ====== Экран проигрыша ====== */
.overlay-score {
    font-size: 18px;
    color: #ffd700;
    letter-spacing: 1px;
}

.overlay-player {
    font-size: 13px;
    color: #9bbc0f;
    letter-spacing: 1px;
    margin-top: -6px;
}

.overlay-error {
    font-size: 12px;
    color: #ff6b6b;
    margin-top: -4px;
}

.overlay-lb-title {
    font-size: 15px;
    color: #7fbf3f;
    letter-spacing: 2px;
    margin-bottom: 2px;
}

/* ====== Таблица лидеров ====== */
.leaderboard {
    background: #1a1a1a;
    border: 2px solid #3b3b3b;
    border-radius: 6px;
    padding: 10px 14px;
    min-width: 280px;
    max-width: 90vw;
    max-height: 40vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.lb-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 13px;
    color: #9bbc0f;
    letter-spacing: 0.5px;
    padding: 3px 6px;
    border-radius: 3px;
}

.lb-row.lb-current {
    background: rgba(155, 188, 15, 0.15);
    color: #ffd700;
    font-weight: bold;
}

.lb-pos {
    color: #5a7a08;
    min-width: 24px;
}

.lb-name {
    flex: 1;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-score {
    color: #7fbf3f;
    font-weight: bold;
    min-width: 40px;
    text-align: right;
}

/* ====== Мобильная адаптация ====== */
@media (max-width: 600px) {
    .game-wrapper {
        padding: 10px;
        gap: 6px;
    }
    .company-title {
        font-size: 12px;
        letter-spacing: 1px;
        padding-bottom: 6px;
    }
    .score-bar {
        font-size: 12px;
    }
    .controls button {
        width: 56px;
        height: 56px;
        font-size: 20px;
    }
    #overlay-text {
        font-size: 18px;
    }
    .leaderboard {
        min-width: 240px;
        padding: 8px 10px;
    }
    .lb-row {
        font-size: 12px;
    }
    #nameInput {
        width: 200px;
        font-size: 14px;
    }
}