/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Generic hidden class */
.hidden {
    display: none !important;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    background: #1a1a2e;
    color: #ffffff;
}

/* Game Container */
#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

/* Canvas */
#renderCanvas {
    width: 100%;
    height: 100%;
    display: block;
    outline: none;
    touch-action: none;
}

/* Header */
#header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 8px 20px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.4) 100%);
    z-index: 101; /* Above build panel */
    backdrop-filter: blur(10px);
    flex-wrap: wrap;
    gap: 2px;
    transition: transform 0.3s ease-in-out;
}

#header.hidden {
    transform: translateY(-100%);
}

@media (orientation: portrait) {
    #header {
        /* Portrait mode - full width since build panel is at bottom */
        right: 0;
    }
}

#game-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 3px;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    flex-shrink: 0;
    order: 1;
    line-height: 1;
}

/* Pyramid logo style (for future use) */
#game-title.pyramid {
    font-family: 'Arial Black', Arial, sans-serif;
    font-weight: 900;
    letter-spacing: 2px;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.8), 0 0 15px rgba(255, 215, 0, 0.3);
    line-height: 0.95;
    text-transform: uppercase;
    font-size: 16px;
}

#header-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
    margin-left: auto;
    order: 2;
}

.header-button {
    background: rgba(255, 215, 0, 0.2);
    border: 2px solid rgba(255, 215, 0, 0.5);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 18px;
    color: #ffd700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.header-button:hover {
    background: rgba(255, 215, 0, 0.4);
    transform: scale(1.1);
}

.header-button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    border-color: rgba(255, 215, 0, 0.2);
}

.header-button:disabled:hover {
    background: rgba(255, 215, 0, 0.2);
    transform: none;
}

.header-button.has-offers {
    background: rgba(0, 200, 0, 0.6);
    border-color: #00cc00;
}

.header-button.has-offers:hover {
    background: rgba(0, 200, 0, 0.8);
}


/* Resources Panel */
#resources-panel {
    display: flex;
    gap: 0;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    order: 3;
}

.resource-box {
    /* display set dynamically by JavaScript to 'grid' */
    display: flex;
    align-items: center;
    gap: 0;
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 12px;
    border-radius: 6px;
    border: 1px solid rgba(255, 215, 0, 0.3);
    flex-wrap: wrap;
    min-height: 24px;
    box-sizing: border-box;
}

/* Note: Landscape orientation styles removed - layout is now dynamic based on actual width */

.resource-item {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    line-height: 1;
    gap: 0px;
}

.resource-item.hidden {
    display: none;
}

.resource-icon {
    font-size: 14px;
    vertical-align: middle;
    line-height: 1;
}

.resource-value {
    font-size: 14px;
    font-weight: 700;
    color: #ffd700;
    vertical-align: middle;
    line-height: 1;
}

.resource-production {
    font-size: 11px;
    font-weight: 600;
    color: #90ee90;
    display: inline-block;
    vertical-align: middle;
    line-height: 1;
}

/* Stacked rate display */
.rate-stack {
    display: inline-flex;
    flex-direction: column;
    justify-content: flex-start;
    vertical-align: middle;
    line-height: 0.8;
    height: 15px;
    min-height: 15px;
}

.rate-combined {
    font-size: 8px;
    font-weight: 600;
    line-height: 0.8;
    display: block;
}

.rate-tax {
    font-size: 7px;
    font-weight: 500;
    line-height: 0.8;
    display: block;
    margin-top: 2px;
}

/* Build Menu Popup - Mobile-first design */
.build-menu-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1.2);
    background: linear-gradient(135deg, rgba(20, 20, 40, 0.98) 0%, rgba(40, 40, 60, 0.98) 100%);
    border: 2px solid rgba(255, 215, 0, 0.2);
    border-radius: 15px;
    padding: 0;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(15px);
    z-index: 200;
    width: min(280px, 79vw);
    max-width: 79vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: visible;
    box-sizing: border-box;
}

.build-menu-popup.hidden {
    display: none;
}

.popup-header {
    position: sticky;
    top: 0;
    background: linear-gradient(135deg, rgba(20, 20, 40, 0.98) 0%, rgba(40, 40, 60, 0.98) 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    gap: 9px;
    border-bottom: 2px solid rgba(255, 215, 0, 0.3);
    border-radius: 15px 15px 0 0;
    z-index: 1;
}

#popup-build-options {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 9px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    justify-content: center;
    gap: 9px;
    max-height: 70vh;
    flex-shrink: 0;
}

/* Single button: 1 column */
.build-menu-popup.single-button #popup-build-options {
    grid-template-columns: 1fr;
}

/* Desktop: fixed-width columns for precise layout */
@media screen and (min-width: 769px) {
    .build-menu-popup {
        width: 270px;
    }

    .build-menu-popup.single-button {
        width: 165px;
    }
    .build-menu-popup.single-button #popup-build-options {
        grid-template-columns: 120px;
    }

    .build-menu-popup.two-button {
        width: 270px;
    }
    .build-menu-popup.two-button #popup-build-options {
        grid-template-columns: 120px 120px;
    }

    .build-menu-popup.three-button,
    .build-menu-popup.three-column {
        width: 398px;
    }
    .build-menu-popup.three-button #popup-build-options,
    .build-menu-popup.three-column #popup-build-options {
        grid-template-columns: 120px 120px 120px;
    }

    .build-menu-popup.four-button,
    .build-menu-popup.four-column {
        width: 525px;
    }
    .build-menu-popup.four-button #popup-build-options,
    .build-menu-popup.four-column #popup-build-options {
        grid-template-columns: 120px 120px 120px 120px;
    }

    #popup-build-options {
        grid-template-columns: 120px 120px;
    }
}

#popup-zone-title {
    font-size: 18px;
    font-weight: 700;
    color: #ffd700;
    letter-spacing: 1px;
}

.popup-close {
    background: rgba(255, 100, 100, 0.3);
    border: 2px solid rgba(255, 100, 100, 0.6);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    min-width: 30px;
    min-height: 30px;
}

.popup-close:hover {
    background: rgba(255, 100, 100, 0.6);
    transform: scale(1.1);
}

