@import url("https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Space+Grotesk:wght@400;600;700&family=JetBrains+Mono:wght@400;600&display=swap");

/* ─── BASE STYLES ─────────────────────── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Space Grotesk", sans-serif;
  background: #1a1a2e;
  color: #f0e6d3;
  overflow: hidden;
  height: 100vh;
  user-select: none;
}

#three-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ─── SELECTION BOX ───────────────────── */
#selection-box {
  position: absolute;
  background: rgba(255, 215, 0, 0.1);
  border: 1px solid rgba(255, 215, 0, 0.5);
  pointer-events: none;
  display: none;
  z-index: 50;
}

/* ─── HUD ────────────────────────────── */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 10;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: linear-gradient(
    180deg,
    rgba(10, 10, 20, 0.95) 0%,
    transparent 100%
  );
  pointer-events: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Cinzel", serif;
  font-size: 22px;
  font-weight: 700;
  color: #ffd700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #ffd700, #f4a940);
  border: 2px solid #8b6c42;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.status-pills {
  display: flex;
  gap: 12px;
}

.pill {
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(20, 21, 38, 0.9);
  border: 1px solid #8b6c42;
  color: #f0e6d3;
  font-family: "Space Grotesk", sans-serif;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.pill.active {
  border-color: #4ade80;
  color: #4ade80;
  background: rgba(20, 40, 30, 0.9);
}
.pill.idle {
  border-color: #f4a940;
  color: #f4a940;
  background: rgba(40, 30, 20, 0.9);
}

/* ─── Camera Controls ─────────────────── */
.camera-controls {
    position: fixed; 
    bottom: 80px; /* Moved to bottom right to avoid Roster overlap */
    right: 20px;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: auto;
}

.cam-btn {
  padding: 10px 14px;
  border-radius: 6px;
  background: #2a2a3e;
  border: 2px solid #444;
  color: #ccc;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: "Cinzel", serif;
  text-transform: uppercase;
  box-shadow: 0 4px 0 #1a1a2e;
}
.cam-btn:hover {
  border-color: #f4a940;
  color: #f4a940;
  transform: translateY(-1px);
}
.cam-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #1a1a2e;
}
.cam-btn.active {
  border-color: #ffd700;
  color: #ffd700;
  background: #3a3a52;
}

/* ─── Agent Name Tag (Persistent) ─────── */
.agent-nametag {
    position: absolute;
    transform: translate(-50%, -100%);
    text-align: center;
    pointer-events: none;
    z-index: 5;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    transition: opacity 0.2s;
    display: block; /* Ensure it's not hidden by default */
}
.tag-name {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 11px; /* Slightly smaller */
    color: #FFD700;
    background: rgba(20, 20, 30, 0.7); /* Darker background for contrast */
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(255, 215, 0, 0.3); /* Subtle gold border */
    white-space: nowrap;
}
.tag-role {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 10px;
    color: #ccc;
    margin-top: 2px;
    display: none; /* Only show name by default to reduce clutter, or show on hover */
}
.agent-nametag.visible .tag-role { display: block; }

/* ─── Agent Tooltip ───────────────────── */
#agent-tooltip {
  position: fixed;
  display: none;
  background: rgba(26, 21, 38, 0.95);
  border: 2px solid #8b6c42;
  border-radius: 8px;
  padding: 14px 18px;
  min-width: 220px;
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  z-index: 20;
}

.tip-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(139, 108, 66, 0.3);
  padding-bottom: 8px;
}
.tip-avatar {
  font-size: 28px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 50%;
  padding: 4px;
  border: 1px solid #8b6c42;
}
.tip-name {
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: 16px;
  color: #ffd700;
}
.tip-role {
  font-size: 11px;
  color: #aaa;
  font-family: "Space Grotesk", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tip-task {
  font-size: 12px;
  color: #d4c89e;
  margin: 8px 0;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  border-left: 3px solid #f4a940;
  font-family: "JetBrains Mono", monospace;
}
.tip-room {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
  margin-top: 4px;
  font-weight: 600;
}

/* ─── Bottom Bar ──────────────────────── */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 24px;
  background: linear-gradient(
    0deg,
    rgba(10, 10, 20, 0.95) 0%,
    transparent 100%
  );
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: auto;
}

