/* ==============================================
   Nanazilla.com — Dark Glassmorphism UI
   ============================================== */

/* --- Design Tokens --- */
:root {
  --bg:          #0f172a;
  --bg-subtle:   #1e293b;
  --surface:     rgba(30, 41, 59, 0.55);
  --surface-hi:  rgba(30, 41, 59, 0.8);
  --glass-blur:  16px;
  --glass-border: rgba(99, 102, 241, 0.12);
  --glass-border-hi: rgba(99, 102, 241, 0.25);
  --text:        #e2e8f0;
  --text-muted:  #94a3b8;
  --text-dim:    #64748b;
  --primary:     #6366f1;
  --primary-hi:  #818cf8;
  --primary-glow: rgba(99, 102, 241, 0.25);
  --danger:      #ef4444;
  --danger-bg:   rgba(239, 68, 68, 0.12);
  --success:     #10b981;
  --canvas-bg:   #ffffff;
  --shadow:      0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-sm:   0 2px 8px rgba(0, 0, 0, 0.2);
  --radius:      10px;
  --radius-lg:   14px;
  --radius-sm:   6px;
  --sidebar-w:   240px;
  --panel-w:     220px;
  --topbar-h:    56px;
  --timeline-h:  120px;
  --transition:  0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
  background-image:
    radial-gradient(ellipse at 15% 85%, rgba(99,102,241,0.06) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 15%, rgba(99,102,241,0.04) 0%, transparent 55%);
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input[type="range"] { cursor: pointer; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Glass utility --- */
.glass {
  background: var(--surface);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
}

/* ======================
   APP SHELL
   ====================== */
.app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--timeline-h);
  height: 100vh;
  gap: 4px;
  padding: 4px 8px;
}

/* --- Top Bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  position: relative;
  z-index: 1000;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.logo-icon {
  width: 34px; height: 34px;
  background: #fff;
  border-radius: 8px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.logo-icon img { width: 36px; height: 36px; }
.brand h1 { font-size: 16px; font-weight: 700; white-space: nowrap; }
.brand .version { font-size: 11px; color: var(--text-dim); margin-left: 6px; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.menu-toggle { display: none !important; }
.separator {
  width: 1px; height: 24px;
  background: var(--glass-border);
  margin: 0 6px;
}

/* ======================
   WORKSPACE (sidebar | canvas | panel)
   ====================== */
.workspace {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 0;
  position: relative;
}

/* --- Sidebar --- */
.sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition), padding var(--transition), opacity var(--transition);
  width: var(--sidebar-w);
  padding: 12px;
}
.sidebar.collapsed {
  width: 0;
  padding: 0;
  border-color: transparent;
  opacity: 0;
  pointer-events: none;
}
.sidebar-toggle {
  position: fixed;
  left: calc(var(--sidebar-w) + 16px);
  top: calc(var(--topbar-h) + 20px);
  z-index: 150;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--surface-hi);
  border: 1px solid var(--glass-border);
  display: grid; place-items: center;
  transition: left var(--transition), transform var(--transition);
}
.sidebar-toggle.shifted {
  left: 16px;
}
.sidebar-toggle svg { width: 14px; height: 14px; transition: transform var(--transition); }
.sidebar-toggle.shifted svg { transform: rotate(180deg); }
.sidebar-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  padding-right: 4px;
}
.sidebar-footer {
  padding: 16px 4px 4px;
  margin-top: 16px;
  border-top: 1px solid var(--glass-border);
  font-size: 10px;
  line-height: 1.5;
  color: var(--text-dim);
  opacity: 0.55;
  text-align: center;
}
.sidebar-footer a {
  color: var(--primary-hi);
  text-decoration: none;
}
.sidebar-footer a:hover {
  text-decoration: underline;
}
.sidebar-divider {
  border: none;
  border-top: 1px solid var(--glass-border);
  margin: 10px 0 6px;
}

/* Canvas Size Modal */
.canvas-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}
.canvas-preset {
  text-align: center;
  transition: all var(--transition);
}
.canvas-preset.active,
.canvas-preset:hover {
  border-color: var(--primary);
  color: var(--primary-hi);
  background: var(--primary-glow);
}
.canvas-size-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.canvas-size-field { flex: 1; }
.canvas-size-field label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.canvas-size-field .text-input {
  width: 100%;
  border-radius: var(--radius-sm);
}
.canvas-size-x {
  color: var(--text-dim);
  font-size: 16px;
  padding-bottom: 6px;
}
.canvas-resize-modes {
  display: flex;
  gap: 12px;
}
.resize-mode-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}
.resize-mode-option input[type="radio"] {
  accent-color: var(--primary);
}
.install-app-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 10px;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: var(--primary);
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.install-app-btn svg {
  width: 14px;
  height: 14px;
}
.install-app-btn:hover {
  background: var(--primary-hi);
}
.tool-section { display: flex; flex-direction: column; gap: 8px; }
.section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.section-label-lcase {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.bigger-font { font-size: 13px !important; }

/* Tool buttons grid */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.tool-btn {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  color: var(--text-muted);
  transition: all var(--transition);
  border: 1px solid transparent;
}
.tool-btn svg { width: 18px; height: 18px; }
.tool-btn:hover {
  background: rgba(99, 102, 241, 0.08);
  color: var(--text);
}
.tool-btn.active {
  background: var(--primary-glow);
  border-color: var(--primary);
  color: var(--primary-hi);
}

/* Controls */
.control-group {
  display: flex; flex-direction: column; gap: 4px;
}
.control-group > label {
  font-size: 11px; color: var(--text-dim); font-weight: 500;
}
.slider-row {
  display: flex; align-items: center; gap: 8px;
}
.slider-row input[type="range"] {
  flex: 1; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: var(--bg-subtle);
  border-radius: 2px;
  outline: none;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg);
  box-shadow: 0 0 6px var(--primary-glow);
  cursor: pointer;
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg);
  box-shadow: 0 0 6px var(--primary-glow);
  cursor: pointer;
}
.val-display {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.color-picker-row {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap;
}
.color-picker-row .hex-input {
  order: -1; width: 100%; flex: none;
}
.color-picker-row input[type="color"], #textColorPicker {
  width: 32px; height: 28px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 2px;
  background: transparent;
  cursor: pointer;
}
.hex-input {
  flex: 1;
  background: var(--bg-subtle);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 12px;
  font-family: 'Inter', monospace;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}
.hex-input:focus { border-color: var(--primary); }