.build-button {
    background: linear-gradient(135deg, rgba(60, 60, 80, 0.9) 0%, rgba(40, 40, 60, 0.9) 100%);
    border: 3px solid orange !important;
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: white;
    font-family: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 120px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

.build-button:hover {
    background: linear-gradient(135deg, rgba(80, 80, 100, 0.9) 0%, rgba(60, 60, 80, 0.9) 100%);
    border-color: rgba(255, 215, 0, 0.8);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.3);
}

.build-button:active {
    transform: translateY(-1px);
}

.build-button.selected {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.3) 0%, rgba(255, 165, 0, 0.3) 100%);
    border-color: #ffd700;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

/* Cannon ship buttons (distinctive red/crimson border) */
.build-button.cannon-ship {
    border-color: #dc143c !important;
    background: linear-gradient(135deg, rgba(70, 40, 45, 0.9) 0%, rgba(50, 30, 35, 0.9) 100%);
}

.build-button.cannon-ship:hover {
    border-color: rgba(220, 20, 60, 0.9) !important;
    box-shadow: 0 6px 20px rgba(220, 20, 60, 0.4);
}

.build-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Info button (non-clickable display) */
.build-button.info-button {
    background: linear-gradient(135deg, rgba(100, 100, 120, 0.8) 0%, rgba(80, 80, 100, 0.8) 100%);
    border-color: rgba(200, 200, 220, 0.6);
    cursor: default;
    opacity: 0.9;
}

.build-button.info-button:hover {
    transform: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    border-color: rgba(200, 200, 220, 0.6);
}

/* Back button spans full width */
.build-button.back-button {
    grid-column: 1 / -1; /* Span all columns */
    background: linear-gradient(135deg, rgba(80, 60, 40, 0.9) 0%, rgba(60, 40, 30, 0.9) 100%);
    border-color: rgba(255, 165, 0, 0.6);
    min-height: 60px;
}

.build-button.back-button:hover {
    background: linear-gradient(135deg, rgba(100, 80, 60, 0.9) 0%, rgba(80, 60, 50, 0.9) 100%);
    border-color: rgba(255, 165, 0, 0.9);
}

.build-icon {
    font-size: 36px;
    line-height: 1;
    position: relative;
    display: inline-block;
}

.queue-badge {
    position: absolute;
    top: -8px;
    right: -12px;
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    color: #000;
    font-size: 14px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    min-width: 20px;
    text-align: center;
    animation: pulse-badge 2s ease-in-out infinite;
}

@keyframes pulse-badge {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.build-name {
    font-size: 14px;
    font-weight: 700;
    color: #ffffff;
    text-align: center;
    line-height: 1.2;
}

.build-cost {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    font-size: 15px;
    font-weight: 700;
    color: #ffd700;
    max-width: 100%;
    min-width: 0;
}

.cost-icon {
    font-size: 15px;
}

.build-info {
    font-size: 11px;
    color: #90ee90;
    font-style: italic;
    text-align: center;
    line-height: 1.3;
}

/* Instructions Panel */
#instructions {
    position: absolute;
    top: 80px; /* Below header (header is ~60px tall in landscape with horizontal resources) */
    left: 20px;
    background: rgba(0, 0, 0, 0.75);
    border: 2px solid rgba(255, 215, 0, 0.3);
    border-radius: 12px;
    padding: 15px;
    max-width: 280px;
    backdrop-filter: blur(10px);
    z-index: 90;
}

#instructions.hidden {
    display: none;
}

#instructions #help-close {
    position: absolute;
    top: 10px;
    right: 10px;
}

@media (orientation: portrait) {
    #instructions {
        /* Portrait mode - move to bottom, above build menu */
        top: auto;
        bottom: 180px;
        left: 10px;
        right: 10px;
        max-width: none;
    }
}

.instruction-item {
    font-size: 12px;
    line-height: 1.8;
}

/* Show/hide controls based on device */
.mobile-controls {
    display: none;
}

@media (max-width: 768px) {
    .desktop-controls {
        display: none;
    }
    
    .mobile-controls {
        display: block;
    }
    
    .instruction-item {
        color: #cccccc;
        margin-bottom: 8px;
    }
}

.instruction-item:last-child {
    margin-bottom: 0;
}

.instruction-item strong {
    color: #ffd700;
}

/* Info Panel */
#info-panel {
    position: fixed;
    bottom: 160px; /* Above disclaimer (which is at bottom: 20px with ~140px height) */
    left: 20px;
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid rgba(100, 150, 255, 0.5);
    border-radius: 10px;
    padding: 8px 12px;
    max-width: 400px; /* Wider on desktop */
    max-height: 140px;
    overflow-y: auto;
    backdrop-filter: blur(10px);
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#info-panel:empty {
    display: none;
}

.info-message {
    font-size: 12px; /* Smaller font */
    line-height: 1.3;
    color: #e0e0e0;
    padding: 4px 0;
    border-bottom: 1px solid rgba(100, 150, 255, 0.2);
}

.info-message:last-child {
    border-bottom: none;
}

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

/* Hover Tooltip - Hide when menus are open */
#hover-tooltip {
    pointer-events: none;
    z-index: 300;
}

/* Hide hover tooltip when any popup/menu is open (using :has() selector) */
#game-container:has(.build-menu-popup:not(.hidden)) #hover-tooltip,
#game-container:has(#trading-menu-popup:not(.hidden)) #hover-tooltip,
#game-container:has(#audit-popup:not(.hidden)) #hover-tooltip,
#game-container:has(#instructions:not(.hidden)) #hover-tooltip,
#game-container:has(#map-view:not(.hidden)) #hover-tooltip,
#game-container:has(#hierarchy-view:not(.hidden)) #hover-tooltip {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Login Screen */
#login-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    transition: opacity 0.5s ease;
}

#login-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.login-content {
    text-align: center;
    background: linear-gradient(135deg, rgba(20, 20, 40, 0.95) 0%, rgba(30, 30, 50, 0.95) 100%);
    padding: 40px 80px;
    border-radius: 20px;
    border: 3px solid #9d4edd;
    box-shadow:
        0 0 40px rgba(157, 78, 221, 0.4),
        0 0 80px rgba(157, 78, 221, 0.2),
        inset 0 0 20px rgba(157, 78, 221, 0.05);
    max-width: min(700px, calc(100vw - 20px));
    width: 90%;
    backdrop-filter: blur(20px);
    box-sizing: border-box;
}

