/* Nighty Design: the Motion timeline (public/assets/js/designer/motion/). A calm glass dock along the bottom of the
   canvas, the keyframe diamonds of the Design panel, the easing popover and the animation export dialog. Uses the
   shell's tokens (designer.css); everything here is prefixed dz-motion. */

/* ---------- the dock ---------- */
.dz-motion {
  --dz-motion-names: 176px;
  --dz-motion-row: 28px;
  --dz-motion-ruler: 26px;
  --dz-motion-key: 18px;
  position: relative;
  display: flex;
  flex-direction: column;
  height: min(var(--dz-motion-h, 236px), 46vh);
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  background: var(--dz-surface-strong);
  -webkit-backdrop-filter: var(--dz-blur);
  backdrop-filter: var(--dz-blur);
  box-shadow: var(--dz-shadow-float);
}

.dz-motion.is-collapsed {
  height: auto;
}

.dz-motion.is-collapsed .dz-motion-body,
.dz-motion.is-collapsed .dz-motion-resize {
  display: none;
}

.dz-motion:focus {
  outline: none;
}

/* The top edge resizes the dock. */
.dz-motion-resize {
  position: absolute;
  top: 0;
  left: 24px;
  right: 24px;
  z-index: 6;
  height: 6px;
  cursor: ns-resize;
  touch-action: none;
}

.dz-motion-head {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 5px 6px 5px 8px;
  border-bottom: 1px solid var(--dz-line);
  overflow-x: auto;
  scrollbar-width: none;
}

.dz-motion.is-collapsed .dz-motion-head {
  border-bottom: 0;
}

.dz-motion-transport,
.dz-motion-settings,
.dz-motion-tools {
  display: flex;
  flex: none;
  align-items: center;
  gap: 2px;
}

.dz-motion-settings {
  gap: 4px;
  padding-left: 6px;
  border-left: 1px solid var(--dz-line);
}

.dz-motion-play {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--dz-field);
  color: var(--text);
}

.dz-motion-play:hover {
  background: var(--dz-field-hover);
}

.dz-motion-play.is-playing {
  background: var(--accent-soft);
  color: var(--accent);
}

.dz-motion-time {
  min-width: 58px;
  padding: 0 4px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.dz-motion-duration {
  width: 82px;
}

.dz-motion-playback {
  width: 94px;
}

.dz-motion-ease {
  flex: none;
  gap: 5px;
  max-width: 180px;
}

.dz-motion-ease span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dz-motion-spacer {
  display: flex;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

.dz-motion-frame {
  overflow: hidden;
  color: var(--text-3);
  font-size: var(--dz-fs-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- the body: names (left), ruler (top), lanes ---------- */
.dz-motion-stage {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
}

.dz-motion-body {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

/* Over the lanes, not scrolling with them: the playhead and the shade after the end. */
.dz-motion-overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--dz-motion-names);
  right: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
}

.dz-motion-body:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px rgba(var(--dzt-accent-rgb, 255, 92, 168), 0.35);
}

.dz-motion-grid {
  position: relative;
  display: grid;
  grid-template-columns: var(--dz-motion-names) var(--dz-motion-lanes, 600px);
  grid-auto-rows: var(--dz-motion-row);
  grid-template-rows: var(--dz-motion-ruler);
  min-width: 100%;
  min-height: 100%;
}

.dz-motion-rows {
  display: contents;
}

.dz-motion-corner,
.dz-motion-name {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--dz-surface-solid);
  border-right: 1px solid var(--dz-line);
}

.dz-motion-corner {
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border-bottom: 1px solid var(--dz-line);
  color: var(--text-3);
  font-size: var(--dz-fs-sm);
}

.dz-motion-ruler {
  position: sticky;
  top: 0;
  z-index: 4;
  height: var(--dz-motion-ruler);
  border-bottom: 1px solid var(--dz-line);
  background: var(--dz-surface-solid);
  cursor: ew-resize;
  touch-action: none;
  user-select: none;
}

.dz-motion-ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.dz-motion-tick,
.dz-motion-label {
  position: absolute;
  left: var(--x);
  bottom: 0;
}

.dz-motion-tick {
  width: 1px;
  height: 5px;
  background: var(--dz-line-strong);
}

.dz-motion-label {
  height: 100%;
  padding: 4px 0 0 4px;
  border-left: 1px solid var(--dz-line-strong);
  color: var(--text-3);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.dz-motion-end-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--x);
  z-index: 2;
  width: 12px;
  margin-left: -6px;
  cursor: col-resize;
}

.dz-motion-end-handle::after {
  content: '';
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 5px;
  width: 2px;
  border-radius: 1px;
  background: var(--text-3);
}

