:root {
    --vh: 1vh;
}
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    box-sizing: border-box;
    background-color: #0d1117; 
    color: #f4f4f5;
    font-family: 'Fredoka', cursive, sans-serif;
}

/* Visibility Rules with !important to defeat high ID selector specificity */
.hidden,
.modal.hidden,
#start-modal.hidden,
#game-over-modal.hidden,
#factModal.hidden,
#howToModal.hidden,
#mainLeaderboardModal.hidden,
#soundOffIcon.hidden,
#leaderboard-rank.hidden {
    display: none !important;
}

/* Hide unit selection on mobile or compact view when any modal is open */
@media (max-width: 1023px) {
    body.modal-open #unit-selection-container,
    body:has(#start-modal:not(.hidden)) #unit-selection-container,
    body:has(#game-over-modal:not(.hidden)) #unit-selection-container,
    body:has(#howToModal:not(.hidden)) #unit-selection-container,
    body:has(#mainLeaderboardModal:not(.hidden)) #unit-selection-container,
    body:has(#factModal:not(.hidden)) #unit-selection-container {
        display: none !important;
    }
}

@media screen and (max-height: 640px) and (orientation: landscape) {
    body.modal-open #unit-selection-container,
    body:has(#start-modal:not(.hidden)) #unit-selection-container,
    body:has(#game-over-modal:not(.hidden)) #unit-selection-container,
    body:has(#howToModal:not(.hidden)) #unit-selection-container,
    body:has(#mainLeaderboardModal:not(.hidden)) #unit-selection-container,
    body:has(#factModal:not(.hidden)) #unit-selection-container {
        display: none !important;
    }
}


.page-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    padding: 1rem;
    gap: 0.5rem; 
    box-sizing: border-box;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
}

.hud-container { flex-shrink: 0; }

.game-wrapper {
    flex-grow: 1;
    min-height: 0;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.leaderboard-panel { display: none; }

.global-footer { 
    flex-shrink: 0; 
    text-align: center; 
    padding-top: 0.25rem;
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    height: 44px; 
}

.footer-content img {
    height: 100%;
    max-height: 44px;
    width: auto;
    object-fit: contain;
}

.hud { 
    display: grid;
    grid-template-columns: 1fr auto 1fr auto;
    align-items: center; 
    gap: 0.75rem; 
}

.hud-left { text-align: left; }
.hud-center { text-align: center; }
.hud-right { text-align: right; }

.hud-element { 
    background: rgba(22, 36, 71, 0.75); 
    backdrop-filter: blur(8px);
    padding: 0.5rem 1rem; 
    border-radius: 0.75rem; 
    border: 1.5px solid rgba(6, 182, 212, 0.35); 
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap; 
    color: #e2e8f0;
    font-family: 'Fredoka', cursive, sans-serif;
}

.hud-mute-button {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    transition: all 0.2s ease;
    color: #67e8f9;
}

.hud-mute-button:hover {
    background: rgba(6, 182, 212, 0.2);
    border-color: rgba(6, 182, 212, 0.8);
    transform: translateY(-2px) scale(1.05);
}

.hud-icon {
    width: 1.25rem;
    height: 1.25rem;
}

.city-health-container { text-align: center; display: inline-block; }
.hud-label { 
    font-size: 0.8rem; 
    font-weight: 600;
    display: block; 
    margin-bottom: 0.25rem; 
    color: #94a3b8;
    letter-spacing: 0.5px;
}

.city-health-bar { 
    width: 160px; 
    height: 1.25rem; 
    background-color: rgba(15, 23, 42, 0.8); 
    border: 1.5px solid rgba(255, 255, 255, 0.2); 
    border-radius: 9999px; 
    padding: 2px; 
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.city-health-fill { 
    height: 100%; 
    width: 100%; 
    background: linear-gradient(90deg, #22c55e, #10b981); 
    border-radius: 9999px; 
    transition: width 0.3s ease-in-out, background-color 0.3s ease-in-out; 
}

#game-area-wrapper {
    position: relative;
    width: 100%;
    height: 100%; 
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #1e293b; 
    border-radius: 1rem; 
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 1rem;
    overflow: hidden;
    background: #0f172a; 
    border: 2px solid rgba(6, 182, 212, 0.3);
    box-shadow: inset 0 0 30px rgba(0,0,0,0.7);
    background-image: 
        linear-gradient(rgba(255, 255, 255, 0.03) 2px, transparent 2px), 
        linear-gradient(90deg, rgba(255, 255, 255, 0.03) 2px, transparent 2px);
    background-size: 40px 40px;
    cursor: crosshair;
}

#notification-container {
    position: absolute;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 101;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
}

.notification {
    font-size: 1.25rem;
    font-weight: 700;
    padding: 0.5rem 1.25rem;
    border-radius: 9999px;
    color: white;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    animation: fadeInAndOut 4s ease-in-out forwards;
}

.notification.cytokine-storm {
    background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
    border: 2px solid #fecaca;
}

@keyframes fadeInAndOut {
    0%, 100% { opacity: 0; transform: translateY(15px); }
    10%, 90% { opacity: 1; transform: translateY(0); }
}

/* Liveliness & Visual Juice */
#ambient-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 1;
}

.ambient-bubble {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.25) 0%, rgba(56, 189, 248, 0.05) 70%, transparent 100%);
    pointer-events: none;
    animation: bloodstream-drift linear infinite;
}

@keyframes bloodstream-drift {
    0% { transform: translate(0, 0) scale(0.8); opacity: 0; }
    20% { opacity: 0.6; }
    80% { opacity: 0.6; }
    100% { transform: translate(60px, -80px) scale(1.2); opacity: 0; }
}

#score-pop-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 90;
}

.score-pop {
    position: absolute;
    font-family: 'Fredoka', cursive, sans-serif;
    font-size: 1rem;
    font-weight: 700;
    pointer-events: none;
    animation: pop-float 1s ease-out forwards;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    transform: translate(-50%, -50%);
}

@keyframes pop-float {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(0.9); }
    50% { transform: translate(-50%, -75%) scale(1.15); }
    100% { opacity: 0; transform: translate(-50%, -100%) scale(1); }
}

.particle-burst {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    animation: burst-fade 0.6s ease-out forwards;
}

@keyframes burst-fade {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(calc(-50% + var(--vx, 0px)), calc(-50% + var(--vy, 0px))) scale(0.2); opacity: 0; }
}

#damage-vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 95;
    box-shadow: inset 0 0 50px rgba(239, 68, 68, 0.6);
    animation: damage-flash 0.4s ease-out forwards;
}

@keyframes damage-flash {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

#storm-vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 94;
    box-shadow: inset 0 0 60px rgba(251, 146, 60, 0.55);
    animation: storm-pulse 1.5s ease-in-out infinite;
}

@keyframes storm-pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.85; }
}

