* {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #17212f;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: white;
    user-select: none;
}

canvas {
    display: block;
    background: radial-gradient(circle at top, #f7fafc 0%, #dfe9f3 100%);
    cursor: crosshair;
}

#top-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 82px;
    background: rgba(15, 23, 42, 0.94);
    padding: 10px 18px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 16px;
    align-items: center;
    box-shadow: 0 12px 28px rgba(0,0,0,0.35);
    z-index: 10;
    backdrop-filter: blur(12px);
}

.stat-group {
    font-size: 1rem;
    font-weight: 800;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    white-space: nowrap;
}

.stat-group span {
    background: rgba(255,255,255,0.08);
    padding: 8px 10px;
    border-radius: 14px;
}

#shop {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.shop-item {
    min-width: 132px;
    background: linear-gradient(180deg, rgba(255,255,255,0.13), rgba(255,255,255,0.06));
    border: 2px solid transparent;
    padding: 8px 10px;
    border-radius: 16px;
    cursor: pointer;
    text-align: left;
    transition: 0.18s;
    font-weight: 800;
    position: relative;
}

.shop-item:hover {
    transform: translateY(-2px);
    background: rgba(255,255,255,0.16);
}

.shop-item.selected {
    border-color: #facc15;
    box-shadow: 0 0 18px rgba(250, 204, 21, 0.42);
}

.shop-item.disabled {
    opacity: 0.45;
    filter: grayscale(1);
}

.shop-icon {
    font-size: 1.35rem;
    display: inline-block;
    margin-right: 4px;
}

.shop-name {
    font-size: 0.88rem;
}

.shop-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 6px;
    margin-top: 6px;
    color: #dbeafe;
    font-size: 0.72rem;
    font-weight: 600;
}

.shop-desc {
    margin-top: 5px;
    color: #cbd5e1;
    font-size: 0.7rem;
    font-weight: 500;
}

#controls {
    display: flex;
    gap: 8px;
    align-items: center;
    white-space: nowrap;
}

.ctrl-btn, .ctrl-link {
    color: white;
    border: none;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 0.9rem;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
    background: #334155;
    box-shadow: 0 5px 0 rgba(0,0,0,0.25);
    transition: 0.1s;
}

.ctrl-btn:active, .ctrl-link:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.25);
}

.ctrl-btn:disabled {
    background: #64748b !important;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

#btn-save { background: #0ea5e9; }
#btn-leaderboard { background: #7c3aed; }
#btn-pause { background: #f59e0b; }
#btn-skip { background: #9333ea; }
#btn-start { background: #ef4444; }
.ctrl-link { background: #475569; }

#action-menu {
    position: absolute;
    background: rgba(15, 23, 42, 0.96);
    padding: 12px;
    border-radius: 18px;
    box-shadow: 0 18px 35px rgba(0,0,0,0.45);
    display: none;
    flex-direction: column;
    gap: 9px;
    z-index: 20;
    border: 1px solid #facc15;
    transform: translate(-50%, -120%);
    min-width: 170px;
}

#action-info {
    font-size: 0.85rem;
    text-align: center;
    color: #facc15;
    font-weight: 800;
}

.target-label {
    font-size: 0.75rem;
    color: #cbd5e1;
    display: grid;
    gap: 4px;
}

.target-label select {
    width: 100%;
    padding: 7px 8px;
    border-radius: 10px;
    border: 1px solid #475569;
    background: #0f172a;
    color: white;
}

.action-btn {
    border: none;
    padding: 9px 12px;
    border-radius: 12px;
    color: white;
    font-weight: 800;
    cursor: pointer;
    font-size: 0.86rem;
}

.btn-upgrade { background: #22c55e; }
.btn-sell { background: #f97316; }

#map-info {
    position: absolute;
    bottom: 24px;
    right: 24px;
    font-size: 1.35rem;
    font-weight: 900;
    color: rgba(15, 23, 42, 0.25);
    z-index: 5;
    pointer-events: none;
}

#player-info {
    position: absolute;
    left: 18px;
    bottom: 18px;
    z-index: 6;
    background: rgba(15, 23, 42, 0.65);
    padding: 8px 12px;
    border-radius: 14px;
    color: #dbeafe;
    font-size: 0.9rem;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0,0,0,0.58);
    display: grid;
    place-items: center;
}

.modal.hidden,
.hidden {
    display: none !important;
}

.modal-card {
    width: min(620px, calc(100vw - 28px));
    max-height: 80vh;
    overflow: auto;
    background: #0f172a;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 25px 55px rgba(0,0,0,0.5);
    border-radius: 24px;
    padding: 22px;
    position: relative;
}

.modal-card h2 {
    margin: 0 0 16px;
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 16px;
    border: none;
    background: #334155;
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
}

.rank-table {
    width: 100%;
    border-collapse: collapse;
    overflow: hidden;
    border-radius: 14px;
}

.rank-table th,
.rank-table td {
    padding: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    text-align: left;
}

.rank-table th {
    color: #facc15;
    background: rgba(255,255,255,0.06);
}

.achievement-popup {
    position: fixed;
    top: 96px;
    right: 18px;
    z-index: 200;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
    padding: 14px 18px;
    border-radius: 18px;
    font-weight: 900;
    box-shadow: 0 18px 35px rgba(0,0,0,0.35);
}

.auth-page {
    overflow: auto;
    display: grid;
    place-items: center;
    min-height: 100vh;
    background:
        radial-gradient(circle at 20% 20%, rgba(59,130,246,0.3), transparent 28%),
        radial-gradient(circle at 80% 10%, rgba(245,158,11,0.25), transparent 24%),
        #0f172a;
}

.auth-card {
    width: min(420px, calc(100vw - 28px));
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 26px;
    padding: 28px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.38);
}

.auth-card h1 {
    margin: 0 0 8px;
}

.auth-card p {
    color: #cbd5e1;
}

.auth-card form {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.auth-card label {
    color: #e2e8f0;
    font-weight: 700;
}

.auth-card input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #334155;
    border-radius: 14px;
    background: #020617;
    color: white;
    outline: none;
}

.auth-card button {
    margin-top: 8px;
    border: none;
    background: #ef4444;
    color: white;
    padding: 13px 14px;
    border-radius: 14px;
    font-weight: 900;
    cursor: pointer;
}

.alert {
    padding: 12px 14px;
    border-radius: 14px;
    margin: 14px 0;
}

.alert.error {
    background: rgba(239,68,68,0.18);
    border: 1px solid rgba(239,68,68,0.4);
    color: #fecaca;
}

.auth-switch a {
    color: #93c5fd;
    font-weight: 800;
}

@media (max-width: 980px) {
    body, html {
        overflow: auto;
    }

    #top-bar {
        position: relative;
        grid-template-columns: 1fr;
    }

    canvas {
        min-height: 720px;
    }

    #controls {
        overflow-x: auto;
    }

    #player-info {
        display: none;
    }
}
