/* ===== GLOBAL RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    /* Safe area for iPhone notch / Dynamic Island / home indicator */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    /* Prevent iOS bounce / elastic scroll */
    overscroll-behavior: none;
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #0a1628;
    color: #e0e8f0;
    overflow: hidden;
    user-select: none;
    /* Prevent double-tap zoom everywhere */
    touch-action: manipulation;
    /* Prevent text selection on long-press */
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    width: 100vw;
    height: 100%;
    min-height: 100vh;
    /* iOS standalone: use full screen */
    min-height: -webkit-fill-available;
    overscroll-behavior: none;
}

/* When launched from home screen (standalone) */
.is-standalone body {
    /* Extra bottom padding for home indicator */
    padding-bottom: max(env(safe-area-inset-bottom), 8px);
}

/* ===== PWA: PORTRAIT WARNING OVERLAY ===== */
#portrait-warning {
    display: none;
    position: fixed;
    inset: 0;
    background: #0a1628;
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}
.pw-inner {
    text-align: center;
    padding: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.pw-icon {
    font-size: 56px;
    animation: pw-sway 1.5s ease-in-out infinite alternate;
}
.pw-arrow {
    font-size: 48px;
    color: #38bdf8;
    font-weight: 900;
    animation: pw-spin 2s linear infinite;
    display: inline-block;
}
@keyframes pw-sway {
    from { transform: rotate(-20deg); }
    to   { transform: rotate(20deg); }
}
@keyframes pw-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}
#portrait-warning h2 {
    font-size: 1.6rem;
    font-weight: 800;
    color: #e0f0ff;
    margin: 0;
}
#portrait-warning p {
    font-size: 1rem;
    color: #7eb8e0;
    line-height: 1.5;
}

/* ===== PWA: ANDROID INSTALL BANNER ===== */
#pwa-install-banner {
    position: fixed;
    bottom: -100px;
    left: 12px;
    right: 12px;
    background: linear-gradient(135deg, #0f2040, #1a3060);
    border: 1.5px solid rgba(56,189,248,0.35);
    border-radius: 18px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1000;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    transition: bottom 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    backdrop-filter: blur(12px);
}
#pwa-install-banner.pwa-visible { bottom: max(12px, env(safe-area-inset-bottom)); }
.pwa-banner-icon { font-size: 2rem; flex-shrink: 0; }
.pwa-banner-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.pwa-banner-text strong { font-size: 0.9rem; color: #e0f0ff; }
.pwa-banner-text span   { font-size: 0.75rem; color: #7eb8e0; }
.pwa-banner-install {
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 8px 18px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    min-height: 36px;
    transition: opacity 0.15s;
}
.pwa-banner-install:active { opacity: 0.8; }
.pwa-banner-close {
    background: none;
    border: none;
    color: #64748b;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px 6px;
    flex-shrink: 0;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== PWA: iOS INSTALL TIP ===== */
#ios-install-tip {
    position: fixed;
    bottom: -300px;
    left: 12px;
    right: 12px;
    background: linear-gradient(180deg, #0f2040, #0a1628);
    border: 1.5px solid rgba(56,189,248,0.3);
    border-radius: 20px 20px 16px 16px;
    padding: 0 16px 20px;
    z-index: 1000;
    box-shadow: 0 -4px 40px rgba(0,0,0,0.6);
    transition: bottom 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    backdrop-filter: blur(16px);
}
#ios-install-tip.ios-tip-visible { bottom: max(8px, env(safe-area-inset-bottom)); }
.ios-tip-handle {
    width: 40px; height: 4px;
    background: rgba(148,163,184,0.35);
    border-radius: 2px;
    margin: 12px auto 14px;
}
.ios-tip-body {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 14px;
}
.ios-tip-icon { font-size: 2.2rem; flex-shrink: 0; }
.ios-tip-text strong { display: block; font-size: 1rem; color: #e0f0ff; margin-bottom: 6px; }
.ios-tip-text p { font-size: 0.85rem; color: #94a3b8; line-height: 1.5; margin-bottom: 4px; }
.ios-tip-text .ios-tip-sub { font-size: 0.75rem; color: #60a0c0; }
.ios-tip-arrow {
    text-align: center;
    font-size: 1.4rem;
    color: #38bdf8;
    margin-bottom: 10px;
    animation: bounce-arr 1s ease-in-out infinite alternate;
}
@keyframes bounce-arr {
    from { transform: translateY(0); }
    to   { transform: translateY(6px); }
}
.ios-tip-close {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(148,163,184,0.2);
    background: rgba(148,163,184,0.06);
    color: #64748b;
    font-size: 0.9rem;
    cursor: pointer;
    min-height: 44px;
}

/* ===== PWA: OFFLINE BANNER ===== */
#offline-banner {
    position: fixed;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15,25,45,0.95);
    border: 1px solid rgba(56,189,248,0.3);
    border-radius: 24px;
    padding: 8px 20px;
    font-size: 0.82rem;
    color: #7dd3fc;
    z-index: 900;
    white-space: nowrap;
    transition: top 0.3s ease;
    backdrop-filter: blur(8px);
}
#offline-banner.offline-visible {
    top: max(calc(env(safe-area-inset-top) + 8px), 54px);
}

/* ===== PWA: UPDATE BANNER ===== */
#update-banner {
    position: fixed;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #0f4020, #0a3018);
    border: 1px solid rgba(52,211,153,0.4);
    border-radius: 24px;
    padding: 10px 16px 10px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.82rem;
    color: #6ee7b7;
    z-index: 900;
    white-space: nowrap;
    transition: top 0.3s ease;
    backdrop-filter: blur(8px);
}
#update-banner.update-visible {
    top: max(calc(env(safe-area-inset-top) + 8px), 54px);
}
#update-banner button {
    background: #10b981;
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 5px 12px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 30px;
}

