* { margin: 0; padding: 0; box-sizing: border-box; transition: 0.3s all ease; }

body {
  background: #0a0a0f;
  color: #e0e0e0;
  font-family: 'Courier New', monospace;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #111118;
  border-bottom: 1px solid #2a2a35;
  flex-shrink: 0;
  z-index: 9999;
}

#status-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-left: auto;
  font-size: 12px;
  color: #888;
}
#status-bar .stat { color: #aaa; }
#status-bar .status-val { color: #6a6aff; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.status-dot.on { background: #4caf50; }
.status-dot.off { background: #f44336; }

#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#follow-overlay {
  position: absolute;
  left: 8px;
  top: 8px;
  background: rgba(17, 17, 24, 0.85);
  border: 1px solid #2a2a35;
  border-radius: 6px;
  padding: 6px 12px;
  color: #e0e0e0;
  font-size: 13px;
  z-index: 10;
  pointer-events: auto;
}
#follow-overlay label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

#monitor-panel {
  width: 360px;
  background: #111118;
  border-right: 1px solid #2a2a35;
  overflow-y: auto;
  overflow-x: hidden;
  display: none;
  flex-shrink: 0;
  height: 100%;
}
#monitor-panel.visible { display: block; }
.monitor-panel-entry {
  padding: 10px 12px;
  border-bottom: 1px solid #1a1a25;
}
.monitor-panel-entry h2 {
  color: #8a8aff;
  font-size: 13px;
  margin: 0 0 6px;
}
.monitor-panel-entry label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  margin-bottom: 4px;
  color: #aaa;
}
.monitor-canvas {
  display: block;
}

#info-panel {
  width: 280px;
  background: #111118;
  border-left: 1px solid #2a2a35;
  padding: 16px;
  overflow-y: auto;
  font-size: 13px;
  display: none;
  flex-shrink: 0;
}
#info-panel.visible { display: block; }
#info-panel h3 {
  color: #8a8aff;
  margin: 0 0 12px;
  font-size: 14px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}