/* Organic Cell & Pathogen Wobble */
.cell-wobble img {
    animation: defender-breath 3s ease-in-out infinite;
}

@keyframes defender-breath {
    0%, 100% { transform: scale(1, 1); }
    50% { transform: scale(1.05, 0.95); }
}

.pathogen-wobble img {
    animation: germ-squish 1.2s ease-in-out infinite;
}

@keyframes germ-squish {
    0%, 100% { transform: scale(1, 1) rotate(0deg); }
    25% { transform: scale(1.08, 0.92) rotate(-3deg); }
    75% { transform: scale(0.94, 1.06) rotate(3deg); }
}

/* Game Over Stats Grid */
.game-over-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    width: 100%;
    max-width: 32rem;
    margin: 0.75rem auto 1.25rem auto;
}

.game-over-stat-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.75rem;
    padding: 0.65rem 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.72rem;
    color: #94a3b8;
    margin-top: 0.25rem;
    font-weight: 600;
}

/* Modals */
.modal { 
    position: absolute; 
    inset: 0; 
    background: rgba(10, 15, 30, 0.88); 
    backdrop-filter: blur(10px);
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    padding: 1rem; 
    z-index: 100; 
    box-sizing: border-box; 
}

.modal-header { 
    text-align: center; 
    padding-bottom: 0.5rem; 
    flex-shrink: 0; 
    width: 100%;
}

.modal-body { 
    flex-grow: 1; 
    overflow-y: auto; 
    width: 100%; 
    min-height: 0; 
    padding: 0.25rem 0.5rem;
    box-sizing: border-box;
}

.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: #1e293b;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background-color: #facc15;
    border-radius: 6px;
    border: 2px solid #1e293b;
}

.modal-footer { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    gap: 0.75rem; 
    padding-top: 0.75rem; 
    flex-shrink: 0; 
    width: 100%;
}

.modal-title { 
    font-size: clamp(1.6rem, 4.5vw, 2.4rem); 
    font-weight: 700;
    color: #facc15; 
    text-shadow: 0 4px 12px rgba(250, 204, 21, 0.3); 
    margin-bottom: 0.2rem; 
    letter-spacing: 0.5px;
    font-family: 'Fredoka', cursive, sans-serif;
}

