/* Theme overrides — swap these to change the entire color scheme.
   Build: test-update-detection */
[data-theme="dark"] {
  --background: #0e1117;
  --foreground: #e0dbd5;
  --card: #171b22;
  --card-foreground: #e0dbd5;
  --primary: #5fada8;
  --primary-foreground: #0e1117;
  --secondary: #1e2330;
  --secondary-foreground: #e0dbd5;
  --muted: #1e2330;
  --muted-foreground: #8a857e;
  --faint: #141820;
  --accent: #1e2330;
  --border: #282d38;
  --input: #282d38;
  --ring: #5fada8;
  --success: #5a9e64;
  --success-foreground: #e0dbd5;
}

/* Layout tokens */
:root {
  --content-gap: 16px;
}

/* Lock viewport — .page-content is the only scroll container */
html, body {
  height: 100%;
  overflow: hidden;
}

/* App container — header, scrollable content, tab bar as three flex children */
.app {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page-content {
  flex: 1;
  min-height: 0;
  padding: var(--content-gap);
  overflow-y: auto;
}

/* Bottom tab bar — flex child, not fixed */
.tab-bar {
  flex-shrink: 0;
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--background);
}

.tab-bar a {
  flex: 1;
  text-align: center;
  padding: 12px 0;
  font-size: 14px;
  opacity: 0.5;
  text-decoration: none;
}

.tab-bar a.active {
  opacity: 1;
  font-weight: 600;
  color: var(--primary);
  border-top: 2px solid var(--primary);
}

/* App bar — persistent logo + dropdown */
.app-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 6px var(--content-gap);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: relative;
}

.app-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.logo-dropdown { position: relative; }

.logo-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-medium);
  -webkit-tap-highlight-color: transparent;
}
.logo-btn:hover { background: var(--secondary); }
.logo-icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13 5h8'/%3E%3Cpath d='M13 12h8'/%3E%3Cpath d='M13 19h8'/%3E%3Cpath d='m3 17 2 2 4-4'/%3E%3Cpath d='m3 7 2 2 4-4'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13 5h8'/%3E%3Cpath d='M13 12h8'/%3E%3Cpath d='M13 19h8'/%3E%3Cpath d='m3 17 2 2 4-4'/%3E%3Cpath d='m3 7 2 2 4-4'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  mask-size: contain;
}
.logo-overlay { position: fixed; inset: 0; z-index: 49; }

.logo-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  z-index: 50;
  min-width: 180px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  padding: 4px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.logo-menu-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--foreground);
  text-decoration: none;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.logo-menu-item:hover { background: var(--secondary); }

.logo-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.logo-menu-logout { color: var(--muted-foreground); }

.logo-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.logo-menu-toggle .toggle-state {
  font-size: 12px;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.logo-menu-toggle .toggle-subtext {
  font-size: 11px;
  color: var(--muted-foreground);
  font-style: italic;
}
.logo-menu-toggle.is-disabled {
  cursor: not-allowed;
  opacity: 0.6;
}
.logo-menu-toggle.is-disabled:hover {
  background: transparent;
}

.app-bar-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
  pointer-events: none;
}

/* Gear icon — CSS mask-image cog */
.gear-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  background-color: currentColor;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  mask-size: contain;
}

/* Gear button + dropdown wrapper */
.app-bar-gear {
  position: relative;
  margin-left: auto;
}
.gear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--muted-foreground);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-medium);
  -webkit-tap-highlight-color: transparent;
}
.gear-btn:hover { background: var(--secondary); }

.gear-overlay { position: fixed; inset: 0; z-index: 49; }

/* Gear menu (view mode options) */
.gear-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 50;
  min-width: 160px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  padding: 4px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.gear-menu-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--foreground);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.gear-menu-item:hover { background: var(--secondary); }
.gear-menu-item.active {
  color: var(--primary);
  font-weight: 600;
}

/* Show cards */
.show-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.show-card {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  color: var(--foreground);
  background: var(--card);
  padding: var(--space-4);
  border-radius: var(--radius-medium);
}

.show-card-poster {
  width: 48px;
  height: 72px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--muted);
}

.show-card-poster-placeholder {
  width: 48px;
  height: 72px;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--muted);
}

.show-card-info {
  flex: 1;
  min-width: 0;
}

