html {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

:root {
  --bg: #0e0e0e;
  --text: #f1f1f1;
  --container-bg: #1a1a1a;
  --button-bg: #007bff;
  --button-text: #ffffff;
  --button-hover-bg: #0056b3;
  --muted-text: rgba(241, 241, 241, 0.72);
  --menu-button-font-size: 0.92rem;
  --menu-button-padding: 0.45em 0.9em;

  /* Episode tile watch-progress fill (adjust for UX testing) */
  --episode-progress-fill: rgba(76, 175, 80, 0.22);
}
body.light-mode {
  --bg: #f5f5f5;
  --text: #333333;
  --container-bg: #ffffff;
  --muted-text: rgba(51, 51, 51, 0.64);

  /* Episode tile watch-progress fill (adjust for UX testing) */
  --episode-progress-fill: rgba(46, 125, 50, 0.18);
  /* Keep button colors the same or adjust if desired */
}
body {
  -ms-overflow-style: none;
  scrollbar-width: none;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100vh;
}
.container {
  width: 90%;
  max-width: 900px;
  padding: 2em;
  background: var(--container-bg);
  border-radius: 16px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.6);
  text-align: center;
}

#homeMainRegion {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  margin-bottom: 2rem;
  min-height: calc(100vh - 80px);
  padding-top: 1rem;
}

#recentSourcesRail {
  flex: 0 0 auto;
}

.recent-sources {
  /* Home rail */
  position: relative;
  z-index: 5;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;

  /* Poster-style cards */
  --recent-card-width: 180px;
  --recent-card-height: 270px; /* ~2:3 poster */
  --recent-card-gap: 0.9rem;

  padding: 0;
  width: min(980px, 94vw);
  max-width: calc(100vw - 2rem);
  overflow: visible;
  backdrop-filter: none;
  font-size: clamp(0.7rem, 0.55rem + 0.35vw, 0.85rem);
  margin: 0 0 1rem 0;
}

/* Legacy placement attributes are ignored for the Home rail now. */
.recent-sources[data-placement] {
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
  transform: none;
}

.recent-sources[hidden] {
  display: none !important;
}

.recent-sources-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.recent-sources-header h3 {
  margin: 0;
  font-size: 1.1rem;
  text-align: center;
}

.recent-sources-count {
  font-size: 0.85rem;
  color: var(--muted-text);
}

.recent-sources-grid {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: flex-start;
  gap: var(--recent-card-gap);
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.35rem;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

/* Center items only when they don't overflow (toggled by JS). */
.recent-sources-grid.is-centered {
  justify-content: center;
}

.recent-sources-grid::-webkit-scrollbar {
  height: 10px;
}
.recent-sources-grid::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.18);
  border-radius: 999px;
}

.source-card {
  box-sizing: border-box;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 12px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
  padding: 1em;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1em;
  width: 100%;
  min-height: 220px;
}

.source-card.no-thumb {
  flex-direction: column;
  align-items: flex-start;
  min-height: auto;
}

.source-thumb {
  width: 120px;
  height: 180px;
  border-radius: 10px;
  object-fit: cover;
  background: #2a2a2a;
  border: 1px solid #333;
  flex-shrink: 0;
}

.source-right {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35em;
  flex: 1 1 auto;
  text-align: left;
}

.source-right h3 {
  margin: 0;
  font-size: 1.05rem;
}

.source-card p {
  margin: 0.25em 0;
}

.source-time {
  font-size: 0.85em;
  opacity: 0.8;
}

.recent-sources .source-card {
  width: var(--recent-card-width);
  height: var(--recent-card-height);
  flex: 0 0 auto;
  scroll-snap-align: start;

  padding: 0;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.recent-sources .source-card:hover,
.recent-sources .source-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.18);
  box-shadow: 0 10px 26px rgba(0,0,0,0.55);
}

.recent-sources .source-thumb {
  width: clamp(80px, 5vw, 120px);
  height: clamp(120px, 8vw, 170px);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}

.recent-sources .source-right {
  gap: clamp(0.3rem, 0.15rem + 0.35vw, 0.6rem);
  align-self: stretch;
}

.recent-sources .source-right h3 {
  width: 100%;
  font-size: clamp(0.81rem, 0.47rem + 0.51vw, 1.02rem);
  line-height: 1.3;
  padding-bottom: 0.2em;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: clamp(0.2rem, 0.1rem + 0.3vw, 0.45rem);
}

.recent-sources .source-right p {
  font-size: clamp(0.8rem, 0.55rem + 0.35vw, 0.95rem);
}

.recent-sources .source-card:focus-visible {
  outline: 3px solid rgba(99, 179, 237, 0.7);
  outline-offset: 3px;
}

/* Continue rail cards: poster with top/bottom overhang labels */
.recent-sources .source-card.continue-card {
  position: relative;
  overflow: visible; /* allow overhang */
  background: transparent;
  border: none;
  display: block; /* ensure width follows the card (poster), not text */
  /* Make room for the top/bottom overhang labels */
  height: calc(var(--recent-card-height) + 2.6rem);
}

.recent-sources .source-card.continue-card .continue-overlay {
  position: relative;
  inset: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  padding: 0;
  background: none;
  width: 100%;
  box-sizing: border-box;
}

.recent-sources .source-card.continue-card .continue-poster {
  width: 100%;
  height: var(--recent-card-height);
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: 0 12px 26px rgba(0,0,0,0.45);
  box-sizing: border-box;
}
.recent-sources .source-card.continue-card .continue-poster.no-thumb {
  background-image: none !important;
}

.recent-sources .source-card.continue-card .continue-overlay--centered {
  text-align: center;
}

.recent-sources .source-card.continue-card .continue-top {
  width: calc(100% - 1.2rem);
  max-width: calc(100% - 1.2rem);
  font-weight: 900;
  font-size: 0.98rem;
  line-height: 1.15;
  padding: 0.25rem 0.2rem;
  border-radius: 10px;
  background: transparent;
  border: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  z-index: 3;
  margin: 0 auto -0.1rem;
  box-sizing: border-box;
  /* overhang into the poster */
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(0,0,0,0.85);
}