/* ===== FULLSCREEN GATE (Android + iOS, every session) ===== */
#fs-gate {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
#fs-gate.fsg-visible {
    opacity: 1;
    pointer-events: auto;
}
.fsg-bg {
    position: absolute;
    inset: 0;
    background: rgba(5, 12, 28, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.fsg-card {
    position: relative;
    background: linear-gradient(170deg, #0f1e36 0%, #0a1220 100%);
    border: 1.5px solid rgba(56, 189, 248, 0.28);
    border-radius: 28px 28px 0 0;
    padding: 32px 24px max(32px, env(safe-area-inset-bottom));
    width: 100%;
    max-width: 500px;
    transform: translateY(100%);
    transition: transform 0.42s cubic-bezier(0.32, 0.72, 0, 1);
    text-align: center;
}
#fs-gate.fsg-visible .fsg-card {
    transform: translateY(0);
}
.fsg-icon { font-size: 3.2rem; margin-bottom: 14px; display: block; }
.fsg-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: #e2f0ff;
    line-height: 1.25;
    margin-bottom: 10px;
}
.fsg-sub {
    font-size: 0.9rem;
    color: #7eb8e0;
    line-height: 1.55;
    margin-bottom: 22px;
}
.fsg-sub strong { color: #38bdf8; }

/* Android: big primary button */
.fsg-btn-main {
    display: block;
    width: 100%;
    padding: 16px;
    border-radius: 16px;
    border: none;
    background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
    color: #fff;
    font-size: 1.05rem;
    font-weight: 800;
    cursor: pointer;
    min-height: 54px;
    margin-bottom: 12px;
    box-shadow: 0 4px 20px rgba(14, 165, 233, 0.35);
    transition: opacity 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}
.fsg-btn-main:active { opacity: 0.85; transform: scale(0.98); }

/* iOS: steps */
.fsg-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 18px;
    text-align: left;
}
.fsg-step {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(56, 189, 248, 0.06);
    border: 1px solid rgba(56, 189, 248, 0.14);
    border-radius: 12px;
    padding: 11px 14px;
    font-size: 0.87rem;
    color: #b0cce0;
    line-height: 1.4;
}
.fsg-step strong { color: #7dd3fc; }
.fsg-num {
    min-width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.fsg-arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: #38bdf8;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 18px;
}
.fsg-bounce {
    font-size: 1.5rem;
    animation: fsg-b 0.7s ease-in-out infinite alternate;
    display: inline-block;
}
@keyframes fsg-b {
    from { transform: translateY(-2px); }
    to   { transform: translateY(5px); }
}

/* Skip button */
.fsg-btn-skip {
    display: block;
    width: 100%;
    padding: 13px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    background: transparent;
    color: #4e657a;
    font-size: 0.85rem;
    cursor: pointer;
    min-height: 44px;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.fsg-btn-skip:active { background: rgba(148, 163, 184, 0.08); }

/* ===== iOS FULLSCREEN GUIDE (full overlay) ===== */
#ios-fullscreen-guide {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}
#ios-fullscreen-guide.ifg-visible {
    opacity: 1;
    pointer-events: auto;
}
.ifg-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(5, 12, 28, 0.88);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.ifg-card {
    position: relative;
    background: linear-gradient(180deg, #0f1e36 0%, #0a1628 100%);
    border: 1.5px solid rgba(56, 189, 248, 0.3);
    border-radius: 28px 28px 0 0;
    padding: 28px 24px max(32px, env(safe-area-inset-bottom));
    width: 100%;
    max-width: 480px;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    text-align: center;
}
#ios-fullscreen-guide.ifg-visible .ifg-card {
    transform: translateY(0);
}
.ifg-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}
.ifg-title {
    font-size: 1.4rem;
    font-weight: 800;
    color: #e0f0ff;
    line-height: 1.3;
    margin-bottom: 10px;
}
.ifg-sub {
    font-size: 0.85rem;
    color: #7eb8e0;
    line-height: 1.5;
    margin-bottom: 20px;
}
.ifg-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 18px;
    text-align: left;
}
.ifg-step {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(56, 189, 248, 0.06);
    border: 1px solid rgba(56, 189, 248, 0.15);
    border-radius: 12px;
    padding: 10px 14px;
}
.ifg-step-num {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ifg-step-text {
    font-size: 0.88rem;
    color: #c0d8f0;
    line-height: 1.4;
}
.ifg-step-text strong {
    color: #7dd3fc;
}
.ifg-benefits {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-bottom: 20px;
}
.ifg-benefits span {
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid rgba(52, 211, 153, 0.2);
    border-radius: 20px;
    padding: 4px 10px;
    font-size: 0.75rem;
    color: #6ee7b7;
}
.ifg-arrow-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-bottom: 16px;
    color: #38bdf8;
}
.ifg-arrow-text {
    font-size: 0.8rem;
    font-weight: 600;
}
.ifg-bounce {
    font-size: 1.4rem;
    animation: ifg-bounce 0.8s ease-in-out infinite alternate;
    display: inline-block;
}
@keyframes ifg-bounce {
    from { transform: translateY(-3px); }
    to   { transform: translateY(4px); }
}
.ifg-btn-later {
    width: 100%;
    padding: 14px;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.15);
    background: rgba(148, 163, 184, 0.05);
    color: #64748b;
    font-size: 0.9rem;
    cursor: pointer;
    min-height: 48px;
    transition: background 0.15s;
}
.ifg-btn-later:active {
    background: rgba(148, 163, 184, 0.12);
}

