:root {
  --bg: #0b0f14;
  --panel: #121822;
  --panel-2: #0f141c;
  --text: #e6edf3;
  --muted: #98a2b3;
  --accent: #5b9cff;
  --accent-2: #7c4dff;
  --edge: #334155;
  --ok: #22c55e;
  --err: #ef4444;
}

* { box-sizing: border-box; }
html, body { 
  height: 100%; 
  width: 100%;
  margin: 0;
  padding: 0;
}
body {
  display: flex;
  flex-direction: column;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background:
    radial-gradient(1200px 700px at 10% -10%, rgba(91,156,255,0.12), transparent 60%),
    radial-gradient(900px 600px at 110% 20%, rgba(124,77,255,0.10), transparent 60%),
    radial-gradient(600px 500px at 40% 120%, rgba(91,156,255,0.08), transparent 60%),
    linear-gradient(180deg, #0a0f18 0%, #070b12 50%, #050910 100%);
  color: var(--text);
}

#topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(10, 15, 24, 0.55);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  position: sticky;
  top: 0;
  z-index: 1000;
}

#topbar { visibility: visible; }

#topbar .logo {
  font-weight: 600;
  letter-spacing: 0.2px;
}

.logo-icon { width: 50px; height: 50px; border-radius: 4px; margin-right: 8px; vertical-align: middle; }

#topbar .right { display: flex; gap: 8px; align-items: center; }
#hamburgerBtn, .hamburger {
  display: none;
  background: rgba(91, 156, 255, 0.18);
  border: 1px solid rgba(255,255,255,0.12);
  color: #fff;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  width: 36px;
  height: 36px;
  min-width: 36px;
  max-width: 36px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}
#topbar input {
  background: var(--panel);
  border: 1px solid #243041;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  width: 260px;
}
#topbar select {
  background: var(--panel);
  border: 1px solid #243041;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
}
#topbar button {
  background: rgba(91, 156, 255, 0.18);
  border: 1px solid rgba(255,255,255,0.12);
  color: white;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03);
}
#topbar button:hover { background: rgba(91, 156, 255, 0.28); }
#hideHeaderBtn, #showHeaderBtn { font-size: 14px; padding: 6px 8px; border-radius: 10px; }
#mergeModeBtn.active { background: #f59e0b; }

/* Responsive adjustments */
@media (max-width: 900px) {
  #topbar { padding: 0 10px; }
  .logo-icon { width: 40px; height: 40px; }
  #topbar input { width: 200px; }
}

@media (max-width: 700px) {
  #topbar { 
    height: 56px;
    padding: 0 10px; 
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    position: relative;
  }
  #topbar .left { 
    display: flex; 
    align-items: center; 
    gap: 8px; 
  }
  .hamburger { 
    display: flex !important; 
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
  }
  /* Force hide controls on mobile by default */
  #topbarControls { 
    display: none !important; 
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(10, 15, 24, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 12px 10px;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
  }
  body.menu-open #topbarControls { 
    display: flex !important; 
  }
  body.menu-open .hamburger {
    background: rgba(91, 156, 255, 0.3);
  }
  #topbar input, #topbar select { 
    width: 100%; 
    margin-bottom: 4px;
  }
  #topbar button { 
    width: 100%;
    margin-bottom: 4px;
  }
}

@media (max-width: 480px) {
  .logo-icon { width: 36px; height: 36px; }
  #topbar .logo { font-size: 14px; }
  #topbar input, #topbar select { padding: 8px; }
  #topbar button { padding: 7px 9px; font-size: 12px; }
  .hamburger { 
    width: 32px !important; 
    height: 32px !important; 
    min-width: 32px !important;
    max-width: 32px !important;
    font-size: 12px; 
    padding: 4px 6px !important;
  }
}

#canvasWrapper {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

#zoomFab {
  position: fixed;
  right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 1000;
}
#zoomFab button {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(15, 20, 28, 0.6);
  backdrop-filter: blur(4px);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
  font-size: 18px;
}

@media (max-width: 700px) {
  #zoomFab { 
    right: 12px; 
    bottom: 12px; 
    position: fixed;
  }
  #zoomFab button { 
    width: 40px; 
    height: 40px; 
    font-size: 16px; 
  }
}
#canvasWrapper::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(255,255,255,0.5), transparent 2px),
    radial-gradient(1.2px 1.2px at 22% 73%, rgba(255,255,255,0.45), transparent 2px),
    radial-gradient(1px 1px at 48% 12%, rgba(255,255,255,0.55), transparent 2px),
    radial-gradient(1.3px 1.3px at 66% 44%, rgba(255,255,255,0.5), transparent 2px),
    radial-gradient(1px 1px at 78% 22%, rgba(255,255,255,0.45), transparent 2px),
    radial-gradient(1.4px 1.4px at 84% 68%, rgba(255,255,255,0.6), transparent 2px),
    radial-gradient(1.1px 1.1px at 32% 58%, rgba(255,255,255,0.4), transparent 2px),
    radial-gradient(1px 1px at 14% 66%, rgba(255,255,255,0.5), transparent 2px),
    radial-gradient(1.2px 1.2px at 56% 82%, rgba(255,255,255,0.45), transparent 2px),
    radial-gradient(1px 1px at 72% 12%, rgba(255,255,255,0.5), transparent 2px);
  animation: twinkle 4s ease-in-out infinite;
  opacity: .7;
}

