/* ══════════════════════════════════════════════════════════
   RESET & CSS VARIABLES
══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-canvas:          #f0ece4;
  --bg-toolbar:         #ffffff;
  --bg-toolbar-2:       #f5f5f5;
  --bg-active:          #e8f0fe;
  --border:             #d0d0d0;
  --text-primary:       #1a1a1a;
  --text-secondary:     #555555;
  --accent:             #3a7bfd;
  --accent-hover:       #2563eb;
  --shadow:             0 2px 8px rgba(0,0,0,.12);
  --shadow-heavy:       0 4px 20px rgba(0,0,0,.18);
  --radius:             10px;
  --radius-sm:          6px;
  --toolbar-width:      64px;
  --toolbar-expanded:   224px;
  --layers-panel-width: 220px;
  --transition:         180ms ease;
}
[data-theme="dark"] {
  --bg-canvas:        #1a1a2e;
  --bg-toolbar:       #16213e;
  --bg-toolbar-2:     #0f2a4a;
  --bg-active:        #1e3a5f;
  --border:           #2a3a5c;
  --text-primary:     #e8e8f0;
  --text-secondary:   #9090b0;
  --accent:           #4d8aff;
  --accent-hover:     #6ba0ff;
  --shadow:           0 2px 8px rgba(0,0,0,.4);
  --shadow-heavy:     0 4px 20px rgba(0,0,0,.6);
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px; color: var(--text-primary); background: var(--bg-canvas);
  touch-action: none; -webkit-user-select: none; user-select: none;
}

/* ══════════════════════════════════════════════════════════
   APP SHELL
══════════════════════════════════════════════════════════ */
#app { display: flex; width: 100vw; height: 100vh; position: relative; }

/* ══════════════════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════════════════ */
#sidebar {
  display: flex; flex-direction: column;
  width: var(--toolbar-width); height: 100%;
  background: var(--bg-toolbar); border-right: 1px solid var(--border);
  box-shadow: var(--shadow); z-index: 100;
  transition: width var(--transition);
  overflow: hidden; flex-shrink: 0;
}
#sidebar.expanded { width: var(--toolbar-expanded); }

#sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 10px; border-bottom: 1px solid var(--border); min-height: 56px;
}
#app-logo {
  width: 36px; height: 36px; background: var(--accent);
  border-radius: var(--radius-sm); display: flex; align-items: center;
  justify-content: center; color: #fff; font-weight: 800; font-size: 16px; flex-shrink: 0;
}
#app-title {
  font-weight: 700; font-size: 15px; color: var(--text-primary);
  white-space: nowrap; opacity: 0; transition: opacity var(--transition);
}
#sidebar.expanded #app-title { opacity: 1; }

#sidebar-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; }
#sidebar-scroll::-webkit-scrollbar { width: 3px; }
#sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

#toggle-sidebar {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 48px; background: none; border: none;
  border-top: 1px solid var(--border); cursor: pointer;
  color: var(--text-secondary); font-size: 18px; flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
#toggle-sidebar:hover { background: var(--bg-toolbar-2); color: var(--accent); }
#toggle-sidebar svg { transition: transform var(--transition); }
#sidebar.expanded #toggle-sidebar svg { transform: rotate(180deg); }

.tool-section { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.section-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-secondary);
  padding: 4px 4px 6px; white-space: nowrap;
  opacity: 0; height: 0; overflow: hidden;
  transition: opacity var(--transition), height var(--transition);
}
#sidebar.expanded .section-label { opacity: 1; height: auto; }
.tool-group { display: flex; flex-direction: column; gap: 2px; }

.tool-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 48px; padding: 8px;
  background: none; border: 2px solid transparent;
  border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text-primary); position: relative; overflow: hidden;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.tool-btn:hover { background: var(--bg-toolbar-2); color: var(--accent); }
