/* ═══════════════════════════════════════════════════════
   MAIN LAYOUT — Cozy Village Merge Game UI
   Warm, hand-drawn feel with village background
   ═══════════════════════════════════════════════════════ */

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

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─── Village Background ─── */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: url('../assets/bg.png') center center / cover no-repeat;
    z-index: 0;
    pointer-events: none;
    opacity: 0.6;
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    background: linear-gradient(180deg,
            rgba(44, 30, 16, 0.3) 0%,
            rgba(44, 30, 16, 0.1) 30%,
            rgba(44, 30, 16, 0.1) 70%,
            rgba(44, 30, 16, 0.5) 100%);
    z-index: 0;
    pointer-events: none;
}

/* ─── Particles ─── */
#particles-bg {
    position: fixed;
    inset: 0;
    z-index: var(--z-bg);
    pointer-events: none;
}

/* ─── Game Container ─── */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    z-index: var(--z-grid);
}

/* ═══════════════════════════════════════════════════════
   HUD — Warm Wooden Top Bar
   ═══════════════════════════════════════════════════════ */

#hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--hud-height);
    background: linear-gradient(180deg, rgba(58, 38, 18, 0.95), rgba(44, 28, 12, 0.92));
    backdrop-filter: blur(var(--hud-blur));
    -webkit-backdrop-filter: blur(var(--hud-blur));
    border-bottom: 2px solid rgba(200, 170, 100, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    z-index: var(--z-hud);
    box-shadow: 0 3px 20px rgba(30, 15, 5, 0.6);
}

.hud-left {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    min-width: 0;
}

.game-logo {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.2rem;
    background: linear-gradient(135deg, #ffe066, #ffd700, #e8a020);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    letter-spacing: 2px;
    filter: drop-shadow(0 2px 4px rgba(200, 150, 40, 0.4));
}

.game-logo .version {
    font-family: var(--font-body);
    font-size: 0.5rem;
    font-weight: 400;
    -webkit-text-fill-color: var(--text-muted);
    vertical-align: super;
    margin-left: 4px;
}

/* ─── CSS Icons (no emojis) ─── */
.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.icon-coin {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #ffe066, #ffd700, #b8860b);
    box-shadow: 0 2px 6px rgba(255, 215, 0, 0.5), inset 0 -2px 3px rgba(0, 0, 0, 0.2);
    position: relative;
}

.icon-coin::after {
    content: 'G';
    font-size: 0.55rem;
    font-weight: 900;
    color: #6b4c00;
    font-family: var(--font-display);
}

.icon-star {
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, #c084fc, #8b5cf6);
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.icon-trophy {
    width: 16px;
    height: 16px;
    background: linear-gradient(135deg, #ffd700, #f59e0b);
    clip-path: polygon(15% 0%, 85% 0%, 100% 30%, 80% 30%, 75% 60%, 60% 70%, 60% 100%, 40% 100%, 40% 70%, 25% 60%, 20% 30%, 0% 30%);
}

/* ─── Resource Capsules ─── */
.hud-center {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    flex: 1;
    justify-content: center;
}

.resource-capsule {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(180deg, rgba(70, 50, 25, 0.95), rgba(50, 35, 18, 0.98));
    border: 1.5px solid rgba(200, 170, 100, 0.2);
    border-radius: 20px;
    padding: 6px 16px 6px 8px;
    position: relative;
    min-width: 130px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 225, 150, 0.08);
}

.resource-capsule .res-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.resource-capsule .res-icon.gold-icon {
    background: radial-gradient(circle at 35% 35%, #ffee88, #ffd700, #cc9900);
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.4);
}

.resource-capsule .res-icon.gold-icon::after {
    content: 'G';
    font-size: 0.75rem;
    font-weight: 900;
    color: #6b4c00;
    font-family: var(--font-display);
}

.resource-capsule .res-icon.xp-icon {
    background: radial-gradient(circle at 35% 35%, #c084fc, #8b5cf6, #6d28d9);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.35);
}

.resource-capsule .res-icon.xp-icon::after {
    content: '';
    width: 14px;
    height: 14px;
    background: white;
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.resource-capsule .res-values {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.resource-capsule .res-main {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
    transition: transform 0.1s var(--ease-elastic);
}

.resource-capsule .res-main.pop {
    transform: scale(1.12);
}

.resource-capsule .res-sub {
    font-size: 0.6rem;
    color: var(--text-muted);
    font-weight: 500;
    line-height: 1;
}

/* ─── XP Bar ─── */
.xp-capsule {
    position: relative;
    min-width: 150px;
}

.xp-bar-outer {
    width: 100%;
    height: 8px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 2px;
    border: 1px solid rgba(139, 92, 246, 0.15);
}

.xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #8b5cf6, #a78bfa, #c084fc);
    border-radius: 4px;
    width: 0%;
    transition: width 0.5s var(--ease-out);
    position: relative;
}

.xp-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.3), transparent);
    border-radius: 4px 4px 0 0;
}

.level-badge {
    position: absolute;
    right: -6px;
    top: -6px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 800;
    color: white;
    border: 2px solid var(--bg-primary);
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.4);
    font-family: var(--font-display);
    z-index: 2;
}

