/* === Layout Shell === */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* === Sidebar === */
#sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 20;
  overflow: hidden;
}
.sidebar-header {
  padding: 20px var(--pad-lg) var(--pad-md);
  border-bottom: 1px solid var(--border-light);
}
.sidebar-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
  margin-bottom: var(--pad-sm);
}
.sidebar-search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  font-size: 13px;
  color: var(--ink);
  outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.sidebar-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.sidebar-search::placeholder { color: var(--ink-tertiary); }

/* Sidebar sections */
.sidebar-section {
  padding: var(--pad-md) var(--pad-lg);
  border-bottom: 1px solid var(--border-light);
}
.sidebar-section:last-child { border-bottom: none; }
.sidebar-section h3 {
  font-size: 9px;
  font-weight: 600;
  color: var(--ink-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: var(--pad-sm);
}
.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: var(--pad-sm);
}
.sidebar-action {
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-secondary);
  cursor: pointer;
  text-align: center;
  transition: all var(--dur-fast);
}
.sidebar-action:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--ink);
}
.sidebar-action:active {
  transform: scale(0.97);
}

/* Resource list items */
.resource-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}
.resource-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--dur-fast);
}
.resource-item:hover { background: var(--bg-hover); }
.resource-icon {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}
.resource-icon.pdf { background: rgba(240,96,96,0.15); color: #f06060; }
.resource-icon.link { background: rgba(91,156,246,0.15); color: #5b9cf6; }
.resource-icon.project { background: rgba(45,212,160,0.15); color: #2dd4a0; }
.resource-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Main content area === */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* === Top Nav === */
#topnav {
  height: var(--nav-h);
  background: var(--bg-nav);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 0 var(--pad-xl);
  gap: var(--pad-md);
  flex-shrink: 0;
  z-index: 15;
}
.nav-tabs {
  display: flex;
  gap: 1px;
  background: var(--bg-canvas);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.nav-tab {
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all var(--dur-fast);
  border: none;
  background: transparent;
}
.nav-tab:hover { color: var(--ink); background: var(--bg-hover); }
.nav-tab.active { color: var(--ink); background: var(--bg-card); box-shadow: var(--shadow-card); }
.nav-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}
.nav-filters {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.nav-filter {
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--ink-tertiary);
  cursor: pointer;
  background: transparent;
  transition: all var(--dur-fast);
  font-weight: 500;
}
.nav-filter:hover { color: var(--ink-secondary); background: var(--bg-hover); }
.nav-filter.active { color: var(--accent); background: var(--accent-light); border-color: rgba(77,142,247,0.15); }
.nav-search {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  width: 160px;
  background: var(--bg-canvas);
  outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  color: var(--ink);
}
.nav-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.nav-search::placeholder { color: var(--ink-tertiary); }

/* === Canvas Area === */
#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#stage {
  position: absolute;
  inset: 0;
  cursor: grab;
  background: var(--bg-canvas);
}
#stage.grabbing { cursor: grabbing; }

/* Dot grid — subtle, high-contrast dark */
#stage::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,0.06) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
  z-index: 0;
}
#stage::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,0.10) 1.5px, transparent 1.5px);
  background-size: 96px 96px;
  pointer-events: none;
  z-index: 0;
  opacity: 0.6;
}

/* Origin crosshair */
.stage-origin {
  position: absolute;
  left: 50%; top: 50%;
  width: 24px; height: 24px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 0;
  opacity: 0.2;
}
.stage-origin::before,
.stage-origin::after {
  content: '';
  position: absolute;
  background: var(--ink-tertiary);
}
.stage-origin::before {
  width: 1px; height: 100%;
  left: 50%; top: 0;
}
.stage-origin::after {
  width: 100%; height: 1px;
  top: 50%; left: 0;
}

#world {
  position: absolute;
  left: 0; top: 0;
  transform-origin: 0 0;
  z-index: 2;
}

/* === Nodes — premium dark cards === */
.node {
  position: absolute;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  will-change: transform;
  backface-visibility: hidden;
  background: rgba(22, 24, 34, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--dur-fast), border-color var(--dur-fast), transform 0.5s var(--ease-spring), opacity 0.3s ease;
  overflow: visible;
}
.node::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--cat-color);
  opacity: 0.6;
  transition: opacity var(--dur-fast), height var(--dur-fast);
  pointer-events: none;
}
.node:hover {
  box-shadow: var(--shadow-card-hover);
  border-color: var(--border-strong);
  z-index: 10;
}
.node:hover::before {
  opacity: 1;
  height: 3px;
}
.node.sel {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light), var(--shadow-card);
}
.node.sel::before {
  background: var(--accent);
  opacity: 1;
  height: 3px;
}
.node.dim { opacity: 0.15 !important; pointer-events: none; }

