/* 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 for game elements like chat, inventory, controls */
#ui-overlay {
  width: 100%;
  height: 100%;
  pointer-events: none; /* Allow mouse events to pass through by default */
  position: relative; /* Establish positioning context for absolutely positioned children */
  padding: 20px; /* Some padding from the edges for elements */
}

/* Styling for the chat box */
#chat-box {
  pointer-events: all; /* Re-enable pointer events for interaction */
  position: absolute; /* Position explicitly */
  bottom: 20px; /* From the bottom edge */
  left: 20px; /* From the left edge */
  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);
}

#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;
  width: 100%; /* Full width within chat box */
  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 */
  position: absolute; /* Position explicitly */
  top: 20px; /* From the top edge */
  left: 20px; /* From the left edge */
  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;
}

#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;
  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; /* Keep for general inputs not specifically positioned */
  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;
}

/* --- New UI Elements Styling --- */

/* Top Bar (Player Info) */
#top-bar {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%); /* Center horizontally */
    display: flex; /* Use flex to layout contents */
    align-items: center;
    justify-content: center;
    padding: 10px 20px; /* Adjust padding for a bar-like feel */
    min-width: 250px; /* Ensure it's not too small */
}

#player-info {
    display: flex;
    gap: 15px; /* Space between player name and block count */
    font-size: 1.1em;
    color: #e0e0e0;
}

/* Inventory Bar */
#inventory-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%); /* Center horizontally */
    display: flex; /* Arrange slots horizontally */
    gap: 10px; /* Space between inventory slots */
    padding: 10px; /* Padding inside the bar */
    background-color: rgba(30, 30, 50, 0.9); /* Consistent panel background */
    border: 1px solid #4a4a6e;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    pointer-events: all; /* Inventory is interactive */
}

.inventory-slot {
    width: 60px;
    height: 60px;
    background-color: rgba(45, 45, 70, 0.7);
    border: 2px solid #3a3a5e;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
    color: #c0c0c0;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none; /* Prevent text selection */
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
}

.inventory-slot:hover {
    border-color: #a0c4ff;
    background-color: rgba(60, 60, 90, 0.8);
    transform: translateY(-2px);
}

.inventory-slot.active {
    border-color: #a0c4ff; /* Highlight active slot */
    box-shadow: 0 0 12px rgba(160, 196, 255, 0.7), inset 0 0 8px rgba(160, 196, 255, 0.5);
    background-color: rgba(70, 70, 100, 0.9);
    transform: scale(1.05);
}