@keyframes twinkle {
  0%, 100% { opacity: .55; }
  50% { opacity: .9; }
}

#edges {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#canvas {
  position: absolute;
  inset: 0;
  overflow: visible;
  transform-origin: 0 0;
}

.node {
  position: absolute;
  width: 320px;
  min-height: 160px;
  background: var(--panel);
  border: 1px solid #243041;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
}

@media (max-width: 700px) {
  .node { 
    width: min(92vw, 360px); 
    min-height: 140px;
  }
  .node .handle { 
    width: 32px; 
    height: 32px; 
    font-size: 14px;
  }
  .delete-btn { 
    width: 28px; 
    height: 28px; 
    font-size: 16px;
  }
  .resize-grip { 
    width: 16px; 
    height: 16px; 
  }
}

@media (max-width: 480px) {
  .node { 
    width: 92vw; 
    min-height: 150px; 
  }
  .node .messages { 
    padding-right: 2px; 
  }
  .msg { 
    font-size: 12.5px; 
  }
  .ask .send { 
    padding: 8px 10px; 
  }
}

.node .handles { position: absolute; inset: -14px; pointer-events: none; }
.node .handle {
  position: absolute;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid #243041;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  pointer-events: auto;
}
.handle-left { left: -14px; top: calc(50% - 14px); }
.handle-right { right: -14px; top: calc(50% - 14px); }
.handle-up { top: -14px; left: calc(50% - 14px); }
.handle-down { bottom: -14px; left: calc(50% - 14px); }

.resize-grip {
  position: absolute;
  width: 14px; height: 14px;
  right: 4px; bottom: 4px;
  border-right: 2px solid #42526e;
  border-bottom: 2px solid #42526e;
  border-radius: 2px;
  cursor: se-resize;
}

.delete-btn {
  position: absolute;
  top: 6px; right: 6px;
  width: 24px; height: 24px;
  border-radius: 6px;
  background: #1f2937;
  color: #e5e7eb;
  border: 1px solid #2b3648;
  cursor: pointer;
  line-height: 1;
  z-index: 2;
}

.node .content { padding: 36px 12px 12px 12px; display: flex; flex-direction: column; gap: 10px; height: 100%; }
.node .messages { display: flex; flex-direction: column; gap: 8px; overflow: auto; flex: 1; min-height: 0; }
.msg { font-size: 13px; line-height: 1.4; padding: 8px 10px; border-radius: 8px; overflow-wrap: anywhere; word-break: break-word; }
.msg.user { background: #1a2432; align-self: flex-end; }
.msg.ai { background: #0f1723; border: 1px solid #1f2937; align-self: flex-start; }

/* Basic markdown styles */
.msg.ai p { margin: 0 0 6px 0; }
.msg.ai code { background: #0b1220; padding: 2px 4px; border-radius: 4px; }
.msg.ai pre { background: #0b1220; padding: 8px; border-radius: 8px; overflow: auto; }
.msg.ai pre code { background: transparent; padding: 0; }
.msg.ai ul, .msg.ai ol { padding-left: 18px; }
.msg.ai h1, .msg.ai h2, .msg.ai h3 { margin: 6px 0; }
/* Responsive code block handling */
.msg.ai pre, .msg.ai code { 
  max-width: 100%; 
  overflow-x: auto; 
  word-break: break-word;
}

.ask { display: flex; gap: 8px; }
.ask .prompt {
  flex: 1;
  background: #0f141c;
  border: 1px solid #243041;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
}
.ask .send {
  background: var(--accent-2);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

@media (max-width: 480px) {
  .ask .send { padding: 8px 10px; }
}

.edge {
  stroke: var(--edge);
  stroke-width: 2;
  fill: none;
}

.dragging { outline: 2px dashed #42526e; }
.merge-target { outline: 2px solid #22c55e; }

#centerAddBtn {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent-2);
  color: white;
  border: none;
  font-size: 24px;
  display: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  cursor: pointer;
}

@media (max-width: 700px) {
  #centerAddBtn { width: 52px; height: 52px; }
}

@media (max-width: 480px) {
  #centerAddBtn { width: 48px; height: 48px; font-size: 22px; }
}

#showHeaderBtn {
  position: absolute;
  left: 16px; top: 16px;
  width: 36px; height: 28px;
  border-radius: 6px;
  background: #1f2937;
  color: #e5e7eb;
  border: 1px solid #2b3648;
  display: none;
  cursor: pointer;
}

.topbar-hidden #showHeaderBtn { display: inline-block; left: auto; right: 16px; top: 16px; }

/* Scrollbar styling */
/* Firefox */
.node .messages { scrollbar-width: thin; scrollbar-color: #2b3648 transparent; }

/* WebKit */
.node .messages::-webkit-scrollbar { width: 10px; }
.node .messages::-webkit-scrollbar-track { background: transparent; }
.node .messages::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #2b3648, #1f2937);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.node .messages::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, #3a4a62, #253144); }

/* Typing animation */
.msg.ai.typing { display: inline-flex; align-items: center; gap: 6px; }
.typing .dot {
  width: 6px; height: 6px; background: #64748b; border-radius: 50%;
  animation: dotBlink 1s infinite ease-in-out;
}
.typing .dot:nth-child(2) { animation-delay: .15s; }
.typing .dot:nth-child(3) { animation-delay: .3s; }
@keyframes dotBlink {
  0%, 80%, 100% { opacity: .3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}