.show-card-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.show-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Category badges — color-coded */
.cat-maybe {
  background: #3a3a4a;
  color: #b0b0c0;
}

.cat-want_to_watch {
  background: #1e3a5f;
  color: #6db3f2;
}

.cat-watching {
  background: #1a2f4a;
  color: #4da8da;
}

.cat-on_hold {
  background: #4a3a1a;
  color: #d4a544;
}

.cat-completed {
  background: #1a3f22;
  color: #4caf50;
}

/* Airing status badges */
.airing-returning_series {
  background: #1a3f22;
  color: #5a9e64;
}

.airing-in_production {
  background: #1e3a5f;
  color: #6db3f2;
}

.airing-planned {
  background: #2a2a5f;
  color: #8888d8;
}

.airing-ended {
  background: #3a3a4a;
  color: #b0b0c0;
}

.airing-canceled {
  background: #4a2a2a;
  color: #c87070;
}

/* Show detail — backdrop */
.show-detail-backdrop {
  width: 100%;
  max-height: 180px;
  overflow: hidden;
  border-radius: 8px;
  margin-bottom: 12px;
}

.show-detail-backdrop-img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}

/* Show detail — hero (poster + title + quick info) */
.show-detail-hero {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.show-detail-hero-poster {
  width: 100px;
  flex-shrink: 0;
  border-radius: 8px;
}

.show-detail-hero-info {
  flex: 1;
  min-width: 0;
}

.show-detail-hero-info h3 {
  margin: 0 0 4px;
}

.show-detail-original-name {
  font-style: italic;
  font-size: 13px;
  color: var(--color-text-secondary, #aaa);
  margin-bottom: 4px;
}

.show-detail-quick-info {
  font-size: 12px;
  color: var(--color-text-secondary, #aaa);
  margin-bottom: 6px;
}

/* TMDB rating */
.tmdb-rating {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 2px;
}

.tmdb-star {
  color: #f5c518;
}

/* Genre pills */
.genre-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.genre-pill {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 12px;
  background: var(--color-bg-secondary, #2a2a3a);
  color: var(--color-text-secondary, #ccc);
}

/* Show detail — overview */
.show-detail-overview {
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.5;
}

/* Show detail — metadata badges row */
.show-detail-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

/* Show detail — metadata rows (Networks, Production) */
.show-detail-metadata {
  margin-bottom: 12px;
}

.show-detail-metadata-row {
  display: flex;
  gap: 8px;
  font-size: 13px;
  padding: 2px 0;
}

.show-detail-metadata-label {
  font-weight: 600;
  color: var(--color-text-secondary, #aaa);
  white-space: nowrap;
}

.category-select {
  margin-bottom: 16px;
}

.category-select select {
  width: auto;
}

/* Personal rating stars */
.rating-stars { display: flex; gap: 0.25rem; margin-bottom: 16px; }
.rating-star { background: none; border: none; font-size: 1.5rem; cursor: pointer; padding: 0.25rem; -webkit-tap-highlight-color: transparent; }
.rating-star--filled { color: #f5c518; }
.rating-star--empty { color: var(--muted-foreground, #888); }

/* Seasons accordion */
.season {
  margin-bottom: 4px;
}

.season-header {
  position: relative;
  display: flex;
  align-items: center;
  padding: 14px 8px;
  background: var(--card);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s;
  user-select: none;
}

.season-header.expanded {
  border-bottom: 2px solid var(--primary);
}

.season-header.watched {
  color: var(--muted-foreground);
}

.season-progress {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted-foreground);
  padding-right: 8px;
}

.badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
}

.chevron {
  font-size: 20px;
  opacity: 0.5;
  width: 24px;
  text-align: center;
}

/* Episodes */
.episode-list {
  display: flex;
  flex-direction: column;
}

.swipe-container {
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
  border-radius: var(--radius-medium);
}

.swipe-container > :not(.swipe-action) {
  position: relative;
  z-index: 1;
  background: var(--card);
}

.swipe-action {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 16px;
  background: var(--success);
  color: var(--success-foreground);
  font-size: 13px;
  font-weight: 600;
  width: 100%;
}

.episode-row {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  background: var(--background);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s;
}

.ep-inner {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.ep-content {
  display: flex;
  align-items: center;
  padding: 14px 0;
}

.ep-expanded {
  width: 100%;
  padding: 4px 0 8px 36px;
}

/* Mobile: hide the watch button; only overview text shows when expanded */
.ep-watch-btn {
  display: none;
}

/* On mobile, if expanded area only has the hidden button, collapse the padding */
.ep-expanded:not(:has(.ep-overview)) {
  display: none;
}

.season-content {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.episode-row.watched {
  color: var(--muted-foreground);
}

.episode-row-link {
  text-decoration: none;
  color: inherit;
}

.ep-number {
  width: 36px;
  font-size: 13px;
  opacity: 0.5;
  flex-shrink: 0;
}

.ep-name {
  flex: 1;
}

.ep-date-toggle {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.ep-air-date {
  font-size: 11px;
  color: var(--muted-foreground);
  padding-right: 8px;
  white-space: nowrap;
}

.ep-overview-chevron {
  font-size: 0.8em;
  color: var(--muted-foreground);
}

.ep-overview {
  font-size: 0.85em;
  color: var(--muted-foreground);
  margin: 0 0 4px 0;
  line-height: 1.4;
}


.ep-watch-btn {
  margin-top: 6px;
  padding: 4px 12px;
  font-size: 12px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  cursor: pointer;
}

.ep-watch-btn:hover {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}

/* Episode card list */
.episode-card-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Episode card (flat view) */
.episode-card {
  display: block;
  background: var(--card);
  padding: var(--space-4);
  border-radius: var(--radius-medium);
  text-decoration: none;
  color: inherit;
}

.episode-card-show {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--primary);
}

.episode-card-detail {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

/* Show group (grouped/accordion view) */
.show-group {
  margin-bottom: 4px;
}

.show-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: var(--card);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.show-group-header.expanded {
  border-bottom: 2px solid var(--primary);
}

.show-group-title {
  font-weight: 600;
  flex: 1;
  cursor: pointer;
}

.show-group-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 4px;
}

.show-group-episodes {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ep-code {
  font-size: 13px;
  opacity: 0.5;
  font-family: monospace;
}

.air-date {
  margin-left: auto;
  font-size: 13px;
  opacity: 0.5;
}

/* Filter menu (inside gear dropdown on Shows page) */
.filter-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 50;
  min-width: 200px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  padding: 4px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.filter-option {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

.filter-option.selected {
  color: var(--primary);
}

.filter-option.has-sub-filters .filter-sub-btn {
  color: var(--primary);
}

.filter-check {
  width: 24px;
  flex-shrink: 0;
  font-size: 14px;
  text-align: center;
}

.filter-label {
  flex: 1;
  font-size: 14px;
}

.filter-sub-btn {
  width: 28px;
  flex-shrink: 0;
  text-align: center;
  font-size: 12px;
  opacity: 0.5;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
}

.filter-sub-btn:hover {
  opacity: 1;
}

.airing-submenu {
  padding: 2px 0 2px 24px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--faint);
}

.submenu-option {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.submenu-option.selected {
  color: var(--primary);
}

/* Floating action button */
.fab {
  position: fixed;
  bottom: 68px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 24px;
  font-weight: 600;
  text-decoration: none;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 40;
  -webkit-tap-highlight-color: transparent;
}

/* About page */
.about-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px;
  text-align: center;
}

.tmdb-logo {
  width: 200px;
  margin-bottom: 24px;
}

.about-attribution p {
  color: var(--muted-foreground);
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
}

.about-attribution a {
  color: var(--primary);
}

/* Search form */
.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: var(--content-gap);
}

.search-input {
  flex: 1;
  font-size: 16px; /* prevent iOS zoom */
  padding: 10px 12px;
  background: var(--card);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
}

.search-input::placeholder {
  color: var(--muted-foreground);
}

/* Search results */
.search-results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-result-card {
  display: flex;
  gap: 12px;
  background: var(--card);
  padding: var(--space-4);
  border-radius: var(--radius-medium);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.search-result-poster {
  width: 48px;
  height: 72px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.search-result-poster-placeholder {
  width: 48px;
  height: 72px;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--muted);
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.search-result-title small {
  font-weight: 400;
  color: var(--muted-foreground);
}

.search-result-overview {
  font-size: 13px;
  color: var(--muted-foreground);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.search-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted-foreground);
}

/* Preview dialog — sizing within native <dialog> */
dialog.preview-dialog {
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 0;
}

.preview-hero {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.preview-poster {
  width: 100px;
  flex-shrink: 0;
  border-radius: 8px;
}

.preview-info {
  flex: 1;
  min-width: 0;
}

.preview-info h3 {
  margin: 0 0 4px;
}

.preview-quick-info {
  font-size: 12px;
  color: var(--color-text-secondary, #aaa);
  margin-bottom: 6px;
}

.preview-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.preview-overview {
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 12px 0;
}

.preview-metadata-row {
  display: flex;
  gap: 8px;
  font-size: 13px;
  padding: 2px 0;
  margin-bottom: 12px;
}

/* Category picker buttons (in confirm dialog) */
.category-picker-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-picker-buttons button {
  width: 100%;
  justify-content: center;
}

/* Toast overrides for dark theme visibility */
[data-theme="dark"] .toast[data-variant="danger"] {
  background-color: #c0392b;
  color: #fff;
  border: none;
}
[data-theme="dark"] .toast[data-variant="danger"] .toast-message {
  color: #fff;
}
[data-theme="dark"] .toast[data-variant="success"] {
  background-color: var(--success);
  color: #fff;
  border: none;
}
[data-theme="dark"] .toast[data-variant="success"] .toast-message {
  color: #fff;
}

/* Clickable cards — cursor for div-based cards */
.show-card,
.episode-card,
.episode-row-link {
  cursor: pointer;
}

/* Watch toggle — hidden on mobile, hover-reveal on desktop */
.watch-toggle {
  display: none;
}

/* ============================================================
   Responsive breakpoints — mobile-first progressive enhancement
   ============================================================ */

/* --- Tablet (640px+) --- */
@media (min-width: 640px) {
  /* T1: Widen app container */
  :root {
    --content-gap: 20px;
  }
  .app {
    max-width: 960px;
  }

  /* T3: Show list — 2-column grid */
  .show-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  /* T4: Episode card list — 2-column grid */
  .episode-card-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
  /* Keep grouped view full-width */
  .show-group {
    grid-column: 1 / -1;
  }

  /* T6: Show detail — larger backdrop and poster */
  .show-detail-backdrop {
    max-height: 220px;
  }
  .show-detail-backdrop-img {
    height: 220px;
  }
  .show-detail-hero-poster {
    width: 130px;
  }

  /* T8: Show card poster — slightly larger */
  .show-card-poster {
    width: 56px;
    height: 84px;
  }
  .show-card-poster-placeholder {
    width: 56px;
    height: 84px;
  }
}

/* --- Desktop (1024px+) --- */
@media (min-width: 1024px) {
  /* T1: Let app fill available width on desktop */
  :root {
    --content-gap: 24px;
  }
  .app {
    max-width: none;
  }

  /* T2: Transform tab bar into sidebar */
  .app-body {
    flex-direction: row;
  }
  .tab-bar {
    flex-direction: column;
    width: 200px;
    border-top: none;
    border-right: 1px solid var(--border);
    padding-top: 16px;
    order: -1; /* sidebar appears before page-content */
  }
  .tab-bar a {
    flex: none;
    text-align: left;
    padding: 12px 16px;
  }
  .tab-bar a.active {
    border-top: none;
    border-left: 3px solid var(--primary);
  }

  /* T4: Episode card list — 3-column grid */
  .episode-card-list {
    grid-template-columns: repeat(3, 1fr);
  }

  /* T5: Search results — 2-column grid */
  .search-results {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
  /* Constrain search form width */
  .search-form {
    max-width: 500px;
  }

  /* T6: Show detail — even larger backdrop and poster */
  .show-detail-backdrop {
    max-height: 280px;
  }
  .show-detail-backdrop-img {
    height: 280px;
  }
  .show-detail-hero-poster {
    width: 150px;
  }

  /* T7: FAB — no tab bar to clear at desktop */
  .fab {
    bottom: 24px;
    right: 24px;
  }

  /* T8: Preview dialog — wider */
  dialog.preview-dialog {
    max-width: 500px;
  }

  /* T8: Show card poster — slightly larger */
  .show-card-poster {
    width: 60px;
    height: 90px;
  }
  .show-card-poster-placeholder {
    width: 60px;
    height: 90px;
  }

  /* T3 override: single-column lists at desktop width */
  .show-list,
  .episode-card-list {
    display: flex;
    flex-direction: column;
  }

  /* Detail pane layout — inline right panel on desktop */
  .list-detail-layout {
    display: flex;
    height: 100%;
  }
  .list-detail-layout .list-panel {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
    padding: var(--content-gap);
  }
  .list-detail-layout .detail-pane {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
    border-left: 1px solid var(--border);
    padding: var(--content-gap);
    padding-bottom: 80vh;
    position: relative;
  }
  .page-content:has(.list-detail-layout) {
    padding: 0;
  }
  .detail-pane-close {
    position: sticky;
    top: 8px;
    float: right;
    z-index: 10;
    margin-bottom: -32px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--foreground);
    font-size: 16px;
  }
  .show-card.active,
  .episode-card.active,
  .episode-row.active,
  .episode-row-link.active {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
  }
  /* Force single-column in list panel */
  .list-detail-layout .show-list,
  .list-detail-layout .episode-card-list {
    display: flex;
    flex-direction: column;
  }
  /* Keep FAB within the list panel, not overlapping the detail pane */
  .list-detail-layout .fab {
    right: calc(50vw - 76px);
  }
  /* Expanded episode — show watch button and expanded area on desktop */
  .ep-expanded:not(:has(.ep-overview)) {
    display: block;
  }
  .ep-watch-btn {
    display: inline-block;
  }
  /* Episode watch toggle — overlays the date in-place */
  .ep-date-toggle .watch-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    inset: 0;
    background: var(--background);
    border: none;
    border-radius: var(--radius-medium);
    color: var(--muted-foreground);
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 2;
  }
  /* Show episode toggle when hovering the date-toggle area */
  .ep-date-toggle:hover .watch-toggle {
    opacity: 1;
    pointer-events: auto;
  }
  .ep-date-toggle:hover .ep-air-date {
    opacity: 0;
  }
  .ep-date-toggle .watch-toggle:hover {
    color: var(--foreground);
  }
  /* Season watch toggle — absolutely positioned on the header */
  .season-header .watch-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--card);
    border: 1px solid transparent;
    border-radius: var(--radius-medium);
    color: var(--muted-foreground);
    cursor: pointer;
    padding: 2px 10px;
    font-size: 14px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 2;
  }
  .season-header:has(.season-progress:hover) .watch-toggle,
  .season-header:has(.watch-toggle:hover) .watch-toggle {
    opacity: 1;
  }
  .season-header .watch-toggle:hover {
    border-color: var(--border);
    color: var(--foreground);
  }
}

/* ==================== Auth Pages ==================== */

/* Auth checking — full screen spinner */
.auth-checking {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  background: var(--background);
}

/* Login page — full screen, centered card */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  padding: 16px;
  background: var(--background);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  padding: 32px 24px;
}

.login-card h2 {
  text-align: center;
  color: var(--primary);
  margin: 0 0 24px;
  font-size: 24px;
}

.login-subtitle {
  text-align: center;
  color: var(--muted-foreground);
  font-size: 14px;
  margin: 0 0 16px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-input {
  width: 100%;
  font-size: 16px;  /* prevent iOS zoom */
  padding: 12px;
  background: var(--background);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  box-sizing: border-box;
}

.login-input::placeholder {
  color: var(--muted-foreground);
}

.login-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(95, 173, 168, 0.2);
}

.login-submit {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  font-weight: 600;
  background: var(--primary);
  color: var(--primary-foreground);
  border: none;
  border-radius: var(--radius-medium);
  cursor: pointer;
  margin-top: 4px;
}

.login-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-error {
  background: #4a2a2a;
  color: #c87070;
  padding: 10px 12px;
  border-radius: var(--radius-medium);
  font-size: 14px;
  text-align: center;
}

/* About page user section */
.about-user {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.about-user p {
  color: var(--muted-foreground);
  font-size: 14px;
  margin: 0;
}

.about-link {
  color: var(--primary);
  font-size: 14px;
}

.logout-btn {
  padding: 8px 24px;
  font-size: 14px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  cursor: pointer;
}

.logout-btn:hover {
  background: var(--card);
}

/* Admin page */
.admin-page {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--content-gap);
}

.invite-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: var(--content-gap);
}

.invite-result {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  padding: 16px;
}

.invite-link-display {
  width: 100%;
  padding: 10px;
  font-size: 13px;
  font-family: monospace;
  background: var(--background);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  margin-bottom: 8px;
  word-break: break-all;
  box-sizing: border-box;
}

.copy-btn {
  padding: 6px 16px;
  font-size: 13px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  cursor: pointer;
}

/* Import/Export section on About page */
.import-export-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.import-export-section h3 {
  font-size: 16px;
  margin: 0 0 16px;
  color: var(--foreground);
}

.import-export-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.import-export-btn {
  padding: 8px 24px;
  font-size: 14px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  cursor: pointer;
  white-space: nowrap;
}
.import-export-btn:hover:not(:disabled) { background: var(--card); }
.import-export-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.import-file-input {
  font-size: 13px;
  color: var(--muted-foreground);
  min-width: 0;
  flex: 1;
}

.import-progress {
  margin-top: 12px;
}

.import-counter {
  font-size: 14px;
  color: var(--muted-foreground);
  margin: 0 0 8px;
}

.import-summary {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.import-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-medium);
  font-size: 13px;
  font-weight: 600;
}

.import-badge-ok {
  background: color-mix(in srgb, var(--success) 25%, transparent);
  color: var(--success);
}

.import-badge-skipped {
  background: color-mix(in srgb, #d4a017 25%, transparent);
  color: #d4a017;
}

.import-badge-error {
  background: color-mix(in srgb, #e05252 25%, transparent);
  color: #e05252;
}

.import-results {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  padding: 8px;
  background: var(--background);
}

.import-result-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
  color: var(--foreground);
}

.import-result-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.import-error {
  margin-top: 12px;
  padding: 12px;
  background: color-mix(in srgb, #e05252 15%, transparent);
  color: #e05252;
  border-radius: var(--radius-medium);
  font-size: 14px;
}

/* PWA update banner */
#update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 14px;
  font-weight: 500;
}

#update-reload {
  padding: 4px 14px;
  border: 1px solid var(--primary-foreground);
  border-radius: 4px;
  background: transparent;
  color: var(--primary-foreground);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#update-reload:active {
  background: rgba(0, 0, 0, 0.15);
}

/* Shows filter input */
.shows-filter {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  background: var(--background);
}

.shows-filter-input {
  flex: 1;
  font-size: 16px; /* prevent iOS zoom */
  padding: 10px 12px;
  background: var(--card);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
}

.shows-filter-input::placeholder {
  color: var(--muted-foreground);
}

/* History page */
.history-page {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--content-gap);
}

.history-event {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.history-event-time {
  font-size: 12px;
  color: var(--muted-foreground);
  margin-bottom: 2px;
}

.history-event-desc {
  font-size: 14px;
  color: var(--foreground);
}

.history-load-more {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  background: var(--card);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.shows-filter-clear {
  background: none;
  border: none;
  color: var(--muted-foreground);
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
}

/* Rewatch Mode */

.rewatch-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: var(--radius-medium);
  background: var(--faint);
  border: 1px solid var(--border);
}

.rewatch-bar--active {
  background: #1a2f4a;
  border-color: #4da8da;
  justify-content: space-between;
}

.rewatch-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rewatch-start-btn {
  background: var(--primary);
  color: var(--primary-foreground);
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-medium);
  font-weight: 600;
  cursor: pointer;
}

.rewatch-stop-btn {
  background: transparent;
  color: #6db3f2;
  border: 1px solid #6db3f2;
  padding: 6px 12px;
  border-radius: var(--radius-medium);
  font-size: 13px;
  cursor: pointer;
}

.rewatch-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: #4da8da;
  color: #0e1117;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rewatch-indicator {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #4da8da;
  color: #0e1117;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rewatch-progress {
  font-size: 13px;
  color: #6db3f2;
  font-weight: 500;
}

.episode-row.rewatch-locked {
  opacity: 0.45;
  pointer-events: none;
}

/* Hide the green swipe-action background when the row is locked in rewatch
   mode — otherwise it bleeds through the row's reduced opacity and makes
   locked episodes look already-rewatched. */
.swipe-container:has(> .episode-row.rewatch-locked) .swipe-action {
  display: none;
}

/* Hide the watch-toggle button entirely on locked rows (it's already
   disabled, but should not be visible in rewatch mode). */
.episode-row.rewatch-locked .watch-toggle {
  display: none;
}
