.gallery-shell {
  position: relative;
  min-width: 0;
  padding: 20px;
}

.tag-form {
  display: flex;
  align-items: end;
  gap: 10px;
}

.tag-filter-overlay {
  position: sticky;
  top: 12px;
  z-index: 8;
  width: max-content;
  margin-bottom: 12px;
}

.video-sort-overlay {
  position: sticky;
  top: 12px;
  z-index: 8;
  display: flex;
  width: max-content;
  margin: -60px 0 12px auto;
}

.video-sort-overlay[hidden] {
  display: none;
}

.tag-filter-toggle,
.video-sort-toggle {
  position: relative;
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-translucent);
  box-shadow: var(--shadow);
  color: var(--accent-strong);
  backdrop-filter: blur(12px);
}

.tag-filter-toggle:hover,
.tag-filter-toggle:focus-visible,
.tag-filter-toggle.active,
.video-sort-toggle:hover,
.video-sort-toggle:focus-visible,
.video-sort-toggle.active {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 5px var(--focus-ring), var(--shadow);
}

.tag-filter-icon,
.video-sort-icon {
  font-size: 25px;
}

.tag-filter-count,
.video-sort-count {
  position: absolute;
  right: -5px;
  top: -5px;
  display: grid;
  min-width: 20px;
  height: 20px;
  place-items: center;
  border: 2px solid var(--surface);
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.tag-filter-panel,
.video-sort-panel {
  position: fixed;
  top: 96px;
  bottom: 20px;
  width: min(360px, calc(100vw - 40px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 54px rgba(31, 31, 35, 0.18);
  opacity: 0;
  padding: 14px;
  pointer-events: none;
  transform: translateX(-18px);
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease, box-shadow 180ms ease;
  visibility: hidden;
}

.tag-filter-panel {
  left: 20px;
}

.video-sort-panel {
  right: 20px;
  transform: translateX(18px);
}

.tag-filter-overlay.filters-open .tag-filter-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
  visibility: visible;
}

.video-sort-overlay.sort-open .video-sort-panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
  visibility: visible;
}

.tag-filter-panel-head,
.video-sort-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
}

.tag-filter-section,
.video-sort-section {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.tag-filter-section .field,
.tag-filter-section select,
.tag-filter-section input,
.video-sort-section button {
  width: 100%;
}

.tag-filter-section.tag-form {
  grid-template-columns: minmax(0, 1fr) auto;
}

.tag-filter-section-title,
.video-sort-section-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.panel-main-action {
  width: 100%;
  justify-content: center;
}

.tag-filter-options,
.tag-filter-list,
.video-sort-list {
  display: grid;
  gap: 10px;
}

.tag-filter-options {
  margin-bottom: 12px;
}

.tag-filter-favorite {
  gap: 10px;
}

.tag-filter-favorite-icon {
  display: inline-grid;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  font-size: 20px;
  place-items: center;
}

.tag-filter-option,
.tag-filter-check,
.video-sort-option,
.video-sort-direction {
  display: flex;
  align-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 0 0 0 rgba(159, 18, 57, 0);
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 800;
  text-align: left;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease, transform 160ms ease;
}

.tag-filter-option:hover,
.tag-filter-option:focus-visible,
.tag-filter-check:hover,
.tag-filter-check:focus-within,
.video-sort-option:hover,
.video-sort-option:focus-visible,
.video-sort-direction:hover,
.video-sort-direction:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--focus-ring);
  transform: translateX(2px);
}

.tag-filter-option.selected,
.tag-filter-check:has(input:checked),
.video-sort-option.selected,
.video-sort-direction.active {
  border-color: var(--accent);
  background: rgba(159, 18, 57, 0.08);
  box-shadow: inset 3px 0 0 var(--accent), 0 0 0 4px var(--focus-ring);
  color: var(--accent-strong);
}

.video-sort-direction {
  justify-content: space-between;
  gap: 12px;
}

.video-sort-direction .material-symbols-rounded {
  font-size: 22px;
}

.tag-filter-check {
  gap: 12px;
}

.tag-filter-name {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-filter-media-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 24px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 2px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.tag-filter-check:has(input:checked) .tag-filter-media-count {
  border-color: rgba(159, 18, 57, 0.26);
  background: rgba(159, 18, 57, 0.1);
  color: var(--accent-strong);
}

.tag-filter-check input {
  position: relative;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  appearance: none;
  border: 2px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  accent-color: var(--accent);
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.tag-filter-check input::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 7px;
  height: 13px;
  border-right: 3px solid #fff;
  border-bottom: 3px solid #fff;
  opacity: 0;
  transform: rotate(45deg) scale(0.7);
  transition: opacity 120ms ease, transform 120ms ease;
}

.tag-filter-check input:checked {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--focus-ring);
}

.tag-filter-check input:checked::after {
  opacity: 1;
  transform: rotate(45deg) scale(1);
}

.selected-file {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 7px 10px;
  color: var(--muted);
  font-size: 13px;
}

.window-drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  background: var(--drop-overlay-bg);
  color: var(--text);
  text-align: center;
  pointer-events: none;
}

.window-drop-overlay strong,
.window-drop-overlay span {
  display: block;
}

.window-drop-overlay strong {
  font-size: 18px;
}

.window-drop-overlay span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.upload-progress {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.upload-modal {
  width: min(780px, 100%);
}

.upload-modal-body {
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 112px);
  overflow: auto;
  padding: 18px;
}

.upload-modal-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.upload-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.upload-progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.upload-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 160ms ease;
}

.upload-queue {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.upload-item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 8px;
}

.upload-item.uploading {
  border-color: var(--accent);
}

.upload-item.error {
  border-color: var(--danger);
}

