/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    background: #3d2817;
    color: #3d2817;
    overflow: hidden;
    height: 100vh;
}

#game-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Map Area */
#map-area {
    flex: 1;
    position: relative;
    background-image: url('assets/tile.png');
    background-repeat: repeat;
    background-size: auto;
}

#map-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #e8d5b5;
    opacity: 0.8;
    pointer-events: none;
    z-index: 0;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
    position: relative;
    z-index: 1;
}

/* Top Bar */
#top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(61, 40, 23, 0.9);
    padding: 15px 20px;
    display: flex;
    gap: 30px;
    border-bottom: 3px solid #8b6f47;
    z-index: 10;
    flex-wrap: wrap;
}

.stat {
    color: #f4e4c1;
    font-size: 20px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Side Panel */
#side-panel {
    width: 650px;
    background: #f4e4c1;
    border-left: 4px solid #8b6f47;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Panel Tabs */
#panel-tabs {
    display: flex;
    background: #d4c4a1;
    border-bottom: 3px solid #8b6f47;
    position: sticky;
    top: 0;
    z-index: 100;
}

.tab-btn {
    flex: 1;
    padding: 8px 10px;
    background: #d4c4a1;
    border: none;
    border-right: 2px solid #8b6f47;
    color: #3d2817;
    font-family: inherit;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.tab-icon {
    font-size: 15px;
    line-height: 1;
    margin-bottom: 5px;
}

.tab-label {
    font-size: 12px;
    line-height: 1;
}

.tab-btn:last-child {
    border-right: none;
}

.tab-btn:hover {
    background: #e8d5b5;
}

.tab-btn.active {
    background: #f4e4c1;
    color: #8b4513;
    border-bottom: 3px solid #d4a574;
}

.panel-content {
    display: none;
    padding: 20px;
}

.panel-content.active {
    display: block;
}

/* Headings */
h2 {
    font-size: 28px;
    color: #8b4513;
    margin-bottom: 15px;
    text-align: center;
    border-bottom: 2px solid #d4a574;
    padding-bottom: 10px;
}

h3 {
    font-size: 18px;
    color: #a0826d;
    margin: 20px 0 12px 0;
    border-left: 4px solid #8b6f47;
    padding-left: 10px;
}

/* City Header Compact */
.city-header-compact {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 8px;
}

.city-header-compact h2 {
    display: inline;
    font-size: 24px;
}

.city-desc-inline {
    color: #a0826d;
    font-style: italic;
    font-size: 14px;
}

.city-desc {
    text-align: center;
    color: #a0826d;
    font-style: italic;
    margin-bottom: 20px;
    font-size: 14px;
}

/* City Reputation Inline */
.city-reputation-inline {
    font-size: 14px;
    margin-bottom: 15px;
    padding: 8px 0;
    border-bottom: 1px solid #d4c4a1;
}

.city-reputation {
    background: #e8d5b5;
    border: 2px solid #c9b896;
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 15px;
    text-align: center;
}

.reputation-stars {
    font-size: 20px;
    color: #d4a574;
    margin-bottom: 5px;
}

.reputation-label {
    font-size: 12px;
    color: #6b5537;
    font-weight: bold;
}

/* Buttons */
.btn {
    background: #8b6f47;
    color: #f4e4c1;
    border: 2px solid #6b5537;
    padding: 10px 20px;
    font-size: 15px;
    font-family: inherit;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: inline-block;
    text-align: center;
    width: 100%;
}

.btn:hover:not(:disabled) {
    background: #a0826d;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn-primary {
    background: #d4a574;
    border-color: #b8935f;
    color: #3d2817;
    font-weight: bold;
}

.btn-primary:hover:not(:disabled) {
    background: #e0b584;
}

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
    width: auto;
}

.btn-danger {
    background: #8b4513;
    border-color: #6b3410;
}

.btn-danger:hover:not(:disabled) {
    background: #a0522d;
}

.btn-success {
    background: #228b22;
    border-color: #1a6b1a;
}

