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

:root {
  --bg-primary: #0e1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2129;
  --bg-hover: #252c35;
  --border: #2a313a;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #545d68;
  --accent: #58a6ff;
  --accent-dim: #1a3a5c;
  --canvas-bg: #0d1117;
  --sidebar-width: 260px;
  --topbar-height: 48px;
  --scrollbar-track: #161b22;
  --scrollbar-thumb: #2a313a;
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eef2f6;
  --bg-hover: #e8ecf0;
  --border: #d0d7de;
  --text-primary: #1f2328;
  --text-secondary: #57606a;
  --text-muted: #8c959f;
  --accent: #8b5cf6;
  --accent-dim: #f3e8ff;
  --canvas-bg: #fafbfc;
  --scrollbar-track: #f6f8fa;
  --scrollbar-thumb: #d0d7de;
}

html, body {
  height: 100%;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* ── Top Bar ── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: relative;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.logo svg { width: 16px; height: 16px; }

.topbar-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

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

.project-name {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.topbar-btn svg { width: 15px; height: 15px; }

.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }

[data-theme="light"] .theme-toggle .sun-icon { display: block; }
[data-theme="light"] .theme-toggle .moon-icon { display: none; }

/* ── Layout ── */
.main-layout {
  display: flex;
  height: calc(100vh - var(--topbar-height));
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 14px 16px 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

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

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  margin-bottom: 2px;
}

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

.sidebar-item.active {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.sidebar-item-number {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-item.active .sidebar-item-number { color: var(--accent); }

.sidebar-item-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-item.active .sidebar-item-label { color: var(--text-primary); }

.sidebar-add {
  margin: 8px;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: none;
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
}

.sidebar-add:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.sidebar-add svg { width: 14px; height: 14px; }

/* ── Canvas Area ── */
.canvas-area {
  flex: 1;
  background: var(--canvas-bg);
  position: relative;
  overflow: hidden;
}

#konva-container {
  width: 100%;
  height: 100%;
}

/* Grid overlay */
.canvas-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.3;
}

/* Canvas watermark */
.canvas-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  opacity: 0.15;
  user-select: none;
}

.canvas-watermark-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border: 2px solid var(--text-muted);
  border-radius: 12px;
  display: grid;
  place-items: center;
}

.canvas-watermark-icon svg { width: 32px; height: 32px; color: var(--text-muted); }

.canvas-watermark-text {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* ── Resize Handle ── */
.resize-handle {
  width: 4px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.2s;
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}

.resize-handle:hover,
.resize-handle.dragging {
  background: var(--accent);
}

/* ── Disclaimer ── */
.canvas-disclaimer {
  position: absolute;
  top: 6px;
  right: 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.5;
  pointer-events: none;
  user-select: none;
  z-index: 5;
}

/* ── Status Bar ── */
.statusbar {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  z-index: 5;
}

.status-pill {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 4px;
  background: rgba(22, 27, 34, 0.85);
  border: 1px solid var(--border);
  color: var(--text-muted);
  backdrop-filter: blur(8px);
}

/* ── Fade-in animation ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.sidebar-item {
  animation: fadeUp 0.3s ease forwards;
  opacity: 0;
}

.sidebar-item:nth-child(1) { animation-delay: 0.03s; }
.sidebar-item:nth-child(2) { animation-delay: 0.06s; }
.sidebar-item:nth-child(3) { animation-delay: 0.09s; }
.sidebar-item:nth-child(4) { animation-delay: 0.12s; }
.sidebar-item:nth-child(5) { animation-delay: 0.15s; }
.sidebar-item:nth-child(6) { animation-delay: 0.18s; }
.sidebar-item:nth-child(7) { animation-delay: 0.21s; }
.sidebar-item:nth-child(8) { animation-delay: 0.24s; }
.sidebar-item:nth-child(9) { animation-delay: 0.27s; }
.sidebar-item:nth-child(10) { animation-delay: 0.3s; }
.sidebar-item:nth-child(11) { animation-delay: 0.33s; }
.sidebar-item:nth-child(12) { animation-delay: 0.36s; }
.sidebar-item:nth-child(13) { animation-delay: 0.39s; }
.sidebar-item:nth-child(14) { animation-delay: 0.42s; }