/* ===== LOADING SCREEN ===== */
#loading-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, #0a1628 0%, #1a2a4a 50%, #0d1f3c 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-content {
    text-align: center;
}

.loading-content h1 {
    font-size: 3rem;
    color: #7eb8e0;
    margin-bottom: 0.25rem;
    text-shadow: 0 0 20px rgba(126,184,224,0.3);
}

.loading-content h2 {
    font-size: 1.4rem;
    color: #9ec5db;
    font-weight: 300;
    margin-bottom: 2rem;
}

.loading-bar-container {
    width: 300px;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    margin: 0 auto 1rem;
    overflow: hidden;
}

.loading-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #4a90c4, #7eb8e0);
    border-radius: 3px;
    transition: width 0.3s ease;
}

#loading-text {
    color: #6a8faa;
    font-size: 0.9rem;
}

/* ===== INTRO SCREEN ===== */
#intro-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, #0a1628 0%, #1a2a4a 50%, #0d1f3c 100%);
    display: flex;
    align-items: safe center;
    justify-content: center;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 999;
}

.intro-content {
    text-align: center;
    max-width: 700px;
    padding: 2rem;
    margin: auto;
}

.intro-content h1 {
    font-size: 2.8rem;
    color: #7eb8e0;
    margin-bottom: 1rem;
    text-shadow: 0 0 20px rgba(126,184,224,0.3);
}

