:root {
  font-family: Arial, sans-serif;
  color-scheme: dark;
  --bg: #151515;
  --text: #f7f7f7;
  --border: #2f2f2f;
  --surface: #1a1a1a;
  --surface-2: #171717;
  --control-bg: #242424;
  --control-border: #444;
  --timeline-track: #222;
  --stage-bg: #1e1e1e;
  --grid: rgba(255, 255, 255, 0.03);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f4f6;
  --text: #1a1a1a;
  --border: #d0d5dd;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --control-bg: #ffffff;
  --control-border: #c0c7d1;
  --timeline-track: #eef2f7;
  --stage-bg: #ffffff;
  --grid: rgba(0, 0, 0, 0.06);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.toolbar {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.toolbar button {
  padding: 8px 12px;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  background: var(--control-bg);
  color: inherit;
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr 300px;
  gap: 12px;
  padding: 12px;
  align-items: start;
}

.timeline-panel {
  margin: 0 12px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-2);
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

#timeline-playhead {
  width: 100%;
  margin-bottom: 10px;
}

.timeline-tracks {
  display: grid;
  gap: 6px;
  overflow-x: auto;
}

.timeline-track {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
}

.timeline-track-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 12px;
}

.timeline-points {
  position: relative;
  height: 16px;
  background: var(--timeline-track);
  border-radius: 4px;
  min-width: 100%;
}

.timeline-kf {
  position: absolute;
  top: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid #0f67a9;
  background: #56baff;
  transform: translateX(-50%);
  cursor: ew-resize;
}

.timeline-kf.animated {
  box-shadow: 0 0 0 1px #67ffac inset;
}

.timeline-kf.selected-kf {
  outline: 2px solid #fff;
}

.timeline-kf.multi-selected {
  box-shadow: 0 0 0 2px #ffd166 inset;
}

.timeline-selection-box {
  position: absolute;
  border: 1px dashed #9ad1ff;
  background: rgba(74, 168, 255, 0.15);
  pointer-events: none;
  z-index: 50;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface);
}

.panel h3 {
  margin: 0 0 10px;
}

.panel label {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 13px;
}

.panel input,
.panel textarea,
.panel select,
.panel button {
  width: 100%;
  box-sizing: border-box;
  background: var(--control-bg);
  color: var(--text);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  padding: 6px 8px;
}

.project-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}

#save-indicator.is-saving {
  color: #f2b94b;
}

.layers-list {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.layer-row {
  text-align: left;
}

.layer-row-selected {
  border-color: #67b7ff;
}

.panel-muted {
  color: #9a9a9a;
  font-size: 13px;
}

#stage {
  position: relative;
  width: 100%;
  height: 500px;
  border: 1px solid var(--border);
  background:
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 30px 30px,
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 30px 30px,
    var(--stage-bg);
  overflow: hidden;
}

#stage.stage-interactive {
  cursor: default;
}

.layer {
  position: absolute;
  min-width: 20px;
  min-height: 20px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  transform-origin: center center;
  will-change: transform, opacity;
  display: grid;
  place-items: center;
  font-weight: bold;
  user-select: none;
  cursor: pointer;
  transition: filter 80ms linear;
}

.layer.selected {
  outline: 3px solid #67b7ff;
  outline-offset: 2px;
}

.layer.hovered {
  filter: brightness(1.1);
}

.selection-overlay {
  position: absolute;
  border: 2px solid #67b7ff;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 30;
}

.selection-overlay.group {
  border-style: dashed;
}

.rotate-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #ffcc33;
  border: 1px solid #7f6500;
  border-radius: 50%;
  left: 50%;
  top: -28px;
  transform: translateX(-50%);
  cursor: grab;
  pointer-events: auto;
}

.guide {
  position: absolute;
  background: #4aa8ff;
  pointer-events: none;
  z-index: 40;
}

.guide-v {
  width: 1px;
  top: 0;
  bottom: 0;
}

.guide-h {
  height: 1px;
  left: 0;
  right: 0;
}

.resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #67b7ff;
  border: 1px solid #0b4e8a;
  border-radius: 2px;
  pointer-events: auto;
}

.handle-nw {
  left: -6px;
  top: -6px;
  cursor: nwse-resize;
}

.handle-ne {
  right: -6px;
  top: -6px;
  cursor: nesw-resize;
}

.handle-sw {
  left: -6px;
  bottom: -6px;
  cursor: nesw-resize;
}

.handle-se {
  right: -6px;
  bottom: -6px;
  cursor: nwse-resize;
}