.recent-sources .source-card.continue-card .continue-bottom {
  width: calc(100% - 1.2rem);
  max-width: calc(100% - 1.2rem);
  font-weight: 850;
  font-size: 0.9rem;
  opacity: 0.98;
  padding: 0.2rem 0.2rem;
  border-radius: 10px;
  background: transparent;
  border: none;
  z-index: 3;
  margin: -0.1rem auto 0;
  box-sizing: border-box;
  /* overhang into the poster */
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(0,0,0,0.85);
}

video {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 1em;
}
.mm-video-frame {
  position: relative;
  width: 100%;
  margin-bottom: 1em;
}
.mm-video-frame > video {
  display: block;
  margin-bottom: 0;
}
.mm-video-stack {
  display: grid;
  margin-bottom: 1em;
}
.mm-video-stack > video {
  grid-area: 1 / 1;
  margin-bottom: 0;
}
.mm-video-hidden {
  opacity: 0;
  pointer-events: none;
}
button, input[type="text"], input[type="password"] {
  padding: 0.6em 1.2em;
  font-size: 1rem;
  border-radius: 8px;
  border: none;
  margin: 0.5em;
  background: var(--button-bg);
  color: var(--button-text);
}
button {
  cursor: pointer;
  transition: background 0.3s;
}
button:hover {
  background: var(--button-hover-bg);
}
#nextBtn {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 5;
  margin: 0;
  padding: 0.6em 1.4em;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--button-text);
  font-weight: 650;
  backdrop-filter: blur(8px);
}
#nextBtn:hover {
  background: rgba(0, 0, 0, 0.72);
}
#nextBtn:focus-visible {
  outline: 3px solid rgba(99, 179, 237, 0.7);
  outline-offset: 3px;
}
#selectorScreen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1em;
}
#episodeList {
  width: 100%;
  max-width: 1100px;
  --tile-scale: 1;
  --movie-span: 2;
  display: grid;
  /* Use auto-fill so the grid keeps "full-row" sizing even when there are few items */
  grid-template-columns: repeat(auto-fill, minmax(calc(120px * var(--tile-scale)), 1fr));
  gap: calc(0.75rem * var(--tile-scale));
  align-items: stretch;
}
#episodeList.single-tile {
  --tile-scale: 1.5;
  max-width: 100%;
  grid-template-columns: repeat(auto-fill, minmax(calc(140px * var(--tile-scale)), 1fr));
}
.episode-button.movie-tile {
  aspect-ratio: 2 / 3;
  grid-column: span var(--movie-span);
}
@media (max-width: 520px) {
  #episodeList {
    --movie-span: 1;
  }
}
.category-title {
  font-size: 1.2em;
  font-weight: bold;
  margin-top: 0.75em;
  margin-bottom: 0.25em;
  grid-column: 1 / -1;
  text-align: center;
}
.episode-button {
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: calc(0.8rem * var(--tile-scale));
  background: #1f1f1f;
  border-radius: calc(12px * var(--tile-scale));
  border: 1px solid rgba(255,255,255,0.08);
  transition: all 0.25s ease;
  cursor: pointer;
  text-align: center;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: stretch;
  gap: calc(0.4rem * var(--tile-scale));
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
}

/* Watch-progress fill bar behind tile contents (injected by scripts/list.js) */
.episode-button .episode-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: var(--episode-progress-fill);
  pointer-events: none;
  z-index: 0;
}

/* Completed items: stronger "fully done" green */
.episode-button.episode--complete .episode-progress-fill {
  background: rgba(76, 175, 80, 0.45);
}
body.light-mode .episode-button.episode--complete .episode-progress-fill {
  background: rgba(46, 125, 50, 0.35);
}
.episode-button > * {
  position: relative;
  z-index: 1;
}
.episode-button.single-center {
  grid-column: 1 / -1;
  justify-self: center;
  max-width: 220px;
}
.episode-button:hover {
  border-color: #3a82ff;
  background-color: #262a35;
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(0,0,0,0.32);
}
.episode-button.separated-category {
  font-weight: 600;
}
.episode-button.episode--unavailable {
  border-color: rgba(255, 140, 140, 0.45);
  background:
    linear-gradient(180deg, rgba(120, 35, 35, 0.52), rgba(70, 18, 18, 0.72)),
    repeating-linear-gradient(-45deg, rgba(255,255,255,0.04) 0 12px, rgba(0,0,0,0.05) 12px 24px);
}
.episode-button.episode--unavailable:hover {
  border-color: rgba(255, 170, 170, 0.75);
  background:
    linear-gradient(180deg, rgba(145, 38, 38, 0.62), rgba(86, 20, 20, 0.82)),
    repeating-linear-gradient(-45deg, rgba(255,255,255,0.05) 0 12px, rgba(0,0,0,0.06) 12px 24px);
}
.episode-button.episode--unavailable .episode-meta {
  color: #ffd7d7;
  font-weight: 700;
}
.episode-title {
  font-size: calc(0.98em * var(--tile-scale));
  line-height: 1.25;
  width: 100%;
  color: var(--text);
  word-break: break-word;
  min-height: 0;
}
.episode-button.episode--numbered .episode-title {
  font-size: calc(0.85em * var(--tile-scale));
  letter-spacing: 0.05em;
  text-transform: uppercase;
  opacity: 0.85;
}
.episode-number {
  font-size: calc(2.4em * var(--tile-scale));
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  width: 100%;
  color: var(--text);
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.episode-count {
  color: #cbd1dd;
  font-size: calc(0.95em * var(--tile-scale));
  font-weight: 700;
  width: 100%;
  text-align: center;
  padding-top: calc(0.15rem * var(--tile-scale));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.episode-long {
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 700;
  font-size: calc(1.05em * var(--tile-scale));
  line-height: 1.15;
  word-break: break-word;
  overflow-wrap: anywhere;
  padding: 0 calc(4px * var(--tile-scale));
  min-height: 0;
}

.episode-meta {
  color: #cbd1dd;
  font-size: calc(0.95em * var(--tile-scale));
  width: 100%;
  text-align: center;
  margin-top: auto;
  padding-top: calc(0.45rem * var(--tile-scale));
  border-top: 1px solid rgba(255,255,255,0.08);
  min-height: calc(1.35em * var(--tile-scale));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.episode-tooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  background: #111;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.8em;
  color: #f1f1f1;
  box-shadow: 0 6px 14px rgba(0,0,0,0.4);
  pointer-events: none;
  white-space: pre-line;
  display: none;
  z-index: 5;
  max-width: 280px;
}
#episodeList .empty-state {
  padding: 1em;
  text-align: center;
  opacity: 0.7;
  grid-column: 1 / -1;
}
#urlInputContainer {
  display: none;
  flex-direction: column;
  align-items: center;
}
#urlInput {
  width: 100%;
  max-width: 600px;
}
#errorMessage {
  display: none;
  color: #ff4444;
  font-weight: bold;
  margin-bottom: 1em;
}
#directoryTitle {
  color: var(--text) !important;
  font-weight: bold;
  font-size: clamp(2rem, 3.125vw + 0.5rem, 3.25rem);
  margin: 0;
  display: none; /* revealed with header */
  text-align: center;
  flex: 1 1 0;
  min-width: 0;
  line-height: 1.2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.35rem;
}

