* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-dark: #0b111e;
    --bg-panel: #131d31;
    --bg-card: #1c2942;
    --border-gold: #c99e32;
    --accent-gold: #f5b935;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --accent-blue: #38bdf8;
    --accent-purple: #a855f7;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow-x: hidden;
    padding-bottom: 75px;
    min-height: 100vh;
}

/* LOGIN OVERLAY */
#login-modal {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at center, #1e293b 0%, #090d16 100%);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box {
    background: var(--bg-panel);
    border: 2px solid var(--border-gold);
    border-radius: 16px;
    max-width: 440px;
    width: 100%;
    padding: 28px 24px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8), 0 0 25px rgba(245, 185, 53, 0.2);
}

.login-box h1 {
    font-size: 1.8rem;
    color: var(--accent-gold);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.login-box p {
    color: var(--text-muted);
    font-size: 0.92rem;
    margin-bottom: 20px;
    line-height: 1.4;
}

.login-input {
    width: 100%;
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid #334155;
    background: #0f172a;
    color: #fff;
    font-size: 1rem;
    margin-bottom: 14px;
    outline: none;
    transition: border 0.2s;
}

.login-input:focus {
    border-color: var(--accent-gold);
}

.btn-primary {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #090d16;
    font-weight: 800;
    border: none;
    padding: 14px 20px;
    border-radius: 10px;
    font-size: 1rem;
    cursor: pointer;
    width: 100%;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: transform 0.12s, filter 0.2s;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-primary:hover {
    filter: brightness(1.1);
}

/* TOP STICKY HUD */
.top-hud {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(11, 17, 30, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid #263554;
    padding: 8px 12px;
}

.hud-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto 8px auto;
    flex-wrap: wrap;
    gap: 8px;
}

.commander-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}

.online-dot {
    width: 11px;
    height: 11px;
    background: var(--accent-green);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-green);
    animation: pulse 1.6s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.25); opacity: 0.65; }
    100% { transform: scale(1); opacity: 1; }
}

.commander-info {
    font-size: 0.88rem;
}

.commander-info strong {
    color: var(--accent-gold);
    font-size: 1rem;
}

.coord-tag {
    background: #1e293b;
    color: var(--accent-blue);
    padding: 2px 7px;
    border-radius: 6px;
    font-family: monospace;
    font-weight: 700;
}

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

.btn-small {
    background: var(--bg-card);
    border: 1px solid #334155;
    color: var(--text-main);
    padding: 6px 11px;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
}

.btn-small:hover {
    border-color: var(--accent-gold);
}

.btn-Crate {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: #fff;
    border: none;
    animation: bounceGlow 2s infinite;
}

@keyframes bounceGlow {
    0%, 100% { box-shadow: 0 0 6px rgba(34, 197, 94, 0.5); }
    50% { box-shadow: 0 0 16px rgba(34, 197, 94, 0.95); }
}

/* RESOURCE BAR */
.resource-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    max-width: 1200px;
    margin: 0 auto;
}

