/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #1a1a2e;
    --bg-light: #16213e;
    --surface: #0f3460;
    --primary: #e94560;
    --accent: #53d769;
    --text: #eee;
    --text-dim: #999;
    --gold: #f0c040;
    --tile-locked: #2a2a3e;
    --tile-empty: #1e4d2e;
    --border: #334;
    --danger: #e94560;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

.screen { width: 100%; height: 100%; }

/* === Auth === */
.auth-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 1.5rem;
}

.auth-container h1 {
    font-size: 2.5rem;
    color: var(--gold);
    text-shadow: 0 2px 8px rgba(240, 192, 64, 0.3);
}

.auth-form {
    background: var(--bg-light);
    padding: 2rem;
    border-radius: 12px;
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.auth-form h2 { color: var(--text); font-size: 1.2rem; }

.auth-form input {
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
}

.auth-switch { font-size: 0.85rem; color: var(--text-dim); text-align: center; }
.auth-switch a { color: var(--primary); text-decoration: none; }

.error-text { color: var(--danger); font-size: 0.85rem; text-align: center; min-height: 1.2em; }

/* === Buttons === */
.btn {
    padding: 0.55rem 1.2rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn:active { opacity: 0.7; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--accent); color: #111; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.8rem; }

/* === Resource Bar === */
#resource-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    background: var(--bg-light);
    border-bottom: 1px solid var(--border);
    height: 48px;
    overflow-x: auto;
}

#player-info { font-weight: 700; color: var(--gold); white-space: nowrap; }

#resource-list {
    display: flex;
    gap: 1rem;
    flex: 1;
    overflow-x: auto;
}

.resource-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
    font-size: 0.85rem;
}

.resource-item img { width: 20px; height: 20px; object-fit: contain; }

#storage-meter {
    position: relative;
    width: 120px;
    min-width: 120px;
    height: 22px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border);
}

#storage-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s;
}

#storage-fill.danger { background: var(--danger); }

#storage-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* === Game Area === */
#game-area {
    display: flex;
    height: calc(100% - 48px);
}

#tile-grid {
    flex: 1;
    display: grid;
    gap: 3px;
    padding: 12px;
    overflow: auto;
    align-content: start;
}

#side-panel {
    width: 300px;
    min-width: 300px;
    background: var(--bg-light);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: 1rem;
}

/* === Tiles === */
.tile {
    aspect-ratio: 16 / 10;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.15s, transform 0.1s;
    background-size: cover;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tile:hover { box-shadow: 0 0 0 2px var(--gold); transform: scale(1.02); }
.tile.selected { box-shadow: 0 0 0 2px var(--primary); }

.tile-locked {
    background: var(--tile-locked);
    border: 2px dashed #444;
}

.tile-locked .lock-icon {
    font-size: 1.5rem;
    opacity: 0.4;
}

.tile-empty {
    border: 2px dashed var(--accent);
}

.tile-building img {
    width: 70%;
    height: 70%;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}

.tile-building.constructing img {
    opacity: 0.4;
}

.tile-level {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 0.65rem;
    font-weight: 700;
    background: rgba(0,0,0,0.6);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--gold);
}

.tile-timer {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 0.6rem;
    background: rgba(0,0,0,0.7);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--accent);
}

/* === Side Panel === */
#panel-content h3 {
    margin-bottom: 0.75rem;
    color: var(--gold);
}

.panel-section {
    margin-bottom: 1rem;
}

.building-card {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem;
    background: var(--bg);
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 0.4rem;
    border: 1px solid transparent;
    transition: border-color 0.15s;
}

.building-card:hover { border-color: var(--gold); }
.building-card.selected { border-color: var(--primary); }
.building-card img { width: 36px; height: 36px; object-fit: contain; }
.building-card .building-info { flex: 1; }
.building-card .building-name { font-weight: 600; font-size: 0.9rem; }
.building-card .building-type { font-size: 0.75rem; color: var(--text-dim); }

.type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}
.type-badge.producer { background: #2d6a4f; color: #b7e4c7; }
.type-badge.converter { background: #5a3e1b; color: #f0c040; }
.type-badge.storage { background: #1b3a5a; color: #89c4f4; }

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    padding: 0.25rem 0;
}
.stat-label { color: var(--text-dim); }
.stat-value { font-weight: 600; }
.stat-next { color: var(--accent); font-size: 0.8rem; }

.cost-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin: 0.5rem 0;
}
.cost-item {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
}
.cost-item img { width: 16px; height: 16px; }
.cost-item.cant-afford { color: var(--danger); }
.cost-item img { width: 16px; height: 16px; }

.btn-disabled { opacity: 0.4; cursor: not-allowed; }

.building-cost-preview {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-top: 2px;
}
.building-cost-preview .cant-afford { color: var(--danger); }
.cant-afford-card { opacity: 0.6; }

.panel-buttons {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* === Admin === */
.admin-gear {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.4rem;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.admin-gear:hover { background: var(--primary); }

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-light);
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    height: 80%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.btn-close {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
}

.admin-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    padding: 0.6rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.9rem;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--primary); }

#admin-tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.5rem;
}

.admin-split {
    display: flex;
    gap: 1rem;
    height: 100%;
}

.admin-list {
    width: 240px;
    min-width: 240px;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    padding-right: 1rem;
}

.admin-list-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 6px;
    margin-bottom: 0.3rem;
}
.admin-list-item:hover { background: var(--bg); }
.admin-list-item.active { background: var(--surface); }
.admin-list-item img { width: 24px; height: 24px; }

.admin-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.admin-form label {
    font-size: 0.85rem;
    color: var(--text-dim);
}

.admin-form input,
.admin-form select,
.admin-form textarea {
    padding: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
}

.form-row {
    display: flex;
    gap: 0.75rem;
    align-items: end;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
}

/* === Mobile === */
@media (max-width: 768px) {
    #game-area {
        flex-direction: column;
    }
    #side-panel {
        width: 100%;
        min-width: unset;
        max-height: 40%;
        border-left: none;
        border-top: 1px solid var(--border);
    }
    #tile-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
    .admin-split {
        flex-direction: column;
    }
    .admin-list {
        width: 100%;
        min-width: unset;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding-right: 0;
        padding-bottom: 0.5rem;
        max-height: 150px;
    }
}