.intro-desc {
    font-size: 1.05rem;
    line-height: 1.7;
    color: #9eb8cc;
    margin-bottom: 2rem;
}

.intro-features {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
    flex-wrap: wrap;
}

.feature {
    background: rgba(126,184,224,0.08);
    border: 1px solid rgba(126,184,224,0.15);
    border-radius: 12px;
    padding: 1rem 1.2rem;
    min-width: 90px;
    transition: all 0.3s;
}

.feature:hover {
    background: rgba(126,184,224,0.15);
    transform: translateY(-3px);
}

.feature span {
    font-size: 2rem;
    display: block;
    margin-bottom: 0.4rem;
}

.feature p {
    font-size: 0.8rem;
    color: #8aaccc;
}

.btn-primary {
    background: linear-gradient(135deg, #3a7cc0, #5a9ad8);
    color: #fff;
    border: none;
    padding: 14px 48px;
    font-size: 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #4a8cd0, #6aaae8);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(58,124,192,0.4);
}

/* ===== GAME SCREEN ===== */
#game-screen {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== TOP BAR ===== */
#top-bar {
    height: 52px;
    background: linear-gradient(180deg, #0f1e36 0%, #142540 100%);
    border-bottom: 1px solid rgba(126,184,224,0.12);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 10;
    flex-shrink: 0;
}

.resource-group {
    display: flex;
    gap: 16px;
}

.resource {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(126,184,224,0.06);
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid rgba(126,184,224,0.1);
}

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

.res-label {
    font-size: 0.7rem;
    color: #6a8faa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.res-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: #a8d4f0;
    min-width: 55px;
    text-align: right;
}

.status-group {
    display: flex;
    gap: 12px;
}

.status-bar-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-bar-item > span:first-child {
    font-size: 0.9rem;
}

.status-bar {
    width: 80px;
    height: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    overflow: hidden;
}

.status-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.status-fill.happiness { background: linear-gradient(90deg, #e8b84a, #f0d060); }
.status-fill.education { background: linear-gradient(90deg, #4a90c4, #70b0e0); }
.status-fill.health { background: linear-gradient(90deg, #c45a5a, #e07070); }

.status-val {
    font-size: 0.75rem;
    color: #8aaccc;
    min-width: 32px;
}

.time-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.stage-badge {
    background: rgba(126,184,224,0.12);
    border: 1px solid rgba(126,184,224,0.2);
    padding: 3px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    color: #7eb8e0;
    font-weight: 600;
}

#game-time {
    font-size: 0.85rem;
    color: #8aaccc;
}

.speed-controls {
    display: flex;
    gap: 4px;
}

.btn-speed {
    background: rgba(126,184,224,0.08);
    border: 1px solid rgba(126,184,224,0.15);
    color: #7eb8e0;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.65rem;
    transition: all 0.2s;
}

.btn-speed:hover, .btn-speed.active {
    background: rgba(126,184,224,0.2);
    border-color: rgba(126,184,224,0.4);
}

/* ===== GAME AREA ===== */
#game-area {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

#game-canvas {
    flex: 1;
    cursor: grab;
    image-rendering: auto;
}

#game-canvas.placing {
    cursor: crosshair;
}

#game-canvas:active {
    cursor: grabbing;
}

#game-canvas {
    background: linear-gradient(180deg, #6cb4e6 0%, #a8d8f4 60%, #c8e8f8 100%);
}

/* ===== MINI MAP ===== */
#mini-map {
    position: absolute;
    bottom: 12px;
    left: 12px;
    border: 2px solid rgba(126,184,224,0.2);
    border-radius: 8px;
    background: rgba(10,22,40,0.85);
    backdrop-filter: blur(8px);
}

/* ===== SIDE PANEL ===== */
#side-panel {
    width: 260px;
    background: linear-gradient(180deg, #0f1e36 0%, #0c1a30 100%);
    border-left: 1px solid rgba(126,184,224,0.12);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: absolute;
    right: 0;
    top: 52px;
    bottom: 0;
    z-index: 10;
}

.panel-tabs {
    display: flex;
    border-bottom: 1px solid rgba(126,184,224,0.1);
    flex-shrink: 0;
}

.panel-tab {
    flex: 1;
    background: none;
    border: none;
    color: #6a8faa;
    padding: 10px 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.panel-tab:hover {
    color: #a8d4f0;
    background: rgba(126,184,224,0.05);
}

.panel-tab.active {
    color: #7eb8e0;
    border-bottom-color: #4a90c4;
    background: rgba(126,184,224,0.08);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.panel-content::-webkit-scrollbar {
    width: 4px;
}

.panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
    background: rgba(126,184,224,0.2);
    border-radius: 2px;
}

/* ===== BUILD PANEL ===== */
.build-category h3 {
    font-size: 0.8rem;
    color: #6a8faa;
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(126,184,224,0.08);
}

.build-category {
    margin-bottom: 16px;
}

.build-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.build-item {
    background: rgba(126,184,224,0.05);
    border: 1px solid rgba(126,184,224,0.1);
    border-radius: 8px;
    padding: 8px 6px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    position: relative;
}

/* ℹ️ button — hidden on desktop by default, shown on mobile */
.build-info-btn {
    display: none;
    position: absolute;
    top: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: rgba(56,189,248,0.18);
    color: #7dd3fc;
    font-size: 11px;
    cursor: pointer;
    line-height: 20px;
    padding: 0;
    z-index: 2;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.build-item:hover {
    background: rgba(126,184,224,0.12);
    border-color: rgba(126,184,224,0.3);
    transform: translateY(-1px);
}

.build-item.active {
    background: rgba(74,144,196,0.2);
    border-color: rgba(74,144,196,0.5);
    box-shadow: 0 0 10px rgba(74,144,196,0.2);
}

.build-item.disabled {
    opacity: 0.45;
    cursor: help;
    position: relative;
}

.build-item.disabled::after {
    content: '🔒';
    position: absolute;
    top: 3px;
    right: 5px;
    font-size: 0.6rem;
    opacity: 0.8;
}

.build-item .build-icon {
    font-size: 1.6rem;
    display: block;
    margin-bottom: 3px;
}

.build-item .build-name {
    font-size: 0.7rem;
    color: #a8d4f0;
    display: block;
    margin-bottom: 2px;
}

.build-item .build-cost {
    font-size: 0.6rem;
    color: #6a8faa;
}

/* ===== INFO TAB ===== */
#info-content h3 {
    font-size: 0.9rem;
    color: #7eb8e0;
    margin-bottom: 12px;
}

#stats-container .stat-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid rgba(126,184,224,0.06);
    font-size: 0.8rem;
}

.stat-row .stat-label {
    color: #6a8faa;
}

.stat-row .stat-value {
    color: #a8d4f0;
    font-weight: 600;
}

/* ===== EVENT LOG ===== */
#event-log {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.event-entry {
    background: rgba(126,184,224,0.05);
    border: 1px solid rgba(126,184,224,0.08);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 0.75rem;
}

.event-entry .event-time {
    color: #4a7090;
    font-size: 0.65rem;
    margin-bottom: 3px;
}

.event-entry .event-text {
    color: #9ec5db;
    line-height: 1.4;
}

.event-entry.positive { border-left: 3px solid #5ab87a; }
.event-entry.negative { border-left: 3px solid #c45a5a; }
.event-entry.neutral { border-left: 3px solid #7eb8e0; }

/* ===== TOOLTIP ===== */
#building-tooltip {
    position: fixed;
    background: rgba(15,30,54,0.95);
    border: 1px solid rgba(126,184,224,0.25);
    border-radius: 8px;
    padding: 10px 14px;
    z-index: 100;
    pointer-events: none;
    backdrop-filter: blur(10px);
    min-width: 220px;
    max-width: 280px;
    max-width: 220px;
}

#building-tooltip h4 {
    color: #7eb8e0;
    font-size: 0.85rem;
    margin-bottom: 4px;
}

#building-tooltip p {
    color: #8aaccc;
    font-size: 0.75rem;
    margin-bottom: 6px;
    line-height: 1.4;
}

#tooltip-stats .tip-stat {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    padding: 2px 0;
}

