/* General Styles */
*,
*:before,
*:after {
 box-sizing: border-box;
}

body {
 font-family: 'Lora', serif;
 background-color: #1a2634;
 color: #ecf0f1;
 line-height: 1.7;
 margin: 0;
 padding: 10px; /* Padding on body for overall spacing */
}

.container {
 width: 90%;
 max-width: 1200px;
 margin: 10px auto;
 background-color: #2c3e50;
 border-radius: 20px;
 padding: 10px; /* Padding inside container */
 box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* Layout Sections */
.top-section {
 display: flex;
 gap: 20px;
 margin-bottom: 20px;
}

.left-section {
 flex: 1;
 display: flex;
 flex-direction: column;
 gap: 10px;
}

/* Canvas Area */
#canvas-area {
 width: 100%;
 background-color: #34495e;
 border-radius: 12px;
 box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
 padding: 5px;
 display: flex;
 flex-direction: column;
 align-items: center;
}

#gameCanvas {
 border: 1px solid black;
 display: block;
 background-color: #34495e;
 max-width: 100%;
 border-radius: 8px;
}

/* Resource Bar */
#resource-bar {
 display: flex;
 gap: 10px;
 padding: 10px;
 background-color: #34495e;
 border-radius: 12px;
 justify-content: space-between;
}

#resource-bar p {
 margin: 0;
 font-size: 1.1em;
 padding: 10px;
 background-color: #2c3e50;
 border-radius: 8px;
 box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
 flex: 1;
 text-align: left;
}

#resource-bar span {
 float: right;
 font-weight: bold;
 color: #3498db;
}

/* Game State Panel */
#game-state {
 width: 250px;
 flex-shrink: 0;
 padding: 15px;
 border-radius: 12px;
 background-color: #34495e;
}

#game-state p {
 margin: 6px 0;
 font-size: 1.1em;
 padding: 10px;
 background-color: #2c3e50;
 border-radius: 8px;
 box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#game-state span {
 float: right;
 font-weight: bold;
 color: #3498db;
}

/* Chat Area */
#chat-area {
 display: flex;
 flex-direction: column;
 gap: 10px;
 /* Add margin below chat area to space it from options container on mobile */
 margin-bottom: 15px;
}

#chat-log {
 height: 250px;
 padding: 15px;
 overflow-y: auto;
 background-color: #2c3e50;
 border-radius: 12px;
 box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
}

.message-container {
 display: flex;
 align-items: center;
 margin-bottom: 12px;
 padding: 10px;
 border-radius: 8px;
 background-color: #34495e;
 transition: transform 0.2s ease;
}

.message-container:hover {
 transform: translateX(5px);
}

#chat-input {
 width: 100%;
 padding: 12px;
 border: none;
 border-radius: 25px;
 background-color: #34495e;
 color: #fff;
 font-size: 1.1em;
 transition: all 0.3s ease;
 outline: none;
}

#chat-input:focus {
 background-color: #3d566e;
 box-shadow: 0 0 12px rgba(52, 152, 219, 0.3);
}

/* Buttons & Controls Specific */
.ackButton {
 padding: 8px 16px;
 border: none;
 border-radius: 20px;
 background-color: #3498db;
 color: white;
 font-weight: bold;
 cursor: pointer;
 transition: all 0.3s ease;
}

.ackButton:hover {
 background-color: #2980b9;
 transform: scale(1.1);
}

/* Water Display */
.water-container {
 display: inline-block;
}

#water {
 color: blue;
}

#dirty-water {
 color: brown;
}

/* Game Options Container (Desktop: Fixed, Mobile: Static) */
.game-options-container {
 /* Default Desktop Styles: Fixed */
 position: fixed;
 bottom: 10px;
 left: 10px;
 z-index: 1000;
 opacity: 0.5;
 transition: opacity 0.3s ease;
 display: flex;
 flex-direction: column;
 align-items: flex-start;
 gap: 8px;
 background-color: transparent; /* No background needed when fixed */
 padding: 0; /* No padding needed when fixed */
}

.game-options-container:hover {
 opacity: 1;
}