.tool-btn.active { background: var(--bg-active); border-color: var(--accent); color: var(--accent); }
.tool-btn .icon {
  width: 30px; height: 30px; display: flex; align-items: center;
  justify-content: center; font-size: 20px; flex-shrink: 0; line-height: 1;
}
.tool-btn .label {
  font-size: 13px; font-weight: 500; white-space: nowrap;
  opacity: 0; width: 0; transition: opacity var(--transition), width var(--transition);
}
#sidebar.expanded .tool-btn .label { opacity: 1; width: auto; }

.tool-btn[data-tooltip]::after {
  content: attr(data-tooltip); position: absolute; left: calc(100% + 10px); top: 50%;
  transform: translateY(-50%); background: var(--text-primary); color: var(--bg-toolbar);
  font-size: 12px; padding: 4px 8px; border-radius: var(--radius-sm);
  white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity 120ms ease; z-index: 200;
}
#sidebar:not(.expanded) .tool-btn[data-tooltip]:hover::after { opacity: 1; }

.ripple {
  position: absolute; border-radius: 50%; background: var(--accent);
  opacity: .25; pointer-events: none; transform: scale(0);
  animation: ripple-anim 400ms ease-out forwards;
}
@keyframes ripple-anim { to { transform: scale(4); opacity: 0; } }

/* Sub-options (eraser mode, font size) */
.sub-options {
  display: flex; gap: 3px; padding: 0 4px 4px;
  overflow: hidden; max-height: 0; opacity: 0;
  transition: max-height 200ms ease, opacity 200ms ease;
}
#sidebar.expanded .sub-options { max-height: 44px; opacity: 1; }
.sub-btn {
  flex: 1; height: 36px; background: var(--bg-toolbar-2);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; font-size: 11px; font-weight: 600;
  color: var(--text-secondary); transition: all 150ms ease;
}
.sub-btn:hover { background: var(--bg-active); color: var(--accent); }
.sub-btn.active { border-color: var(--accent); background: var(--bg-active); color: var(--accent); }

/* Color panel */
#color-panel { padding: 8px; border-bottom: 1px solid var(--border); }
#current-color-row { display: flex; align-items: center; gap: 6px; padding: 4px 4px 6px; }
#current-color-dot {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--border); background: #222222;
  cursor: pointer; flex-shrink: 0; transition: transform 100ms ease;
}
#current-color-dot:hover { transform: scale(1.1); }
#current-color-label {
  font-size: 11px; color: var(--text-secondary); flex: 1;
  opacity: 0; transition: opacity var(--transition); overflow: hidden;
}
#sidebar.expanded #current-color-label { opacity: 1; }
#hex-input {
  width: 0; padding: 0; border: none; background: none;
  font-size: 11px; color: var(--text-primary); opacity: 0;
  transition: all var(--transition); outline: none;
}
#sidebar.expanded #hex-input {
  width: 70px; padding: 3px 5px;
  background: var(--bg-toolbar-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); opacity: 1;
}
.color-swatches {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px;
  overflow: hidden; max-height: 0; transition: max-height 200ms ease;
}
#sidebar.expanded .color-swatches { max-height: 200px; }
.color-swatch {
  width: 100%; aspect-ratio: 1; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: transform 100ms ease, border-color 100ms ease;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: var(--accent); transform: scale(1.1); }

#opacity-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 4px 2px;
  overflow: hidden; max-height: 0; opacity: 0;
  transition: max-height 200ms ease, opacity 200ms ease;
}
#sidebar.expanded #opacity-row { max-height: 32px; opacity: 1; }
#opacity-label { font-size: 11px; color: var(--text-secondary); white-space: nowrap; }
#opacity-slider { flex: 1; height: 3px; cursor: pointer; accent-color: var(--accent); }
#opacity-value { font-size: 11px; color: var(--text-secondary); width: 28px; text-align: right; }