.modal-subtitle { 
    font-size: clamp(0.85rem, 2.5vw, 1.05rem); 
    font-weight: 500;
    color: #94a3b8; 
    margin-bottom: 0.5rem; 
}

/* Compact Intro Box and Cards Grid */
.intro-box { 
    width: 100%;
    max-width: 58rem; 
    margin: 0 auto 0.75rem auto; 
    padding: 0.75rem;
    background-color: rgba(24, 24, 27, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-sizing: border-box;
}

.cards-hint {
    text-align: center;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    color: #94a3b8;
    letter-spacing: 0.3px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    width: 100%;
}

@media (min-width: 540px) {
    .cards-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 720px) {
    .cards-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 900px) {
    .cards-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

.character-card {
    position: relative;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.85rem;
    padding: 0.65rem 0.5rem 0.6rem 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.character-card:hover {
    animation: wiggle 0.4s ease-in-out;
    transform: translateY(-4px) scale(1.03);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}

.character-card:active {
    transform: scale(0.96);
}

.card-hero { border-color: rgba(34, 211, 238, 0.4); }
.card-hero:hover { border-color: #22d3ee; box-shadow: 0 8px 24px rgba(34, 211, 238, 0.25); }
.card-ally { border-color: rgba(56, 189, 248, 0.35); }
.card-ally:hover { border-color: #38bdf8; box-shadow: 0 8px 24px rgba(56, 189, 248, 0.2); }
.card-threat { border-color: rgba(248, 113, 113, 0.35); }
.card-threat:hover { border-color: #f87171; box-shadow: 0 8px 24px rgba(248, 113, 113, 0.2); }

.card-badge {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.55rem;
    border-radius: 9999px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 0.35rem;
    line-height: 1.2;
}

.badge-hero { background: rgba(34, 211, 238, 0.2); color: #67e8f9; border: 1px solid rgba(34, 211, 238, 0.4); }
.badge-ally { background: rgba(56, 189, 248, 0.2); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.4); }
.badge-threat { background: rgba(239, 68, 68, 0.2); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.4); }

.card-name {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.2rem;
}

.card-ability {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.72rem;
    color: #d4d4d8;
    line-height: 1.25;
    font-weight: 500;
}

/* Aspect-Ratio Preserving Icon Container */
.card-portrait, .icon-container {
    width: 3.5rem;
    height: 3.5rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 0.65rem;
    padding: 0.3rem;
    box-sizing: border-box;
    margin-bottom: 0.35rem;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.character-card:hover .card-portrait,
.character-card:hover .icon-container {
    transform: scale(1.08);
    background: rgba(0, 0, 0, 0.35);
}

.icon-container img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

/* Playful Buttons */
.btn-primary, .btn-secondary { 
    font-family: 'Fredoka', cursive, sans-serif;
    color: white; 
    padding: 0.75rem 1.75rem; 
    border-radius: 0.75rem; 
    font-size: 1.05rem; 
    font-weight: 700;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.2s; 
    border: none; 
    cursor: pointer; 
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-primary { 
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); 
    color: #0f172a;
}

.btn-primary:hover { 
    transform: translateY(-2px) scale(1.02); 
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.45); 
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
}

.btn-primary:active {
    transform: translateY(1px) scale(0.98);
}

.btn-secondary { 
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%); 
    color: white; 
}

.btn-secondary:hover { 
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.45); 
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}

.btn-secondary:active {
    transform: translateY(1px) scale(0.98);
}

.modal-footer-buttons { 
    display: flex; 
    gap: 1rem; 
    justify-content: center;
    width: 100%;
}

.player-name-input { 
    background-color: rgba(15, 23, 42, 0.8); 
    color: white; 
    text-align: center; 
    padding: 0.5rem 1.25rem; 
    border-radius: 0.5rem; 
    border: 1.5px solid rgba(6, 182, 212, 0.4); 
    font-family: 'Fredoka', cursive, sans-serif;
    font-size: 1rem;
    font-weight: 600;
}

.player-name-input:focus { 
    outline: none; 
    border-color: #facc15; 
    box-shadow: 0 0 12px rgba(250, 204, 21, 0.3);
}

.player-name-input.shake-input { animation: input-shake 0.4s; }
@keyframes input-shake { 
    10%, 90% { transform: translateX(-3px); } 
    20%, 80% { transform: translateX(3px); } 
    30%, 50%, 70% { transform: translateX(-3px); } 
    40%, 60% { transform: translateX(3px); } 
}

/* Wiggle Keyframes */
@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-3deg) scale(1.03); }
    75% { transform: rotate(3deg) scale(1.03); }
}

