:root {
    --grass: #4f793c;
    --grass-dark: #34582b;
    --panel: rgba(18, 28, 19, 0.88);
    --panel-strong: rgba(10, 16, 11, 0.94);
    --line: rgba(255, 255, 255, 0.12);
    --text: #f3f6ee;
    --muted: #aeb8a6;
    --accent: #69b51c;
    --danger: #d84d55;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #1d2f1a;
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input {
    font: inherit;
}

#gameCanvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    display: block;
    background: var(--grass);
}

.login-panel {
    position: fixed;
    z-index: 30;
    left: 50%;
    top: 50%;
    width: min(340px, calc(100vw - 32px));
    transform: translate(-50%, -50%);
    padding: 22px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 18px 70px rgba(0, 0, 0, 0.35);
}

body:not(.is-playing) .side-menu,
body:not(.is-playing) .panel,
body:not(.is-playing) .hud,
body:not(.is-playing) .build-bar,
body:not(.is-playing) .build-tooltip,
body:not(.is-playing) .connection-status {
    display: none !important;
    pointer-events: none;
}

.login-panel h1 {
    margin: 0 0 6px;
    font-size: 40px;
    line-height: 1;
    text-transform: uppercase;
}

.login-panel p {
    margin: 0 0 18px;
    color: var(--muted);
}

.login-panel input,
.login-panel button {
    width: 100%;
    height: 52px;
    border-radius: 6px;
    border: 0;
    margin-bottom: 10px;
}

.login-panel input {
    padding: 0 16px;
}

.login-panel button {
    background: #4aa60b;
    color: white;
    cursor: pointer;
}

.login-panel small {
    color: var(--muted);
}

.hidden {
    display: none !important;
}

.leaderboard {
    position: fixed;
    z-index: 8;
    right: 18px;
    top: 18px;
    width: 300px;
    padding: 12px;
    background: rgba(15, 24, 15, 0.55);
    border-radius: 6px;
    font-size: 14px;
}

.table-head,
.leaderboard-row {
    display: grid;
    grid-template-columns: 44px 1fr 64px 52px;
    gap: 8px;
    align-items: center;
}

.table-head {
    color: var(--muted);
    margin-bottom: 8px;
}

.leaderboard-row {
    min-height: 24px;
}

.tutorial {
    position: fixed;
    z-index: 9;
    top: 26px;
    left: 50%;
    width: min(430px, calc(100vw - 40px));
    transform: translateX(-50%);
    padding: 16px 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: #dfe8d8;
    text-align: center;
    transition: opacity 180ms ease, transform 180ms ease;
}

.tutorial.hidden {
    display: block !important;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(-8px);
}

.side-menu {
    position: fixed;
    z-index: 12;
    right: 16px;
    top: 50%;
    display: grid;
    gap: 8px;
    transform: translateY(-50%);
}

.side-menu button,
.build-bar button {
    border: 1px solid var(--line);
    background: rgba(20, 31, 21, 0.72);
    color: var(--text);
    border-radius: 6px;
    cursor: pointer;
}

.side-menu button {
    width: 78px;
    height: 46px;
}

.side-menu button:hover,
.build-bar button:hover,
.build-bar button.active {
    background: rgba(93, 159, 32, 0.85);
}

.panel {
    position: fixed;
    z-index: 24;
    left: 50%;
    top: 50%;
    width: min(820px, calc(100vw - 40px));
    max-height: min(640px, calc(100vh - 40px));
    transform: translate(-50%, -50%);
    padding: 18px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: auto;
}

.panel header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.panel h2 {
    margin: 0;
}

.panel header button {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 4px;
    color: white;
    background: transparent;
}

.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.tabs button {
    min-width: 92px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.tabs button.active {
    background: var(--accent);
}

.shop-items {
    display: grid;
    gap: 10px;
}

.shop-card {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    padding: 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--line);
    border-radius: 6px;
}