.login-content h1 {
    font-size: 56px;
    color: #ffd700;
    letter-spacing: 2px;
    margin-bottom: 3px;
    text-shadow:
        0 0 20px rgba(255, 215, 0, 0.6),
        0 4px 20px rgba(0, 0, 0, 0.8);
    font-weight: 800;
}

/* Pyramid-style login title */
.login-content h1.pyramid {
    font-family: 'Arial Black', Arial, sans-serif;
    font-weight: 900;
    letter-spacing: 3px;
    text-transform: uppercase;
    text-shadow: 0 0 25px rgba(255, 215, 0, 0.5), 0 4px 15px rgba(0, 0, 0, 0.8);
    line-height: 1.05;
    font-size: 52px;
    margin-bottom: 10px;
}

.login-subtitle {
    font-size: 16px;
    color: #d0d0d0;
    margin-bottom: 28px;
    letter-spacing: 2px;
    font-style: italic;
    opacity: 0.9;
    line-height: 1.4;
}

#matchmaking-form,
#login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#matchmaking-server-input,
#matchmaking-email-input,
#matchmaking-username-input,
#matchmaking-token-input,
#username-input,
#server-input {
    padding: 7px 18px;
    font-size: 15px;
    border: 2px solid rgba(255, 215, 0, 0.4);
    background: rgba(0, 0, 0, 0.5);
    color: #ffffff;
    border-radius: 10px;
    outline: none;
    transition: all 0.3s ease;
    text-align: center;
}

#matchmaking-server-input::placeholder,
#matchmaking-email-input::placeholder,
#matchmaking-username-input::placeholder,
#matchmaking-token-input::placeholder,
#username-input::placeholder,
#server-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#matchmaking-server-input:focus,
#matchmaking-email-input:focus,
#matchmaking-username-input:focus,
#matchmaking-token-input:focus,
#username-input:focus,
#server-input:focus {
    border-color: #ffd700;
    background: rgba(0, 0, 0, 0.7);
    box-shadow:
        0 0 15px rgba(255, 215, 0, 0.4),
        inset 0 0 10px rgba(255, 215, 0, 0.05);
}

.primary-button {
    padding: 7px 40px;
    font-size: 16px;
    font-weight: 700;
    background: linear-gradient(135deg, #9d4edd 0%, #7b2cbf 100%);
    color: #ffd700;
    border: 2px solid #ffd700;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(157, 78, 221, 0.4);
    text-transform: uppercase;
}

#login-button,
#matchmaking-button {
    padding: 7px 40px;
    font-size: 16px;
    font-weight: 700;
    background: linear-gradient(135deg, #9d4edd 0%, #7b2cbf 100%);
    color: #ffd700;
    border: 2px solid #ffd700;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(157, 78, 221, 0.4);
    text-transform: uppercase;
}

#matchmaking-button {
    text-shadow:
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000,
        1px 1px 0 #000;
}

.primary-button:hover {
    transform: translateY(-3px);
    box-shadow:
        0 8px 25px rgba(157, 78, 221, 0.6),
        0 0 20px rgba(157, 78, 221, 0.4);
    background: linear-gradient(135deg, #b560f5 0%, #9d4edd 100%);
}

#login-button:hover,
#matchmaking-button:hover {
    transform: translateY(-3px);
    box-shadow:
        0 8px 25px rgba(157, 78, 221, 0.6),
        0 0 20px rgba(157, 78, 221, 0.4);
    background: linear-gradient(135deg, #b560f5 0%, #9d4edd 100%);
    color: #ffed4e;
}

.primary-button:active,
#login-button:active,
#matchmaking-button:active {
    transform: translateY(-1px);
}

.primary-button:disabled,
#login-button:disabled,
#matchmaking-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: linear-gradient(135deg, #555 0%, #444 100%);
    border-color: #666;
    color: #888;
    box-shadow: none;
    transform: none;
}

.primary-button:disabled:hover,
#login-button:disabled:hover,
#matchmaking-button:disabled:hover {
    transform: none;
    box-shadow: none;
    background: linear-gradient(135deg, #555 0%, #444 100%);
    color: #888;
}

.secondary-button {
    padding: 6px 20px;
    font-size: 14px;
    font-weight: 700;
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.3) 0%, rgba(255, 165, 0, 0.2) 100%);
    color: #ffd700;
    border: 2px solid rgba(255, 215, 0, 0.6);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 0.5px;
}

.secondary-button:hover {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.5) 0%, rgba(255, 165, 0, 0.4) 100%);
    border-color: #ffd700;
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.2);
    transform: translateY(-2px);
}

.secondary-button:active {
    transform: translateY(0);
}

.login-hint {
    font-size: 13px;
    color: #b0b0b0;
    margin-top: 20px;
}

#toggle-connection-mode {
    color: #ffd700 !important;
    text-decoration: none;
    transition: all 0.3s ease;
    font-weight: 600;
}

#toggle-connection-mode:hover {
    color: #ffed4e !important;
    text-decoration: underline;
}

/* Loading Screen */
#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

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

.loading-content h1 {
    font-size: 48px;
    color: #ffd700;
    letter-spacing: 8px;
    margin-bottom: 30px;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 215, 0, 0.2);
    border-top-color: #ffd700;
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-content p {
    font-size: 16px;
    color: #cccccc;
    letter-spacing: 2px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #header {
        padding: 0px;
        gap: 0px;
        flex-wrap: wrap;
    }

    #game-title {
        font-size: 16px;
        letter-spacing: 1px;
        order: 1;
        flex-shrink: 0;
    }

    #header-buttons {
        order: 2;
        flex-shrink: 0;
        gap: 2px;
        width: 100%;
        justify-content: center;
        margin-left: 0;
    }

    .header-button {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    #resources-panel {
        order: 3;
        width: 100%;
        gap: 0;
        flex-wrap: nowrap;
    }

    .resource-item {
        padding: 0;
    }

    .resource-icon {
        font-size: 16px;
    }

    .resource-label {
        font-size: 12px;
    }

    .resource-value {
        font-size: 13px;
        min-width: 40px;
    }

    .build-button {
        padding: 10px 12px;
    }

    .build-icon {
        font-size: 28px;
    }

    .build-name {
        font-size: 12px;
    }

    .build-cost {
        font-size: 14px;
    }

    .build-info {
        font-size: 10px;
    }

    .instruction-item {
        font-size: 11px;
        margin-bottom: 6px;
    }

    #info-text {
        font-size: 12px;
    }

    .loading-content h1 {
        font-size: 36px;
        letter-spacing: 5px;
    }
}