@keyframes pulse-wiggle {
    0%, 100% { transform: scale(1) rotate(0deg); }
    20% { transform: scale(1.04) rotate(-2deg); }
    40% { transform: scale(1.04) rotate(2deg); }
    60% { transform: scale(1.02) rotate(-1deg); }
    80% { transform: scale(1.02) rotate(1deg); }
}

/* Tutorial Corner Button */
.tutorial-corner-btn {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1.5px solid rgba(6, 182, 212, 0.4);
    border-radius: 9999px;
    padding: 0.4rem 0.85rem;
    font-family: 'Fredoka', cursive, sans-serif;
    font-weight: 600;
    font-size: 0.8rem;
    color: #a5f3fc;
    cursor: pointer;
    backdrop-filter: blur(6px);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.tutorial-corner-btn svg {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.tutorial-corner-btn:hover {
    background: rgba(6, 182, 212, 0.2);
    border-color: rgba(6, 182, 212, 0.8);
    transform: translateY(-2px) scale(1.03);
}

/* How to Play Card Modal */
.how-to-card {
    position: relative;
    width: 100%;
    max-width: 48rem;
    max-height: 90vh;
    margin: auto;
    overflow-y: auto;
    background: linear-gradient(135deg, rgba(30, 20, 50, 0.96) 0%, rgba(15, 23, 42, 0.98) 100%);
    border: 2px solid rgba(6, 182, 212, 0.45);
    border-radius: 1.25rem;
    padding: 1.5rem 1.75rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 30px rgba(6, 182, 212, 0.25);
    text-align: center;
    box-sizing: border-box;
}

.how-to-header-badge {
    display: inline-block;
    background: rgba(6, 182, 212, 0.15);
    border: 1.5px solid rgba(6, 182, 212, 0.4);
    color: #38bdf8;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.2rem 0.75rem;
    border-radius: 9999px;
    margin-bottom: 0.5rem;
    letter-spacing: 0.5px;
}

.how-to-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: #facc15;
    margin-bottom: 0.25rem;
}

.how-to-subtitle {
    font-size: 0.9rem;
    color: #94a3b8;
    margin-bottom: 1.25rem;
}

.tutorial-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
    text-align: left;
}

.tutorial-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.tutorial-icon-box {
    margin-bottom: 0.75rem;
}

.tutorial-step-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #38bdf8;
    margin-bottom: 0.25rem;
}

.tutorial-step-desc {
    font-size: 0.8rem;
    color: #cbd5e1;
    line-height: 1.35;
}

/* Fact Modal */
.fact-card {
    position: relative;
    width: 100%;
    max-width: 26rem;
    margin: auto;
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.96) 0%, rgba(15, 23, 42, 0.98) 100%);
    border: 2px solid rgba(56, 189, 248, 0.4);
    border-radius: 1.25rem;
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
}

.fact-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.fact-close-btn {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.fact-close-btn:hover { color: white; }

.fact-portrait {
    margin: 0 auto 0.75rem auto;
    width: 4.5rem;
    height: 4.5rem;
}

.fact-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #facc15;
    margin-bottom: 0.5rem;
}

.fact-text {
    font-size: 0.88rem;
    color: #e2e8f0;
    line-height: 1.4;
    margin-bottom: 1.25rem;
}

.fact-btn {
    width: 100%;
}

/* Leaderboard Boxes & Podium Cards */
.leaderboard-box { 
    background: rgba(15, 23, 42, 0.8); 
    padding: 0.75rem; 
    border-radius: 0.75rem; 
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.85rem; 
    width: 100%; 
    max-width: 48rem; 
    box-sizing: border-box; 
}

.leaderboard-tip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(6, 182, 212, 0.1);
    border: 1px dashed rgba(6, 182, 212, 0.35);
    border-radius: 0.65rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-family: 'Fredoka', cursive, sans-serif;
    font-size: 0.75rem;
    color: #67e8f9;
}

.leaderboard-podium-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.55rem 0.75rem;
    margin-bottom: 0.45rem;
    border-radius: 0.65rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-weight: 600;
}

.podium-rank-1 {
    background: linear-gradient(90deg, rgba(250, 204, 21, 0.2) 0%, rgba(30, 41, 59, 0.7) 100%);
    border: 1.5px solid rgba(250, 204, 21, 0.6);
}