.info-label { color: #888; }
.info-value { color: #e0e0e0; }
.stat-bar-wrap { display: flex; align-items: center; gap: 6px; }
.stat-bar { flex: 1; height: 6px; background: #1a1a24; border-radius: 3px; overflow: hidden; min-width: 60px; }
.stat-fill { display: block; height: 100%; background: #6a9fff; border-radius: 3px; transition: width 0.2s; }
.stat-num { font-size: 11px; min-width: 32px; text-align: right; }
.blip-link { color: #6a9fff; text-decoration: none; cursor: pointer; }
.blip-link:hover { text-decoration: underline; }
.section-title {
  color: #6a6aff;
  font-size: 12px;
  margin: 14px 0 6px;
  border-top: 1px solid #2a2a35;
  padding-top: 8px;
}
.reasoning-item {
  color: #aaa;
  font-size: 12px;
  padding: 2px 0 2px 14px;
  position: relative;
}
.reasoning-item::before {
  content: "→";
  position: absolute;
  left: 0;
  color: #6a6aff;
}
.panel-hint {
  color: #555;
  font-size: 12px;
  font-style: italic;
}

.mind-row { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; }
.es-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.es-label.stressed { color: #ff6666; }
.es-label.neutral { color: #888; }
.es-label.confident { color: #66dd66; }
.es-bar { height: 4px; background: #1a1a25; border-radius: 2px; margin: 4px 0 8px; position: relative; }
.es-fill { height: 100%; background: linear-gradient(90deg, #ff4444, #888 50%, #44cc44); border-radius: 2px; }
.es-marker { position: absolute; top: -2px; width: 1px; height: 8px; background: #555; }
.drive-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 11px; }
.drive-name { color: #888; min-width: 70px; }
.drive-bar { flex: 1; height: 3px; background: #1a1a25; border-radius: 2px; }
.drive-fill { height: 100%; background: #6a6aff; border-radius: 2px; }
.drive-val { color: #aaa; min-width: 28px; text-align: right; font-size: 10px; }
.wm-row { display: flex; align-items: center; gap: 6px; padding: 4px 0; flex-wrap: wrap; }
.wm-stack { display: flex; align-items: center; gap: 2px; font-size: 11px; }
.wm-item { color: #8a8aff; background: #1a1a28; padding: 1px 5px; border-radius: 3px; font-size: 10px; }

.thought-tree { margin: 6px 0; position: relative; padding-left: 14px; }
.thought-tree::before { content: ''; position: absolute; left: 5px; top: 0; bottom: 0; width: 1px; background: #2a2a3a; }
.tt-node { display: flex; align-items: center; gap: 5px; padding: 3px 0; font-size: 12px; position: relative; }
.tt-node::before { content: ''; position: absolute; left: -9px; top: 50%; width: 9px; height: 1px; background: #2a2a3a; }
.tt-node.chosen::before { background: #8aff8a; }
.tt-node.chosen::after { content: ''; position: absolute; left: -12px; top: 50%; transform: translateY(-50%); width: 5px; height: 5px; border-radius: 50%; background: #8aff8a; }
.tt-node.chosen { color: #e0e0e0; }
.tt-node:not(.chosen) { color: #666; }
.tt-conn { display: none; }
.tt-action { min-width: 80px; white-space: nowrap; font-size: 11px; }
.tt-bar { flex: 1; height: 3px; background: #1a1a25; border-radius: 2px; min-width: 20px; }
.tt-fill { height: 100%; border-radius: 2px; background: #3a3a55; }
.tt-node.chosen .tt-fill { background: #6a6aff; }
.tt-score { min-width: 32px; text-align: right; font-size: 10px; color: #777; }
.tt-node.chosen .tt-score { color: #aaa; font-weight: 600; }
.tt-reason { font-size: 10px; color: #888; padding: 1px 0 2px 17px; }
.tt-breakdown { font-size: 9px; color: #555; padding: 0 0 3px 17px; letter-spacing: 0.2px; }

.nav-btn {
  background: #1a1a25;
  color: #8a8aff;
  border: 1px solid #3a3a50;
  padding: 4px 12px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  border-radius: 3px;
}
.nav-btn:hover, .nav-btn.active { background: #2a2a3a; }

#page-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 32px 48px;
  background: #0a0a0f;
  color: #ccc;
  font-size: 14px;
  line-height: 1.7;
}
#page-content.visible { display: block; }
#page-content h1 { color: #8a8aff; font-size: 22px; margin: 24px 0 12px; }
#page-content h2 { color: #6a6aff; font-size: 18px; margin: 20px 0 10px; }
#page-content h3 { color: #5a5aff; font-size: 15px; margin: 16px 0 8px; }
#page-content p { margin: 8px 0; }
#page-content ul, #page-content ol { margin: 8px 0 8px 24px; }
#page-content li { margin: 4px 0; }
#page-content code { background: #1a1a25; padding: 2px 6px; border-radius: 3px; font-size: 13px; }
#page-content pre { background: #1a1a25; padding: 12px 16px; border-radius: 4px; overflow-x: auto; margin: 12px 0; }
#page-content pre code { padding: 0; background: none; }
#page-content strong { color: #e0e0e0; }
#page-content a { color: #8a8aff; }
#page-content blockquote { border-left: 3px solid #3a3a50; padding-left: 12px; color: #999; margin: 8px 0; }
#page-content hr { border: none; border-top: 1px solid #2a2a35; margin: 20px 0; }
#page-content table { border-collapse: collapse; margin: 12px 0; }
#page-content th, #page-content td { border: 1px solid #2a2a35; padding: 6px 12px; text-align: left; }
#page-content th { background: #1a1a25; color: #8a8aff; }

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal.visible { display: flex; }
.modal-box {
  background: #1a1a25;
  border: 1px solid #3a3a50;
  padding: 24px 32px;
  border-radius: 6px;
  text-align: center;
}
.modal-box p { margin-bottom: 16px; font-size: 14px; }
.modal-box button { margin: 0 8px; }
.modal-box input[type="text"] {
  width: 100%;
  background: #0a0a0f;
  border: 1px solid #3a3a50;
  color: #e0e0e0;
  padding: 8px;
  font-family: inherit;
  font-size: 13px;
  border-radius: 3px;
  margin-bottom: 12px;
}
.modal-box input[type="number"] {
  background: #0a0a0f;
  border: 1px solid #3a3a50;
  color: #e0e0e0;
  padding: 8px;
  font-family: inherit;
  font-size: 13px;
  border-radius: 3px;
  margin-bottom: 12px;
  width: 100%;
  -moz-appearance: textfield;
}
.modal-box input[type="number"]::-webkit-inner-spin-button,
.modal-box input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.coord-row {
  display: flex;
  gap: 8px;
}
.coord-row input { flex: 1; }

#buffering-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 15, 0.85);
  z-index: 90;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}
#buffering-overlay.visible { display: flex; }
.buffering-text {
  font-size: 24px;
  color: #888;
  font-family: 'Courier New', monospace;
  letter-spacing: 2px;
}
.buffering-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #333;
  border-top-color: #888;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

button {
  background: #1a1a25;
  color: #e0e0e0;
  border: 1px solid #3a3a50;
  padding: 8px 20px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.3s ease;
  margin-right: 8px;
}
button:hover { background: #2a2a3a; }
button.danger { border-color: #ff4444; color: #ff6666; }
button.danger:hover { background: #331111; }

.learning-dashboard { max-width: 900px; }
.learning-desc { color: #777; font-size: 12px; margin: 4px 0 12px; }
.learning-footer { color: #555; font-size: 11px; margin-top: 24px; text-align: center; }
.muted { color: #555; }
.good { color: #44cc44; }
.bad { color: #ff5555; }

.drive-chart { margin: 8px 0 16px; }
.drive-chart-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.drive-chart-name { color: #888; font-size: 12px; min-width: 110px; text-transform: capitalize; }
.drive-chart-bar { flex: 1; height: 6px; background: #1a1a25; border-radius: 3px; }
.drive-chart-fill { height: 100%; background: #6a6aff; border-radius: 3px; }
.drive-chart-val { color: #aaa; font-size: 11px; min-width: 40px; text-align: right; }

.learning-metrics {
  display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0 20px;
}
.metric-card {
  background: #1a1a25; border: 1px solid #2a2a35; border-radius: 6px;
  padding: 16px 24px; min-width: 140px; text-align: center;
}
.metric-value { font-size: 28px; font-weight: bold; color: #e0e0e0; }
.metric-label { font-size: 11px; color: #888; margin-top: 4px; }
.metric-card.tier-high { border-color: #44cc44; }
.metric-card.tier-high .metric-value { color: #44cc44; }
.metric-card.tier-mid { border-color: #ccaa33; }
.metric-card.tier-mid .metric-value { color: #ccaa33; }
.metric-card.tier-low { border-color: #ff5555; }
.metric-card.tier-low .metric-value { color: #ff5555; }

.color-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  vertical-align: middle; margin-right: 4px;
}

.bar-wrap {
  display: inline-block; width: 100px; height: 14px;
  background: #1a1a25; border-radius: 3px; position: relative;
  vertical-align: middle; overflow: hidden;
}
.bar-wrap.stacked { width: 120px; display: flex; }
.bar-fill { height: 100%; border-radius: 3px; }
.bar-fill.consensus { background: #6a6aff; }
.bar-fill.good { background: #44cc44; }
.bar-fill.bad { background: #ff5555; }
.bar-fill.neutral-fill { background: #333; }
.bar-label {
  position: absolute; right: 4px; top: 0; font-size: 10px; color: #ccc;
  line-height: 14px;
}
.situation { color: #aaa; font-size: 12px; max-width: 250px; }

.bar-wrap.gene { position: relative; }
.bar-center {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: #555;
}
.bar-fill.gene-up { background: #44cc44; position: absolute; top: 0; height: 100%; border-radius: 0 3px 3px 0; }
.bar-fill.gene-down { background: #ff5555; position: absolute; top: 0; height: 100%; border-radius: 3px 0 0 3px; }

.history-page { max-width: 960px; }
.history-table {
  width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px;
}
.history-table th, .history-table td {
  padding: 6px 10px; text-align: left; border-bottom: 1px solid #2a2a35;
}
.history-table th { color: #888; font-weight: normal; font-size: 11px; text-transform: uppercase; }
.history-table tr:hover td { background: #1a1a25; }

.blip-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle;
}
.blip-dot.alive { background: #4caf50; }
.blip-dot.dead { background: #f44336; }
.blip-dot.hollow.alive { background: transparent; border: 2px solid #4caf50; }
.blip-dot.hollow.dead { background: transparent; border: 2px solid #f44336; }
.blip-history-table td:first-child { width: 16px; text-align: center; }

@media (max-width: 768px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
  }

  #controls {
    flex-wrap: wrap;
    padding: 8px 10px;
    gap: 8px;
  }
  #nav-buttons { flex-wrap: wrap; gap: 6px !important; }
  #status-bar {
    margin-left: 0;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 11px;
    width: 100%;
  }

  #main-area {
    flex-direction: column !important;
    overflow: visible;
    flex: none;
  }
  #canvas-wrap {
    min-height: 50vh;
    flex: none;
    height: 50vh;
  }

  #monitor-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #2a2a35;
    order: 2;
    height: auto;
    overflow-y: auto;
    overflow-x: auto;
  }
  #monitor-panel.visible {
    display: block;
  }
  .monitor-canvas {
    width: 100% !important;
    height: auto !important;
  }

  #info-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid #2a2a35;
    max-height: 40vh;
  }

  #page-content {
    padding: 16px 14px;
  }

  .modal-box {
    margin: 12px;
    padding: 20px 16px;
    width: calc(100% - 24px);
    max-width: 400px;
  }

  .learning-metrics { gap: 8px; }
  .metric-card { min-width: 100px; padding: 12px 14px; }
  .metric-value { font-size: 22px; }

  .history-table { font-size: 12px; }
  .history-table th, .history-table td { padding: 5px 6px; }
}
