/* ========== BASE RESET ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: dark;
  --ui-bg: #1e1e2e;
  --ui-surface: #2a2a3e;
  --ui-surface-panel: #202231;
  --ui-surface-input: #292d3d;
  --ui-surface-focus: #30354a;
  --ui-surface-hover: #333350;
  --ui-surface-hover-strong: #343a50;
  --ui-surface-selected: #2d3558;
  --ui-border: #444;
  --ui-border-subtle: #3a3a4e;
  --ui-border-input: #444a60;
  --ui-neutral: #555;
  --ui-neutral-hover: #666;
  --ui-text: #eee;
  --ui-text-muted: #aaa;
  --ui-text-subtle: #888;
  --ui-accent: #4a6cf7;
  --ui-accent-hover: #5a7cf7;
  --ui-accent-active: #3a5ce7;
  --ui-focus: #7892ff;
  --ui-success: #27ae60;
  --ui-success-hover: #37be70;
  --ui-danger: #e74c3c;
  --ui-danger-hover: #f75c4c;
  --ui-warning: #e67e22;
  --ui-radius-sm: 4px;
  --ui-radius-md: 6px;
  --ui-radius-lg: 8px;
  --ui-control-height: 30px;
}

html, body {
  overflow: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  user-select: none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar,
*::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

body {
  font-family: system-ui, sans-serif;
  font-size: 12px;
  background: var(--ui-bg);
  color: var(--ui-text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  line-height: 1.2;
  border-radius: var(--ui-radius-sm);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--ui-focus);
  outline-offset: 2px;
}

html:fullscreen,
html:fullscreen body {
  width: 100%;
  height: 100%;
}

/* ========== TOOLBAR ========== */
.toolbar {
  background: var(--ui-surface);
  padding: 4px 6px;
  display: flex;
  gap: 6px;
  align-items: center;
  border-bottom: 1px solid var(--ui-border);
  flex-wrap: wrap;
}

