* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: manipulation;
    user-select: none;
}

body {
    overflow: hidden;
    background: #0a1230;
    font-family: 'Arial Rounded MT Bold', 'Arial', sans-serif;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

#gameContainer {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
}

#uiContainer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 10px;
    pointer-events: none;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

#timeDisplay {
    font-size: 28px;
    font-weight: bold;
    color: #B3E5FC;
    text-shadow: 0 0 8px rgba(0,0,0,0.7);
}

#scoreDisplay {
    font-size: 32px;
    font-weight: bold;
    text-align: right;
    color: #FFD700;
    text-shadow: 0 0 8px rgba(0,0,0,0.7);
}

#speedDisplay {
    font-size: 24px;
    text-align: right;
    color: #FF9800;
    text-shadow: 0 0 6px rgba(0,0,0,0.7);
    display: none;
}

#comboDisplay {
    font-size: 20px;
    text-align: right;
    color: #FF4081;
    text-shadow: 0 0 6px rgba(0,0,0,0.7);
    opacity: 0;
    transition: opacity 0.5s;
}

#controlsInfo {
    position: absolute;
    bottom: 30px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 20px;
    color: #FFEB3B;
    text-shadow: 0 0 6px rgba(0,0,0,0.7);
    background: rgba(0,0,0,0.3);
    padding: 10px;
    border-radius: 15px;
    max-width: 100%;
    margin: 0 auto;
    transition: opacity 1s;
}

#assistHint {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 24px;
    font-weight: bold;
    color: #FFF;
    background: rgba(0, 0, 0, 0.55);
    border: 2px solid #FFEB3B;
    padding: 12px 25px;
    border-radius: 15px;
    white-space: nowrap;
    display: none;
    z-index: 15;
    animation: hintPulse 1s infinite;
    pointer-events: none;
}

@keyframes hintPulse {
    0% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.08); }
    100% { transform: translateX(-50%) scale(1); }
}

/* ---------- Лоадер ---------- */

#loaderScreen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(160deg, #0a1230, #123a2e);
    z-index: 60;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 18px;
}

#loaderTitle {
    font-family: Impact, 'Arial Black', sans-serif;
    font-size: clamp(40px, 9vw, 84px);
    letter-spacing: 5px;
    text-transform: uppercase;
    color: #ECEFF1;
    filter: drop-shadow(3px 4px 0 rgba(136, 14, 79, 0.9));
}

#loaderBarBox {
    width: min(340px, 70vw);
    height: 18px;
    border: 2px solid rgba(255,255,255,0.55);
    border-radius: 10px;
    overflow: hidden;
    background: rgba(255,255,255,0.12);
}

#loaderBarFill {
    display: block;
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #FF9800, #FFEB3B);
    transition: width 0.2s;
}

#loaderStatus {
    font-size: 16px;
    color: #B3E5FC;
}

/* ---------- Баннер нового рекорда ---------- */

#recordBanner {
    position: absolute;
    top: 12%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 35; /* поверх затемнения экрана смерти */
    font-family: Impact, 'Arial Black', sans-serif;
    font-size: clamp(20px, 5.5vw, 40px);
    letter-spacing: 2px;
    white-space: nowrap;
    color: #FFD700;
    text-shadow: 3px 3px 0 rgba(0,0,0,0.9), 0 0 18px rgba(255, 215, 0, 0.65);
    display: none;
    pointer-events: none;
    animation: recordPulse 0.9s ease-in-out infinite;
}

@keyframes recordPulse {
    0% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.14); }
    100% { transform: translateX(-50%) scale(1); }
}

/* ---------- Пауза ---------- */

#pauseBtn {
    pointer-events: auto;
    cursor: pointer;
    font-size: 26px;
    line-height: 1;
    margin-top: 6px;
    opacity: 0.75;
    text-shadow: 0 0 8px rgba(0,0,0,0.7);
    display: none; /* показывается только в игре */
    width: fit-content;
}

