/* ===== CSS VARIABLES / THEMES ===== */
:root[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-surface: #16213e;
  --bg-surface-hover: #1e2d4d;
  --bg-overlay: rgba(0, 0, 0, 0.6);
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --text-muted: #6b6b80;
  --border-color: #2a2a40;
  --border-light: #333350;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-secondary: #8b5cf6;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --node-bg: #1e2340;
  --node-border: #3a3f5c;
  --node-selected: #6366f1;
  --node-hover: #252a4a;
  --connection-color: rgba(255, 255, 255, 0.6);
  --connection-highlight: rgba(255, 255, 255, 0.9);
  --toolbar-bg: #1a1a2eee;
  --topbar-bg: #0f0f1af0;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --minimap-bg: #1a1a2ecc;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #eab308;
  --scrollbar-thumb: #333350;
}

:root[data-theme="light"] {
  --bg-primary: #f0f2f5;
  --bg-secondary: #ffffff;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f5f5f8;
  --bg-overlay: rgba(0, 0, 0, 0.3);
  --text-primary: #1a1a2e;
  --text-secondary: #555570;
  --text-muted: #8888a0;
  --border-color: #dddde8;
  --border-light: #e8e8f0;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-secondary: #8b5cf6;
  --accent-glow: rgba(99, 102, 241, 0.2);
  --node-bg: #ffffff;
  --node-border: #c0c0d0;
  --node-selected: #6366f1;
  --node-hover: #f0f0ff;
  --connection-color: rgba(0, 0, 0, 0.5);
  --connection-highlight: rgba(0, 0, 0, 0.8);
  --toolbar-bg: #ffffffee;
  --topbar-bg: #f0f2f5f0;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);
  --minimap-bg: #ffffffcc;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #ca8a04;
  --scrollbar-thumb: #ccccdd;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent);
  color: white;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== SCREENS ===== */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.screen.active { display: flex; }

/* ===== LANDING SCREEN ===== */
#landing-screen {
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  flex-direction: column;
}

.landing-container {
  max-width: 700px;
  width: 100%;
  padding: 40px 24px;
  animation: fadeInUp 0.5s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.landing-header {
  text-align: center;
  margin-bottom: 40px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
}

.logo h1 {
  font-size: 32px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-secondary);
  font-size: 16px;
}

.landing-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.landing-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.landing-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.card-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.landing-card h2 {
  font-size: 18px;
  font-weight: 600;
}

.landing-card p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.4;
}

.landing-card input {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.landing-card input:focus {
  border-color: var(--accent);
}

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

.landing-footer {
  text-align: center;
}

.powered-by {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.powered-by a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.powered-by a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 16px;
}
.btn-ghost:hover {
  color: var(--text-primary);
  background: var(--bg-surface);
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
}
.btn-small:hover { background: var(--accent-hover); }

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.icon-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.icon-btn-sm {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.15s;
}
.icon-btn-sm:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

/* ===== TOPBAR ===== */
#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

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

.topbar-center {
  display: flex;
  align-items: center;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

#map-name {
  font-size: 15px;
  font-weight: 600;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 600;
}

.collab-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

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

/* ===== DROPDOWN ===== */
.dropdown {
  position: relative;
}
.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 4px;
  min-width: 160px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu button {
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}
.dropdown-menu button:hover {
  background: var(--bg-surface-hover);
}

/* ===== FLOATING TOOLBAR ===== */
#toolbar {
  position: fixed;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--toolbar-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 90;
  box-shadow: var(--shadow);
}

.toolbar-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toolbar-divider {
  height: 1px;
  background: var(--border-color);
  margin: 4px 2px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.tool-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}
.tool-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.tool-btn span { pointer-events: none; }

.zoom-level {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 2px 0;
  user-select: none;
}

/* ===== COLOR PALETTE ===== */
.color-picker-wrap, .shape-picker-wrap {
  position: relative;
}

.color-palette {
  position: absolute;
  left: 100%;
  top: 0;
  margin-left: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.color-swatch:hover {
  transform: scale(1.15);
  border-color: white;
}
.color-swatch.active {
  border-color: white;
  box-shadow: 0 0 0 2px var(--accent);
}

/* ===== SHAPE PALETTE ===== */
.shape-palette {
  position: absolute;
  left: 100%;
  top: 0;
  margin-left: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}

.shape-option {
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shape-option:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}
.shape-option.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== CANVAS ===== */
#canvas-viewport {
  position: fixed;
  top: 52px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  cursor: grab;
  background: var(--bg-primary);
  /* Subtle grid pattern */
  background-image:
    radial-gradient(circle, var(--border-color) 1px, transparent 1px);
  background-size: 30px 30px;
}

#canvas-viewport.grabbing { cursor: grabbing; }
#canvas-viewport.node-dragging { cursor: default; }

#canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
}

#connections-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
  z-index: 0;
}

