/* ===== FULL SCREEN GAME ===== */
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #1a1a2e;
}

#game-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#game-container > canvas {
  display: block;
}

/* ===== UI OVERLAY BASE ===== */
.ui-overlay {
  position: fixed;
  z-index: 100;
  background: rgba(20, 20, 30, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

/* ===== TOP CONTROL BAR ===== */
.top-bar {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 28px;
  border-radius: 0 0 16px 16px;
  border-top: none;
}

.time-display {
  font-size: 1.3em;
  font-weight: 600;
  min-width: 200px;
  text-align: center;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}

.control-buttons {
  display: flex;
  gap: 8px;
}

.control-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.control-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.control-btn.active {
  background: #4CAF50;
}

.control-btn .icon {
  font-size: 18px;
  line-height: 1;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.speed-control label {
  font-size: 0.9em;
  opacity: 0.7;
}

.speed-control input[type="range"] {
  width: 120px;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  cursor: pointer;
}

.speed-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: #4CAF50;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.1s;
}

.speed-control input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

.speed-control input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #4CAF50;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

#speed_label {
  font-weight: 600;
  min-width: 30px;
}

.zoom-display {
  font-size: 0.9em;
  opacity: 0.7;
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
}

#zoom-indicator {
  font-weight: 600;
  min-width: 45px;
  text-align: center;
}

/* ===== SIDE PANEL (PERSONA LIST) ===== */
.side-panel {
  top: 80px;
  right: 0;
  width: 340px;
  max-height: calc(100vh - 100px);
  border-radius: 16px 0 0 16px;
  border-right: none;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.side-panel.collapsed {
  transform: translateX(calc(100% - 40px));
}

.panel-header {
  display: flex;
  flex-direction: row-reverse;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 1.1em;
  font-weight: 600;
  flex-shrink: 0;
}

.toggle-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 6px;
  opacity: 0.8;
  transition: all 0.2s;
}

.toggle-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.2);
}

.side-panel.collapsed .toggle-btn {
  transform: scaleX(-1);
}

.panel-content {
  overflow-y: auto;
  flex: 1;
  padding: 12px;
}

/* ===== PERSONA CARDS ===== */
.persona-card {
  display: flex;
  gap: 14px;
  padding: 14px;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  transition: all 0.2s;
  cursor: pointer;
  border: 1px solid transparent;
}

.persona-card:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateX(-4px);
}

.persona-card:last-child {
  margin-bottom: 0;
}

.persona-avatar {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.persona-avatar img {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  object-fit: none;
  object-position: -32px 0;
}

.persona-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.persona-name {
  font-weight: 600;
  font-size: 1.05em;
  color: #7dd87d;
}

.persona-info .label {
  font-size: 0.7em;
  opacity: 0.5;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 4px;
}

.persona-action,
.persona-location {
  font-size: 0.85em;
  line-height: 1.4;
  word-wrap: break-word;
  opacity: 0.9;
}

/* ===== SCROLLBAR STYLING ===== */
.panel-content::-webkit-scrollbar {
  width: 8px;
}

.panel-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.panel-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
}

.panel-content::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.4);
}

/* ===== HIDDEN DATA ELEMENTS ===== */
.hidden-data {
  display: none !important;
}

/* ===== SIMULATION STATUS INDICATOR ===== */
.sim-status {
  bottom: 20px;
  left: 20px;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9em;
  min-width: 120px;
}

.sim-status #sim-status-text {
  display: block;
  margin-bottom: 6px;
}

.sim-progress-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
}

.sim-progress-bar::after {
  content: '';
  display: block;
  height: 100%;
  width: 0%;
  background: #4CAF50;
  transition: width 0.3s ease;
}

