/* Pino Autonomous 3D — Retro moody aesthetic */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Courier New', monospace;
  background: #0d0d24;
  color: #fff;
  overflow: hidden;
}

#scene-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
}

/* Speech Bubbles */
#speech-bubbles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 10;
}

.speech-bubble {
  position: absolute;
  background: rgba(20, 20, 60, 0.9);
  border: 2px solid #6666aa;
  border-radius: 10px;
  padding: 8px 12px;
  color: #fff;
  font-size: 13px;
  max-width: 180px;
  white-space: pre-wrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, -100%);
}

/* Chat Log Overlay */
#chat-log {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 320px;
  height: 280px;
  background: rgba(15, 15, 45, 0.85);
  border: 2px solid #333366;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  z-index: 20;
  backdrop-filter: blur(4px);
}

.chat-header {
  padding: 8px 12px;
  background: rgba(30, 30, 80, 0.9);
  border-bottom: 1px solid #333366;
  font-size: 13px;
  font-weight: bold;
  color: #aaaacc;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.5;
}

.chat-line {
  margin-bottom: 4px;
  word-wrap: break-word;
}

.chat-line.user {
  color: #66ccff;
}

.chat-name {
  color: #ff9955;
  font-weight: bold;
}

/* Sidebar with Tabs */
#sidebar {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 400px;
  height: calc(100vh - 32px);
  background: rgba(15, 15, 45, 0.9);
  border: 2px solid #333366;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  z-index: 20;
  backdrop-filter: blur(4px);
}

#tab-bar {
  display: flex;
  background: rgba(30, 30, 80, 0.9);
  border-bottom: 1px solid #333366;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: #aaaacc;
  padding: 8px 4px;
  font-size: 11px;
  font-family: 'Courier New', monospace;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-btn:hover {
  background: rgba(50, 50, 120, 0.5);
  color: #ffffff;
}

.tab-btn.active {
  border-bottom-color: #66ccff;
  color: #ffffff;
  background: rgba(50, 50, 120, 0.3);
}

#tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-pane {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
}

.tab-pane.active {
  display: flex;
}

#tab-overview .chat-header {
  flex-shrink: 0;
}

#chat-messages {
  flex: 1;
}

/* Chat log content styles */
.chat-line {
  margin-bottom: 4px;
  word-wrap: break-word;
  padding: 2px 0;
}

.chat-line.user {
  color: #66ccff;
}

.chat-line .chat-name {
  color: #ff9955;
  font-weight: bold;
}

/* Diary, Features, Stories, Mood panels */
#thoughts-panel,
#features-panel,
#diary-panel,
#stories-panel,
#mood-panel {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.5;
}

/* Tab-specific accent colors */
#tab-diary .chat-header { color: #f59e0b; }
#tab-features .chat-header { color: #8b5cf6; }
#tab-stories .chat-header { color: #66ccff; }
#tab-mood .chat-header { color: #ff6b9d; }

/* HUD */
#hud {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(15, 15, 45, 0.85);
  border: 2px solid #333366;
  border-radius: 8px;
  padding: 8px 16px;
  z-index: 20;
  backdrop-filter: blur(4px);
}

.hud-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.endpoint-status #endpoint-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff3366;
  display: inline-block;
}

.endpoint-status #endpoint-text {
  font-size: 12px;
  color: #aaaacc;
}

.prompt-bar input {
  background: rgba(30, 30, 80, 0.9);
  border: 1px solid #444488;
  border-radius: 4px;
  color: #fff;
  padding: 6px 10px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  width: 220px;
  outline: none;
}

.prompt-bar input:focus {
  border-color: #6666cc;
}

.prompt-bar button {
  background: rgba(60, 60, 140, 0.9);
  border: 1px solid #4444aa;
  border-radius: 4px;
  color: #fff;
  padding: 6px 12px;
  font-size: 12px;
  font-family: 'Courier New', monospace;
  cursor: pointer;
  transition: background 0.15s;
}