/* Title + poster header */
.directory-header {
  display: none; /* revealed when source loads */
  margin-bottom: 1em;
  position: relative;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 180px;
  padding: 0;
  gap: 24px;
  flex-direction: row;
  flex-wrap: wrap;
  max-width: min(720px, 100%);
  margin: 0 auto;
  border-radius: 20px;
  justify-content: center;
}

#directoryPoster {
  display: none; /* only if Image present */
  height: 252px;
  width: auto;
  max-width: 360px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid #333;
  background: #2a2a2a;
  flex: 0 0 auto;
  order: 2;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  z-index: 0;
  align-self: center;
}

#directoryHeader {
  position: relative;
  z-index: 0;
}
header {
  font-size: 0.9em;
  color: #aaa;
  margin: 1em auto 0;
  text-align: center;
  max-width: min(960px, 100%);
  width: 100%;
  padding: 0;
}

.account-header-line {
  font-size: 0.85em;
  color: #8f8f8f;
  margin: 0.2em auto 0.8em;
  text-align: center;
  max-width: min(960px, 100%);
  width: 100%;
  padding: 0 1rem;
  box-sizing: border-box;
}

.site-title-link,
.site-title-link:visited,
.site-title-link:hover,
.site-title-link:active {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  display: block;
  width: 100%;
}

.site-title-link:focus-visible {
  outline: 2px solid var(--button-bg);
  outline-offset: 4px;
  border-radius: 10px;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 1001;
  background: #111;
  border-bottom: 1px solid #1f1f1f;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35em 1rem;
  box-sizing: border-box;
  min-height: 64px;
  width: 100%;
  left: 0;
  right: 0;
}

 .toolbar-actions {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 0.4em;
}

.toolbar-actions--left {
  right: 5rem;
  left: auto;
}

.toolbar-actions--right {
  right: 1rem;
  left: auto;
}

.toolbar-actions button {
  width: 2.5em;
  height: 2.5em;
  border-radius: 6px;
  background: var(--button-bg);
  color: var(--button-text);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2em;
  transition: background 0.2s, transform 0.1s;
}

.toolbar-actions button:hover {
  background: var(--button-hover-bg);
}

.toolbar-actions button:active {
  transform: scale(0.96);
}

.toolbar .dropdown-content {
  z-index: 1002;
}

@media (max-width: 768px) {
  .directory-header {
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 0 1rem;
    margin: 0 auto;
  }
  #directoryPoster {
    max-width: 280px;
    width: min(80vw, 280px);
    height: auto;
    align-self: center;
    order: -1;
  }
  #directoryTitle {
    text-align: center;
    max-width: 100%;
    width: 100%;
    flex: unset;
  }
  .toolbar-actions--left {
    right: auto;
    left: 1rem;
  }
  .toolbar-actions--right {
    right: 1rem;
    left: auto;
  }
}