.dz-motion-head-mark {
  position: absolute;
  top: 2px;
  left: var(--x);
  z-index: 3;
  width: 11px;
  height: 14px;
  margin-left: -5px;
  border-radius: 3px 3px 6px 6px;
  background: var(--accent);
  pointer-events: none;
}

.dz-motion-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--x, 14px);
  width: 1px;
  background: var(--accent);
}

.dz-motion-after {
  position: absolute;
  top: var(--dz-motion-ruler);
  bottom: 0;
  left: var(--x, 0px);
  right: 0;
  background: rgba(0, 0, 0, 0.22);
}

.dz-motion-marquee {
  position: absolute;
  top: var(--y);
  left: var(--x);
  z-index: 3;
  width: var(--w);
  height: var(--h);
  border: 1px solid var(--accent-line);
  border-radius: 3px;
  background: rgba(var(--dzt-accent-rgb, 255, 92, 168), 0.08);
  pointer-events: none;
}

/* Names: a layer (fold, name, +) or one of its properties (name, diamond). */
.dz-motion-name {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 0 4px 0 calc(6px + var(--depth, 0) * 10px);
  border-bottom: 1px solid var(--dz-line);
}

.dz-motion-name.is-selected .dz-motion-layer {
  color: var(--accent);
}

.dz-motion-fold {
  display: grid;
  flex: none;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  cursor: var(--nc-hand, pointer);
}

.dz-motion-fold:hover {
  color: var(--text);
}

.dz-motion-layer {
  flex: 1;
  min-width: 0;
  padding: 0 4px;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: var(--nc-hand, pointer);
}

.dz-motion-add {
  flex: none;
  opacity: 0.55;
}

.dz-motion-name:hover .dz-motion-add,
.dz-motion-add:focus-visible {
  opacity: 1;
}

.dz-motion-prop {
  flex: 1;
  min-width: 0;
  padding-left: 22px;
  overflow: hidden;
  color: var(--text-2);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Lanes: keys as diamonds, the movement between two keys as a line. */
.dz-motion-lane {
  position: relative;
  border-bottom: 1px solid var(--dz-line);
  touch-action: pan-x pan-y;
}

.dz-motion-lane.is-layer {
  background: rgba(var(--dzt-fg-rgb, 255, 255, 255), 0.015);
}

.dz-motion-key {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--x);
  z-index: 1;
  display: grid;
  place-items: center;
  width: var(--dz-motion-key);
  margin-left: calc(var(--dz-motion-key) / -2);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-2);
  cursor: grab;
  touch-action: none;
}

.dz-motion-key svg path {
  fill: var(--dz-surface-solid);
  stroke: currentColor;
  stroke-width: 1.4;
}

.dz-motion-key:hover {
  color: var(--text);
}

.dz-motion-key.is-selected {
  color: var(--accent);
}

.dz-motion-key.is-selected svg path {
  fill: var(--accent);
}

.dz-motion-key.is-summary {
  color: var(--text-3);
}

.dz-motion-key.is-hold svg path {
  stroke-dasharray: 2 1.5;
}

.dz-motion-key:focus-visible {
  outline: none;
}

.dz-motion-key:focus-visible svg {
  filter: drop-shadow(0 0 2px var(--accent));
}

.is-dragging .dz-motion-key {
  cursor: grabbing;
}

.dz-motion-key[data-drag]::after {
  content: attr(data-drag);
  position: absolute;
  bottom: calc(100% - 2px);
  left: 50%;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--dz-surface-solid);
  box-shadow: var(--dz-shadow-pop);
  color: var(--text);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transform: translateX(-50%);
}

.dz-motion-segment {
  position: absolute;
  top: 50%;
  left: var(--x);
  width: var(--w);
  height: 4px;
  margin-top: -2px;
  border-radius: 2px;
  background: rgba(var(--dzt-fg-rgb, 255, 255, 255), 0.12);
  cursor: var(--nc-hand, pointer);
}

.dz-motion-segment::before {
  content: '';
  position: absolute;
  inset: -8px 0;
}

.dz-motion-segment.is-selected {
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent-line);
}

.dz-motion-segment.is-hold {
  background: repeating-linear-gradient(90deg, rgba(var(--dzt-fg-rgb, 255, 255, 255), 0.16) 0 4px, transparent 4px 7px);
}

.dz-motion-segment.is-spring,
.dz-motion-segment.is-back,
.dz-motion-segment.is-elastic,
.dz-motion-segment.is-bounce {
  background: linear-gradient(90deg, rgba(var(--dzt-fg-rgb, 255, 255, 255), 0.12), rgba(var(--dzt-accent-rgb, 255, 92, 168), 0.28));
}