.toolbar button {
  background: var(--ui-accent);
  color: white;
  border: none;
  padding: 4px 6px;
  border-radius: var(--ui-radius-sm);
  cursor: pointer;
  font-size: 12px;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.toolbar button:hover { background: var(--ui-accent-hover); }
.toolbar button:active { background: var(--ui-accent-active); }
.toolbar button:disabled { background: var(--ui-neutral); cursor: not-allowed; opacity: 0.6; }
.toolbar button.danger { background: var(--ui-danger); }
.toolbar button.danger:hover { background: var(--ui-danger-hover); }
.toolbar button.secondary { background: var(--ui-neutral); }
.toolbar button.secondary:hover { background: var(--ui-neutral-hover); }
.toolbar button.accent { background: var(--ui-success); }
.toolbar button.accent:hover { background: var(--ui-success-hover); }
.toolbar button svg { display: block; }

.kf-indicator {
  font-size: 12px;
  color: var(--ui-text-muted);
  padding: 4px 8px;
  background: var(--ui-bg);
  border-radius: 4px;
  font-family: monospace;
}

.kf-indicator strong { color: var(--ui-accent); }

/* ========== MAIN LAYOUT ========== */
.main-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ========== STAGE WRAPPER ========== */
.stage-wrapper {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px;
  background:
    linear-gradient(#1e1e2e, #1e1e2e),
    repeating-linear-gradient(0deg, #252538 0 2px, transparent 2px 20px),
    repeating-linear-gradient(90deg, #252538 0 2px, transparent 2px 20px);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.stage-wrapper.panning {
  cursor: grabbing !important;
}

.stage-wrapper.can-pan {
  cursor: grab;
}

/* ========== STAGE RULERS ========== */
.stage-rulers {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 24px 1fr;
  grid-template-rows: 24px 1fr;
  pointer-events: none;
  z-index: 5;
}

.stage-ruler-corner {
  grid-column: 1;
  grid-row: 1;
  background: #2a2a3e;
  border-right: 1px solid #444;
  border-bottom: 1px solid var(--ui-border);
  position: relative;
  pointer-events: auto;
}

.stage-ruler-corner::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background: var(--ui-accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.stage-ruler-top {
  grid-column: 2;
  grid-row: 1;
  height: 24px;
  background: #2a2a3e;
  border-bottom: 1px solid #444;
  position: relative;
  overflow: hidden;
  pointer-events: auto;
  z-index: 5;
}

.stage-ruler-left {
  grid-column: 1;
  grid-row: 2;
  width: 24px;
  background: #2a2a3e;
  border-right: 1px solid #444;
  position: relative;
  overflow: hidden;
  pointer-events: auto;
  z-index: 5;
}

/* ========== STAGE ========== */
#stage {
  grid-column: 2;
  grid-row: 2;
  pointer-events: auto;
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  touch-action: none;
  transform-origin: top left;
  transition: none;
  will-change: transform;
  align-self: center;
  justify-self: center;
  background:
    linear-gradient(#1e1e2e, #1e1e2e),
    repeating-linear-gradient(0deg, #252538 0 2px, transparent 2px 20px),
    repeating-linear-gradient(90deg, #252538 0 2px, transparent 2px 20px);
  z-index: 4;
}

/* ========== RULER CANVAS & INDICATORS ========== */
#stageRulerTopCanvas,
#stageRulerLeftCanvas {
  display: block;
  width: 100%;
  height: 100%;
  z-index: 5;
}

.ruler-mouse-indicator {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: var(--ui-danger);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 5;
}

.ruler-mouse-indicator.vertical {
  width: 100%;
  height: 1px;
  top: auto;
  left: 0;
}

.ruler-mouse-indicator.active {
  opacity: 1;
}

.zoom-indicator {
  position: absolute;
  top: 30px;
  right: 10px;
  background: transparent;
  color: #eee;
  padding: 4px 8px;
  border: 0;
  font-size: 12px;
  font-family: monospace;
  pointer-events: none;
  z-index: 5;
}

.btn-undo{
  position: absolute;
  bottom: 5px;
  right: 40px;
  background: transparent;
  color: #eee;
  padding: 4px 8px;
  border:0;
  border-radius: 6px;
  font-size: 12px;
  font-family: monospace;
  cursor: pointer;
  z-index: 5;
}

.btn-redo{
  position: absolute;
  bottom: 5px;
  right: 10px;
  background: transparent;
  color: #eee;
  padding: 4px 8px;
  border:0;
  border-radius: 6px;
  font-size: 12px;
  font-family: monospace;
  z-index: 5;
  cursor: pointer;
}

/* ========== SIDEBAR ========== */
.sidebar {
  width: 380px;
  border-left: 1px solid var(--ui-border);
  display: none;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-section {
  padding: 8px;
  border-bottom: 1px solid var(--ui-border-subtle);
}

.sidebar-section:last-child { border-bottom: none; }

.props-header { padding: 4px 8px 2px; }
.props-title-row { display: flex; align-items: center; gap: 6px; }
.props-title {
  flex: 1;
  font-size: 13px;
  color: #d7dbea;
  font-weight: 600;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.sidebar-header h3 {
  font-size: 12px;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-header .icon-btn {
  background: var(--ui-success);
  color: white;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: var(--ui-radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.sidebar-header .icon-btn:hover { background: var(--ui-success-hover); }

.sidebar-action {
  width: 100%;
  margin-top: 6px;
  background: var(--ui-success);
  color: white;
  border: none;
  padding: 6px 8px;
  border-radius: var(--ui-radius-sm);
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.sidebar-action:hover { background: var(--ui-success-hover); }
.sidebar-action.accent { background: var(--ui-accent); }
.sidebar-action.accent:hover { background: var(--ui-accent-hover); }

.eraser-controls {
  display: none;
  align-items: center;
  gap: 6px;
  color: #aaa;
}

.eraser-controls input[type="range"] { width: 90px; }

@media (min-width: 1024px) {
  .sidebar { display: flex; }
  #manageKfBtn, #objectsBtn, #addKfBtn, #playBtn { display: none; }
}

@media (max-width: 1023px) {
  .sidebar { display: none !important; }
  .sidebar.mobile-open {
    position: fixed;
    inset: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
    z-index: 900;
    display: flex !important;
    width: auto;
    max-width: 480px;
    margin: 0 auto;
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    overflow: hidden;
  }
  .sidebar.mobile-open .props-header { flex-shrink: 0; }
  .sidebar.mobile-open #propsPanel {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    margin: 0;
  }
  .props-backdrop.open {
    position: fixed;
    inset: 0;
    z-index: 899;
    display: block;
    background: rgba(0, 0, 0, 0.65);
  }
  .sidebar.mobile-open .props-close-btn { display: inline-flex; }
}

/* ========== RECTANGLES ========== */
.rect {
  position: absolute;
  left: 0; top: 0;
  transform-origin: center center;
  cursor: move;
  user-select: none;
  touch-action: none;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.rect.selected {
  outline: 1px dashed var(--ui-accent);
  outline-offset: 2px;
}

.rect-selection-overlay {
  position: absolute;
  left: 0;
  top: 0;
  box-sizing: border-box;
  outline: 1px dashed var(--ui-accent);
  outline-offset: 2px;
  background: transparent;
  cursor: move;
  pointer-events: auto;
}

.rect-selection-overlay.pivot-mode {
  outline-color: var(--ui-danger);
}

.rect-selection-overlay > .handle {
  position: absolute;
  z-index: 100;
  pointer-events: auto;
}

.rect-selection-overlay > .pivot-handle { pointer-events: none; }
.rect-selection-overlay > .pivot-handle.active { pointer-events: auto; }

.rect.locked {
  cursor: not-allowed;
  outline: 2px solid var(--ui-warning);
  outline-offset: 2px;
}

.rect.locked.selected { outline: 1px dashed var(--ui-accent); }

.rect.locked::after {
  content: '🔒';
  position: absolute;
  top: 4px; right: 4px;
  font-size: 14px;
  pointer-events: none;
}

.shape-content {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.rect > .handle,
.rect > .pivot-handle,
.rect > .connection-point {
  position: absolute;
  z-index: 100;
  pointer-events: auto;
}

.rect.hidden-rect {
  opacity: 0.3;
  pointer-events: none;
  outline: none !important;
}

.rect.hidden-rect::after,
.rect.hidden-rect > .handle,
.rect.hidden-rect > .pivot-handle,
.rect.hidden-rect > .connection-point,
.rect.hidden-rect .border-svg {
  display: none !important;
}

#stage.drawing-mode-active .rect-selection-overlay,
#stage.drawing-mode-active .rect > .handle,
#stage.drawing-mode-active .rect > .pivot-handle,
#stage.drawing-mode-active .rect > .connection-point,
#stage.drawing-mode-active > .group-transform-controls {
  display: none !important;
  pointer-events: none !important;
}

#freehandOverlayBar, #polylineOverlayBar {
  display: flex !important;
}

#stage.color-pick-mode,
#stage.color-pick-mode .rect {
  cursor: crosshair !important;
}

#stage.bucket-fill-mode,
#stage.bucket-fill-mode .rect {
  cursor: crosshair !important;
}

#stage.color-pick-mode .rect-selection-overlay,
#stage.bucket-fill-mode .rect-selection-overlay {
  pointer-events: none;
}

#stage.eraser-mode,
#stage.eraser-mode * {
  cursor: none !important;
}

#stage.reference-drawing-mode > .rect.reference-drawing-hidden {
  visibility: hidden !important;
}

#refImageDrawingModeBtn.active {
  background: var(--ui-success);
  color: #fff;
}

/* ========== HANDLES ========== */
.handle {
  position: absolute;
  width: 16px; height: 16px;
  background: white;
  border: 2px solid var(--ui-accent);
  border-radius: 50%;
  z-index: 10;
  touch-action: none;
}

.handle.rotate {
  background: var(--ui-accent);
  cursor: grab;
  left: 50%;
  top: -48px;
  transform: translateX(-50%);
}

.handle.rotate::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 24px;
  background: var(--ui-accent);
  transform: translateX(-50%);
}

.handle.tl { top: -11px; left: -11px; cursor: nwse-resize; }
.handle.tr { top: -11px; right: -11px; cursor: nesw-resize; }
.handle.bl { bottom: -11px; left: -11px; cursor: nesw-resize; }
.handle.br { bottom: -11px; right: -11px; cursor: nwse-resize; }
/* Stretch Handles */
.handle.stretch {
  width: 10px;
  height: 10px;
  background: #fff;
  border: 1px solid var(--ui-accent);
  border-radius: 50%;
  position: absolute;
  z-index: 10000;
}

.handle.stretch.left {
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.handle.stretch.right {
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.handle.stretch.top {
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.handle.stretch.bottom {
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.handle.skew-handle {
  width: 12px;
  height: 12px;
  border-width: 2px;
  border-style: solid;
  border-radius: 2px;
  border-color: var(--ui-warning);
  background: #fff;
  outline: none;
  z-index: 11;
}

.handle.skew-x.top,
.handle.skew-x.bottom {
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  cursor: ew-resize;
}

.handle.skew-x.top { top: -28px; }
.handle.skew-x.bottom { bottom: -28px; }

.handle.skew-y.left,
.handle.skew-y.right {
  top: 50%;
  transform: translateY(-50%) rotate(45deg);
  cursor: ns-resize;
}

.handle.skew-y.left { left: -28px; }
.handle.skew-y.right { right: -28px; }

.marquee {
  position: absolute;
  border: 2px dashed var(--ui-accent);
  background: rgba(74, 108, 247, 0.1);
  pointer-events: none;
  z-index: 9999;
}

.group-selection-active .rect.selected .pivot-handle,
.group-selection-active .rect.selected .handle,
.group-selection-active .rect > .handle,
.group-selection-active .rect > .pivot-handle,
.group-selection-active .rect-selection-overlay {
  display: none !important;
  pointer-events: none !important;
}

body:not(.group-selection-active) .rect.selected .handle {
  display: block;
}

.group-selection-active .rect,
.group-selection-active .rect.selected {
  outline: none !important;
  outline-offset: 0 !important;
}

.group-transform-controls {
  position: absolute;
  box-sizing: border-box;
  z-index: 10000;
  border: 1px dashed var(--ui-accent);
  cursor: move;
  touch-action: none;
}

.group-transform-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 2px solid var(--ui-accent);
  background: #fff;
  border-radius: 50%;
  cursor: nwse-resize;
  touch-action: none;
}

.group-transform-handle.scale-tl { top: -10px; left: -10px; }
.group-transform-handle.scale-tr { top: -10px; right: -10px; cursor: nesw-resize; }
.group-transform-handle.scale-bl { bottom: -10px; left: -10px; cursor: nesw-resize; }
.group-transform-handle.scale-br { bottom: -10px; right: -10px; }

.group-transform-handle.group-stretch-handle {
  width: 10px;
  height: 10px;
  border-width: 1px;
  border-color: var(--ui-accent);
  background: #fff;
  z-index: 2;
}

.group-transform-handle.stretch-tc {
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.group-transform-handle.stretch-bc {
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.group-transform-handle.stretch-ml {
  left: -5px;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.group-transform-handle.stretch-mr {
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.group-transform-handle.group-skew-handle {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border-color: var(--ui-warning);
  background: #fff;
  z-index: 1;
}

.group-transform-handle.skew-x-top,
.group-transform-handle.skew-x-bottom {
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  cursor: ew-resize;
}

.group-transform-handle.skew-x-top { top: -24px; }
.group-transform-handle.skew-x-bottom { bottom: -24px; }

.group-transform-handle.skew-y-left,
.group-transform-handle.skew-y-right {
  top: 50%;
  transform: translateY(-50%) rotate(45deg);
  cursor: ns-resize;
}

.group-transform-handle.skew-y-left { left: -24px; }
.group-transform-handle.skew-y-right { right: -24px; }

.group-transform-handle.group-rotate-handle {
  top: -44px;
  left: 50%;
  transform: translateX(-50%);
  border-color: var(--ui-accent);
  background: var(--ui-accent);
  cursor: grab;
}
.group-transform-handle.group-rotate-handle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 24px;
  background: var(--ui-accent);
  transform: translateX(-50%);
}

.group-selection-active .rect-selection-overlay,
.group-selection-active .rect > .handle,
.group-selection-active .rect > .pivot-handle,
.group-selection-active .rect.selected .handle,
.group-selection-active .rect.selected .pivot-handle {
  display: none !important;
  pointer-events: none !important;
}

.rect-selection-overlay,
.group-transform-controls {
  border-width: 1px;
  outline-width: 1px;
}

#stage.timeline-playing .rect-selection-overlay,
#stage.timeline-playing .rect > .handle,
#stage.timeline-playing .rect > .pivot-handle,
#stage.timeline-playing .rect > .connection-point,
#stage.timeline-playing > .group-transform-controls {
  display: none !important;
  pointer-events: none !important;
}

#stage.timeline-playing .rect.selected {
  outline: none !important;
}

/* ========== PROPERTIES PANEL ========== */

#propsPanel {
  background: var(--ui-surface-panel);
  border: 1px solid var(--ui-border-subtle);
  border-radius: var(--ui-radius-lg);
  padding: 12px;
  margin-bottom: 8px;
  color: var(--ui-text);
  font-family: inherit;
  font-size: 12px;
  display: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.props-close-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #aaa;
  font-size: 22px;
  cursor: pointer;
}

.props-close-btn:hover { background: #333; color: #fff; }
.props-backdrop { display: none; }

.prop-section {
  padding: 8px 0;
  border-top: 1px solid var(--ui-border-subtle);
}

.prop-state-buttons { grid-template-columns: repeat(2, 1fr); }

.prop-section-title {
  margin: 2px 0 8px;
  color: #c1c8da;
  font-size: 12px;
  font-weight: 600;
}

#propsPanel input[type="file"] {
  width: 100%;
  min-width: 0;
  color: #bbb;
  font-size: 11px;
}

#propsPanel .prop-field-full > .check-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  width: 100%;
}

#propsPanel .check-label input[type="checkbox"] {
  width: auto;
  min-height: 0;
  margin: 0;
}

#propsPanel .prop-field-full > button {
  width: 100%;
}

#propsPanel .prop-row .check-label {
  flex: 1;
  min-width: 0;
}

#propsPanel .prop-btn {
  min-width: 0;
}

#propsTypeName {
  font-size: 14px;
  font-weight: 650;
  color: #91a8ff;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--ui-border-subtle);
}

#propsEmpty {
  text-align: center;
  color: var(--ui-text-subtle);
  padding: 10px 0;
  font-style: italic;
  font-size: 11px;
}