@media (max-width: 480px) {
    #header {
        padding: 10px 15px;
    }

    #game-title {
        font-size: 18px;
    }

    .resource-item {
        gap: 0;
        padding: 0;
    }

    .resource-icon {
        font-size: 18px;
    }

    .resource-label {
        font-size: 11px;
    }

    .resource-value {
        font-size: 13px;
        min-width: 35px;
    }

    #build-panel {
        padding: 10px;
    }

    .build-button {
        padding: 8px 10px;
        gap: 4px;
    }

    .build-icon {
        font-size: 24px;
    }

    .build-name {
        font-size: 11px;
    }

    .build-cost {
        font-size: 12px;
    }

    .build-info {
        font-size: 9px;
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.resource-value.updated {
    animation: pulse 0.3s ease;
}

/* Trading Menu Styles */
.trading-tab {
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #ffffff;
    cursor: pointer;
    margin-right: 2px;
    border-radius: 2px 2px 0 0;
    font-size: 12px;
}

.trading-tab.active {
    background: rgba(100, 200, 255, 0.3);
}

.trading-tab:hover {
    background: rgba(255, 255, 255, 0.2);
}

.offers-badge {
    background: #ff3333;
    color: white;
    border-radius: 10px;
    padding: 1px 5px;
    font-size: 10px;
    margin-left: 4px;
    font-weight: bold;
}

#trading-menu-popup {
    width: fit-content !important;
    min-width: auto;
}

#trading-menu-popup .popup-header {
    width: 100%;
}

#trading-menu-popup .popup-content {
    width: fit-content;
}

.trading-resource-grid {
    display: grid;
    grid-template-columns: auto auto;
    gap: 0 10px;
    column-gap: 10px;
    position: relative;
    width: fit-content;
}

/* ==================== TRADING MENU LAYOUT PROTECTION ====================
 * CRITICAL: This section prevents recurring alignment issues
 *
 * PROBLEM: The trading menu keeps breaking because:
 * 1. Grid elements placed by HTML source order (fragile)
 * 2. Repeat row has different content than other rows (3 buttons vs input+2 buttons)
 * 3. No width constraints = auto-sizing causes misalignment
 *
 * SOLUTION: Explicit grid positioning + explicit widths
 *
 * CONSTRAINTS THAT MUST BE MAINTAINED:
 * - All trading-resource-rows MUST be exactly 101.63px wide
 * - Repeat row MUST be in grid column 1, row 5
 * - Confirm button MUST be in grid column 2, spanning rows 5-6
 * - Repeat buttons MUST each be 35.36px wide (3 buttons = 106.08px - gaps/icon = 101.63px total)
 *
 * WARNING: Changes here MUST also be made in the "25% SIZE REDUCTION" section (around line 2270)
 * ======================================================================== */

/* EXPLICIT POSITIONING: Prevent layout breaks from HTML order changes */
.trading-resource-row:has([data-resource="repeat"]) {
    grid-column: 1;
    grid-row: 5;
}

/* EXPLICIT WIDTHS: Make repeat buttons equal width to maintain 127.04px row width */
.trading-resource-row:has([data-resource="repeat"]) .trading-btn-small {
    width: 44.2px; /* 3 buttons × 44.2px = exact match to other rows (127.04px total, scaled up 25%) */
}

/* confirm-trade-btn positioning set dynamically in buildTradingGrid() */

.trading-resource-grid::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(255, 215, 0, 0.3);
    transform: translateX(-50%);
}

@media (max-width: 768px) {
    .trading-resource-grid {
        grid-template-columns: 1fr 1fr;
    }

    .trading-resource-grid::before {
        display: block;
    }
}

.trading-resource-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 2.5px;
    border-radius: 2.5px;
    width: fit-content !important;
    justify-self: start !important;
}

.trading-resource-row {
    display: flex;
    align-items: center;
    gap: 2.5px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 2.5px;
    border: 2.5px solid transparent;
    width: fit-content;
}

.resource-icon {
    font-size: 17.5px;
}

.trading-gold-box {
    display: flex;
    align-items: center;
    gap: 2.5px;
    padding: 0;
    background: none;
    border: none;
    border-radius: 0;
    line-height: 1;
    height: 22.5px;
    box-sizing: border-box;
}

.gold-icon {
    font-size: 12.5px;
    line-height: 1;
}

.trading-btn-small {
    padding: 2.5px 5px;
    background: rgba(100, 200, 255, 0.3);
    border: 1.25px solid rgba(100, 200, 255, 0.5);
    color: #ffffff;
    cursor: pointer;
    border-radius: 2.5px;
    font-size: 12.5px;
    line-height: 1;
    height: 22.5px;
    box-sizing: border-box;
}

.trading-btn-small:hover {
    background: rgba(100, 200, 255, 0.5);
}

.trading-btn-small.repeat-btn-active {
    background: rgba(255, 215, 0, 0.6);
    border-color: #FFD700;
    color: #000;
    font-weight: bold;
}

.trading-input {
    width: 56px;
    padding: 2.5px;
    background: rgba(0, 0, 0, 0.5);
    border: 1.25px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    text-align: center;
    border-radius: 2.5px;
    font-size: 14px;
    height: 22.5px;
    box-sizing: border-box;
}

.offer-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 5px;
    border: 1.25px solid rgba(255, 215, 0, 0.3);
}

.offer-header {
    font-size: 15px;
    font-weight: bold;
    margin-bottom: 5px;
    color: #ffd700;
}

.offer-details {
    font-size: 14px;
    margin-bottom: 10px;
    line-height: 1.4;
}

.offer-actions {
    display: flex;
    gap: 5px;
}

.offer-accept-btn {
    flex: 1;
    padding: 5px;
    background: rgba(0, 255, 0, 0.3);
    border: 1.25px solid rgba(0, 255, 0, 0.5);
    color: #ffffff;
    cursor: pointer;
    border-radius: 2.5px;
    font-size: 14px;
}

.offer-accept-btn:hover {
    background: rgba(0, 255, 0, 0.5);
}