/* Nav tabs and dropdown */
.tabs {
  display: flex;
  gap: 0.5em;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  flex: 1;
}
.tab-button {
  padding: 0.6em 1.2em;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: background 0.2s, transform 0.1s;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.tab-button:hover { background: #0056b3; }
.tab-button:active { transform: scale(0.98); }
.dropdown { position: relative; }
.dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  flex-direction: column;
  background: #1a1a1a;
  padding: 0.35em;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  gap: 0.25em;
}
.dropdown-content .dropdown-item {
  width: 100%;
  text-align: center;
  margin: 0;
  font-size: var(--menu-button-font-size);
  padding: var(--menu-button-padding);
  letter-spacing: 0.35px;
  border-radius: 6px;
}
.dropdown:hover .dropdown-content { display: flex; }

/* Danger button style */
.danger-button, .tab-button.danger {
  background: #d9534f;
  color: #fff;
}
.danger-button:hover, .tab-button.danger:hover {
  background: #c13f3b;
}

/* Folder select button */
.folder-button {
  padding: 0.6em 1.2em;
  background: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0.5em;
  display: inline-block;
}
.folder-button:hover { background: var(--button-hover-bg); }

/* Settings overlay/panel */
#settingsOverlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.6);
  align-items: center;
  justify-content: center;
  z-index: 10000;
}
#settingsPanel {
  background: var(--container-bg);
  color: var(--text);
  border: 1px solid #444;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  min-width: 280px;
  max-width: 90%;
  box-shadow: 0 20px 40px -10px rgba(0,0,0,0.6);
}
#settingsPanel .settings-categories-columns {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin-top: 0.65rem;
}
#settingsPanel .settings-category-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
#settingsPanel .settings-category-col .setting-category {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 0.65rem 0.7rem;
  background: rgba(0, 0, 0, 0.08);
}
body.light-mode #settingsPanel .settings-category-col .setting-category {
  border-color: rgba(0, 0, 0, 0.12);
  background: rgba(0, 0, 0, 0.03);
}
#settingsPanel .settings-category-col .setting-category-header {
  font-size: 0.72rem;
  margin-bottom: 0.25rem;
  letter-spacing: 0.06em;
}
#settingsPanel .settings-category-col .setting-row {
  gap: 0.4em;
  margin-bottom: 0.35rem;
}
#settingsPanel .settings-category-col .setting-row:last-child {
  margin-bottom: 0;
}
#settingsPanel .storage-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  align-items: stretch;
  justify-items: stretch;
}
#settingsPanel .storage-actions-grid button {
  margin: 0;
  width: 100%;
  padding: 0.5em 0.75em;
  font-size: 0.92rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.5rem;
}
#settingsPanel .storage-actions-grid button .icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  flex: 0 0 auto;
}
@media (max-width: 720px) {
  #settingsPanel .settings-categories-columns { flex-direction: column; }
}
#settingsPanel button:not(.storage-menu-item) {
  font-size: 0.95rem;
  padding: 0.55em 1.05em;
  margin: 0.35em;
}
#settingsPanel #storageMenuBtn,
#settingsPanel #devMenuBtn {
  font-size: var(--menu-button-font-size);
  padding: var(--menu-button-padding);
  margin: 0.35em;
}
.setting-row {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin-bottom: 0.5rem;
}
.recent-sources-setting {
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.recent-sources-label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-weight: 600;
}
.recent-sources-label small {
  font-weight: 400;
  opacity: 0.75;
}
.recent-sources-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.recent-sources-controls select {
  padding: 0.35em 0.75em;
  border-radius: 6px;
  border: 1px solid #444;
  background: var(--container-bg);
  color: var(--text);
}
.setting-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.1em 0.55em;
  border-radius: 999px;
  font-size: 0.7em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  margin-left: 0.45em;
}
.setting-tag--dev {
  background: rgba(59, 130, 246, 0.18);
  color: #60a5fa;
}
.setting-tag--unstable {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
}
.setting-tag--beta {
  background: rgba(250, 204, 21, 0.2);
  color: #facc15;
}
.storage-menu { position: relative; display: inline-flex; align-items: center; }
#storageMenuBtn { margin: 0; }
.storage-menu-panel {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  flex-direction: column;
  align-items: stretch;
  padding: 0.4rem;
  background: var(--container-bg);
  border: 1px solid #444;
  border-radius: 8px;
  min-width: 10rem;
  box-shadow: 0 12px 24px rgba(0,0,0,0.45);
  z-index: 10100;
}
.storage-menu-panel.open { display: flex; }
.storage-menu-item {
  margin: 0;
  width: 100%;
  text-align: left;
  font-size: var(--menu-button-font-size);
  padding: var(--menu-button-padding);
  border-radius: 6px;
}
.storage-menu-item + .storage-menu-item { margin-top: 0.25rem; }
/* Settings header row spacing */
#settingsPanel .setting-row:first-child { justify-content: space-between; }
#settingsPanel h3 { margin: 0; }
#settingsPanel .setting-row + .setting-row { margin-top: 0.5rem; }
.setting-category {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid #333;
}
.setting-category:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
.setting-category-header {
  color: var(--muted-text);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
label[for="downloadConcurrencyRange"] { min-width: 8.5em; }
#downloadConcurrencyRange { flex: 1; }
#downloadConcurrencyValue { width: 2.5em; text-align: right; }
.download-concurrency-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}
.download-concurrency-row label[for="downloadConcurrencyRange"] {
  min-width: 0;
}
.download-concurrency-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.download-concurrency-controls #downloadConcurrencyRange {
  width: 100%;
}
#devMenuRow {
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
#devMenuBtn {
  margin: 0;
}
.dev-menu-status {
  font-size: 0.85rem;
  color: var(--muted-text);
  margin: 0;
}

#settingsPanel .settings-dev-menu-row {
  justify-content: center;
  margin-top: 0.65rem;
  margin-bottom: 0;
}

/* Download button */
#downloadBtn { margin-top: 1em; }
#downloadBtn:hover { background: #0056b3; }
#downloadBtn:active { transform: scale(0.98); }

#editSourceBtn { margin-top: 0.6em; }
#editSourceBtn:hover { background: #0056b3; }
#editSourceBtn:active { transform: scale(0.98); }

.pill-button {
  padding: 0.6em 1.4em;
  border-radius: 999px;
  border: none;
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  transition: background 0.2s ease;
}
.pill-button:hover { background: #0056b3; }

/* Back and Clip buttons */
#backBtn { margin-bottom: 1em; display: none; }
#clipBtn {
  margin-left: 0.5em;
  padding: 0.6em 1.2em;
  background: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Placeholder notice */
#placeholderNotice {
  display: none;
  padding: 1em;
  background: rgba(0,0,0,0.5);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 8px;
  margin: 0.75em 0;
}

