/* Global layout */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #eee;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    sans-serif;
  /* Отключаем выделение текста и системные меню (особенно на iOS/iPadOS) */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body.clean-mode .subtle-button,
body.clean-mode #background-panel,
body.clean-mode #panel-toggle,
body.clean-mode #spotlight-controls {
  opacity: 0 !important;
  pointer-events: none !important;
}

body.ui-hidden .subtle-button,
body.ui-hidden #background-panel,
body.ui-hidden #panel-toggle,
body.ui-hidden #spotlight-controls {
  opacity: 0 !important;
  pointer-events: none !important;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* Stage / background */
#stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
}

#background-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
}

.background-item {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.45s ease-in-out;
}

.background-item.active {
  opacity: 1;
}

.background-item img,
.background-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.background-item video {
  object-position: center center;
  /* Небольшое увеличение яркости для компенсации затемнения от canvas */
  filter: brightness(1.15);
}

/* Spotlight canvas */
#spotlight-canvas {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  touch-action: none;
}

/* Left background panel */
#background-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 18%;
  min-width: 220px;
  max-width: 340px;
  background: rgba(8, 8, 10, 0.92);
  backdrop-filter: blur(10px);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.35s ease, opacity 0.25s ease;
  z-index: 10;
}

#background-panel.collapsed {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

.panel-header,
.panel-footer {
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
}

.panel-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.panel-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.7;
}

.panel-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  justify-content: flex-end;
}

.background-list {
  padding: 0.5rem;
  overflow-y: auto;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

.background-tile {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  min-height: 70px;
  max-height: 70px; /* фиксируем высоту, чтобы тайл не раздувался при dnd */
}

.background-tile::before,
.background-tile::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  height: 0;
  border-radius: 999px;
  pointer-events: none;
}

.background-tile.drop-before::before {
  top: 2px;
  border-top: 2px solid rgba(255, 255, 255, 0.8);
}

.background-tile.drop-after::after {
  bottom: 2px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.8);
}

.background-placeholder {
  border-radius: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.4);
  background: transparent;
  min-height: 70px;
  max-height: 70px;
}

.bg-drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.7);
  opacity: 0.95;
  border-radius: 8px;
  overflow: hidden;
}

.background-tile img,
.background-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.background-tile .tile-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.25rem 0.4rem;
  font-size: 0.7rem;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.8),
    rgba(0, 0, 0, 0.1)
  );
}

.background-tile .tile-key-badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 0.15rem 0.35rem;
  font-size: 0.65rem;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.9);
  z-index: 2;
  pointer-events: none;
}

.background-tile.active {
  border-color: rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.3);
}

.background-tile.add-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.7);
}

/* Edge tab to toggle panel */
.edge-tab {
  position: absolute;
  left: 12px;
  top: 52px;
  transform: none;
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.7rem;
  z-index: 11;
}

/* Floating UI overlay */
#ui-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.corner-button {
  position: absolute;
  top: 10px;
  right: 10px;
  margin-left: 8px;
}

#fullscreen-toggle {
  right: 10px;
  top: auto;
  bottom: 10px;
}

#bg-cycle-controls {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  gap: 4px;
  pointer-events: auto;
}

.subtle-button {
  pointer-events: auto;
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.35);
  color: #f5f5f5;
  font-size: 0.75rem;
  opacity: 0.18;
  transition: opacity 0.25s ease, background 0.25s ease,
    transform 0.15s ease, border-color 0.25s ease;
  outline: none;
}

.subtle-button:hover,
.subtle-button:focus-visible {
  opacity: 0.8;
  background: rgba(0, 0, 0, 0.6);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-1px);
}

.panel-button {
  font-size: 0.75rem;
}

/* Spotlight mini-controls */
.spotlight-controls {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(12px);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
  pointer-events: auto;
  opacity: 0.45; /* немного заметнее даже на тёмном фоне */
  transition: opacity 0.25s ease;
}

.spotlight-controls:hover {
  opacity: 0.9;
}

.spotlight-controls.active {
  opacity: 0.9;
}

.spotlight-controls.hidden {
  display: none;
}

.mini-button {
  border-radius: 999px;
  padding: 0.15rem 0.45rem;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  line-height: 1;
}

.color-palette {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
}

.color-palette.hidden {
  display: none;
}

.color-swatch {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.4);
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6);
}

/* Drag and drop overlay hint */
body.drag-over #stage::after {
  content: "Drop image or video to add as background";
  position: absolute;
  inset: 20% 15%;
  border: 2px dashed rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.8);
  background: rgba(0, 0, 0, 0.4);
  pointer-events: none;
  z-index: 50;
}

/* Utility */
.hidden {
  display: none;
}

/* Responsive tweaks */
@media (max-width: 768px) {
  #background-panel {
    width: 60%;
    min-width: 0;
  }

  .background-tile .tile-label {
    font-size: 0.65rem;
  }
}