.level-badge.glow {
    animation: levelGlow 1.5s ease-out;
}

@keyframes levelGlow {
    0% {
        box-shadow: 0 0 12px rgba(245, 158, 11, 0.6), 0 0 30px rgba(245, 158, 11, 0.4);
        transform: scale(1.2);
    }

    100% {
        box-shadow: 0 2px 6px rgba(245, 158, 11, 0.4);
        transform: scale(1);
    }
}

/* ─── HUD Right ─── */
.hud-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.hud-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(80, 55, 30, 0.9), rgba(55, 38, 18, 0.95));
    border: 1.5px solid rgba(200, 170, 100, 0.15);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    font-family: var(--font-body);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hud-btn:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 215, 0, 0.3);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    color: var(--gold-400);
}

.hud-btn:active {
    transform: translateY(1px) scale(0.95);
}

.hud-btn.active {
    background: linear-gradient(180deg, rgba(255, 215, 0, 0.12), rgba(255, 215, 0, 0.05));
    border-color: rgba(255, 215, 0, 0.2);
    color: var(--gold-400);
}

.high-score-display {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: nowrap;
    background: rgba(0, 0, 0, 0.25);
    padding: 4px 10px;
    border-radius: 10px;
    border: 1px solid rgba(200, 170, 100, 0.1);
    font-weight: 600;
}

/* ═══════════════════════════════════════════════════════
   MAIN CONTENT — GAME GRID
   Rounded dark container like the reference image
   ═══════════════════════════════════════════════════════ */

#main-area {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: calc(var(--hud-height) + 8px) 12px 8px;
    position: relative;
    overflow: hidden;
}

#grid-wrapper {
    position: relative;
    transform: none;
    transition: transform 0.3s var(--ease-out);
    width: 100%;
    max-width: 520px;
    overflow: hidden;
}

/* Outer wooden frame border */
#grid-wrapper::before {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: 22px;
    background: linear-gradient(145deg, #5a4a6e, #3a3050, #4a3a5e);
    z-index: -1;
    box-shadow:
        0 8px 40px rgba(0, 0, 0, 0.7),
        0 4px 20px rgba(60, 40, 90, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

/* Inner accent line */
#grid-wrapper::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 18px;
    border: 1.5px solid rgba(180, 160, 200, 0.15);
    z-index: -1;
    pointer-events: none;
}

#grid {
    display: grid;
    gap: 6px;
    padding: 10px;
    border-radius: 16px;
    background: linear-gradient(145deg, #2e2844, #262040, #2e2844);
    position: relative;
    overflow: hidden;
    width: 100%;
    box-shadow: inset 0 3px 15px rgba(0, 0, 0, 0.5);
}

/* Subtle pattern overlay */
#grid::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 16px;
    background:
        repeating-linear-gradient(90deg, transparent 0px, transparent 10px, rgba(255, 255, 255, 0.01) 10px, rgba(255, 255, 255, 0.01) 11px),
        repeating-linear-gradient(0deg, transparent 0px, transparent 10px, rgba(255, 255, 255, 0.01) 10px, rgba(255, 255, 255, 0.01) 11px);
    pointer-events: none;
    z-index: 0;
}