#connections-layer path {
  fill: none;
  stroke: var(--connection-color);
  stroke-width: 3;
  stroke-linecap: round;
  /* no transition — prevents ghost traces during drag */
}
#connections-layer path.highlight {
  stroke: var(--connection-highlight);
  stroke-width: 4;
}

#connections-layer .arrow-marker {
  fill: var(--connection-color);
}

#nodes-layer {
  position: absolute;
  top: 0;
  left: 0;
}

/* ===== MIND MAP NODES ===== */
.mm-node {
  position: absolute;
  min-width: 120px;
  max-width: 300px;
  padding: 10px 18px;
  background: var(--node-bg);
  border: 2px solid var(--node-border);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 1;
  animation: nodeAppear 0.25s ease;
  white-space: nowrap;
}

@keyframes nodeAppear {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

.mm-node:hover {
  background: var(--node-hover);
  border-color: var(--accent);
  z-index: 2;
}

.mm-node.selected {
  border-color: var(--node-selected);
  box-shadow: 0 0 0 3px var(--accent-glow), var(--shadow);
  z-index: 3;
}

.mm-node.remote-selected {
  box-shadow: 0 0 0 3px rgba(255, 200, 50, 0.4);
}

.mm-node.root-node {
  font-size: 17px;
  font-weight: 700;
  padding: 16px 28px;
  min-width: 140px;
  border-width: 3px;
  border-radius: 14px;
  box-shadow: 0 0 20px var(--accent-glow);
}

.mm-node.dragging {
  opacity: 0.85;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  cursor: grabbing;
}

/* Node shapes */
.mm-node.shape-pill { border-radius: 50px; }
.mm-node.shape-rectangle { border-radius: 2px; }
.mm-node.shape-diamond {
  border-radius: 2px;
  transform: rotate(0deg); /* diamond handled via clip-path */
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  padding: 20px 30px;
  text-align: center;
  justify-content: center;
}

.mm-node .node-emoji {
  font-size: 18px;
  flex-shrink: 0;
}

.mm-node .node-text {
  outline: none;
  min-width: 30px;
  font-size: 14px;
  line-height: 1.4;
}

.mm-node .node-text[contenteditable="true"] {
  white-space: pre-wrap;
  word-break: break-word;
}

.mm-node .node-text:focus {
  cursor: text;
}

.mm-node .collapse-btn {
  position: absolute;
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 2px solid var(--node-border);
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  z-index: 5;
}
.mm-node .collapse-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg-surface-hover);
}

.mm-node.collapsed .collapse-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Node search highlight */
.mm-node.search-match {
  border-color: var(--warning);
  box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.3);
}

.mm-node.search-dimmed {
  opacity: 0.3;
}

/* ===== MINIMAP ===== */
#minimap {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 180px;
  height: 120px;
  background: var(--minimap-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  z-index: 80;
  cursor: pointer;
}

#minimap-canvas {
  width: 100%;
  height: 100%;
}

#minimap-viewport-rect {
  position: absolute;
  border: 1.5px solid var(--accent);
  background: var(--accent-glow);
  border-radius: 2px;
  pointer-events: none;
}

/* ===== SEARCH OVERLAY ===== */
#search-overlay {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 110;
  width: 380px;
  max-width: calc(100% - 32px);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: var(--shadow-lg);
}

.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
.search-box input::placeholder { color: var(--text-muted); }

#search-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

#search-results {
  margin-top: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
#search-results:empty { display: none; }

.search-result-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.15s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-surface-hover); }

/* ===== MODALS ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  max-width: 420px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-lg);
  animation: modalSlideUp 0.25s ease;
}

.modal-sm { max-width: 340px; }

@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.share-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.share-section label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.copy-row {
  display: flex;
  gap: 8px;
}

.copy-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  font-family: monospace;
}

.qr-section {
  align-items: center;
  text-align: center;
}

#qr-code {
  padding: 16px;
  background: white;
  border-radius: 12px;
  display: inline-block;
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== EMOJI GRID ===== */
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
}

.emoji-grid button {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.emoji-grid button:hover {
  background: var(--bg-surface-hover);
}

/* ===== TOAST NOTIFICATION ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  z-index: 600;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
  .landing-cards {
    grid-template-columns: 1fr;
  }

  #toolbar {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: 16px;
    transform: none;
    flex-direction: row;
    overflow-x: auto;
    border-radius: 12px;
    padding: 6px;
  }

  .toolbar-group {
    flex-direction: row;
  }

  .toolbar-divider {
    width: 1px;
    height: auto;
    margin: 2px 4px;
  }

  .tool-btn span:not(:first-child) {
    display: none;
  }

  .tool-btn {
    padding: 8px;
  }

  #minimap { display: none; }

  .color-palette, .shape-palette {
    left: auto;
    bottom: 100%;
    top: auto;
    margin-left: 0;
    margin-bottom: 8px;
  }
}

@media (max-width: 480px) {
  .landing-container { padding: 24px 16px; }
  .landing-card { padding: 20px 16px; }
  .logo h1 { font-size: 26px; }
  .tagline { font-size: 14px; }
}