/* --- Easing Dropdown --- */
.easing-dropdown-container { position: relative; }
.easing-dropdown-btn {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 5px 8px; border-radius: var(--radius-sm, 6px);
  background: var(--bg-subtle, rgba(15,23,42,0.6)); border: 1px solid var(--glass-border);
  color: var(--text); font-size: 12px; cursor: pointer;
  transition: border-color var(--transition);
}
.easing-dropdown-btn:hover, .easing-dropdown-btn.open { border-color: var(--primary); }
.easing-dropdown-list {
  display: none; position: absolute; bottom: calc(100% + 4px); left: 0; right: 0;
  max-height: 260px; overflow-y: auto; z-index: 100;
  background: var(--surface-hi, rgba(30,41,59,0.92));
  backdrop-filter: blur(var(--glass-blur)); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm, 6px); padding: 4px 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
}
.easing-group-header {
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); padding: 6px 10px 2px; user-select: none;
}
.easing-dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px; cursor: pointer; font-size: 12px; color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.easing-dropdown-item:hover { background: rgba(99,102,241,0.12); color: var(--text); }
.easing-dropdown-item.active { color: var(--primary); }
.easing-sparkline { flex-shrink: 0; line-height: 0; color: var(--text-dim); }
.easing-dropdown-item:hover .easing-sparkline,
.easing-dropdown-item.active .easing-sparkline { color: var(--primary); }
.easing-dropdown-list::-webkit-scrollbar { width: 4px; }
.easing-dropdown-list::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 2px; }

.color-swatches {
  display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px;
}
.swatch {
  width: 20px; height: 20px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: var(--primary-hi); }

/* --- Eyedropper Button --- */
.eyedropper-btn {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; flex-shrink: 0;
  background: var(--bg-subtle);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.eyedropper-btn:hover { border-color: var(--primary); color: var(--text); }
.eyedropper-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.eyedropper-btn.unsupported {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* --- Recent Colors --- */
.recent-colors-row {
  display: flex; gap: 3px; flex-wrap: wrap; margin-top: 4px;
}
.recent-colors-row:empty { display: none; }
.recent-colors-row .swatch {
  width: 16px; height: 16px;
  border-radius: 3px;
  border: 1.5px solid transparent;
  opacity: 0.85;
}
.recent-colors-row .swatch:hover { opacity: 1; }
.recent-colors-row::before {
  content: 'Recent';
  display: block; width: 100%;
  font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); margin-bottom: 1px;
}

/* --- Eyedropper active cursor overlay --- */
body.eyedropper-active,
body.eyedropper-active * {
  cursor: crosshair !important;
}
.toggle-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
  cursor: pointer;
}
.toggle-label input[type="checkbox"] {
  -webkit-appearance: none; appearance: none;
  width: 32px; height: 18px;
  background: var(--bg-subtle);
  border-radius: 9px;
  position: relative;
  cursor: pointer;
  transition: background var(--transition);
}
.toggle-label input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: all var(--transition);
}
.toggle-label input[type="checkbox"]:checked {
  background: var(--primary);
}
.toggle-label input[type="checkbox"]:checked::after {
  left: 16px;
  background: #fff;
}

/* Entity Mode Slider */
.entity-mode-slider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  cursor: pointer;
  user-select: none;
}
.entity-mode-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  transition: color 0.2s ease;
  min-width: 38px;
}
#entityModeRigLabel { text-align: right; }
#entityModeAnimateLabel { text-align: left; }
.entity-slider-track {
  width: 34px;
  height: 18px;
  background: var(--bg-subtle);
  border: 1px solid var(--glass-border);
  border-radius: 9px;
  position: relative;
  flex-shrink: 0;
  transition: border-color 0.2s ease;
}
.entity-slider-thumb {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  top: 50%;
  transform: translateY(-50%);
  left: 2px;
  transition: left 0.2s ease;
}
/* Rig active state */
.entity-mode-slider[data-mode="rig"] #entityModeRigLabel {
  color: #3b82f6;
}
/* Animate active state */
.entity-mode-slider[data-mode="animate"] .entity-slider-thumb {
  left: 18px;
}
.entity-mode-slider[data-mode="animate"] #entityModeAnimateLabel {
  color: #3b82f6;
}

/* Onion Skin Mode Switcher */
.onion-mode-group {
  margin-top: -2px;
}
.onion-mode-switcher {
  display: flex;
  gap: 2px;
  background: var(--bg-subtle);
  border-radius: 6px;
  padding: 2px;
}
.onion-mode-btn {
  flex: 1;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
}
.onion-mode-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.onion-mode-btn.active {
  color: #fff;
  background: var(--primary);
}

/* ======================
   CANVAS AREA
   ====================== */
