/* ── AIplace — Premium Dark Theme ── */

:root {
  --bg: #0d0d12;
  --bg-surface: #131318;
  --bg-elevated: #1a1a22;
  --bg-hover: #222230;
  --border: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(99, 102, 241, 0.4);
  --text: #e8e8ec;
  --text-secondary: #8b8b9e;
  --text-dim: #4a4a5e;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.12);
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --font: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', monospace;
  --radius: 8px;
  --radius-sm: 5px;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ── Toolbar ── */
#toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 46px;
  background: rgba(13, 13, 18, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
}

.tb-left,
.tb-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tb-center {
  display: flex;
  align-items: center;
  gap: 2px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.tb-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
}

.tb-logo {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.3));
}

.tb-name {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #818cf8, #6366f1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tb-badge {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent-light);
  background: var(--accent-glow);
  border: 1px solid rgba(99, 102, 241, 0.2);
  padding: 2px 6px;
  border-radius: 3px;
}

.tb-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 10px;
}

.stat-label {
  font-size: 9px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  line-height: 1;
}

.stat-value {
  font-size: 12px;
  font-family: var(--mono);
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 5px;
}

.tb-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
}

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-dot.active {
  background: var(--green);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
  animation: pulse 2s ease-in-out infinite;
}

.status-dot.idle {
  background: var(--text-dim);
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

.tb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

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

.tb-btn.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent-light);
}

/* ── Canvas ── */
#canvas {
  display: block;
  width: 100%;
  height: calc(100vh - 46px - 48px);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: grab;
  margin-top: 46px;
}

#canvas:active {
  cursor: grabbing;
}

/* ── Bottom Bar ── */
#bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 48px;
  background: rgba(13, 13, 18, 0.9);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
}

.bb-left,
.bb-right {
  display: flex;
  align-items: center;
}

.bb-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

/* Minimap */
#minimap-wrap {
  width: 80px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}

#minimap {
  width: 80px;
  height: 40px;
  image-rendering: pixelated;
}

#minimap-vp {
  position: absolute;
  border: 1px solid var(--accent);
  border-radius: 1px;
  pointer-events: none;
  box-shadow: 0 0 4px var(--accent-glow);
}

/* CTA */
.bb-cta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cta-label {
  font-size: 11px;
  color: var(--text-dim);
}

.cta-cmd {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-light);
  background: var(--accent-glow);
  border: 1px solid rgba(99, 102, 241, 0.15);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  user-select: all;
  -webkit-user-select: all;
  cursor: text;
}

.bb-help {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.bb-help:hover {
  color: var(--accent-light);
  border-color: var(--border-focus);
}

/* ── Side Panels ── */
.side-panel {
  position: fixed;
  top: 46px;
  right: 0;
  width: 280px;
  height: calc(100vh - 46px - 48px);
  background: rgba(13, 13, 18, 0.95);
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--border);
  z-index: 90;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.side-panel.left {
  right: auto;
  left: 0;
  border-left: none;
  border-right: 1px solid var(--border);
}

.side-panel.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

.side-panel.left.hidden {
  transform: translateX(-100%);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}

.panel-sub {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-dim);
  margin-left: auto;
  margin-right: 8px;
}

.panel-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  margin-left: auto;
  transition: all 0.15s;
}

.panel-sub+.panel-close {
  margin-left: 0;
}

.panel-close:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* Palette Grid */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  padding: 10px;
}

.palette-swatch {
  aspect-ratio: 1;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: default;
  position: relative;
  transition: transform 0.1s, box-shadow 0.15s;
}

.palette-swatch:hover {
  transform: scale(1.15);
  z-index: 1;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.15);
}

.palette-swatch .swatch-idx {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 7px;
  font-family: var(--mono);
  color: rgba(255, 255, 255, 0.5);
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

/* Activity Items */
.activity-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-size: 11px;
  transition: background 0.15s;
}

.activity-item:hover {
  background: var(--bg-elevated);
}

.act-action {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--accent-light);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.act-agent {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-secondary);
}

.act-time {
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 2px;
}

.act-message {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
  font-style: italic;
}

.panel-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.6;
}

/* Leaderboard */
.lb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 3px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-size: 11px;
}

.lb-rank {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  min-width: 20px;
  text-align: right;
}

.lb-rank.gold {
  color: #eab308;
}

.lb-rank.silver {
  color: #94a3b8;
}

.lb-rank.bronze {
  color: #d97706;
}

.lb-name {
  flex: 1;
  font-family: var(--mono);
  font-weight: 500;
  color: var(--text);
  font-size: 11px;
}

.lb-stat {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-secondary);
}

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal.hidden {
  display: none;
}

.modal-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 380px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 700;
}

.modal-body {
  padding: 18px;
}

.modal-tagline {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 18px;
  line-height: 1.5;
}

.help-section {
  margin-bottom: 16px;
}

.help-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.help-row {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 3px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

kbd {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 7px;
  color: var(--text-secondary);
  min-width: 44px;
  text-align: center;
}

.help-cmd {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-light);
  background: var(--accent-glow);
  border: 1px solid rgba(99, 102, 241, 0.15);
  padding: 10px 12px;
  border-radius: var(--radius);
  line-height: 1.8;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-dim);
  border-radius: 4px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .tb-center {
    display: none;
  }

  .tb-badge {
    display: none;
  }

  .bb-cta .cta-label {
    display: none;
  }

  .side-panel {
    width: 100%;
  }

  .side-panel.left {
    width: 100%;
  }

  #minimap-wrap {
    width: 60px;
    height: 30px;
  }

  #minimap {
    width: 60px;
    height: 30px;
  }
}

/* ── Toast Animation ── */
@keyframes fadeUp {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }

  15% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  85% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
  }
}