/* --- Form Group: Label + Input on Same Line --- */
.prop-group {
  margin-bottom: 8px;
}

.prop-row {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.prop-field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.prop-field label {
  width: auto;
  font-size: 11px;
  font-weight: 600;
  color: #b6bed0;
  line-height: 1.25;
  text-align: left;
}

.color-picker-control {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.color-picker-control > input[type="color"] {
  flex: 1;
  min-width: 0;
}

.prop-field > .color-picker-control,
.prop-field-full > .color-picker-control,
#polylineToolbar .color-picker-control {
  width: 100%;
}

.option-row > .color-picker-control {
  flex: 1 1 72px;
}

.color-eyedropper-btn {
  display: inline-flex;
  flex: 0 0 var(--ui-control-height);
  align-items: center;
  justify-content: center;
  width: var(--ui-control-height);
  height: var(--ui-control-height);
  padding: 0;
  color: var(--ui-text);
  background: var(--ui-surface-input);
  border: 1px solid var(--ui-border-input);
  border-radius: var(--ui-radius-md);
  cursor: pointer;
}

.color-eyedropper-btn:hover {
  color: #fff;
  border-color: var(--ui-accent);
  background: var(--ui-surface-hover);
}

.prop-field-full {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  margin-top: 8px;
  margin-bottom: 8px;
}

.prop-field-full label {
  width: auto;
  font-size: 11px;
  font-weight: 600;
  color: #b6bed0;
  line-height: 1.25;
  text-align: left;
}

.prop-field-full.prop-range-field {
  display: block;
}

.prop-range-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.prop-range-field .prop-range-heading label {
  width: auto;
  text-align: left;
}

/* --- Inputs --- */
#propsPanel input[type="text"],
#propsPanel input[type="number"],
#propsPanel select {
  width: 100%;
  min-width: 0;
  min-height: var(--ui-control-height);
  padding: 6px 8px;
  background: var(--ui-surface-input);
  border: 1px solid var(--ui-border-input);
  border-radius: var(--ui-radius-md);
  color: #ffffff;
  font-size: 12px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  box-sizing: border-box;
}

#propsPanel input[type="text"]:focus,
#propsPanel input[type="number"]:focus,
#propsPanel select:focus {
  outline: none;
  border-color: var(--ui-focus);
  background: var(--ui-surface-focus);
  box-shadow: 0 0 0 3px rgba(102, 133, 255, 0.18);
}

#propsPanel input[type="color"] {
  width: 100%;
  height: var(--ui-control-height);
  padding: 3px;
  background: var(--ui-surface-input);
  border: 1px solid var(--ui-border-input);
  border-radius: var(--ui-radius-md);
  cursor: pointer;
  box-sizing: border-box;
}

#propsPanel input[type="color"]:hover {
  border-color: var(--ui-accent);
}

#polylineToolbar input[type="color"] {
  height: var(--ui-control-height) !important;
  padding: 3px !important;
  background: var(--ui-surface-input) !important;
  border: 1px solid var(--ui-border-input) !important;
  border-radius: var(--ui-radius-md) !important;
  box-sizing: border-box;
}