.offer-deny-btn {
    flex: 1;
    padding: 5px;
    background: rgba(255, 0, 0, 0.3);
    border: 1.25px solid rgba(255, 0, 0, 0.5);
    color: #ffffff;
    cursor: pointer;
    border-radius: 2.5px;
    font-size: 14px;
}

.offer-deny-btn:hover {
    background: rgba(255, 0, 0, 0.5);
}

/* AEIB (Archipelago Export-Import Bureau) offer styling */
.offer-item.aeib-offer {
    border-left: 3.75px solid #4169e1; /* Royal blue accent (scaled up 25%) */
    background: linear-gradient(to right, rgba(65, 105, 225, 0.15), rgba(0, 0, 0, 0.3));
}

.offer-item.aeib-offer .offer-header {
    color: #4169e1;
}

.trading-cost {
    font-size: 12.5px;
    color: #ffffff;
    min-width: 19px;
    text-align: center;
    line-height: 1;
}

/* Multiplayer Panel */
#multiplayer-panel {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid rgba(100, 150, 255, 0.5);
    border-radius: 4px;
    padding: 8px;
    font-size: 11px;
    color: #e0e0e0;
    min-width: 150px;
}

#multiplayer-panel.hidden {
    display: none;
}

.mp-status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    font-weight: bold;
}

#mp-status-icon {
    font-size: 10px;
}

.mp-detail {
    margin: 2px 0;
    font-size: 10px;
    color: #b0b0b0;
}

.mp-detail.hidden {
    display: none;
}

.mp-player-list {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid rgba(100, 150, 255, 0.3);
    font-size: 10px;
}

.mp-player-list.hidden {
    display: none;
}

.mp-player-item {
    padding: 2px 0;
    color: #c0c0c0;
}

.mp-player-item.self {
    color: #ffd700;
    font-weight: bold;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    /* Larger touch targets */
    .header-button {
        width: 38px;
        height: 38px;
        font-size: 20px;
    }

    /* Compact header on mobile */
    #game-title {
        font-size: 20px;
        letter-spacing: 1px;
    }

    #header {
        padding: 8px 10px !important;
        gap: 8px !important;
        min-height: auto !important;
        align-items: center !important;
    }

    #header-buttons {
        margin: 0 !important;
        padding: 0 !important;
        gap: 2px !important;
    }

    #game-title {
    }

    /* Resource panel - compact 2-row layout for mobile */
    #resources-panel {
        overflow: visible;
        width: 100%;
        max-width: none;
        gap: 0px !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .resource-box {
        display: grid !important;
        /* grid-template-columns set dynamically by JavaScript */
        gap: 0 !important;
        row-gap: 0 !important;
        padding: 0px !important;
        margin: 0 !important;
        width: 100% !important;
        flex-wrap: nowrap !important;
        justify-content: start !important;
        align-items: center !important;
        align-content: start !important;
        grid-auto-rows: 24px !important;
        min-height: 0 !important;
        max-height: fit-content !important;
    }

    .resource-item:not(.hidden) {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        white-space: nowrap !important;
        background: rgba(0, 0, 0, 0.6) !important;
        padding: 2px 4px !important;
        border-radius: 4px !important;
        font-size: 14px !important;
        line-height: 1 !important;
        gap: 0px !important;
        margin: 0 !important;
    }

    .resource-icon {
        font-size: 16px !important;
    }

    .resource-value {
        font-size: 13px !important;
        font-weight: 700 !important;
    }

    /* Keep rate-stack inline-flex for vertical stacking */
    .rate-stack {
        display: inline-flex !important;
        flex-direction: column !important;
        height: auto !important;
        min-height: auto !important;
    }

    .rate-combined {
        font-size: 9px !important;
        line-height: 1 !important;
    }

    .rate-tax {
        font-size: 9px !important;
        line-height: 1 !important;
        margin-top: 1px !important;
    }

    /* Mobile build button styling */
    .build-button {
        min-height: 80px;
        padding: 10px;
        gap: 4px;
        justify-content: center;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .build-icon {
        font-size: 28px;
    }

    .build-name {
        font-size: 13px;
        font-weight: 700;
        text-align: center;
        word-wrap: break-word;
        overflow-wrap: break-word;
        width: 100%;
    }

    .build-cost {
        font-size: 13px;
        gap: 4px;
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
        max-width: 100%;
    }

    .cost-icon {
        font-size: 14px;
    }

    .build-info {
        font-size: 10px;
        text-align: center;
        line-height: 1.2;
        width: 100%;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    #popup-zone-title {
        font-size: 16px;
    }

    /* Info panel - bottom of screen on mobile, full width, smaller font */
    #info-panel {
        position: fixed;
        top: auto;
        bottom: 130px; /* Above disclaimer on mobile */
        left: 10px;
        right: 10px;
        max-width: none; /* Full width minus margins */
        max-height: 100px; /* Shorter on mobile */
        padding: 8px 10px;
        font-size: 11px;
    }

    .info-message {
        font-size: 11px;
        line-height: 1.2;
        padding: 3px 0;
    }

    /* Trading menu mobile */
    #trading-menu-popup {
        width: fit-content !important;
        min-width: auto;
        max-width: 95vw !important;
    }

    #trading-menu-popup .popup-header {
        width: 100%;
    }

    #trading-menu-popup .popup-content {
        width: fit-content;
        max-width: 95vw;
    }

    #trading-menu-popup .popup-content {
        max-width: 95vw;
        max-height: 85vh;
        overflow-y: auto;
        overflow-x: auto;
    }

    /* Trading menu - keep same as desktop, just prevent touch stretching */
    #trading-menu-popup button,
    #trading-menu-popup select,
    #trading-menu-popup input {
        min-height: auto;
    }

    #trading-menu-popup .popup-close {
        height: 28px;
        width: 28px;
    }

    #trading-menu-popup .trading-resource-row {
        width: fit-content;
    }

    #trading-menu-popup .trading-resource-grid {
        grid-template-columns: auto auto;
        width: fit-content;
    }

    #trading-tabs {
        width: fit-content;
    }

    /* Ensure trading partner dropdown is visible on mobile */
    #trading-partner-container {
        display: flex !important;
        flex-shrink: 0;
        min-width: fit-content;
    }

    #trading-partner {
        min-width: 120px;
        flex-shrink: 0;
    }

    /* Map view mobile */
    #map-view {
        max-width: 95vw;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Login screen mobile */
    .login-content {
        padding: 30px 20px;
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
    }

    .login-content h1 {
        font-size: clamp(32px, 9vw, 40px);
        letter-spacing: clamp(2px, 0.5vw, 4px);
        margin-bottom: 6px;
        text-align: center;
    }

    .login-subtitle {
        font-size: 14px;
        margin-bottom: 30px;
    }

    #matchmaking-email-input,
    #matchmaking-username-input,
    #matchmaking-token-input,
    #username-input,
    #server-input {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 48px;
        padding: 14px;
    }

    .primary-button,
    #login-button,
    #matchmaking-button {
        min-height: 48px;
        font-size: 16px;
        padding: 14px;
    }

    .secondary-button {
        min-height: 44px;
        padding: 12px 16px;
        font-size: 13px;
    }

    /* Instructions panel */
    #instructions {
        max-width: 90vw;
        max-height: 80vh;
        overflow-y: auto;
        font-size: 14px;
    }

    /* Popup close buttons - larger touch target */
    .popup-close {
        width: 36px;
        height: 36px;
        font-size: 24px;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    #game-title {
        font-size: 16px;
        display: none; /* Hide title on very small screens */
    }

    /* Further reduce login title on narrow screens */
    .login-content h1 {
        font-size: clamp(24px, 8vw, 32px);
        letter-spacing: clamp(1px, 0.4vw, 2px);
        line-height: 1.2;
        text-align: center;
        word-break: keep-all;
    }

    /* Scale down build menus for very narrow screens */
    .build-menu-popup {
        max-width: 98vw !important;
    }

    .build-menu-popup.single-button,
    .build-menu-popup.two-button,
    .build-menu-popup.three-button,
    .build-menu-popup.four-button,
    .build-menu-popup.three-column,
    .build-menu-popup.four-column {
        width: min(260px, 98vw) !important;
    }

    #popup-build-options {
        gap: 6px !important;
        padding: 6px !important;
    }

    .build-button {
        min-height: 75px !important;
        padding: 8px !important;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Trading menu scaling for very narrow screens */
    #trading-menu-popup {
        max-width: 98vw !important;
    }

    #trading-menu-popup .popup-content {
        max-width: 98vw !important;
    }

    #trading-menu-popup .popup-header {
        padding: 6px !important;
    }

    /* Audit popup scaling for very narrow screens */
    #audit-popup {
        width: 98vw !important;
        max-width: 98vw !important;
    }

    /* All popups - ensure they fit on screen */
    .build-menu-popup,
    #trading-menu-popup,
    #audit-popup,
    #hierarchy-view {
        box-sizing: border-box;
    }

    .resource-item:not(.hidden) {
        font-size: 14px !important;
    }

    .resource-icon {
        font-size: 16px !important;
    }

    .resource-value {
        font-size: 13px !important;
    }

    .rate-combined {
        font-size: 9px !important;
    }

    .rate-tax {
        font-size: 9px !important;
    }
}