.canvas-area {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  gap: 6px;
}
.canvas-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 4px 8px;
  flex-shrink: 0;
}
.action-group {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 3px;
}
.zoom-val {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 38px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: color var(--transition);
}
.zoom-val:hover { color: var(--text); }
.canvas-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: padding var(--transition);
}
.canvas-container {
  position: relative;
  width: var(--canvas-display-w, 100%);
  height: var(--canvas-display-h, 100%);
  max-width: 100%;
  max-height: 100%;
  background: var(--canvas-bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  transition: width var(--transition), height var(--transition);
}
.canvas-container.zoomed {
  max-width: none;
  max-height: none;
  flex-shrink: 0;
}
.canvas-container canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}
#bgCanvas   { z-index: 0; pointer-events: none; }
#gridCanvas { z-index: 1; pointer-events: none; }
#rulerCanvas{ z-index: 2; pointer-events: none; }
#onionCanvas{ z-index: 3; pointer-events: none; }
#selectionCanvas { z-index: 4; pointer-events: none; }
#drawCanvas { z-index: 5; }
#guidelineCanvas { z-index: 6; pointer-events: none; }
#cursorOverlay {
  position: absolute;
  z-index: 7;
  pointer-events: none;
  border: 1.5px solid #fff;
  border-radius: 50%;
  mix-blend-mode: difference;
  box-sizing: border-box;
  display: none;
  will-change: transform;
}
.canvas-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.canvas-hint.hidden { opacity: 0; }
.hint-content { text-align: center; }
.hint-icon { font-size: 36px; margin-bottom: 8px; }
.hint-content h2 { font-size: 18px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.hint-content p { font-size: 11px; color: var(--text-dim); }

/* ======================
   RIGHT PANEL (Layers + Preview)
   ====================== */
.panel-right {
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow: hidden;
  gap: 8px;
  width: var(--panel-w);
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-header h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.layers-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
  flex: 1;
  min-height: 60px;
  max-height: 220px;
}
.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  transition: all var(--transition);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.layer-item:hover { background: rgba(99,102,241,0.06); }
.layer-item.active {
  background: var(--primary-glow);
  border-color: rgba(99,102,241,0.2);
}
.layer-item .layer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.layer-item .layer-actions {
  display: flex; gap: 2px; opacity: 0;
  transition: opacity var(--transition);
}
.layer-item:hover .layer-actions { opacity: 1; }
.layer-item button {
  width: 22px; height: 22px;
  border-radius: 4px;
  display: grid; place-items: center;
  font-size: 12px;
  transition: background var(--transition);
}
.layer-item button:hover { background: rgba(255,255,255,0.08); }
.layer-item button.vis-off { opacity: 0.3; }
.layer-item button:disabled { opacity: 0.2; cursor: default; pointer-events: none; }

/* Layer drag-and-drop */
.layer-drag-handle {
  display: flex;
  align-items: center;
  color: var(--text-dim);
  opacity: 0.3;
  cursor: grab;
  flex-shrink: 0;
  padding: 0 2px;
  transition: opacity var(--transition);
}
.layer-drag-handle svg { pointer-events: none; }
.layer-item:hover .layer-drag-handle { opacity: 0.7; }
.layer-drag-handle:active { cursor: grabbing; }
.layer-item.layer-dragging {
  opacity: 0.4;
}
.layer-item.layer-drag-over-top {
  box-shadow: inset 0 2px 0 0 var(--primary);
}
.layer-item.layer-drag-over-bottom {
  box-shadow: inset 0 -2px 0 0 var(--primary);
}

.layer-flip-btns {
  display: flex; gap: 2px; margin-left: auto; margin-right: 4px;
}
.btn-flip {
  width: 22px; height: 22px; padding: 3px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition);
  display: grid; place-items: center;
}
.btn-flip:hover { color: var(--text); background: rgba(99,102,241,0.12); }
.btn-flip.active { color: var(--primary); border-color: var(--primary); background: rgba(99,102,241,0.15); }
.layer-type-icon {
  font-size: 10px;
  font-weight: 700;
  opacity: 0.6;
  margin-right: 2px;
  flex-shrink: 0;
  color: var(--primary-hi);
  background: var(--primary-glow);
  padding: 1px 4px;
  border-radius: 3px;
  letter-spacing: 0.03em;
}
.preview-canvas {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
  background: var(--canvas-bg);
  aspect-ratio: var(--canvas-aspect, 16/9);
}
.panel-right.hidden {
  display: none;
}

/* ======================
   TIMELINE
   ====================== */
.timeline {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  overflow: hidden;
  position: relative;
}

/* --- Desktop Timeline Grid (> 768px) --- */
@media (min-width: 769px) {
  .timeline {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 2px 8px;
    padding: 4px 10px;
    padding-top: 20px;
    overflow: visible;
    position: relative;
  }
  .timeline-controls {
    grid-row: 1;
    grid-column: 1;
    justify-self: start;
  }
  .timeline-actions {
    grid-row: 1;
    grid-column: 2;
    justify-self: end;
  }
  .timeline-frames {
    grid-row: 2;
    grid-column: 1 / -1;
    padding: 2px 0;
  }
  /* Canvas-wrap is an overlay drawer that slides up from the timeline */
  .timeline-canvas-wrap {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    height: 150px;
    z-index: 10;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.35);
    transition: transform var(--transition), opacity var(--transition);
    transform: translateY(0);
    opacity: 1;
  }
  /* Collapsed state — only hide canvas-wrap, keep frames visible */
  .timeline.collapsed .timeline-canvas-wrap {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
  }
  .timeline.collapsed {
    padding-top: 4px;
  }
}

/* Collapse toggle button */
.timeline-collapse-btn {
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  z-index: 5;
  transition: all var(--transition);
  padding: 0;
}
.timeline-collapse-btn svg {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  transition: transform var(--transition);
}
.timeline-collapse-btn:hover {
  border-color: var(--primary);
}
.timeline-collapse-btn:hover svg {
  color: var(--primary-hi);
}
.timeline.collapsed .timeline-collapse-btn svg {
  transform: rotate(180deg);
}
.timeline-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.btn-play {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: grid; place-items: center;
  transition: all var(--transition);
  box-shadow: 0 0 12px var(--primary-glow);
}
.btn-play:hover { background: var(--primary-hi); transform: scale(1.05); }
.btn-play.playing { background: var(--danger); box-shadow: 0 0 12px rgba(239,68,68,0.25); }
.btn-play svg { width: 14px; height: 14px; color: #fff; }
.frame-counter {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: center;
  margin-left: 4px;
}
.timeline-frames {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  flex: 1;
  padding: 2px 0;
  scroll-behavior: smooth;
}
.timeline-thumb {
  flex-shrink: 0;
  width: 72px; height: 44px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  background: var(--bg-subtle);
}
.timeline-thumb canvas {
  width: 100%; height: 100%;
  display: block;
}
.timeline-thumb:hover { border-color: var(--text-dim); }
.timeline-thumb.active { border-color: var(--primary); box-shadow: 0 0 8px var(--primary-glow); }
.timeline-thumb .thumb-label {
  position: absolute;
  bottom: 2px; left: 0; right: 0;
  text-align: center;
  font-size: 9px;
  color: var(--text-muted);
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}
.thumb-dur-badge {
  position: absolute;
  top: 2px; right: 2px;
  padding: 0 3px;
  height: 14px;
  font-size: 8px;
  font-family: inherit;
  font-weight: 600;
  line-height: 14px;
  text-align: center;
  color: var(--text);
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--glass-border);
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}
.thumb-dur-badge:hover,
.thumb-dur-badge.popover-open {
  background: rgba(0,0,0,0.7);
  border-color: var(--primary);
}
.timeline-thumb.thumb-hidden { opacity: 0.35; }
.timeline-thumb.thumb-hidden .thumb-label::after {
  content: ' (hidden)';
  color: var(--danger);
}

