/* Immersive Media Feed Layout */
body {
  padding-bottom: 0 !important;
  overscroll-behavior-y: none;
  background-color: #000;
}
html, body {
  height: 100%;
  overflow: hidden;
}

#container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  background: #000;
}

#feed-container {
  position: absolute;
  inset: 0;
}

.video-start-cover {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000 center / contain no-repeat;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 160ms ease, visibility 0s linear 160ms;
}
.video-start-cover.is-visible {
  opacity: 1;
  visibility: visible;
  transition: none;
}
.video-start-cover-spinner {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  opacity: 0;
  animation: flow-state-spin 0.8s linear infinite;
  transition: opacity 140ms ease;
}
.video-start-cover.is-waiting .video-start-cover-spinner { opacity: 1; }

.flow-state {
  position: fixed;
  inset: 0;
  z-index: 230;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: rgba(255, 255, 255, 0.96);
  background: rgba(0, 0, 0, 0.34);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}
.flow-state.is-visible {
  opacity: 1;
  pointer-events: auto;
}
.flow-state-card {
  width: min(100%, 310px);
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 20px;
  text-align: center;
  background: rgba(24, 24, 23, 0.9);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.3), inset 0 1px rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transform: translateY(7px) scale(0.98);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}
.flow-state.is-visible .flow-state-card { transform: translateY(0) scale(1); }
.flow-state-spinner {
  width: 22px;
  height: 22px;
  margin: 0 auto 12px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: rgba(255, 255, 255, 0.86);
  border-radius: 50%;
  animation: flow-state-spin 0.8s linear infinite;
}
.flow-state:not([data-kind="loading"]) .flow-state-spinner { display: none; }
.flow-state-title { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.flow-state-detail { margin-top: 6px; color: rgba(255, 255, 255, 0.55); font-size: 12px; line-height: 1.55; }
.flow-state-actions { display: flex; justify-content: center; gap: 8px; margin-top: 16px; }
.flow-state-actions[hidden] { display: none; }
.flow-state-btn {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.88);
  background: rgba(255, 255, 255, 0.07);
  font-size: 12px;
  font-weight: 620;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.flow-state-btn.primary { color: #181817; background: #f5f4ef; border-color: #f5f4ef; }
.flow-state-btn[hidden] { display: none; }
@keyframes flow-state-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .flow-state, .flow-state-card { transition-duration: 0.01ms; }
  .flow-state-spinner { animation-duration: 1.6s; }
  .video-start-cover { transition-duration: 0.01ms; }
  .video-start-cover-spinner { animation-duration: 1.6s; }
}

.feed-media {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.feed-media.active {
  display: block;
}
.feed-image-group {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  top: 0;
  left: 0;
  transform: none;
  z-index: 9;
  pointer-events: none;
}
.feed-image-group.active {
  display: block;
}
.image-group-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}
.image-group-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  opacity: 1;
  transform: translateX(0);
  transition: opacity 0.18s ease, transform 0.22s ease;
}
/* Gallery position, and a memory's month, sit quietly where a caption would. */
.image-group-overlay {
  position: absolute;
  left: 18px;
  bottom: calc(28px + env(safe-area-inset-bottom));
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: rgba(255, 255, 255, 0.82);
  font: 600 14px/1.3 system-ui, -apple-system, sans-serif;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
}
.image-group-counter {
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

.flow-mode {
  position: absolute;
  top: calc(21px + env(safe-area-inset-top));
  left: 16px;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  color: rgba(255, 255, 255, 0.86);
  font: 600 13px/1.4 system-ui, -apple-system, sans-serif;
  text-decoration: none;
  transition: opacity 0.2s ease;
}
.flow-mode[hidden] { display: none; }
body.immersive-mode .flow-mode {
  opacity: 0;
  pointer-events: none;
}

#overlay-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Double-tap favorite: a heart blooms where the finger landed, then drifts up. */
.tap-heart {
  position: fixed;
  z-index: 240;
  width: 92px;
  height: 92px;
  margin: -46px 0 0 -46px;
  color: #e8735a;
  pointer-events: none;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.32));
  animation: tap-heart 760ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.tap-heart svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}
@keyframes tap-heart {
  0% { opacity: 0; transform: rotate(var(--tilt)) scale(0.4); }
  18% { opacity: 1; transform: rotate(var(--tilt)) scale(1.12); }
  32% { transform: rotate(var(--tilt)) scale(0.96); }
  46% { opacity: 1; transform: rotate(var(--tilt)) scale(1); }
  100% { opacity: 0; transform: rotate(var(--tilt)) translateY(-64px) scale(0.86); }
}
@media (prefers-reduced-motion: reduce) {
  .tap-heart { animation-duration: 420ms; }
}

#play-status-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  width: 80px;
  height: 80px;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  pointer-events: none;
  z-index: 15;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}
#play-status-icon.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.1);
}

