@import url('https://fonts.googleapis.com/css2?family=Karla:wght@400;700&display=swap');

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden; /* Prevent scrollbars on the body */
}

body {
    font-family: 'Karla', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
    background-color: #333; /* Dark background for the letterbox */
    color: #3d405b;
}

#game-wrapper {
    width: 100vw;
    height: 100vh;
    background-color: #f4f1de;
    overflow-y: auto; /* Allow scrolling within the game */
    position: relative;
    padding: 10px;
    box-sizing: border-box;
}

/* Letterbox on larger screens */
@media (min-width: 1280px) and (min-height: 720px) {
    body {
        display: flex;
        justify-content: center;
        align-items: center;
    }
    #game-wrapper {
        width: 1280px;
        height: 720px;
        box-shadow: 0 0 20px rgba(0,0,0,0.5);
        border-radius: 12px;
    }
}


.notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #f28482;
    color: white;
    padding: 15px 25px;
    border-radius: 8px;
    z-index: 1000;
    font-size: 18px;
    font-weight: 700;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s, top 0.3s;
}

.notification.show {
    opacity: 1;
    visibility: visible;
    top: 40px;
}

h1, h2 {
    font-weight: 700;
    color: #81b29a;
}

h1 {
    text-align: center;
    margin-bottom: 20px;
}

#game-container {
    display: flex;
    justify-content: space-around;
    gap: 20px;
}

#left-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 250px;
    flex-shrink: 0;
}

#field-container, #warehouse-container, #buildings-container, .modal-content {
    background-color: #c6d5ac; /* New, softer background color */
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    border: 2px solid #3d405b;
}

.btn {
    background-color: #81b29a;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Karla', sans-serif;
    font-size: 16px;
    font-weight: 700;
    transition: background-color 0.2s;
}

.btn:hover {
    background-color: #3d405b;
}

.button-group {
    display: flex;
    gap: 10px;
}

#player-stats {
    background-color: #e07a5f88;
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    font-size: 20px;
    font-weight: 700;
}

#level-display {
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 5px;
}

#xp-bar-container {
    width: 100%;
    background-color: #e0e0e0;
    border-radius: 5px;
    margin-bottom: 10px;
    position: relative;
    height: 20px;
    border: 1px solid #3d405b;
}

#xp-bar {
    width: 0%;
    height: 100%;
    background-color: #81b29a;
    border-radius: 4px;
    transition: width 0.3s ease-in-out;
}

#xp-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #3d405b;
    font-size: 14px;
    font-weight: 700;
    text-shadow: 1px 1px 2px #f4f1de;
    white-space: nowrap;
}

#bonus-display {
    font-size: 14px;
    font-weight: 400;
    margin-top: 10px;
    opacity: 0.8;
}

.language-switcher {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
}

.lang-btn {
    padding: 5px 10px;
    font-size: 14px;
}

.sell-btn {
    background-color: #f28482;
    margin-left: 10px;
}

/* Store Tab Styles */
.store-tabs {
    display: flex;
    border-bottom: 2px solid #3d405b;
    margin-bottom: 15px;
}

.tab-btn {
    background-color: transparent;
    border: none;
    padding: 10px 15px;
    cursor: pointer;
    font-size: 18px;
    font-weight: 700;
    color: #3d405b;
    opacity: 0.6;
}

.tab-btn.active {
    opacity: 1;
    border-bottom: 3px solid #e07a5f;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}


/* Modal Styles */
.modal {
    display: none; /* Hidden by default */
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
}

.modal-content {
    margin: 15% auto;
    width: 80%;
    max-width: 400px;
    position: relative;
}

.close-btn {
    color: #3d405b;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-btn:hover,
.close-btn:focus {
    color: #e07a5f;
}

#field-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 8px;
    background-color: #f2cc8f;
    padding: 10px;
    border-radius: 8px;
    max-width: 500px; /* Prevent oversized plots on large screens */
    margin: auto; /* Center the grid */
    flex-grow: 1; /* Allow grid to grow */
}

.plot {
    aspect-ratio: 1 / 1; /* Maintain square shape, width/height set by grid */
    background-color: #a5682a;
    border: 2px solid #654321;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2em; /* Responsive font size */
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
    overflow: hidden;
}

.plot:hover {
    transform: scale(1.1);
}

#buildings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.building {
    background-color: #f4f1de;
    padding: 15px;
    border-radius: 12px;
    border: 2px solid #3d405b;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.building:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

.building-icon {
    font-size: 40px;
    line-height: 1;
}

.building-name {
    font-size: 18px;
    font-weight: 700;
    color: #3d405b;
}

.building-recipe {
    font-size: 14px;
    opacity: 0.8;
}

.building-timer {
    margin-top: auto; /* Pushes the button/timer to the bottom */
    padding-top: 10px;
    font-weight: 700;
    color: #e07a5f;
}

.item {
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    margin-bottom: 5px;
    transition: background-color 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
}

.item:hover {
    background-color: #f4f1de;
}

.item.selected {
    background-color: #81b29a;
    color: #fff;
    box-shadow: 0 0 5px #81b29a;
    font-weight: 700;
}

#market-items .item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.market-item-info {
    flex-grow: 1;
}

.market-actions {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
}

.sell-amount-input {
    width: 60px;
    padding: 5px;
    border-radius: 4px;
    border: 1px solid #3d405b;
    font-family: 'Karla', sans-serif;
}

#store-items .item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.store-item-info {
    flex-grow: 1;
}

.store-actions {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 5px;
}

.buy-amount-input {
    width: 60px;
    padding: 5px;
    border-radius: 4px;
    border: 1px solid #3d405b;
    font-family: 'Karla', sans-serif;
}