/* Shimmer sweep */
#grid::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.02), transparent);
    animation: gridShimmer 15s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
    border-radius: 16px;
}

@keyframes gridShimmer {

    0%,
    100% {
        left: -50%;
    }

    50% {
        left: 100%;
    }
}

/* ─── Grid Cells ─── */
.grid-cell {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 14px;
    position: relative;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all var(--transition-fast);
}

.grid-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 14px;
    background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.02), transparent);
    pointer-events: none;
}

.grid-cell.highlight-valid {
    background: rgba(82, 184, 106, 0.2) !important;
    border-color: rgba(82, 184, 106, 0.5);
    box-shadow: inset 0 0 20px rgba(82, 184, 106, 0.15), 0 0 12px rgba(82, 184, 106, 0.2);
}

.grid-cell.highlight-invalid {
    background: rgba(220, 80, 60, 0.15) !important;
    border-color: rgba(220, 80, 60, 0.4);
    box-shadow: inset 0 0 15px rgba(220, 80, 60, 0.1);
}

.grid-cell.occupied {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
}

.grid-full-warning {
    animation: gridFullFlash 0.6s ease-out 3;
}

@keyframes gridFullFlash {

    0%,
    100% {
        box-shadow: none;
    }

    50% {
        box-shadow: 0 0 0 3px rgba(220, 80, 60, 0.5);
    }
}

/* ═══════════════════════════════════════════════════════
   ACTION BAR — Warm Village Buttons
   ═══════════════════════════════════════════════════════ */

#action-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 8px 16px 16px;
    position: relative;
    z-index: var(--z-hud);
    flex-shrink: 0;
}

.action-btn {
    position: relative;
    padding: 10px 20px;
    border-radius: 12px;
    border: none;
    font-family: var(--font-display);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2), 0 6px 16px rgba(0, 0, 0, 0.25);
    color: white;
}

.action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.2), transparent);
    border-radius: 12px 12px 0 0;
    pointer-events: none;
}

/* Spawn — green */
.action-btn:nth-child(1) {
    background: linear-gradient(180deg, #5cc472, #3a9e50);
    box-shadow: 0 4px 0 #2a7a38, 0 6px 16px rgba(58, 158, 80, 0.3);
}

/* Power Spawn — purple */
.action-btn:nth-child(2) {
    background: linear-gradient(180deg, #a88bde, #7c5ac0);
    box-shadow: 0 4px 0 #5a3a98, 0 6px 16px rgba(124, 90, 192, 0.3);
}

/* Clear — orange */
.action-btn:nth-child(3) {
    background: linear-gradient(180deg, #f0a048, #d87820);
    box-shadow: 0 4px 0 #b06018, 0 6px 16px rgba(216, 120, 32, 0.3);
}

.action-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.action-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.15);
}

.action-btn.disabled {
    filter: grayscale(0.6) brightness(0.5);
    cursor: not-allowed;
    pointer-events: none;
}

.action-btn .cost {
    font-weight: 800;
    font-size: 0.72rem;
    opacity: 0.9;
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 8px;
    border-radius: 6px;
    font-family: var(--font-body);
}

/* ═══════════════════════════════════════════════════════
   SIDEBARS — Village Wood Panels
   ═══════════════════════════════════════════════════════ */

#civ-log {
    position: fixed;
    top: var(--hud-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, rgba(50, 35, 18, 0.98), rgba(40, 28, 14, 0.99));
    backdrop-filter: blur(20px);
    border-right: 2px solid rgba(200, 170, 100, 0.12);
    z-index: var(--z-sidebar);
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    overflow-y: auto;
    padding: var(--space-lg);
    scrollbar-width: thin;
    scrollbar-color: rgba(200, 170, 100, 0.2) transparent;
}

