:root {
  color-scheme: dark;
  --bg: #0b0f19;
  --surface: #141a29;
  --surface-2: #1c2438;
  --text: #e6e9f0;
  --text-dim: #8b93a7;
  --accent: #22d3ee;
  --accent-dim: #0e7490;
  --danger: #f87171;
  --radius: 10px;
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-2);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}

.user-menu {
  position: relative;
  flex: 0 0 auto;
}

.user-menu-trigger {
  position: relative;
  display: block;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 50%;
}

.menu-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
}

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-menu-trigger[aria-expanded="true"] .avatar {
  outline: 2px solid var(--accent);
}

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.user-menu-name {
  padding: 8px 10px 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--surface);
  margin-bottom: 4px;
  word-break: break-word;
}

.user-menu-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text);
  font-size: 0.85rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.user-menu-item:hover {
  background: var(--surface);
}

.user-menu-item.danger {
  color: var(--danger);
}

.login-screen {
  max-width: 320px;
  margin: 15vh auto 0;
  text-align: center;
}

.login-screen h2 {
  margin-bottom: 4px;
}

.google-btn {
  margin-top: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fff;
  color: #1f1f1f;
  border-color: #fff;
  width: 100%;
}

.brand {
  flex: 0 0 auto;
  font-size: 1.1rem;
  margin: 0;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.tabs {
  display: flex;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs a {
  flex: 0 0 auto;
  white-space: nowrap;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: var(--radius);
}

.tabs a.active {
  color: var(--text);
  background: var(--surface-2);
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #05262b;
  font-size: 0.7rem;
  font-weight: 700;
}

@media (max-width: 480px) {
  .topbar-inner {
    padding: 10px 12px;
    gap: 6px;
  }

  .brand {
    font-size: 1rem;
  }

  .tabs a {
    padding: 6px 8px;
    font-size: 0.8rem;
  }
}

.view {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.loading,
.empty,
.error {
  color: var(--text-dim);
  text-align: center;
  padding: 32px 16px;
}

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

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-row input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 1rem;
}

.search-row button {
  background: var(--accent);
  color: #05262b;
  border: none;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
}

h2.section-title {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 24px 0 12px;
}

.mail-usage {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: -8px 0 16px;
}

.mail-usage.warn {
  color: var(--danger);
}

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

.card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  border: none;
  color: var(--text);
  padding: 0;
  display: flex;
  flex-direction: column;
}

.card img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
}

.card .card-body {
  padding: 8px 10px;
}

.card .card-title {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card .card-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.detail-header img {
  width: 130px;
  border-radius: var(--radius);
  flex-shrink: 0;
}

/* Overrides the poster sizing above for an avatar nested in the header (e.g. the watch-with trigger). */
.detail-header .avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.detail-meta h2 {
  margin: 0 0 6px;
}

.detail-meta .overview {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.4;
}

.btn {
  display: inline-block;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
  margin-top: 10px;
}

.btn.active {
  background: var(--accent);
  color: #05262b;
}

.btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-text {
  border-color: transparent;
  color: var(--text-dim);
  padding-left: 0;
  padding-right: 0;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.watch-with-members {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.watch-with-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.8rem;
}

.watch-with-chip .avatar {
  width: 22px;
  height: 22px;
  font-size: 0.7rem;
}

.watch-with-chip.pending {
  opacity: 0.6;
  font-style: italic;
}

.watch-with-trigger-avatars {
  display: inline-flex;
  align-items: center;
}

.watch-with-trigger-avatars .avatar {
  width: 24px;
  height: 24px;
  font-size: 0.7rem;
  border: 2px solid var(--bg);
  margin-left: -8px;
}

.watch-with-trigger-avatars .avatar:first-child {
  margin-left: 0;
}

.watch-with-trigger-avatars .avatar.pending {
  opacity: 0.55;
}

.watch-with-invite {
  display: flex;
  gap: 8px;
}

.watch-with-invite select {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 0.85rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  padding: 16px;
}

.modal {
  width: 100%;
  max-width: 380px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 0;
  font-size: 1rem;
}

.modal-close {
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-body .btn {
  margin-top: 0;
}

.season-block {
  margin-bottom: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
}

.season-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.season-header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.episode-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.episode-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  background: var(--surface-2);
}

.episode-row.watched {
  opacity: 0.55;
}

.episode-row.unaired {
  opacity: 0.5;
}

.episode-row.unaired .ep-date {
  color: var(--accent);
  font-style: italic;
}

.episode-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.episode-row input[type="checkbox"]:disabled {
  cursor: not-allowed;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.episode-row .ep-title {
  flex: 1;
  font-size: 0.85rem;
}

.episode-row .ep-date {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.calendar-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.calendar-sentinel {
  height: 1px;
}

.calendar-today-marker {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.calendar-today-marker::before,
.calendar-today-marker::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--accent);
  opacity: 0.4;
}

.calendar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px;
  transition: opacity 0.15s ease;
}

.calendar-row.watched {
  opacity: 0.55;
}

.calendar-row img {
  width: 48px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
}

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

.calendar-row .date {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
}

.calendar-row .show-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.calendar-row .ep-info {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Large circular touch target for marking an episode watched right from the calendar. */
.watched-circle {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  margin: 0;
  border-radius: 50%;
  border: 2px solid var(--text-dim);
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.watched-circle:hover:not(:disabled) {
  border-color: var(--accent);
}

.watched-circle:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.watched-circle:checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 11px;
  height: 20px;
  border: solid var(--bg);
  border-width: 0 3px 3px 0;
  transform: translate(-50%, -60%) rotate(45deg);
}

.watched-circle:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.watched-circle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.watchlist-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 10px;
  cursor: pointer;
}

.watchlist-row img {
  width: 48px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
}

/* Overrides the poster sizing above for an avatar nested in a row (e.g. the People list). */
.watchlist-row .avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.watchlist-row .info {
  flex: 1;
}

.watchlist-row .show-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.watchlist-row .progress {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.wtw-date {
  color: var(--text-dim);
}

.wtw-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.wtw-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(34, 211, 238, 0.12);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

.wtw-badge-zero {
  color: var(--text-dim);
  background: var(--surface-2);
}