/* Clip overlay */
#clipOverlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  align-items: center; justify-content: center;
  z-index: 10001;
  text-align: center;
}
.overlay-close {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 999px;
  border: none;
  background: rgba(255,255,255,0.08);
  color: inherit;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.overlay-close:hover,
.overlay-close:focus {
  background: rgba(255,255,255,0.16);
  color: #fff;
  outline: none;
}
body.light-mode #clipOverlayContent .overlay-close,
body.light-mode #clipPresetContent .overlay-close {
  background: rgba(0,0,0,0.15);
  color: #222;
}
body.light-mode #clipOverlayContent .overlay-close:hover,
body.light-mode #clipOverlayContent .overlay-close:focus,
body.light-mode #clipPresetContent .overlay-close:hover,
body.light-mode #clipPresetContent .overlay-close:focus {
  background: rgba(0,0,0,0.25);
  color: #000;
}
#clipOverlayContent {
  position: relative;
  padding: 1.5em;
  background: var(--container-bg);
  border-radius: 12px;
  width: min(520px, 92%);
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.15rem;
  box-shadow: 0 22px 45px rgba(0,0,0,0.55);
}
#clipMessage {
  margin: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  word-break: break-word;
  color: var(--text);
}
.clip-result {
  width: 100%;
  padding: 1em 1.15em;
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75em;
  text-align: center;
  box-sizing: border-box;
}
.clip-result--error {
  background: rgba(168,48,57,0.18);
  border-color: rgba(255,120,136,0.38);
}
.clip-result__title {
  font-weight: 700;
  font-size: 1.05rem;
}
.clip-result__detail {
  margin: 0;
  color: var(--text);
  max-width: 100%;
  word-break: break-word;
}
.clip-result__detail--muted {
  opacity: 0.75;
  font-size: 0.9rem;
}
.clip-result__detail--link {
  word-break: break-all;
  overflow-wrap: anywhere;
}
.clip-result__link {
  color: #5ab8ff;
  text-decoration: underline;
}
.clip-preview-video {
  width: 100%;
  max-width: 440px;
  max-height: 260px;
  border-radius: 12px;
  box-shadow: 0 18px 38px rgba(0,0,0,0.5);
  display: block;
  margin: 0 auto;
}
#clipButtonsRow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  width: 100%;
}
.clip-history-preview {
  align-self: stretch;
  margin-top: 0.5em;
  text-align: left;
}
.clip-history-preview ul {
  list-style: none;
  padding: 0;
  margin: 0.35em 0 0 0;
}
.clip-history-preview li {
  margin: 0.25em 0;
}
.clip-history-preview__title {
  font-weight: 600;
  margin-bottom: 0.4em;
}
.clip-history-preview__meta {
  opacity: 0.7;
  font-size: 0.9rem;
}
#clipPresetOverlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  align-items: center; justify-content: center;
  z-index: 10003;
}
#clipPresetContent {
  width: min(460px, 90%);
  background: #1b1b1b;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  padding: 1.5rem 1.35rem 1.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  box-shadow: 0 18px 40px rgba(0,0,0,0.6);
  position: relative;
}
#clipPresetButtons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
#clipPresetButtons button {
  flex: 1 1 30%;
  min-width: 100px;
  padding: 0.5em 0.8em;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(45,45,45,0.8);
  color: inherit;
  cursor: pointer;
  transition: background 0.2s ease;
}
#clipPresetButtons button:hover {
  background: rgba(70,70,70,0.85);
}
.clip-custom-row {
  display: flex;
  flex-direction: column;
  gap: 0.4em;
}
.trim-slider {
  position: relative;
  height: 26px;
  margin-top: 0.6em;
  touch-action: none;
  cursor: pointer;
}
.trim-track {
  position: absolute;
  inset: 50% 0 0;
  height: 4px;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.18);
  border-radius: 2px;
}
.trim-range {
  position: absolute;
  height: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,123,255,0.45);
  border-radius: 2px;
  z-index: 1;
  pointer-events: none;
}
.trim-handle {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 18px;
  height: 24px;
  border-radius: 2px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: transform 0.15s ease;
  z-index: 2;
}
.trim-handle:active {
  transform: translate(-50%, -50%) scaleY(1.05);
}
.trim-handle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0,123,255,0.45);
}
.trim-handle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  width: 2px;
  height: 100%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.95);
  border-radius: 1px;
}
.trim-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255,255,255,0.75);
  transform: translateX(-50%);
  display: none;
  pointer-events: none;
}
.clip-custom-controls {
  display: flex;
  gap: 0.5em;
  flex-wrap: wrap;
  align-items: center;
}
.trim-display {
  display: flex;
  gap: 1.2em;
  font-size: 0.85em;
  opacity: 0.85;
}
.trim-display span {
  white-space: nowrap;
}
.clip-custom-controls button {
  padding: 0.5em 1.1em;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(35,35,35,0.85);
  color: inherit;
  cursor: pointer;
}
.clip-custom-controls button:hover {
  background: rgba(60,60,60,0.9);
}
.clip-custom-hint {
  opacity: 0.65;
  font-size: 0.8em;
}
.clip-remember-row {
  display: flex;
  align-items: center;
  gap: 0.5em;
}
#clipHistorySection {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.clip-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
#clipHistoryList {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 30vh;
  overflow: auto;
}
#clipHistoryList a {
  color: #69c4ff;
}
#clipHistoryClearBtn {
  padding: 0.35em 0.9em;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(35,35,35,0.85);
  color: inherit;
  cursor: pointer;
  transition: background 0.2s ease;
}
#clipHistoryClearBtn:hover {
  background: rgba(60,60,60,0.9);
}
#clipDoneBtn, #clipDownloadBtn {
  padding: 0.6em 1.2em;
  background: var(--button-bg);
  color: var(--button-text);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Clip progress overlay */
#clipProgressOverlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  align-items: center; justify-content: center;
  z-index: 10002; text-align: center;
}
#clipProgressContent {
  padding: 1em;
  background: var(--container-bg);
  border-radius: 8px;
  max-width: 90%;
  margin: auto;
  color: var(--text);
}
#clipProgressMessage { margin-bottom: 1em; }
#clipProgressBar { width: 100%; }

/* CBZ progress overlay */
#cbzProgressOverlay {
  display: none;
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.65);
  align-items: center; justify-content: center;
  z-index: 10002; text-align: center;
}
#cbzProgressContent {
  padding: 1em;
  background: var(--container-bg);
  border-radius: 8px;
  max-width: 90%;
  margin: auto;
  color: var(--text);
}
#cbzProgressHeader { display:flex; align-items:center; justify-content:space-between; gap:0.5em; }
#cbzProgressMessage { margin-bottom: 1em; }
#cbzProgressBar { width: 100%; }