#custom-controls {
  position: absolute;
  bottom: calc(84px + env(safe-area-inset-bottom));
  left: 12px;
  right: 12px;
  height: 32px;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 1;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-container {
  position: relative;
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
}

input[type=range] {
  -webkit-appearance: none;
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  z-index: 2;
  cursor: pointer;
  margin: 0;
}
input[type=range]:disabled {
  cursor: default;
}

.progress-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  transition: all 0.2s ease;
  pointer-events: none;
}

.progress-fill {
  position: absolute;
  left: 0;
  height: 4px;
  background: #fff;
  border-radius: 2px;
  width: 0%;
  transition: width 0.1s linear, height 0.2s ease;
  pointer-events: none;
  z-index: 1;
}

.progress-fill::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%) scale(0);
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.time-display {
  color: rgba(255, 255, 255, 0.9);
  font-size: 11px;
  font-family: system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  width: 35px;
  text-align: center;
  opacity: 1;
  transition: opacity 0.2s;
}

body.immersive-mode #custom-controls {
  /* Keep the touch target clear of the system home gesture. */
  bottom: max(6px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  padding: 0;
  gap: 0;
}

body.immersive-mode .progress-track {
  height: 2px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 0;
}

body.immersive-mode .progress-fill {
  height: 2px;
  border-radius: 0;
}

body.immersive-mode .time-display {
  opacity: 0;
  width: 0;
  overflow: hidden;
  margin: 0;
}

body:not(.immersive-mode) .progress-fill::after,
#custom-controls.is-seeking .progress-fill::after {
  transform: translateY(-50%) scale(1);
}
#custom-controls.is-seeking .progress-track,
#custom-controls.is-seeking .progress-fill {
  height: 6px;
}

body.immersive-mode .controls-sidebar {
  opacity: 0;
  pointer-events: none;
  transform: translateX(20px);
}
body.immersive-mode .floating-dock {
  transform: translate(-50%, 150%) !important;
}
.controls-sidebar {
  position: absolute;
  right: 16px;
  bottom: calc(140px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 20;
  align-items: center;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.action-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  text-decoration: none;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.2s;
  cursor: pointer;
  position: relative;
}
.action-btn:active {
  transform: scale(0.9);
}
.action-btn svg {
  width: 24px;
  height: 24px;
  stroke-width: 2;
}

.speed-btn {
  font-size: 14px;
  font-weight: 700;
  font-family: system-ui, -apple-system, sans-serif;
}
.speed-btn.is-changed {
  background: rgba(255, 255, 255, 0.28);
  border-color: rgba(255, 255, 255, 0.7);
}
/* Speed choices open to the left in one row, level with the button. */
.zoom-options.speed-options {
  flex-direction: row;
  bottom: 2px;
}
.speed-options .zoom-btn {
  font-size: 10px;
}

/* Transient feedback for hold-to-speed and seeking. */
#flow-hud {
  position: absolute;
  top: calc(84px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fff;
  font: 600 13px/1.4 system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
  z-index: 30;
  opacity: 0;
  transition: opacity 0.15s ease;
}
#flow-hud.is-visible {
  opacity: 1;
}

@keyframes heart-burst {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}
.action-btn.is-active .heart-filled {
  display: block;
  color: #e8735a;
  animation: heart-burst 0.3s forwards;
}
.action-btn.is-active .heart-outline {
  display: none;
}
.heart-filled {
  display: none;
}
.action-btn .collection-count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(24, 24, 22, 0.9);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}
.action-btn.has-collection {
  background: rgba(255, 255, 255, 0.24);
  border-color: rgba(255, 255, 255, 0.72);
}
.action-btn.has-collection .collection-count {
  display: inline-flex;
}

/* Image overlay controls */
.image-tool-wrap {
  position: relative;
}
.zoom-options {
  position: absolute;
  right: 58px;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(8px);
  transition: all 0.2s ease;
}
.zoom-options.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}
.zoom-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(5px);
  color: rgba(255, 255, 255, 0.7);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: all 0.2s ease;
}
.zoom-btn.active {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border-color: white;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.magnifier {
  position: absolute;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  background-repeat: no-repeat;
  background-color: #000;
  cursor: grab;
  z-index: 210;
  display: none;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), width 0.3s ease, height 0.3s ease;
}
.magnifier.magnifier-large {
  width: 300px;
  height: 300px;
}
.magnifier.active {
  display: block;
  transform: translate(-50%, -50%) scale(1);
}
.magnifier:active {
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.02);
}
.mag-badge {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.magnifier.active .mag-badge {
  opacity: 1;
}

.caption-panel {
  position: fixed;
  left: 20px;
  bottom: 90px;
  max-width: min(72vw, 420px);
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  color: white;
  backdrop-filter: blur(10px);
  z-index: 215;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.caption-title {
  font-size: 14px;
  line-height: 1.4;
  font-weight: 600;
}
.caption-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.caption-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.86);
}
.caption-panel.is-hidden {
  display: none;
}
body.immersive-mode .caption-panel:not(.is-hidden) {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
}