.tip-stat .tip-label { color: #6a8faa; }
.tip-stat .tip-val { color: #a8d4f0; }
.tip-stat .tip-val.positive { color: #5ab87a; }
.tip-stat .tip-val.negative { color: #c45a5a; }
.tip-stat .tip-val.insufficient { color: #ff6b6b; font-weight: 600; }

/* --- Tooltip Requirements --- */
#tooltip-requirements {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(126,184,224,0.15);
}

.tip-req-header {
    color: #ffb347;
    font-size: 0.7rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.tip-req-item {
    font-size: 0.68rem;
    padding: 2px 0;
    line-height: 1.4;
}

.tip-req-item.locked {
    color: #ff8a8a;
}

.tip-req-item.unlocked {
    color: #6ecf8a;
}

.tip-req-current {
    font-size: 0.65rem;
    color: #8a9ab0;
    padding-left: 18px;
    margin-bottom: 2px;
}

/* ===== NOTIFICATIONS ===== */
#notifications {
    position: fixed;
    top: 64px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
}

.notification {
    background: rgba(15,30,54,0.9);
    border: 1px solid rgba(126,184,224,0.2);
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 0.85rem;
    color: #a8d4f0;
    backdrop-filter: blur(10px);
    animation: notifyIn 0.3s ease, notifyOut 0.3s ease 2.7s forwards;
    white-space: nowrap;
    text-align: center;
}

.notification.success { border-color: rgba(90,184,122,0.4); color: #7ed8a0; }
.notification.warning { border-color: rgba(232,184,74,0.4); color: #f0d060; }
.notification.error { border-color: rgba(196,90,90,0.4); color: #e08080; }

@keyframes notifyIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes notifyOut {
    from { opacity: 1; }
    to { opacity: 0; transform: translateY(-10px); }
}

/* ===== EVENT MODAL ===== */
#event-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: linear-gradient(135deg, #0f1e36 0%, #142540 100%);
    border: 1px solid rgba(126,184,224,0.2);
    border-radius: 16px;
    padding: 30px 36px;
    text-align: center;
    max-width: 400px;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.modal-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.modal-content h3 {
    color: #7eb8e0;
    font-size: 1.2rem;
    margin-bottom: 10px;
}

.modal-content p {
    color: #9ec5db;
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 16px;
}

#modal-effects {
    margin-bottom: 20px;
}

#modal-effects .effect-item {
    font-size: 0.8rem;
    padding: 3px 0;
}

.effect-item.positive { color: #5ab87a; }
.effect-item.negative { color: #c45a5a; }

/* ===== PEOPLE ANIMATION OVERLAY ===== */
.person-sprite {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    pointer-events: none;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 1025px) and (max-width: 1200px) {
    .resource-group { gap: 8px; }
    .resource { padding: 3px 8px; }
    .res-label { display: none; }
    #side-panel { width: 220px; }
}

@media (min-width: 1025px) and (max-width: 900px) {
    .status-group { display: none; }
    #side-panel { width: 200px; }
}

/* ===== MOBILE (≤1024px — covers iPhone landscape 932px & iPad portrait) ===== */
@media (max-width: 1024px) {

    /* Top bar: smaller, single row, compact */
    #top-bar {
        height: auto;
        min-height: 44px;
        padding: 4px 6px;
        flex-wrap: wrap;
        gap: 4px;
    }
    .resource-group {
        gap: 4px;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .resource {
        padding: 3px 6px;
        font-size: 11px;
        min-width: 44px;
        min-height: 32px;
    }
    .res-icon { font-size: 14px; }
    .res-value { font-size: 11px; }
    .res-label { display: none; }
    .status-group { display: none; }
    .time-group { font-size: 11px; gap: 4px; }
    .speed-controls { gap: 2px; }
    .btn-speed {
        width: 30px;
        height: 30px;
        font-size: 11px;
        min-width: 30px;
        min-height: 30px;
    }
    #game-stage { font-size: 10px; padding: 2px 6px; }
    #game-time { font-size: 10px; }

    /* Game area: full width */
    #game-wrapper {
        flex-direction: column;
    }
    #game-area {
        width: 100% !important;
        flex: 1;
        position: relative;
    }
    #game-canvas {
        width: 100% !important;
    }

    /* Mini map: smaller, bottom-left */
    #mini-map {
        width: 100px !important;
        height: 100px !important;
        bottom: 60px;
        left: 8px;
        right: auto;
        top: auto;
    }

    /* Side panel: bottom sheet */
    #side-panel {
        position: fixed !important;
        top: auto !important;        /* Reset desktop top: 52px */
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 60vh !important;
        max-height: 60vh !important;
        border-radius: 18px 18px 0 0;
        border-top: 2px solid rgba(148, 163, 184, 0.25);
        border-right: none !important;
        border-left: none !important;
        transform: translateY(105%) !important;    /* 105% ensures full hide on all devices */
        transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1) !important;
        z-index: 200 !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }
    #side-panel.mobile-open {
        transform: translateY(0) !important;
    }

    /* Drag handle on bottom sheet */
    #side-panel::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: rgba(148,163,184,0.4);
        border-radius: 2px;
        margin: 10px auto 6px;
        flex-shrink: 0;
    }

    /* Build grid: larger touch targets */
    .build-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }
    .build-btn {
        min-height: 56px;
        padding: 4px 2px;
        font-size: 10px;
    }
    .build-btn .btn-icon { font-size: 22px; }
    .build-btn .btn-name { font-size: 9px; }

    /* Panel tabs: bigger */
    .panel-tabs { gap: 4px; padding: 6px 8px 0; }
    .panel-tab {
        padding: 8px 10px;
        font-size: 12px;
        min-height: 40px;
    }

    /* Panel toggle button */
    #btn-panel-toggle {
        display: flex !important;
        position: fixed;
        bottom: 12px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 60;
        background: rgba(15, 23, 42, 0.92);
        border: 2px solid rgba(56, 189, 248, 0.4);
        color: #7dd3fc;
        border-radius: 28px;
        padding: 10px 24px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        backdrop-filter: blur(12px);
        box-shadow: 0 4px 20px rgba(0,0,0,0.4);
        gap: 6px;
        align-items: center;
        min-height: 44px;
        min-width: 44px;
        transition: all 0.2s;
        -webkit-tap-highlight-color: transparent;
    }
    #btn-panel-toggle.panel-open {
        background: rgba(56, 189, 248, 0.2);
        border-color: rgba(56, 189, 248, 0.7);
        bottom: calc(60vh + 12px);
    }

    /* Help button: repositioned */
    #btn-help {
        bottom: 64px !important;
        left: auto !important;
        right: 12px !important;
    }

    /* Tooltip: full width at bottom */
    #building-tooltip {
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        border-radius: 12px 12px 0 0;
        padding: 12px 16px 20px;
        font-size: 13px;
    }

    /* Notifications: top */
    #notifications {
        top: 54px;
        bottom: auto;
        right: 8px;
        left: 8px;
        max-width: none;
    }

    /* Modal: full-screen on mobile */
    #event-modal .modal-content {
        max-width: 95vw;
        margin: 0 auto;
    }

    /* Selected building info bar */
    #selected-building-bar {
        bottom: 60px;
        left: 8px;
        right: 8px;
        font-size: 12px;
    }

    /* Show ℹ️ button on mobile */
    .build-info-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    /* Disabled items: ℹ️ replaces lock icon so no overlap */
    .build-item.disabled::after {
        right: 26px; /* shift lock icon left to avoid overlapping ℹ️ */
    }
    .build-info-btn:active {
        background: rgba(56,189,248,0.35);
    }
}