.stroke-group {
  display: flex; gap: 4px; padding: 4px;
  overflow: hidden; max-height: 0; transition: max-height 200ms ease;
}
#sidebar.expanded .stroke-group { max-height: 60px; }
.stroke-btn {
  flex: 1; height: 44px; background: var(--bg-toolbar-2);
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: border-color var(--transition), background var(--transition);
  color: var(--text-primary);
}
.stroke-btn:hover { background: var(--bg-active); }
.stroke-btn.active { border-color: var(--accent); background: var(--bg-active); }
#color-picker-input { display: none; }

/* ══════════════════════════════════════════════════════════
   CANVAS AREA
══════════════════════════════════════════════════════════ */
#canvas-area { flex: 1; position: relative; overflow: hidden; background: var(--bg-canvas); }
#canvas-transform { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
#canvas-main { display: block; box-shadow: var(--shadow-heavy); }
#canvas-overlay { position: absolute; top: 0; left: 0; pointer-events: none; }

/* ══════════════════════════════════════════════════════════
   STATUS BAR
══════════════════════════════════════════════════════════ */
#status-bar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: var(--bg-toolbar); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 14px;
  display: flex; align-items: center; gap: 12px;
  font-size: 12px; color: var(--text-secondary);
  box-shadow: var(--shadow); z-index: 50; pointer-events: none; opacity: .8;
}
#status-bar span { white-space: nowrap; }
#user-indicator { pointer-events: auto; }

/* ══════════════════════════════════════════════════════════
   FLOAT BAR
══════════════════════════════════════════════════════════ */
#float-bar {
  position: absolute; bottom: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 8px; z-index: 100;
}
.float-btn {
  width: 48px; height: 48px; background: var(--bg-toolbar);
  border: 1px solid var(--border); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 18px; box-shadow: var(--shadow);
  color: var(--text-primary);
  transition: background var(--transition), color var(--transition), transform 100ms ease;
}
.float-btn:hover { background: var(--bg-active); color: var(--accent); transform: scale(1.08); }
.float-btn:active { transform: scale(.95); }
.float-btn.active { background: var(--bg-active); color: var(--accent); border-color: var(--accent); }

/* ══════════════════════════════════════════════════════════
   EXPORT PANEL
══════════════════════════════════════════════════════════ */
#export-panel {
  display: none; position: absolute; bottom: 16px; right: 72px;
  background: var(--bg-toolbar); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px;
  box-shadow: var(--shadow-heavy); z-index: 200;
  flex-direction: column; gap: 4px; min-width: 170px;
}
#export-panel.open { display: flex; }
.export-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  cursor: pointer; background: none; border: none;
  font-size: 13px; color: var(--text-primary); text-align: left;
  transition: background var(--transition);
}
.export-item:hover { background: var(--bg-toolbar-2); }
.export-item .eicon { font-size: 18px; width: 24px; text-align: center; }

/* ══════════════════════════════════════════════════════════
   TEXT EDITOR OVERLAY
══════════════════════════════════════════════════════════ */
#text-editor-wrap { display: none; position: absolute; z-index: 300; pointer-events: all; }
#text-editor {
  background: transparent; border: 1.5px dashed var(--accent); outline: none;
  resize: none; font-family: inherit; color: var(--text-primary);
  padding: 2px 4px; min-width: 80px; min-height: 30px; overflow: hidden; line-height: 1.3;
}
[data-theme="dark"] #text-editor { color: #e8e8f0; }

/* ══════════════════════════════════════════════════════════
   LASER POINTER
══════════════════════════════════════════════════════════ */
#laser-dot {
  display: none; position: absolute; width: 16px; height: 16px;
  border-radius: 50%; pointer-events: none; z-index: 500;
  transform: translate(-50%, -50%);
  background: rgba(255,30,30,.9);
  box-shadow: 0 0 0 3px rgba(255,30,30,.3), 0 0 12px 4px rgba(255,30,30,.5);
  animation: laser-pulse 1s ease-in-out infinite;
}
@keyframes laser-pulse {
  0%,100% { box-shadow: 0 0 0 3px rgba(255,30,30,.3), 0 0 12px 4px rgba(255,30,30,.5); }
  50%      { box-shadow: 0 0 0 6px rgba(255,30,30,.15), 0 0 20px 8px rgba(255,30,30,.7); }
}
body.laser-active #laser-dot { display: block; }
body.laser-active * { cursor: none !important; }

