:root {
  --bg: #000000;
  --bg-panel: #050508;
  --bg-surface: #0a0a10;
  --bg-hover: #0f0f18;
  --glow: #ffffff;
  --glow-soft: rgba(255, 255, 255, 0.08);
  --glow-med: rgba(255, 255, 255, 0.15);
  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.25);
  --cyan: #0ff0fc;
  --cyan-glow: rgba(15, 240, 252, 0.15);
  --green: #22ee88;
  --text: #ccccdd;
  --text-dim: #666680;
  --text-muted: #333348;
  --border: #1a1a28;
  --danger: #ff3344;
  --font: "JetBrains Mono", "Share Tech Mono", monospace;
  --radius: 6px;
}

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

html, body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
}

/* Scanline overlay */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ===== HEADER (terminal title bar) ===== */

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.terminal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.terminal-dot.red { background: #ff5f57; }
.terminal-dot.yellow { background: #ffbd2e; }
.terminal-dot.green { background: #28ca42; }

.header-path {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-left: 8px;
  letter-spacing: 0.5px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.gen-tag {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 3px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--cyan);
  letter-spacing: 1.5px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.active {
  background: var(--green);
  box-shadow: 0 0 8px rgba(34, 238, 136, 0.6);
  animation: pulse-dot 2s ease infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== MAIN LAYOUT ===== */

#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== SIDEBAR ===== */

#sidebar {
  width: 340px;
  min-width: 340px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Logo section */
.logo-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.logo-container {
  position: relative;
  width: 120px;
  height: 120px;
  margin-bottom: 16px;
}

.logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.3));
  animation: logo-breathe 4s ease-in-out infinite;
}

.logo-pulse {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.06);
  animation: logo-ring 4s ease-in-out infinite;
}

@keyframes logo-breathe {
  0%, 100% { filter: drop-shadow(0 0 15px rgba(255, 255, 255, 0.2)) brightness(0.9); }
  50% { filter: drop-shadow(0 0 30px rgba(255, 255, 255, 0.4)) brightness(1.1); }
}

@keyframes logo-ring {
  0%, 100% { transform: scale(1); opacity: 0.3; }
  50% { transform: scale(1.08); opacity: 0.08; }
}

.entity-name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 8px;
  color: #fff;
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.3);
}

.entity-tagline {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 8px;
  line-height: 1.5;
  max-height: 60px;
  overflow: hidden;
  padding: 0 10px;
}

/* CA section */
.ca-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.ca-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  margin-top: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
}

.ca-row:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 12px var(--cyan-glow);
}

.ca-value {
  font-size: 0.72rem;
  color: var(--cyan);
  letter-spacing: 0.5px;
  font-weight: 500;
}

.ca-copy {
  font-size: 0.55rem;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  font-weight: 700;
  transition: color 0.15s ease;
}

.ca-row:hover .ca-copy {
  color: var(--cyan);
}

.ca-copy.copied {
  color: var(--green) !important;
}

/* Terminal sections in sidebar */
.terminal-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.terminal-label {
  font-size: 0.65rem;
  color: var(--green);
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

.mem-count {
  color: var(--text-dim);
}

/* Traits - terminal style */
.trait-row {
  font-size: 0.65rem;
  line-height: 1.7;
  white-space: pre;
  font-variant-ligatures: none;
}

.trait-name {
  display: inline;
}

.trait-bar {
  opacity: 0.6;
  font-size: 0.55rem;
}

.trait-val {
  color: var(--text-dim);
  font-size: 0.6rem;
}

/* Memories */
.memories-list {
  max-height: 220px;
  overflow-y: auto;
}

.mem-item {
  font-size: 0.65rem;
  color: var(--text-dim);
  padding: 3px 0;
  line-height: 1.4;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.mem-item.dim {
  opacity: 0.3;
}

/* ===== CONSOLE OUTPUT (thought stream) ===== */

#console-output {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.console-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.console-title {
  font-size: 0.65rem;
  color: var(--green);
  letter-spacing: 0.5px;
}

.console-count {
  font-size: 0.6rem;
  color: var(--text-dim);
}

.console-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.console-empty {
  padding: 40px 0;
  text-align: center;
  font-size: 0.75rem;
}

.dim { color: var(--text-dim); }

.console-cursor-line {
  padding: 8px 20px 12px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--green);
  flex-shrink: 0;
}

.prompt-char {
  color: var(--green);
  margin-right: 4px;
}

.cursor-blink {
  animation: blink 1s step-end infinite;
}

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

/* Thought entries */
.thought-entry {
  padding: 8px 0;
  font-size: 0.75rem;
  line-height: 1.6;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  animation: entry-in 0.4s ease;
}

.thought-new {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.03), transparent);
}

.thought-ts {
  color: var(--text-muted);
  font-size: 0.6rem;
}

.thought-tag {
  color: var(--cyan);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 1px;
}

.thought-text {
  color: var(--text);
  margin-left: 2px;
}

@keyframes entry-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== ADMIN-SPECIFIC ===== */

/* Panel (admin sidebar panels) */
.panel {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-badge {
  font-size: 0.6rem;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--bg-surface);
  color: var(--text-dim);
}

.personality-text {
  font-size: 0.72rem;
  line-height: 1.6;
  color: var(--text-dim);
}

/* Admin trait bars (fallback for admin page) */
.trait-bar-bg {
  flex: 1;
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}

.trait-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.8s ease;
}

.trait-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  min-width: 90px;
  text-transform: capitalize;
}

.trait-value {
  font-size: 0.6rem;
  color: var(--text-muted);
  min-width: 28px;
  text-align: right;
}