.model-info {
  display: flex;
  gap: 20px;
  font-size: 11px;
  color: #8b6c42;
  font-family: "JetBrains Mono", monospace;
}
.model-info span {
  color: #d4c89e;
}

/* ─── Navigation Hint ─────────────────── */
.controls-hint {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid #444;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12px;
  color: #ccc;
  opacity: 0.7;
  pointer-events: none;
}

/* ─── Quest Board Panel ───────────────── */
/* ─── LEFT SIDEBAR LAYOUT ─── */
#left-sidebar {
    position: fixed;
    top: 80px;
    left: 20px;
    bottom: 50px;
    width: 280px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 100;
    pointer-events: none; /* Container passes clicks */
}

/* Make all panels in sidebar flexible and equal height */
#left-sidebar > div {
    flex: 1;
    min-height: 0; /* Important for scrolling inside flex items */
    pointer-events: auto; /* Panels capture clicks */
    max-height: none; /* Remove previous limits */
    display: flex;
    flex-direction: column;
}

/* Ensure content areas scroll */
.quest-panel, #roster-panel, #history-panel {
    overflow: hidden; /* Let inner content scroll if needed, or container */
}

/* Specific content containers should scroll */
#history-content, .roster-list, .quest-panel { 
    overflow-y: auto; 
    flex: 1; 
}

/* Reset specific Panel styles that conflict with generic rule above */
.quest-panel {
    /* width: 100%; explicit width handled by sidebar */
    pointer-events: auto;
}

/* Quest/Backlog Panel (Top of Sidebar) */
.quest-panel {
    /* Removed fixed position, now in sidebar */
    width: 100%;
    background: rgba(18, 14, 28, 0.95);
    border: 1px solid #4a4e69;
    border-radius: 8px;
    padding: 12px;
    color: #e0e1dd;
    pointer-events: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    transition: all 0.3s ease;
    flex-shrink: 0;
    max-height: 50vh;
    overflow-y: auto;
}

.quest-title {
  font-family: "Cinzel", serif;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #ffd700;
  margin-bottom: 10px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 6px;
}