/* ══════════════════════════════════════════════════════════
   PRESENTATION MODE
══════════════════════════════════════════════════════════ */
body.presentation-mode #sidebar,
body.presentation-mode #status-bar { display: none; }
#presentation-bar {
  display: none; position: absolute; bottom: 20px; left: 50%;
  transform: translateX(-50%); background: rgba(0,0,0,.75);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-radius: 30px; padding: 8px 16px; gap: 10px; z-index: 200;
}
body.presentation-mode #presentation-bar { display: flex; }
.pres-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.15); border: none;
  color: #fff; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 150ms ease;
}
.pres-btn:hover { background: rgba(255,255,255,.3); }
.pres-btn.active { background: rgba(255,80,80,.6); }

/* ══════════════════════════════════════════════════════════
   MODAL
══════════════════════════════════════════════════════════ */
#modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); backdrop-filter: blur(3px);
  z-index: 500; align-items: center; justify-content: center;
}
#modal-overlay.open { display: flex; }
.modal-box {
  background: var(--bg-toolbar); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; min-width: 280px;
  max-width: 90vw; box-shadow: var(--shadow-heavy);
  display: flex; flex-direction: column; gap: 16px;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.modal-body  { font-size: 14px; color: var(--text-secondary); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.btn {
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; cursor: pointer; border: none;
  transition: opacity 150ms ease, transform 100ms ease;
}
.btn:active { transform: scale(.97); }
.btn-ghost { background: var(--bg-toolbar-2); border: 1px solid var(--border); color: var(--text-primary); }
.btn-ghost:hover { background: var(--bg-active); }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }

/* ══════════════════════════════════════════════════════════
   TOOL OPTIONS MODAL (double-tap / dblclick)
══════════════════════════════════════════════════════════ */
#tool-modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 600; align-items: center; justify-content: center;
}
#tool-modal-overlay.open { display: flex; }

#tool-modal {
  background: var(--bg-toolbar); border: 1px solid var(--border);
  border-radius: 20px; padding: 22px 24px;
  width: min(460px, 94vw); max-height: 90vh;
  overflow-y: auto; box-shadow: var(--shadow-heavy);
  display: flex; flex-direction: column; gap: 20px;
  animation: tmo-pop 200ms cubic-bezier(.34,1.5,.64,1) forwards;
}
@keyframes tmo-pop {
  from { transform: scale(.82) translateY(20px); opacity: 0; }
  to   { transform: scale(1)   translateY(0);    opacity: 1; }
}
#tool-modal::-webkit-scrollbar { width: 4px; }
#tool-modal::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

#tmo-header {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
#tmo-icon {
  width: 44px; height: 44px; background: var(--bg-active);
  border: 1.5px solid var(--border); border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0;
}
#tmo-title { flex: 1; font-size: 17px; font-weight: 700; color: var(--text-primary); }
#tmo-close {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--bg-toolbar-2); cursor: pointer;
  color: var(--text-secondary); font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: background 150ms, color 150ms;
}
#tmo-close:hover { background: #ef4444; color: #fff; }

.tmo-section { display: flex; flex-direction: column; gap: 10px; }
.tmo-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-secondary);
}