/* Ensure direct children don't have unwanted left margins (Desktop) */
.game-options-container > * {
 margin-left: 0;
}

/* Styles for elements within game-options-container */
#play-pause-button,
#save-button,
#load-button,
#cloud-save-button {
 background-color: #4caf50;
 border: none;
 color: white;
 padding: 5px 10px;
 text-align: center;
 text-decoration: none;
 display: inline-block;
 font-size: 14px;
 cursor: pointer;
 border-radius: 5px;
 margin: 0; /* Reset margin, rely on gap or container padding */
}

#play-pause-button:hover,
#save-button:hover,
#load-button:hover,
#cloud-save-button:hover {
 background-color: #3e8e41;
}

.auto-task-label {
 display: inline-flex;
 align-items: center;
 color: white;
 font-size: 14px;
 cursor: pointer;
 margin: 0;
}

#auto-task-checkbox {
 margin-right: 4px;
 cursor: pointer;
 appearance: none;
 -webkit-appearance: none;
 width: 16px;
 height: 16px;
 border: 2px solid #4caf50;
 border-radius: 3px;
 background: transparent;
 position: relative;
 vertical-align: middle;
}

#auto-task-checkbox:checked {
 background: #4caf50;
}

#auto-task-checkbox:checked::after {
 content: '✓';
 position: absolute;
 color: white;
 font-size: 12px;
 line-height: 1;
 left: 2px;
 top: 0px;
}

#ai-model-selector {
 background-color: #4caf50;
 border: none;
 color: white;
 padding: 5px 10px;
 padding-right: 25px;
 font-size: 14px;
 cursor: pointer;
 border-radius: 5px;
 -moz-appearance: none;
 appearance: none;
 background-image: url("data:image/svg+xml;utf8,<svg fill='white' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
 background-repeat: no-repeat;
 background-position-x: 95%;
 background-position-y: center;
 background-size: 16px 16px;
 margin: 0;
}

#ai-model-selector:hover {
 background-color: #3e8e41;
}

/* Scrollbar Styles */
::-webkit-scrollbar {
 width: 10px;
}

::-webkit-scrollbar-track {
 background: #2c3e50;
 border-radius: 5px;
}

::-webkit-scrollbar-thumb {
 background: #3498db;
 border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
 background: #2980b9;
}

/* --- Modal Styles --- */
.modal {
 display: none;
 position: fixed;
 z-index: 1001;
 left: 0;
 top: 0;
 width: 100%;
 height: 100%;
 overflow: auto;
 background-color: rgba(0, 0, 0, 0.6);
 justify-content: center;
 align-items: center;
 font-family: 'Lora', serif;
}

.modal-content {
 background-color: #2c3e50;
 margin: auto;
 padding: 25px 30px;
 border: 1px solid #888;
 width: 80%;
 max-width: 450px;
 border-radius: 15px;
 box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
 position: relative;
 text-align: center;
 color: #ecf0f1;
}

.modal-content h2 {
 margin-top: 0;
 color: #3498db;
}

.modal-content p {
 line-height: 1.6;
 margin-bottom: 15px;
}

.modal-content input[type="text"] {
 width: calc(100% - 24px);
 padding: 12px;
 margin-bottom: 10px;
 border: 1px solid #34495e;
 border-radius: 5px;
 background-color: #34495e;
 color: #ecf0f1;
 font-size: 1em;
}

.modal-content input[type="text"]:focus {
 outline: none;
 border-color: #3498db;
 box-shadow: 0 0 8px rgba(52, 152, 219, 0.3);
}

.modal-content button {
 background-color: #3498db;
 color: white;
 padding: 12px 20px;
 border: none;
 border-radius: 5px;
 cursor: pointer;
 font-size: 1em;
 transition: background-color 0.2s ease;
 margin-top: 10px;
}

.modal-content button:hover {
 background-color: #2980b9;
}

.modal-error {
 color: #e74c3c;
 font-size: 0.9em;
 height: 1.2em;
 margin-bottom: 5px;
}

.close-button {
 color: #aaa;
 position: absolute;
 top: 10px;
 right: 15px;
 font-size: 28px;
 font-weight: bold;
}

