body {
    margin: 0;
    overflow: hidden;
    background-color: #111;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Courier New', Arial, sans-serif;
}

#auth-container {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #000;
    gap: 18px;
}

#auth-title {
    font-size: 120px;
    font-weight: bold;
    color: #ff0000;
    text-shadow: 0 0 10px rgba(255, 0, 0, 0.8),
                 0 0 20px rgba(255, 0, 0, 0.5);
    letter-spacing: 8px;
    font-family: "Arial Black", sans-serif;
}

#lang-selector {
    text-align: center;
}

#lang-title {
    color: #ddd;
    font-size: 20px;
    margin-bottom: 14px;
}

.lang-buttons {
    display: flex;
    gap: 14px;
    justify-content: center;
    flex-wrap: wrap;
}

#auth-panel {
    width: min(420px, 90vw);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#auth-subtitle {
    color: #fff;
    font-size: 18px;
    text-align: center;
}

#auth-username,
#auth-password {
    padding: 12px 14px;
    font-size: 18px;
    background: #130909;
    color: #fff;
    border: 2px solid #661111;
    outline: none;
    font-family: inherit;
}

#auth-username:focus,
#auth-password:focus {
    border-color: #ff0000;
}

.auth-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

#auth-status {
    min-height: 24px;
    color: #ffaaaa;
    text-align: center;
    font-size: 14px;
}

.auth-remember {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #ddd;
    font-size: 14px;
    user-select: none;
}

.auth-remember input {
    accent-color: #ff0000;
}

.menu-user-bar {
    position: absolute;
    bottom: max(12px, env(safe-area-inset-bottom, 12px));
    right: max(12px, env(safe-area-inset-right, 12px));
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10;
}

.menu-username {
    color: #ddd;
    font-size: 14px;
    max-width: min(42vw, 220px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.auth-loading {
    color: #aaa;
    font-size: 18px;
    text-align: center;
    margin-top: 16px;
    width: 100%;
}

#menu-container {
    position: relative;
    width: 100%;
    height: 100vh;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #000;
}

#title {
    position: relative;
    font-size: 180px;
    font-weight: bold;
    color: #ff0000;
    text-shadow: 0 0 10px rgba(255, 0, 0, 0.8),
                 0 0 20px rgba(255, 0, 0, 0.5),
                 0 0 30px rgba(255, 0, 0, 0.3);
    animation: flicker 4s infinite;
    font-family: "Arial Black", sans-serif;
    letter-spacing: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#blood-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: 
        radial-gradient(circle at 30% 20%, transparent 0%, #600 20%, transparent 30%),
        radial-gradient(circle at 70% 20%, transparent 0%, #600 15%, transparent 25%),
        radial-gradient(circle at 50% 50%, transparent 0%, #600 10%, transparent 20%);
    opacity: 0.1;
    mix-blend-mode: multiply;
}

/* Кровавые капли для каждой буквы */
#title::before {
    content: 'CAT';
    position: absolute;
    top: 0;
    left: 0;
    background: linear-gradient(180deg, 
        transparent 0%,
        rgba(255, 0, 0, 0.8) 40%,
        rgba(255, 0, 0, 0.9) 60%,
        rgba(128, 0, 0, 1) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    z-index: -1;
}

.letter-container {
    position: relative;
    display: inline-block;
}

.blood-drip {
    position: fixed;
    top: 0;
    width: 3px;
    background: linear-gradient(to bottom, #ff0000, rgba(255, 0, 0, 0.1));
    transform-origin: top;
    opacity: 0;
    animation: drip var(--drip-duration) ease-in var(--drip-delay) infinite;
    pointer-events: none;
    z-index: 1;
}

@keyframes drip {
    0% {
        height: 0;
        opacity: 1;
    }
    70% {
        height: var(--drip-length);
        opacity: 1;
    }
    100% {
        height: var(--drip-length);
        opacity: 0;
    }
}

/* Добавляем кровавые разводы */
#title::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 50%, rgba(255,0,0,0.8) 0%, transparent 20%),
        radial-gradient(circle at 50% 50%, rgba(255,0,0,0.6) 0%, transparent 30%),
        radial-gradient(circle at 80% 50%, rgba(255,0,0,0.7) 0%, transparent 25%);
    filter: blur(10px);
    opacity: 0.3;
    mix-blend-mode: screen;
    pointer-events: none;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-top: 48px;
}

.menu-mode-btn {
    padding: 18px 36px;
    font-size: 22px;
    background: #300;
    color: #fff;
    border: 2px solid #f00;
    cursor: pointer;
    transition: all 0.3s;
    text-shadow: 0 0 10px #f00;
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    font-family: 'Courier New', monospace;
    max-width: 90vw;
}

.menu-mode-btn:hover {
    background: #500;
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(255, 0, 0, 0.5);
}

.menu-mode-btn::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,0,0,0.1) 0%, transparent 70%);
    animation: pulse 2s infinite;
}