.prompt-bar button:hover {
  background: rgba(80, 80, 160, 0.9);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  #sidebar {
    width: 100%;
    left: 0;
    top: 0;
    height: 120px;
    border-radius: 0;
  }

  /* Horizontally scrollable tab bar — prevents label truncation */
  #tab-bar {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
  }

  #tab-bar::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    text-overflow: clip;
    overflow: visible;
    padding: 8px 12px;
    font-size: 12px;
  }

  /* Compact mobile chat input — single row, high-contrast */
  #hud {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    width: calc(100% - 24px);
    left: 12px;
    transform: translateX(0);
    bottom: 12px;
    border-radius: 12px;
  }

  .prompt-bar {
    display: flex;
    gap: 8px;
    padding: 0;
    width: 100%;
  }

  .prompt-bar input {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #ffffff;
    font-size: 16px;
    padding: 8px 12px;
    border-radius: 8px;
  }

  #send-btn {
    background: #4f46e5;
    color: #ffffff;
    min-width: 64px;
    height: 44px;
    border-radius: 8px;
    padding: 0 12px;
  }

  #think-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    height: 44px;
    border-radius: 8px;
    padding: 0 12px;
  }

  /* Hide secondary status elements on mobile to prevent overlap */
  .endpoint-status {
    display: none;
  }

  .control-hints {
    display: none;
  }

  /* Hide debug button on mobile */
  #debug-render-btn {
    display: none;
  }

  .chat-header {
    font-size: 12px;
  }

  #chat-messages {
    font-size: 11px;
  }

  .speech-bubble {
    font-size: 12px;
    padding: 6px 10px;
  }

  /* Mobile touch targets */
  button, input {
    -webkit-tap-highlight-color: transparent;
  }
}

/* Mobile joystick */
#mobile-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 15;
}

.joystick {
  position: absolute;
  width: 100px;
  height: 100px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  display: none;
  pointer-events: none;
  transition: opacity 0.3s;
}

@media (max-width: 480px) {
  #sidebar {
    height: 100px;
  }
  
  #hud {
    padding: 6px 8px;
    font-size: 12px;
  }
  
  .endpoint-status #endpoint-text {
    font-size: 10px;
  }
}

/* Sidebar and Tab UI */
#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  height: 100vh;
  background: rgba(15, 15, 45, 0.95);
  color: #fff;
  font-family: 'Courier New', monospace;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  border-left: 2px solid #333366;
  overflow: hidden;
}

#tab-bar {
  display: flex;
  background: rgba(30, 30, 80, 0.9);
  border-bottom: 1px solid #333366;
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 12px 4px;
  background: transparent;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
}

.tab-btn.active {
  color: #fff;
  border-bottom: 2px solid #6666cc;
  background: rgba(102, 102, 204, 0.15);
}

.tab-btn:hover {
  color: #ccc;
  background: rgba(255, 255, 255, 0.05);
}

#tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: flex;
}

/* Diary item styles */
.diary-item {
  background: rgba(30, 30, 80, 0.5);
  padding: 10px;
  margin: 8px 0;
  border-radius: 6px;
  border-left: 3px solid #66ccff;
}

.diary-item.worry { border-left-color: #ff9955; }
.diary-item.promise { border-left-color: #66ff99; }

.diary-label {
  color: #888;
  font-size: 11px;
  text-transform: uppercase;
  margin-bottom: 4px;
}

/* Feature request styles */
.feature-item {
  background: rgba(30, 30, 80, 0.5);
  padding: 10px;
  margin: 8px 0;
  border-radius: 6px;
  border-left: 3px solid #ff9955;
}

.feature-priority {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: bold;
  text-transform: uppercase;
  margin-top: 6px;
}

.feature-priority.high {
  background: rgba(255, 51, 102, 0.3);
  color: #ff3366;
  border: 1px solid #ff3366;
}

.feature-priority.medium {
  background: rgba(255, 153, 85, 0.3);
  color: #ff9955;
  border: 1px solid #ff9955;
}

.feature-priority.low {
  background: rgba(153, 153, 204, 0.3);
  color: #aaaacc;
  border: 1px solid #aaaacc;
}

/* Story item styles */
.story-item {
  background: rgba(30, 30, 80, 0.5);
  padding: 10px;
  margin: 8px 0;
  border-radius: 6px;
  border-left: 3px solid #ffcc66;
}

.story-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: bold;
  text-transform: uppercase;
  margin-top: 6px;
}

.story-tag.exploration {
  background: rgba(102, 204, 255, 0.3);
  color: #66ccff;
  border: 1px solid #66ccff;
}

.story-tag.achievement {
  background: rgba(102, 255, 153, 0.3);
  color: #66ff99;
  border: 1px solid #66ff99;
}

.story-tag.insight {
  background: rgba(255, 204, 102, 0.3);
  color: #ffcc66;
  border: 1px solid #ffcc66;
}

/* Mood arc styles */
.mood-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.mood-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
}

.mood-legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.mood-canvas-container {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid #333366;
  border-radius: 8px;
  padding: 12px;
}

/* Diary styles */
.diary-entry {
  background: rgba(40, 40, 100, 0.6);
  border-left: 3px solid #8b5cf6;
  padding: 12px 15px;
  margin-bottom: 12px;
  border-radius: 0 6px 6px 0;
}

