:root {
  color-scheme: light;
  --bg: #efefed;
  --paper: #f7f7f4;
  --text: #222321;
  --muted: #787a76;
  --dim: #a6a7a3;
  --line: #d7d8d3;
  --line-dark: #bbbdb7;
  --accent: #333b46;
  --accent-soft: #dfe3e6;
  --danger: #6d3c3c;
  --radius: 15px;
  --font-size: 22px;
  --meta-font-size: calc(var(--font-size) * .78);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  background: var(--bg);
  color: var(--text);
}

html[data-font-scale="small"] { --font-size: 20px; }
html[data-font-scale="medium"] { --font-size: 22px; }
html[data-font-scale="large"] { --font-size: 24px; }

html[data-theme="light"] {
  color-scheme: light;
  --bg: #efefed; --paper: #f7f7f4; --text: #222321; --muted: #787a76; --dim: #a6a7a3;
  --line: #d7d8d3; --line-dark: #bbbdb7; --accent: #333b46; --accent-soft: #dfe3e6; --danger: #6d3c3c;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1b1c1b; --paper: #242523; --text: #eeeeea; --muted: #a5a7a1; --dim: #696b67;
  --line: #383a36; --line-dark: #50524d; --accent: #d7dce1; --accent-soft: #353a3e; --danger: #d89999;
}
html[data-theme="system"] { color-scheme: light dark; }
@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --bg: #1b1c1b; --paper: #242523; --text: #eeeeea; --muted: #a5a7a1; --dim: #696b67;
    --line: #383a36; --line-dark: #50524d; --accent: #d7dce1; --accent-soft: #353a3e; --danger: #d89999;
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-width: 0;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--font-size)/1.48 "IBM Plex Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.watching-app {
  width: min(100%, 780px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) clamp(18px, 5vw, 42px) calc(124px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  margin-bottom: clamp(28px, 7vw, 54px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2em;
  font-weight: 600;
  letter-spacing: -0.035em;
}
.brand-icon { display: inline-flex; color: var(--accent); }
.lucide-icon { display: block; flex: none; }
.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) {
  .icon-button:hover, .floating-button:hover, .show-toggle:hover, .episode-button:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
}

.main-view { display: grid; gap: clamp(34px, 7vw, 52px); }
.watch-section { min-width: 0; }
.section-heading {
  display: flex;
  width: 100%;
  min-height: 38px;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 10px;
  border: 0;
  border-bottom: 1px solid var(--line-dark);
  background: transparent;
  color: var(--muted);
  font-size: .77em;
  font-weight: 600;
  letter-spacing: .105em;
  text-align: left;
  cursor: pointer;
}
.show-list { display: grid; }
.show-row { position: relative; min-width: 0; border-bottom: 1px solid var(--line); }
.show-row-main { display: flex; align-items: center; min-width: 0; }
.show-toggle {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 2px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.show-copy { display: grid; min-width: 0; gap: 4px; }
.show-title-line { display: flex; min-width: 0; align-items: center; gap: 8px; }
.show-title {
  overflow: hidden;
  color: var(--text);
  font-size: 1em;
  font-weight: 500;
  letter-spacing: -.028em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.priya-marker { display: inline-flex; flex: none; color: var(--muted); }
.show-meta { color: var(--muted); font-size: var(--meta-font-size); letter-spacing: -.015em; }
.show-chevron { color: var(--muted); flex: none; }
.show-actions-button {
  display: grid; flex: none; width: 42px; height: 44px; place-items: center; padding: 0; border: 0;
  border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer;
}
.show-actions-scrim { position: fixed; inset: 0; z-index: 28; background: transparent; }
.show-actions-menu {
  position: absolute; top: 58px; right: 0; z-index: 30; width: min(220px, calc(100vw - 42px));
  overflow: hidden; border: 1px solid var(--line-dark); border-radius: 12px; background: var(--paper);
  box-shadow: 0 12px 34px rgba(0,0,0,.16);
}
.show-actions-menu button {
  display: block; width: 100%; min-height: 46px; padding: 0 14px; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--text); font-size: var(--meta-font-size); text-align: left; cursor: pointer;
}
.show-actions-menu button:last-child { border-bottom: 0; }
.show-actions-menu .show-actions-danger { color: var(--danger); }
@media (hover: hover) and (pointer: fine) {
  .show-actions-button:hover, .show-actions-menu button:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
}

.episode-list {
  display: grid;
  margin: 0;
  padding: 0 0 10px;
  list-style: none;
}
.episode-row { min-width: 0; }
.episode-button {
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 38px 8px 18px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: .92em;
  text-align: left;
  cursor: pointer;
}
.episode-button > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.episode-runtime { color: var(--muted); white-space: nowrap; }
.episode-row--watched .episode-button { color: var(--dim); }
.episode-row--watched .episode-runtime { color: var(--dim); }

.floating-pill {
  position: fixed;
  right: max(18px, calc((100vw - 780px) / 2 + 24px));
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  width: 52px;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--line-dark);
  border-radius: 26px;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  box-shadow: 0 8px 24px rgba(22,23,21,.09);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.floating-button {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.floating-button--active { background: var(--accent); color: var(--bg); }
.floating-divider { height: 1px; margin: 0 10px; background: var(--line); }
.floating-button--active + .floating-divider, .floating-divider:has(+ .floating-button--active) { background: transparent; }

.menu-scrim, .sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(26,27,25,.12);
}
.menu-panel {
  position: fixed;
  top: max(64px, calc(env(safe-area-inset-top) + 52px));
  right: max(18px, calc((100vw - 780px) / 2 + 24px));
  z-index: 50;
  width: min(270px, calc(100vw - 36px));
  overflow: hidden;
  border: 1px solid var(--line-dark);
  border-radius: 14px;
  background: color-mix(in srgb, var(--paper) 98%, transparent);
  box-shadow: 0 16px 40px rgba(20,21,20,.12);
}
.menu-item {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.menu-control-row { display: grid; gap: 9px; padding: 13px 16px 15px; border-bottom: 1px solid var(--line); }
.menu-label { color: var(--muted); font-size: .74em; }
.font-size-controls, .theme-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.font-size-controls button, .theme-controls button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}
.font-size-controls button[aria-pressed="true"], .theme-controls button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--bg); }
.theme-controls button { font-size: .72em; }
.menu-version { padding: 12px 16px; color: var(--muted); font-size: .72em; }

