/* ============================================
   GERAND TANKS BATTLE - Стили
   Мобильная танковая игра для детей 5+
   ============================================ */

/* --- Базовые стили и сброс --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(180deg, #87CEEB 0%, #E0F6FF 100%);
    touch-action: none;
}

.hidden {
    display: none !important;
}

/* --- Экраны --- */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 100vw;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
}

.screen.active {
    display: flex;
}

.screen.overlay {
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    backdrop-filter: blur(4px);
}

/* --- Стартовый экран --- */
#startScreen {
    background:
        linear-gradient(180deg, rgba(110, 214, 255, 0.95) 0%, rgba(201, 244, 255, 0.94) 46%, rgba(137, 201, 110, 0.96) 47%, rgba(58, 126, 67, 0.98) 100%);
    width: 100vw;
    max-width: 100vw;
    padding: max(18px, env(safe-area-inset-top)) 20px max(18px, env(safe-area-inset-bottom));
    text-align: center;
    gap: 14px;
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
}

#startScreen > * {
    width: min(100%, calc(100vw - 40px));
    max-width: 760px;
    min-width: 0;
    flex: 0 0 auto;
}

.logo {
    margin-bottom: 4px;
    animation: float 3s ease-in-out infinite;
}

.tank-icon {
    font-size: 62px;
    margin-bottom: 8px;
}

.logo h1 {
    color: #1f3f2a;
    font-size: clamp(30px, 5.8vw, 48px);
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.55),
                 2px 3px 0 rgba(0, 0, 0, 0.16);
    letter-spacing: 0;
    font-weight: 900;
}

.subtitle {
    color: #9b2f24;
    font-size: 18px;
    margin-top: 5px;
    letter-spacing: 0;
    text-transform: uppercase;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.player-setup {
    width: min(100%, 560px);
    max-width: 100%;
    padding: 16px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.34);
    box-shadow: 0 10px 28px rgba(28, 74, 60, 0.18);
    backdrop-filter: blur(8px);
}

.setup-title {
    margin-bottom: 4px;
    color: #1d3b29;
    font-size: 20px;
    font-weight: 900;
}

.setup-subtitle {
    margin-bottom: 12px;
    color: rgba(31, 63, 42, 0.82);
    font-size: 13px;
    font-weight: 800;
    max-width: 100%;
    overflow-wrap: anywhere;
}

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

.name-field {
    display: grid;
    gap: 6px;
    text-align: left;
    color: #1f3f2a;
    font-size: 13px;
    font-weight: 900;
}

.name-field span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.name-field span::before {
    content: "";
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.65);
}

.name-field-blue span::before {
    background: #4169e1;
}

.name-field-red span::before {
    background: #dc143c;
}

.name-field input {
    min-width: 0;
    min-height: 56px;
    width: 100%;
    border: 3px solid rgba(31, 63, 42, 0.24);
    border-radius: 8px;
    padding: 0 16px;
    background: rgba(255, 255, 255, 0.94);
    color: #183221;
    font-size: 20px;
    font-weight: 800;
    outline: none;
    user-select: text;
    -webkit-user-select: text;
}

.name-field input:focus {
    border-color: #1e9f66;
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(30, 159, 102, 0.18);
}

.setup-hint,
.auth-hint,
.landscape-note {
    margin-top: 10px;
    color: rgba(31, 63, 42, 0.78);
    font-size: 12px;
    font-weight: 800;
}

.landscape-note {
    margin-top: 0;
    padding: 6px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.3);
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* --- Кнопки меню --- */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 560px;
}

.menu-btn {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 16px 24px;
    border: none;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
    text-align: left;
    width: 100%;
}

.menu-btn:active {
    transform: scale(0.95);
}