/* --- Frame Settings Popover --- */
.frame-settings-popover {
  position: fixed; z-index: 200; min-width: 200px; padding: 12px;
  background: var(--surface-hi, rgba(30,41,59,0.95));
  backdrop-filter: blur(var(--glass-blur)); border: 1px solid var(--glass-border);
  border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.frame-pop-header {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); margin-bottom: 10px;
}
.frame-pop-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.frame-pop-row:last-child { margin-bottom: 0; }
.frame-pop-row label {
  font-size: 11px; color: var(--text-dim); min-width: 52px;
}
.frame-dur-input {
  width: 60px; padding: 3px 6px; font-size: 11px;
  background: var(--bg-subtle, rgba(15,23,42,0.6)); border: 1px solid var(--glass-border);
  border-radius: 4px; color: var(--text); outline: none; font-family: inherit;
}
.frame-dur-input:focus { border-color: var(--primary); }
.frame-dur-unit { font-size: 10px; color: var(--text-dim); }
.frame-hide-toggle {
  position: relative;
  width: 32px; height: 16px;
  background: var(--bg-subtle, rgba(15,23,42,0.6));
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.frame-hide-toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform var(--transition), background var(--transition);
}
.frame-hide-toggle.active {
  background: var(--primary-glow);
  border-color: var(--primary);
}
.frame-hide-toggle.active::after {
  transform: translateX(16px);
  background: var(--primary);
}
.frame-pop-divider {
  height: 1px;
  background: var(--glass-border);
  margin: 10px 0;
}
.tween-controls {
  overflow: hidden;
  max-height: 200px;
  opacity: 1;
  transition: max-height 0.2s ease, opacity 0.15s ease;
}
.tween-controls-hidden {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}
.tween-easing-sel {
  flex: 1;
  padding: 3px 6px;
  font-size: 11px;
  background: var(--bg-subtle, rgba(15,23,42,0.6));
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  color: var(--text);
  outline: none;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 18px;
}
.tween-easing-sel:focus {
  border-color: var(--primary);
}
.timeline-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* --- Multi-Frame Drawing Controls --- */
.multi-frame-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 4px;
}
.multi-frame-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  user-select: none;
}
.multi-frame-toggle input[type="checkbox"] {
  accent-color: var(--primary);
  width: 13px;
  height: 13px;
  cursor: pointer;
}
.multi-frame-toggle input[type="checkbox"]:checked + span {
  color: var(--primary-hi);
}
.multi-frame-range {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.multi-frame-input {
  width: 42px;
  padding: 2px 4px;
  font-size: 11px;
  text-align: center;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  color: var(--text);
  outline: none;
}
.multi-frame-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.multi-frame-dash {
  color: var(--text-dim);
  font-size: 11px;
}

/* Canvas multi-frame active indicator */
.canvas-viewport.multi-frame-active {
  box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.5);
}

/* Floating multi-frame indicator badge */
.multi-frame-indicator {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: rgba(59, 130, 246, 0.8);
  border-radius: 10px;
  backdrop-filter: blur(4px);
  pointer-events: none;
  animation: multiFramePulse 2s ease-in-out infinite;
  white-space: nowrap;
}
@keyframes multiFramePulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

/* --- Transition Indicator (between timeline frames) --- */
.transition-indicator {
  display: flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; flex-shrink: 0; align-self: center;
  border-radius: 50%; border: 1.5px dashed var(--text-dim);
  background: transparent; color: var(--text-dim);
  cursor: pointer; transition: all var(--transition);
  margin: 0 -2px;
}
.transition-indicator:hover { border-color: var(--primary); color: var(--primary); background: rgba(99,102,241,0.1); }
.transition-indicator.active {
  border-style: solid; border-color: var(--primary); color: var(--primary);
  background: rgba(99,102,241,0.15);
}

/* --- Transition Popover --- */
.transition-popover {
  position: fixed; z-index: 200; min-width: 360px; max-width: 400px; padding: 12px;
  background: var(--surface-hi, rgba(30,41,59,0.95));
  backdrop-filter: blur(var(--glass-blur)); border: 1px solid var(--glass-border);
  border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.trans-pop-header {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); margin-bottom: 8px;
}
.trans-types-wrap {
  max-height: 320px; overflow-y: auto; margin-bottom: 10px;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.trans-types-wrap::-webkit-scrollbar { width: 4px; }
.trans-types-wrap::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
.trans-category { margin-bottom: 8px; }
.trans-cat-label {
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); margin-bottom: 4px; padding-left: 2px;
}
.trans-cat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 4px;
}
.trans-types-row {
  display: flex; gap: 4px; margin-bottom: 10px;
}
.trans-type-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px; border-radius: var(--radius-sm, 6px);
  border: 1px solid transparent; background: rgba(255,255,255,0.04);
  color: var(--text-muted); cursor: pointer; font-size: 8px;
  transition: all var(--transition); min-width: 0;
}
.trans-type-btn:hover { background: rgba(99,102,241,0.1); color: var(--text); }
.trans-type-btn.active { border-color: var(--primary); color: var(--primary); background: rgba(99,102,241,0.15); }
.trans-type-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; display: block; text-align: center; }
.trans-preview-cvs { border-radius: 3px; background: rgba(0,0,0,0.2); display: block; }
.trans-none-icon { width: 40px; height: 30px; display: flex; align-items: center; justify-content: center; opacity: 0.5; }
.trans-pop-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.trans-pop-row label {
  font-size: 11px; color: var(--text-dim); min-width: 52px;
}
.trans-dur-input {
  width: 60px; padding: 3px 6px; font-size: 11px;
  background: var(--bg-subtle, rgba(15,23,42,0.6)); border: 1px solid var(--glass-border);
  border-radius: 4px; color: var(--text); outline: none; font-family: inherit;
}
.trans-dur-input:focus { border-color: var(--primary); }
.trans-dur-unit { font-size: 10px; color: var(--text-dim); }
.trans-easing-sel {
  flex: 1; padding: 3px 6px; font-size: 11px;
  background: var(--bg-subtle, rgba(15,23,42,0.6)); border: 1px solid var(--glass-border);
  border-radius: 4px; color: var(--text); outline: none; font-family: inherit;
}
.trans-easing-sel:focus { border-color: var(--primary); }

/* ======================
   BUTTONS
   ====================== */
.btn-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  transition: all var(--transition);
  color: var(--text-muted);
}
.btn-icon:hover { background: rgba(99,102,241,0.1); color: var(--text); }
.btn-icon.active { color: var(--primary-hi); background: var(--primary-glow); }
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon.sm { width: 30px; height: 30px; }
.btn-icon.sm svg { width: 15px; height: 15px; }
.btn-icon.xs { width: 24px; height: 24px; font-size: 14px; font-weight: 600; }
.btn-sm {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-hi);
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  transition: all var(--transition);
}
.btn-sm:hover { background: rgba(99,102,241,0.12); color: var(--text); border-color: var(--glass-border-hi); }
.btn-sm.danger { color: var(--danger); }
.btn-sm.danger:hover { background: var(--danger-bg); }

  /* Reset button: destructive action warning */
  #resetBtn {
    color: #dc3545;
  }
  #resetBtn:hover {
    background: rgba(220, 53, 69, 0.15);
    color: #dc3545;
  }