#civ-log.open {
    transform: translateX(0);
}

.civ-log-title {
    font-family: var(--font-display);
    font-size: 0.95rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: var(--space-lg);
    letter-spacing: 3px;
    text-transform: uppercase;
}

.civ-log-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 8px var(--space-md);
    margin-bottom: 4px;
    border-radius: 10px;
    background: rgba(245, 234, 208, 0.03);
    border: 1px solid rgba(200, 170, 100, 0.06);
    transition: all var(--transition-fast);
}

.civ-log-item.discovered {
    border-color: rgba(200, 170, 100, 0.12);
}

.civ-log-item.discovered:hover {
    background: rgba(245, 234, 208, 0.06);
    transform: translateX(4px);
}

.civ-log-item .tier-preview {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    font-weight: 800;
    font-family: var(--font-display);
    color: white;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.civ-log-item .tier-info {
    flex: 1;
    min-width: 0;
}

.civ-log-item .tier-name {
    font-weight: 600;
    font-size: 0.8rem;
}

.civ-log-item .tier-gps {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.civ-log-item .tier-count {
    font-size: 0.75rem;
    color: var(--gold-400);
    font-weight: 700;
    background: rgba(255, 215, 0, 0.08);
    padding: 2px 8px;
    border-radius: 8px;
}

.civ-log-item.locked .tier-name {
    color: var(--text-muted);
}

.civ-log-item.locked .lock-icon {
    font-size: 0.7rem;
    opacity: 0.3;
}

/* ─── Shop Panel ─── */
#shop-panel {
    position: fixed;
    top: var(--hud-height);
    right: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, rgba(50, 35, 18, 0.98), rgba(40, 28, 14, 0.99));
    backdrop-filter: blur(20px);
    border-left: 2px solid rgba(200, 170, 100, 0.12);
    z-index: var(--z-sidebar);
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    overflow-y: auto;
    padding: var(--space-lg);
}

#shop-panel.open {
    transform: translateX(0);
}

.shop-title {
    font-family: var(--font-display);
    font-size: 0.95rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: var(--space-lg);
    letter-spacing: 3px;
    text-transform: uppercase;
}

.shop-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 12px;
    background: rgba(245, 234, 208, 0.03);
    border: 1px solid rgba(200, 170, 100, 0.08);
    transition: all var(--transition-fast);
    cursor: pointer;
}

.shop-item:hover {
    background: rgba(245, 234, 208, 0.07);
    border-color: rgba(255, 215, 0, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.shop-item.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none !important;
}

.shop-item .item-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.shop-item .item-icon {
    font-size: 1.3rem;
}

.shop-item .item-name {
    font-weight: 600;
    font-size: 0.85rem;
    flex: 1;
}

.shop-item .item-cost {
    color: var(--gold-400);
    font-weight: 800;
    font-size: 0.8rem;
}

.shop-item .item-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.3;
}

.shop-item .item-status {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--gem-purple);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ─── Shop Section Headings ─── */
.shop-section-heading {
    font-family: var(--font-display);
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 16px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(200, 170, 100, 0.1);
}

/* ─── Shop Tile Buy Buttons ─── */
#shop-tile-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.shop-action-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(200, 170, 100, 0.1);
    background: rgba(245, 234, 208, 0.03);
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
    text-align: left;
    gap: 10px;
}

