@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --border: #21262d;
  --border2: #30363d;
  --text: #c9d1d9;
  --text2: #8b949e;
  --text3: #484f58;
  --bright: #f0f6fc;
  --accent: #58a6ff;
  --red: #f85149;
  --green: #238636;
  --font: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Top Bar ─────────────────────────────────────── */
.topbar {
  height: 52px;
  background: linear-gradient(180deg, var(--bg2) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 10;
}

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

.logo {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, #e94560, #7209b7);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
}

.app-title { font-size: 14px; font-weight: 600; color: var(--bright); letter-spacing: -0.02em; }

.badge-live {
  font-size: 10px; background: var(--green); color: #fff;
  padding: 2px 8px; border-radius: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
}

.avatar-stack { display: flex; margin-right: 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--bg);
  position: relative;
}
.avatar + .avatar { margin-left: -8px; }
.avatar-you {
  background: var(--border2); color: var(--text2);
  font-size: 11px; font-weight: 600;
}

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

/* ── Buttons ─────────────────────────────────────── */
.btn-icon {
  width: 32px; height: 32px; border: none; border-radius: 6px;
  background: transparent; color: var(--text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s;
}
.btn-icon:hover { color: var(--bright); }
.btn-icon.danger { color: var(--red); }
.btn-icon svg { width: 16px; height: 16px; }

/* ── Main Layout ─────────────────────────────────── */
.main { display: flex; flex: 1; overflow: hidden; }

/* ── Left Toolbar ────────────────────────────────── */
.toolbar {
  width: 56px; background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding-top: 12px; gap: 4px; flex-shrink: 0; z-index: 5;
}

.tool-btn {
  width: 40px; height: 40px; border: none; border-radius: 8px;
  background: transparent; color: var(--text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  position: relative; transition: all 0.15s;
}
.tool-btn:hover { color: var(--text); background: #21262d44; }
.tool-btn.active { background: var(--border); color: var(--accent); }
.tool-btn.active::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; background: var(--accent); border-radius: 0 2px 2px 0;
}
.tool-btn svg { width: 20px; height: 20px; }

.toolbar-sep { width: 32px; height: 1px; background: var(--border); margin: 8px 0; }

.color-swatch {
  width: 40px; height: 40px; border: none; border-radius: 8px;
  background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.color-swatch-inner {
  width: 24px; height: 24px; border-radius: 6px;
  border: 2px solid var(--border2);
}
.color-swatch-inner.transparent-fill {
  background: repeating-conic-gradient(var(--border2) 0% 25%, var(--bg2) 0% 50%) 0 0 / 8px 8px;
}

.size-control {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.size-label { font-size: 9px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.1em; }
.size-value { font-size: 11px; color: var(--text2); font-weight: 500; }
.size-slider {
  width: 40px; writing-mode: vertical-lr; direction: rtl;
  height: 80px; accent-color: var(--accent);
}

/* ── Color Picker ────────────────────────────────── */
.color-picker {
  position: absolute; left: 52px; top: -8px;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 12px; padding: 12px; z-index: 100;
  box-shadow: 0 8px 30px #00000066; width: 176px;
}
.color-picker.hidden { display: none; }
.color-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.color-opt {
  width: 32px; height: 32px; border-radius: 6px;
  border: 1px solid var(--border2); cursor: pointer;
}
.color-opt.selected { border: 2px solid var(--accent); }
.color-custom {
  width: 100%; height: 28px; margin-top: 8px;
  border: none; border-radius: 6px; cursor: pointer; background: transparent;
}

/* ── Canvas ──────────────────────────────────────── */
.canvas-container {
  flex: 1; position: relative; overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 50%, #161b2208 0%, var(--bg) 70%),
    repeating-linear-gradient(0deg, transparent, transparent 39px, #161b2215 39px, #161b2215 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, #161b2215 39px, #161b2215 40px);
}

.canvas-transform {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  transform-origin: 0 0;
}

/* ── Collaborator Cursors ────────────────────────── */
.collab-cursor {
  position: absolute; pointer-events: none;
  transition: left 0.05s linear, top 0.05s linear; z-index: 100;
}
.collab-label {
  position: absolute; left: 16px; top: 14px;
  color: var(--bg); font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 4px; white-space: nowrap;
  font-family: var(--font);
}

/* ── Text Input ──────────────────────────────────── */
.text-input {
  background: #161b2288; border: 1px solid var(--accent);
  font-family: var(--font); padding: 4px 8px; border-radius: 4px;
  outline: none; min-width: 120px; backdrop-filter: blur(8px);
}

/* ── Selection Info Bar ──────────────────────────── */
.sel-info {
  position: absolute; bottom: 60px; left: 50%; transform: translateX(-50%);
  background: #161b22ee; border: 1px solid var(--border2);
  border-radius: 10px; padding: 8px 14px;
  display: flex; align-items: center; gap: 12px;
  backdrop-filter: blur(12px); font-size: 11px; color: var(--text2); z-index: 20;
}
.sel-info.hidden { display: none; }
.sel-count { color: var(--accent); font-weight: 600; }
.sel-hint { font-size: 10px; color: var(--text3); }

/* ── Zoom Controls ───────────────────────────────── */
.zoom-controls {
  position: absolute; bottom: 16px; left: 16px;
  display: flex; align-items: center; gap: 4px;
  background: #161b22ee; border: 1px solid var(--border);
  border-radius: 10px; padding: 4px 6px; backdrop-filter: blur(12px);
}
.zoom-btn {
  width: 28px; height: 28px; border: none; border-radius: 6px;
  background: transparent; color: var(--text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.zoom-btn svg { width: 15px; height: 15px; }
.zoom-label {
  font-size: 11px; color: var(--text2); min-width: 44px;
  text-align: center; font-weight: 500; cursor: pointer;
}

.element-count {
  position: absolute; bottom: 16px; font-size: 10px; color: var(--text3);
  background: #161b22cc; padding: 4px 10px; border-radius: 6px;
  border: 1px solid var(--border); transition: right 0.2s;
}

/* ── Layers Panel ────────────────────────────────── */
.layers-panel {
  width: 248px; background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: width 0.2s ease; overflow: hidden; flex-shrink: 0; z-index: 5;
}
.layers-panel.collapsed { width: 0; border-left: none; }

.layers-header {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.layers-title { font-size: 12px; font-weight: 600; color: var(--bright); }
.layers-add {
  width: 26px; height: 26px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--bg2); color: var(--text2);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.layers-add svg { width: 14px; height: 14px; }

.layers-list { flex: 1; overflow-y: auto; padding: 8px 6px; }

.layer-item {
  padding: 8px 10px; border-radius: 8px; margin-bottom: 2px;
  cursor: pointer; border: 1px solid transparent; transition: all 0.15s;
}
.layer-item:hover { background: #161b2266; }
.layer-item.active { background: var(--bg2); border-color: var(--border); }
.layer-item.hidden-layer { opacity: 0.4; }

.layer-row { display: flex; align-items: center; justify-content: space-between; }
.layer-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.layer-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--border2); flex-shrink: 0; }
.layer-dot.active { background: var(--accent); }
.layer-name {
  font-size: 12px; color: var(--text2); font-weight: 400;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.layer-name.active { color: var(--bright); font-weight: 500; }
.layer-count { font-size: 10px; color: var(--text3); margin-left: 4px; flex-shrink: 0; }

.layer-name-input {
  background: var(--bg); border: 1px solid var(--accent);
  color: var(--bright); font-size: 12px; font-family: var(--font);
  padding: 1px 4px; border-radius: 3px; outline: none; width: 100%;
}

.layer-controls {
  display: flex; align-items: center; gap: 4px; margin-top: 6px;
}
.layer-ctrl-btn {
  width: 24px; height: 24px; border: none; border-radius: 4px;
  background: transparent; color: var(--text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.layer-ctrl-btn.danger { color: var(--red); }
.layer-ctrl-btn svg { width: 13px; height: 13px; }
.layer-opacity { flex: 1; height: 3px; accent-color: var(--accent); }

.layer-del-btn {
  width: 24px; height: 24px; border: none; border-radius: 4px;
  background: transparent; color: var(--red); cursor: pointer;
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; padding: 0;
}

/* ── Layers Toggle ───────────────────────────────── */
.layers-toggle {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 20px; height: 48px;
  background: var(--bg2); border: 1px solid var(--border); border-right: none;
  border-radius: 6px 0 0 6px; color: var(--text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; z-index: 6; transition: right 0.2s ease;
}
