:root {
  --tile-size: 104px;
  --gap: 10px;
  --bg: #12121a;
  --surface: #1e1e2a;
  --surface-active: #2b2b3d;
  --text: #eaeaf2;
  --text-dim: #9a9ab0;
  --accent: #7c6cff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  /* respect notches / home bars */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  flex: 0 0 auto;
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.zoom-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
}
.zoom-toggle:active,
.zoom-toggle.open { color: var(--accent); background: var(--surface); }

.topbar-buttons { display: flex; gap: 4px; align-items: center; }

.zoom-toggle.done {
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  padding: 6px 12px;
}

/* ---------- Edit mode ---------- */
@keyframes jiggle {
  0%, 100% { transform: rotate(-1.4deg); }
  50% { transform: rotate(1.4deg); }
}

body.editing .tile {
  animation: jiggle 0.35s ease-in-out infinite;
  touch-action: none;
  cursor: grab;
}
body.editing .tile:nth-child(2n) { animation-duration: 0.4s; animation-delay: -0.2s; }
body.editing .zoom-toggle:not(#editToggle) { visibility: hidden; }
body.editing .dots { visibility: hidden; }
body.editing .pager { overflow: hidden; }

.tile.drag-source {
  opacity: 0.35;
  animation: none !important;
}

.drag-clone {
  position: fixed;
  z-index: 100;
  margin: 0;
  pointer-events: none;
  animation: none !important;
  transform: scale(1.07);
  background: var(--surface-active);
  border-color: var(--accent);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}

/* ---------- Hidden zoom slider ---------- */
.zoom-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 20px 12px;
  flex: 0 0 auto;
}
.zoom-panel[hidden] { display: none; }

.zoom-label { color: var(--text-dim); font-weight: 700; line-height: 1; }
.zoom-label.small { font-size: 0.7rem; }
.zoom-label.big { font-size: 1.2rem; }

.zoom-panel input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  min-height: 28px; /* comfortable touch target */
}

/* ---------- Swipeable pager ---------- */
.pager {
  flex: 1 1 auto;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.pager::-webkit-scrollbar { display: none; }

.page {
  flex: 0 0 100%;
  width: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  grid-auto-rows: min-content;
  gap: var(--gap);
  padding: 4px 14px 14px;
  align-content: start;
}

/* ---------- Tiles ---------- */
.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-height: var(--tile-size);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.06s ease, background 0.06s ease;
}

.tile:active {
  background: var(--surface-active);
  transform: scale(0.95);
}

.tile.playing {
  background: var(--surface-active);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 18px rgba(124, 108, 255, 0.35);
}

.tile img {
  width: calc(var(--tile-size) * 0.68);
  height: calc(var(--tile-size) * 0.68);
  pointer-events: none;
}

/* ---------- Page dots ---------- */
.dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px 0 14px;
  flex: 0 0 auto;
}

.dots button {
  width: 8px;
  height: 8px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface-active);
  cursor: pointer;
}
.dots button.active { background: var(--accent); }