.shop-action-btn:hover {
    background: rgba(245, 234, 208, 0.08);
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.shop-action-btn.shop-spawn {
    border-left: 3px solid #5cc472;
}

.shop-action-btn.shop-power {
    border-left: 3px solid #a88bde;
}

.shop-action-btn.shop-clear {
    border-left: 3px solid #f0a048;
}

.shop-action-btn.shop-tier-buy {
    border-left: 3px solid var(--gold-400);
}

.shop-action-label {
    font-weight: 700;
    font-size: 0.82rem;
    letter-spacing: 0.5px;
    display: block;
}

.shop-action-desc {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 2px;
    display: block;
}

.shop-action-cost {
    font-weight: 800;
    font-size: 0.8rem;
    color: var(--gold-400);
    background: rgba(255, 215, 0, 0.08);
    padding: 3px 10px;
    border-radius: 8px;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ─── Ad Reward Card ─── */
.ad-reward-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.08), rgba(255, 180, 0, 0.04));
    border: 1.5px solid rgba(255, 215, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.ad-reward-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 215, 0, 0.06), transparent);
    animation: adShimmer 3s ease-in-out infinite;
}

@keyframes adShimmer {

    0%,
    100% {
        transform: translateX(-100%);
    }

    50% {
        transform: translateX(100%);
    }
}

/* Coin Bag Icon (CSS-only) */
.ad-reward-icon {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    position: relative;
}

.coin-bag-body {
    width: 36px;
    height: 30px;
    background: linear-gradient(145deg, #d4a340, #b8860b, #d4a340);
    border-radius: 4px 4px 14px 14px;
    position: absolute;
    bottom: 4px;
    left: 6px;
    box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.3);
}

.coin-bag-body::before {
    content: '$';
    position: absolute;
    width: 100%;
    text-align: center;
    top: 6px;
    font-size: 14px;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.7);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.coin-bag-body::after {
    content: '';
    position: absolute;
    top: -8px;
    left: 8px;
    width: 20px;
    height: 12px;
    background: linear-gradient(145deg, #d4a340, #b8860b);
    border-radius: 50% 50% 0 0;
    border: 2px solid #a07020;
    border-bottom: none;
}

.coin-bag-coins {
    position: absolute;
    top: 0;
    right: 0;
}

.coin {
    display: block;
    width: 14px;
    height: 14px;
    background: radial-gradient(circle at 40% 35%, #ffe066, #ffd700, #e8a020);
    border-radius: 50%;
    border: 1.5px solid #c89020;
    position: absolute;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.coin.c1 {
    top: 0;
    right: 0;
}

.coin.c2 {
    top: 6px;
    right: 8px;
}

.coin.c3 {
    top: 12px;
    right: 2px;
}

.ad-reward-info {
    flex: 1;
    z-index: 1;
}

.ad-reward-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gold-400);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.ad-reward-desc {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.ad-reward-btn {
    padding: 10px 18px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(180deg, #5cc472, #3a9e50);
    color: white;
    font-family: var(--font-display);
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 3px 0 #2a7a38, 0 5px 12px rgba(58, 158, 80, 0.3);
    z-index: 1;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-width: 70px;
    text-align: center;
}

.ad-reward-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 0 #2a7a38, 0 8px 20px rgba(58, 158, 80, 0.4);
}

.ad-reward-btn:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #2a7a38;
}

.ad-reward-btn.on-cooldown {
    background: linear-gradient(180deg, rgba(200, 170, 100, 0.2), rgba(200, 170, 100, 0.1));
    color: var(--text-muted);
    box-shadow: none;
    cursor: not-allowed;
}

.ad-btn-timer {
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 600;
}

/* ─── Auto Merge Indicator ─── */
.auto-merge-indicator {
    display: none;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
    font-weight: 700;
    color: #52b86a;
    background: rgba(82, 184, 106, 0.1);
    padding: 3px 8px;
    border-radius: 8px;
    border: 1px solid rgba(82, 184, 106, 0.2);
}

.auto-merge-indicator.active {
    display: flex;
}

.auto-merge-indicator .pulse-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #52b86a;
    animation: pulseDot 1s infinite;
}

@keyframes pulseDot {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.4;
        transform: scale(1.4);
    }
}

/* ═══════════════════════════════════════════════════════
   EFFECTS LAYER & UI ELEMENTS
   ═══════════════════════════════════════════════════════ */

#effects-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: var(--z-effects);
}