#polylineToolbar input[type="color"]:hover {
  border-color: var(--ui-accent) !important;
}

#polylineToolbar input[type="range"],
#polylineToolbar input[type="checkbox"] {
  accent-color: var(--ui-accent);
}

.polyline-track-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ui-accent);
}

#propsPanel select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%239ca3af' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 26px;
}

/* --- Section Divider --- */
.prop-divider {
  height: 1px;
  background: var(--ui-border-subtle);
  margin: 10px 0;
}

/* --- Action Buttons --- */
.prop-btn-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--ui-border-subtle);
}

.prop-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 7px 6px;
  background: #292d3d;
  border: 1px solid #444a60;
  border-radius: 6px;
  color: #e0e0e0;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.prop-btn:hover {
  background: var(--ui-surface-hover-strong);
  border-color: #7892ff;
  color: #ffffff;
}

.prop-btn:active {
  transform: translateY(1px);
}

#propDelete {
  background: rgba(231, 76, 60, 0.1);
  border-color: rgba(231, 76, 60, 0.3);
  color: var(--ui-danger);
}

#propDelete:hover {
  background: rgba(231, 76, 60, 0.2);
  border-color: var(--ui-danger);
  color: #ff6b6b;
}

#propTransparent {
  width: 100%;
  padding: 8px 10px;
  margin-top: 6px;
  background: #292d3d;
  border: 1px dashed #444a60;
  border-radius: 6px;
  color: #b6bed0;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s ease;
}

#propTransparent:hover {
  border-color: var(--ui-accent);
  color: var(--ui-accent);
  background: var(--ui-surface-hover);
}

/* Text Alignment Buttons */
.prop-align-row {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.prop-align-btn {
  flex: 1;
  padding: 5px;
  background: #2a2a3e;
  border: 1px solid #3f3f5f;
  border-radius: 4px;
  color: #9ca3af;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.prop-align-btn:hover {
  background: var(--ui-surface-hover);
  color: #ffffff;
  border-color: var(--ui-accent);
}

/* --- Dynamic Visibility --- */
#propBorderRadiusRow,
#propSidesRow,
#propPointsRow,
#propInnerRadiusRow,
#propsTextSection {
  display: none;
}

#propExportPngBtn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px;
  font-size: 12px;
  cursor: pointer;
}

/* ========== MODALS ========== */
.modal-backdrop {
  width: fit-content;
  height: fit-content;
  position: fixed;
  inset: 0;
  top: 60px;
  left: 16px;
  z-index: 1000;  /* Base z-index, will be overridden by JS */
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s, z-index 0s;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-backdrop.dragging {
  align-items: flex-start;
  justify-content: flex-start;
}

/* Emphasize the active modal. */
.modal-backdrop.open .modal {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transition: box-shadow 0.2s;
}

.modal-backdrop.open:last-of-type .modal,
.modal-backdrop[style*="z-index"] .modal {
  box-shadow: 0 25px 70px rgba(74, 108, 247, 0.3), 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border-subtle);
  border-radius: var(--ui-radius-lg);
  padding: 12px;
  max-width: 500px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  position: relative;
}

.modal-backdrop.dragging .modal {
  position: absolute;
  margin: 0;
}

.modal.wide { max-width: 640px; }

.modal h2 {
  font-size: 16px;
  margin-bottom: 8px;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal h2 .close-btn {
  background: none;
  border: none;
  color: #aaa;
  font-size: 22px;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}

.modal h2 .close-btn:hover { color: #fff; }

.modal-section {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--ui-border-subtle);
}

.modal-section:last-child { border-bottom: none; }

.modal-actions {
  display: flex;
  gap: 6px;
}

.modal-actions button { flex: 1; justify-content: center; padding: 6px 8px; }

.modal-section h3 {
  font-size: 12px;
  color: #aaa;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-action {
  width: 100%;
  color: white;
  border: none;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.modal-action.primary { background: var(--ui-accent); }
.modal-action.primary:hover { background: var(--ui-accent-hover); }
.modal-action.accent { background: var(--ui-success); }
.modal-action.accent:hover { background: var(--ui-success-hover); }
.modal-action.secondary { background: var(--ui-neutral); }
.modal-action.secondary:hover { background: var(--ui-neutral-hover); }

.about-intro {
  color: #ccc;
  line-height: 1.6;
}

.about-list {
  margin: 0;
  padding-left: 20px;
  color: #ccc;
  line-height: 1.7;
}

.about-shortcuts {
  display: grid;
  gap: 6px;
}

.about-shortcuts > div {
  display: grid;
  grid-template-columns: minmax(105px, auto) 1fr;
  align-items: center;
  gap: 8px;
  color: #ccc;
}

.about-shortcuts kbd {
  width: fit-content;
  padding: 2px 5px;
  border: 1px solid #4a4a60;
  border-radius: 4px;
  background: #1e1e2e;
  color: #eee;
  font: inherit;
  white-space: nowrap;
}

.about-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.about-actions > * {
  flex: 1 1 130px;
  text-decoration: none;
}

.about-note {
  margin-top: 8px;
  color: #999;
  font-size: 11px;
}

#transformInfo {
  font-size: 12px;
  color: #aaa;
  margin-bottom: 8px;
}

.modal h2.draggable {
  cursor: move;
}

.dragging-modal {
  opacity: 0.9;
  box-shadow: 0 0 20px rgba(74, 108, 247, 0.7);
}

/* ========== KEYFRAMES LIST ========== */
.kf-list { display: flex; flex-direction: column; gap: 4px; }

.kf-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  background: var(--ui-bg);
  border-radius: var(--ui-radius-md);
  border: 1px solid transparent;
  flex-wrap: wrap;
}

.kf-item.active { border-color: var(--ui-accent); background: var(--ui-surface-selected); }

.kf-item .kf-name {
  flex: 1;
  background: transparent;
  border: none;
  color: #eee;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
  min-width: 80px;
}