/* Ultra-narrow screens (small phones) */
@media (max-width: 360px) {
    .login-content h1 {
        font-size: clamp(20px, 7.5vw, 28px);
        letter-spacing: 0.5px;
        line-height: 1.1;
        text-align: center;
    }
}

/* Landscape mobile */
@media (max-width: 900px) and (orientation: landscape) {
    #header {
        padding: 5px 10px;
    }

    .header-button {
        width: 36px;
        height: 36px;
    }

    #game-title {
        font-size: 18px;
    }

    /* Compact popups in landscape */
    .build-menu-popup,
    #trading-menu-popup,
    #map-view {
        max-height: 90vh;
    }
}

/* Touch-specific improvements */
@media (pointer: coarse) {
    /* Build buttons need larger touch targets */
    .build-button {
        min-height: 44px;
    }

    /* Header buttons need both dimensions to stay circular */
    .header-button {
        min-width: 44px;
        min-height: 44px;
    }

    /* Trading menu keeps compact sizing on touch devices */
    #trading-menu-popup button,
    #trading-menu-popup select {
        min-height: auto;
    }

    /* Keep close button circular */
    .popup-close {
        min-height: auto;
        height: 36px;
        width: 36px;
    }

    /* Prevent text selection on touch */
    .build-button,
    .header-button,
    .trading-btn-small,
    .popup-close {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    /* Better touch feedback */
    button:active,
    .build-button:active {
        transform: scale(0.95);
    }
}

/* Production Audit Table Styles */
.audit-table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.3);
}

.audit-cell {
    padding: 8px 12px;
    border: 1px solid rgba(255, 215, 0, 0.2);
    text-align: center;
    white-space: nowrap;
}

.audit-header {
    background: linear-gradient(135deg, rgba(139, 69, 19, 0.8) 0%, rgba(101, 67, 33, 0.8) 100%);
    color: #FFD700;
    font-weight: bold;
    position: sticky;
    top: 0;
    z-index: 10;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

.audit-player {
    font-weight: bold;
    color: #DDD;
    background: rgba(0, 0, 0, 0.2);
}

.audit-table tbody tr:hover {
    background: rgba(255, 215, 0, 0.1);
}

.audit-table tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.15);
}

.audit-table tbody tr:nth-child(even):hover {
    background: rgba(255, 215, 0, 0.15);
}

#audit-table-container {
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.2);
    overflow-x: auto;
    max-width: 100%;
}

#audit-popup {
    width: auto;
    min-width: min(1000px, 95vw);
    max-width: 95vw;
    overflow: hidden;
    box-sizing: border-box;
}

#audit-popup .popup-content {
    min-width: 100%;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}