/* ===== MOBILE BUILD INFO SHEET (injected by JS) ===== */
#mobile-build-info {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-end;
}

#mobile-build-info .mbi-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(3px);
}

#mobile-build-info .mbi-sheet {
    position: relative;
    width: 100%;
    background: linear-gradient(180deg, #0f1e38 0%, #0a1628 100%);
    border-top: 2px solid rgba(56,189,248,0.25);
    border-radius: 20px 20px 0 0;
    padding: 0 16px 32px;
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
#mobile-build-info .mbi-sheet.mbi-open {
    transform: translateY(0);
}

#mobile-build-info .mbi-handle {
    width: 40px;
    height: 4px;
    background: rgba(148,163,184,0.35);
    border-radius: 2px;
    margin: 12px auto 14px;
}

#mobile-build-info .mbi-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}
#mobile-build-info .mbi-icon {
    font-size: 2.4rem;
    flex-shrink: 0;
    line-height: 1;
    margin-top: 2px;
}
#mobile-build-info .mbi-title-group { flex: 1; }
#mobile-build-info .mbi-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: #e0f0ff;
    margin-bottom: 4px;
}
#mobile-build-info .mbi-desc {
    font-size: 0.78rem;
    color: #8aaccc;
    line-height: 1.4;
}
#mobile-build-info .mbi-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(148,163,184,0.25);
    background: rgba(148,163,184,0.08);
    color: #94a3b8;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