.floating-text {
    position: absolute;
    font-weight: 800;
    font-size: 0.95rem;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7), 0 0 20px currentColor;
    pointer-events: none;
    white-space: nowrap;
    font-family: var(--font-display);
}

.merge-ring {
    position: absolute;
    border: 2px solid;
    border-radius: 50%;
    pointer-events: none;
}

.particle-burst {
    position: absolute;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    pointer-events: none;
}

.gold-coin-rain {
    position: fixed;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #ffe066, #ffd700, #b8860b);
    pointer-events: none;
    z-index: var(--z-effects);
    animation: goldFall 2.5s ease-in forwards;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

@keyframes goldFall {
    0% {
        opacity: 1;
        transform: translateY(-20px) rotate(0deg);
    }

    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(720deg);
    }
}

/* ─── Level Up Banner ─── */
#level-up-banner {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #f0a048, #d87820);
    color: white;
    padding: 10px 28px;
    border-radius: 16px;
    font-family: var(--font-display);
    font-size: 1.1rem;
    text-align: center;
    z-index: var(--z-modal);
    box-shadow: 0 4px 0 #b06018, 0 8px 30px rgba(216, 120, 32, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.2);
    white-space: nowrap;
    letter-spacing: 1px;
}

#level-up-banner .bonus {
    display: block;
    font-family: var(--font-body);
    font-size: 0.65rem;
    font-weight: 500;
    opacity: 0.85;
    margin-top: 2px;
}

/* ─── Power-Up Timers ─── */
#powerup-timers {
    position: fixed;
    top: calc(var(--hud-height) + 10px);
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: var(--z-hud);
}

.powerup-timer {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(240, 160, 72, 0.12);
    border: 1px solid rgba(240, 160, 72, 0.2);
    border-radius: 10px;
    padding: 4px 10px;
    font-size: 0.7rem;
    color: #f0a048;
    font-weight: 700;
    backdrop-filter: blur(8px);
}

/* ═══════════════════════════════════════════════════════
   SIDEBAR BACKDROP
   ═══════════════════════════════════════════════════════ */

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20, 12, 4, 0.6);
    z-index: calc(var(--z-sidebar) + 5);
    cursor: pointer;
}

.sidebar-backdrop.visible {
    display: block;
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */

@media (min-width: 1025px) {
    #civ-log {
        transform: translateX(0);
        left: 0;
        box-shadow: 10px 0 40px rgba(0, 0, 0, 0.6);
        background: linear-gradient(180deg, rgba(55, 40, 22, 0.95), rgba(40, 28, 14, 0.98));
    }

    #shop-panel {
        transform: translateX(0);
        right: 0;
        box-shadow: -10px 0 40px rgba(0, 0, 0, 0.6);
        background: linear-gradient(180deg, rgba(55, 40, 22, 0.95), rgba(40, 28, 14, 0.98));
    }

    #btn-civ-log,
    #btn-shop {
        display: none !important;
    }

    #main-area {
        padding-left: calc(var(--sidebar-width) + 32px);
        padding-right: calc(var(--sidebar-width) + 32px);
        padding-top: calc(var(--hud-height) + 24px);
    }

    #grid-wrapper {
        max-width: 600px;
    }
}

@media (max-width: 1024px) {
    :root {
        --sidebar-width: 250px;
    }

    .game-logo {
        font-size: 1rem;
    }

    .resource-capsule {
        min-width: 110px;
        padding: 5px 12px 5px 6px;
    }

    .resource-capsule .res-main {
        font-size: 0.9rem;
    }
}

@media (max-width: 768px) {
    #grid-wrapper {
        max-width: 95vw;
    }

    #main-area {
        padding-top: calc(var(--hud-height) + 8px);
        padding-bottom: 120px;
    }

    .action-btn {
        padding: 8px 14px;
        font-size: 0.7rem;
    }

    #action-bar {
        gap: 6px;
        padding: 6px 10px 12px;
    }
}