/* Mobile Styles */
@media (max-width: 768px) {
    /* Production Audit - Mobile layout */
    #audit-popup {
        width: 95vw !important;
        min-width: auto !important;
        max-width: 95vw !important;
        max-height: 90vh !important;
    }

    #audit-popup .popup-content {
        padding: 10px !important;
    }

    #audit-table-container {
        overflow-x: auto !important;
        max-height: 70vh !important;
        -webkit-overflow-scrolling: touch;
    }

    .audit-table {
        font-size: 10px !important;
        min-width: 100%;
        display: block;
        overflow-x: auto;
    }

    .audit-cell {
        padding: 6px 8px !important;
        white-space: nowrap;
    }

    .audit-header {
        font-size: 11px !important;
        position: sticky;
        top: 0;
    }

    /* Make hierarchy view take more screen space on mobile */
    #hierarchy-view {
        width: 95vw !important;
        height: 85vh !important;
        max-width: 95vw !important;
        max-height: 85vh !important;
    }

    /* Ensure scrolling works properly */
    #hierarchy-view > div:nth-child(3) {
        /* This is the chartWrapper */
        overflow-x: auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }

    /* Remove transform scale - it breaks SVG line alignment
       Let content be natural size and rely on scrolling */

    /* Scale down header elements for mobile */
    #hierarchy-title {
        font-size: 16px !important;
    }

    #hierarchy-instructions {
        font-size: 10px !important;
    }

    /* Scale down close button */
    #hierarchy-view button[style*="position: absolute"] {
        font-size: 16px !important;
        padding: 6px 10px !important;
    }

    /* Compact touch targets for mobile */
    #hierarchy-view button {
        min-height: 36px;
        -webkit-tap-highlight-color: transparent;
    }

    /* Reduce flag sizes by 20% on mobile (exclude connection lines canvas) */
    #hierarchy-view canvas:not(.connection-lines) {
        transform: scale(0.8);
        transform-origin: top center;
    }
}

/* ==================== LOBBY SCREEN ==================== */

#lobby-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    flex-direction: column;
}

#lobby-screen.hidden {
    display: none !important;
}

.lobby-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('/lobby/eoeMsEDRnfodPibnxbViVe-879456682.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    z-index: 9999;
}

.lobby-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    pointer-events: auto;
}

.lobby-marquee {
    background: rgba(20, 20, 40, 0.95);
    border-bottom: 3px solid #ffd700;
    padding: 12px 0;
    width: 100%;
    backdrop-filter: blur(15px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
    color: #ffd700;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.lobby-marquee span {
    color: #ffd700;
}

#lobby-status-detail {
    color: #ffffff;
    font-size: 16px;
}

#lobby-status-timer {
    color: #99ccff;
    font-size: 14px;
    font-family: monospace;
}

.lobby-tagline {
    position: fixed;
    top: 85px;
    left: 20px;
    color: black;
    font-weight: bold;
    font-size: 24px;
    z-index: 10002;
    white-space: nowrap;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 12px;
    border-radius: 4px;
}

.lobby-disclaimer {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    color: black;
    font-size: 12px;
    z-index: 10002;
    pointer-events: none;
    line-height: 1.4;
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 12px;
    border-radius: 4px;
    max-width: calc(100% - 40px);
}

/* Responsive lobby screen for tablets and mobile */
@media (max-width: 768px) {
    .lobby-background {
        background-image: url('/lobby/NASA-X-59-in-Flight-400x263-1487421624.jpg');
        background-attachment: scroll; /* Fixed attachment doesn't work well on mobile */
        background-size: contain;
        background-repeat: no-repeat;
    }

    .lobby-tagline {
        white-space: normal;
        max-width: 90vw;
        font-size: 18px;
        line-height: 1.2;
        top: 75px;
    }

    .lobby-marquee {
        font-size: 14px;
        padding: 10px 8px;
        border-bottom: 2px solid #ffd700;
        gap: 6px;
    }

    #lobby-status-detail {
        font-size: 13px;
    }

    #lobby-status-timer {
        font-size: 12px;
    }
}

/* Responsive lobby screen for narrow mobile */
@media (max-width: 480px) {
    .lobby-marquee {
        font-size: 12px;
        padding: 8px 6px;
        gap: 4px;
        line-height: 1.4;
    }

    #lobby-status-detail {
        font-size: 11px;
    }

    #lobby-status-timer {
        font-size: 10px;
    }
}

/* Responsive lobby screen for very narrow screens */
@media (max-width: 360px) {
    .lobby-marquee {
        font-size: 11px;
        padding: 6px 4px;
        gap: 3px;
    }

    #lobby-status-detail {
        font-size: 10px;
    }

    #lobby-status-timer {
        font-size: 9px;
    }
}

.lobby-status-container.resetting {
    animation: scrollRight 10s linear forwards;
}

.lobby-status-message {
    font-size: 18px;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.5px;
}

.lobby-status-detail {
    font-size: 16px;
    color: #ffffff;
    font-weight: 500;
}

.lobby-status-timer {
    font-size: 14px;
    color: #99ccff;
    font-family: monospace;
}

.lobby-status-timer.warning {
    color: #ffaa00;
    font-weight: bold;
}

.lobby-status-timer.critical {
    color: #ff6b6b;
    font-weight: bold;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Scrolling animations for lobby banner */
@keyframes scrollLeft {
    0% {
        transform: translateX(100%);
    }
    100% {
        transform: translateX(-100%);
    }
}

@keyframes scrollRight {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* ==================== 25% SIZE REDUCTION FOR BUTTONS AND HEADERS ==================== */
/* Reduce actual sizes by 25% (multiply by 0.75) for proper layout */

/* Header elements - reduce padding */
#header {
    padding: 6px 15px; /* was 8px 20px */
}

#game-title {
    font-size: 21px; /* was 28px */
    letter-spacing: 2.25px; /* was 3px */
}

/* Header buttons */
.header-button {
    width: 24px; /* was 32px */
    height: 24px; /* was 32px */
    font-size: 13.5px; /* was 18px */
}

/* Build menu popup headers */
.popup-header {
    padding: 11.25px; /* was 15px */
    gap: 9px; /* was 12px */
}

#popup-zone-title {
    font-size: 13.5px; /* was 18px */
}

.popup-close {
    width: 22.5px; /* was 30px */
    height: 22.5px; /* was 30px */
    min-width: 22.5px; /* was 30px */
    min-height: 22.5px; /* was 30px */
    font-size: 13.5px; /* was 18px */
}

.build-name {
    font-size: 10.5px; /* was 14px */
}

.build-cost {
    font-size: 11.25px; /* was 15px */
    gap: 4.5px; /* was 6px */
}

.cost-icon {
    font-size: 11.25px; /* was 15px */
}

.build-info {
    font-size: 8.25px; /* was 11px */
}

/* Login/Matchmaking buttons */
.primary-button,
#login-button,
#matchmaking-button {
    padding: 5.25px 30px; /* was 7px 40px */
    font-size: 12px; /* was 16px */
    border-radius: 7.5px; /* was 10px */
}