.diary-time {
  font-size: 11px;
  color: #8b5cf6;
  margin-bottom: 8px;
  font-style: italic;
}

.diary-text {
  font-size: 14px;
  color: #e0d8f0;
  line-height: 1.5;
  font-style: italic;
}

/* Responsive sidebar */
@media (max-width: 768px) {
  #sidebar {
    width: 100%;
    height: 50vh;
    top: auto;
    bottom: 0;
    border-left: none;
    border-top: 2px solid #333366;
  }
}

/* Pino Mind & Workspace HUD */
#pino-hud {
  position: fixed;
  top: 10px;
  left: 10px;
  width: 300px;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(100, 100, 180, 0.6);
  border-radius: 8px;
  color: #ddd;
  font-family: monospace;
  font-size: 11px;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  transition: all 0.2s ease;
}

#pino-hud:hover {
  box-shadow: 0 4px 25px rgba(100, 100, 180, 0.4);
}

.pino-hud-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(40, 40, 80, 0.9);
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  border-bottom: 1px solid rgba(100, 100, 180, 0.3);
}

.pino-hud-title {
  font-weight: bold;
  font-size: 12px;
  color: #eee;
}

.pino-hud-toggle {
  background: none;
  border: none;
  color: #aaa;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.pino-hud-toggle:hover {
  color: #fff;
}

.pino-hud-body {
  padding: 8px 10px;
  max-height: 400px;
  overflow-y: auto;
  transition: max-height 0.2s ease;
}

.pino-hud-body.collapsed {
  max-height: 0;
  padding: 0 10px;
  overflow: hidden;
}

.pino-hud-section {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(100, 100, 180, 0.2);
}

.pino-hud-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.pino-hud-section-title {
  font-weight: bold;
  color: #8888cc;
  margin-bottom: 6px;
  font-size: 11px;
}

.pino-hud-item {
  color: #ccc;
  margin-bottom: 2px;
  line-height: 1.4;
}

.pino-hud-code-block {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(100, 100, 180, 0.3);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 10px;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.pino-hud-output-block {
  background: rgba(0, 20, 0, 0.5);
  border: 1px solid rgba(100, 180, 100, 0.3);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 10px;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: #88cc88;
}

.pino-spawn-badge {
  background: #ff6b9d;
  color: #fff;
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 8px;
  animation: pino-bounce 0.5s ease-in-out 3;
  display: inline-block;
}

@keyframes pino-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.pino-hud-diary-entries {
  max-height: 150px;
  overflow-y: auto;
}

.pino-hud-diary-empty {
  color: #666;
  font-style: italic;
}

.pino-hud-diary-entry {
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(100, 100, 180, 0.15);
}

.pino-hud-diary-entry:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.pino-hud-diary-time {
  color: #888;
  font-size: 9px;
}

.pino-hud-diary-location {
  color: #6699cc;
  font-size: 9px;
}

.pino-hud-diary-text {
  color: #ddd;
  font-size: 10px;
  line-height: 1.4;
}

/* ─── Mobile Responsive Enhancements ──────────────────────────────────────── */

/* Prevent rubber-band scrolling on canvas */
#scene-container canvas {
  touch-action: none;
}

/* Mobile camera control buttons */
#mobile-camera-controls {
  position: fixed;
  top: 12px;
  right: 12px;
  display: none;
  z-index: 1000;
}

#mobile-camera-controls button {
  display: block;
  margin-bottom: 8px;
}

.mobile-control-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(30, 30, 60, 0.85);
  border: 1px solid rgba(100, 100, 180, 0.5);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.mobile-control-btn:hover {
  background: rgba(60, 60, 120, 0.9);
}

.mobile-control-btn:active {
  transform: scale(0.95);
}

.mobile-control-btn.active {
  background: rgba(100, 100, 200, 0.9);
  border-color: #8888ff;
  box-shadow: 0 0 8px rgba(100, 100, 255, 0.5);
}

/* Chat input: prevent iOS auto-zoom on focus */
.prompt-bar input {
  font-size: 16px;
}