.dz-motion-dot {
  position: absolute;
  top: 50%;
  left: var(--x);
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 1px;
  background: var(--text-3);
  transform: rotate(45deg);
  pointer-events: none;
}

.dz-motion-empty {
  position: absolute;
  inset: calc(var(--dz-motion-ruler) + var(--dz-motion-row) + 12px) 16px auto calc(var(--dz-motion-names) + 16px);
  color: var(--text-3);
  font-size: var(--dz-fs-sm);
  pointer-events: none;
}

/* ---------- keyframe diamonds (the Design panel and the timeline's property rows) ---------- */
.dz-motion-diamond {
  display: grid;
  flex: none;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: 2px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-3);
  cursor: var(--nc-hand, pointer);
}

.dz-motion-diamond:hover {
  background: var(--dz-hover-bg);
  color: var(--text);
}

.dz-motion-diamond:focus-visible {
  outline: none;
  box-shadow: var(--dz-ring);
}

.dz-motion-diamond svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
}

.dz-motion-diamond[data-state='animated'],
.dz-motion-diamond[data-state='mixed'] {
  color: var(--accent);
}

.dz-motion-diamond[data-state='mixed'] svg path {
  fill: var(--accent-soft);
}

.dz-motion-diamond[data-state='key'] {
  color: var(--accent);
}

.dz-motion-diamond[data-state='key'] svg path {
  fill: var(--accent);
}

.dz-motion-diamond:disabled {
  opacity: 0.5;
  cursor: var(--nc-arrow, default);
}

/* Inside a number field it sits after the value. */
.dz-number > .dz-motion-diamond {
  margin-left: -2px;
}

/* ---------- the Motion button in the tool bar ---------- */
.dz-motion-tool {
  margin-left: 2px;
  padding-left: 4px;
  border-left: 1px solid var(--dz-line);
}

.dz-motion-toggle.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- the easing popover ---------- */
.dz-motion-ease-editor {
  display: grid;
  gap: 10px;
  width: min(292px, calc(100vw - 32px));
  padding: 4px;
}

.dz-motion-ease-top {
  display: grid;
  justify-items: center;
  gap: 4px;
}

.dz-motion-ease-curve {
  width: 100%;
  max-width: 260px;
  height: auto;
  border-radius: 10px;
  background: var(--dz-field);
  touch-action: none;
}

.dz-motion-ease-base {
  stroke: var(--dz-line-strong);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  fill: none;
}

.dz-motion-ease-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dz-motion-ease-arm {
  stroke: var(--text-3);
  stroke-width: 1;
}

.dz-motion-ease-handle {
  fill: var(--dz-surface-solid);
  stroke: var(--accent);
  stroke-width: 2;
  cursor: grab;
}

.dz-motion-ease-handle[hidden],
.dz-motion-ease-arm[hidden] {
  display: none;
}

.dz-motion-ease-name {
  color: var(--text);
  font-weight: 700;
}

.dz-motion-ease-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.dz-motion-ease-group {
  grid-column: 1 / -1;
  margin-top: 4px;
  color: var(--text-3);
  font-size: var(--dz-fs-sm);
}

.dz-motion-ease-choice {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-height: 40px;
  padding: 3px 2px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--dz-field);
  color: var(--text-2);
  font-size: 10px;
  line-height: 1.15;
  cursor: var(--nc-hand, pointer);
}

.dz-motion-ease-choice:hover {
  background: var(--dz-field-hover);
  color: var(--text);
}

.dz-motion-ease-choice[aria-checked='true'] {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--text);
}

.dz-motion-ease-mini path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
}

.dz-motion-ease-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
}

.dz-motion-ease-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.dz-motion-ease-fields.is-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.dz-motion-ease-roblox {
  color: var(--text-3);
  font-size: var(--dz-fs-sm);
}

/* ---------- the Animate popover: presets and animation styles ---------- */
.dz-motion-animate-btn {
  flex: none;
  gap: 5px;
}

.dz-motion-animate {
  display: grid;
  gap: 10px;
  width: min(300px, calc(100vw - 32px));
  padding: 4px;
}

.dz-motion-animate:focus {
  outline: none;
}

.dz-motion-presets {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.dz-motion-preset {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
  min-height: 52px;
  padding: 5px 2px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--dz-field);
  color: var(--text-2);
  font-size: 10px;
  line-height: 1.15;
  text-align: center;
  cursor: var(--nc-hand, pointer);
}

.dz-motion-preset:hover:not(:disabled) {
  background: var(--dz-field-hover);
  color: var(--text);
}

.dz-motion-preset:focus-visible {
  border-color: var(--accent-line);
}

.dz-motion-preset:disabled {
  opacity: 0.4;
  cursor: var(--nc-arrow, default);
}