/* Colour swatches – 6 per row (larger than sidebar) */
#tmo-swatches {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 9px;
}
.tmo-swatch {
  width: 100%; aspect-ratio: 1; border-radius: 50%;
  border: 2.5px solid transparent; cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.tmo-swatch:hover  { transform: scale(1.2); }
.tmo-swatch.active { border-color: var(--accent); transform: scale(1.12);
                     box-shadow: 0 0 0 3px rgba(58,123,253,.2); }

#tmo-color-row {
  display: flex; align-items: center; gap: 10px;
}
#tmo-color-dot {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid var(--border); cursor: pointer;
  flex-shrink: 0; transition: transform 100ms;
}
#tmo-color-dot:hover { transform: scale(1.1); }
#tmo-hex {
  flex: 1; padding: 9px 12px;
  background: var(--bg-toolbar-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px;
  color: var(--text-primary); outline: none; font-family: monospace;
}
#tmo-hex:focus { border-color: var(--accent); }
#tmo-native-picker-modal { display: none; }

#tmo-opacity-row {
  display: flex; align-items: center; gap: 10px;
}
.tmo-range-label { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
#tmo-opacity { flex: 1; accent-color: var(--accent); cursor: pointer; }
#tmo-opacity-val { font-size: 12px; color: var(--text-secondary); width: 38px; text-align: right; }

/* Stroke / eraser size – 3 wide buttons with SVG preview */
#tmo-strokes { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.tmo-stroke {
  height: 60px; background: var(--bg-toolbar-2);
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text-primary);
  transition: border-color 150ms, background 150ms;
}
.tmo-stroke:hover   { background: var(--bg-active); }
.tmo-stroke.active  { border-color: var(--accent); background: var(--bg-active); }

/* Generic option row (eraser mode, etc.) */
.tmo-opt-row { display: flex; gap: 8px; }
.tmo-opt-btn {
  flex: 1; min-height: 52px; padding: 8px 4px;
  background: var(--bg-toolbar-2); border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px; font-weight: 600; line-height: 1.4;
  color: var(--text-secondary); transition: all 150ms;
}
.tmo-opt-btn:hover  { background: var(--bg-active); color: var(--accent); }
.tmo-opt-btn.active { border-color: var(--accent); background: var(--bg-active); color: var(--accent); }

/* Font size buttons in modal */
.tmo-font-row { display: flex; gap: 8px; }
.tmo-font-btn {
  flex: 1; height: 60px; background: var(--bg-toolbar-2);
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; font-weight: 700; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  transition: all 150ms;
}
.tmo-font-btn:hover  { background: var(--bg-active); }
.tmo-font-btn.active { border-color: var(--accent); background: var(--bg-active); color: var(--accent); }

@media (max-width: 480px) {
  :root { --toolbar-width: 56px; --toolbar-expanded: 180px; }
  #tmo-swatches { grid-template-columns: repeat(4, 1fr); }
}

/* ══════════════════════════════════════════════════════════
   LAYERS PANEL (right sidebar)
══════════════════════════════════════════════════════════ */
#layers-panel {
  display: flex;
  flex-direction: column;
  width: var(--layers-panel-width);
  height: 100%;
  background: var(--bg-toolbar);
  border-left: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  transition: width var(--transition);
  position: relative;
  z-index: 100;
}
#layers-panel.collapsed { width: 32px; }

#layers-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
}
#layers-panel.collapsed #layers-header { opacity: 0; pointer-events: none; }

#layers-title {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-secondary);
}
#layers-header-btns { display: flex; gap: 4px; }
#layers-header-btns button {
  width: 28px; height: 28px;
  background: var(--bg-toolbar-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-primary);
  transition: background var(--transition), color var(--transition);
}
#layers-header-btns button:hover { background: var(--bg-active); color: var(--accent); }

