:root {
  --sidebar-width: 300px;
}

.game-page {
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== HEADER — 2 rows, evenly distributed ===== */
.game-header {
  display: flex;
  flex-direction: column;
  padding: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

/* Shared row style */
.hdr-row {
  display: flex;
  align-items: center;
  padding: 0.5rem 1.25rem;
  gap: 1.5rem;
  min-height: 40px;
}

.hdr-row-1 {
  border-bottom: 1px solid var(--border);
}

/* Row 1 elements */
.game-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.game-logo:hover { color: var(--accent); }

.hdr-tagline {
  font-size: 0.8rem;
  color: var(--text-muted, #8b949e);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 0;
  min-width: 0;
}

.hdr-mission {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
  background: rgba(88,166,255,0.10);
  padding: 0.2rem 0.75rem;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--text-muted, #8b949e);
}
.hdr-mi b {
  color: var(--text);
  font-weight: 600;
  margin-left: 0.25rem;
}

.hdr-link {
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.hdr-link:hover { text-decoration: underline; }

/* Row 2 elements */
.hdr-row-2 {
  gap: 0.75rem;
}

.hdr-row-2 label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted, #8b949e);
  white-space: nowrap;
}

.hdr-row-2 select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

.hdr-spacer {
  flex: 1 1 0;
}

.hdr-row-2 .btn-primary,
.hdr-row-2 .btn-secondary-outline {
  width: auto;
  min-width: 90px;
  height: 32px;
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.mission-complete-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.mission-complete-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  max-width: 420px;
  text-align: center;
}

.mission-complete-card h2 {
  margin: 0 0 1.5rem;
  font-size: 1.5rem;
  color: var(--allow);
}

.mission-complete-stats {
  text-align: left;
  margin-bottom: 1.5rem;
}

.mission-complete-stats p {
  margin: 0.5rem 0;
  font-size: 0.95rem;
}

.mission-complete-stats strong {
  color: var(--text);
}


/* (old mode-selector styles removed — controls now in .hdr-row-2) */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--allow);
  color: #fff;
  border: none;
  padding: 0.4rem 0.9rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
  min-width: 110px;
  height: 40px;
  line-height: 1.2;
}

.btn-primary:hover {
  opacity: 0.9;
}

/* Layout */
.game-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.game-sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  overflow-y: auto;
}