.menu-btn.primary {
    background: linear-gradient(135deg, #1e9f66 0%, #1677b9 100%);
    box-shadow: 0 4px 15px rgba(22, 119, 185, 0.35);
}

.menu-btn.primary:hover {
    box-shadow: 0 6px 20px rgba(22, 119, 185, 0.45);
    transform: translateY(-2px);
}

.menu-btn.secondary {
    background: linear-gradient(135deg, #f39c12 0%, #d35400 100%);
    box-shadow: 0 4px 15px rgba(211, 84, 0, 0.35);
}

.menu-btn.secondary:hover {
    box-shadow: 0 6px 20px rgba(211, 84, 0, 0.45);
    transform: translateY(-2px);
}

.btn-icon {
    font-size: 28px;
}

.btn-text {
    line-height: 1.3;
}

.btn-text small {
    font-size: 13px;
    opacity: 0.8;
    font-weight: 400;
}

/* --- Магазин танков --- */
.tank-shop {
    width: min(100%, 760px);
    max-width: 100%;
    min-width: 0;
    padding: 14px;
    border: 2px solid rgba(31, 63, 42, 0.22);
    border-radius: 8px;
    background:
        linear-gradient(180deg, rgba(247, 255, 247, 0.78), rgba(213, 235, 190, 0.78)),
        linear-gradient(90deg, rgba(42, 79, 62, 0.14) 0 1px, transparent 1px 100%);
    background-size: auto, 28px 100%;
    box-shadow: 0 12px 28px rgba(28, 74, 60, 0.18);
    backdrop-filter: blur(8px);
}

.hangar-shop {
    display: grid;
    gap: 10px;
}

.shop-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    text-align: left;
    min-width: 0;
}

.shop-head > div {
    min-width: 0;
}

.shop-head .setup-subtitle {
    margin-bottom: 0;
}

.shop-badge {
    flex: 0 0 auto;
    padding: 6px 9px;
    border-radius: 8px;
    background: rgba(30, 159, 102, 0.16);
    color: #145c3d;
    font-size: 12px;
    font-weight: 900;
}

.shop-player-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    min-width: 0;
}

.shop-tab {
    min-height: 42px;
    border: 2px solid rgba(31, 63, 42, 0.18);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.58);
    color: #1f3f2a;
    font-size: 15px;
    font-weight: 900;
    cursor: pointer;
    transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.shop-tab:active {
    transform: scale(0.97);
}

.shop-tab.active {
    border-color: var(--active-player-color, #4169e1);
    background: #ffffff;
    box-shadow: inset 0 -4px 0 var(--active-player-color, #4169e1), 0 8px 18px rgba(31, 63, 42, 0.12);
}

.hangar-stage {
    display: grid;
    grid-template-columns: minmax(0, 1.18fr) minmax(210px, 0.82fr);
    gap: 12px;
    align-items: stretch;
    min-width: 0;
    padding: 12px;
    border: 2px solid rgba(31, 63, 42, 0.14);
    border-radius: 8px;
    background:
        radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.82), transparent 34%),
        linear-gradient(180deg, rgba(166, 213, 232, 0.84) 0 50%, rgba(103, 143, 76, 0.9) 51% 100%);
    box-shadow: inset 0 -18px 0 rgba(44, 69, 43, 0.12);
    overflow: hidden;
}

.hangar-preview {
    position: relative;
    min-height: 134px;
    border-radius: 8px;
    background:
        linear-gradient(180deg, transparent 0 64%, rgba(31, 63, 42, 0.18) 65% 67%, transparent 68%),
        radial-gradient(ellipse at 50% 82%, rgba(0, 0, 0, 0.22), transparent 48%);
    overflow: hidden;
}

.hangar-preview::before,
.hangar-preview::after {
    content: "";
    position: absolute;
    bottom: 23px;
    width: 74px;
    height: 34px;
    border: 2px solid rgba(31, 63, 42, 0.24);
    border-bottom: 0;
}

.hangar-preview::before {
    left: 12px;
    transform: skewX(-12deg);
}

.hangar-preview::after {
    right: 12px;
    transform: skewX(12deg);
}