/* CBZ info tooltip */
.cbz-info-wrap { position: relative; display: inline-block; }
#cbzInfoBtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; line-height: 26px;
  border-radius: 50%; border: 1px solid #444;
  background: transparent; color: var(--text);
  font-weight: 700; cursor: help; padding: 0;
}
#cbzInfoBtn:hover { background: rgba(255,255,255,0.06); }
#cbzInfoBtn:focus { outline: 2px solid #5ab8ff; outline-offset: 2px; }
.cbz-info-tooltip {
  position: absolute; left: 50%; bottom: calc(100% + 10px);
  transform: translateX(-50%) translateY(6px);
  background: var(--container-bg); color: var(--text);
  border: 1px solid #333; border-radius: 8px;
  padding: 0.6em 0.75em; max-width: 320px; width: max-content;
  box-shadow: 0 10px 24px rgba(0,0,0,0.45);
  opacity: 0; visibility: hidden; pointer-events: none;
  z-index: 10003; text-align: left; font-size: 0.9rem;
}
.cbz-info-wrap:hover .cbz-info-tooltip,
.cbz-info-wrap:focus-within .cbz-info-tooltip {
  opacity: 1; visibility: visible; pointer-events: auto; transform: translateX(-50%) translateY(0);
}
.cbz-info-tooltip::after {
  content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border-width: 7px; border-style: solid;
  border-color: var(--container-bg) transparent transparent transparent;
}

/* Clear Storage confirmation overlay */
#clearStorageOverlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(139, 0, 0, 0.35); /* reddish tint */
  align-items: center; justify-content: center;
  z-index: 10050;
}
#clearStoragePanel {
  background: linear-gradient(180deg, #3a0b0b, #2b0a0a);
  color: #ffdede;
  border: 1px solid #a33;
  padding: 1.15rem 1.05rem 1.05rem;
  border-radius: 12px;
  min-width: 280px;
  max-width: 90%;
  box-shadow: 0 20px 40px -10px rgba(0,0,0,0.7);
  position: relative;
}
#clearStoragePanel h3 { margin: 0 0 0.5rem 0; }
#clearStoragePanel p { margin-top: 0; margin-bottom: 0.75rem; }

/* Selective Delete (per-show) overlay */
#storageSelectiveDeleteOverlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.6);
  align-items: center; justify-content: center;
  z-index: 10055;
}
#storageSelectiveDeletePanel {
  background: var(--container-bg);
  color: var(--text);
  border: 1px solid #444;
  padding: 1.15rem 1.05rem 1.05rem;
  border-radius: 12px;
  min-width: min(480px, 92%);
  max-width: 92%;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0 20px 40px -10px rgba(0,0,0,0.65);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.storage-delete-header {
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.storage-delete-header h3 { margin: 0; }
.storage-delete-tools {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.storage-delete-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: flex-start;
}
.storage-delete-option {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}
.storage-delete-option input[type="checkbox"] {
  margin: 0;
}
.storage-delete-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.storage-delete-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  background: rgba(0,0,0,0.12);
}
.storage-delete-item input[type="checkbox"] {
  margin-top: 0.2rem;
}
.storage-delete-item__body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  flex: 1;
}
.storage-delete-item__title {
  font-weight: 650;
  line-height: 1.2;
  word-break: break-word;
}
.storage-delete-item__meta {
  opacity: 0.85;
  font-size: 0.9rem;
}
.storage-delete-empty {
  opacity: 0.9;
  padding: 0.75rem;
  border: 1px dashed rgba(255,255,255,0.18);
  border-radius: 10px;
}

#storageImportOverlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.6);
  align-items: center; justify-content: center;
  z-index: 10060;
}
#storageImportPanel {
  background: var(--container-bg);
  color: var(--text);
  border: 1px solid #444;
  padding: 1.5rem 1.25rem 1.25rem;
  border-radius: 12px;
  min-width: min(400px, 90%);
  max-width: 90%;
  box-shadow: 0 20px 40px -10px rgba(0,0,0,0.65);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
#storageImportPanel p { margin: 0; }
.import-label { font-weight: 600; margin-bottom: 0; }
#storageImportPanel input[type="text"],
#storageImportPanel input[type="file"] {
  margin: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.import-code-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.import-code-row input {
  flex: 1;
}
.scanner-launcher {
  border: none;
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--button-text);
  padding: 0 0.85rem;
  font-weight: 600;
  min-width: 120px;
  cursor: pointer;
  transition: filter 0.2s ease;
}
.scanner-launcher:hover {
  filter: brightness(1.05);
}
.import-divider {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
  color: var(--muted-text, #aaa);
  font-size: 0.75rem;
}
.import-actions { justify-content: flex-end; gap: 0.75rem; }

#accountSyncOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  align-items: center;
  justify-content: center;
  z-index: 10065;
}
#accountSyncPanel {
  background: var(--container-bg);
  color: var(--text);
  border: 1px solid #444;
  padding: 1.15rem 1.05rem 1.05rem;
  border-radius: 12px;
  width: min(380px, 90%);
  max-width: 90%;
  box-shadow: 0 20px 40px -10px rgba(0,0,0,0.65);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
#accountSyncPanel button:not(.account-sync-warning):not(.overlay-close) {
  font-size: 0.95rem;
  padding: 0.55em 1.05em;
  margin: 0.35em;
}

#clearStoragePanel button,
#storageSelectiveDeletePanel button,
#storageImportScanPanel button:not(.overlay-close) {
  font-size: 0.95rem;
  padding: 0.55em 1.05em;
  margin: 0.35em;
}
#accountSyncPanel p { margin: 0; }
#accountSyncPanel .account-sync-header {
  display: flex;
  align-items: center;
  justify-content: center;
}
#accountSyncPanel .account-sync-header h3 {
  margin: 0;
}
#accountSyncCloseBtn.overlay-close {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  transform: none;
  background: #2a2a2a;
  color: #fff;
  z-index: 3;
}
#accountSyncCloseBtn.overlay-close:hover,
#accountSyncCloseBtn.overlay-close:focus {
  background: #3a3a3a;
  color: #fff;
}
body.light-mode #accountSyncCloseBtn.overlay-close {
  background: #e7e7e7;
  color: #111;
}
body.light-mode #accountSyncCloseBtn.overlay-close:hover,
body.light-mode #accountSyncCloseBtn.overlay-close:focus {
  background: #d7d7d7;
  color: #000;
}