#leaderboard-panel {
    position: fixed;
    right: 18px;
    top: 18px;
    width: min(360px, 34vw);
    max-height: calc(100vh - 36px);
    overflow: auto;
    padding: 12px;
    border: 1px solid #aa2222;
    background: rgba(20, 0, 0, 0.75);
    color: #fff;
    z-index: 20;
}

#leaderboard-title {
    font-size: 20px;
    margin-bottom: 8px;
    color: #ffb1b1;
    text-shadow: 0 0 8px rgba(255, 0, 0, 0.35);
}

#leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

#leaderboard-table th,
#leaderboard-table td {
    padding: 4px 6px;
    border-bottom: 1px solid rgba(255, 0, 0, 0.22);
    text-align: left;
}

#leaderboard-table tbody tr.me-row {
    background: rgba(255, 0, 0, 0.16);
}

#leaderboard-me {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 0, 0, 0.45);
    font-size: 14px;
    color: #ffd2d2;
}

#menu-lang-switch {
    position: fixed;
    left: 16px;
    bottom: 16px;
    display: flex;
    gap: 8px;
    z-index: 20;
}

.menu-lang-btn {
    padding: 8px 12px;
    font-size: 13px;
    color: #fff;
    background: #220707;
    border: 1px solid #f00;
    cursor: pointer;
    font-family: inherit;
    text-shadow: 0 0 6px #f00;
}

.menu-lang-btn.active {
    background: #500;
    box-shadow: 0 0 12px rgba(255, 0, 0, 0.45);
}

@keyframes flicker {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.95; }
    25%, 75% { opacity: 0.85; }
}

@keyframes pulse {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#game-container {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: none;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

#game-canvas {
    background-color: #000;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

#vhs-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 100%;
    box-sizing: border-box;
    pointer-events: none;
    opacity: 0.1;
    background: 
        repeating-linear-gradient(0deg, 
            rgba(0,0,0,0.3) 0px, 
            rgba(0,0,0,0.3) 1px, 
            transparent 1px, 
            transparent 2px),
        repeating-linear-gradient(90deg, 
            rgba(0,0,0,0.3) 0px, 
            rgba(0,0,0,0.3) 1px, 
            transparent 1px, 
            transparent 2px);
    mix-blend-mode: overlay;
}

#scanlines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 100%;
    box-sizing: border-box;
    pointer-events: none;
    background: linear-gradient(
        rgba(0, 0, 0, 0) 50%, 
        rgba(0, 0, 0, 0.3) 50%
    );
    background-size: 100% 4px;
}

#assets {
    display: none;
}

.mobile-pet-btn {
    display: none;
    position: fixed;
    bottom: max(16px, env(safe-area-inset-bottom, 16px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    padding: 14px 32px;
    font-size: clamp(16px, 4vw, 22px);
    font-family: inherit;
    color: #fff;
    background: #400;
    border: 2px solid #f00;
    border-radius: 8px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    text-shadow: 0 0 8px #f00;
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.35);
}

/* Погладить — красная кнопка на аркаде; дубль кнопки скрыт */
body.touch-mode .mobile-pet-btn {
    display: none !important;
}

/* Во время скримера дубль «Гладь» поверх экрана (аркадные кнопки не перекрываются оверлеем) */
body.touch-mode.screamer-active .mobile-pet-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    pointer-events: auto;
}