/* Memory items (admin style) */
.memory-item {
  font-size: 0.65rem;
  color: var(--text-dim);
  padding: 5px 8px;
  margin-bottom: 3px;
  background: var(--bg);
  border-radius: 3px;
  border-left: 2px solid var(--accent);
  line-height: 1.4;
}

.memory-item:nth-child(even) {
  border-left-color: var(--cyan);
}

/* Thought stream in admin */
.stream-title {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-dim);
  padding: 14px 20px 0;
}

#thought-stream {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

#thought-stream #thoughts-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px 20px;
}

.thought-item {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  margin-bottom: 8px;
  animation: entry-in 0.4s ease;
}

.thought-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.thought-author {
  font-size: 0.55rem;
  letter-spacing: 2px;
  color: var(--accent);
  font-weight: 700;
}

.thought-gen {
  font-size: 0.5rem;
  letter-spacing: 1px;
  padding: 2px 5px;
  border-radius: 3px;
  background: var(--bg-surface);
  color: var(--cyan);
  border: 1px solid rgba(15, 240, 252, 0.1);
}

.thought-time {
  font-size: 0.55rem;
  color: var(--text-muted);
  margin-left: auto;
}

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

/* X status panel */
.x-status-text {
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--text-dim);
}

.x-status-text strong {
  color: var(--text);
}

.x-link {
  color: #1d9bf0;
  text-decoration: none;
}

.x-link:hover {
  text-decoration: underline;
}

/* ===== BUTTONS ===== */

.btn {
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--bg-surface);
  color: var(--text);
  text-decoration: none;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.btn-feed {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-feed:hover {
  box-shadow: 0 0 16px var(--accent-glow);
}

.btn-danger {
  border-color: var(--danger);
  color: var(--danger);
  background: transparent;
}

.btn-danger:hover {
  background: rgba(255, 51, 68, 0.08);
}

.btn-secondary {
  background: transparent;
  border-color: var(--text-muted);
  color: var(--text-dim);
}

.btn-x {
  background: transparent;
  border-color: #1d9bf0;
  color: #1d9bf0;
}

.btn-x:hover {
  background: rgba(29, 155, 240, 0.08);
}

.btn-send {
  background: var(--cyan);
  border-color: var(--cyan);
  color: var(--bg);
}

.btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ===== MODALS ===== */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  animation: modal-in 0.25s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-title {
  font-size: 0.8rem;
  letter-spacing: 3px;
  color: var(--accent);
  margin-bottom: 8px;
  font-weight: 700;
}

.modal-desc {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 14px;
  line-height: 1.5;
}

#feed-textarea {
  width: 100%;
  min-height: 180px;
  font-family: var(--font);
  font-size: 0.75rem;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  outline: none;
  line-height: 1.5;
}

#feed-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

#feed-textarea::placeholder { color: var(--text-muted); }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}

/* Mutation report */
.mutation-report {
  border-color: var(--accent);
  box-shadow: 0 0 30px var(--accent-glow);
}

.mutation-gen {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--cyan);
  text-shadow: 0 0 16px var(--cyan-glow);
  margin: 10px 0;
  text-align: center;
  letter-spacing: 4px;
}

.mutation-trigger {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 14px;
  padding: 8px;
  background: var(--bg);
  border-radius: var(--radius);
}

.trait-change {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 0.68rem;
}

.trait-change-name {
  min-width: 90px;
  text-transform: capitalize;
  color: var(--text-dim);
}

.trait-change-arrow { color: var(--text-muted); }
.trait-change-up { color: var(--green); }
.trait-change-down { color: var(--danger); }

.mutation-response {
  margin-top: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius);
  font-size: 0.75rem;
  line-height: 1.6;
  font-style: italic;
  color: var(--text);
}

/* ===== FORM ELEMENTS ===== */

.form-group { margin-bottom: 12px; }

.form-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 5px;
  text-transform: uppercase;
}

.form-input {
  width: 100%;
  font-family: var(--font);
  font-size: 0.75rem;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.form-input:focus {
  border-color: #1d9bf0;
  box-shadow: 0 0 8px rgba(29, 155, 240, 0.15);
}

.form-input::placeholder { color: var(--text-muted); }

.form-hint {
  display: block;
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.form-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-toggle-row .form-label { margin-bottom: 0; }

.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 22px;
  transition: 0.3s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: 0.3s;
}

.toggle input:checked + .toggle-slider {
  background: rgba(29, 155, 240, 0.15);
  border-color: #1d9bf0;
}

.toggle input:checked + .toggle-slider::before {
  background: #1d9bf0;
  transform: translateX(18px);
}

/* ===== LOADING ===== */

.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(6px);
  z-index: 2000;
}

.loading.hidden { display: none; }

.loading-inner { text-align: center; }

.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}

@keyframes spin { to { transform: rotate(360deg); } }

#loading-text {
  font-size: 0.72rem;
  color: var(--text-dim);
  letter-spacing: 1px;
}

/* Mutation flash */
.mutating {
  animation: mutation-flash 0.6s ease;
}

@keyframes mutation-flash {
  0% { box-shadow: none; }
  50% { box-shadow: 0 0 40px var(--accent-glow), inset 0 0 20px var(--accent-glow); }
  100% { box-shadow: none; }
}

/* ===== EMPTY STATE ===== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 10px;
  text-align: center;
  padding: 40px;
}

.empty-state-icon { font-size: 2.5rem; opacity: 0.2; }
.empty-state-text { font-size: 0.75rem; line-height: 1.6; }

/* ===== SCROLLBAR ===== */

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== RESPONSIVE ===== */

@media (max-width: 768px) {
  #main { flex-direction: column; }

  #sidebar {
    width: 100%;
    min-width: unset;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .logo-container { width: 80px; height: 80px; }
}