/* ======================
   MODALS
   ====================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface-hi);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border-hi);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-width: 340px;
  max-width: 90vw;
  box-shadow: var(--shadow);
  transform: scale(0.95) translateY(8px);
  transition: transform 0.25s ease;
}
.modal-overlay.open .modal { transform: scale(1) translateY(0); }
.modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.modal p { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.5; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px;
}
.btn-secondary {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--glass-border);
  font-size: 13px; font-weight: 600;
  color: var(--text-muted);
  transition: all var(--transition);
}
.btn-secondary:hover { color: var(--text); background: var(--surface); }
.btn-danger {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--danger);
  font-size: 13px; font-weight: 600;
  color: #fff;
  transition: all var(--transition);
}
.btn-danger:hover { background: #dc2626; }
.btn-primary {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  font-size: 13px; font-weight: 600;
  color: #fff;
  transition: all var(--transition);
}
.btn-primary:hover { background: var(--primary-hi); }

/* --- License Key / Premium Export --- */
.license-key-section {
  margin-bottom: 4px;
}
.license-key-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.license-key-group {
  display: flex;
  align-items: center;
  gap: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: rgba(15, 23, 42, 0.5);
  transition: border-color var(--transition);
}
.license-key-group:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
.license-key-input {
  flex: 1;
  padding: 8px 10px;
  font-size: 13px;
  font-family: 'Inter', system-ui, sans-serif;
  background: transparent;
  border: none;
  color: var(--text);
  outline: none;
}
.license-key-input::placeholder {
  color: var(--text-dim);
  opacity: 0.6;
}
.license-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--transition);
}
.license-toggle-btn:hover {
  color: var(--text);
}
.license-toggle-btn svg {
  width: 16px;
  height: 16px;
}
.export-status {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 600;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.export-status.watermarked {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
}
.export-status.premium {
  color: #34d399;
  background: rgba(52, 211, 153, 0.12);
}

/* Export modal grid */
.export-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.export-card {
  display: flex; flex-direction: column;
  align-items: center; gap: 6px;
  padding: 16px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
  background: rgba(15,23,42,0.4);
  transition: all var(--transition);
  text-align: center;
}
.export-card:hover {
  border-color: var(--primary);
  background: var(--primary-glow);
}
.export-icon {
  font-size: 14px;
  font-weight: 800;
  color: var(--primary-hi);
  background: var(--primary-glow);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.04em;
}
.export-card span { font-size: 12px; font-weight: 600; }
.export-card small { font-size: 10px; color: var(--text-dim); }
.export-recommended {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--primary);
  color: #fff;
  padding: 1px 5px;
  border-radius: 3px;
  vertical-align: middle;
  margin-left: 4px;
}

/* WebP settings modal */
.webp-settings { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 13px; font-weight: 500; color: var(--text);
}
.setting-row select {
  padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border);
  background: rgba(15,23,42,0.6); color: var(--text); font-size: 12px; font-family: inherit;
}
.setting-range { display: flex; align-items: center; gap: 8px; }
.setting-range input[type="range"] { width: 120px; }
.setting-range span { min-width: 24px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; }
.setting-range input[type="number"] {
  padding: 4px 6px; border-radius: 5px; border: 1px solid var(--border);
  background: rgba(15,23,42,0.6); color: var(--text); font-size: 12px; font-family: inherit;
}

/* WebP progress bar */
.webp-progress-wrap {
  width: 100%; height: 8px; border-radius: 4px;
  background: rgba(255,255,255,0.08); overflow: hidden; margin-top: 12px;
}
.webp-progress-bar {
  height: 100%; width: 0%; border-radius: 4px;
  background: var(--primary);
  transition: width 0.15s ease;
}

/* Save As modal */
.save-form { margin-top: 12px; }
.save-input-row {
  display: flex; align-items: center; gap: 0; margin-top: 6px;
}
.text-input {
  flex: 1;
  padding: 8px 12px;
  font-size: 13px; font-family: inherit; font-weight: 500;
  color: var(--text);
  background: rgba(15,23,42,0.6);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  outline: none;
  transition: border-color var(--transition);
}
.text-input:focus { border-color: var(--primary); }
.save-ext {
  padding: 8px 10px;
  font-size: 13px; font-weight: 600;
  color: var(--text-dim);
  background: rgba(15,23,42,0.8);
  border: 1px solid var(--glass-border);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Template gallery */
.template-gallery-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.template-gallery-header h4 { font-size: 13px; font-weight: 600; margin: 0; }
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}
.template-card {
  display: flex; flex-direction: column;
  align-items: center; gap: 6px;
  padding: 10px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
  background: rgba(15,23,42,0.4);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}
.template-card:hover {
  border-color: var(--primary);
  background: var(--primary-glow);
}
.template-card img {
  width: 80px; height: 80px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.2);
  image-rendering: pixelated;
}
.template-card span { font-size: 11px; font-weight: 600; color: var(--text); }
.template-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: var(--text-dim);
}

/* Asset library categories */
.asset-categories { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }
.asset-cat-btn {
  padding: 4px 10px; border-radius: 12px; font-size: 11px;
  border: 1px solid var(--glass-border); background: transparent;
  color: var(--text-muted); cursor: pointer; transition: all var(--transition);
}
.asset-cat-btn.active, .asset-cat-btn:hover {
  background: var(--primary); color: white; border-color: var(--primary);
}
.asset-info { font-size: 11px; color: var(--text-muted); padding: 0 0 6px; }
.template-card .asset-frames {
  font-size: 9px; color: var(--text-dim); font-weight: 400;
}
.sound-card svg { color: var(--primary); margin-bottom: 4px; }
.sound-card:hover svg { color: #fff; }
#muteToggleBtn.muted { color: var(--danger); border-color: var(--danger); }
.select-sm {
  padding: 4px 8px; width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--bg-subtle);
  color: var(--text);
  font-size: 12px;
}

/* Shortcuts modal */
.modal.wide { min-width: 480px; }
.shortcuts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 24px;
  margin-top: 12px;
}
.shortcut-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
}
.shortcut-key {
  background: var(--bg-subtle);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  font-family: 'Inter', monospace;
  color: var(--text-muted);
  border: 1px solid var(--glass-border);
}
.shortcut-desc { color: var(--text-muted); }