#caption-btn.is-loading::after {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  border-top-color: transparent;
  animation: caption-spin 0.9s linear infinite;
}
#caption-btn {
  position: relative;
}
#caption-btn.is-loading i {
  opacity: 0.35;
}
#caption-btn.is-error::after {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 999px;
  border: 1.5px solid rgba(248, 113, 113, 0.9);
}
@keyframes caption-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 640px) {
  .caption-panel {
    max-width: min(82vw, 320px);
    left: 12px;
  }
}

.collection-modal {
  position: fixed;
  inset: 0;
  z-index: 260;
  background: rgba(24, 24, 22, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s;
}
.collection-modal.active {
  opacity: 1;
  pointer-events: auto;
}
.collection-modal-card {
  width: min(440px, 100%);
  border-radius: 14px;
  border: 1px solid rgba(150, 146, 136, 0.28);
  background: rgba(255, 255, 255, 0.98);
  color: #23231f;
  box-shadow: 0 24px 80px rgba(24, 24, 22, 0.3);
  padding: 12px;
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.collection-modal.active .collection-modal-card {
  transform: translateY(0);
}
[data-theme="dark"] .collection-modal-card {
  background: rgba(24, 24, 22, 0.98);
  border-color: rgba(150, 146, 136, 0.2);
  color: #f5f3ee;
}
.collection-modal-header {
  margin-bottom: 10px;
}
.collection-modal-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.collection-modal-header h3 {
  font-size: 14px;
  font-weight: 700;
}
.collection-modal-meta {
  margin-top: 4px;
  font-size: 11px;
  color: #7a766c;
}
[data-theme="dark"] .collection-modal-meta {
  color: #a19d93;
}
.collection-modal-close {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid rgba(150, 146, 136, 0.28);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.collection-modal-close svg {
  width: 15px;
  height: 15px;
}
.collection-modal-create {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.collection-modal-create input {
  flex: 1;
  min-width: 0;
  border-radius: 10px;
  border: 1px solid rgba(150, 146, 136, 0.32);
  background: rgba(248, 250, 252, 0.86);
  color: #23231f;
  font-size: 13px;
  padding: 8px 10px;
}
[data-theme="dark"] .collection-modal-create input {
  background: rgba(24, 24, 22, 0.82);
  color: #efece5;
  border-color: rgba(150, 146, 136, 0.2);
}
.collection-modal-create button {
  border-radius: 10px;
  border: 1px solid rgba(150, 146, 136, 0.3);
  background: rgba(24, 24, 22, 0.9);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 12px;
}
[data-theme="dark"] .collection-modal-create button {
  background: rgba(244, 241, 234, 0.94);
  color: #23231f;
}
.collection-modal-list {
  max-height: min(44vh, 320px);
  overflow: auto;
  border: 1px solid rgba(150, 146, 136, 0.24);
  border-radius: 10px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(248, 250, 252, 0.78);
}
[data-theme="dark"] .collection-modal-list {
  background: rgba(24, 24, 22, 0.76);
  border-color: rgba(150, 146, 136, 0.2);
}
.collection-modal-item {
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.collection-modal-item:hover {
  background: rgba(150, 146, 136, 0.12);
}
.collection-modal-item.is-pending {
  opacity: 0.6;
  pointer-events: none;
}
.collection-modal-item.is-selected {
  background: rgba(189, 91, 61, 0.07);
}
.collection-modal-item input[type="checkbox"] {
  position: absolute; opacity: 0; width: 0; height: 0;
}
.collection-modal-item span.coll-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
em.coll-count {
  font-style: normal;
  font-size: 11px;
  color: #a19d93;
  flex-shrink: 0;
}
.coll-icon {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: rgba(150, 146, 136, 0.12);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: #7a766c;
}
.coll-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 1.5px solid rgba(150, 146, 136, 0.45);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.coll-check svg { display: none; color: white; }
.collection-modal-item.is-selected .coll-check {
  background: #bd5b3d;
  border-color: #bd5b3d;
}
.collection-modal-item.is-selected .coll-check svg { display: block; }
.collection-modal-empty {
  text-align: center;
  font-size: 12px;
  color: #7a766c;
  padding: 14px 8px;
}
[data-theme="dark"] .collection-modal-empty {
  color: #a19d93;
}
.coll-drag-handle {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: rgba(150, 146, 136, 0.35);
  margin: 12px auto 16px;
  display: none;
}
@media (max-width: 540px) {
  .collection-modal {
    align-items: flex-end;
    padding: 0;
  }
  .collection-modal-card {
    width: 100%;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    padding: 0 12px 24px;
  }
  .collection-modal.active .collection-modal-card {
    transform: translateY(0);
  }
  .coll-drag-handle { display: block; }
}