.kf-item .kf-name:focus { background: #2a2a3e; outline: 1px solid var(--ui-accent); }

.kf-item .kf-count {
  font-size: 11px;
  color: #888;
  font-family: monospace;
}

.kf-item button {
  background: var(--ui-neutral);
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.kf-item button:hover { background: var(--ui-neutral-hover); }
.kf-item button.select-btn.active { background: var(--ui-accent); }
.kf-item button.del-btn { background: var(--ui-danger); }
.kf-item button.del-btn:hover { background: var(--ui-danger-hover); }

/* ========== OBJECTS LIST ========== */
.obj-toolbar {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.obj-toolbar button {
  background: var(--ui-neutral);
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.obj-toolbar button:hover { background: var(--ui-neutral-hover); }

.obj-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 4px;
}

.obj-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  background: #1e1e2e;
  border-radius: 6px;
  border: 2px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}

.obj-item.selected { border-color: var(--ui-accent); background: var(--ui-surface-selected); }
.obj-item.dragging { opacity: 0.4; }

.obj-item .drag-handle {
  cursor: grab;
  color: #666;
  padding: 4px;
  touch-action: none;
  user-select: none;
}

.obj-item .drag-handle:active { cursor: grabbing; }
.obj-item .drag-handle:hover { color: #aaa; }

.obj-item .obj-preview {
  width: 36px; height: 36px;
  border-radius: 4px;
  background: #fff;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid #444;
}

.obj-item .obj-preview-inner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.obj-item .obj-preview-rect {
  width: 60%; height: 60%;
  background-size: cover;
  background-position: center;
  border: 1px solid rgba(0,0,0,0.2);
}

.obj-item .obj-name {
  flex: 1;
  background: transparent;
  border: none;
  color: #eee;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
  min-width: 0;
}

.obj-item .obj-name:focus { background: #2a2a3e; outline: 1px solid var(--ui-accent); }

.obj-item .obj-actions {
  display: flex;
  gap: 3px;
}

.obj-item .obj-actions button {
  background: var(--ui-neutral);
  color: white;
  border: none;
  width: 26px; height: 26px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.obj-item .obj-actions button:hover { background: var(--ui-neutral-hover); }
.obj-item .obj-actions button.hidden-active { background: var(--ui-warning); }

.obj-empty {
  color: #888;
  font-size: 12px;
  text-align: center;
  padding: 12px;
}

/* ========== OPTION ROWS ========== */
.option-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.option-row label {
  font-size: 12px;
  color: #bbb;
  min-width: 80px;
}

.option-row input[type="color"] {
  width: 50px;
  height: var(--ui-control-height);
  border: 1px solid var(--ui-border-input);
  border-radius: var(--ui-radius-md);
  cursor: pointer;
  background: var(--ui-surface-input);
}

.option-row input[type="text"],
.option-row input[type="number"],
.option-row select {
  background: var(--ui-surface-input);
  border: 1px solid var(--ui-border-input);
  color: var(--ui-text);
  padding: 5px 8px;
  border-radius: var(--ui-radius-md);
  font-size: 12px;
  min-height: var(--ui-control-height);
}

.option-row input[type="text"],
.option-row input[type="number"] {
  flex: 1;
  min-width: 80px;
}

.option-row input[type="number"] { max-width: 80px; }
.option-row input[type="file"] { font-size: 11px; color: #bbb; flex: 1; }

.option-row button {
  background: var(--ui-neutral);
  color: white;
  border: none;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.option-row button:hover { background: var(--ui-neutral-hover); }
.option-row button.primary { background: var(--ui-accent); }
.option-row button.primary:hover { background: var(--ui-accent-hover); }
.option-row button.danger { background: var(--ui-danger); }
.option-row button.danger:hover { background: var(--ui-danger-hover); }
.option-row button.lock-active { background: var(--ui-warning); }

.gemini-key-setting {
  display: grid;
  gap: 8px;
}
.gemini-key-setting > label {
  color: #bbb;
  font-size: 12px;
}
.gemini-key-setting input {
  width: 100%;
  min-width: 0;
  min-height: var(--ui-control-height);
  padding: 6px 8px;
  border: 1px solid var(--ui-border-input);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface-input);
  color: var(--ui-text);
  font: inherit;
}
.gemini-key-setting select {
  width: 100%;
  min-height: var(--ui-control-height);
  padding: 6px 8px;
  border: 1px solid var(--ui-border-input);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface-input);
  color: var(--ui-text);
  font: inherit;
}
.gemini-key-setting input:focus {
  border-color: var(--ui-focus);
  outline: none;
  box-shadow: 0 0 0 3px rgba(102, 133, 255, 0.18);
}
.gemini-key-actions {
  display: flex;
  gap: 8px;
}
.gemini-key-actions .modal-action { width: auto; flex: 1; }
.gemini-key-status,
.gemini-key-note {
  color: #aaa;
  font-size: 11px;
  line-height: 1.5;
}
.gemini-key-note { color: #888; }

.add-to-kf-btn {
  width: 100%;
  background: var(--ui-success) !important;
  color: white;
  border: none;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.add-to-kf-btn:hover { background: var(--ui-success-hover) !important; }
.add-to-kf-btn:disabled { background: #555 !important; cursor: not-allowed; }

.kf-target-info {
  font-size: 11px;
  color: #aaa;
  text-align: center;
  margin-bottom: 8px;
  font-family: monospace;
}

.kf-target-info strong { color: var(--ui-accent); }

/* ========== TOAST ========== */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ui-success);
  color: white;
  padding: 8px 14px;
  border-radius: 4px;
  font-size: 12px;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show { opacity: 1; }

/* ========== EXPORT OVERLAY ========== */
.export-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 3000;
}

.export-overlay.active { display: flex; }

.export-overlay-content {
  background: #2a2a3e;
  border-radius: 8px;
  padding: 16px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  border: 1px solid #444;
}

#exportProgressLabel {
  font-size: 12px;
  color: #eee;
  margin-bottom: 8px;
}

.export-progress-track {
  width: 100%;
  height: 8px;
  background: #1e1e2e;
  border-radius: 4px;
  overflow: hidden;
}

.export-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--ui-accent), var(--ui-success));
  border-radius: 4px;
  transition: width 0.1s;
}

/* ========== PIVOT HANDLE ========== */
.group-pivot-handle{
  position: absolute;
  background: var(--ui-danger);
  border: 2px solid #fff;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  z-index: 10002;
}
.pivot-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: rgba(231, 76, 60, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  z-index: 15;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: width 0.15s, height 0.15s, background 0.15s;
}

.pivot-handle.active {
  width: 20px;
  height: 20px;
  background: var(--ui-danger);
  border-color: white;
  cursor: move;
  pointer-events: auto;
  z-index: 20;
  box-shadow: 
    0 0 0 1px rgba(231, 76, 60, 0.3),
    20px 0 0 -19.5px var(--ui-danger),
    -20px 0 0 -19.5px var(--ui-danger),
    0 20px 0 -19.5px var(--ui-danger),
    0 -20px 0 -19.5px var(--ui-danger);
}

.pivot-handle.active::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 32px;
  height: 32px;
  border: 2px dashed var(--ui-danger);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: pivot-pulse 1.5s ease-in-out infinite;
}

.pivot-handle.active::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 40px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--ui-danger) 30%, var(--ui-danger) 70%, transparent);
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 0 0 999px transparent;
}

@keyframes pivot-pulse {
  0%, 100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 0.5; transform: translate(-50%, -50%) scale(1.15); }
}

.pivot-handle.connect-target {
  width: 20px;
  height: 20px;
  background: var(--ui-success);
  border-color: white;
  cursor: pointer;
  pointer-events: auto;
  z-index: 20;
  animation: pivot-connect-pulse 1s ease-in-out infinite;
}

.pivot-handle.connect-target::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36px;
  height: 36px;
  border: 2px dashed var(--ui-success);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: pivot-pulse 1.5s ease-in-out infinite;
}

@keyframes pivot-connect-pulse {
  0%, 100% { 
    box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.7);
    transform: translate(-50%, -50%) scale(1);
  }
  50% { 
    box-shadow: 0 0 0 12px rgba(39, 174, 96, 0);
    transform: translate(-50%, -50%) scale(1.2);
  }
}

.rect.pivot-mode {
  outline: none !important;
}

/* ========== RANGE INPUT ========== */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  height: 20px;
  margin: 0;
  padding: 0;
  background: transparent;
  outline: none;
  cursor: pointer;
  touch-action: pan-y;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: #3b4255;
  border: 1px solid #525b72;
  border-radius: 999px;
}