.upload-thumb {
  position: relative;
  width: 56px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: calc(var(--radius) - 2px);
  background: var(--surface-strong);
}

.upload-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.upload-thumb video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.upload-item.uploaded .upload-thumb::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(159, 18, 57, 0.78);
}

.upload-item.uploaded .upload-thumb::after {
  content: "";
  position: absolute;
  left: 20px;
  top: 14px;
  width: 13px;
  height: 23px;
  border-right: 4px solid #fff;
  border-bottom: 4px solid #fff;
  transform: rotate(45deg);
}

.upload-item-body {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.upload-item-name,
.upload-item-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-item-name {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.upload-item-meta {
  color: var(--muted);
  font-size: 12px;
}

.upload-item.error .upload-item-meta {
  color: var(--danger);
}

.tag-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tag-checks.vertical {
  display: grid;
  margin-bottom: 12px;
}

.tag-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 6px 9px;
  color: var(--text);
  font-size: 13px;
}

.tag-check input {
  accent-color: var(--accent);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--empty-bg);
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.video-watch-sections {
  display: grid;
  gap: 14px;
  margin-bottom: 22px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px;
}

.video-watch-sections.video-watch-home {
  gap: 26px;
  overflow: visible;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.video-watch-section {
  display: grid;
  min-width: 0;
  gap: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 12px 0 12px 12px;
}

.video-watch-home .video-watch-section {
  overflow: visible;
  border: 0;
  background: transparent;
  padding: 0;
}

.video-watch-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.video-watch-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.video-watch-home .video-watch-head h3 {
  font-size: 18px;
}

.video-watch-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  padding: 0 12px 4px 0;
  scroll-padding-inline: 12px;
  scroll-snap-type: x proximity;
}

.video-watch-home .video-watch-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 18px;
  overflow: visible;
  padding: 0;
  scroll-snap-type: none;
}

.video-watch-card {
  flex: 0 0 clamp(240px, 30vw, 340px);
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 8px;
  text-align: left;
  scroll-snap-align: start;
}

.video-watch-home .video-watch-card {
  min-width: 0;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  align-items: stretch;
  overflow: hidden;
  padding: 0;
  scroll-snap-align: none;
}

.video-watch-card:hover,
.video-watch-card:focus-visible {
  border-color: var(--accent);
}

.video-watch-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: calc(var(--radius) - 2px);
  background: var(--surface-strong);
}

.video-watch-home .video-watch-thumb {
  border-radius: 0;
}

.video-watch-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.video-watch-placeholder {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.video-watch-body {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.video-watch-home .video-watch-body {
  gap: 7px;
  padding: 12px;
}

.video-watch-title,
.video-watch-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-watch-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.video-watch-home .video-watch-title {
  font-size: 14px;
}

.video-watch-meta {
  color: var(--muted);
  font-size: 12px;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.media-grid.video-grid {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 18px;
}

.media-card {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0;
  opacity: 0;
  outline: none;
  translate: 0 0;
  transform: translateY(0);
  animation: photoItemIn both linear;
  animation-timeline: view();
  animation-range: entry 0% cover 25%;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.media-grid.video-grid .media-card {
  aspect-ratio: 16 / 9;
  border-radius: 6px;
}

.media-card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 0.2s ease;
}

.media-card-title {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: linear-gradient(180deg, rgba(31, 31, 35, 0), rgba(31, 31, 35, 0.82));
  color: #fff;
  padding: 22px 10px 9px;
  font-size: 13px;
  font-weight: 800;
  text-align: left;
}

.media-placeholder {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.media-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 1;
  min-height: 26px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius);
  background: rgba(31, 31, 35, 0.78);
  color: #fff;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
}

.media-favorite-badge {
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 3;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  background: transparent;
  color: var(--accent);
  filter: drop-shadow(0 1px 2px rgba(31, 31, 35, 0.34));
  font-size: 22px;
  pointer-events: none;
}

.media-watch-overlay {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 1;
  border-radius: var(--radius);
  background: rgba(31, 31, 35, 0.78);
  color: #fff;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
}

.media-progress {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 34px;
  z-index: 2;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.38);
}

.media-progress span,
.video-watch-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.video-watch-progress {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.media-grid.video-grid .media-badge {
  top: 8px;
  bottom: auto;
}

.media-grid.video-grid .media-favorite-badge {
  top: 42px;
}

.media-card.processing .media-badge {
  background: rgba(109, 84, 20, 0.82);
}

.media-card.failed .media-badge {
  background: rgba(159, 18, 57, 0.86);
}

.media-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(159, 18, 57, 0.08), rgba(109, 15, 40, 0.34));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.media-card:hover,
.media-card:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 14px 30px rgba(159, 18, 57, 0.22);
  transform: translateY(-2px);
}

.media-card:hover::after,
.media-card:focus-visible::after {
  opacity: 1;
}

.media-card:hover img,
.media-card:focus-visible img {
  transform: scale(1.025);
}

.media-sentinel {
  min-height: 32px;
}

@keyframes photoItemIn {
  from {
    opacity: 0;
    translate: 0 5svh;
  }

  to {
    opacity: 1;
    translate: 0 0;
  }
}

@media (max-width: 640px) {
  .gallery-shell {
    padding: 14px;
  }

  .tag-filter-panel {
    left: 14px;
    top: 84px;
    bottom: 14px;
    width: calc(100vw - 28px);
  }

  .video-sort-panel {
    right: 14px;
    top: 84px;
    bottom: 14px;
    width: calc(100vw - 28px);
  }

  .tag-filter-section.tag-form {
    grid-template-columns: 1fr;
  }

  .upload-modal-controls {
    grid-template-columns: 1fr;
  }

  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  }

  .media-grid.video-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }

  .video-watch-home .video-watch-list {
    grid-template-columns: 1fr;
  }
}