.panel {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.panel h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Metrics */
.metric-row {
  margin-bottom: 0.75rem;
}

.metric-row:last-child {
  margin-bottom: 0;
}

.metric-label {
  font-size: 0.85rem;
  color: var(--muted);
  display: block;
  margin-bottom: 0.2rem;
}

.metric-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.metric-value.money {
  color: var(--allow);
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.2rem;
}

.progress-bar .fill {
  height: 100%;
  transition: width 0.3s ease;
}

.progress-bar .fill.battery {
  background: var(--allow);
}

.progress-bar .fill.safety {
  background: var(--accent);
}

.metric-row.session-goal {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.metric-row.session-goal .progress-bar {
  flex: 1;
}

.progress-bar .fill.goal-fill {
  background: var(--allow);
}

.metric-val-text {
  font-size: 0.85rem;
  color: var(--text);
  float: right;
  margin-top: -4px;
}

.metric-row.small {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.metric-row.small strong {
  color: var(--text);
}

/* Strategy */
.control-group {
  margin-bottom: 0.75rem;
}

.control-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.control-group input[type="range"] {
  width: 100%;
  margin-bottom: 0.25rem;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
}

.control-group.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-group.checkbox label {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  cursor: pointer;
}

.btn-secondary {
  width: 100%;
  background: var(--border);
  color: var(--text);
  border: none;
  padding: 0.4rem;
  border-radius: 4px;
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--muted);
  color: #fff;
}

/* Robot Selector */
.robot-selector {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.robot-selector input[type="radio"] {
  display: none;
}

.robot-selector label {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.4rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted);
  font-weight: bold;
  transition: 0.2s;
  flex: 1;
  text-align: center;
}

.robot-selector input[type="radio"]:checked+label {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.quick-actions-group .quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.quick-actions-group .btn-quick {
  font-size: 0.8rem;
  padding: 0.35rem 0.6rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}
.quick-actions-group .btn-quick:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Events */
.events-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.events-list li {
  padding: 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  background: rgba(248, 81, 73, 0.1);
  border-left: 3px solid var(--block);
  color: var(--text);
}

.events-list li.event-empty {
  background: transparent;
  border: none;
  color: var(--muted);
  text-align: center;
  font-style: italic;
}

.event-name {
  font-weight: 700;
  color: var(--block);
  display: block;
  margin-bottom: 0.2rem;
}

/* Main View — fixed width so console doesn't stretch to full screen */
.game-main-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  overflow-y: auto;
  position: relative;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

.alert-banner {
  background: rgba(248, 81, 73, 0.2);
  border: 1px solid var(--block);
  color: var(--block);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  text-align: center;
  font-weight: 700;
  animation: pulse 2s infinite;
  display: none;
}

@keyframes pulse {
  0% {
    opacity: 0.8;
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: 0.8;
  }
}

.canvas-container {
  flex: 1;
  background: #0d1117;
  border-radius: 8px;
  border: 1px solid var(--border);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  transition: box-shadow 0.4s ease;
}

.canvas-container.battery-low {
  box-shadow: inset 0 0 80px 20px rgba(210, 153, 34, 0.12);
}

#warehouse {
  max-width: 100%;
  max-height: 100%;
}

.canvas-tooltip {
  position: absolute;
  pointer-events: none;
  padding: 4px 8px;
  background: rgba(0,0,0,0.85);
  color: #eee;
  font-size: 0.75rem;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 10;
  display: none;
}

.canvas-tooltip.visible {
  display: block;
}

.canvas-summary {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: var(--muted);
  background: rgba(0,0,0,0.6);
  padding: 4px 12px;
  border-radius: 4px;
}

.you-can-help {
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(88, 166, 255, 0.08);
  border: 1px solid rgba(88, 166, 255, 0.3);
  border-radius: 6px;
}

.you-can-help h4 {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  color: var(--accent);
  text-transform: uppercase;
}

.you-can-help-content {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.5;
}

.help-tip {
  margin-bottom: 0.2rem;
}

.help-tip:last-child {
  margin-bottom: 0;
}

.example-commands {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

.example-label {
  color: var(--text-muted, #8b949e);
  margin-right: 0.25rem;
}

.btn-example {
  padding: 0.25rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.75rem;
}

.btn-example:hover {
  background: rgba(88, 166, 255, 0.15);
  border-color: var(--accent);
}

/* Console — one row: [R1 chat | R2 chat | Reasoning | Stats], fixed width */
.game-console {
  display: flex;
  flex-direction: row;
  gap: 1rem;
  margin-top: 1rem;
  height: 350px;
  min-height: 350px;
  max-height: 350px;
  min-width: 0;
}

.game-console > * {
  min-height: 0;
}

.game-console .dual-chat-container {
  flex: 2 1 0;
  min-width: 0;
  display: flex;
  gap: 1rem;
  overflow: hidden;
  align-items: stretch;
}

.console-right-row {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
  flex: 0 0 380px;
  min-width: 320px;
  max-width: 380px;
  height: 100%;
  min-height: 0;
  align-items: stretch;
}

.chat-section,
.reasoning-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.chat-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  padding-right: 0.5rem;
}

.chat-msg {
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
}

.chat-msg.user {
  color: var(--accent);
  font-weight: 600;
}

.chat-msg.ai {
  color: var(--text);
  /* Better contrast */
}

.chat-msg.thinking {
  color: var(--muted);
  font-style: italic;
  font-size: 0.8rem;
}

.chat-input-wrap {
  display: flex;
  gap: 0.5rem;
}

.chat-input {
  flex: 1;
  padding: 0.8rem;
  /* Increased from 0.4rem */
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  /* Increased */
}

.chat-send {
  background: var(--allow);
  color: #fff;
  border: none;
  padding: 0 1rem;
  border-radius: 4px;
  cursor: pointer;
}

.reasoning-section {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.reasoning-section h4 {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  flex-shrink: 0;
}

.reasoning-log {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  font-size: 0.72rem;
  line-height: 1.3;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: monospace;
  padding: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

/* System Efficiency stats — right of Reasoning Engine */
.stats-panel {
  flex: 0 0 160px;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.stats-panel h4 {
  margin: 0 0 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  flex-shrink: 0;
}

.stats-content {
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text);
}

.stats-content .stat-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.stats-content .stat-label {
  color: var(--muted);
}

.stats-content .stat-value {
  font-weight: 600;
  color: var(--allow);
}

.stats-content .stat-value.negative {
  color: #e57373;
}

/* Modal */
.modal {
  background: rgba(0, 0, 0, 0.8);
  border: none;
  border-radius: 8px;
  color: var(--text);
  padding: 0;
  max-width: 600px;
  width: 90%;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.8);
}

.modal-content {
  background: var(--surface);
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--muted);
  cursor: pointer;
}

.btn-close:hover {
  color: var(--text);
}

.modal-body {
  font-size: 0.95rem;
  line-height: 1.6;
}

.modal-body h3 {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
  font-size: 1.1rem;
}

.modal-body ul {
  margin: 0 0 1rem;
  padding-left: 1.25rem;
}

.modal-body li {
  margin-bottom: 0.25rem;
}



/* Dual Chat Layout — scroll inside */
.dual-chat-container {
  display: flex;
  gap: 1rem;
  min-height: 0;
}

.robot-chat-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  height: 100%;
}

.robot-chat-header {
  flex-shrink: 0;
  background: var(--bg);
  padding: 0.5rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.robot-chat-panel .chat-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem;
  font-size: 0.8rem;
  -webkit-overflow-scrolling: touch;
}

.robot-chat-panel .chat-msg {
  font-size: 0.8rem;
  margin-bottom: 0.3rem;
}

.robot-chat-panel .chat-input-wrap {
  flex-shrink: 0;
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  border-top: 1px solid var(--border);
}

.robot-chat-panel .chat-input {
  flex: 1;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.9rem;
}

.robot-chat-panel .chat-send {
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}

.robot-chat-panel .chat-send:hover {
  opacity: 0.9;
}

/* Task Pool Panel */
.task-pool-panel {
  margin-bottom: 1rem;
}

.task-pool-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem;
}

.task-pool-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 1rem;
  font-style: italic;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem;
  margin-bottom: 0.3rem;
  background: var(--surface);
  border-left: 3px solid var(--border);
  border-radius: 3px;
  font-size: 0.85rem;
}