.sheet-scrim { z-index: 60; background: rgba(24,25,23,.26); }
.sheet {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 70;
  width: min(560px, calc(100vw - 24px));
  max-height: min(76vh, 680px);
  overflow: auto;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 18px 60px rgba(20,21,20,.2);
  padding: 18px;
}
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.sheet-header h2 { margin: 0; font-size: 1em; font-weight: 600; }
.field-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .76em; }
.text-field {
  display: block;
  width: 100%;
  min-height: 46px;
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--line-dark);
  border-radius: 10px;
  background: var(--paper);
  color: var(--text);
  font-size: max(16px, 1em);
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compact-field { margin-bottom: 15px; }
.search-results { display: grid; gap: 4px; }
.manual-link {
  min-height: 44px;
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.choice-group { display: grid; gap: 10px; margin: 2px 0 18px; padding: 0; border: 0; }
.choice-group legend { margin-bottom: 8px; color: var(--muted); font-size: .76em; }
.choice-group label, .check-row { display: flex; min-height: 34px; align-items: center; gap: 9px; }
.choice-group input, .check-row input { width: 18px; height: 18px; }
.check-row { margin: 0 0 20px; }
.primary-button {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
}

.archive-view { display: grid; gap: 18px; }
.archive-header { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line-dark); padding-bottom: 12px; }
.archive-header h1 { margin: 0; font-size: 1em; font-weight: 600; }
.archive-list { display: grid; }
.archive-row { display: flex; min-height: 72px; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 2px; border-bottom: 1px solid var(--line); }
.archive-row strong { font-size: .98em; font-weight: 500; }
.archive-meta { margin-top: 3px; color: var(--muted); font-size: .76em; }
.archive-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.season-available { padding: 7px 9px; border: 1px solid var(--line-dark); border-radius: 8px; background: transparent; color: var(--accent); font-size: .72em; cursor: pointer; }
.empty-state { color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(102px + env(safe-area-inset-bottom));
  z-index: 100;
  max-width: calc(100vw - 32px);
  transform: translate(-50%, 12px);
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  opacity: 0;
  padding: 9px 13px;
  font-size: 12px;
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
.toast--visible { transform: translate(-50%, 0); opacity: .96; }

@media (max-width: 520px) {
  .watching-app { padding-left: 16px; padding-right: 16px; }
  .app-header { margin-bottom: 28px; }
  .main-view { gap: 34px; }
  .show-toggle { min-height: 66px; }
  .episode-button { padding-right: 12px; padding-left: 10px; }
  .floating-pill { right: 16px; }
  .menu-panel { right: 16px; }
  .archive-row { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; }
}

.search-empty {
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: .78em;
}
.search-result {
  display: grid;
  width: 100%;
  min-height: 52px;
  gap: 2px;
  padding: 9px 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.search-result-title { font-size: .92em; font-weight: 500; }
.search-result-meta { color: var(--muted); font-size: .72em; }
.sheet-kicker { margin-bottom: 3px; color: var(--muted); font-size: .7em; }
.sheet select.text-field { appearance: auto; }
.show-row--dragging {
  opacity: .26;
}
.drop-marker {
  height: 2px;
  margin: -1px 0;
  border-radius: 2px;
  background: var(--accent);
  pointer-events: none;
}
.dragging-show, .dragging-show * {
  cursor: grabbing !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

.completion-copy {
  margin: -6px 0 18px;
  color: var(--muted);
  font-size: .8em;
}
.completion-actions { display: grid; gap: 9px; }
.secondary-button,
.text-button {
  width: 100%;
  min-height: 46px;
  border-radius: 11px;
  cursor: pointer;
}
.secondary-button {
  border: 1px solid var(--line-dark);
  background: transparent;
}
.text-button {
  border: 0;
  background: transparent;
  color: var(--muted);
}

.auth-shell,
.boot-message {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: max(72px, calc(env(safe-area-inset-top) + 48px)) 22px 48px;
}
.auth-card { display: grid; }
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 28px; }
.auth-brand h1 { margin: 0; font-size: 1.2em; font-weight: 600; letter-spacing: -.035em; }
.auth-copy { margin: 0 0 26px; color: var(--muted); font-size: .82em; }
.auth-message { margin: -8px 0 18px; color: var(--danger); font-size: .78em; }
.boot-message { color: var(--muted); font-size: .82em; }


.show-edit-row { display: flex; justify-content: flex-end; padding: 0 4px 10px; }
.show-edit-button { min-height: 38px; padding: 0 8px; border: 0; background: transparent; color: var(--muted); font-size: .74em; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.edit-show-title { margin: -4px 0 18px; color: var(--text); font-size: .94em; }

.episode-empty { margin: 0; padding: 0.55rem 0 0.9rem; color: var(--muted); font-size: var(--meta-size); }
