:root {
  --bg: #f8f9fa;
  --panel-bg: rgba(255, 255, 255, 0.96);
  --border: rgba(0, 0, 0, 0.08);
  --text: #212529;
  --text-dim: #495057;
  --accent: #d97757;
  --accent-soft: rgba(217, 119, 87, 0.08);
  --canvas-bg: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.04), 0 1px 4px rgba(0, 0, 0, 0.02);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

/* ── CANVAS ── */
.canvas-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--canvas-bg);
  touch-action: none;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#canvas.tool-select { cursor: default; }
#canvas.tool-text { cursor: text; }
#canvas.tool-eraser { cursor: cell; }
#canvas.panning { cursor: grabbing; }

/* ── FLOATING PANEL BASE ── */
.floating-brand,
.floating-toolbar,
.floating-actions,
.floating-panel,
.floating-nav {
  position: absolute;
  z-index: 10;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ── BRAND ── */
.floating-brand {
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 10px;
  height: 40px;
}

.brand-logo {
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-logo img { display: block; border-radius: 4px; }

.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand-links {
  display: flex;
  gap: 10px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
  margin-left: 2px;
}

.brand-link {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  text-decoration: none;
}

.brand-link:hover { color: var(--accent); }

/* ── TOOLBAR ── */
.floating-toolbar {
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  height: 48px;
}

.tool-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  transition: background 0.12s ease, color 0.12s ease;
}

.tool-btn svg { width: 19px; height: 19px; }

.tool-btn:hover { background: var(--accent-soft); color: var(--text); }

.tool-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── ACTIONS ── */
.floating-actions {
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  height: 48px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
}

.action-btn svg { width: 16px; height: 16px; }

.action-btn:hover { background: var(--accent-soft); color: var(--text); }

.action-dropdown { position: relative; }

.export-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: none;
  flex-direction: column;
  min-width: 150px;
  padding: 6px;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.export-menu.open { display: flex; }

.export-menu button {
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  color: var(--text);
}

.export-menu button:hover { background: var(--accent-soft); color: var(--accent); }

/* ── SIDEBAR ── */
.floating-panel {
  top: 85px;
  left: 14px;
  bottom: 85px;
  width: 220px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-resizer {
  position: absolute;
  top: 0;
  right: -6px;
  width: 12px;
  height: 100%;
  cursor: ew-resize;
  touch-action: none;
  z-index: 1;
}

.panel-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid transparent;
  position: relative;
  transition: transform 0.1s ease;
}

.color-swatch:hover { transform: scale(1.08); }

.color-swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
}

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

.stroke-option-btn {
  flex: 1;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
}

.stroke-option-btn span {
  display: block;
  width: 60%;
  border-radius: 2px;
  background: var(--text);
}

.stroke-option-btn:hover { background: var(--accent-soft); }

.stroke-option-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.toggle-row input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

.stencil-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stencil-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.stencil-tab {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--border);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.stencil-tab:hover { background: var(--accent-soft); }

.stencil-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.stencil-grid {
  display: grid;
  align-content: start;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 4px;
}

.stencil-item {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  cursor: grab;
  padding: 8px;
  position: relative;
}

.stencil-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.stencil-item:active { cursor: grabbing; }

.stencil-item svg { width: 100%; height: 100%; }

.stencil-item .stencil-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.stencil-item:hover .stencil-tooltip { opacity: 1; }

/* ── NAV ── */
.floating-nav {
  bottom: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  height: 40px;
}

.nav-btn {
  width: 32px;
  height: 30px;
  min-width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
}

.nav-btn svg { width: 16px; height: 16px; }

.nav-btn:hover:not(:disabled) { background: var(--accent-soft); color: var(--text); }

.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.nav-btn.zoom-label {
  width: auto;
  min-width: 48px;
  padding: 0 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  font-weight: 600;
}

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

/* ── MOBILE PANEL TOGGLE ── */
.mobile-panel-toggle {
  display: none;
  position: absolute;
  z-index: 11;
  top: 85px;
  left: 14px;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text-dim);
}

.mobile-panel-toggle svg { width: 18px; height: 18px; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 66px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .floating-brand {
    display: none;
  }

  .floating-actions {
    top: 14px;
    right: 14px;
    padding: 4px;
  }

  .floating-actions .action-btn {
    padding: 0 10px;
  }

  .floating-actions .action-btn span {
    display: none;
  }

  .export-menu {
    min-width: 140px;
  }

  .floating-toolbar {
    top: auto;
    bottom: 62px;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100vw - 24px);
    overflow-x: auto;
  }

  .floating-panel {
    top: 14px;
    bottom: 14px;
    left: 14px;
    width: 240px;
    transform: translateX(-120%);
    transition: transform 0.2s ease;
  }

  .floating-panel.open {
    transform: translateX(0);
  }

  .floating-nav {
    left: 50%;
    transform: translateX(-50%);
  }

  .mobile-panel-toggle {
    display: flex;
  }
}