.task-item.task-urgent {
  border-left-color: #ff4444;
  background: rgba(255, 68, 68, 0.1);
}

.task-item.task-high {
  border-left-color: #ffaa00;
  background: rgba(255, 170, 0, 0.1);
}

.task-item.task-normal {
  border-left-color: var(--accent);
}

.task-item.task-assigned {
  opacity: 0.6;
  background: rgba(100, 100, 100, 0.1);
}

.task-id {
  font-weight: 700;
  color: var(--accent);
  min-width: 30px;
}

.task-desc {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-priority {
  font-size: 0.75rem;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  background: var(--bg);
  text-transform: uppercase;
  font-weight: 600;
}

.task-priority.urgent {
  background: #ff4444;
  color: white;
}

.task-priority.high {
  background: #ffaa00;
  color: black;
}

.task-value {
  color: #4caf50;
  font-weight: 600;
}

.task-deadline {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.task-status {
  font-size: 0.7rem;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  background: var(--bg);
  color: var(--text-muted);
}

.task-status.assigned {
  background: var(--accent);
  color: white;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  width: 100%;
  margin-top: 0.3rem;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-secondary-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  padding: 0.4rem 0.9rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
  min-width: 110px;
  height: 40px;
  line-height: 1.2;
  margin-left: 0.5rem;
}

.btn-secondary-outline:hover {
  opacity: 0.9;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  width: 100%;
}

.btn-secondary:hover {
  background: var(--bg);
}