body.touch-mode #game-container {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    /* Стабильная высота вьюпорта: меньше прыжков при появлении/скрытии панелей браузера */
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    padding: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
    overflow: hidden;
}

body.touch-mode .arcade-frame {
    position: relative;
    width: 100% !important;
    max-width: 100vw;
    height: 100% !important;
    min-height: 0;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    margin: 0 !important;
    box-sizing: border-box;
    background: none !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

body.touch-mode .arcade-top,
body.touch-mode .arcade-bottom {
    display: none !important;
}

body.touch-mode .arcade-screen {
    position: absolute;
    inset: 0;
    width: 100% !important;
    max-width: 100%;
    height: 100% !important;
    margin: 0 !important;
    aspect-ratio: unset;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    z-index: 1;
}

/* Затемнение снизу на весь экран (без «шва» от фона только на полоске контролов) */
body.touch-mode .arcade-screen::after {
    background:
        radial-gradient(
            circle at center,
            transparent 0%,
            rgba(0, 0, 0, 0.32) 100%
        ),
        linear-gradient(
            to top,
            rgba(0, 0, 0, 0.28) 0%,
            rgba(0, 0, 0, 0.06) 42%,
            transparent 72%
        );
}

body.touch-mode .arcade-controls {
    position: absolute;
    left: 0;
    right: 0;
    /* Выше низа экрана — удобнее для больших пальцев */
    bottom: max(96px, env(safe-area-inset-bottom, 0px));
    padding: 10px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left)) !important;
    margin: 0 !important;
    border: none !important;
    border-top: none !important;
    display: flex;
    justify-content: space-between;
    /* Колонки сверху: левый джойстик выравнивается по вертикали с LOOK (под кнопками) */
    align-items: flex-start;
    gap: 8px;
    flex-shrink: 0;
    z-index: 20;
    pointer-events: none;
}

body.touch-mode .arcade-controls > .joystick-container:first-child {
    /* Высота ряда кнопок + gap как у .arcade-controls-right — совпадение линии MOVE/LOOK */
    padding-top: calc(58px + 14px);
}

body.touch-mode .arcade-controls .joystick-container {
    gap: 4px !important;
}

body.touch-mode .arcade-controls .joystick {
    width: 108px !important;
    height: 108px !important;
    border-width: 5px !important;
}

body.touch-mode .arcade-controls .joystick .stick {
    width: 40px !important;
    height: 40px !important;
    margin: -20px 0 0 -20px !important;
    border-width: 2px !important;
}

body.touch-mode .arcade-controls .horizontal-joystick {
    width: 156px !important;
    height: 56px !important;
    border-radius: 28px !important;
    border-width: 5px !important;
}

body.touch-mode .arcade-controls .horizontal-joystick::after {
    left: 16px !important;
    right: 16px !important;
}

body.touch-mode .arcade-controls .horizontal-joystick .stick {
    width: 36px !important;
    height: 36px !important;
    margin: -18px 0 0 -18px !important;
}

body.touch-mode .arcade-controls .buttons {
    gap: 14px !important;
}

body.touch-mode .arcade-controls .button {
    width: 58px !important;
    height: 58px !important;
    border-width: 5px !important;
}

body.touch-mode .joystick-label {
    font-size: 10px !important;
    letter-spacing: 0.5px;
}

body.touch-mode .arcade-controls .joystick,
body.touch-mode .arcade-controls .buttons {
    pointer-events: auto;
}

body.touch-mode .joystick-label {
    pointer-events: none;
}

body.touch-mode .arcade-controls .joystick,
body.touch-mode .arcade-controls .button {
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}

body.touch-mode .arcade-screen .stick,
body.touch-mode .horizontal-joystick .stick {
    transition: none;
}