#pauseBtn:hover {
    opacity: 1;
}

#pauseScreen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 25;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* ---------- Меню в стиле Contra ---------- */

#menuRoot {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 30;
    display: none;
    flex-direction: column;
}

.menuScreen {
    display: none;
    flex: 1;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 0px;
    text-align: center;
    overflow-y: auto;
    position: relative;
    display: none;
}
.menuScreen #title span {
    display: none;
}
.menuScreen #title img {
    max-width: 20vw;
    filter: contrast(1.1) brightness(0.9);
}

.menuScreen.active {
    display: flex;
}

#title {
    font-family: Impact, 'Arial Black', sans-serif;
    font-size: clamp(56px, 10vw, 120px);
    line-height: 0.95;
    letter-spacing: 5px;
    text-transform: uppercase;
    color: #ECEFF1;
    filter: drop-shadow(4px 5px 0 rgba(136, 14, 79, 0.9)) drop-shadow(0 0 20px rgba(0,0,0,0.7));
    margin-bottom: 6vh;
}

@supports (-webkit-background-clip: text) or (background-clip: text) {
    #title {
        background: linear-gradient(180deg, #FFFFFF 0%, #E8EAF6 30%, #90A4AE 48%, #ECEFF1 56%, #607D8B 100%);
        -webkit-background-clip: text;
        background-clip: text;
        color: transparent;
    }
}

.menuHeader {
    font-family: Impact, 'Arial Black', sans-serif;
    font-size: 34px;
    letter-spacing: 5px;
    text-transform: uppercase;
    color: #FF9800;
    text-shadow: 3px 3px 0 rgba(0,0,0,0.85);
    margin-bottom: 10px;
}

.menuHint {
    /* Фиксированная высота: смена текста подсказки не сдвигает пункты ниже */
    height: 62px;
    flex-shrink: 0;
    overflow: hidden;
    font-size: 15px;
    line-height: 1.35;
    color: #B3E5FC;
    max-width: min(620px, 92vw);
    margin-bottom: 10px;
    text-shadow: 1px 1px 2px #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menuList {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.menuItem {
    position: relative;
    font-family: Impact, 'Arial Black', sans-serif;
    font-size: 30px;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: #E0E0E0;
    text-shadow: 3px 3px 0 rgba(0,0,0,0.85);
    padding: 12px 20px 12px;
    cursor: pointer;
    white-space: nowrap;
}

.menuItem.focused {
    color: #FFEB3B;
}

.menuItem.focused::before {
    content: '➤';
    position: absolute;
    left: -20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8em;
    color: #FF9800;
    text-shadow: 0 0 10px rgba(255, 152, 0, 0.9);
    animation: cursorBlink 0.8s steps(2) infinite;
}

.menuItem[data-action="installApp"] {
    font-size: 1em;
}

@keyframes cursorBlink {
    0% { opacity: 1; }
    50% { opacity: 0.25; }
    100% { opacity: 1; }
}

.menuItem.menuBack {
    font-size: 22px;
    margin-top: 14px;
    color: #B0BEC5;
}

.menuItem.menuBack:last-child {
    margin-top: 0;
}

.menuItem.menuBack.focused {
    color: #FFEB3B;
}

#menuFooter {
    position: absolute;
    bottom: 3vh;
    left: 0;
    width: 100%;
    font-size: 14px;
    color: rgba(255,255,255,0.75);
    text-shadow: 1px 1px 2px #000;
    pointer-events: none;
}

/* Строки настроек */

.settingsList {
    /* Список вырос (вибрация, режим окна, установка) — на низких экранах скроллим */
    max-height: 66vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 1;
}

.settingsList .menuItem.setting {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    width: min(640px, 94vw);
    font-size: 20px;
    letter-spacing: 2px;
    white-space: nowrap;
    padding: 4px 12px;
}