.hangar-tank-preview {
    position: absolute;
    left: 50%;
    bottom: 16px;
    width: min(92%, 330px);
    height: 110px;
    margin: 0;
    transform: translateX(-50%);
    filter: drop-shadow(0 13px 8px rgba(0, 0, 0, 0.2));
    overflow: visible;
}

.hangar-tank-preview::before {
    left: 5%;
    right: 8%;
    bottom: 20px;
    height: 38px;
    border-width: 3px;
    border-radius: 10px 22px 8px 12px;
}

.hangar-tank-preview::after {
    left: 33%;
    bottom: 58px;
    width: 30%;
    height: 31px;
    border-width: 3px;
    border-radius: 10px 10px 6px 6px;
}

.hangar-tank-preview .preview-track {
    left: 2%;
    right: 3%;
    bottom: 0;
    height: 24px;
    border-width: 3px;
    background: repeating-linear-gradient(90deg, #171d22 0 13px, #4b5660 13px 22px);
}

.hangar-tank-preview .preview-turret {
    left: 56%;
    bottom: 72px;
    width: 42%;
    height: 12px;
    border-width: 3px;
}

.hangar-info {
    display: grid;
    align-content: center;
    gap: 6px;
    min-width: 0;
    text-align: left;
    color: #183221;
}

.hangar-player-label {
    width: fit-content;
    max-width: 100%;
    padding: 4px 8px;
    border-radius: 8px;
    background: var(--active-player-color, #4169e1);
    color: #fff;
    font-size: 11px;
    font-weight: 900;
}

.hangar-info h2 {
    font-size: clamp(22px, 4vw, 34px);
    line-height: 1;
}

.hangar-info p {
    color: rgba(24, 50, 33, 0.74);
    font-size: 13px;
    font-weight: 800;
}

.tank-stats {
    display: grid;
    gap: 6px;
    margin-top: 4px;
}

.tank-stat {
    display: grid;
    grid-template-columns: 52px 48px minmax(0, 1fr);
    gap: 7px;
    align-items: center;
    font-size: 11px;
    font-weight: 900;
}

.tank-stat span {
    color: rgba(24, 50, 33, 0.72);
}

.tank-stat strong {
    color: #183221;
    font-size: 11px;
}

.tank-stat i {
    display: block;
    height: 8px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--active-player-color, #4169e1), rgba(255, 255, 255, 0.7));
    box-shadow: inset 0 0 0 1px rgba(31, 63, 42, 0.12);
}

.shop-columns {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
    min-width: 0;
    overflow: hidden;
}

.shop-player {
    display: grid;
    gap: 8px;
    text-align: left;
    min-width: 0;
}

.shop-player h2 {
    font-size: 13px;
    color: #1f3f2a;
    font-weight: 900;
}

.tank-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    min-width: 0;
}

.hangar-options {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.tank-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 112px;
    border: 3px solid rgba(31, 63, 42, 0.16);
    border-radius: 8px;
    padding: 9px;
    background: rgba(255, 255, 255, 0.72);
    color: #183221;
    text-align: left;
    cursor: pointer;
    transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
    overflow: hidden;
}

.tank-card:active {
    transform: scale(0.97);
}

.tank-card.selected {
    border-color: var(--player-color, #1e9f66);
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.42), 0 8px 18px rgba(28, 74, 60, 0.18);
}

.tank-card.selected .tank-title::after {
    content: " выбран";
    color: var(--player-color, #1e9f66);
    font-size: 10px;
}

.tank-preview {
    display: block;
    position: relative;
    height: 40px;
    margin-bottom: 7px;
    max-width: 100%;
    overflow: hidden;
}

.tank-preview::before,
.tank-preview::after,
.tank-preview .preview-turret,
.tank-preview .preview-track {
    content: "";
    position: absolute;
    display: block;
}

.tank-preview::before {
    left: 7%;
    right: 11%;
    bottom: 6px;
    height: 18px;
    border: 2px solid #1d2429;
    border-radius: 7px 13px 5px 8px;
    background: linear-gradient(135deg, var(--tank-light), var(--tank-base) 58%, var(--tank-dark));
}

.tank-preview::after {
    left: 34%;
    bottom: 22px;
    width: 30%;
    height: 16px;
    border: 2px solid #1d2429;
    border-radius: 7px 7px 4px 4px;
    background: linear-gradient(135deg, var(--tank-light), var(--tank-base));
}

.preview-track {
    left: 4%;
    right: 5%;
    bottom: 0;
    height: 11px;
    border: 2px solid #11161a;
    border-radius: 999px;
    background: repeating-linear-gradient(90deg, #20252b 0 8px, #46505a 8px 13px);
}

.preview-turret {
    left: 56%;
    bottom: 28px;
    width: 38%;
    height: 7px;
    border: 2px solid #1d2429;
    border-radius: 999px;
    background: #74838a;
}

.tank-card[data-tank="shark"] .tank-preview::before {
    right: 6%;
    clip-path: polygon(0 46%, 14% 0, 72% 0, 100% 48%, 76% 100%, 6% 100%);
}

.hangar-preview[data-tank="shark"] .tank-preview::before,
.tank-card[data-tank="shark"] .tank-preview::before {
    right: 6%;
    clip-path: polygon(0 46%, 14% 0, 72% 0, 100% 48%, 76% 100%, 6% 100%);
}

.tank-card[data-tank="mammoth"] .tank-preview::before {
    left: 2%;
    right: 2%;
    height: 20px;
}

.tank-card[data-tank="mammoth"] .tank-preview::after {
    left: 29%;
    width: 38%;
    height: 19px;
}

.hangar-preview[data-tank="mammoth"] .tank-preview::before,
.tank-card[data-tank="mammoth"] .tank-preview::before {
    left: 2%;
    right: 2%;
}

.hangar-preview[data-tank="mammoth"] .tank-preview::after,
.tank-card[data-tank="mammoth"] .tank-preview::after {
    left: 29%;
    width: 38%;
}

.tank-card[data-tank="scout"] .tank-preview::before {
    left: 15%;
    right: 18%;
    height: 15px;
}

.tank-card[data-tank="scout"] .tank-preview::after {
    left: 40%;
    width: 22%;
    height: 13px;
}

.hangar-preview[data-tank="scout"] .tank-preview::before,
.tank-card[data-tank="scout"] .tank-preview::before {
    left: 15%;
    right: 18%;
}

.hangar-preview[data-tank="scout"] .tank-preview::after,
.tank-card[data-tank="scout"] .tank-preview::after {
    left: 40%;
    width: 22%;
}

.tank-card[data-tank="fortress"] .tank-preview::after {
    box-shadow: -24px 11px 0 -3px var(--tank-base), 24px 11px 0 -3px var(--tank-base);
}

.hangar-preview[data-tank="fortress"] .tank-preview::after,
.tank-card[data-tank="fortress"] .tank-preview::after {
    box-shadow: -24px 11px 0 -3px var(--tank-base), 24px 11px 0 -3px var(--tank-base);
}

.tank-title {
    display: block;
    font-size: 14px;
    font-weight: 900;
    line-height: 1.1;
}

.tank-meta {
    display: block;
    margin-top: 4px;
    color: rgba(31, 63, 42, 0.74);
    font-size: 11px;
    font-weight: 800;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.shop-selection-summary {
    grid-template-columns: 1fr 1fr;
}

.shop-picked {
    min-height: 38px;
    padding: 9px 10px;
    border-radius: 8px;
    border: 2px solid rgba(31, 63, 42, 0.12);
    background: rgba(255, 255, 255, 0.52);
    color: #183221;
    font-size: 13px;
    font-weight: 900;
}

/* --- Авторизация --- */
.auth-section {
    margin-top: 0;
    width: 100%;
    max-width: 560px;
}

.auth-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px 24px;
    background: #24292e;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-btn.unavailable {
    background: rgba(31, 63, 42, 0.52);
    cursor: default;
    opacity: 0.76;
}

.auth-btn:not(.unavailable):hover {
    background: #2f363d;
}

.github-icon {
    width: 20px;
    height: 20px;
    fill: white;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.24);
    padding: 10px 16px;
    border-radius: 12px;
}

.user-info.hidden {
    display: none;
}

#userAvatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid #FFD700;
}

#userName {
    color: white;
    font-weight: 600;
    flex: 1;
}