@media (max-width: 600px) {
    :root {
        --hud-height: 54px;
    }

    #hud {
        padding: 0 8px;
    }

    .game-logo {
        display: none;
    }

    .hud-center {
        gap: 4px;
    }

    .resource-capsule {
        min-width: 70px;
        padding: 3px 6px 3px 4px;
        gap: 4px;
    }

    .resource-capsule .res-icon {
        width: 22px;
        height: 22px;
    }

    .resource-capsule .res-main {
        font-size: 0.75rem;
    }

    .resource-capsule .res-sub {
        font-size: 0.45rem;
    }

    .hud-right {
        gap: 3px;
    }

    .hud-btn {
        width: 34px;
        height: 34px;
        font-size: 0.6rem;
    }

    .high-score-display {
        display: none;
    }

    .xp-capsule {
        min-width: 90px;
    }

    /* Action bar fixed above tab bar */
    #action-bar {
        position: fixed;
        bottom: 50px;
        left: 0;
        right: 0;
        flex-wrap: wrap;
        gap: 4px;
        padding: 8px 12px;
        background: linear-gradient(180deg, rgba(50, 35, 18, 0.95), rgba(40, 28, 14, 0.98));
        backdrop-filter: blur(12px);
        border-top: 1px solid rgba(200, 170, 100, 0.1);
        z-index: var(--z-hud);
        justify-content: center;
    }

    .action-btn {
        padding: 7px 12px;
        font-size: 0.65rem;
    }

    #civ-log,
    #shop-panel {
        width: 80vw;
        max-width: 320px;
        z-index: calc(var(--z-sidebar) + 10);
    }

    #powerup-timers {
        right: 6px;
    }

    #grid-wrapper {
        max-width: 92vw;
        margin: auto;
        overflow: hidden;
    }

    #main-area {
        padding-bottom: 110px;
    }
}

@media (max-width: 400px) {
    .hud-btn {
        width: 30px;
        height: 30px;
        font-size: 0.5rem;
    }

    .xp-capsule {
        display: none;
    }

    .resource-capsule {
        min-width: 60px;
    }

    #grid {
        padding: 6px;
        gap: 4px;
    }

    #grid-wrapper {
        max-width: 96vw;
    }

    .action-btn {
        padding: 6px 10px;
        font-size: 0.6rem;
    }
}

/* ─── Mobile Tab Bar ─── */
#mobile-tab-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: linear-gradient(180deg, rgba(50, 35, 18, 0.97), rgba(40, 28, 14, 0.99));
    backdrop-filter: blur(12px);
    border-top: 1px solid rgba(200, 170, 100, 0.1);
    z-index: calc(var(--z-hud) + 5);
    align-items: center;
    justify-content: space-around;
}

@media (max-width: 600px) {
    #mobile-tab-bar {
        display: flex;
    }
}

/* ─── Sidebar Close Button ─── */
.sidebar-close-btn {
    display: none;
}

@media (max-width: 600px) {
    .sidebar-close-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 10px;
        margin-bottom: 10px;
        background: rgba(220, 80, 60, 0.1);
        border: 1px solid rgba(220, 80, 60, 0.25);
        border-radius: 10px;
        color: #e06050;
        font-family: var(--font-body);
        font-size: 0.75rem;
        font-weight: 700;
        cursor: pointer;
        text-transform: uppercase;
        letter-spacing: 1px;
        transition: all 0.2s;
    }

    .sidebar-close-btn:hover,
    .sidebar-close-btn:active {
        background: rgba(220, 80, 60, 0.2);
    }
}

.tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 700;
    cursor: pointer;
    padding: 6px 16px;
    border-radius: 6px;
    transition: all var(--transition-fast);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: var(--font-display);
}

.tab-btn.active {
    color: var(--gold-400);
}

/* ─── FPS Counter ─── */
#fps-counter {
    position: fixed;
    bottom: 4px;
    left: 4px;
    font-size: 0.5rem;
    color: var(--text-muted);
    z-index: 9999;
    font-family: monospace;
    pointer-events: none;
    opacity: 0.3;
}