.close-button:hover,
.close-button:focus {
 color: #ecf0f1;
 text-decoration: none;
 cursor: pointer;
}

.modal-visible {
 display: flex;
}

/* --- Responsive Styles --- */

/* Mobile styles (Portrait & General) */
@media screen and (max-width: 768px) {
 body {
 padding: 5px;
 /* REMOVED padding-bottom: 80px; */
 box-sizing: border-box;
 }

 .container {
 width: 95%;
 padding: 8px;
 margin: 5px auto;
 /* REMOVED margin-bottom: 0; */
 }

 .top-section {
 flex-direction: column;
 gap: 5px;
 }

 #game-state {
 order: -1;
 width: calc(100% - 10px);
 display: grid;
 grid-template-columns: repeat(2, 1fr);
 gap: 3px;
 padding: 5px;
 font-size: 0.8em;
 box-sizing: border-box;
 }

 #game-state p {
 margin: 1px;
 padding: 4px 8px;
 font-size: 1em;
 width: 100%;
 box-sizing: border-box;
 }

 #canvas-area {
 padding: 3px;
 width: calc(100% - 6px);
 box-sizing: border-box;
 }

 #gameCanvas {
 width: 100%;
 height: auto;
 }

 #resource-bar {
 width: calc(100% - 10px);
 display: grid;
 grid-template-columns: repeat(2, 1fr);
 gap: 3px;
 padding: 5px;
 font-size: 0.8em;
 box-sizing: border-box;
 }

 #resource-bar p {
 margin: 1px;
 padding: 4px 8px;
 font-size: 1em;
 width: 100%;
 box-sizing: border-box;
 }

 #chat-log {
 height: 180px;
 }

 #chat-input {
 width: calc(100% - 24px);
 box-sizing: border-box;
 }

 /* Game Options Container on Mobile: Static Flow */
 .game-options-container {
 /* Override fixed positioning */
 position: static; /* CHANGE: Back to normal flow */
 opacity: 1; /* Fully visible */
 z-index: auto; /* Reset z-index */

 /* Layout */
 display: flex; /* Keep flex for centering/wrapping */
 flex-direction: row;
 flex-wrap: wrap;
 justify-content: center;
 align-items: center;
 gap: 10px;
 width: 100%; /* Take full width available */
 padding: 10px; /* Add padding for spacing */
 margin-top: 15px; /* Add space above the container */
 background-color: #2c3e50; /* Give it a background */
 border-radius: 10px; /* Optional rounded corners */
 box-sizing: border-box;
 }

 /* No need to reset margin-left here as it's handled by flex centering */
 /* .game-options-container > * { margin-left: 0; } */
}

/* Small phones */
@media screen and (max-width: 480px) {
 #chat-log {
 height: 150px;
 }

 .game-options-container {
 gap: 5px;
 padding: 8px;
 margin-top: 10px;
 }

 .game-options-container button,
 .game-options-container select,
 .game-options-container label {
 font-size: 12px;
 padding: 4px 8px;
 }

 #ai-model-selector {
 padding-right: 20px;
 }
}

/* Landscape mode */
@media screen and (max-width: 768px) and (orientation: landscape) {
 .container {
 max-height: 95vh;
 overflow: hidden;
 }

 .top-section {
 flex-direction: row;
 align-items: flex-start;
 }

 #game-state {
 order: 0;
 width: 200px;
 grid-template-columns: 1fr;
 font-size: 0.9em;
 }

 #game-state p {
 font-size: 0.9em;
 }

 .left-section {
 flex: 1;
 }

 #chat-log {
 height: 100px;
 }

 #chat-input {
 /* Ensure input doesn't cause overflow */
 max-width: 100%;
 }

 #gameCanvas {
 max-height: 45vh;
 }

 /* Game Options Container in Landscape: Still Static */
 .game-options-container {
 /* Keep static positioning from the portrait mobile rule */
 /* Adjustments if needed for landscape */
 margin-top: 10px;
 padding: 8px;
 gap: 8px;
 }
}