@media (max-width: 768px) {
  /* Use dynamic viewport height for safe area */
  body {
    height: 100dvh;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  /* Show mobile camera controls */
  #mobile-camera-controls {
    display: block;
  }

  /* Drawer toggle handle — sleek bar at top of drawer */
  .drawer-handle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(30, 30, 60, 0.95);
    border-bottom: 1px solid rgba(100, 100, 180, 0.3);
    cursor: pointer;
    font-size: 13px;
    color: #aaaacc;
    font-family: 'Courier New', monospace;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.2s;
  }

  .drawer-handle:hover {
    background: rgba(50, 50, 120, 0.9);
  }

  .drawer-handle:active {
    background: rgba(60, 60, 140, 0.9);
  }

  .drawer-handle-label {
    font-weight: bold;
  }

  .drawer-handle-arrow {
    font-size: 12px;
    transition: transform 0.25s ease;
  }

  /* Shrink sidebar to bottom sheet — collapsed by default on mobile */
  #sidebar {
    width: 100%;
    height: 40%;
    top: auto;
    bottom: 0;
    transform: translateY(calc(100% - 48px));
    transition: transform 0.25s ease;
    border-radius: 16px 16px 0 0;
  }

  #sidebar.expanded {
    transform: translateY(0);
  }

  /* When expanded, arrow points down */
  #sidebar.expanded .drawer-handle-arrow {
    transform: rotate(180deg);
  }

  /* Compact floating chip for Pino's Mind & Workspace header on mobile */
  #pino-hud {
    width: auto;
    max-width: calc(100vw - 80px);
    padding: 8px 14px;
    font-size: 13px;
    top: 10px;
    left: 10px;
    border-radius: 12px;
  }

  #pino-hud-header {
    padding: 6px 10px;
  }

  .pino-hud-title {
    font-size: 13px;
  }

  /* Keep home button aligned in top-right */
  #mobile-camera-controls {
    top: 10px;
    right: 10px;
  }

  /* Hide old floating HUD on mobile — chat input moved inside drawer */
  #hud {
    display: none;
  }

  /* Drawer chat input bar — tucked inside drawer */
  .drawer-chat-bar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid rgba(100, 100, 180, 0.3);
    background: rgba(15, 15, 45, 0.95);
  }

  .drawer-chat-bar input {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #ffffff;
    font-size: 16px;
    padding: 8px 12px;
    border-radius: 8px;
    outline: none;
  }

  .drawer-chat-bar input:focus {
    border-color: #6666cc;
  }

  .drawer-chat-bar #send-btn {
    background: #4f46e5;
    color: #ffffff;
    font-weight: 600;
    font-size: 14px;
    min-width: 64px;
    height: 44px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    padding: 0;
  }

  .drawer-chat-bar #think-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    height: 44px;
    border-radius: 8px;
    padding: 0 12px;
    border: none;
    cursor: pointer;
  }

  /* Tab bar as bottom sheet tabs — horizontally scrollable */
  #tab-bar {
    display: flex;
    border-bottom: 1px solid rgba(100, 100, 180, 0.3);
    padding: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
  }

  #tab-bar::-webkit-scrollbar {
    display: none;
  }

  .tab-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    text-overflow: clip;
    overflow: visible;
    font-size: 13px;
    padding: 8px 12px;
    min-height: 44px;
  }

  /* Shrink HUD */
  #pino-hud {
    width: 90%;
    left: 5%;
    top: 10px;
    max-height: 35vh;
    overflow-y: auto;
    border-radius: 12px;
  }

  .pino-hud-body {
    max-height: calc(35vh - 40px);
    overflow-y: auto;
  }

  /* Make all buttons at least 44px for thumb tapping */
  button {
    min-height: 44px;
    min-width: 44px;
    -webkit-tap-highlight-color: transparent;
  }

  /* Compact HUD sections on mobile */
  .pino-hud-section {
    padding: 8px 10px;
  }

  .pino-hud-item {
    font-size: 11px;
    margin: 4px 0;
  }

  /* Mobile prompt bar — compact row, high-contrast */
  .prompt-bar {
    display: flex;
    gap: 8px;
    width: 100%;
  }

  .prompt-bar input {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #ffffff;
    font-size: 16px;
    padding: 10px 12px;
    border-radius: 8px;
  }

  #send-btn {
    background: #4f46e5;
    color: #ffffff;
    min-width: 64px;
    height: 44px;
    border-radius: 8px;
    padding: 0 12px;
  }

  #think-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    height: 44px;
    border-radius: 8px;
    padding: 0 12px;
  }

  /* Mobile control hints */
  .control-hints span {
    font-size: 10px;
  }

  /* Compact chat messages */
  .chat-line {
    font-size: 11px;
    padding: 4px 8px;
  }
}

/* Even more compact on small phones */
@media (max-width: 480px) {
  #pino-hud {
    width: 95%;
    left: 2.5%;
    max-height: 30vh;
  }

  .pino-hud-body {
    max-height: calc(30vh - 40px);
  }

  .pino-hud-item {
    font-size: 10px;
  }

  #mobile-camera-controls {
    top: 8px;
    right: 8px;
  }
}