/* ======================
   NOTIFICATIONS
   ====================== */
.notification {
  position: fixed;
  top: 16px; right: 16px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 600;
  z-index: 2000;
  box-shadow: var(--shadow);
  animation: notifIn 0.3s ease, notifOut 0.3s ease 1.7s forwards;
  color: #fff;
}
.notification.success { background: var(--success); }
.notification.error { background: var(--danger); }

@keyframes notifIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes notifOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-10px); }
}

/* ======================
   TIMELINE PRO (Canvas-based)
   ====================== */
.timeline-canvas-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: rgba(15, 23, 42, 0.6);
}
.timeline-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}


/* ======================
   ZEN MODE
   ====================== */

/* --- Floating Zen Triggers --- */
.zen-trigger {
  display: none;
  position: fixed;
  z-index: 1700;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  color: var(--text-muted);
  cursor: pointer;
  place-items: center;
  opacity: 0.4;
  pointer-events: auto;
  transition: opacity 0.25s ease, transform 0.2s ease, background 0.25s ease,
              box-shadow 0.25s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.zen-trigger svg { width: 16px; height: 16px; pointer-events: none; }
.zen-trigger:hover,
.zen-trigger:active {
  opacity: 1;
  background: var(--surface-hi);
  box-shadow: 0 0 12px var(--primary-glow), 0 2px 8px rgba(0, 0, 0, 0.3);
  transform: scale(1.1);
}
.zen-trigger.active {
  opacity: 0.9;
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-hi);
  box-shadow: 0 0 16px var(--primary-glow);
}
/* Positioning: anchored to edges, outside canvas area */
.zen-trigger-top    { top: 6px;    left: 50%;  transform: translateX(-50%); }
.zen-trigger-top:hover,
.zen-trigger-top:active { transform: translateX(-50%) scale(1.1); }
.zen-trigger-top.active { transform: translateX(-50%); }

.zen-trigger-left   { left: 6px;   top: 50%;   transform: translateY(-50%); }
.zen-trigger-left:hover,
.zen-trigger-left:active { transform: translateY(-50%) scale(1.1); }
.zen-trigger-left.active { transform: translateY(-50%); }

.zen-trigger-right  { right: 6px;  top: 50%;   transform: translateY(-50%); }
.zen-trigger-right:hover,
.zen-trigger-right:active { transform: translateY(-50%) scale(1.1); }
.zen-trigger-right.active { transform: translateY(-50%); }

.zen-trigger-bottom { bottom: 6px; left: 50%;  transform: translateX(-50%); }
.zen-trigger-bottom:hover,
.zen-trigger-bottom:active { transform: translateX(-50%) scale(1.1); }
.zen-trigger-bottom.active { transform: translateX(-50%); }

/* Zen mode active */
.app.zen-mode { grid-template-rows: 0 1fr 0; gap: 0; padding: 0; }
.app.zen-mode .zen-trigger { display: grid; }