/* Content area */
.node .content {
  padding: 10px 14px;
  min-width: 0;
}
.node .title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.node .title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.node .meta-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}
.node .meta {
  color: var(--ink-tertiary);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.node .recent { display: none; }

/* Category dot indicator */
.node .cat-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--cat-color);
  box-shadow: 0 0 6px var(--cat-color);
}

/* Badges */
.node .badge {
  font-size: 9px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 20px;
  letter-spacing: 0.02em;
  line-height: 1.4;
  flex-shrink: 0;
}
.badge-new { background: rgba(45,212,160,0.15); color: #2dd4a0; }
.badge-wip { background: rgba(232,160,23,0.15); color: #e8a017; }
.badge-done { background: rgba(91,156,246,0.15); color: #5b9cf6; }
.badge-pdf { background: rgba(214,64,159,0.15); color: #d6409f; }
.badge-star5 { background: rgba(232,160,23,0.15); color: #e8a017; }

/* Level-specific sizes */
.node.root {
  min-height: 52px;
  border-width: 1px;
  border-color: var(--border-strong);
  box-shadow: var(--shadow-card), 0 0 0 4px rgba(77,142,247,0.04);
}
.node.root .content { padding: 12px 18px; }
.node.root .title { font-weight: 700; font-size: 14px; letter-spacing: -0.02em; }
.node.root::before { height: 2px; }

.node.category {
  min-height: 42px;
  min-width: 200px;
}
.node.category .content { padding: 9px 15px; }
.node.category .title { font-weight: 600; font-size: 13px; }

.node.topic {
  min-height: 38px;
  min-width: 170px;
}
.node.topic .content { padding: 8px 13px; }
.node.topic .title { font-weight: 500; font-size: 12.5px; }

.node.leaf {
  min-height: 32px;
  min-width: 150px;
}
.node.leaf .content { padding: 7px 12px; }
.node.leaf .title { font-weight: 450; font-size: 12px; }
.node.leaf::before { height: 1.5px; opacity: 0.4; }
.node.leaf:hover::before { height: 2px; opacity: 0.8; }

/* Collapse arrow */
.collapse-arrow {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%) rotate(0deg);
  font-size: 7px;
  color: var(--ink-tertiary);
  transition: transform var(--dur-md) var(--ease-out);
  cursor: pointer;
  padding: 4px;
  opacity: 0;
}
.node:hover .collapse-arrow { opacity: 0.6; }
.collapse-arrow.collapsed { transform: translateY(-50%) rotate(-90deg); }
.node:hover .collapse-arrow { opacity: 1; }

/* Zoom levels — progressive disclosure */
#world[data-zoom="mid"] .node .meta-row,
#world[data-zoom="near"] .node .meta-row { display: flex; }
#world[data-zoom="near"] .node .recent { display: block; }
#world[data-zoom="far"] .node .title { font-weight: 450; }
#world[data-zoom="far"] .node .meta-row { display: none; }
#world[data-zoom="far"] .node .badge { display: none; }
#world[data-zoom="far"] .node.root { font-size: 13px; }
#world[data-zoom="far"] .node.cat-dot { display: none; }

/* === Edges === */
#edges {
  position: absolute; left: 0; top: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}
.edge-line {
  stroke: var(--border-strong);
  stroke-width: 1;
  fill: none;
  stroke-opacity: 0.4;
  transition: stroke-opacity var(--dur-fast), stroke-width var(--dur-fast);
}
.edge-line.hot { stroke: var(--accent); stroke-opacity: 0.6; stroke-width: 1.5; }

/* === Group frames === */
.group-frame {
  position: absolute;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(77,142,247,0.02);
  pointer-events: none;
  transition: opacity var(--dur-md);
}
.group-frame .g-label {
  position: absolute;
  top: -8px; left: 14px;
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
  background: var(--bg-canvas);
  padding: 0 8px;
  white-space: nowrap;
}
.group-frame.hidden { opacity: 0; }

/* === Zoom Controls (bottom-right) === */
#zoom-controls {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated);
  z-index: 30;
  overflow: hidden;
  backdrop-filter: blur(12px);
}
.zoom-btn {
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--ink-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--dur-fast);
}
.zoom-btn:hover { background: var(--bg-hover); color: var(--ink); }
.zoom-btn:active { background: rgba(255,255,255,0.06); transform: scale(0.95); }
.zoom-divider {
  height: 1px;
  margin: 0;
  background: var(--border-light);
}

/* === Status Bar === */
#statusbar {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: rgba(22, 24, 34, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 5px 14px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-tertiary);
  box-shadow: var(--shadow-elevated);
  z-index: 30;
  display: flex;
  gap: 12px;
  align-items: center;
}
#statusbar .dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #2dd4a0;
  box-shadow: 0 0 6px rgba(45,212,160,0.5);
}