/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border-radius: 0.5rem;
  font-weight: 700;
  font-size: 0.85rem;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1;
}
.btn-lg {
  padding: 0.7rem 1.4rem;
  font-size: 1rem;
}
.btn-icon { font-size: 0.9em; }
.btn-primary {
  background-color: #0ea5e9;
  color: #0d1117;
  box-shadow: 0 4px 14px -4px rgba(14, 165, 233, 0.6);
}
.btn-primary:hover { background-color: #38bdf8; transform: translateY(-1px); }
.btn-primary:disabled {
  background-color: #334155;
  color: #64748b;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-ghost {
  background-color: transparent;
  color: #c9d1d9;
  border-color: #374151;
}
.btn-ghost:hover { border-color: #38bdf8; color: #38bdf8; background-color: rgba(56, 189, 248, 0.05); }
.btn-danger:hover { border-color: #ef4444; color: #f87171; background-color: rgba(239, 68, 68, 0.06); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* Toolbar layout */
.toolbar {
  position: relative;
  /* Must sit above the media grid; backdrop-filter creates its own stacking
     context, so give the whole toolbar a z-index in the root context. */
  z-index: 30;
  padding: 1.1rem 1.1rem 1.25rem;
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.75), rgba(13, 17, 23, 0.75));
  border: 1px solid #1f2937;
  border-radius: 0.85rem;
  backdrop-filter: blur(6px);
}
.tb-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}
.tb-primary-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 1rem;
}
.tb-duration-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}
.per-slide-info {
  font-size: 0.75rem;
  color: #94a3b8;
}

/* Hamburger button (top-left of toolbar) */
.menu-btn {
  position: absolute;
  top: 0.85rem;
  left: 0.85rem;
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  background-color: transparent;
  border: 1px solid #374151;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
  z-index: 5;
}
.menu-btn:hover { border-color: #38bdf8; background-color: rgba(56, 189, 248, 0.06); }
.menu-btn[aria-expanded="true"] { border-color: #38bdf8; background-color: rgba(56, 189, 248, 0.1); }
.menu-icon {
  display: block;
  width: 1.15rem;
  height: 2px;
  background-color: #c9d1d9;
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.15s ease;
}
.menu-btn:hover .menu-icon,
.menu-btn[aria-expanded="true"] .menu-icon { background-color: #38bdf8; }

/* Hamburger dropdown panel */
.menu-panel {
  position: absolute;
  top: calc(0.85rem + 2.5rem + 0.4rem);
  left: 0.85rem;
  min-width: 15rem;
  background-color: #0d1117;
  border: 1px solid #1f2937;
  border-radius: 0.65rem;
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.6);
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  z-index: 20;
}
.menu-panel.hidden { display: none; }
.menu-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.35rem 0.15rem;
  border-top: 1px solid #1f2937;
}
.menu-group:first-child { border-top: none; padding-top: 0.1rem; }
.menu-group-label {
  font-size: 0.65rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0 0.4rem;
  margin-bottom: 0.15rem;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.7rem;
  background-color: transparent;
  border: 1px solid transparent;
  border-radius: 0.4rem;
  color: #c9d1d9;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.menu-item:hover {
  background-color: rgba(56, 189, 248, 0.08);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.3);
}
.menu-item:disabled { opacity: 0.5; cursor: not-allowed; }
.menu-item-danger:hover {
  background-color: rgba(239, 68, 68, 0.08);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}

/* Toolbar controls */
.ctrl {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
}
.ctrl-wide .ctrl-input { min-width: 12rem; }
.ctrl-label {
  font-size: 0.65rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.ctrl-input {
  background-color: #0d1117;
  color: #c9d1d9;
  border: 1px solid #374151;
  border-radius: 0.4rem;
  padding: 0.45rem 0.65rem;
  font-family: inherit;
  font-size: 0.9rem;
  min-width: 8rem;
}
.ctrl-input:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25);
}
#totalDuration { width: 8rem; min-width: 0; text-align: center; }
#videoDuration { width: 7rem; min-width: 0; text-align: center; }