.setName {
    text-align: left;
}

/* Чекбоксы на экране вибрации */
.vibToggle {
    display: flex;
    align-items: center;
    gap: 14px;
}

.vibBox {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    border: 3px solid rgba(255, 255, 255, 0.75);
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
}

.vibToggle.on .vibBox {
    border-color: #69F0AE;
    color: #69F0AE;
}

.vibToggle.on .vibBox::after {
    content: '✓';
}

.setControl {
    display: flex;
    align-items: center;
    gap: 8px;
}

.adjArrow {
    font-size: 34px;
    line-height: 1;
    padding: 0 12px;
    color: #FF9800;
    cursor: pointer;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.85);
    position: relative;
    top: -3px;
}

.adjArrow:hover {
    color: #FFEB3B;
}

.adjArrow:active {
    transform: scale(0.85);
}

.setValue {
    color: #FFF;
    font-size: 18px;
    letter-spacing: 1px;
}

.setValue.num {
    min-width: 30px;
    text-align: center;
}

/* Название трека: обычный шрифт с разрядкой — Impact слипается */
.setValue.trackName {
    font-family: Arial, sans-serif;
    font-weight: bold;
    font-size: 14px;
    max-width: 210px;
    white-space: normal;
    line-height: 1.25;
    letter-spacing: 1.5px;
}

.volBar {
    width: 110px;
    height: 14px;
    background: rgba(255,255,255,0.18);
    border: 2px solid rgba(255,255,255,0.55);
    border-radius: 3px;
    overflow: hidden;
}

.volFill {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #FF9800, #FFEB3B);
}

/* Ползунок цвета шарика — радуга по оттенкам */
.hueBar .volFill {
    background: linear-gradient(90deg,
        hsl(0, 80%, 55%), hsl(60, 80%, 55%), hsl(120, 80%, 55%),
        hsl(180, 80%, 55%), hsl(240, 80%, 55%), hsl(300, 80%, 55%), hsl(360, 80%, 55%));
}

/* ---------- Достижения ---------- */

#achToasts {
    position: fixed;
    top: 125px; /* ниже очков и комбо — не перекрывает их */
    right: 12px;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.achToast {
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(180deg, rgba(40, 30, 5, 0.95), rgba(20, 15, 0, 0.95));
    border: 2px solid #FFD700;
    border-radius: 12px;
    padding: 10px 14px;
    max-width: min(320px, 80vw);
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.45s ease, opacity 0.45s;
    box-shadow: 0 4px 18px rgba(0,0,0,0.6), 0 0 14px rgba(255, 215, 0, 0.35);
}

.achToast.show {
    transform: translateX(0);
    opacity: 1;
}

.achToast .achIcon {
    font-size: 28px;
}

.achToast .achText b {
    display: block;
    font-size: 15px;
    color: #FFD700;
}

.achToast .achText i {
    display: block;
    font-size: 12px;
    font-style: normal;
    color: #E0E0E0;
}

#achBox {
    width: min(560px, 92vw);
    max-height: 56vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 14px;
    padding: 10px 16px;
    margin-bottom: 10px;
}

.achRow {
    display: flex;
    align-items: center;
    gap: 14px;
    text-align: left;
    padding: 8px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    opacity: 0.45;
    filter: grayscale(0.9);
}

.achRow:last-child {
    border-bottom: none;
}

.achRow.unlocked {
    opacity: 1;
    filter: none;
}

.achRow .achIcon {
    font-size: 26px;
    width: 34px;
    text-align: center;
    flex-shrink: 0;
}

.achRow .achText b {
    display: block;
    font-size: 16px;
    color: #FFEB3B;
}

.achRow.unlocked .achText b {
    color: #FFD700;
}

.achRow .achText i {
    display: block;
    font-size: 13px;
    font-style: normal;
    color: #B0BEC5;
}

/* ---------- Таблица лидеров ---------- */