#layers-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 0;
}
#layers-panel.collapsed #layers-list { opacity: 0; pointer-events: none; }
#layers-list::-webkit-scrollbar { width: 3px; }
#layers-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.layer-row {
  display: flex;
  flex-direction: column;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
  border-left: 3px solid transparent;
}
.layer-row:hover { background: var(--bg-toolbar-2); }
.layer-row.active { background: var(--bg-active); border-left-color: var(--accent); }
.layer-row.active.locked { border-left-color: #f97316; }

.layer-row-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.layer-drag-handle {
  cursor: grab; color: var(--text-secondary);
  font-size: 14px; padding: 2px; flex-shrink: 0;
  opacity: .45; transition: opacity 150ms;
}
.layer-drag-handle:hover { opacity: 1; }
.layer-drag-handle:active { cursor: grabbing; }

.layer-thumb {
  width: 48px; height: 32px;
  border: 1px solid var(--border);
  border-radius: 4px; flex-shrink: 0;
  background: #fff; display: block;
}
[data-theme="dark"] .layer-thumb { background: #1e1e2e; }

.layer-name {
  flex: 1; font-size: 12px; font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  outline: none; border-radius: 3px; padding: 1px 3px; min-width: 0;
}
.layer-name[contenteditable="true"] {
  background: var(--bg-toolbar-2);
  border: 1px solid var(--accent);
  white-space: normal; overflow: visible;
}

.layer-controls { display: flex; gap: 3px; flex-shrink: 0; }
.layer-btn-vis, .layer-btn-lock {
  width: 24px; height: 24px;
  background: none; border: none; cursor: pointer;
  font-size: 13px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  opacity: .6; transition: opacity 150ms, background 150ms;
}
.layer-btn-vis:hover, .layer-btn-lock:hover { opacity: 1; background: var(--bg-toolbar-2); }
.layer-row.hidden .layer-thumb { opacity: 0.3; }
.layer-row.hidden .layer-name  { opacity: 0.5; }
.layer-row.locked .layer-btn-lock { opacity: 1; color: var(--accent); }

.layer-opacity-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 2px 0;
  max-height: 0; overflow: hidden; opacity: 0;
  transition: opacity 200ms, max-height 200ms;
}
.layer-row.active .layer-opacity-row { max-height: 28px; opacity: 1; }
.layer-opacity-label { font-size: 10px; color: var(--text-secondary); white-space: nowrap; }
.layer-opacity-slider { flex: 1; accent-color: var(--accent); cursor: pointer; }
.layer-opacity-value { font-size: 10px; color: var(--text-secondary); width: 30px; text-align: right; }

/* Drop target indicator when dragging */
.layer-row.drop-target { border-top: 2px solid var(--accent); }

#toggle-layers-panel {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 36px;
  background: none; border: none; border-top: 1px solid var(--border);
  cursor: pointer; color: var(--text-secondary); flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
#toggle-layers-panel:hover { background: var(--bg-toolbar-2); color: var(--accent); }
#layers-panel.collapsed #toggle-layers-panel svg { transform: rotate(180deg); }

/* Locked flash animation */
@keyframes layer-locked-shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-5px); }
  60%      { transform: translateX(5px); }
}
#layers-panel.locked-flash { animation: layer-locked-shake 300ms ease; }

/* Presentation mode: hide layers panel */
body.presentation-mode #layers-panel { display: none; }

/* Mobile: collapse layers panel */
@media (max-width: 600px) {
  #layers-panel { width: 32px; }
  #layers-panel #layers-header, #layers-panel #layers-list { opacity: 0; pointer-events: none; }
}

/* ══════════════════════════════════════════════════════════
   COLOR TOOL BUTTON
══════════════════════════════════════════════════════════ */
#color-tool-icon {
  display: flex; align-items: center; justify-content: center;
}
#color-tool-dot {
  width: 22px; height: 22px; border-radius: 50%;
  background: #222222;
  border: 2px solid rgba(255,255,255,.35);
  box-shadow: 0 0 0 1.5px rgba(0,0,0,.25);
  display: inline-block;
  transition: background 150ms;
}