/* Loop toggle */
.loop-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.85rem;
  border: 1px solid #374151;
  border-radius: 0.4rem;
  color: #c9d1d9;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.loop-toggle input {
  accent-color: #38bdf8;
  width: 1rem;
  height: 1rem;
}
.loop-toggle:hover { border-color: #38bdf8; color: #38bdf8; }

@media (max-width: 520px) {
  .menu-panel { min-width: 12rem; left: 0.85rem; right: auto; }
  #totalDuration { width: 100%; }
}

/* Grid tiles */
#grid .tile {
  position: relative;
  aspect-ratio: 1 / 1;
  background-color: #111827;
  border: 1px solid #1f2937;
  border-radius: 0.6rem;
  overflow: hidden;
  cursor: grab;
  user-select: none;
}
#grid .tile:active { cursor: grabbing; }
#grid .tile.sortable-ghost { opacity: 0.35; }
#grid .tile.sortable-chosen { border-color: #38bdf8; box-shadow: 0 0 0 2px rgba(56,189,248,0.35); }
#grid .tile img,
#grid .tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
#grid .tile .badge {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  background: rgba(0,0,0,0.65);
  color: #e5e7eb;
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
#grid .tile .idx {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  background: rgba(14,165,233,0.9);
  color: #0d1117;
  font-weight: 700;
  font-size: 0.75rem;
  padding: 0.1rem 0.45rem;
  border-radius: 0.3rem;
}
#grid .tile .name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.7rem;
  background: linear-gradient(to top, rgba(0,0,0,0.85), rgba(0,0,0,0));
  color: #e5e7eb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#grid .tile .remove-btn {
  position: absolute;
  bottom: 0.35rem;
  right: 0.35rem;
  background: rgba(239,68,68,0.9);
  color: #fff;
  border: none;
  border-radius: 0.3rem;
  padding: 0.15rem 0.45rem;
  font-size: 0.7rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
#grid .tile:hover .remove-btn { opacity: 1; }
#grid .tile .loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #94a3b8; font-size: 0.75rem;
}

/* Player overlay */
#player {
  position: fixed;
  inset: 0;
  background-color: #000;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
/* Tailwind's .hidden loses to #player on specificity, so force it here. */
#player.hidden { display: none !important; }
#stage {
  position: relative;
  flex: 1;
  overflow: hidden;
}
.slide-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 600ms ease, transform 600ms ease;
  will-change: opacity, transform;
}
.slide-layer.active { opacity: 1; z-index: 2; }
.slide-layer.behind { z-index: 1; }
.slide-layer img,
.slide-layer video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Transitions */
.t-fade    .slide-layer                 { transition: opacity 500ms ease; }
.t-cross   .slide-layer                 { transition: opacity 800ms ease; }
.t-slide-l .slide-layer                 { transition: opacity 500ms ease, transform 500ms ease; }
.t-slide-l .slide-layer.enter           { transform: translateX(100%); opacity: 1; }
.t-slide-l .slide-layer.active          { transform: translateX(0); }
.t-slide-l .slide-layer.exit            { transform: translateX(-100%); opacity: 1; }
.t-slide-u .slide-layer                 { transition: opacity 500ms ease, transform 500ms ease; }
.t-slide-u .slide-layer.enter           { transform: translateY(100%); opacity: 1; }
.t-slide-u .slide-layer.active          { transform: translateY(0); }
.t-slide-u .slide-layer.exit            { transform: translateY(-100%); opacity: 1; }
.t-zoom    .slide-layer                 { transition: opacity 600ms ease, transform 600ms ease; }
.t-zoom    .slide-layer.enter           { transform: scale(0.85); opacity: 0; }
.t-zoom    .slide-layer.active          { transform: scale(1); opacity: 1; }
.t-zoom    .slide-layer.exit            { transform: scale(1.15); opacity: 0; }
.t-none    .slide-layer                 { transition: none; }

#playerHud {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(180deg, rgba(13,17,23,0) 0%, rgba(13,17,23,0.85) 55%);
  transition: opacity 0.25s ease;
  z-index: 3;
}
#player.hud-hidden #playerHud {
  opacity: 0;
  pointer-events: none;
}
#player.hud-hidden { cursor: none; }
.hud-btn {
  background: transparent;
  color: #e5e7eb;
  border: 1px solid #374151;
  border-radius: 0.4rem;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  font-family: inherit;
}
.hud-btn:hover { border-color: #38bdf8; color: #38bdf8; }

/* Video export overlay */
.export-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
#exportOverlay.hidden { display: none !important; }
.export-panel {
  background: #0d1117;
  border: 1px solid #1f2937;
  border-radius: 0.85rem;
  padding: 1.5rem 2rem;
  min-width: min(24rem, 90vw);
  max-width: 32rem;
  text-align: center;
  color: #c9d1d9;
  box-shadow: 0 16px 40px -8px rgba(0, 0, 0, 0.8);
}
.export-panel h3 {
  color: #38bdf8;
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}
#exportStatusText {
  font-size: 0.9rem;
  color: #cbd5e1;
  margin-bottom: 0.75rem;
}
.export-progress {
  position: relative;
  height: 12px;
  background: #1f2937;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}
#exportProgressBar {
  position: relative;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0ea5e9, #38bdf8);
  transition: width 0.25s ease;
  overflow: hidden;
  min-width: 4px;
}
#exportProgressBar::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: linear-gradient(
    -45deg,
    rgba(255, 255, 255, 0.28) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, 0.28) 50%,
    rgba(255, 255, 255, 0.28) 75%,
    transparent 75%,
    transparent
  );
  background-size: 22px 22px;
  animation: export-stripes 900ms linear infinite;
}
@keyframes export-stripes {
  from { background-position: 0 0; }
  to   { background-position: 44px 0; }
}
#exportHint {
  font-size: 0.7rem;
  color: #64748b;
  margin-bottom: 1rem;
}