.dz-motion-animate-hint {
  margin: 0;
}

/* Styles: a head with "+", then the shell's style rows (designer.css .dz-style-row). */
.dz-motion-animate-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--dz-line);
}

.dz-motion-animate-head .dz-subhead {
  margin: 0;
}

.dz-motion-animate-styles {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.dz-motion-animate-styles .dz-hint {
  margin: 0;
}

.dz-motion-animate .dz-button-row:has(> [hidden]:only-child) {
  display: none;
}

/* ---------- the export dialog ---------- */
/* One column as wide as the dialog: long code lines scroll inside the code box instead of widening it. */
.dz-motion-export {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.dz-motion-export > .dz-seg {
  justify-self: start;
  width: min(100%, 320px);
}

.dz-motion-export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.dz-motion-export-info {
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.dz-motion-export-result {
  display: grid;
  gap: 10px;
  justify-items: start;
}

.dz-motion-export-preview {
  max-width: 100%;
  max-height: 260px;
  border-radius: 10px;
  background: var(--dz-checker);
}

.dz-motion-export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dz-motion-code {
  max-height: 300px;
}

.dz-motion-notes {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
  color: var(--text-2);
  font-size: var(--dz-fs-sm);
}

/* ---------- the shell's toasts float above the open timeline (like the tool bar), never over its keys ---------- */
.designer[data-motion] .dz-toasts {
  bottom: calc(18px + var(--dz-safe-bottom) + var(--dz-keyboard) + var(--dz-dock-h, 0px));
}

/* ---------- touch, phones, reduced motion ---------- */
@media (pointer: coarse) {
  .dz-motion {
    --dz-motion-row: 40px;
    --dz-motion-ruler: 32px;
    --dz-motion-key: 32px;
  }

  .dz-motion-diamond {
    width: 30px;
    height: 30px;
  }

  .dz-motion-fold {
    width: 28px;
    height: 28px;
  }

  .dz-motion-add {
    opacity: 1;
  }
}

.designer[data-layout='phone'] .dz-motion {
  --dz-motion-names: 140px;
  height: var(--dz-motion-h, min(300px, 40vh));
  border-radius: 14px;
  margin: 0 6px;
}

.designer[data-layout='phone'] .dz-motion-frame,
.designer[data-layout='phone'] .dz-motion-resize {
  display: none;
}

.designer[data-layout='phone'] .dz-motion-tools .dz-btn {
  width: 36px;
  height: 36px;
}

/* Phones: the head takes two lines. Play, the time, then fit / export / fold / close; below them the duration, the
   playback, the easing (its icon) and zoom. */
.designer[data-layout='phone'] .dz-motion-head {
  flex-wrap: wrap;
  row-gap: 4px;
  overflow: visible;
}

.designer[data-layout='phone'] .dz-motion-tools {
  display: contents;
}

.designer[data-layout='phone'] .dz-motion-spacer {
  order: 1;
}

.designer[data-layout='phone'] .dz-motion-tools > .dz-btn {
  order: 2;
}

.designer[data-layout='phone'] .dz-motion-settings {
  order: 3;
  padding-left: 0;
  border-left: 0;
}

.designer[data-layout='phone'] .dz-motion-ease {
  order: 4;
}

.designer[data-layout='phone'] .dz-motion-ease span {
  display: none;
}

.designer[data-layout='phone'] .dz-motion-tools > .dz-motion-zoom {
  order: 5;
}

.designer[data-layout='phone'] .dz-motion-tools > .dz-motion-zoom:first-child {
  margin-left: auto;
}

/* The easing editor fills its bottom sheet. */
.designer[data-layout='phone'] .dz-motion-ease-editor {
  width: 100%;
}

/* Animate: only its icon in the head; the popover fills its bottom sheet with bigger tiles. */
.designer[data-layout='phone'] .dz-motion-animate-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
}

.designer[data-layout='phone'] .dz-motion-animate-btn span {
  display: none;
}

.designer[data-layout='phone'] .dz-motion-animate {
  width: 100%;
}

.designer[data-layout='phone'] .dz-motion-preset {
  min-height: 64px;
  font-size: 11px;
}

.designer[data-layout='phone'][data-motion] .dz-toasts {
  bottom: calc(76px + env(safe-area-inset-bottom) + var(--dz-dock-h, 0px));
}

/* The on-screen keyboard hides the dock: toasts go back to their place. */
.designer[data-layout='phone'][data-motion].has-keyboard .dz-toasts {
  bottom: calc(76px + env(safe-area-inset-bottom));
}

@media (prefers-reduced-motion: reduce) {
  .dz-motion *,
  .dz-motion-ease-editor * {
    transition: none !important;
  }
}