.logout-btn {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
}

.version {
    position: static;
    color: rgba(31, 63, 42, 0.7);
    font-size: 12px;
}

@media (max-width: 600px) and (min-height: 640px) {
    #startScreen {
        gap: 10px;
        padding-left: 16px;
        padding-right: 16px;
    }

    #startScreen > * {
        width: calc(100vw - 32px);
        max-width: calc(100vw - 32px);
    }

    .player-setup,
    .tank-shop,
    .menu-buttons,
    .auth-section,
    .landscape-note,
    .version {
        width: calc(100vw - 32px);
        max-width: calc(100vw - 32px);
    }

    .tank-icon {
        font-size: 48px;
        margin-bottom: 4px;
    }

    .logo h1 {
        font-size: 28px;
    }

    .subtitle {
        font-size: 15px;
        margin-top: 2px;
    }

    .player-setup {
        padding: 12px;
    }

    .tank-shop {
        padding: 12px;
    }

    .shop-head {
        margin-bottom: 9px;
    }

    .shop-badge {
        display: none;
    }

    .shop-player-switch {
        gap: 6px;
    }

    .shop-tab {
        min-height: 38px;
        font-size: 14px;
    }

    .hangar-stage {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 8px;
    }

    .hangar-preview {
        min-height: 104px;
    }

    .hangar-preview::before,
    .hangar-preview::after {
        bottom: 18px;
        width: 50px;
        height: 24px;
    }

    .hangar-tank-preview {
        width: min(96%, 270px);
        height: 82px;
        bottom: 12px;
    }

    .hangar-tank-preview::before {
        bottom: 15px;
        height: 29px;
    }

    .hangar-tank-preview::after {
        bottom: 44px;
        height: 24px;
    }

    .hangar-tank-preview .preview-track {
        height: 18px;
    }

    .hangar-tank-preview .preview-turret {
        bottom: 56px;
        height: 10px;
    }

    .hangar-info {
        gap: 4px;
    }

    .hangar-info h2 {
        font-size: 22px;
    }

    .hangar-info p {
        font-size: 12px;
    }

    .tank-stats {
        gap: 5px;
    }

    .tank-stat {
        grid-template-columns: 48px 44px minmax(0, 1fr);
        font-size: 10px;
    }

    .tank-card {
        min-height: 92px;
        padding: 8px;
    }

    .tank-options {
        grid-template-columns: minmax(0, 1fr);
    }

    .hangar-options {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .tank-preview {
        height: 34px;
        margin-bottom: 6px;
    }

    .tank-title {
        font-size: 13px;
    }

    .tank-meta {
        font-size: 10px;
    }

    .setup-title {
        font-size: 18px;
    }

    .setup-subtitle {
        margin-bottom: 8px;
        font-size: 12px;
    }

    .name-grid {
        gap: 8px;
    }

    .name-field input {
        min-height: 52px;
        font-size: 19px;
    }

    .setup-hint,
    .auth-hint,
    .landscape-note {
        margin-top: 8px;
        font-size: 11px;
    }

    .menu-buttons {
        gap: 10px;
        position: sticky;
        bottom: max(8px, env(safe-area-inset-bottom));
        z-index: 5;
        padding: 8px;
        border: 2px solid rgba(31, 63, 42, 0.12);
        border-radius: 10px;
        background: rgba(231, 249, 231, 0.9);
        box-shadow: 0 -8px 22px rgba(28, 74, 60, 0.16);
        backdrop-filter: blur(8px);
    }

    .menu-btn {
        min-height: 62px;
        padding: 10px 14px;
        font-size: 16px;
    }

    .auth-btn {
        padding: 12px 18px;
    }
}