#mobile-build-info .mbi-cost-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
#mobile-build-info .mbi-cost-item {
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}
#mobile-build-info .mbi-cost-item.ok {
    background: rgba(34,197,94,0.12);
    border: 1px solid rgba(34,197,94,0.25);
    color: #86efac;
}
#mobile-build-info .mbi-cost-item.bad {
    background: rgba(239,68,68,0.12);
    border: 1px solid rgba(239,68,68,0.25);
    color: #fca5a5;
}

#mobile-build-info .mbi-effects {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
#mobile-build-info .mbi-effect {
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 0.75rem;
    font-weight: 500;
}
#mobile-build-info .mbi-effect.positive {
    background: rgba(56,189,248,0.1);
    border: 1px solid rgba(56,189,248,0.2);
    color: #7dd3fc;
}

#mobile-build-info .mbi-reqs {
    background: rgba(239,68,68,0.07);
    border: 1px solid rgba(239,68,68,0.2);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 14px;
}
#mobile-build-info .mbi-req {
    font-size: 0.78rem;
    margin-bottom: 4px;
    line-height: 1.4;
}
#mobile-build-info .mbi-req:last-child { margin-bottom: 0; }
#mobile-build-info .mbi-req.locked { color: #fca5a5; }

#mobile-build-info .mbi-actions {
    margin-top: 6px;
}
#mobile-build-info .mbi-btn-select {
    width: 100%;
    padding: 14px;
    border-radius: 14px;
    border: none;
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.15s;
    min-height: 50px;
}
#mobile-build-info .mbi-btn-select:active { opacity: 0.8; }
#mobile-build-info .mbi-btn-locked {
    width: 100%;
    padding: 14px;
    border-radius: 14px;
    border: 1px solid rgba(148,163,184,0.2);
    background: rgba(148,163,184,0.06);
    color: #64748b;
    font-size: 1rem;
    font-weight: 600;
    cursor: not-allowed;
    min-height: 50px;
}