/* ══════════════════════════════════════════════════════════
   SHAPE PICKER (inside tool modal)
══════════════════════════════════════════════════════════ */
.tmo-shape-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px;
  margin-bottom: 6px;
}
.tmo-shape-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 8px 4px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-toolbar-2); cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
  color: var(--text-primary);
}
.tmo-shape-btn:hover { border-color: var(--accent); background: var(--bg-active); }
.tmo-shape-btn.active {
  border-color: var(--accent); background: var(--bg-active); color: var(--accent);
}
.tmo-shape-icon { font-size: 20px; line-height: 1; }
.tmo-shape-name { font-size: 10px; font-weight: 500; white-space: nowrap; }

/* ══════════════════════════════════════════════════════════
   SIDEBAR COLOR PICKER
══════════════════════════════════════════════════════════ */
#sidebar-color { padding: 4px 6px; }
#sidebar-swatches {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px;
  margin-bottom: 8px;
}
#sidebar-swatches .sb-swatch {
  width: 100%; aspect-ratio: 1; border-radius: 4px; border: 2px solid transparent;
  cursor: pointer; transition: border-color 150ms, transform 150ms;
}
#sidebar-swatches .sb-swatch:hover { transform: scale(1.15); }
#sidebar-swatches .sb-swatch.active { border-color: var(--accent); transform: scale(1.1); }

#sidebar-color-row {
  display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}
#sidebar-color-dot {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border);
  cursor: pointer; flex-shrink: 0; transition: border-color 150ms;
}
#sidebar-color-dot:hover { border-color: var(--accent); }
#sidebar-hex {
  flex: 1; min-width: 0; padding: 4px 6px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--bg-toolbar-2);
  color: var(--text-primary); font-size: 12px; font-family: monospace;
}
#sidebar-hex:focus { border-color: var(--accent); outline: none; }
#sidebar-native-picker { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }

#sidebar-opacity-row {
  display: flex; align-items: center; gap: 6px;
}
.sidebar-range-label { font-size: 10px; color: var(--text-secondary); white-space: nowrap; }
#sidebar-opacity { flex: 1; accent-color: var(--accent); cursor: pointer; }
#sidebar-opacity-val { font-size: 10px; color: var(--text-secondary); width: 30px; text-align: right; }

/* Hide sidebar color details when collapsed */
#sidebar:not(.expanded) #sidebar-color-row,
#sidebar:not(.expanded) #sidebar-opacity-row { display: none; }
#sidebar:not(.expanded) #sidebar-swatches { grid-template-columns: repeat(2, 1fr); }

/* ══════════════════════════════════════════════════════════
   QUICK COLOR BAR (bottom center)
══════════════════════════════════════════════════════════ */
#quick-colors {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; z-index: 60;
  background: var(--bg-toolbar); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 14px;
  box-shadow: var(--shadow);
}
.qc-btn {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid transparent; cursor: pointer;
  transition: transform 150ms, border-color 150ms, box-shadow 150ms;
}
.qc-btn:hover { transform: scale(1.15); }
.qc-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--bg-toolbar), 0 0 0 4px var(--accent);
  transform: scale(1.1);
}
body.presentation-mode #quick-colors { display: none; }

/* ══════════════════════════════════════════════════════════
   USER INDICATOR (status bar)
══════════════════════════════════════════════════════════ */
#user-indicator { margin-left: auto; }
#btn-user {
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 3px 10px; font-size: 12px; cursor: pointer;
  color: var(--text-secondary); transition: background var(--transition), color var(--transition);
}
#btn-user:hover { background: var(--bg-active); color: var(--accent); }
#btn-user.logged-in { color: var(--accent); border-color: var(--accent); }
#btn-logout {
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 3px 10px; font-size: 12px; cursor: pointer;
  color: var(--text-secondary); margin-left: 4px;
  transition: background var(--transition), color var(--transition);
}
#btn-logout:hover { background: rgba(239,68,68,.1); color: #ef4444; border-color: #ef4444; }