/* --- Canvas --- */
#gameCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#gameCanvas.shake {
    animation: canvasShake 0.18s linear;
}

/* --- HUD --- */
.hud {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
    z-index: 10;
    pointer-events: none;
}

.hud.hidden {
    display: none;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.player-hud {
    flex: 1;
    max-width: 230px;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(17, 31, 36, 0.42);
    backdrop-filter: blur(8px);
}

.player-hud.player2 {
    text-align: right;
}

.player-name {
    font-size: 14px;
    font-weight: 700;
    color: white;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
    margin-bottom: 4px;
}

.player1 .player-name {
    color: #87CEFA;
}

.player2 .player-name {
    color: #FF6B6B;
}

.hp-bar {
    position: relative;
    height: 20px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.hp-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 0.3s ease;
}

.player1 .hp-fill {
    background: linear-gradient(90deg, #4169E1, #87CEFA);
}

.player2 .hp-fill {
    background: linear-gradient(90deg, #DC143C, #FF6B6B);
}

.hp-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 11px;
    font-weight: 700;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

.reload-indicator {
    margin-top: 4px;
    height: 4px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 2px;
    overflow: hidden;
    display: none;
}

.reload-indicator.reloading {
    display: block;
}

.reload-fill {
    height: 100%;
    width: 0%;
    background: #FFD700;
    border-radius: 2px;
    animation: reload 2s linear forwards;
}

.tank-readout {
    margin-top: 4px;
    color: rgba(255, 255, 255, 0.92);
    font-size: 11px;
    font-weight: 700;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    white-space: nowrap;
}

@keyframes reload {
    from { width: 0%; }
    to { width: 100%; }
}

.round-info {
    text-align: center;
    min-width: 130px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: rgba(17, 31, 36, 0.42);
    backdrop-filter: blur(8px);
}

.round-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

.score-text {
    font-size: 24px;
    font-weight: 900;
    color: #FFD700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5),
                 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.wind-indicator,
.map-label {
    margin-top: 2px;
    color: rgba(255, 255, 255, 0.92);
    font-size: 11px;
    font-weight: 800;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

.map-label {
    color: #ffef8a;
    max-width: 150px;
}

/* --- AI Комментарий --- */
.ai-comment {
    position: fixed;
    top: 86px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: #FFD700;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    max-width: 80%;
    animation: commentPop 0.5s ease;
    z-index: 11;
}

@keyframes commentPop {
    0% { transform: translateX(-50%) scale(0); opacity: 0; }
    50% { transform: translateX(-50%) scale(1.1); }
    100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* --- Touch-управление --- */
.touch-controls {
    position: fixed;
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 20;
    display: grid;
    grid-template-columns: 64px 64px;
    grid-template-rows: 64px 64px;
    gap: 10px;
    align-items: center;
    justify-items: center;
}

.touch-controls.hidden {
    display: none;
}

.controls-left {
    left: max(18px, env(safe-area-inset-left));
}

.controls-right {
    right: max(18px, env(safe-area-inset-right));
}

.control-row {
    display: contents;
}

.ctrl-btn {
    width: 64px;
    height: 64px;
    border: none;
    border-radius: 10px;
    background: rgba(22, 42, 49, 0.66);
    backdrop-filter: blur(10px);
    color: white;
    font-size: 24px;
    font-weight: 900;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: 0 5px 14px rgba(0, 0, 0, 0.25),
                inset 0 1px 0 rgba(255, 255, 255, 0.28);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ctrl-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.34);
}

.aim-btn {
    width: 64px;
    height: 64px;
    font-size: 20px;
}

.touch-controls .aim-btn[data-action="aimUp"] {
    grid-column: 1;
    grid-row: 1;
}

.touch-controls .aim-btn[data-action="aimDown"] {
    grid-column: 1;
    grid-row: 2;
}

.touch-controls .move-btn[data-action="left"] {
    grid-column: 2;
    grid-row: 1;
}

.touch-controls .move-btn[data-action="right"] {
    grid-column: 2;
    grid-row: 2;
}

/* --- Кнопка огня --- */
.fire-btn {
    position: fixed;
    bottom: max(18px, env(safe-area-inset-bottom));
    left: calc(max(18px, env(safe-area-inset-left)) + 150px);
    width: 92px;
    height: 92px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #FF416C 0%, #FF4B2B 100%);
    color: white;
    font-size: 28px;
    font-weight: 900;
    cursor: pointer;
    z-index: 20;
    box-shadow: 0 6px 20px rgba(255, 75, 43, 0.5),
                inset 0 2px 0 rgba(255, 255, 255, 0.3);
    transition: all 0.1s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    overflow: hidden;
    touch-action: none;
}

.fire-btn.hidden {
    display: none;
}

.fire-btn:active {
    transform: scale(0.9);
    box-shadow: 0 3px 10px rgba(255, 75, 43, 0.3);
}

.fire-btn::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: var(--charge, 0%);
    background: rgba(255, 255, 255, 0.25);
    pointer-events: none;
}

.fire-btn.charging {
    transform: scale(0.94);
    box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.18),
                0 6px 20px rgba(255, 75, 43, 0.5);
}

.fire-btn small {
    font-size: 10px;
    font-weight: 700;
}

.fire-btn-p2 {
    right: calc(max(18px, env(safe-area-inset-right)) + 150px);
    left: auto;
    background: linear-gradient(135deg, #2b9cff 0%, #2c5bd7 100%);
    box-shadow: 0 6px 20px rgba(44, 91, 215, 0.45);
}

/* --- Кнопка паузы --- */
.pause-btn {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    color: white;
    font-size: 20px;
    cursor: pointer;
    z-index: 20;
}

.pause-btn.hidden {
    display: none;
}

.orientation-overlay {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    padding: 24px;
    text-align: center;
    color: #ffffff;
    background: linear-gradient(180deg, rgba(19, 51, 76, 0.96), rgba(31, 79, 58, 0.96));
}

.orientation-overlay h2 {
    font-size: 28px;
    line-height: 1.1;
}

.orientation-overlay p {
    max-width: 320px;
    color: rgba(255, 255, 255, 0.78);
    font-size: 16px;
    font-weight: 700;
}

.phone-turn {
    width: 82px;
    height: 82px;
    display: grid;
    place-items: center;
    border: 3px solid rgba(255, 255, 255, 0.55);
    border-radius: 18px;
    font-size: 46px;
    font-weight: 900;
    color: #ffd966;
    transform: rotate(90deg);
}

/* --- Overlay экраны --- */
.overlay-content {
    background: linear-gradient(135deg, #13334c 0%, #1f4f3a 100%);
    padding: 40px 30px;
    border-radius: 8px;
    text-align: center;
    max-width: 90%;
    width: 360px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 215, 0, 0.3);
}

.overlay-content h2 {
    color: #FFD700;
    font-size: 28px;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.overlay-content .menu-btn {
    margin: 8px 0;
    justify-content: center;
    text-align: center;
}

/* --- Экран окончания раунда --- */
.genai-comment {
    background: rgba(255, 215, 0, 0.15);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 8px;
    padding: 12px;
    margin: 15px 0;
    color: #FFD700;
    font-size: 15px;
    font-style: italic;
}

.round-stats {
    display: flex;
    justify-content: space-around;
    margin: 15px 0;
    color: white;
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 24px;
    font-weight: 900;
    color: #87CEFA;
}

.stat-label {
    font-size: 12px;
    opacity: 0.7;
}

/* --- Экран окончания игры --- */
.winner-display {
    margin: 20px 0;
}

.winner-crown {
    font-size: 60px;
    margin-bottom: 10px;
    animation: bounce 1s ease infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

#gameWinnerName {
    color: #FFD700;
    font-size: 24px;
    margin-bottom: 5px;
}

#gameWinnerText {
    color: rgba(255, 255, 255, 0.8);
    font-size: 16px;
}

.final-score {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 15px;
    margin: 15px 0;
    color: white;
    font-size: 18px;
}

/* --- Таблица лидеров --- */
.leaderboard-container {
    background: linear-gradient(135deg, #13334c 0%, #1f4f3a 100%);
    padding: 30px 20px;
    border-radius: 8px;
    max-width: 90%;
    width: 400px;
    max-height: 80%;
    overflow-y: auto;
    border: 2px solid rgba(255, 215, 0, 0.3);
}

.leaderboard-container h2 {
    color: #FFD700;
    font-size: 24px;
    margin-bottom: 20px;
    text-align: center;
}

.leaderboard-list {
    margin-bottom: 20px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    margin-bottom: 8px;
    color: white;
}

.leaderboard-rank {
    font-size: 20px;
    font-weight: 900;
    width: 30px;
    text-align: center;
}

.leaderboard-rank.gold { color: #FFD700; }
.leaderboard-rank.silver { color: #C0C0C0; }
.leaderboard-rank.bronze { color: #CD7F32; }

.leaderboard-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.leaderboard-name {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
}

.leaderboard-score {
    font-weight: 900;
    color: #FFD700;
    font-size: 16px;
}

/* --- Адаптация для маленьких экранов --- */
@media (max-height: 600px) {
    .logo {
        margin-bottom: 15px;
    }
    
    .tank-icon {
        font-size: 50px;
    }
    
    .logo h1 {
        font-size: 28px;
    }
    
    .menu-btn {
        padding: 12px 20px;
        font-size: 16px;
    }
    
    .player-setup {
        padding: 10px;
    }

    .name-grid {
        grid-template-columns: 1fr 1fr;
    }

    .shop-columns {
        grid-template-columns: 1fr 1fr;
    }

    .menu-buttons {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        max-width: 720px;
    }

    .menu-btn {
        min-height: 72px;
        padding: 10px 12px;
        gap: 10px;
    }

    .btn-icon {
        font-size: 23px;
    }

    .auth-section {
        max-width: 520px;
    }

    .touch-controls {
        grid-template-columns: 56px 56px;
        grid-template-rows: 56px 56px;
        gap: 8px;
    }

    .ctrl-btn,
    .aim-btn {
        width: 56px;
        height: 56px;
        font-size: 19px;
    }

    .fire-btn {
        left: calc(max(14px, env(safe-area-inset-left)) + 132px);
        width: 82px;
        height: 82px;
        font-size: 25px;
    }

    .fire-btn-p2 {
        right: calc(max(14px, env(safe-area-inset-right)) + 132px);
        left: auto;
    }
}

/* --- Адаптация для планшетов --- */
@media (min-width: 768px) {
    .name-grid {
        grid-template-columns: 1fr 1fr;
    }

    .shop-columns {
        grid-template-columns: 1fr 1fr;
    }

    .ctrl-btn {
        width: 70px;
        height: 70px;
        font-size: 28px;
    }
    
    .aim-btn {
        width: 60px;
        height: 60px;
        font-size: 22px;
    }
    
    .fire-btn {
        width: 90px;
        height: 90px;
        font-size: 32px;
    }
}

@media (orientation: portrait) {
    #gameScreen.active .orientation-overlay {
        display: flex;
    }

    #gameScreen.active .hud,
    #gameScreen.active .touch-controls,
    #gameScreen.active .fire-btn,
    #gameScreen.active .pause-btn {
        display: none !important;
    }
}

@media (orientation: landscape) {
    #startScreen {
        justify-content: center;
    }
}

/* --- Анимации --- */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.pulse {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.3s ease-in-out;
}

@keyframes canvasShake {
    0%, 100% { transform: translate3d(0, 0, 0); }
    25% { transform: translate3d(-4px, 2px, 0); }
    50% { transform: translate3d(4px, -2px, 0); }
    75% { transform: translate3d(-2px, -1px, 0); }
}