/* Seed-specific colors */
.wheat-seed { background-color: #f2cc8f44; }
.carrot-seed { background-color: #e07a5f44; }
.tomato-seed { background-color: #f2848244; }
.potato-seed { background-color: #a5682a44; }
.strawberry-seed { background-color: #ff8da144; }
.blueberry-seed { background-color: #8cb9ff44; }
.corn-seed { background-color: #f7d04b44; }
.bell-pepper-seed { background-color: #82b74b44; }

/* Override for selected items to ensure text is readable */
.item.selected {
    color: #fff !important;
    background-color: #81b29a;
}

/* Crop-specific colors in the field */
.plot.wheat { background-color: #f2cc8f44; }
.plot.carrot { background-color: #e07a5f44; }
.plot.tomato { background-color: #f2848244; }
.plot.potato { background-color: #a5682a44; }
.plot.strawberry { background-color: #ff8da144; }
.plot.blueberry { background-color: #8cb9ff44; }
.plot.corn { background-color: #f7d04b44; }
.plot.bell-pepper { background-color: #82b74b44; }

.automated-plot {
    border: 3px dashed #81b29a;
    box-sizing: border-box;
}

.product-icon {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.5em;
    z-index: 1;
}

.automation-icon {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.5em;
    z-index: 1;
}
.automated-plot.automated-wheat { border-color: #f2cc8f; }
.automated-plot.automated-carrot { border-color: #e07a5f; }
.automated-plot.automated-tomato { border-color: #f28482; }
.automated-plot.automated-potato { border-color: #a5682a; }
.automated-plot.automated-strawberry { border-color: #ffb3ba; }
.automated-plot.automated-blueberry { border-color: #a2d2ff; }
.automated-plot.automated-corn { border-color: #f7d04b; }
.automated-plot.automated-bell-pepper { border-color: #82b74b; }

.building.automated {
    border-color: #81b29a;
    box-shadow: 0 0 10px #81b29a;
}

.building-automation {
    margin-top: 5px;
}

.recipe-selector-btn {
    background-color: #f28482; /* red */
}

.recipe-selector-btn.active {
    background-color: #81b29a; /* green */
}

/* Orders Section */
#orders-container {
    background-color: #f4f1de;
    padding: 15px;
    border-radius: 12px;
    margin: 0 auto 20px auto;
    max-width: 1000px;
}

#order-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
}

.order {
    padding: 15px;
    border-radius: 8px;
    border: 2px solid rgba(0,0,0,0.2);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.order-info {
    font-size: 14px;
}

/* Customer-specific Order Colors */
.order-customer-npc1 { background-color: #f2cc8fcc; } /* Farmer Joe - Wheat-like */
.order-customer-npc2 { background-color: #a2d2ffcc; } /* Granny Smith - Sky Blue */
.order-customer-npc3 { background-color: #ffc8ddcc; } /* Chef Pierre - Rosy Pink */
.order-customer-npc4 { background-color: #cdb4dbcc; } /* Rancher Rick - Lavender */
.order-customer-npc5 { background-color: #bde0fecc; } /* Baker Betty - Light Blue */

/* Level Up Modal Styles */
#level-up-modal .modal-content {
    text-align: center;
    background: linear-gradient(135deg, #f2cc8f, #e07a5f);
    border-color: #3d405b;
}

#level-up-title {
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    font-size: 2.5em;
}

#level-up-unlocks h3 {
    color: #3d405b;
    border-bottom: 2px solid #3d405b;
    padding-bottom: 5px;
    margin-top: 20px;
}

#level-up-unlocks ul {
    list-style-type: none;
    padding: 0;
}

#level-up-unlocks li {
    background-color: #f4f1de;
    padding: 10px;
    border-radius: 8px;
    margin: 5px 0;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.reset-container {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1000;
}

#debug-controls {
    position: absolute;
    top: 50px;
    right: 10px;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#debug-controls.hidden {
    display: none;
}

/* Mobile Landscape */
@media (max-height: 480px) and (orientation: landscape) {
    h1 {
        font-size: 1.2em;
        margin-top: 10px;
        margin-bottom: 5px;
    }

    #game-container {
        flex-direction: row;
        align-items: flex-start;
        gap: 10px;
    }

    #left-panel {
        min-width: 180px;
        gap: 10px;
    }

    #field-container, #warehouse-container, #buildings-container, .modal-content {
        padding: 10px;
    }

    #field-container, #buildings-container {
        flex-grow: 1;
    }

    #field-grid {
        grid-template-columns: repeat(5, 1fr);
        grid-template-rows: repeat(5, 1fr);
        gap: 5px;
        padding: 5px;
    }

    .plot {
        font-size: 1.5em; /* Adjust font size for smaller plots */
    }

    #buildings-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    }

    #orders-container {
        padding: 5px;
        margin-bottom: 10px;
    }

    #order-items {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 10px;
    }

    .btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .modal-content {
        width: 90%;
        max-width: none;
        margin: 2% auto;
        padding: 15px;
    }

    .tab-btn {
        padding: 8px 12px;
        font-size: 14px;
    }

    .close-btn {
        font-size: 24px;
        top: 5px;
        right: 10px;
    }
}

.btn.disabled, .btn:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    border-color: #999999;
}

.btn-danger {
    background-color: #dc3545 !important;
    color: white;
}

.btn-danger:hover {
    background-color: #c82333 !important;
}

.recipe-selector-btn.btn-inactive {
    background-color: #6c757d;
    color: white;
    opacity: 0.65;
}

.building-status-problem {
    color: #dc3545;
    font-weight: bold;
    margin-top: 5px;
}