/* Collapse workspace grid to single column so canvas-area fills the viewport */
.app.zen-mode .workspace {
  grid-template-columns: 1fr;
}
.app.zen-mode .topbar {
  opacity: 0; pointer-events: none; height: 0; min-height: 0;
  overflow: hidden; padding: 0; border: none;
  transition: opacity 0.3s ease, height 0.3s ease;
  will-change: opacity, height;
}
.app.zen-mode .sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 0; padding: 0; opacity: 0; pointer-events: none;
  border: none; overflow: hidden;
  transition: width 0.25s ease, padding 0.25s ease, opacity 0.2s ease;
  will-change: width, opacity;
}
.app.zen-mode .sidebar-toggle { display: none; }
.app.zen-mode .panel-right {
  position: fixed; top: 0; right: 0; bottom: 0;
  display: none;
}
.app.zen-mode .timeline {
  height: 0; min-height: 0; padding: 0; opacity: 0;
  pointer-events: none; border: none; overflow: hidden;
  transition: opacity 0.3s ease, height 0.3s ease;
  will-change: opacity, height;
}
.app.zen-mode .timeline .timeline-collapse-btn {
  pointer-events: auto;
}
.app.zen-mode .canvas-actions {
  /* Reposition to bottom-right as vertical floating bar */
  position: fixed;
  bottom: 14px;
  right: 14px;
  z-index: 1650;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: rgba(30, 41, 59, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  opacity: 0.5;
  transition: opacity 0.25s ease;
  pointer-events: auto;
}
.app.zen-mode .canvas-actions:hover { opacity: 1; }
.app.zen-mode .canvas-actions .action-group {
  flex-direction: column;
  gap: 2px;
}
.app.zen-mode .canvas-actions .zoom-val {
  font-size: 10px;
  min-width: auto;
}
.app.zen-mode .menu-toggle { display: none !important; }
.app.zen-mode .topbar-actions {
  margin-left: auto;
  display: flex !important;
  position: static;
  width: auto;
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  flex-direction: row;
}
.app.zen-mode .canvas-viewport { border-radius: 0; border: none; background: var(--bg); }

/* Panel reveals (triggered by zen-show-* classes) */
.app.zen-mode.zen-show-top .topbar {
  opacity: 1; pointer-events: auto; height: var(--topbar-h);
  padding: 0 16px;
  position: fixed; top: 0; left: 0; right: 0; z-index: 1600;
  border-radius: 0;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.app.zen-mode.zen-show-top .zen-trigger-top { top: calc(var(--topbar-h) + 6px); }

.app.zen-mode.zen-show-left .sidebar {
  width: var(--sidebar-w); padding: 12px; opacity: 1; pointer-events: auto;
  z-index: 1600;
  border-radius: 0; overflow-y: auto;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.app.zen-mode.zen-show-left .zen-trigger-left { left: calc(var(--sidebar-w) + 6px); }

.app.zen-mode.zen-show-right .panel-right {
  display: flex;
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 1600;
  border-radius: 0;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.app.zen-mode.zen-show-right .zen-trigger-right { right: calc(var(--panel-w) + 6px); }
.app.zen-mode.zen-show-right .canvas-actions { right: calc(var(--panel-w) + 14px); }

.app.zen-mode.zen-show-bottom .timeline {
  opacity: 1; pointer-events: auto; height: var(--timeline-h);
  padding: 10px 14px;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1600;
  border-radius: 0;
  overflow: visible;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.app.zen-mode.zen-show-bottom .zen-trigger-bottom { bottom: calc(var(--timeline-h) + 6px); }
.app.zen-mode.zen-show-bottom .canvas-actions { bottom: calc(var(--timeline-h) + 14px); }

.app.zen-mode.zen-show-bottom .timeline .timeline-canvas-wrap {
  z-index: 1601;
  pointer-events: auto;
}
.app.zen-mode.zen-show-bottom .timeline .timeline-collapse-btn {
  z-index: 1602;
  pointer-events: auto;
}

/* ======================
   GRADIENT BACKGROUND PANEL
   ====================== */
.gradient-panel {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
  padding: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
}
.gradient-settings.active .gradient-panel { display: flex; }
.gradient-preview {
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: linear-gradient(135deg, #6366f1 0%, #0f172a 100%);
}
.gradient-type-row {
  display: flex; gap: 4px;
}
.gradient-type-btn {
  flex: 1;
  font-size: 11px;
  padding: 4px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border) !important;
  background: transparent !important;
  color: var(--text-muted);
  transition: all var(--transition);
}
.gradient-type-btn.active {
  background: var(--primary-glow) !important;
  border-color: var(--primary) !important;
  color: var(--text);
}
.gradient-angle-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.gradient-angle-row label { font-size: 11px; color: var(--text-muted); min-width: 32px; }
.gradient-angle-row input[type="range"] { flex: 1; }
.gradient-stops { display: flex; flex-direction: column; gap: 6px; }
.gradient-stop-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.gradient-stop-row input[type="color"] {
  width: 28px; height: 28px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 1px;
  cursor: pointer;
  background: transparent;
}
.gradient-stop-row input[type="range"] { flex: 1; }
.gradient-stop-row .val-display { min-width: 32px; text-align: right; }
.gradient-stop-row .remove-stop {
  width: 20px; height: 20px;
  display: grid; place-items: center;
  font-size: 14px; color: var(--danger);
  border-radius: 50%;
  transition: background var(--transition);
}
.gradient-stop-row .remove-stop:hover { background: var(--danger-bg); }

/* ======================
   IMAGE BACKGROUND PANEL
   ====================== */
.bg-image-panel {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
  padding: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
}
.bg-image-settings.active .bg-image-panel { display: flex; }
.bg-image-preview {
  position: relative;
  height: 64px;
  border-radius: var(--radius-sm);
  border: 2px dashed var(--glass-border);
  display: grid;
  place-items: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color var(--transition);
}
.bg-image-preview:hover,
.bg-image-preview.drag-over { border-color: var(--primary); }
.bg-image-placeholder {
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: none;
}
.bg-image-fit-row { display: flex; align-items: center; gap: 6px; }
.bg-image-fit-row label { font-size: 11px; color: var(--text-muted); min-width: 24px; }
.bg-image-fit-select {
  flex: 1;
  font-size: 11px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--bg-subtle);
  color: var(--text);
  cursor: pointer;
  outline: none;
}
.bg-image-fit-select:focus { border-color: var(--primary); }
.bg-image-opacity-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.bg-image-opacity-row label { font-size: 11px; color: var(--text-muted); min-width: 42px; }
.bg-image-opacity-row input[type="range"] { flex: 1; }

/* ======================
   RESPONSIVE
   ====================== */

/* --- Tablet (<= 1100px) --- */
@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  /* Sidebar → fixed overlay */
  .sidebar {
    position: fixed;
    top: calc(var(--topbar-h) + 16px);
    left: 8px;
    bottom: calc(var(--timeline-h) + 16px);
    z-index: 100;
    width: var(--sidebar-w);
    box-shadow: var(--shadow);
    background: var(--surface-hi);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    transition: transform var(--transition), opacity var(--transition);
  }
  .sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-w) - 20px));
    opacity: 0;
    pointer-events: none;
    width: var(--sidebar-w); /* keep width, just slide off */
  }
  .sidebar-toggle {
    left: calc(var(--sidebar-w) + 16px);
    top: calc(var(--topbar-h) + 16px);
  }
  .sidebar-toggle.shifted {
    left: 8px;
  }

  /* Panel → fixed overlay */
  .panel-right {
    position: fixed;
    top: calc(var(--topbar-h) + 16px);
    right: 8px;
    bottom: calc(var(--timeline-h) + 16px);
    z-index: 100;
    width: var(--panel-w);
    box-shadow: var(--shadow);
    background: var(--surface-hi);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    transition: transform var(--transition), opacity var(--transition);
  }
  .panel-right.hidden {
    transform: translateX(calc(var(--panel-w) + 20px));
    opacity: 0;
    pointer-events: none;
    display: flex; /* override desktop display:none */
  }

  /* Topbar wraps on tablet */
  .topbar {
    flex-wrap: wrap;
    padding: 0 12px;
    gap: 8px;
  }
  .topbar-actions {
    flex-wrap: wrap;
    gap: 2px;
  }
}

/* --- Tablet-small / Navigation breakpoint (<= 768px) --- */
@media (max-width: 768px) {
  /* Hamburger toggle — visible below 768px */
  .menu-toggle {
    display: grid !important; place-items: center;
    width: 36px; height: 36px;
    margin-left: auto;
  }
  .separator { display: none; }

  /* Topbar actions — hidden by default, dropdown when open */
  .topbar-actions {
    display: none;
    position: fixed;
    top: var(--topbar-h);
    right: 4px;
    width: 200px;
    flex-direction: column;
    flex-wrap: nowrap;
    padding: 8px;
    gap: 2px;
    background: var(--bg-subtle);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 9999;
  }
  .topbar-actions.open { display: flex; }

  /* Menu items: icon + label row */
  .topbar-actions .btn-icon {
    width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-start;
  }
  .topbar-actions .btn-icon svg { width: 18px; height: 18px; flex-shrink: 0; }
  .topbar-actions .btn-icon::after {
    content: attr(data-label);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
  }
  .topbar-actions .btn-icon:hover {
    background: var(--primary-glow);
  }
}