.shop-icon {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    border: 2px solid rgba(0, 0, 0, 0.34);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.12));
    color: #f8f2dc;
    font-size: 25px;
    font-weight: 800;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.shop-card-pickaxe .shop-icon { background-color: #7d8790; }
.shop-card-spear .shop-icon { background-color: #85533a; }
.shop-card-bow .shop-icon { background-color: #96632d; }
.shop-card-bomb .shop-icon { background-color: #513f4f; }
.shop-card-shield .shop-icon { background-color: #416a8e; }
.shop-card-guard_pet .shop-icon { background-color: #6f8240; }
.shop-card-consumable .shop-icon { background-color: #8f3f49; }

.shop-card strong {
    display: block;
    margin-bottom: 5px;
}

.shop-card p {
    margin: 0;
    color: var(--muted);
}

.shop-card span {
    display: block;
    margin-top: 6px;
    color: #d7c07b;
    font-size: 12px;
    text-transform: uppercase;
}

.shop-card button {
    min-width: 126px;
    height: 40px;
    padding: 0 14px;
    border: 0;
    border-radius: 5px;
    background: #d59a25;
    color: #1c1300;
    cursor: pointer;
}

.shop-card button:disabled {
    background: rgba(255, 255, 255, 0.12);
    color: var(--muted);
    cursor: not-allowed;
}

.hud {
    position: fixed;
    z-index: 12;
    right: 20px;
    bottom: 104px;
    width: 250px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: hidden;
    background: rgba(15, 24, 15, 0.72);
    border: 1px solid var(--line);
    border-radius: 6px;
}

.hud div {
    display: flex;
    justify-content: space-between;
    min-height: 34px;
    padding: 9px 12px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.hud b {
    color: var(--muted);
    font-size: 12px;
}

.hud .health {
    grid-column: 1 / -1;
    background: #4b9707;
}

.build-bar {
    position: fixed;
    z-index: 12;
    left: 14px;
    right: 14px;
    bottom: 18px;
    display: flex;
    gap: 8px;
    justify-content: center;
    overflow-x: auto;
    padding-bottom: 2px;
}

.build-bar button {
    flex: 0 0 82px;
    width: 82px;
    height: 64px;
    line-height: 1.2;
    padding: 6px 5px;
}

.build-bar button strong,
.build-bar button small,
.build-key {
    display: block;
}

.build-key {
    color: #f8f4df;
    font-size: 12px;
}

.build-bar button strong {
    margin-top: 1px;
    font-size: 15px;
}

.build-bar button small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.05;
}

.build-tooltip {
    position: fixed;
    z-index: 26;
    width: 260px;
    min-height: 104px;
    display: grid;
    grid-template-columns: 74px 1fr;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(9, 16, 11, 0.95);
    box-shadow: 0 14px 45px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

.build-tooltip strong,
.build-tooltip span,
.build-tooltip p {
    display: block;
}

.build-tooltip span {
    margin-top: 4px;
    color: #d6c490;
    font-size: 12px;
}

.build-tooltip p {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.tooltip-preview {
    width: 66px;
    height: 66px;
    display: grid;
    place-items: center;
    border: 3px solid rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    color: white;
    font-weight: 700;
    font-size: 26px;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.tooltip-gold_stash { background: #b98724; }
.tooltip-wall { background: #58645f; }
.tooltip-door { background: #6b5949; }
.tooltip-gold_mine { background: #92702b; }
.tooltip-harvester { background: #6b7d33; }
.tooltip-arrow_tower { background: #3f7198; }
.tooltip-cannon_tower { background: #65506d; }
.tooltip-melee_tower { background: #8d5945; }
.tooltip-bomb_tower { background: #79484a; }
.tooltip-magic_tower { background: #426a91; }
.tooltip-slow_trap { background: #347a80; }

.connection-status {
    position: fixed;
    z-index: 12;
    left: 14px;
    bottom: 14px;
    min-width: 80px;
    padding: 8px 10px;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.45);
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.muted {
    color: var(--muted);
}

@media (max-width: 760px) {
    .leaderboard {
        display: none;
    }

    .build-bar {
        left: 10px;
        right: 10px;
        transform: none;
        overflow-x: auto;
        justify-content: flex-start;
    }

    .hud {
        width: 210px;
        right: 10px;
        bottom: 158px;
    }

    .side-menu {
        right: 10px;
    }
}