.backlog-stats {
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-bar {
  display: flex;
  height: 6px;
  background: #333;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.stat-segment { height: 100%; transition: width 0.3s; }
.stat-segment.done { background: #4ade80; }
.stat-segment.prog { background: #f4a940; }
.stat-segment.fail { background: #e94560; }

.stat-legend {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #aaa;
  font-family: "JetBrains Mono", monospace;
  padding: 0 4px;
}

.quest-item {
  padding: 8px;
  margin-bottom: 6px;
  border-radius: 4px;
  font-size: 11px;
  background: rgba(0, 0, 0, 0.2);
  border-left: 3px solid transparent;
  color: #d4c89e;
  font-family: "Space Grotesk", sans-serif;
  transition: transform 0.2s;
  cursor: pointer;
}
.quest-item:hover {
  transform: translateX(2px);
  background: rgba(255, 255, 255, 0.05);
}
.quest-item.urgent {
  border-left-color: #e94560;
}
.quest-item.active {
  border-left-color: #4ade80;
}
.quest-item.pending {
  border-left-color: #f4a940;
}

/* ─── Loading ─────────────────────────── */
#loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #0a0a14;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.8s;
}
#loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-text {
  font-family: "Cinzel", serif;
  font-size: 28px;
  font-weight: 700;
  color: #ffd700;
  margin-bottom: 8px;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}
.loading-sub {
  font-size: 14px;
  color: #888;
  margin-bottom: 24px;
  letter-spacing: 1px;
}
.loading-bar {
  width: 300px;
  height: 6px;
  background: #222;
  border: 1px solid #444;
  border-radius: 4px;
  overflow: hidden;
}
.loading-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #f4a940, #ffd700);
  transition: width 0.3s;
}

/* ─── Roster Panel ────────────────────── */
/* Roster Panel (Bottom of Sidebar) */
#roster-panel {
    /* Removed fixed position, now in sidebar */
    width: 100%;
    background: rgba(18, 14, 28, 0.95);
    border: 1px solid #4a4e69;
    border-radius: 8px;
    padding: 10px;
    border-radius: 8px;
    padding: 10px;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    /* flex/height handled by generic sidebar rule */
}
.roster-title {
  font-family: "Cinzel", serif;
  font-size: 14px;
  font-weight: 700;
  color: #f4a940;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 6px;
  margin-bottom: 4px;
}
.roster-group {
  margin-bottom: 8px;
}
.roster-room {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
  margin-bottom: 2px;
  font-weight: 700;
}
.roster-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.roster-avatar {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: help;
  border: 1px solid transparent;
  transition: all 0.2s;
}
.roster-avatar:hover {
  border-color: #ffd700;
  transform: scale(1.1);
}

/* ─── Toast Notifications ────────────── */
#toast-container {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  z-index: 100;
}
.toast {
  background: rgba(20, 20, 30, 0.95);
  border: 1px solid #ffd700;
  color: #ffd700;
  padding: 8px 16px;
  border-radius: 4px;
  font-family: "Cinzel", serif;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  animation:
    slideIn 0.3s ease-out,
    fadeOut 0.5s ease-in 2.5s forwards;
  display: flex;
  align-items: center;
  gap: 8px;
}
@keyframes slideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* ─── Message History Panel ───────────── */
#history-panel {
    /* Integrated into Sidebar */
    /* width: 100%; -> Inherited */
    /* max-height: 400px; -> Removed to let flex-grow work */
    background: rgba(18, 14, 28, 0.95); /* Consistent with other panels */
    border: 1px solid #4a4e69; /* Consistent border */
    border-radius: 8px;
    font-family: 'Space Grotesk', sans-serif;
    color: #e0e1dd;
    padding: 10px;
    pointer-events: auto;
    /* flex/height handled by generic sidebar rule */
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
}
#history-panel h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: #FFD700;
    border-bottom: 1px solid rgba(139, 108, 66, 0.5);
    padding-bottom: 4px;
}
.history-entry {
    font-size: 11px;
    margin-bottom: 4px;
    opacity: 0.8;
}
.history-entry .timestamp {
    color: #4ade80;
    margin-right: 6px;
}