input[type="range"]::-moz-range-track {
  height: 6px;
  background: #3b4255;
  border: 1px solid #525b72;
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  background: #f4f6ff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid #6685ff;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  box-sizing: border-box;
  background: #f4f6ff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid #6685ff;
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px rgba(102, 133, 255, 0.28);
}

input[type="range"]:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 3px rgba(102, 133, 255, 0.28);
}

/* ========== CONNECTION ========== */
.rect.connect-mode {
  outline: 2px dashed #9b59b6 !important;
  outline-offset: 4px;
  cursor: crosshair;
}

.connection-point {
  position: absolute;
  width: 12px;
  height: 12px;
  background: white;
  border: 2px solid #333;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 15;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
  pointer-events: auto;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.connection-point:hover {
  background: var(--ui-accent);
  border-color: #fff;
  transform: translate(-50%, -50%) scale(1.3);
}

.connection-point.selected {
  background: #f39c12;
  border-color: #fff;
  transform: translate(-50%, -50%) scale(1.4);
  box-shadow: 0 0 0 3px rgba(243, 156, 18, 0.3);
}

.connection-point.connected {
  background: var(--ui-success);
  border-color: #fff;
}

.connection-point.connected::after {
  content: '';
  position: absolute;
  inset: -4px;
  border: 2px dashed var(--ui-success);
  border-radius: 50%;
  pointer-events: none;
}

.point-context-menu {
  position: fixed;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  padding: 4px;
  z-index: 5000;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  min-width: 160px;
}

.point-context-menu button,
#markerContextMenu button {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  background: transparent;
  color: var(--ui-text);
  border: none;
  padding: 5px 8px;
  border-radius: var(--ui-radius-sm);
  cursor: pointer;
  font-size: 12px;
  text-align: left;
}

#markerContextMenu button:hover,
.point-context-menu button:hover {
  background: var(--ui-accent);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--ui-accent);
  cursor: pointer;
  flex-shrink: 0;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0 !important;
  cursor: pointer;
}

.inline-icon-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.control-value {
  min-width: 40px;
  color: #c1c8da;
  font-size: 12px;
  text-align: right;
}

.unit-label {
  color: #888;
  font-size: 12px;
}

.point-list {
  max-height: 200px;
  overflow-y: auto;
  background: #1e1e2e;
  border-radius: 4px;
  padding: 4px;
}

.point-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  border: 2px solid transparent;
}

.point-list-item:hover {
  background: #2a2a3e;
}

.point-list-item.selected {
  background: var(--ui-surface-selected);
  border-color: #f39c12;
}

.point-name {
  flex: 1;
  font-weight: 500;
}

.point-info {
  font-size: 11px;
  color: #888;
  font-family: monospace;
}

/* ========== OBJECT PICKER ========== */
.object-type-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 6px;
}

.object-type-btn {
  background: #1e1e2e;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 8px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
  color: #eee;
}

.object-type-btn:hover {
  background: #2a2a3e;
  border-color: var(--ui-accent);
  transform: translateY(-2px);
}

.object-type-preview {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.object-type-label {
  font-size: 11px;
  color: #bbb;
  text-align: center;
}

.object-text {
  line-height: 1.2;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ========== TIMELINE ========== */
.timeline-container {
  background: var(--ui-bg);
  border-top: 1px solid var(--ui-border);
  display: flex;
  flex-direction: column;
  height: 280px;
  min-height: 180px;
  flex-shrink: 0;
}

.timeline-toolbar {
  background: var(--ui-surface);
  padding: 4px 6px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid #444;
  flex-wrap: wrap;
}

.tl-toolbar-group {
  display: flex;
  gap: 4px;
  align-items: center;
}

.tl-btn {
  background: var(--ui-neutral);
  color: var(--ui-text);
  border: none;
  width: 26px;
  height: 26px;
  border-radius: var(--ui-radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  transition: background-color 0.15s ease;
}

.tl-btn:hover { background: var(--ui-neutral-hover); }
.tl-btn.active { background: var(--ui-accent); }
.tl-btn.accent { background: var(--ui-success); }
.tl-btn.accent:hover { background: var(--ui-success-hover); }
.tl-btn.primary { background: var(--ui-accent); }
.tl-btn.primary:hover { background: var(--ui-accent-hover); }

.tl-time-display {
  font-family: monospace;
  font-size: 11px;
  color: var(--ui-accent);
  padding: 4px 10px;
  background: var(--ui-bg);
  border-radius: var(--ui-radius-sm);
  min-width: 130px;
  text-align: center;
}

.tl-label {
  font-size: 11px;
  color: #aaa;
}

.tl-select {
  background: var(--ui-bg);
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-sm);
  padding: 4px 6px;
  font-size: 11px;
  cursor: pointer;
}

.tl-zoom-slider {
  width: 100px;
  height: 4px;
}

.timeline-main {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ========== TIMELINE LABELS ========== */
.timeline-labels {
  width: 240px;
  flex: 0 0 240px;
  background: var(--ui-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.timeline-label-resize-handle {
  position: relative;
  flex: 0 0 8px;
  cursor: col-resize;
  touch-action: none;
  z-index: 2;
}

.timeline-label-resize-handle::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3px;
  width: 2px;
  background: var(--ui-border);
  transition: background 0.15s ease;
}

.timeline-label-resize-handle:hover::before,
.timeline-label-resize-handle:focus-visible::before,
.timeline-label-resize-handle.dragging::before {
  background: var(--ui-accent);
}

.timeline-label-resize-handle:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: -2px;
}

.timeline-ruler-spacer {
  height: 28px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-surface);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.timeline-ruler-spacer::-webkit-scrollbar { display: none; }

.timeline-ruler-spacer button {
  background: var(--ui-neutral);
  border: none;
  color: var(--ui-text);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--ui-radius-sm);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}

.timeline-ruler-spacer button:hover {
  background: var(--ui-neutral-hover);
  color: var(--ui-text);
}

.timeline-tracks-labels {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}

.timeline-tracks-labels::-webkit-scrollbar { display: none; }

.timeline-track-label {
  height: 36px;
  background: var(--ui-surface);
  border-bottom: 1px solid var(--ui-border-subtle);
  display: flex;
  align-items: center;
  padding: 0 4px;
  gap: 4px;
  cursor: pointer;
  transition: background 0.15s;
  box-sizing: border-box;
}

.timeline-track-label:hover {
  background: var(--ui-surface-input);
}

.timeline-track-label.selected {
  background: var(--ui-surface-selected) !important;
  border-left: 3px solid var(--ui-accent);
  padding-left: 1px;
}

.track-name {
  flex: 1;
  font-size: 12px;
  color: #eee;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-controls {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.track-ctrl-btn {
  background: transparent;
  color: #888;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.track-ctrl-btn:hover { background: #444; color: #eee; }
.track-ctrl-btn.active { color: #f39c12; }

/* ========== TIMELINE SCROLL AREA ========== */
.timeline-scroll-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

.timeline-ruler {
  height: 28px;
  background: #252538;
  border-bottom: 1px solid #444;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
}

.timeline-ruler-scroll {
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.timeline-ruler-scroll::-webkit-scrollbar { display: none; }

.timeline-ruler-content {
  position: relative;
  height: 100%;
}

.timeline-canvas {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}

.timeline-playhead-ruler {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--ui-danger);
  pointer-events: none;
  z-index: 10;
}

.playhead-handle {
  position: absolute;
  top: -2px;
  left: -6px;
  width: 14px;
  height: 14px;
  background: var(--ui-danger);
  clip-path: polygon(0 0, 100% 0, 100% 60%, 50% 100%, 0 60%);
  cursor: ew-resize;
  pointer-events: auto;
}

.timeline-track-scroll {
  flex: 1;
  overflow: auto;
  position: relative;
}

.timeline-playhead {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--ui-danger);
  pointer-events: none;
  z-index: 20;
  box-shadow: 0 0 4px rgba(231, 76, 60, 0.5);
}

.timeline-track-content {
  position: relative;
  min-height: 100%;
  width: 100%;
  height: 100%;
}

.timeline-tracks { display: flex; flex-direction: column; }

.timeline-track {
  height: 36px;
  border-bottom: 1px solid #333;
  position: relative;
  background: repeating-linear-gradient(
    90deg,
    transparent 0,
    transparent calc(var(--step, 50px) - 1px),
    rgba(255,255,255,0.03) calc(var(--step, 50px) - 1px),
    rgba(255,255,255,0.03) var(--step, 50px)
  );
}

.timeline-track:hover {
  background-color: rgba(74, 108, 247, 0.05);
}

.timeline-track-label.drag-over {
  border-top: 2px solid var(--ui-accent);
}

.timeline-track-label.dragging-label {
  opacity: 0.4;
}

.track-drag-handle {
  cursor: grab;
  color: #666;
  padding: 2px;
  font-size: 12px;
  user-select: none;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  flex-shrink: 0;
}

.track-drag-handle:hover { color: #aaa; }
.track-drag-handle:active { cursor: grabbing; }

.track-thumbnail {
  width: 26px;
  height: 26px;
  background: #fff;
  border-radius: 3px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  border: 1px solid #444;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.track-thumbnail-inner {
  position: absolute;
  inset: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.track-thumbnail-shape {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
}

.track-name-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ui-text);
  font-size: 11px;
  padding: 3px 4px;
  border-radius: 3px;
  outline: none;
  font-family: inherit;
}

.track-name-input:hover {
  border-color: #444;
}

.track-name-input:focus {
  background: var(--ui-bg);
  border-color: var(--ui-accent);
}

.timeline-track-label.selected .track-name-input {
  color: #fff;
  font-weight: 600;
}

.track-kf-count {
  font-size: 10px;
  color: var(--ui-accent);
  background: var(--ui-bg);
  padding: 1px 5px;
  border-radius: 8px;
  font-family: monospace;
  min-width: 18px;
  text-align: center;
}

/* ========== TIMELINE KEYFRAMES ========== */
.timeline-keyframe {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  cursor: pointer;
  z-index: 2;
}

.kf-diamond {
  width: 12px;
  height: 12px;
  background: var(--ui-accent);
  transform: rotate(45deg);
  margin: 2px;
  border: 2px solid #2a2a3e;
  transition: transform 0.1s, background 0.1s;
}

.timeline-keyframe:hover .kf-diamond {
  background: var(--ui-accent-hover);
  transform: rotate(45deg) scale(1.2);
}

.timeline-keyframe.selected .kf-diamond:hover {
  background: #f39c12;
  border-color: #fff;
}

.timeline-keyframe.active .kf-diamond {
  background: var(--ui-success);
  border-color: #fff;
}

.timeline-loop-region {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(74, 108, 247, 0.15);
  border-left: 2px solid var(--ui-accent);
  border-right: 2px solid var(--ui-accent);
  pointer-events: none;
  z-index: 1;
}

.timeline-marker {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  pointer-events: auto;
  cursor: pointer;
  z-index: 3;
}

.timeline-marker-flag {
  position: absolute;
  top: 0;
  left: -6px;
  width: 14px;
  height: 14px;
  background: inherit;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 70%, 0 100%);
}

/* =========================================
   Timeline Vertical Resize Handle
   ========================================= */

#timelineContainer {
  position: relative;
  overflow: hidden;
}

.timeline-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 12px;
  background: transparent;
  cursor: ns-resize;
  z-index: 100;
  touch-action: none;
  transition: background 0.15s ease;
}