.lbTabRow {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.lbTab {
    font-size: 14px;
    letter-spacing: 1px;
    padding: 5px 12px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 20px;
    color: #B0BEC5;
    cursor: pointer;
    text-shadow: 1px 1px 2px #000;
    user-select: none;
}

.lbTab:hover {
    color: #FFF;
    border-color: rgba(255,255,255,0.6);
}

.lbTab.active {
    color: #FFEB3B;
    border-color: #FF9800;
    background: rgba(255, 152, 0, 0.15);
}

/* Своя строка в топе */
.leaderRow.me {
    background: rgba(255, 215, 0, 0.14);
    border-left: 3px solid #FFD700;
    padding-left: 6px;
    border-radius: 6px;
}

.lrSep {
    text-align: center;
    color: #78909C;
    padding: 2px 0;
    letter-spacing: 4px;
}

#leadersBox {
    width: min(560px, 92vw);
    max-height: 56vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 14px;
    padding: 12px 16px;
    margin-bottom: 10px;
}

#leadersList {
    font-size: 17px;
}

.leaderRow {
    display: flex;
    gap: 12px;
    padding: 7px 4px;
    align-items: baseline;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.leaderRow:last-child {
    border-bottom: none;
}

.lrPos {
    width: 36px;
    flex-shrink: 0;
    color: #90A4AE;
    font-weight: bold;
}

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

.lrTime {
    flex-shrink: 0;
    color: #B3E5FC;
    font-size: 0.85em;
}

.lrScore {
    min-width: 52px;
    text-align: right;
    flex-shrink: 0;
    color: #FFD700;
    font-weight: bold;
}

.leaderRow.top1 { font-size: 19px; }
.leaderRow.top1 .lrPos { color: #FFD700; }
.leaderRow.top2 .lrPos { color: #E0E0E0; }
.leaderRow.top3 .lrPos { color: #FF8A65; }

/* Кнопки серверного реплея в строке топа: ▶ смотреть, ⚔ бросить вызов */
.lrBtn {
    flex-shrink: 0;
    padding: 2px 6px;
    color: #FF9800;
    cursor: pointer;
    font-weight: bold;
}

.lrBtn:hover {
    color: #FFEB3B;
}

/* Ввод имени на экране Game Over */

#nameEntry {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

#nameInput {
    font-family: inherit;
    font-size: 20px;
    text-align: center;
    letter-spacing: 1px;
    background: rgba(0, 0, 0, 0.45);
    color: #FFF;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    padding: 10px 16px;
    width: min(320px, 80vw);
    outline: none;
    user-select: text;
}

#nameInput:focus {
    border-color: #FFEB3B;
}

#saveStatus {
    min-height: 20px;
    font-size: 14px;
    color: #B3E5FC;
    text-shadow: 1px 1px 2px #000;
    max-width: 90vw;
}

/* ---------- Реплеи ---------- */

#replaysBox {
    width: min(640px, 94vw);
    max-height: 52vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 14px;
    padding: 10px 14px;
    margin-bottom: 10px;
}

#replaysList {
    font-size: 17px;
}

.replayRow {
    display: flex;
    gap: 10px;
    padding: 8px 4px;
    align-items: baseline;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
}

.replayRow:hover {
    background: rgba(255, 255, 255, 0.06);
}

.replayRow:last-child {
    border-bottom: none;
}

.rpMode {
    flex-shrink: 0;
    width: 28px;
    text-align: center;
}

.rpDate {
    flex-shrink: 0;
    color: #90A4AE;
    font-size: 0.85em;
}

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

.rpTime {
    flex-shrink: 0;
    color: #B3E5FC;
    font-size: 0.85em;
}

.rpScore {
    min-width: 52px;
    text-align: right;
    flex-shrink: 0;
    color: #FFD700;
    font-weight: bold;
}

.rpBtn {
    flex-shrink: 0;
    padding: 2px 8px;
    color: #FF9800;
    cursor: pointer;
    font-weight: bold;
}