/* ─── Room Details Panel ──────────────── */
/* Room Panel REMOVED */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.panel-header h3 {
    font-family: 'Cinzel', serif;
    color: #FFD700;
    margin: 0;
    font-size: 24px;
}
.panel-header button {
    background: none;
    border: none;
    color: #FF4444;
    font-size: 24px;
    cursor: pointer;
}
.panel-content h4 {
    color: #4ade80;
    margin-top: 15px;
    margin-bottom: 8px;
}
.stat-row {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
}
.progress-bar {
    flex-grow: 1;
    height: 8px;
    background: #333;
    border-radius: 4px;
    overflow: hidden;
}
.progress-bar .fill {
    height: 100%;
    background: linear-gradient(90deg, #FFD700, #FFA500);
}

/* ─── Guild Log Categories ────────────── */
.history-entry.cat-move { border-left: 2px solid #4ade80; padding-left: 6px; }
.history-entry.cat-task { border-left: 2px solid #f4a940; padding-left: 6px; }
.history-entry.cat-msg  { border-left: 2px solid #4a9eff; padding-left: 6px; }
.history-entry.cat-sys  { border-left: 2px solid #888;    padding-left: 6px; }

/* ─── Speech Bubble ──────────────────── */
.speech-bubble {
    position: absolute;
    transform: translate(-50%, -100%);
    background: rgba(30, 25, 40, 0.95);
    border: 2px solid #ffd700;
    border-radius: 12px 12px 12px 0;
    padding: 6px 12px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 11px;
    color: #f0e6d3;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    z-index: 25;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    animation: bubbleIn 0.3s ease-out, bubbleFade 0.5s ease-in 2.5s forwards;
}
.speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 8px;
    width: 0; height: 0;
    border-left: 8px solid #ffd700;
    border-bottom: 8px solid transparent;
}
@keyframes bubbleIn {
    from { transform: translate(-50%, -80%) scale(0.7); opacity: 0; }
    to   { transform: translate(-50%, -100%) scale(1);   opacity: 1; }
}
@keyframes bubbleFade {
    to { opacity: 0; transform: translate(-50%, -120%); }
}

/* ─── Agent Context Menu ─────────────── */
#agent-context-menu {
    position: fixed;
    display: none;
    background: rgba(26, 21, 38, 0.98);
    border: 2px solid #8b6c42;
    border-radius: 8px;
    min-width: 180px;
    z-index: 300;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
    overflow: hidden;
}
.ctx-header {
    font-family: 'Cinzel', serif;
    font-size: 13px;
    font-weight: 700;
    color: #ffd700;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(139, 108, 66, 0.4);
}
.ctx-item {
    padding: 10px 14px;
    font-size: 12px;
    color: #f0e6d3;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Space Grotesk', sans-serif;
}
.ctx-item:hover {
    background: rgba(255, 215, 0, 0.1);
    color: #ffd700;
}
.ctx-item:active {
    background: rgba(255, 215, 0, 0.2);
}
.ctx-divider {
    height: 1px;
    background: rgba(139, 108, 66, 0.3);
    margin: 2px 0;
}

/* ─── Room Panel: Agent List ─────────── */
.room-agent-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.room-agent-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(139, 108, 66, 0.4);
    border-radius: 20px;
    font-size: 11px;
    color: #d4c89e;
}
.room-agent-chip .chip-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #4ade80;
}

/* ─── Floating Terminal (3D CanvasTexture now used in agents.js) ───────────────── */
/* CSS removed as we now use THREE.Mesh and CanvasTexture */

/* ─── Room Status Board ───────────────── */
.room-board-overlay {
    position: absolute;
    transform: translate(-50%, -50%);
    background: rgba(20, 16, 28, 0.95);
    border: 2px solid #8b6c42;
    border-radius: 6px;
    padding: 10px;
    width: 200px;
    pointer-events: none; /* Let clicks pass through if needed, or auto to interact */
    pointer-events: auto;
    z-index: 15;
    box-shadow: 0 4px 16px rgba(0,0,0,0.6);
    display: none; /* Hidden by default, shown by JS */
}
.board-header {
    font-family: 'Cinzel', serif;
    font-size: 12px;
    font-weight: 700;
    color: #ffd700;
    border-bottom: 1px solid #444;
    padding-bottom: 4px;
    margin-bottom: 6px;
    text-align: center;
}
.board-stats {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: #aaa;
    margin-bottom: 6px;
}
.board-tasks {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.board-task-item {
    background: rgba(255,255,255,0.05);
    padding: 4px 6px;
    border-radius: 3px;
    font-size: 10px;
    color: #d4c89e;
    border-left: 2px solid #f4a940;
}

/* ─── CUSTOM SCROLLBARS ───────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb {
    background: rgba(139, 108, 66, 0.6); /* Bronze */
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.3);
}
::-webkit-scrollbar-thumb:hover {
    background: #f4a940; /* Amber hover */
    border-color: #ffd700;
}
::-webkit-scrollbar-corner {
    background: transparent;
}

