#uiContainer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through to the canvas */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #f0f0f0;
}
/* Main Tool Panel */
.tool-panel {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    background-color: rgba(30, 40, 50, 0.85);
    border: 1px solid rgba(150, 180, 210, 0.3);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
    pointer-events: auto;
    backdrop-filter: blur(10px);
}
.tool-btn {
    background-color: transparent;
    border: 2px solid transparent;
    color: #a0b0c0;
    font-size: 1.8rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s;
    line-height: 1;
}
.tool-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}
.tool-btn.active {
    background-color: #4a90e2;
    color: white;
}
.popup-screen {
    position: absolute;
    background-color: rgba(30, 40, 50, 0.85);
    border: 1px solid rgba(150, 180, 210, 0.3);
    border-radius: 8px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    min-width: 300px;
    pointer-events: auto; /* Capture events for this element */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    overflow: hidden;
    max-height: calc(100vh - 40px); /* Ensure panel doesn't exceed viewport height */
    max-width: 900px; /* Max width for 3-column layout */
}

.popup-header {
    background-color: rgba(50, 65, 80, 0.9);
    padding: 8px 12px;
    cursor: grab;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(150, 180, 210, 0.2);
}

.popup-title {
    font-weight: 600;
    font-size: 1rem;
}

.popup-close-btn {
    background: none;
    border: none;
    color: #a0b0c0;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 5px;
    transition: color 0.2s;
}

.popup-close-btn:hover {
    color: #ffffff;
}

.popup-content {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto; /* Allow content to scroll vertically */
    flex: 1; /* Allow content to fill available space */
}
.panel-columns {
  display: flex;
  flex-direction: row;
  gap: 20px;
}
.panel-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel-column h4 {
  margin-top: 0;
  margin-bottom: 8px;
  color: #a0b0c0;
  font-weight: 500;
  border-bottom: 1px solid rgba(150, 180, 210, 0.2);
  padding-bottom: 8px;
}
.panel-section {
    padding-top: 15px;
    margin-top: 15px;
    border-top: 1px solid rgba(150, 180, 210, 0.2);
}
.panel-footer {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid rgba(150, 180, 210, 0.2);
  display: flex;
  gap: 10px;
  flex-wrap: wrap; /* Allow buttons to wrap on smaller screens */
}
.panel-footer button {
  flex: 1;
}
/* Form elements styling */
.input-row {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.label-with-button {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#refresh-worlds-btn {
  background: none;
  border: none;
  color: #a0b0c0;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 5px;
  transition: color 0.2s, transform 0.2s;
}
#refresh-worlds-btn:hover {
  color: #4a90e2;
  transform: rotate(90deg);
}
#refresh-worlds-btn:active {
  transform: scale(0.95) rotate(180deg);
}
.input-row label {
    font-size: 0.85rem;
    color: #c0d0e0;
}
.radio-group {
    display: flex;
    gap: 10px;
    background-color: rgba(0,0,0,0.2);
    padding: 5px;
    border-radius: 5px;
}
.radio-group label {
    flex-grow: 1;
    text-align: center;
    padding: 5px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    font-size: 0.8rem;
}
.radio-group input {
    display: none;
}
.radio-group input:checked + label {
    background-color: #4a90e2;
    color: white;
    font-weight: 600;
}
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: #2c3e50;
    outline: none;
    opacity: 0.9;
    transition: opacity .2s;
    border-radius: 4px;
}
input[type="range"]:hover {
    opacity: 1;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: #4a90e2;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #ffffff;
}
input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #4a90e2;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #ffffff;
}

button {
    background-color: #4a90e2;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s, transform 0.1s;
}

button:hover {
    background-color: #357abd;
}

button:active {
    background-color: #2a6198;
    transform: scale(0.98);
}
.input-row button + button {
  margin-left: 10px;
}
button.btn-danger {
  background-color: #E91E63; /* A distinct, alarming color */
}
button.btn-danger:hover {
  background-color: #c2185b;
}
button.btn-danger:active {
  background-color: #ad1457;
}
hr {
  border: none;
  border-top: 1px solid rgba(150, 180, 210, 0.2);
  margin: 10px 0;
}
input[type="text"], select {
    width: 100%;
    padding: 8px;
    background-color: #1e2a38;
    border: 1px solid #2c3e50;
    border-radius: 4px;
    color: #e0e0e0;
    box-sizing: border-box; /* Important for width */
}
input[type="text"]:focus, select:focus {
    outline: none;
    border-color: #4a90e2;
    box-shadow: 0 0 5px rgba(74, 144, 226, 0.5);
}
select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23c0d0e0%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
    background-repeat: no-repeat;
    background-position: right 10px top 50%;
    background-size: .65em auto;
    padding-right: 25px; /* Make space for the arrow */
}
/* Modal styles */
.modal-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    pointer-events: auto;
    backdrop-filter: blur(5px);
}
.modal-dialog {
    background-color: #2a3b4d;
    padding: 25px 30px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    min-width: 320px;
    max-width: 450px;
    text-align: center;
    border: 1px solid rgba(150, 180, 210, 0.3);
    animation: modal-fade-in 0.3s ease-out;
}
@keyframes modal-fade-in {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
.modal-message {
    margin-top: 0;
    margin-bottom: 25px;
    font-size: 1.05rem;
    color: #e0e0e0;
    line-height: 1.6;
}
.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
}
.modal-buttons button {
    min-width: 110px;
}
button.btn-secondary {
    background-color: #5a6878;
}
button.btn-secondary:hover {
    background-color: #6a7c8e;
}
button.btn-secondary:active {
    background-color: #495563;
}
/* Info Panel styles */
.info-panel {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 220px;
  background-color: rgba(30, 40, 50, 0.8);
  border: 1px solid rgba(150, 180, 210, 0.25);
  border-radius: 8px;
  padding: 12px 18px;
  color: #c0d0e0;
  font-size: 0.85rem;
  pointer-events: auto;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}
.info-panel .info-header {
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 10px;
  font-size: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  padding-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.info-panel.collapsed .info-header {
  margin-bottom: 0;
  border-bottom: none;
  padding-bottom: 0;
}
.info-toggle-btn {
  background: none;
  border: none;
  color: #a0b0c0;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 5px;
  transition: color 0.2s, transform 0.2s;
}
.info-toggle-btn:hover {
  color: #ffffff;
  transform: scale(1.1);
}
.info-panel ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.info-panel li {
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}
.info-panel b {
  color: #4a90e2;
  font-weight: 600;
}
/* Mobile Controls */
#joystick-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 150px;
    height: 150px;
    pointer-events: auto;
}
#joystick-container .back {
    background-color: rgba(0, 0, 0, 0.2) !important;
    border: 2px solid rgba(255, 255, 255, 0.3) !important;
}
#joystick-container .front {
    background-color: rgba(255, 255, 255, 0.5) !important;
}