.secondary-button {
    padding: 4.5px 15px; /* was 6px 20px */
    font-size: 10.5px; /* was 14px */
    border-radius: 6px; /* was 8px */
}

/* Login screen title - desktop only, mobile sizes in media queries */
@media (min-width: 769px) {
    .login-content h1 {
        font-size: 42px; /* was 56px */
        letter-spacing: 1.5px; /* was 2px */
    }

    .login-content h1.pyramid {
        font-size: 39px; /* was 52px */
        letter-spacing: 2.25px; /* was 3px */
    }
}

/* Loading screen title */
.loading-content h1 {
    font-size: 36px; /* was 48px */
    letter-spacing: 6px; /* was 8px */
}

/* ==================== MAP VIEW ==================== */
#map-view {
    padding: 15px !important; /* was 20px */
    border-radius: 6px !important; /* was 8px */
}

#map-view h2 {
    font-size: 18px !important; /* was 24px */
}

#map-view button {
    width: 24px !important; /* was 32px */
    height: 24px !important; /* was 32px */
    font-size: 18px !important; /* was 24px */
}

#map-grid {
    gap: 7.5px !important; /* was 10px */
    margin-bottom: 7.5px !important; /* was 10px */
}

/* ==================== HIERARCHY VIEW ==================== */
#hierarchy-view {
    padding: 15px !important; /* Outer padding reduced */
}

#hierarchy-view > button {
    padding: 6px 9px !important; /* was 8px 12px */
    font-size: 16px !important;
}

#hierarchy-view > div:first-of-type {
    padding: 11.25px 15px 3.75px 15px !important; /* was 15px 20px 5px 20px */
}

#hierarchy-view > div:nth-child(3) {
    padding: 0 11.25px 11.25px 11.25px !important; /* was 0 15px 15px 15px */
}

#hierarchy-title {
    font-size: 18px !important; /* was 24px */
}

#hierarchy-instructions {
    font-size: 9px !important; /* was 12px */
}

#hierarchy-chart .player-node {
    padding: 15px !important; /* was 20px */
    margin-bottom: 30px !important; /* was 40px */
}

#hierarchy-chart .players-container {
    gap: 15px !important; /* was 20px */
}

/* ==================== TRADING MENU ==================== */
.trading-tab {
    padding: 1.875px 7.5px; /* was 1.5px 6px (25% increase) */
    margin-right: 1.875px; /* was 1.5px (25% increase) */
    border-radius: 1.875px 1.875px 0 0; /* was 1.5px 1.5px 0 0 (25% increase) */
    font-size: 11.25px; /* was 9px (25% increase) */
}

.offers-badge {
    border-radius: 9.375px; /* was 7.5px (25% increase) */
    padding: 0.9375px 4.6875px; /* was 0.75px 3.75px (25% increase) */
    font-size: 9.375px; /* was 7.5px (25% increase) */
    margin-left: 3.75px; /* was 3px (25% increase) */
}

.trading-resource-grid {
    gap: 0 7.5px; /* was 0 6px (25% increase) */
    column-gap: 7.5px; /* was 6px (25% increase) */
}

/* ==================== TRADING MENU (25% REDUCTION) ====================
 * CRITICAL: These rules MIRROR the base trading menu rules (around line 1098)
 * Any changes to base rules MUST be replicated here with 25% reduction applied
 * ======================================================================== */

/* Maintain explicit positioning in 25% reduction section */
.trading-resource-row:has([data-resource="repeat"]) {
    grid-column: 1;
    grid-row: 5;
}

/* confirm-trade-btn positioning set dynamically in buildTradingGrid() */

/* Repeat buttons width reduction */
.trading-resource-row:has([data-resource="repeat"]) .trading-btn-small {
    width: 33.15px; /* Base: 44.2px, reduced by 25% = 33.15px (scaled up 25% from 26.52px) */
}

.trading-resource-item {
    padding: 1.875px; /* was 1.5px (25% increase) */
    border-radius: 1.875px; /* was 1.5px (25% increase) */
}

.trading-resource-row {
    gap: 1.875px; /* was 1.5px (25% increase) */
    border-radius: 1.875px; /* was 1.5px (25% increase) */
    border: 1.875px solid transparent; /* was 1.5px (25% increase) */
}

.trading-resource-row .resource-icon {
    font-size: 13.125px; /* was 10.5px (25% increase) */
}

.trading-gold-box {
    gap: 1.875px; /* was 1.5px (25% increase) */
    height: 16.875px; /* was 13.5px (25% increase) */
}

.gold-icon {
    font-size: 9.375px; /* was 7.5px (25% increase) */
}

.trading-btn-small {
    padding: 1.875px 3.75px; /* was 1.5px 3px (25% increase) */
    border-radius: 1.875px; /* was 1.5px (25% increase) */
    font-size: 9.375px; /* was 7.5px (25% increase) */
    height: 16.875px; /* was 13.5px (25% increase) */
}

.trading-input {
    width: 42px; /* was 33.75px (25% increase) */
    padding: 1.875px; /* was 1.5px (25% increase) */
    border-radius: 1.875px; /* was 1.5px (25% increase) */
    font-size: 10.3125px; /* was 8.25px (25% increase) */
    height: 16.875px; /* was 13.5px (25% increase) */
}

.offer-item {
    padding: 7.5px; /* was 6px (25% increase) */
    margin-bottom: 7.5px; /* was 6px (25% increase) */
    border-radius: 3.75px; /* was 3px (25% increase) */
}

.offer-header {
    font-size: 11.25px; /* was 9px (25% increase) */
    margin-bottom: 3.75px; /* was 3px (25% increase) */
}

.offer-details {
    font-size: 10.3125px; /* was 8.25px (25% increase) */
    margin-bottom: 7.5px; /* was 6px (25% increase) */
}

.offer-actions {
    gap: 3.75px; /* was 3px (25% increase) */
}

.offer-accept-btn,
.offer-deny-btn {
    padding: 3.75px; /* was 3px (25% increase) */
    border-radius: 1.875px; /* was 1.5px (25% increase) */
    font-size: 10.3125px; /* was 8.25px (25% increase) */
}

.trading-cost {
    font-size: 9.375px; /* was 7.5px (25% increase) */
}