.btn-success:hover:not(:disabled) {
    background: #2e9e2e;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Goods List */
.goods-list {
    display: grid;
    gap: 8px;
    margin-bottom: 20px;
    grid-template-columns: repeat(2, 1fr);
}

.good-item {
    background: #e8d5b5;
    border: 2px solid #c9b896;
    border-radius: 4px;
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.good-item.luxury {
    border-color: #d4a574;
    background: linear-gradient(135deg, #f4e4c1 0%, #e8d5b5 100%);
    box-shadow: 0 2px 8px rgba(212, 165, 116, 0.3);
}

.good-item.contraband {
    border-color: #8b4513;
    background: linear-gradient(135deg, #e8d5b5 0%, #d4c4a1 100%);
    position: relative;
    overflow: hidden;
}

.good-item.contraband::before {
    content: '⚠️';
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 12px;
    opacity: 0.5;
}

.good-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.good-icon {
    font-size: 20px;
}

.good-details {
    flex: 1;
}

.good-name {
    font-weight: bold;
    color: #3d2817;
    font-size: 14px;
}

.good-price {
    color: #8b6f47;
    font-size: 12px;
}

.price-indicator {
    font-size: 11px;
    margin-left: 4px;
}

.price-low { color: #228b22; }
.price-high { color: #dc143c; }

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

/* Cargo */
.cargo-list {
    min-height: 50px;
    background: #e8d5b5;
    border: 2px solid #c9b896;
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.cargo-item {
    background: #f4e4c1;
    border: 2px solid #d4c4a1;
    border-radius: 4px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 5px;
}

.cargo-item .good-icon {
    font-size: 24px;
}

.cargo-item .good-details {
    width: 100%;
}

.cargo-item .good-name {
    font-size: 12px;
}

.cargo-item .good-price {
    font-size: 11px;
}

.cargo-quantity {
    background: #8b6f47;
    color: #f4e4c1;
    padding: 2px 8px;
    border-radius: 3px;
    font-weight: bold;
    font-size: 12px;
    min-width: 30px;
    text-align: center;
}

.cargo-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 15px;
    color: #a0826d;
    font-style: italic;
    font-size: 14px;
}

/* Routes */
.routes-list {
    display: grid;
    gap: 8px;
}

.route-item {
    background: #e8d5b5;
    border: 2px solid #c9b896;
    border-radius: 4px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.route-item:hover {
    border-color: #8b6f47;
    background: #f0e0c5;
    transform: translateX(4px);
}

.route-name {
    font-weight: bold;
    font-size: 16px;
    color: #3d2817;
    margin-bottom: 4px;
}

.route-info {
    display: flex;
    gap: 15px;
    font-size: 12px;
    color: #6b5537;
    flex-wrap: wrap;
}

.risk-low { color: #228b22; }
.risk-medium { color: #ffa500; }
.risk-high { color: #dc143c; }

/* === UNIFIED ITEM CARD SYSTEM === */
/* Universal classes used across ALL item types */

/* Universal icon (used by all items) */
.item-icon,
.good-icon,
.shop-icon,
.crew-icon,
.feature-icon,
.investment-icon,
.achievement-icon {
    font-size: 24px;
    min-width: 30px;
    text-align: center;
    line-height: 1;
}

/* Universal content wrapper (flex-grows to fill space) */
.item-info,
.shop-info,
.crew-info,
.feature-content,
.investment-header,
.achievement-info {
    flex: 1;
}

/* Universal name/title */
.item-name,
.shop-name,
.crew-name,
.feature-name,
.investment-name,
.achievement-name {
    font-weight: bold;
    color: #3d2817;
    font-size: 14px;
    margin-bottom: 2px;
}

/* Universal description */
.item-desc,
.shop-desc,
.crew-desc,
.feature-desc,
.investment-desc,
.achievement-desc {
    color: #6b5537;
    font-size: 12px;
    font-style: italic;
}

/* Universal price/cost (legacy - now in buttons but keeping for compatibility) */
.item-price,
.shop-price,
.crew-cost,
.feature-cost,
.investment-cost {
    color: #8b6f47;
    font-size: 13px;
    font-weight: bold;
}

/* Base item container (all items inherit this) */
.shop-item,
.crew-item,
.feature-item,
.investment-item,
.achievement-item {
    background: #e8d5b5;
    border: 2px solid #c9b896;
    border-radius: 4px;
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Owned/active states */
.shop-item.owned,
.crew-item.hired,
.feature-item.active,
.investment-item.owned,
.achievement-item.unlocked {
    opacity: 0.7;
    border-color: #228b22;
}

/* Grid layouts for lists */
.shop-list,
.crew-list,
.features-list,
.investments-list,
.achievements-list {
    display: grid;
    gap: 8px;
    margin-bottom: 20px;
    grid-template-columns: repeat(2, 1fr);
}

/* Contracts */
.contracts-list {
    display: grid;
    gap: 10px;
    margin-bottom: 20px;
}

/* Mini contracts in market tab - 3 column grid */
#active-contracts-mini {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

#active-contracts-mini .contract-item {
    font-size: 11px;
}

#active-contracts-mini .contract-title {
    font-size: 12px;
}

#active-contracts-mini .contract-reward {
    font-size: 11px;
}

/* Single column for mobile */
@media (max-width: 900px) {
    #active-contracts-mini {
        grid-template-columns: 1fr;
    }
}

.contract-item {
    background: #e8d5b5;
    border: 2px solid #c9b896;
    border-radius: 4px;
    padding: 12px;
}

.contract-item.active {
    border-color: #d4a574;
    background: #f0e0c5;
}

.contract-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.contract-title {
    font-weight: bold;
    color: #3d2817;
    font-size: 15px;
}

.contract-reward {
    color: #228b22;
    font-weight: bold;
    font-size: 14px;
}

.contract-desc {
    color: #6b5537;
    font-size: 13px;
    margin-bottom: 8px;
}

.contract-progress {
    background: #d4c4a1;
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.contract-progress-bar {
    background: #228b22;
    height: 100%;
    transition: width 0.3s ease;
}

.contract-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.contract-deadline {
    color: #8b4513;
}

/* Investments */
.investments-list, .monuments-list, .caravans-list {
    display: grid;
    gap: 10px;
    margin-bottom: 20px;
    grid-template-columns: repeat(2, 1fr);
}

/* Investments */
.investments-list {
    display: grid;
    gap: 8px;
    margin-bottom: 20px;
    grid-template-columns: repeat(2, 1fr);
}

/* Investment-specific: income badge */
.investment-income {
    color: #228b22;
    font-weight: bold;
    font-size: 11px;
}

/* Achievements */
.achievements-list {
    display: grid;
    gap: 8px;
    margin-bottom: 20px;
    grid-template-columns: repeat(2, 1fr);
}

/* Achievement-specific: unlocked state different from owned (no opacity change) */
.achievement-item.unlocked {
    border-color: #d4a574;
    background: #f0e0c5;
    opacity: 1; /* Override default owned opacity */
}

/* Achievement icons start dim, become bright when unlocked */
.achievement-icon {
    opacity: 0.3;
}

.achievement-item.unlocked .achievement-icon {
    opacity: 1;
}

/* Leaderboard */
.leaderboard {
    background: #e8d5b5;
    border: 2px solid #c9b896;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 20px;
    max-height: 300px;
    overflow-y: auto;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    margin-bottom: 6px;
    background: #f4e4c1;
    border-radius: 3px;
}

.leaderboard-entry.current {
    border: 2px solid #d4a574;
    background: #f0e0c5;
}

.leaderboard-rank {
    font-weight: bold;
    color: #8b6f47;
    min-width: 30px;
}

.leaderboard-stats {
    flex: 1;
    text-align: right;
    font-size: 13px;
    color: #6b5537;
}

/* Stats Display */
.stats-display {
    background: #e8d5b5;
    border: 2px solid #c9b896;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 20px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid #d4c4a1;
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-label {
    color: #6b5537;
    font-size: 14px;
}

.stat-value {
    color: #3d2817;
    font-weight: bold;
    font-size: 14px;
}

/* Overlays */
#start-overlay, #event-overlay, #gameover-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(61, 40, 23, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#start-overlay.active, #event-overlay.active, #gameover-overlay.active {
    opacity: 1;
    pointer-events: all;
}

#start-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: all;
}

.overlay-content {
    background: #f4e4c1;
    border: 4px solid #8b6f47;
    border-radius: 8px;
    padding: 40px;
    max-width: 600px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    max-height: 80vh;
    overflow-y: auto;
}

.upgrades-info {
    background: #e8d5b5;
    padding: 15px;
    border-radius: 4px;
    margin: 20px 0;
    font-size: 14px;
}

.upgrade-item {
    background: #f4e4c1;
    padding: 6px 10px;
    margin: 4px 0;
    border-radius: 4px;
    border-left: 3px solid #228b22;
}

/* Event Choices */
.choices-list {
    display: grid;
    gap: 10px;
}

.choice-btn {
    background: #e8d5b5;
    border: 2px solid #c9b896;
    border-radius: 4px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.choice-btn:hover {
    background: #f0e0c5;
    border-color: #8b6f47;
    transform: translateY(-2px);
}

.choice-title {
    font-weight: bold;
    color: #3d2817;
    font-size: 16px;
    margin-bottom: 5px;
}

.choice-desc {
    color: #6b5537;
    font-size: 13px;
}

/* Notifications */
.notification, .message {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: #3d2817;
    color: #f4e4c1;
    padding: 12px 24px;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 2000;
    animation: slideDown 0.3s ease;
}

#contract-notification {
    display: none; /* Hidden by default */
    top: 140px; /* Lower position so it doesn't overlap with regular messages */
    background: #228b22;
    font-weight: bold;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Responsive */
@media (max-width: 900px) {
    #game-container {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    #map-area {
        height: 30vh;
        flex-shrink: 0;
    }

    #side-panel {
        width: 100%;
        height: 70vh;
        flex: 1;
        border-left: none;
        border-top: 4px solid #8b6f47;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    #panel-tabs {
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 100;
    }
    
    .panel-content {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #top-bar {
        font-size: 14px;
        gap: 10px;
        padding: 8px 10px;
    }

    .tab-btn {
        padding: 8px 4px;
        gap: 3px;
        min-width: 60px;
    }
    
    .tab-icon {
        font-size: 20px;
    }
    
    .tab-label {
        font-size: 9px;
    }
    
    .cargo-list {
        grid-template-columns: 1fr;
    }
    
    /* Make all 2-column grids single column on mobile */
    .shop-list,
    .achievements-list,
    .investments-list,
    .monuments-list,
    .caravans-list,
    .crew-list,
    .features-list {
        grid-template-columns: 1fr;
    }
}

/* === NEW PANELS === */

/* Crew Panel */
.crew-list {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, 1fr);
}

/* Crew-specific: stat bars for morale/health */
.crew-stats {
    margin-top: 10px;
}

.stat-bar {
    margin-bottom: 8px;
}

.stat-label {
    font-size: 11px;
    color: #5d4a37;
    margin-bottom: 3px;
}

.stat-bar-container {
    height: 12px;
    background: #d4c4a1;
    border-radius: 6px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    transition: width 0.3s ease;
}

/* Features Panel */
.features-list {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, 1fr);
}

/* Features (Services) */
.features-list {
    display: grid;
    gap: 8px;
    margin-bottom: 20px;
    grid-template-columns: repeat(2, 1fr);
}

/* Features - no unique styles needed, all covered by universal classes above */

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #f4e4c1;
    border: 4px solid #8b6f47;
    border-radius: 8px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    color: #3d2817;
    margin-bottom: 15px;
}

.modal-content p {
    color: #5d4a37;
    margin-bottom: 20px;
    line-height: 1.5;
}

#event-choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#event-choices .btn {
    text-align: left;
    padding: 15px;
}

#event-choices .btn small {
    color: #f4e4c1;
    display: block;
    margin-top: 5px;
}

/* Contracts Mini (3-column grid) */
.contracts-mini {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.contracts-mini .contract-item {
    font-size: 13px;
}

.contracts-mini .contract-title {
    font-size: 14px;
}

.contracts-mini .contract-reward {
    font-size: 13px;
}

.contracts-mini .contract-desc {
    font-size: 12px;
    color: #5d4a37;
    margin: 5px 0;
}

.contracts-mini .contract-deadline {
    font-size: 11px;
    color: #8b6f47;
}

/* Additional responsive adjustments */
@media (max-width: 900px) {    
    #panel-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .tab-btn {
        min-width: 70px;
        flex-shrink: 0;
    }
    
    /* Stack all item grids to 1 column on mobile */
    .shop-list,
    .crew-list,
    .features-list,
    .investments-list,
    .achievements-list {
        grid-template-columns: 1fr !important;
    }
}

/* === START SCREEN === */
#start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #8b6f47 0%, #d4a574 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    color: #f4e4c1;
    text-align: center;
}

.start-content {
    max-width: 600px;
    padding: 40px;
    background: rgba(61, 40, 23, 0.3);
    border-radius: 10px;
}

.start-icon {
    width: 200px;
    height: 200px;
    margin-bottom: 30px;
}

#start-screen h1 {
    font-size: 48px;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

#start-screen p {
    font-size: 20px;
    margin-bottom: 40px;
}

#start-screen.hidden {
    display: none;
}

.btn-large {
    font-size: 24px;
    padding: 20px 50px;
}

.hidden {
    display: none !important;
}