#accountSyncPanel .account-sync-warning-wrap {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
}

#accountSyncPanel button.account-sync-warning {
  border: 1px solid #ff4a4a;
  background: #b00000;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  cursor: pointer;
}
#accountSyncPanel button.account-sync-warning:hover,
#accountSyncPanel button.account-sync-warning:focus {
  background: #d00000;
}

#accountSyncPanel .account-sync-warning-tooltip {
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  width: min(320px, 78vw);
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  background: rgba(20, 20, 20, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 18px 34px -12px rgba(0,0,0,0.8);
  color: var(--text);
  font-size: 0.85rem;
  white-space: normal;
  z-index: 2;
  display: none;
}

#accountSyncPanel .account-sync-warning-tooltip strong {
  font-weight: 800;
}

#accountSyncPanel .account-sync-warning-wrap:hover .account-sync-warning-tooltip,
#accountSyncPanel .account-sync-warning-wrap:focus-within .account-sync-warning-tooltip {
  display: block;
}
#accountSyncPanel .account-sync-status {
  margin-top: 0.5rem;
  opacity: 0.85;
  font-size: 0.95em;
  white-space: pre-line;
}
#accountSyncPanel .account-sync-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
}
#accountSyncPanel .account-sync-syncrow {
  width: min(260px, 100%);
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
#accountSyncPanel .account-sync-syncrow button {
  flex: 1;
  width: auto;
}
#accountSyncPanel input.account-sync-interval {
  width: 74px;
  padding: 0.35rem 0.5rem;
}
#accountSyncPanel .account-sync-footer > button {
  width: min(260px, 100%);
}
#accountSyncPanel input[type="text"],
#accountSyncPanel input[type="password"] {
  margin: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

#storageImportScanOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  align-items: center;
  justify-content: center;
  z-index: 10100;
}
#storageImportScanOverlay.is-visible {
  display: flex;
}
#storageImportScanPanel {
  background: var(--container-bg);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 1.15rem;
  border-radius: 16px;
  width: min(420px, 90%);
  max-width: 90%;
  box-shadow: 0 28px 48px -15px rgba(0,0,0,0.7);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
}
#storageImportScanPanel p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted-text);
}
.scanner-video-wrap {
  width: 100%;
  aspect-ratio: 4 / 3;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #111;
  border: 1px solid rgba(255,255,255,0.2);
}
#storageImportScanVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(1.2);
}
.scanner-target {
  position: absolute;
  inset: 12%;
  border: 2px dashed rgba(255,255,255,0.5);
  border-radius: 16px;
  pointer-events: none;
}
#storageImportScanMessage {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted-text);
}

#devMenuOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 3vw, 2rem);
  z-index: 10070;
}
#devMenuOverlay.is-open {
  display: flex;
}
body.dev-menu-open {
  overflow: hidden;
}
#devMenuPanel {
  background: var(--container-bg);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  width: min(480px, 92vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 28px 52px -18px rgba(0, 0, 0, 0.68);
  position: relative;
}
.dev-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.95rem 1.1rem 0.4rem;
}
.dev-menu-header h3 {
  margin: 0;
  font-size: 1.15rem;
}
#devMenuCloseBtn {
  margin: 0;
  padding: 0.4rem 0.8rem;
  font-size: var(--menu-button-font-size);
}
.dev-menu-content {
  padding: 0 1.1rem 1.1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.dev-menu-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0.8rem 0.85rem;
  background: rgba(0, 0, 0, 0.18);
}
body.light-mode .dev-menu-section {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.08);
}

/* Light mode recent sources styling */
body.light-mode .recent-sources {
  background: rgba(245, 245, 245, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
}

body.light-mode .recent-sources-header h3 {
  color: #333333;
}

body.light-mode .recent-sources-count {
  color: rgba(51, 51, 51, 0.64);
}

body.light-mode .source-card {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

body.light-mode .source-card:hover {
  border-color: rgba(0, 123, 255, 0.3);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

body.light-mode .source-card-title {
  color: #333333;
}

body.light-mode .source-card-info {
  color: rgba(51, 51, 51, 0.7);
}

.dev-menu-section h4 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}
.dev-menu-toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
}
.dev-menu-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted-text);
}
.dev-field {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.dev-field label {
  font-weight: 600;
}
.dev-field-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
#devConcurrencyInput {
  width: 6.5rem;
  margin: 0;
}
#devConcurrencyResetBtn {
  margin: 0;
}
.dev-action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.6rem;
}
.dev-action-grid button {
  margin: 0;
  padding: 0.55rem 0.8rem;
  font-size: 0.95rem;
}
.dev-menu-diagnostics-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
#devDiagnosticsRefreshBtn {
  margin: 0;
  padding: 0.45rem 0.85rem;
}
.dev-stats {
  margin: 0;
  display: grid;
  gap: 0.45rem;
}
.dev-stat {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
}
.dev-stat dt {
  font-weight: 600;
  margin: 0;
}
.dev-stat dd {
  margin: 0;
  color: var(--muted-text);
  text-align: right;
}
.storage-notice-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(2px);
  z-index: 11000;
  padding: clamp(1.5rem, 2vw, 3rem);
}
.storage-notice-overlay.is-visible {
  display: flex;
}
body.mm-notice-open {
  overflow: hidden;
}
.storage-notice-stack {
  width: min(420px, 90vw);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
}
.storage-notice {
  background: var(--container-bg);
  color: var(--text);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  padding: 1.15rem 1.5rem 1.15rem 1.2rem;
  box-shadow: 0 24px 48px -22px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  position: relative;
  pointer-events: auto;
}
.storage-notice::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 12px;
  border-left: 4px solid transparent;
  pointer-events: none;
}
.storage-notice--success::before { border-left-color: #22c55e; }
.storage-notice--error::before { border-left-color: #ef4444; }
.storage-notice--warning::before { border-left-color: #f59e0b; }
.storage-notice--info::before { border-left-color: #3b82f6; }
.storage-notice__title {
  font-weight: 700;
  margin: 0;
  font-size: 1rem;
}
.storage-notice__message {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.35;
  white-space: pre-line;
}
.storage-notice__qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  justify-content: center;
  padding: 0.25rem 0.35rem;
}
.storage-notice__qr div {
  width: min(260px, 80vw);
  height: auto;
  background: #fff;
  padding: 0.55rem;
  border-radius: 14px;
  border: 2px solid #fff;
  box-shadow: 0 8px 20px rgba(15,23,42,0.25), inset 0 0 0 1px rgba(0,0,0,0.06);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.storage-notice__qr div:hover,
.storage-notice__qr div:focus-within {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(15,23,42,0.3), inset 0 0 0 1px rgba(0,0,0,0.08);
}
.storage-notice__qr img,
.storage-notice__qr canvas {
  width: 100%;
  height: auto;
  max-width: 260px;
  border-radius: 0 !important; /* keep the code itself square */
  background: #fff;
  display: block;
}
.storage-notice__qr-caption {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-text);
}
.storage-notice__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.storage-notice__btn {
  background: transparent;
  color: inherit;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.storage-notice__btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.35);
}
.storage-notice__btn:focus-visible {
  outline: 2px solid #5ab8ff;
  outline-offset: 2px;
}
.storage-notice__btn--secondary {
  background: transparent;
  border-color: rgba(255,255,255,0.25);
}
.storage-notice__btn--secondary:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.45);
}
.storage-notice__btn--danger {
  background: #d9534f;
  border-color: #d9534f;
  color: #fff;
}
.storage-notice__btn--danger:hover {
  background: #c13f3b;
  border-color: #c13f3b;
}
.storage-notice__btn--primary {
  background: var(--button-bg);
  border-color: var(--button-bg);
  color: var(--button-text);
}
.storage-notice__btn--primary:hover {
  background: var(--button-hover-bg);
  border-color: var(--button-hover-bg);
}

