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

html,
body {
    height: 100%;
}

body {
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    font-family: 'Courier New', Courier, monospace;
    color: #fff;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

#game-container {
    position: relative;
    line-height: 0;
    width: min(100vw, calc(100vh * 4 / 3));
    max-width: 800px;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    background: #0A0A0A;
    image-rendering: pixelated;
    cursor: crosshair;
    touch-action: none;
}

/* ---------------------------------------------------------------- overlay */
#overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.4;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(2px);
}

#overlay.hidden {
    display: none;
}

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    text-align: center;
    padding: 24px;
    width: 100%;
}

.screen.active {
    display: flex;
}

h1 {
    font-size: 72px;
    letter-spacing: 12px;
    font-weight: 700;
}

h2 {
    font-size: 26px;
    letter-spacing: 3px;
    font-weight: 700;
}

.tagline,
.hint {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.62);
}

.error {
    font-size: 14px;
    color: #ff6b6b;
    min-height: 18px;
}

/* ---------------------------------------------------------------- controls */
.btn {
    appearance: none;
    border: 2px solid rgba(255, 255, 255, 0.8);
    background: transparent;
    color: #fff;
    font-family: inherit;
    font-size: 18px;
    letter-spacing: 2px;
    padding: 12px 28px;
    min-width: 300px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn:active {
    transform: scale(0.98);
}

.btn.primary {
    background: #fff;
    color: #000;
    border-color: #fff;
}

.btn.primary:hover {
    background: rgba(255, 255, 255, 0.85);
}

.btn[hidden] {
    display: none;
}

.link {
    appearance: none;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.66);
    font-family: inherit;
    font-size: 15px;
    padding: 6px 4px;
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.15s, text-shadow 0.15s;
}

.link:hover {
    color: #fff;
    text-shadow: 0 0 12px rgba(124, 252, 158, 0.5);
}

#code-input {
    width: 260px;
    padding: 12px;
    margin-bottom: 4px;
    background: rgba(255, 255, 255, 0.06);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    font-family: inherit;
    font-size: 38px;
    letter-spacing: 16px;
    text-align: center;
    text-transform: uppercase;
    caret-color: #7CFC9E;
    outline: none;
}

#code-input:focus {
    border-color: #7CFC9E;
}

#room-code {
    font-size: 64px;
    letter-spacing: 18px;
    padding: 8px 0 8px 18px;
    color: #7CFC9E;
    text-shadow: 0 0 24px rgba(124, 252, 158, 0.35);
}

.waiting {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    color: rgba(255, 255, 255, 0.75);
}

.pulse {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #7CFC9E;
    animation: pulse 1.1s ease-in-out infinite;
}

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

.keys-hint {
    margin-top: 6px;
}

/* подсказка про поворот экрана — показывается только в портрете на телефоне */
#rotate-hint {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    bottom: -32px;
    text-align: center;
    font-size: 13px;
    line-height: 1.3;
    color: rgba(255, 255, 255, 0.45);
    pointer-events: none;
}

@media (orientation: portrait) and (max-width: 900px) {
    #rotate-hint {
        display: block;
    }
}

@media (max-width: 840px) {
    #game-container {
        max-width: none;
    }
}

@media (max-width: 520px) {
    .screen {
        padding: 12px;
        gap: 10px;
    }

    h1 {
        font-size: 44px;
        letter-spacing: 8px;
    }

    h2 {
        font-size: 20px;
        letter-spacing: 2px;
    }

    .btn {
        min-width: 230px;
        font-size: 16px;
        padding: 12px 18px;
    }

    #code-input {
        width: 210px;
        font-size: 30px;
        letter-spacing: 10px;
    }

    #room-code {
        font-size: 46px;
        letter-spacing: 12px;
        padding-left: 12px;
    }

    .tagline,
    .hint {
        font-size: 13px;
    }
}
