/* Universal box-sizing reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Body styles for a full-screen application */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #1a1a2e; /* Dark background for a game environment */
  color: #e0e0e0; /* Light text color */
  overflow: hidden; /* Prevent scrolling, as canvas will fill screen */
  height: 100vh; /* Full viewport height */
  width: 100vw; /* Full viewport width */
  line-height: 1.6;
  position: relative; /* Establish stacking context for children */
}

/* Styles for the main game canvas (dynamically created by Three.js in script.js) */
/* This targets the <canvas> element that script.js appends directly to the body. */
canvas {
  position: absolute; /* Position relative to the body */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1; /* Place behind all UI elements */
  display: block; /* Ensure it behaves as a block element */
  background-color: #000; /* Fallback background for canvas area */
}

/* Main container for the UI elements, overlays the canvas */
#game-container {
  position: absolute; /* Position relative to the body */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10; /* Ensure UI is above the canvas */
  /* #ui-overlay will handle its own layout within this container */
}

/* UI Overlay for game elements like chat, inventory, controls */
#ui-overlay {
  width: 100%;
  height: 100%;
  pointer-events: none; /* Allow mouse events to pass through by default */
  display: flex; /* Use flexbox for overall layout */
  flex-direction: column; /* Stack main areas vertically */
  justify-content: space-between; /* Push top and bottom areas to edges */
  padding: 20px; /* Some padding from the edges */
}

/* Styling for the chat box */
#chat-box {
  pointer-events: all; /* Re-enable pointer events for interaction */
  align-self: flex-start; /* Align to the start (left) of the bottom section */
  background-color: rgba(30, 30, 50, 0.8); /* Semi-transparent dark background */
  border: 1px solid #4a4a6e;
  border-radius: 8px;
  padding: 10px;
  width: 300px; /* Fixed width for chat */
  max-height: 250px; /* Max height for chat box */
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  margin-top: auto; /* Push to the bottom within its flex parent (ui-overlay) */
}

#chat-messages {
  flex-grow: 1; /* Allow messages area to take available space */
  overflow-y: auto; /* Enable scrolling for messages */
  margin-bottom: 10px;
  font-size: 0.9em;
  line-height: 1.4;
  color: #c0c0c0;
  padding-right: 5px; /* Space for scrollbar */
}

/* Custom scrollbar for chat messages */
#chat-messages::-webkit-scrollbar {
  width: 8px;
}

#chat-messages::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: #4a4a6e;
  border-radius: 4px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
  background: #a0c4ff;
}

#chat-input {
  background-color: #2a2a4a;
  border: 1px solid #4a4a6e;
  color: #e0e0e0;
  padding: 10px;
  border-radius: 5px;
  font-size: 1em;
  margin-bottom: 0; /* Override general input margin */
  width: 100%; /* Full width within chat box */
  max-width: none; /* Override max-width from general input style */
  pointer-events: all; /* Inputs are interactive */
}

#chat-input:focus {
  outline: none;
  border-color: #a0c4ff;
  box-shadow: 0 0 5px rgba(160, 196, 255, 0.5);
}

/* Styling for controls information */
#controls-info {
  pointer-events: none; /* Info display, no interaction needed */
  align-self: flex-start; /* Align to the start (left) of the top section */
  background-color: rgba(30, 30, 50, 0.8);
  border: 1px solid #4a4a6e;
  border-radius: 8px;
  padding: 10px 15px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  color: #c0c0c0;
  font-size: 0.9em;
  margin-bottom: auto; /* Push to the top within its flex parent (ui-overlay) */
}

#controls-info p {
    margin: 0; /* Remove default paragraph margin */
    padding: 0;
    font-size: 1em; /* Adjust relative to parent */
}

/* General UI element styles */
.ui-panel {
  background-color: rgba(30, 30, 50, 0.9);
  border: 1px solid #4a4a6e;
  border-radius: 8px;
  padding: 20px;
  margin: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  color: #e0e0e0;
  pointer-events: all; /* Panels are interactive */
}

button,
.button {
  background-color: #a0c4ff;
  color: #1a1a2e;
  border: none;
  padding: 10px 20px;
  margin: 5px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1em;
  font-weight: bold;
  transition: background-color 0.3s ease, transform 0.2s ease;
  pointer-events: all; /* Buttons are interactive */
}

button:hover,
.button:hover {
  background-color: #b8d0ff;
  transform: translateY(-2px);
}

button:active,
.button:active {
  transform: translateY(0);
  background-color: #8cb5ff;
}

/* General input styles - specific overrides for #chat-input are handled above */
input[type="text"],
textarea {
  background-color: #2a2a4a;
  border: 1px solid #4a4a6e;
  color: #e0e0e0;
  padding: 10px;
  border-radius: 5px;
  font-size: 1em;
  margin-bottom: 10px;
  width: 100%;
  max-width: 300px; /* Default max-width for general inputs */
  pointer-events: all; /* Inputs are interactive */
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: #a0c4ff;
  box-shadow: 0 0 5px rgba(160, 196, 255, 0.5);
}

/* H1 and P styles for general use within UI, if applicable */
h1 {
  font-size: 2.8em;
  margin-bottom: 0.5em;
  color: #a0c4ff;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  letter-spacing: 1px;
}

p {
  font-size: 1.2em;
  margin-bottom: 1.5em;
  max-width: 800px;
  padding: 0 20px;
  color: #c0c0c0;
}