.timeline-resize-handle::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 2px;
  background: var(--ui-accent);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.timeline-resize-handle:hover {
  background: rgba(74, 108, 247, 0.1);
}

.timeline-resize-handle:hover::before {
  opacity: 1;
}

.timeline-resize-handle.dragging {
  background: rgba(74, 108, 247, 0.2);
}

.timeline-resize-handle.dragging::before {
  opacity: 1;
  width: 60px;
}

/* Prevent text selection while dragging */
body.timeline-resizing {
  cursor: ns-resize !important;
  user-select: none;
}

body.timeline-resizing * {
  cursor: ns-resize !important;
  user-select: none !important;
}

/* ========== MARKER CONTEXT MENU ========== */
#markerContextMenu button[style*="color: rgb(231, 76, 60)"]:hover {
  background: var(--ui-danger);
  color: white !important;
}

.timeline-scroll-area.panning {
  cursor: grabbing !important;
}

.timeline-scroll-area.can-pan {
  cursor: grab;
}

/* ========== KEYFRAME POPUP ========== */
.kf-popup {
  position: fixed;
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-lg);
  padding: 0;
  z-index: 5000;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  min-width: 260px;
  overflow: hidden;
}

.kf-popup.copy-options-open {
  min-width: min(360px, calc(100vw - 16px));
}

.kf-popup-header {
  background: var(--ui-bg);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--ui-border);
}

.kf-popup-name {
  flex: 1;
  background: transparent;
  border: none;
  color: #eee;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 6px;
  border-radius: 4px;
  outline: none;
}

.kf-popup-name:focus {
  background: #2a2a3e;
  outline: 1px solid var(--ui-accent);
}