.podium-rank-2 {
    background: linear-gradient(90deg, rgba(203, 213, 225, 0.2) 0%, rgba(30, 41, 59, 0.7) 100%);
    border: 1.5px solid rgba(203, 213, 225, 0.6);
}

.podium-rank-3 {
    background: linear-gradient(90deg, rgba(217, 119, 6, 0.2) 0%, rgba(30, 41, 59, 0.7) 100%);
    border: 1.5px solid rgba(217, 119, 6, 0.6);
}

.podium-badge {
    width: 1.5rem;
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    font-weight: 700;
    font-size: 0.75rem;
    margin-right: 0.5rem;
}

.podium-badge.rank-1 {
    background: linear-gradient(135deg, #facc15 0%, #ca8a04 100%);
    color: #1e092b;
}

.podium-badge.rank-2 {
    background: linear-gradient(135deg, #e2e8f0 0%, #94a3b8 100%);
    color: #0f172a;
}

.podium-badge.rank-3 {
    background: linear-gradient(135deg, #fb923c 0%, #c2410c 100%);
    color: white;
}

.leaderboard-player {
    display: flex;
    align-items: center;
}

.leaderboard-rank-text { 
    font-size: 1.1rem; 
    font-weight: 700;
    color: #facc15; 
    margin-bottom: 1rem; 
}

/* In-game Units & Germs */
.pathogen, .t-effector-cell, .t-reg-cell, .dendritic-cell, .macrophage-cell, .neutrophil-cell { 
    position: absolute; 
    width: 40px; 
    height: 40px; 
    will-change: transform; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
}

.pathogen img, .t-effector-cell img, .t-reg-cell img, .dendritic-cell img, .macrophage-cell img, .neutrophil-cell img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    -webkit-user-drag: none; 
    user-select: none; 
}

.pathogen.small-dividing {
    width: 25px;
    height: 25px;
}

.pathogen.health { 
    animation: pulse-green 1s infinite; 
}

.pathogen.stealth.cloaked {
    opacity: 0.25;
}

.t-effector-cell, .t-reg-cell, .dendritic-cell, .macrophage-cell, .neutrophil-cell {
    cursor: pointer;
}

.t-effector-cell.over-excited { 
    animation: pulse-red 0.5s infinite; 
}

.digestive-pool {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 160px; 
    height: 160px;
    background-color: rgba(236, 72, 153, 0.15);
    border: 2px dashed rgba(236, 72, 153, 0.45);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    transition: width 0.3s, height 0.3s;
    z-index: -1;
}

.excitement-meter, .lifespan-meter, .germ-health-bar { 
    position: absolute; 
    width: 32px; 
    height: 5px; 
    background-color: rgba(0,0,0,0.6); 
    border-radius: 3px; 
    border: 1px solid rgba(255, 255, 255, 0.8); 
    overflow: hidden;
}

.excitement-meter { top: -10px; left: 4px; }
.lifespan-meter { top: -17px; left: 4px; }
.germ-health-bar { top: -8px; left: 4px; }

.excitement-fill, .lifespan-fill, .germ-health-fill { 
    height: 100%; 
    border-radius: 2px; 
    transition: width 0.2s linear; 
}

.excitement-fill { background-color: #facc15; width: 0%;}
.lifespan-fill { background-color: #38bdf8; width: 100%;}
.germ-health-fill { background-color: #ef4444; width: 100%; }

.upgrade-level {
    position: absolute;
    bottom: -14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 2px;
}

.upgrade-level img {
    width: 12px;
    height: 12px;
}

.projectile { 
    position: absolute; 
    width: 8px; 
    height: 8px; 
    background-color: #38bdf8; 
    border-radius: 50%; 
    box-shadow: 0 0 10px #38bdf8; 
}

.calm-aura { 
    position: absolute; 
    border-radius: 50%; 
    width: 200px; 
    height: 200px; 
    transform: translate(-50%, -50%) scale(0.1); 
    top: 50%; 
    left: 50%; 
    animation: calm-pulse 2s infinite ease-out; 
    pointer-events: none; 
    border: 2px solid rgba(52, 211, 153, 0.7); 
    transition: width 0.3s, height 0.3s; 
}

.placement-preview {
    position: absolute;
    border: 2px dashed rgba(56, 189, 248, 0.7);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    transition: width 0.2s, height 0.2s;
    z-index: 99;
}

/* Bottom Unit Bar */
#unit-selection-container {
    flex-shrink: 0;
    display: flex;
    justify-content: center;
}

#unit-selection { 
    display: flex; 
    gap: 0.5rem; 
    background: rgba(15, 23, 42, 0.75); 
    backdrop-filter: blur(8px);
    padding: 0.5rem; 
    border-radius: 0.85rem; 
    border: 1.5px solid rgba(6, 182, 212, 0.35);
}

.unit-btn { 
    width: 62px; 
    height: 62px; 
    background: rgba(30, 41, 59, 0.8); 
    border: 1.5px solid rgba(255, 255, 255, 0.15); 
    border-radius: 0.65rem; 
    cursor: pointer; 
    transition: all 0.2s ease; 
    display: flex; 
    flex-direction: column; 
    justify-content: center; 
    align-items: center; 
    color: white; 
    font-size: 0.75rem; 
    font-weight: 700;
    font-family: 'Fredoka', cursive, sans-serif;
}

.unit-btn:hover { 
    background: rgba(56, 189, 248, 0.2); 
    border-color: rgba(56, 189, 248, 0.6);
    transform: translateY(-2px);
}

.unit-btn.selected { 
    border-color: #facc15; 
    box-shadow: 0 0 14px rgba(250, 204, 21, 0.6); 
    transform: scale(1.08); 
    background: rgba(250, 204, 21, 0.15);
}

.unit-btn:disabled { 
    cursor: not-allowed; 
    opacity: 0.45; 
    background: rgba(15, 23, 42, 0.5); 
    border-color: rgba(255, 255, 255, 0.05);
    transform: none;
}

.unit-icon {
    width: 34px;
    height: 34px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.unit-icon img { 
    max-height: 100%; 
    max-width: 100%; 
    object-fit: contain; 
}

.unit-cost { margin-top: 2px; }

@keyframes pulse-red { 50% { filter: brightness(1.6); } }
@keyframes pulse-green { 50% { filter: brightness(1.5) drop-shadow(0 0 12px #34d399); } }
@keyframes calm-pulse { 
    0% { transform: translate(-50%, -50%) scale(0.1); opacity: 0; } 
    50% { opacity: 0.8; } 
    100% { transform: translate(-50%, -50%) scale(1); opacity: 0; } 
}
@keyframes pulse-red-glow {
    50% { filter: drop-shadow(0 0 8px #ef4444); }
}

.lifespan-ending img {
    animation: pulse-red-glow 1s infinite ease-in-out;
}

/* Desktop Grid Layout (lg: breakpoint) */
@media (min-width: 1024px) {
    .page-container {
        display: grid;
        grid-template-columns: 1fr 320px;
        grid-template-rows: auto 1fr auto auto;
        gap: 1rem;
        height: 96vh;
        max-height: 920px;
    }
    .hud-container { grid-column: 1 / -1; grid-row: 1;}
    .game-wrapper { grid-column: 1; grid-row: 2; }
    #unit-selection-container { grid-column: 1; grid-row: 3; }
    .leaderboard-panel { 
        grid-column: 2;
        grid-row: 2 / span 2; 
        display: flex;
        flex-direction: column;
        background: rgba(15, 23, 42, 0.75);
        backdrop-filter: blur(8px);
        border-radius: 1rem;
        padding: 1rem;
        border: 2px solid rgba(6, 182, 212, 0.35);
        box-sizing: border-box;
    }
    .leaderboard-panel-title { 
        font-size: 1.4rem; 
        font-weight: 700;
        text-align: center; 
        margin-bottom: 0.75rem; 
        color: #facc15; 
        letter-spacing: 0.5px;
    }
    .leaderboard-box { 
        overflow-y: auto; 
        flex-grow: 1; 
        min-height: 0; 
    }
    .global-footer { grid-column: 1 / -1; grid-row: 4; }
    #leaderboardBtn,
    #leaderboardGameOverBtn {
        display: none !important;
    }
    .game-wrapper .modal {
        inset: 1.5rem 3rem;
        border-radius: 1rem;
    }
    
    /* Centered start button on desktop when leaderboard button is hidden */
    .modal-footer-buttons {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
    }

    #start-game-btn {
        margin: 0 auto;
        display: inline-block;
    }
}

@media (max-width: 640px) {
     .hud-element { font-size: 0.75rem; padding: 0.35rem 0.65rem; }
     .unit-btn { width: 52px; height: 52px; }
     .unit-icon { width: 28px; height: 28px; }
     #unit-selection { gap: 0.3rem; }
     .cards-grid { grid-template-columns: repeat(2, 1fr); }
}

.hud-mute-button {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    transition: transform 0.15s ease, background-color 0.2s, border-color 0.2s;
}

.hud-mute-button:hover {
    transform: scale(1.06);
    background: rgba(39, 39, 42, 0.95);
    border-color: #a1a1aa;
}

.hud-mute-button:active {
    transform: scale(0.95);
}

.hud-mute-button svg {
    width: 1.25rem;
    height: 1.25rem;
    display: block;
}

#rotate-warning {
    display: none;
    position: fixed;
    inset: 0;
    background-color: #18181b;
    color: #f4f4f5;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 200;
    padding: 1.5rem;
    font-family: 'Fredoka', sans-serif;
}

.rotate-icon {
    width: 4.5rem;
    height: 4.5rem;
    margin-bottom: 1.25rem;
    color: #38bdf8;
    animation: rotate-pulse 2s infinite ease-in-out;
}

@keyframes rotate-pulse {
    0%, 100% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(90deg) scale(1.08); }
}

@media screen and (max-width: 1023px) and (orientation: portrait) {
    .page-container, footer, .global-footer {
        display: none !important;
    }
    #rotate-warning {
        display: flex !important;
    }
}

@media screen and (max-height: 640px) and (orientation: landscape), screen and (max-width: 1023px) and (orientation: landscape) {
    footer,
    .global-footer {
        display: none !important;
    }
    .page-container {
        padding: 0.25rem 0.5rem;
        gap: 0.25rem;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
    }
    .game-wrapper {
        max-width: 100%;
        height: 100%;
        min-height: 0;
        flex: 1 1 auto;
    }
    .leaderboard-panel {
        display: none !important;
    }
    .hud {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        margin-bottom: 0.25rem !important;
        gap: 0.35rem !important;
    }
    .hud-element {
        font-size: 0.78rem;
        padding: 0.2rem 0.5rem;
        border-radius: 0.5rem;
    }
    .hud-label {
        display: none !important;
    }
    .city-health-container {
        min-width: 70px;
        max-width: 180px;
        flex-grow: 1;
    }
    .city-health-bar {
        height: 0.95rem;
        border-radius: 0.35rem;
        width: 100%;
        max-width: 140px;
    }
    .hud-mute-button {
        display: flex !important;
        padding: 0.2rem 0.4rem;
    }
    .canvas-container,
    .game-area-wrapper,
    #game-area-wrapper,
    #game-container {
        min-height: 0;
        flex: 1 1 auto;
        height: 100%;
    }
    canvas {
        max-height: 100%;
        max-width: 100%;
    }
    .modal {
        padding: 0.35rem 0.5rem;
        justify-content: space-between;
    }
    .modal-header {
        padding-bottom: 0.1rem;
    }
    .modal-title {
        font-size: clamp(1.1rem, 2.5vw, 1.35rem);
        line-height: 1.1;
        margin-bottom: 0.1rem;
    }
    .modal-subtitle {
        font-size: clamp(0.65rem, 1.5vw, 0.75rem);
        margin: 0 0 0.15rem 0;
    }
    .tutorial-corner-btn {
        top: 0.35rem;
        left: 0.35rem;
        right: auto !important;
        padding: 0.18rem 0.45rem;
        font-size: 0.68rem;
        gap: 0.25rem;
        white-space: nowrap;
        height: 24px;
    }
    .tutorial-corner-btn svg {
        width: 0.75rem;
        height: 0.75rem;
        flex-shrink: 0;
    }
    .intro-box {
        padding: 0.25rem 0.4rem;
        margin-bottom: 0.2rem;
        gap: 0.2rem;
        max-width: 100%;
    }
    .cards-hint {
        font-size: 0.65rem;
        margin-bottom: 0.15rem;
    }
    .cards-grid {
        display: grid !important;
        grid-template-columns: repeat(6, 1fr) !important;
        gap: 0.25rem;
        width: 100%;
    }
    @media (max-width: 580px) {
        .cards-grid {
            grid-template-columns: repeat(4, 1fr) !important;
        }
    }
    .character-card {
        padding: 0.25rem 0.15rem;
        border-radius: 0.5rem;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
    .card-badge {
        font-size: 0.5rem;
        padding: 0.05rem 0.25rem;
        margin-bottom: 0.12rem;
        line-height: 1;
    }
    .card-portrait, .icon-container {
        width: 2.15rem;
        height: 2.15rem;
        padding: 0.15rem;
        margin-bottom: 0.12rem;
        border-radius: 0.45rem;
    }
    .card-portrait img, .icon-container img {
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
    }
    .card-name {
        font-size: 0.62rem;
        font-weight: 700;
        margin-bottom: 0;
        line-height: 1.1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }
    .card-ability {
        display: none !important;
    }
    .modal-footer {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
        padding-top: 0.25rem !important;
        gap: 0.4rem !important;
        width: 100%;
    }
    .player-name-input {
        padding: 0.3rem 0.6rem;
        font-size: 0.82rem;
        height: 32px;
        max-width: 11rem;
        border-radius: 0.5rem;
        margin: 0;
    }
    .modal-footer-buttons {
        display: flex !important;
        flex-direction: row !important;
        gap: 0.4rem !important;
        width: auto !important;
        margin-top: 0 !important;
    }
    .btn-primary, .btn-secondary {
        padding: 0.3rem 0.85rem;
        font-size: 0.82rem;
        height: 32px;
        border-radius: 0.5rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .game-over-title {
        font-size: 1.3rem;
    }
    .game-over-fact-card {
        padding: 0.35rem 0.6rem;
        max-width: 22rem;
        margin: 0.2rem auto;
    }
    .game-over-fact-portrait {
        width: 2.75rem;
        height: 2.75rem;
        margin-bottom: 0.2rem;
    }
    .game-over-fact-title {
        font-size: 0.95rem;
        margin-bottom: 0.15rem;
    }
    .game-over-fact-text {
        font-size: 0.72rem;
        line-height: 1.25;
    }
    #mainLeaderboardModal .modal-body,
    .how-to-card,
    .fact-card {
        max-height: 85vh;
        overflow-y: auto;
    }
    .fact-card {
        max-width: 22rem;
        padding: 0.75rem 1rem;
        border-radius: 0.85rem;
    }
    .fact-header {
        margin-bottom: 0.35rem;
    }
    .fact-portrait {
        width: 3rem;
        height: 3rem;
        margin-bottom: 0.35rem;
    }
    .fact-title {
        font-size: 1.05rem;
        margin-bottom: 0.25rem;
    }
    .fact-text {
        font-size: 0.75rem;
        line-height: 1.25;
        margin-bottom: 0.5rem;
    }
    .fact-btn {
        padding: 0.35rem 1rem;
        font-size: 0.85rem;
        height: 32px;
    }
    .tutorial-cards {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.35rem;
    }
    .tutorial-card {
        padding: 0.4rem;
    }
    .tutorial-step-img {
        width: 2rem;
        height: 2rem;
    }
}

.science-corner-btn {
    position: absolute;
    top: 1rem;
    left: auto;
    right: 1rem;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #f4f4f5;
    background: rgba(5, 150, 105, 0.35);
    border: 1.5px solid #34d399;
    border-radius: 9999px;
    padding: 0.35rem 1rem;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}
.science-corner-btn:hover {
    background: #059669;
    color: #ffffff;
    box-shadow: 0 0 15px rgba(52, 211, 153, 0.6);
    transform: translateY(-1px);
}
#scienceInfoModal {
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    box-sizing: border-box;
}
#scienceInfoModal.hidden {
    display: none !important;
}
.science-info-card {
    position: relative;
    background: #18181b;
    border: 2px solid #34d399;
    border-radius: 1.25rem;
    padding: 1.5rem;
    max-width: 48rem;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.65);
    margin: auto;
}
.science-info-body {
    text-align: left;
    color: #d4d4d8;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    line-height: 1.55;
    width: 100%;
}
.science-info-body h3 {
    color: #6ee7b7;
    font-size: 0.95rem;
    font-weight: 700;
    margin: 1rem 0 0.4rem 0;
}
.science-info-body p { margin: 0.5rem 0; }
.science-info-body ul {
    margin: 0.3rem 0 0.6rem 1.1rem;
    list-style: disc;
}
.science-info-body li { margin: 0.2rem 0; }
.science-info-body a {
    color: #38bdf8;
    text-decoration: underline;
}
.science-info-body a:hover { color: #7dd3fc; }
.science-grade { font-size: 0.8rem; color: #a1a1aa; }
@media (max-width: 1024px) {
    .science-corner-btn {
        top: 0.35rem;
        right: 0.35rem;
        left: auto !important;
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
    }
}

.footer-legal {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    margin-top: 0.4rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.7rem;
}
.footer-legal a, .footer-legal-btn {
    color: #71717a;
    text-decoration: none;
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    cursor: pointer;
}
.footer-legal a:hover, .footer-legal-btn:hover { color: #34d399; }