.res-item {
    background: var(--bg-panel);
    border: 1px solid #263554;
    border-radius: 8px;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.res-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.res-icon {
    font-size: 1.2rem;
}

.res-name {
    font-size: 0.72rem;
    color: var(--text-muted);
    display: block;
}

.res-val {
    font-weight: 800;
    font-size: 0.95rem;
    color: #fff;
}

.res-rate {
    font-size: 0.72rem;
    color: var(--accent-green);
    font-weight: 700;
}

/* ALERT BANNER FOR INCOMING ATTACKS / RETALIATION */
#threat-banner {
    background: linear-gradient(90deg, #7f1d1d, #dc2626, #7f1d1d);
    color: #fff;
    text-align: center;
    padding: 7px 12px;
    font-size: 0.85rem;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* MAIN CONTAINER */
.main-container {
    max-width: 1200px;
    margin: 14px auto;
    padding: 0 12px;
}

.tab-section {
    display: none;
    animation: fadeIn 0.2s ease;
}

.tab-section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-title {
    font-size: 1.25rem;
    color: var(--accent-gold);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.section-sub {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 14px;
}

/* CARDS GRID */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 12px;
}

.game-card {
    background: var(--bg-panel);
    border: 1px solid #283756;
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.15s, border-color 0.2s;
    position: relative;
    overflow: hidden;
}

.game-card:hover {
    border-color: var(--border-gold);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.card-emoji {
    font-size: 2rem;
    background: var(--bg-card);
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #334155;
    flex-shrink: 0;
}

.card-title-group h3 {
    font-size: 1rem;
    color: #fff;
}

.card-badge {
    display: inline-block;
    background: #25334d;
    color: var(--accent-gold);
    font-size: 0.73rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 99px;
    margin-top: 3px;
}

.card-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    line-height: 1.35;
}

.card-stats {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.stat-pill {
    background: #0f172a;
    border: 1px solid #1e293b;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.74rem;
    font-weight: 600;
}

.cost-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    background: rgba(15, 23, 42, 0.65);
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 0.76rem;
}

.cost-item {
    display: flex;
    align-items: center;
    gap: 3px;
}

.cost-item.insufficient {
    color: var(--accent-red);
}

.card-actions {
    display: flex;
    gap: 6px;
}

.btn-action {
    flex: 1;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    border: none;
    padding: 9px 10px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.82rem;
    cursor: pointer;
    transition: filter 0.15s, transform 0.1s;
}

.btn-action:hover {
    filter: brightness(1.12);
}

.btn-action:active {
    transform: scale(0.97);
}

.btn-action.gold-btn {
    background: linear-gradient(135deg, #d97706, #b45309);
}

.btn-action.upgrade-btn {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    flex: 0.85;
}

/* DOME DEFENSE ACTIVE STATUS BAR */
.dome-status-panel {
    background: linear-gradient(135deg, #131d31 0%, #1e1b4b 100%);
    border: 1px solid #4338ca;
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.dome-shield-meter {
    display: flex;
     gap: 14px;
    flex-wrap: wrap;
}

.dome-pill {
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid #312e81;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.82rem;
}

/* WORLD MAP (TRAVIAN COORDINATE GRID) */
.map-layout {
    display: grid;
    grid-template-columns: 1fr 330px;
    gap: 14px;
}

@media (max-width: 900px) {
    .map-layout {
        grid-template-columns: 1fr;
    }
}

.map-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-panel);
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid #283756;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 8px;
}

.map-viewport {
    background: #09131c;
    border: 2px solid #283756;
    border-radius: 12px;
    overflow: auto;
    max-height: 540px;
    padding: 12px;
    position: relative;
}

.map-grid {
    display: grid;
    grid-template-columns: repeat(15, 48px);
    grid-auto-rows: 48px;
    gap: 4px;
    width: max-content;
    margin: 0 auto;
}

.map-tile {
    width: 48px;
    height: 48px;
    border-radius: 7px;
    background: #122230;
    border: 1px solid #1e3346;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: transform 0.1s, border-color 0.15s;
    font-size: 1.15rem;
}

.map-tile:hover {
    transform: scale(1.12);
    z-index: 5;
    border-color: var(--accent-gold);
}

.map-tile.selected {
    border: 2px solid var(--accent-gold);
    box-shadow: 0 0 12px rgba(245, 185, 53, 0.7);
}

.map-tile.own-village {
    background: radial-gradient(circle, #1e3a8a 0%, #172554 100%);
    border-color: var(--accent-blue);
}

.map-tile.enemy-village {
    background: radial-gradient(circle, #4c1d24 0%, #2a1215 100%);
    border-color: #7f1d1d;
}

.map-tile.oasis-tile {
    background: #0f2922;
    border-color: #115e59;
}

.tile-coord {
    position: absolute;
    bottom: 1px;
    right: 3px;
    font-size: 0.52rem;
    color: #64748b;
    font-family: monospace;
}

.tile-online-badge {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-green);
    box-shadow: 0 0 6px var(--accent-green);
}

.tile-offline-badge {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #64748b;
}

.map-inspector {
    background: var(--bg-panel);
    border: 1px solid #283756;
    border-radius: 12px;
    padding: 16px;
    height: fit-content;
}

/* MESSAGING & DIPLOMACY */
.chat-container {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 14px;
}

@media (max-width: 850px) {
    .chat-container {
        grid-template-columns: 1fr;
    }
}

.chat-box {
    background: var(--bg-panel);
    border: 1px solid #283756;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    height: 460px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.msg-bubble {
    background: var(--bg-card);
    border-left: 3px solid var(--accent-blue);
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
}

.msg-bubble.own {
    border-left-color: var(--accent-gold);
    background: #232d45;
}

.msg-bubble.ai-threat {
    border-left-color: var(--accent-red);
    background: #2d1a22;
}

.msg-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.chat-input-row {
    padding: 10px;
    border-top: 1px solid #283756;
    display: flex;
    gap: 8px;
}

/* LEADERBOARD & QUESTS */
.quest-card {
    background: linear-gradient(90deg, #172554 0%, #1e293b 100%);
    border: 1px solid #3b82f6;
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.rank-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-panel);
    border-radius: 12px;
    overflow: hidden;
}

.rank-table th, .rank-table td {
    padding: 11px 12px;
    text-align: left;
    border-bottom: 1px solid #22304d;
    font-size: 0.85rem;
}

.rank-table th {
    background: #18243c;
    color: var(--accent-gold);
}

/* BOTTOM NAVIGATION BAR */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(11, 17, 30, 0.98);
    border-top: 1px solid #283756;
    display: flex;
    justify-content: space-around;
    padding: 6px 4px;
    z-index: 200;
}

.nav-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    transition: color 0.15s, background 0.15s;
}

.nav-btn span.nav-icon {
    font-size: 1.25rem;
}

.nav-btn.active {
    color: var(--accent-gold);
    background: rgba(245, 185, 53, 0.12);
}

/* TOAST NOTIFICATION */
#toast-container {
    position: fixed;
    bottom: 82px;
    right: 16px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 320px;
}

.toast {
    background: #1e293b;
    border-left: 4px solid var(--accent-gold);
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.6);
    font-size: 0.83rem;
    animation: fadeIn 0.2s ease;
}

@media (max-width: 600px) {
    .resource-bar {
        grid-template-columns: repeat(2, 1fr);
    }
    .map-grid {
        grid-template-columns: repeat(15, 42px);
        grid-auto-rows: 42px;
    }
    .map-tile {
        width: 42px;
        height: 42px;
    }
}