.kf-popup-close {
  background: transparent;
  border: none;
  color: #aaa;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.kf-popup-close:hover { color: #fff; }

.kf-popup-info {
  padding: 8px 10px;
}

.kf-popup-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.kf-popup-row:last-child { margin-bottom: 0; }

.kf-popup-label {
  font-size: 12px;
  color: #aaa;
  min-width: 50px;
}

.kf-popup-input {
  background: var(--ui-surface-input);
  border: 1px solid var(--ui-border-input);
  color: var(--ui-text);
  padding: 4px 8px;
  border-radius: var(--ui-radius-md);
  font-size: 12px;
  min-height: var(--ui-control-height);
  width: 80px;
}

.kf-popup-unit {
  font-size: 11px;
  color: #888;
}

.kf-popup-value {
  font-size: 12px;
  color: #eee;
  font-weight: 500;
}

.kf-popup-actions {
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  border-top: 1px solid var(--ui-border);
  background: var(--ui-bg);
}

.kf-popup-btn {
  flex: 1;
  background: var(--ui-neutral);
  color: #eee;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.kf-popup-btn:hover { background: var(--ui-neutral-hover); }
.kf-popup-btn.danger { background: var(--ui-danger); }
.kf-popup-btn.danger:hover { background: var(--ui-danger-hover); }

.kf-copy-options {
  display: grid;
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  border-top: 1px solid var(--ui-border);
  color: var(--ui-text);
  font-size: 12px;
}

.kf-copy-options[hidden] { display: none; }
.kf-copy-options > label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.kf-copy-options input { accent-color: var(--ui-accent); }
.kf-copy-params-heading { padding-top: 4px; color: var(--ui-text-muted); }
.kf-copy-params { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; max-height: 160px; overflow-y: auto; }
.kf-copy-params label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.kf-copy-help { color: var(--ui-text-muted); font-size: 11px; line-height: 1.4; }
.kf-copy-options-actions { display: flex; gap: 6px; padding-top: 4px; }

/* ========== ONION SKIN ========== */
.onion-ghost {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 0;
  mix-blend-mode: normal;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.onion-ghost.prev {
  outline: 2px solid rgba(231, 76, 60, 0.6);
  outline-offset: -2px;
}

.onion-ghost.next {
  outline: 2px solid rgba(39, 174, 96, 0.6);
  outline-offset: -2px;
}

.primary { background: var(--ui-accent); }
.primary:hover { background: var(--ui-accent-hover); }
.danger { background: var(--ui-danger); }
.danger:hover { background: var(--ui-danger-hover); }

#cropCanvas {
  cursor: crosshair;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

/* ========== FREEHAND BRUSH TYPE BUTTONS ========== */
.fh-brush-type-btn.active {
  background: var(--ui-accent) !important;
  border-color: #fff !important;
}

.fh-brush-type-options {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.fh-brush-type-btn {
  flex: 1;
  background: var(--ui-neutral);
  color: var(--ui-text);
  border: 2px solid transparent;
  border-radius: var(--ui-radius-sm);
  padding: 6px 8px;
  cursor: pointer;
}

.fh-endpoint-select { flex: 1; }

.fh-brush-type-btn:hover:not(.active) {
  background: var(--ui-neutral-hover) !important;
}

.modal.ai-assistant-modal {
  display: flex;
  flex-direction: column;
  width: min(760px, calc(100vw - 32px));
  max-width: 760px;
  max-height: 90vh;
  overflow: hidden;
}
.ai-assistant-modal h2 {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-chat-clear {
  margin-left: auto;
  padding: 5px 9px;
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface-input);
  color: var(--ui-text-muted);
  cursor: pointer;
  font-size: 12px;
}
.ai-chat-clear:hover { background: var(--ui-neutral); color: #fff; }
.ai-chat-clear:disabled { cursor: wait; opacity: 0.55; }
.ai-chat-messages {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 12px;
  min-height: 220px;
  max-height: 62vh;
  overflow-y: auto;
  padding: 12px 8px;
  overscroll-behavior: contain;
}
.ai-chat-message {
  max-width: min(88%, 600px);
  padding: 10px 13px;
  border: 1px solid #383844;
  border-radius: 14px;
  background: #23232e;
  color: #e7e7ec;
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.ai-chat-message.user {
  align-self: flex-end;
  border-color: #3d5d9c;
  background: #263b5d;
}
.ai-chat-message.assistant { align-self: flex-start; }
.ai-chat-message.error {
  align-self: flex-start;
  border-color: #824a4a;
  background: #422b30;
  color: #ffc1ba;
}
.ai-chat-message.thinking {
  color: #a7a7b3;
  font-style: italic;
}
.ai-chat-message p { margin: 0; }
.ai-chat-action-list {
  display: grid;
  gap: 5px;
  margin: 8px 0 0;
  padding-left: 19px;
  color: #c8c8d1;
  font-size: 12px;
}
.ai-chat-outcome {
  margin-top: 8px;
  color: #a9c5a5;
  font-size: 11px;
}
.ai-chat-outcome.pending { color: #e2c47a; }
.ai-chat-outcome.expired,
.ai-chat-outcome.discarded { color: #aaa; }
.ai-chat-message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.ai-chat-message-actions button {
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}
.ai-chat-apply { background: var(--ui-success); }
.ai-chat-apply:hover { background: var(--ui-success-hover); }
.ai-chat-discard { background: var(--ui-neutral); }
.ai-chat-discard:hover { background: var(--ui-neutral-hover); }
.ai-chat-composer {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  align-items: stretch;
  padding-top: 10px;
  border-top: 1px solid #363640;
}
.ai-chat-input-wrap {
  position: relative;
  width: 100%;
}
.ai-assistant-prompt {
  display: block;
  width: 100%;
  min-height: 92px;
  max-height: 220px;
  resize: vertical;
  padding: 10px 52px 10px 12px;
  border: 1px solid var(--ui-border-input);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface-input);
  color: var(--ui-text);
  font: inherit;
}
.ai-assistant-prompt:focus {
  border-color: var(--ui-focus);
  outline: none;
  box-shadow: 0 0 0 3px rgba(102, 133, 255, 0.18);
}
.ai-chat-send {
  position: absolute;
  right: 9px;
  bottom: 9px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: var(--ui-accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.ai-chat-send:hover:not(:disabled) { background: var(--ui-accent-hover); }
.ai-chat-send:disabled {
  cursor: wait;
  opacity: 0.65;
}
@media (max-width: 768px) {
  .modal.ai-assistant-modal { width: calc(100vw - 20px); max-height: 94vh; }
  .ai-chat-messages { min-height: 180px; max-height: 68vh; }
  .ai-chat-message { max-width: 94%; }
  .ai-assistant-prompt { min-height: 82px; }
}

/* ========== FREEHAND PERFORMANCE ========== */
.rect[data-type="freehand"] .shape-content {
  will-change: transform;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

@media (max-width: 1023px) {
  .toolbar {
    padding: 6px 8px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    flex-shrink: 0;
  }
  .toolbar > * {
    flex-shrink: 0;
  }
  .toolbar button {
    padding: 6px 10px;
    min-height: 32px;
    font-size: 12px;
  }
  .kf-indicator {
    font-size: 11px;
    padding: 6px 8px;
    white-space: nowrap;
  }
  .timeline-toolbar {
    padding: 6px 8px;
    padding-top: 12px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    flex-shrink: 0;
  }
  .tl-toolbar-group {
    gap: 4px;
    flex-shrink: 0;
  }
  .tl-btn {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
  }
  .tl-time-display {
    min-width: 110px;
    flex-shrink: 0;
  }
  .timeline-resize-handle {
    height: 16px;
  }
  .timeline-resize-handle::before {
    opacity: 0.7;
    width: 48px;
    height: 3px;
  }
  .stage-wrapper { padding: 4px; }
  .handle { width: 24px; height: 24px; }
  .handle.tl { top: -12px; left: -12px; }
  .handle.tr { top: -12px; right: -12px; }
  .handle.bl { bottom: -12px; left: -12px; }
  .handle.br { bottom: -12px; right: -12px; }
  .handle.rotate { top: -50px; }
  .modal-backdrop {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 8px;
  }
  .modal {
    padding: 12px;
    max-width: 100%;
    max-height: 88dvh;
  }
  .option-row label { min-width: 72px; }
  .object-type-grid { grid-template-columns: repeat(3, 1fr); }
  .timeline-container {
    height: 190px;
    min-height: 130px;
  }
  .timeline-labels { width: 190px; flex-basis: 190px; }
  .timeline-track-label { padding: 0 4px; }
}

body.timeline-label-resizing,
body.timeline-label-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}