.sim-status.simulating .sim-progress-bar::after {
  width: 100%;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ===== MENU OVERLAY ===== */
.menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.menu-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.menu-panel {
  background: rgba(30, 30, 45, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 30px 40px;
  min-width: 400px;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.menu-panel h2 {
  margin: 0 0 20px 0;
  font-size: 1.8em;
  font-weight: 600;
  color: #fff;
  text-align: center;
}

.menu-section {
  margin-bottom: 20px;
}

.menu-section h3 {
  margin: 0 0 10px 0;
  font-size: 1em;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.menu-section p {
  margin: 0;
  color: #fff;
  font-size: 1.1em;
}

.menu-buttons {
  display: flex;
  gap: 12px;
  margin: 25px 0;
}

.menu-btn {
  flex: 1;
  padding: 14px 20px;
  border: none;
  border-radius: 10px;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.menu-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.menu-btn.primary {
  background: #4CAF50;
}

.menu-btn.primary:hover {
  background: #5CBF60;
}

.menu-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.saves-list {
  max-height: 200px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  padding: 10px;
}

.saves-loading {
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  padding: 20px;
  margin: 0;
}

.save-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.save-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.save-item:last-child {
  margin-bottom: 0;
}

.save-item .save-name {
  font-weight: 600;
  color: #7dd87d;
}

.save-item .save-info {
  font-size: 0.85em;
  color: rgba(255, 255, 255, 0.6);
}

.save-item.current {
  border: 1px solid #4CAF50;
}

.menu-hint {
  text-align: center;
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.85em;
  margin: 20px 0 0 0;
}

/* ===== CHAT POPUP ===== */
.chat-popup {
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  max-width: 90vw;
  max-height: 300px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  transition: opacity 0.3s ease;
  z-index: 200;
}

.chat-popup.hidden {
  opacity: 0;
  pointer-events: none;
}

.chat-popup.minimized {
  max-height: 44px;
  overflow: hidden;
}

.chat-popup.minimized .chat-header {
  border-bottom: none;
  padding: 0 16px;
  height: 44px;
  min-height: 44px;
}

.chat-popup.minimized .chat-messages {
  display: none;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.chat-tabs {
  display: flex;
  gap: 8px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}

.chat-tabs::-webkit-scrollbar {
  display: none;
}

.chat-tab {
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 0.9em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.chat-tab:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chat-tab.active {
  background: #4CAF50;
}

.chat-tab.new {
  animation: tabHighlight 1.5s ease-out;
}

@keyframes tabHighlight {
  0%, 30% {
    background: #7dd87d;
    transform: scale(1.05);
  }
  100% {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1);
  }
}

.chat-minimize {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 1.4em;
  cursor: pointer;
  padding: 4px 10px;
  margin-left: 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.chat-minimize:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  max-height: 240px;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 3px;
}

.chat-bubble {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  animation: bubbleIn 0.2s ease-out;
}

@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-bubble:last-child {
  margin-bottom: 0;
}

.chat-bubble.new .message {
  background: rgba(125, 216, 125, 0.25);
}

/* When fading class is added (on play resume), animate the fade */
.chat-bubble.new.fading .message {
  animation: messageHighlight 1.5s ease-out forwards;
}

@keyframes messageHighlight {
  0% {
    background: rgba(125, 216, 125, 0.25);
  }
  100% {
    background: rgba(255, 255, 255, 0.08);
  }
}

.chat-bubble .speaker {
  font-weight: 600;
  color: #7dd87d;
  min-width: 120px;
  text-align: right;
  flex-shrink: 0;
}

.chat-bubble .message {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 1.05em;
  line-height: 1.4;
}

.chat-empty {
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
  font-style: italic;
  padding: 20px;
}

/* ===== RESPONSIVE ADJUSTMENTS ===== */
@media (max-width: 900px) {
  .side-panel {
    width: 300px;
  }

  .side-panel.collapsed {
    transform: translateX(260px);
  }

  .top-bar {
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 16px;
    max-width: 95vw;
  }

  .time-display {
    font-size: 1.1em;
    min-width: 160px;
  }

  .zoom-display {
    display: none;
  }
}

@media (max-width: 600px) {
  .side-panel {
    width: 100%;
    top: auto;
    bottom: 0;
    right: 0;
    max-height: 50vh;
    border-radius: 16px 16px 0 0;
  }

  .side-panel.collapsed {
    transform: translateY(calc(100% - 50px));
  }

  .toggle-btn {
    transform: rotate(90deg);
  }

  .side-panel.collapsed .toggle-btn {
    transform: rotate(-90deg);
  }
}