/* ══════════════════════════════════════════════════════════
   AUTH MODAL
══════════════════════════════════════════════════════════ */
#auth-overlay, #designs-overlay {
  display: none; position: fixed; inset: 0; z-index: 3000;
  background: rgba(0,0,0,.55); backdrop-filter: blur(3px);
  align-items: center; justify-content: center;
}
#auth-overlay.open, #designs-overlay.open { display: flex; }

#auth-modal, #designs-modal {
  background: var(--bg-toolbar); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-heavy);
  width: min(400px, 92vw); max-height: 85vh;
  display: flex; flex-direction: column; overflow: hidden;
}

#auth-header, #designs-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px; border-bottom: 1px solid var(--border);
}
#auth-title, #designs-title { font-weight: 700; font-size: 15px; }
#auth-close, #designs-close {
  background: none; border: none; cursor: pointer; font-size: 16px;
  color: var(--text-secondary); border-radius: 4px; padding: 2px 6px;
  transition: background var(--transition);
}
#auth-close:hover, #designs-close:hover { background: var(--bg-toolbar-2); color: var(--text-primary); }

#auth-tabs {
  display: flex; border-bottom: 1px solid var(--border); padding: 0 12px;
}
.atab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 9px 16px; cursor: pointer; font-size: 13px; font-weight: 500;
  color: var(--text-secondary); transition: color var(--transition), border-color var(--transition);
  margin-bottom: -1px;
}
.atab:hover { color: var(--text-primary); }
.atab.active { color: var(--accent); border-bottom-color: var(--accent); }

.atab-panel {
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}

#auth-modal input[type="text"],
#auth-modal input[type="password"],
#designs-modal input[type="text"] {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-toolbar-2);
  color: var(--text-primary); font-size: 13px; outline: none;
  transition: border-color var(--transition);
}
#auth-modal input:focus, #designs-modal input:focus { border-color: var(--accent); }

.auth-msg, .designs-msg {
  font-size: 12px; min-height: 16px; padding: 2px 4px; border-radius: 4px;
}
.auth-msg.error, .designs-msg.error { color: #ef4444; }
.auth-msg.success, .designs-msg.success { color: #22c55e; }

.auth-btn-primary, .designs-btn-primary {
  padding: 9px 18px; border-radius: var(--radius-sm); font-size: 13px;
  font-weight: 600; cursor: pointer; border: none;
  background: var(--accent); color: #fff;
  transition: background var(--transition);
}
.auth-btn-primary:hover, .designs-btn-primary:hover { background: var(--accent-hover); }

/* ══════════════════════════════════════════════════════════
   DESIGNS MODAL
══════════════════════════════════════════════════════════ */
#designs-modal { width: min(480px, 94vw); }

#designs-save-row {
  display: flex; gap: 8px; padding: 14px 16px 8px;
}
#designs-save-row input { flex: 1; }

#dsave-msg { padding: 0 16px; }

#dload-list {
  padding: 8px 16px 16px; overflow-y: auto; max-height: 50vh;
  display: flex; flex-direction: column; gap: 6px;
}
.dload-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-toolbar-2);
  cursor: pointer; transition: border-color var(--transition), background var(--transition);
}
.dload-item:hover { border-color: var(--accent); background: var(--bg-active); }
.dload-item-info { flex: 1; min-width: 0; }
.dload-item-name {
  font-weight: 600; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dload-item-meta { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.dload-item-btns { display: flex; gap: 4px; flex-shrink: 0; }
.dload-item-btn {
  background: none; border: 1px solid var(--border); border-radius: 4px;
  font-size: 13px; padding: 3px 7px; cursor: pointer;
  color: var(--text-secondary); transition: background var(--transition), color var(--transition);
}
.dload-item-btn:hover { background: var(--bg-toolbar); color: var(--text-primary); }
.dload-item-btn.danger:hover { color: #ef4444; border-color: #ef4444; }
.dload-empty {
  font-size: 13px; color: var(--text-secondary); text-align: center; padding: 28px 0;
}