.rpBtn:hover {
    color: #FFEB3B;
}

.rpBtn.rpDel {
    color: #EF9A9A;
}

.rpBtn.rpDel:hover {
    color: #FF5252;
}

/* ---------- Онлайн ---------- */

#netCodeEntry {
    margin: 6px 0 2px;
}

#netCodeInput {
    font-family: inherit;
    font-size: 20px;
    text-align: center;
    letter-spacing: 3px;
    text-transform: uppercase;
    background: rgba(0, 0, 0, 0.45);
    color: #FFF;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    padding: 8px 12px;
    width: 240px;
    outline: none;
    user-select: text;
}

#netCodeInput:focus {
    border-color: #FFEB3B;
}

#netStatusEl {
    color: #FFEB3B;
}

/* Панель управления просмотром реплея */

#replayBar {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 15;
    display: none;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.55);
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 14px;
    padding: 6px 12px;
    max-width: 94vw;
}

#rpBarLabel {
    font-size: 16px;
    color: #B3E5FC;
    margin-right: 8px;
    max-width: 44vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rpBarBtn {
    font-size: 22px;
    line-height: 1;
    padding: 8px 12px;
    color: #FF9800;
    cursor: pointer;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.85);
}

.rpBarBtn:hover {
    color: #FFEB3B;
}

.rpBarBtn:active {
    transform: scale(0.9);
}

/* ---------- Экран Game Over ---------- */

#gameOverScreen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
    display: none;
}

#finalScore {
    font-size: 52px;
    font-weight: bold;
    margin-bottom: 16px;
    color: #FFD700;
    text-shadow: 0 0 12px rgba(255, 215, 0, 0.7);
}

#finalTime {
    font-size: 30px;
    margin-bottom: 8px;
    color: #B3E5FC;
    text-shadow: 0 0 8px rgba(0,0,0,0.7);
}

#finalDist {
    font-size: 20px;
    margin-bottom: 30px;
    color: #B3E5FC;
    opacity: 0.9;
    text-shadow: 0 0 8px rgba(0,0,0,0.7);
}

/* ---------- Широкие экраны (landscape): шарик висит справа ---------- */

@media (min-aspect-ratio: 1/1) {
    /* Сдвигаем колонку меню чуть левее, чтобы не пересекаться с шариком */
    .menuScreen {
        padding-right: 0vw;
    }

    #menuFooter {
        padding-right: 0vw;
    }
}

/* ---------- Мобильная (портретная) верстка ---------- */

@media (max-aspect-ratio: 1/1) {
    /* Сверху оставляем место под шарик на веревке */
    #screenMain {
        justify-content: flex-start;
        padding-top: 30vh;
    }

    #title {
        font-size: clamp(44px, 14vw, 76px);
        margin-bottom: 5vh;
    }

    .menuItem {
        font-size: 24px;
        padding: 10px 16px 10px;
    }

    .menuHeader {
        font-size: 28px;
    }

    .menuScreen #title img {
        max-width: 60vw;
    }

    .settingsList .menuItem.setting {
        font-size: 15px;
        letter-spacing: 1px;
        padding: 0px 6px 0px;
        gap: 8px;
    }

    .adjArrow {
        font-size: 30px;
        padding: 0 8px;
    }

    .volBar {
        width: 64px;
    }

    .setValue {
        font-size: 15px;
    }

    .setValue.trackName {
        font-size: 11px;
        max-width: 110px;
    }

    #finalScore {
        font-size: 42px;
    }

    /* Реплеи: на узком экране дата не влезает */
    #replaysList {
        font-size: 14px;
    }

    .rpDate {
        display: none;
    }

    #controlsInfo {
        font-size: 16px;
    }

    #assistHint {
        font-size: 17px;
        white-space: normal;
        text-align: center;
        max-width: 90vw;
    }
}