/* GitHub and version badges */
#githubLink,
#versionBadge {
  display: flex;
  align-items: center;
  text-decoration: none;
  font-family: inherit;
  font-size: clamp(0.75rem, 0.65rem + 0.7vw, 1.2rem);
  padding: clamp(0.45rem, 0.35rem + 0.4vw, 0.85rem) clamp(0.75rem, 0.6rem + 0.7vw, 1.35rem);
  border-radius: clamp(0.45rem, 0.4rem + 0.4vw, 0.8rem);
  gap: clamp(0.35rem, 0.25rem + 0.3vw, 0.6rem);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  z-index: 10000;
}

#githubLink {
  position: fixed;
  bottom: clamp(0.75rem, 0.55rem + 0.9vw, 1.5rem);
  left: clamp(0.75rem, 0.55rem + 0.9vw, 1.5rem);
  background: var(--button-bg);
  color: var(--button-text);
}

#githubLink img {
  height: 1em;
  width: 1em;
}

/* Version badge (bottom-right) */
#versionBadge {
  position: fixed;
  bottom: clamp(0.75rem, 0.55rem + 0.9vw, 1.5rem);
  right: clamp(0.75rem, 0.55rem + 0.9vw, 1.5rem);
  background: #16a34a; /* default green, JS updates with age */
  color: var(--button-text);
}


/* Theater toggle button */
#theaterBtn {
  margin-left: 0.5em;
  background: var(--button-bg);
  color: var(--button-text);
  border: none;
  padding: 0.6em;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.3s, transform 0.1s;
}
#theaterBtn.is-active,
#theaterBtn[aria-pressed="true"] {
  background: var(--button-hover-bg);
}
#theaterBtn:hover {
  background: var(--button-hover-bg);
}
#theaterBtn:active {
  transform: scale(0.95);
}

/* Theater mode (YouTube-style wide player) */
body.theater-mode #playerContainer.container {
  width: 100%;
  max-width: none;
  padding: 1rem;
  border-radius: 0;
}

body.theater-mode #playerScreen .mm-video-frame {
  width: calc(100% + 2rem);
  margin-left: -1rem;
  margin-right: -1rem;
  margin-bottom: 1rem;
  background: #000;
  border-radius: 0;
  height: var(--mm-theater-height, 70vh);
}

body.theater-mode #playerScreen .mm-video-frame > video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  margin: 0;
  border-radius: 0;
}


/* Ensure player screen is relative for spinner overlay */
#playerScreen {
  position: relative;
}

.separated-parts-bar {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  margin: 0.5em 0 1em;
}

.separated-part-pill {
  background: #222;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 0.4em 0.9em;
  font-size: 0.9rem;
  margin: 0;
  transition: background 0.25s, border-color 0.25s, transform 0.1s;
}

.separated-part-pill:hover {
  background: #2f2f2f;
  border-color: rgba(255, 255, 255, 0.14);
}

.separated-part-pill:focus-visible {
  outline: 2px solid var(--button-bg);
  outline-offset: 2px;
}

.separated-part-pill.active {
  background: var(--button-bg);
  color: var(--button-text);
  border-color: transparent;
  transform: translateY(-1px);
}

/* Spinner overlay */
.spinner {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid var(--button-bg);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  z-index: 1000;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}
/* Resume message styling */
#resumeMessage {
  color: #6ec1e4;
  font-weight: bold;
  margin-bottom: 0.5em;
}
#resumeMessage a {
  color: #6ec1e4;
  text-decoration: underline;
  cursor: pointer;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none;
}

/* Design-preserving responsive and interaction fixes */
body {
  overflow-x: hidden;
}

.container,
.directory-header {
  box-sizing: border-box;
}

.dropdown.is-open .dropdown-content {
  display: flex;
}

.dropbtn:focus-visible,
.dropdown-item:focus-visible {
  outline: 3px solid rgba(99, 179, 237, 0.7);
  outline-offset: 2px;
}

@media (max-width: 768px) {
  .container {
    width: calc(100% - 1rem);
    padding: 1rem;
  }

  #homeMainRegion {
    padding-bottom: 5.5rem;
  }

  .directory-header {
    max-width: 100%;
  }
}