/* --- Mobile (<= 640px): Viewport-Locked Single-Screen Layout --- */
@media (max-width: 640px) {
  :root {
    --sidebar-w: 240px;
    --panel-w: 220px;
    --topbar-h: 48px;
    --timeline-h: auto;
  }

  /* --- Viewport lock: kill ALL document scroll & pull-to-refresh --- */
  html {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;           /* Chrome/Android pull-to-refresh off */
  }
  body {
    height: 100%;
    overflow: hidden;                    /* was: overflow-y: auto */
    overscroll-behavior: none;           /* belt-and-suspenders for older Android */
    -webkit-overflow-scrolling: auto;    /* disable iOS momentum scroll on body */
  }

  /* --- App shell: hard-locked to the visible viewport --- */
  .app {
    padding: 4px;
    gap: 4px;
    height: 100vh;                       /* fallback for browsers without dvh */
    height: 100dvh;                      /* dvh = Dynamic Viewport Height (iOS 15.4+, Chrome 108+) */
    min-height: unset;                   /* remove old min-height: 100vh */
    grid-template-rows: var(--topbar-h) 1fr auto;
    /* row 1: topbar (fixed px)
       row 2: canvas area (greedy — fills all remaining space)
       row 3: timeline (auto-height, collapsed by default on mobile) */
    overflow: hidden;
  }

  /* Flatten workspace so children participate in .app grid directly */
  .workspace {
    display: contents;
  }

  /* Lock a single full-width column so display:contents children (sidebar,
     sidebar-toggle, panel-right — even when position:fixed) can't create
     implicit columns that nudge topbar/canvas-area/timeline off-center. */
  .app {
    grid-template-columns: minmax(0, 1fr);
  }
  .app > .topbar,
  .app > .timeline,
  .canvas-area {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    margin-inline: 0;
  }

  /* Canvas area: fill row 2 without overflowing — no fixed min-height */
  .canvas-area {
    grid-row: 2;
    min-height: 0;                       /* was: 65vh — let grid control height */
    overflow: hidden;
  }

  /* Canvas viewport: fill the entire .canvas-area cell */
  .canvas-viewport {
    touch-action: none;                  /* CSS-level: suppress browser pan/pinch-zoom */
    height: 100%;
    width: 100%;
  }

  /* All stacked canvases: no browser touch handling whatsoever */
  #drawCanvas,
  #bgCanvas,
  #gridCanvas,
  #rulerCanvas,
  #guidelineCanvas,
  #onionCanvas,
  #selectionCanvas,
  #cursorOverlay {
    touch-action: none;
  }

  .topbar {
    padding: 0 8px;
    gap: 6px;
    position: relative;
  }
  .brand h1 { font-size: 13px; }
  .brand .version { display: none; }
  .logo-icon { width: 28px; height: 28px; }
  .logo-icon svg { width: 14px; height: 14px; }

  /* Canvas actions compact */
  .canvas-actions { gap: 6px; padding: 2px 4px 2px 40px; }
  .action-group { padding: 2px; }
  .btn-icon.sm { width: 26px; height: 26px; }
  .btn-icon.sm svg { width: 13px; height: 13px; }

  /* Timeline compact */
  .timeline {
    padding: 16px 6px 3px;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
    min-height: 44px;
  }
  .timeline-controls { gap: 2px; }
  .btn-play { width: 28px; height: 28px; }
  .btn-play svg { width: 12px; height: 12px; }
  .timeline-thumb { width: 48px; height: 30px; }
  .timeline-actions { gap: 2px; }
  .btn-sm { padding: 3px 6px; font-size: 10px; }
  .frame-counter { font-size: 10px; min-width: 32px; }

  /* Modals full-width */
  .modal { min-width: 0; width: 95vw; padding: 16px; }
  .modal.wide { min-width: 0; }
  .shortcuts-grid { grid-template-columns: 1fr; }
  .export-options { grid-template-columns: 1fr; }

  /* Sidebar stays as fixed overlay */
  .sidebar {
    top: calc(var(--topbar-h) + 8px);
    bottom: 90px;
    left: 4px;
  }
  .sidebar-toggle {
    top: calc(var(--topbar-h) + 8px);
  }
  .sidebar-toggle.shifted { left: 4px; }

  /* Panel-right: fixed overlay (mirrors sidebar pattern) — OUT of grid flow.
     This prevents it from adding a 4th row that would push .app past 100dvh. */
  .panel-right {
    position: fixed !important;
    top: calc(var(--topbar-h) + 8px) !important;
    right: 4px !important;
    bottom: 90px !important;
    width: var(--panel-w) !important;
    max-height: none !important;
    border-radius: var(--radius-lg);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;   /* smooth layer-list scroll on iOS */
    z-index: 800;
    /* visual style preserved — glass effect still applies from base class */
  }
  .panel-right.hidden {
    display: none !important;
  }
}

/* --- Mobile (<= 768px): vertical timeline stack --- */
@media (max-width: 768px) {
  .timeline {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 16px 8px 4px;
    min-height: auto;
    overflow: visible;
    position: relative;
  }

  .timeline-controls {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    flex-wrap: nowrap;
  }
  .timeline-controls .btn-play {
    width: 40px;
    height: 40px;
  }
  .timeline-controls .btn-play svg {
    width: 16px;
    height: 16px;
  }
  .timeline-controls .btn-icon {
    min-width: 40px;
    min-height: 40px;
  }
  .frame-counter {
    font-size: 11px;
    min-width: auto;
  }

  .timeline-canvas-wrap {
    flex: none;
    width: 100%;
    aspect-ratio: 16 / 9;
    min-height: 0;
    max-height: 100px;
    transition: max-height var(--transition), opacity var(--transition);
  }

  .timeline-frames {
    flex: none;
    width: 100%;
    max-width: calc(100vw - 24px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 3px 0;
    box-sizing: border-box;
    transition: max-height var(--transition), opacity var(--transition), padding var(--transition);
  }
  .timeline-thumb {
    flex-shrink: 0;
    min-width: 40px;
    min-height: 36px;
    width: 52px;
    height: 36px;
  }

  .timeline-actions {
    justify-content: center;
    gap: 4px;
    transition: max-height var(--transition), opacity var(--transition);
  }
  .timeline-actions .btn-icon,
  .timeline-actions .btn-sm {
    min-width: 40px;
    min-height: 36px;
  }

  /* Mobile collapsed state — only show controls row */
  .timeline.collapsed .timeline-canvas-wrap,
  .timeline.collapsed .timeline-frames,
  .timeline.collapsed .timeline-actions {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding: 0;
    margin: 0;
    pointer-events: none;
  }

  /* Layers: cap height and scroll */
  .layers-list {
    max-height: 150px;
    overflow-y: auto;
  }
}

/* Hamburger toggle — hidden on desktop, shown in mobile media query */

/* --- Very small screens (<= 400px) --- */
@media (max-width: 400px) {
  .action-group-zen { display: none; }
  .action-group-ruler { display: none; }
  .canvas-actions { overflow-x: auto; justify-content: flex-start; gap: 4px; }
}
