:root, [data-theme="dark"] {
  color-scheme: dark;
  --bg: #16191f;
  --bg-deep: #12151a;
  --surface: #1e232c;
  --surface-2: #252b36;
  --ink: #e8e6e1;
  --muted: #9a958c;
  --line: #323844;
  --accent: #4ec9a8;
  --accent-ink: #0c1a16;
  --err: #e07070;
  --ok: #4ec9a8;
  --ph: #2a303a;
  --ph-stripe: #343a46;
  --bar-track: #2e3440;
  --star-off: #4a4650;
  --star-on: #d4b84a;
  --panel: rgba(30, 35, 44, 0.72);
  --glow: #1a2830;
  --cal-head: #1a1e26;
  --cal-day: #1e232c;
  --cal-out: #171a20;
  --ev-season: #1a332c;
  --ev-ep: #2a2830;
  --add: #2a8f5c;
  --pass: #b44545;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 5px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 10px;
  --motion: .18s;
  --motion-slow: .28s;
  --ease-out: ease;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f3ee;
  --bg-deep: #efe8dc;
  --surface: #ffffff;
  --surface-2: #f3eee4;
  --ink: #1c1a16;
  --muted: #6b6458;
  --line: #d9d2c5;
  --accent: #0f5c4c;
  --accent-ink: #ffffff;
  --err: #8b1e1e;
  --ok: #0f5c4c;
  --ph: #ddd6c8;
  --ph-stripe: #d9d2c5;
  --bar-track: #e4ddd0;
  --star-off: #c8c0b4;
  --star-on: #c9a227;
  --panel: rgba(255, 255, 255, 0.55);
  --glow: #fff8e8;
  --cal-head: #f3eee4;
  --cal-day: #ffffff;
  --cal-out: #f7f4ee;
  --ev-season: #e8f0ea;
  --ev-ep: #f0ebe3;
  --add: #1a7a4c;
  --pass: #a33;
}

* { box-sizing: border-box; }
html {
  /* stop layout shift when one page scrolls and another does not */
  scrollbar-gutter: stable;
  overflow-y: scroll;
}
@media (max-width: 800px) {
  html { scrollbar-gutter: auto; }
}
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse at top left, var(--glow) 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-deep) 0%, var(--bg) 42%);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.wrap {
  max-width: 1120px; margin: 0 auto; padding: 1.25rem 1.5rem;
  animation: fade-in var(--motion) var(--ease-out);
}
@supports (view-transition-name: none) {
  .wrap { animation: none; }
}
.wrap--wide { max-width: 1280px; }
.wrap--cal {
  max-width: none;
  width: 100%;
  padding-left: clamp(.75rem, 1.5vw, 1.5rem);
  padding-right: clamp(.75rem, 1.5vw, 1.5rem);
  padding-top: .75rem;
  padding-bottom: .75rem;
}
@media (min-width: 801px) {
  body:has(.wrap--cal) {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }
  body:has(.wrap--cal) .top { flex-shrink: 0; }
  body:has(.wrap--cal) .wrap--cal {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
  }
}
.top {
  display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: center;
  justify-content: space-between; padding: .7rem 1.25rem;
  border-bottom: 1px solid var(--line); background: var(--panel);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 40;
  view-transition-name: site-header;
}
.brand {
  font-weight: 700; font-size: 1.05rem; color: var(--ink);
  letter-spacing: -.01em; text-decoration: none; flex-shrink: 0;
}
.brand:hover { color: var(--accent); text-decoration: none; }
.nav {
  display: flex; flex-wrap: wrap; gap: .45rem .65rem; align-items: center;
  justify-content: flex-end; flex: 1; min-width: 0;
}
.nav-tools {
  display: flex; flex-wrap: wrap; gap: .25rem; align-items: center;
}
.nav-links + .nav-tools {
  margin-left: .15rem; padding-left: .55rem;
  border-left: 1px solid var(--line);
}
.nav-links {
  display: flex; flex-wrap: wrap; gap: .25rem; align-items: center;
}
.nav-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; padding: 0; flex-shrink: 0;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: transparent; color: var(--muted); cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.nav-toggle:hover {
  color: var(--ink); border-color: var(--ink); background: var(--surface);
}
.nav-toggle-bars {
  display: block; width: 1rem; height: .75rem;
  background:
    linear-gradient(currentColor, currentColor) 0 0 / 100% 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) 0 50% / 100% 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) 0 100% / 100% 1.5px no-repeat;
}
.nav-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .35rem .7rem; border-radius: var(--radius);
  border: 1px solid transparent; background: transparent;
  color: var(--muted); font: inherit; font-size: .82rem; font-weight: 500;
  line-height: 1.2; text-decoration: none; cursor: pointer;
  box-sizing: border-box;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.nav-btn:hover {
  color: var(--ink); background: var(--surface); text-decoration: none;
}
.nav-btn.is-active {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 500;
}
.nav-btn.is-active:hover {
  color: var(--accent-ink); background: var(--accent); border-color: var(--accent);
}
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; padding: 0; flex-shrink: 0;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: transparent; color: var(--muted); cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.theme-toggle:hover {
  color: var(--ink); border-color: var(--ink); background: var(--surface);
}
.theme-toggle svg { width: 1.1rem; height: 1.1rem; display: none; }
.theme-toggle .icon-search { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}
@view-transition { navigation: auto; }
::view-transition-old(root) {
  animation: fade-out var(--motion) var(--ease-out) both;
}
::view-transition-new(root) {
  animation: fade-in var(--motion) var(--ease-out) both;
}
::view-transition-old(site-header),
::view-transition-new(site-header) {
  animation: none;
}
@media (prefers-reduced-motion: reduce) {
  .wrap { animation: none; }
  ::view-transition-old(root),
  ::view-transition-new(root) { animation: none; }
  .flash li,
  .search-results,
  #season-panel,
  [id^="watch-card-"],
  dialog.modal,
  dialog.modal::backdrop {
    animation: none !important;
    transition: none !important;
  }
}
.muted { color: var(--muted); }
.flash { list-style: none; padding: 0; }
.flash li {
  padding: .5rem .75rem; margin: 0 0 .5rem; border: 1px solid var(--line);
  background: var(--surface); border-radius: var(--radius);
  animation: fade-in var(--motion-slow) var(--ease-out) both;
}
.flash .error { border-color: var(--err); color: var(--err); }
.flash .ok { border-color: var(--ok); color: var(--ok); }
.status-msg {
  padding: .5rem .75rem; margin: .65rem 0; border: 1px solid var(--line);
  background: var(--surface); border-radius: var(--radius); max-width: 36rem;
}
.status-msg--err { border-color: var(--err); color: var(--err); }
.status-msg--ok { border-color: var(--ok); color: var(--ok); }
.export-progress { max-width: 28rem; }
.export-progress .bar { margin-top: .45rem; }
.export-progress-head { font-size: .92rem; }
.export-progress-counts { margin: .4rem 0 0; font-size: .82rem; }
.filters, form.inline { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 1rem 0; }
input, select, button, textarea {
  font: inherit; padding: .4rem .55rem; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); border-radius: var(--radius);
}
button { cursor: pointer; }

/* Button roles — see styles.md. .btn-watched is a legacy alias for .btn */
.btn,
.btn-watched,
a.btn,
a.btn-watched {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  box-sizing: border-box;
  font: inherit;
  font-weight: 600;
  padding: .4rem .75rem;
  line-height: 1.25;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  cursor: pointer;
  width: auto;
}
.btn:hover,
.btn-watched:hover,
a.btn:hover,
a.btn-watched:hover {
  filter: brightness(1.05);
  text-decoration: none;
}

/* Filled neutral secondary — not outline-only */
.btn-ghost,
a.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  box-sizing: border-box;
  font: inherit;
  font-weight: 500;
  padding: .4rem .75rem;
  line-height: 1.25;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  width: auto;
}
.btn-ghost:hover,
a.btn-ghost:hover {
  background: var(--surface);
  border-color: var(--ink);
  color: var(--ink);
  text-decoration: none;
  filter: none;
}

.btn-danger,
a.btn-danger,
.btn-pass,
.btn-pass-wide,
.btn-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  box-sizing: border-box;
  font: inherit;
  font-weight: 600;
  padding: .4rem .75rem;
  line-height: 1.25;
  border: 1px solid var(--pass);
  border-radius: var(--radius);
  background: var(--pass);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  width: auto;
}
.btn-danger:hover,
a.btn-danger:hover,
.btn-pass:hover,
.btn-pass-wide:hover,
.btn-logout:hover {
  filter: brightness(1.08);
  text-decoration: none;
}
.btn-danger:disabled {
  opacity: .45; cursor: not-allowed; filter: none;
}

.btn-icon,
.btn-add,
.btn-pass {
  width: 2.1rem; height: 2.1rem; padding: 0;
  font-size: 1.25rem; font-weight: 700; line-height: 1;
  border-radius: var(--radius);
}
.btn-add {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.btn-add:hover { filter: brightness(1.05); }

.btn-sm, .btn-ep { padding: .35rem .65rem; font-size: .82rem; white-space: nowrap; }
.btn-block { width: 100%; }

button.theme-toggle {
  background: transparent; color: var(--muted); border-color: var(--line);
}
button.theme-toggle:hover {
  color: var(--ink); border-color: var(--ink); background: var(--surface);
}
.media-list, .ep-list { list-style: none; padding: 0; margin: 0; }
.media-list li, .ep-list li {
  display: flex; flex-wrap: wrap; align-items: center; gap: .45rem .7rem;
  padding: .7rem 0; border-bottom: 1px solid var(--line);
}
.media-list li > p { flex: 1 1 100%; margin: .15rem 0 0; }

.season-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: .85rem 1rem;
  margin: 1rem 0;
}
.season-tile {
  display: flex; flex-direction: column; gap: .4rem;
  padding: 0; border: 1px solid transparent; background: transparent;
  color: inherit; text-align: left; cursor: pointer; border-radius: 6px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.season-tile:hover { border-color: var(--line); }
.season-tile.is-open { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.season-tile.is-complete .season-poster {
  outline: 2px solid var(--ok);
  outline-offset: 2px;
}
.season-poster {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 4px;
  background: var(--ph);
}
.season-poster img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}
.season-ph { width: 100%; height: auto; aspect-ratio: 2 / 3; }
.season-tile-meta { display: flex; flex-direction: column; gap: .1rem; font-size: .85rem; }
.season-panel {
  margin: .5rem 0 1.5rem; padding: .85rem 0 0; border-top: 1px solid var(--line);
}
.season-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .5rem;
}
.season-panel-head h3 { margin: 0; }
.htmx-indicator { display: none; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { display: block; }
.ep-cards { list-style: none; padding: 0; margin: 0 0 1rem; }
.ep-card {
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr);
  gap: .85rem 1rem;
  padding: .85rem 0;
  border-bottom: 1px solid var(--line);
  align-items: start;
}
.ep-card.is-watched { opacity: .92; }
.ep-still {
  width: 176px; height: 99px; border-radius: 4px; overflow: hidden;
  background: var(--ph); flex-shrink: 0;
}
.ep-still img { display: block; width: 100%; height: 100%; object-fit: cover; }
.ep-still .still-ph { width: 100%; height: 100%; }
.ep-body { min-width: 0; display: flex; flex-direction: column; gap: .35rem; }
.ep-top {
  display: flex; flex-wrap: wrap; gap: .5rem .85rem;
  align-items: flex-start; justify-content: space-between;
}
.ep-heading {
  display: flex; flex-wrap: wrap; gap: .35rem .55rem; align-items: baseline; min-width: 0;
}
.ep-title { font-size: 1rem; line-height: 1.25; }
.ep-date { margin: 0; font-size: .78rem; }
.ep-overview {
  margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.ep-actions {
  display: flex; flex-wrap: wrap; gap: .4rem .55rem; align-items: center; flex-shrink: 0;
}
.ep-actions form { margin: 0; }
.ep-plays { font-size: .78rem; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .ep-card { grid-template-columns: 1fr; }
  .ep-still { width: 100%; height: auto; aspect-ratio: 16 / 9; }
}
.poster-ph {
  width: 70px; height: 105px; background: var(--line); display: inline-block; flex-shrink: 0;
}
.poster-ph.sm { width: 36px; height: 54px; }
.poster-ph.big { width: 70px; height: 105px; }
.detail-head { display: flex; gap: 1.25rem; flex-wrap: wrap; align-items: flex-start; }
.detail-main { flex: 1; min-width: 0; }
.detail-overview { max-width: 42rem; line-height: 1.45; }
.detail-actions {
  display: flex; flex-wrap: wrap; gap: .45rem; align-items: center;
  margin-top: 1rem; padding-top: .85rem; border-top: 1px solid var(--line);
}
.detail-actions form { margin: 0; }
.detail-actions .btn,
.detail-actions .btn-ghost { padding: .4rem .75rem; font-size: .85rem; }
.fetch-meta {
  display: inline-flex; flex-wrap: wrap; gap: .35rem .55rem; align-items: center;
}
.fetch-when { font-size: .78rem; }
.star-rate {
  display: inline-flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  gap: 0;
  align-items: center;
}
.star-btn {
  background: none; border: none; padding: 0 .04rem; margin: 0;
  font-size: 1.25rem; line-height: 1; cursor: pointer; color: var(--star-off);
}
.star-btn.is-on { color: var(--star-on); }
.star-btn:hover,
.star-btn:hover ~ .star-btn { color: var(--star-on); }
.ids { display: flex; flex-wrap: wrap; gap: .35rem .75rem; margin: .65rem 0 0; }
.ids a { color: var(--accent); font-size: .9rem; }
.ids a:hover { text-decoration: underline; }

.credits-block { margin: .85rem 0 0; }
.credits-label {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; margin: 0 0 .4rem;
}
.credits-row { margin-bottom: .75rem; max-width: 100%; }
.credits-line { margin: .35rem 0; font-size: .92rem; max-width: 46rem; }
.credits-line .credits-label { margin-right: .5rem; }
.credits-line a { color: var(--accent); }
.cast-strip {
  list-style: none; margin: 0;
  display: flex; gap: .75rem;
  overflow-x: auto; overflow-y: hidden;
  padding: .15rem .15rem .55rem 0;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.cast-strip li {
  flex: 0 0 auto; width: 5.25rem;
  scroll-snap-align: start;
}
.cast-link {
  display: flex; flex-direction: column; gap: .25rem;
  text-decoration: none; color: inherit; font-size: .78rem; line-height: 1.25;
}
.cast-link img, .cast-ph {
  width: 72px; height: 108px; object-fit: cover; background: var(--line);
  display: block; border-radius: 3px;
}
.cast-name {
  font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.cast-char {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.ep-credits { margin: .35rem 0 0; font-size: .82rem; line-height: 1.35; }
.ep-credits a { color: var(--accent); }

.person-head { display: flex; gap: 1.25rem; flex-wrap: wrap; align-items: flex-start; margin-bottom: 1.25rem; }
.person-photo, .person-photo-ph {
  width: 120px; height: 180px; object-fit: cover; background: var(--line); flex-shrink: 0;
}
.person-main { flex: 1; min-width: 0; }
.person-counts { margin: .45rem 0 0; font-size: .9rem; }
.person-section { margin: 0 0 1.75rem; }
.person-section h2 { margin: 0 0 .35rem; font-size: 1.15rem; }
.person-count { font-size: .85rem; font-weight: 500; }
.person-section-note { margin: 0 0 .65rem; font-size: .85rem; }
.person-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem 1.1rem;
  margin: .75rem 0 0;
  align-items: stretch;
}
.person-tile {
  display: flex; flex-direction: column; gap: .4rem; min-width: 0;
  height: 100%;
}
.person-poster {
  display: block; width: 100%; aspect-ratio: 2 / 3; overflow: hidden;
  border-radius: 4px; background: var(--ph); padding: 0; border: none;
  color: inherit; text-decoration: none; cursor: pointer; flex-shrink: 0;
}
button.person-poster { background: var(--ph); }
.person-poster img,
.person-poster .poster-ph {
  display: block; width: 100%; height: 100%; object-fit: cover; object-position: center top;
  pointer-events: none;
}
.person-tile-meta {
  display: flex; flex-direction: column; gap: .12rem; font-size: .82rem; min-width: 0;
  flex: 1 1 auto;
  /* fixed text block so Add/actions never lived here — rows stay level */
  min-height: 4.6rem;
}
.person-tile-meta a,
.person-tile-meta .linkish {
  color: inherit; text-decoration: none; text-align: left;
}
.person-tile-meta a:hover strong,
.person-tile-meta .linkish:hover strong { text-decoration: underline; }
.person-tile-title {
  display: block; min-height: 2.5em;
}
.person-tile-title strong {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.25;
}
.person-tile-sub {
  font-size: .78rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.person-role {
  font-size: .72rem;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 1.05em;
}
.person-tile-foot {
  min-height: 2rem;
  margin-top: auto;
  display: flex;
  align-items: stretch;
}
.person-tile-foot form { margin: 0; width: 100%; }
.person-tile-foot .btn-ep {
  width: 100%;
  padding: .3rem .4rem;
  font-size: .75rem;
}

.discovery-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 1rem .85rem;
  margin: 1rem 0 0;
}
.history-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: .75rem .65rem;
}
.plan-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 1rem .85rem;
  margin: 1rem 0 0;
  list-style: none;
  padding: 0;
}
/* Match discovery/plan: 8→4→2 only. */
@media (max-width: 1000px) {
  .discovery-grid,
  .plan-grid,
  .history-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .discovery-grid,
  .plan-grid,
  .history-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.discovery-tile,
.plan-tile {
  transition: opacity .35s ease, transform .35s ease;
}
.discovery-tile.htmx-swapping,
.plan-tile.htmx-swapping {
  opacity: 0;
  transform: scale(.96);
}
.discovery-tile {
  display: flex; flex-direction: column; gap: .45rem; min-width: 0;
  height: 100%;
}
.discovery-poster, .plan-poster.media-preview-open {
  display: block; width: 100%; aspect-ratio: 2 / 3; overflow: hidden;
  border-radius: 4px; background: var(--ph); padding: 0; border: none; cursor: pointer;
  color: inherit;
}
button.discovery-poster,
button.plan-poster {
  background: var(--ph);
}
.discovery-poster img, .plan-poster.media-preview-open img {
  display: block; width: 100%; height: 100%; object-fit: cover; object-position: center top;
  pointer-events: none;
}
.discovery-tile-meta, .plan-tile-meta {
  display: flex; flex-direction: column; gap: .1rem; font-size: .85rem; min-width: 0;
}
.linkish {
  background: none; border: none; padding: 0; margin: 0; text-align: left;
  color: inherit; cursor: pointer; font: inherit;
}
.linkish:hover strong { text-decoration: underline; }
.discovery-tile-meta strong, .plan-tile-meta strong {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.25;
  min-height: 2.5em;
}
.discovery-actions {
  display: flex; flex-direction: row; flex-wrap: nowrap;
  align-items: center; justify-content: space-between;
  margin-top: auto; gap: .35rem;
}
.discovery-actions form { margin: 0; display: flex; }
.discovery-actions .btn-icon {
  flex: none;
  width: 1.75rem; height: 1.55rem;
  font-size: 1.05rem; font-weight: 700; line-height: 1;
}

.search-meta { margin: 0 0 .25rem; }
.search-empty { margin: 1.25rem 0 0; }
.search-section { margin-top: 1.75rem; }
.search-section h2 {
  margin: 0 0 .15rem;
  font-size: 1.05rem;
  font-weight: 600;
}
.search-section .discovery-grid { margin-top: .85rem; }

.search-bar {
  display: flex; flex-wrap: wrap; gap: .55rem .65rem; align-items: center;
  margin: 0; flex: 1 1 auto; min-width: 0;
}
.search-bar-field { flex: 1 1 10rem; margin: 0; min-width: 0; }
.search-bar-field input[type="search"] {
  width: 100%; box-sizing: border-box;
  padding: .55rem .7rem; font-size: 1rem;
}
.search-busy { font-size: .85rem; }
.search-busy.htmx-indicator { display: none; }
.search-busy.htmx-request { display: inline; }
.search-results {
  margin: 0;
  transition: opacity var(--motion) var(--ease-out);
}
.search-dialog .search-results:not(:has(*)) {
  display: none;
}
.search-dialog .search-results:has(*) {
  margin-top: .85rem;
  max-height: min(65vh, calc(100vh - 8rem));
  overflow: auto;
  overscroll-behavior: contain;
}
.search-dialog .discovery-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
@media (max-width: 520px) {
  .search-dialog .discovery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.search-results.htmx-settling,
#season-panel.htmx-settling,
[id^="watch-card-"].htmx-settling {
  opacity: 0;
}
#season-panel,
[id^="watch-card-"] {
  transition: opacity var(--motion) var(--ease-out);
}

/* Modals — opacity only (open + close via discrete transitions) */
dialog.modal {
  opacity: 0;
  transition:
    opacity var(--motion) var(--ease-out),
    overlay var(--motion) var(--ease-out) allow-discrete,
    display var(--motion) var(--ease-out) allow-discrete;
}
dialog.modal[open] {
  opacity: 1;
}
@starting-style {
  dialog.modal[open] {
    opacity: 0;
  }
}
dialog.modal::backdrop {
  background: rgba(0,0,0,.55);
  opacity: 0;
  transition:
    opacity var(--motion) var(--ease-out),
    overlay var(--motion) var(--ease-out) allow-discrete,
    display var(--motion) var(--ease-out) allow-discrete;
}
dialog.modal[open]::backdrop {
  opacity: 1;
}
@starting-style {
  dialog.modal[open]::backdrop {
    opacity: 0;
  }
}
/* Fallback when starting-style / discrete transitions unavailable */
@supports not (overlay: auto) {
  dialog.modal[open] {
    animation: fade-in var(--motion) var(--ease-out) both;
  }
  dialog.modal[open]::backdrop {
    animation: fade-in var(--motion) var(--ease-out) both;
  }
}

.modal {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 0;
  max-width: min(640px, calc(100vw - 2rem));
  width: 100%;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 16px 48px rgba(0,0,0,.45);
}
.modal.search-dialog {
  width: min(40rem, calc(100vw - 2rem));
  overflow: hidden;
}
.search-dialog-body {
  display: flex; flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
}
.search-dialog-top {
  display: flex; gap: .55rem; align-items: center;
  flex: none;
}
.modal-body { padding: 1.1rem 1.2rem 1.25rem; }
.modal-title { margin: 0 0 .35rem; font-size: 1.25rem; line-height: 1.25; }
.preview-subtitle {
  margin: 0 0 .35rem;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
}
.preview-subtitle[hidden] { display: none; }
#preview-meta { margin: 0 0 .75rem; }
.modal-field {
  display: flex; flex-direction: column; gap: .35rem;
  font-size: .85rem; color: var(--muted); margin: 1rem 0;
}
.modal-actions {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .75rem;
}
.modal-close { float: right; margin: 0 0 .5rem .5rem; }
.preview-body { overflow: auto; }
.preview-layout {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 1rem 1.15rem;
  clear: both;
}
.preview-poster-wrap {
  width: 140px; aspect-ratio: 2 / 3; overflow: hidden; border-radius: 4px; background: var(--ph);
}
.preview-poster-wrap.is-still {
  width: 180px; aspect-ratio: 16 / 9;
}
.preview-layout:has(.preview-poster-wrap.is-still) {
  grid-template-columns: 180px minmax(0, 1fr);
}
.preview-poster-wrap img {
  display: block; width: 100%; height: 100%; object-fit: cover; object-position: center top;
}
.preview-overview {
  margin: .65rem 0 0; line-height: 1.45; max-height: 12rem; overflow: auto; white-space: pre-wrap;
}
.preview-actions {
  display: flex; flex-wrap: wrap; gap: .45rem; margin-top: 1rem; align-items: center;
}
.preview-actions form { margin: 0; }
.preview-actions .btn-ghost,
.preview-actions .btn,
.preview-actions a.btn-ghost,
.preview-actions a.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .4rem .75rem; text-decoration: none; width: auto;
}
@media (max-width: 520px) {
  .preview-layout { grid-template-columns: 1fr; }
  .preview-poster-wrap { width: 120px; }
}
.login {
  max-width: 360px; margin: 4.5rem auto; padding: 1.5rem 1.35rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.login h1 { margin: 0 0 .35rem; }
.login .muted { margin: 0 0 1.1rem; }
.login form {
  display: flex; flex-direction: column; gap: .85rem;
}
.login label {
  display: flex; flex-direction: column; gap: .3rem;
  font-size: .82rem; color: var(--muted);
}
.login input { width: 100%; padding: .5rem .65rem; }
.login button,
.login .btn {
  width: 100%; padding: .55rem .75rem; font-weight: 600;
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
h1 { margin-top: 0; font-size: 1.6rem; letter-spacing: -.015em; }
h2 { font-size: 1.15rem; margin-top: 1.75rem; }

.ep-code { font-variant-numeric: tabular-nums; font-weight: 600; }
.bar {
  height: 8px; background: var(--bar-track); border-radius: 99px; overflow: hidden; width: 100%;
}
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; }
.bar-label { font-size: .72rem; display: block; margin-top: .2rem; text-align: center; }

/* Shared page head + filter bars (styles.md) */
.page-head,
.watching-head {
  display: flex; flex-wrap: wrap; gap: .85rem 1rem; align-items: flex-end;
  justify-content: space-between; margin-bottom: .35rem;
}
.page-head h1,
.watching-head h1 { margin-bottom: 0; }
.page-head .head-note,
.watching-head .head-note { margin: .2rem 0 0; }
.page-head-actions { margin: 0; flex: none; }

.filter-bar,
.plan-filters,
.history-filters,
.watching-sort {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .55rem .75rem;
  align-items: end;
  margin: .75rem 0 1rem; padding: .65rem .75rem;
  border: 1px solid var(--line); border-radius: var(--radius-md);
  background: var(--panel);
}
.watching-sort {
  display: flex; flex-wrap: wrap;
  align-items: center; margin: 0; padding: .4rem .55rem;
  grid-template-columns: unset;
}
.filter-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.25rem, 1fr));
  gap: .45rem .65rem;
  min-width: 0;
  align-items: end;
}
.filter-actions {
  display: flex; flex-wrap: nowrap; gap: .4rem; align-items: center;
  justify-content: flex-end;
}
.filter-bar label,
.plan-filters label,
.history-filters label {
  display: flex; flex-direction: column; gap: .2rem;
  font-size: .72rem; color: var(--muted);
  min-width: 0;
  margin: 0;
}
.watching-sort label {
  font-size: .72rem; font-weight: 500; letter-spacing: .03em;
  text-transform: uppercase; color: var(--muted); margin: 0;
}
.filter-bar input,
.filter-bar select,
.plan-filters input,
.plan-filters select,
.history-filters input,
.history-filters select {
  width: 100%;
  min-width: 0;
  max-width: none;
  box-sizing: border-box;
  padding: .3rem .4rem;
  font-size: .85rem;
}
.filter-bar .btn,
.filter-bar .btn-ghost,
.plan-filters .btn,
.plan-filters .btn-ghost,
.history-filters .btn,
.watching-sort .btn {
  padding: .35rem .65rem; font-size: .85rem;
  white-space: nowrap;
}
.watching-sort .btn { padding: .3rem .55rem; font-size: .82rem; font-weight: 500; }
.watching-sort select {
  min-width: 10.5rem; padding: .3rem .45rem; font-size: .85rem;
  background: var(--surface); border-color: var(--line);
}
.watching-sort input[type="search"] {
  min-width: 10rem; max-width: 14rem; padding: .3rem .45rem; font-size: .85rem;
  background: var(--surface); border-color: var(--line);
}
.watching-sort-clear {
  font-size: .78rem; color: var(--muted); text-decoration: none;
  padding: .15rem .2rem;
}
.watching-sort-clear:hover { color: var(--ink); text-decoration: underline; }
@media (max-width: 720px) {
  .plan-filters,
  .history-filters {
    grid-template-columns: 1fr;
  }
  .filter-actions { justify-content: flex-end; }
}
@media (max-width: 520px) {
  .watching-sort { width: 100%; }
  .watching-sort select { flex: 1; min-width: 0; }
  .filter-fields {
    grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
  }
}

/* Watching (main) */
.watch-list { list-style: none; padding: 0; margin: 1rem 0 0; }
.watch-card {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) minmax(320px, 400px);
  gap: .75rem 1.25rem;
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--line);
  align-items: center;
}
.watch-poster img {
  display: block; width: 70px; height: 105px; object-fit: cover; border-radius: 3px;
}
.watch-body {
  display: flex; flex-direction: column; gap: .55rem; min-width: 0;
  justify-content: center;
}
.watch-title { min-width: 0; line-height: 1.3; }
.watch-title a { color: inherit; text-decoration: none; }
.watch-title a:hover strong { text-decoration: underline; }
.watch-progress {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  width: 100%;
  min-width: 0;
}
.watch-progress .bar { min-width: 0; height: 14px; }
.watch-stats {
  display: flex;
  flex-wrap: wrap;
  gap: .15rem .9rem;
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}

.watch-next { justify-self: end; width: 100%; max-width: 400px; align-self: center; }
.next-card {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  column-gap: .75rem;
  align-items: center;
  height: 105px;
  box-sizing: border-box;
  padding: .4rem .55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.next-still {
  display: block;
  width: 160px;
  height: 90px;
  aspect-ratio: auto;
  border-radius: 4px;
  overflow: hidden;
  background: var(--ph);
  flex-shrink: 0;
  padding: 0;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
}
.next-still:hover { outline: 2px solid var(--accent); outline-offset: 1px; filter: none; }
.next-still img {
  display: block; width: 160px; height: 90px; object-fit: cover;
}
.next-still img.thumb-fade {
  opacity: 0;
  transition: opacity .35s ease;
}
.next-still img.thumb-fade.is-ready {
  opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
  .next-still img.thumb-fade { transition: none; opacity: 1; }
  .next-still.is-loading-still .still-ph { animation: none; }
}
.next-still.is-loading-still .still-ph {
  animation: still-pulse 1.2s ease-in-out infinite;
}
@keyframes still-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}
.still-ph { display: block; width: 160px; height: 90px; background: repeating-linear-gradient(
  -45deg, var(--ph), var(--ph) 6px, var(--ph-stripe) 6px, var(--ph-stripe) 12px
); }
.next-info {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  min-width: 0;
  justify-content: center;
  padding-right: .1rem;
}
.next-meta {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.next-meta:hover { filter: none; background: transparent; }
.next-meta:hover .next-name { text-decoration: underline; }
.next-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  line-height: 1.2;
}
.next-meta .ep-code { font-size: .8rem; line-height: 1.2; }
.next-name {
  font-size: .88rem; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.next-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-top: .1rem;
}
.next-date { font-size: .75rem; line-height: 1.2; }
.next-foot form { margin: 0 0 0 auto; display: flex; align-items: center; }
.btn-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  padding: 0;
  border: 1.5px solid var(--muted);
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}
.btn-check:hover {
  color: var(--accent-ink);
  border-color: var(--accent);
  background: var(--accent);
  filter: none;
}
.btn-check:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 800px) {
  .watch-card {
    grid-template-columns: 70px 1fr;
    grid-template-areas:
      "poster title"
      "poster progress"
      "next next";
  }
  .watch-poster { grid-area: poster; }
  .watch-body { display: contents; }
  .watch-title { grid-area: title; }
  .watch-progress { grid-area: progress; }
  .watch-next { grid-area: next; justify-self: stretch; max-width: none; }
  .next-card { max-width: none; }
}
@media (max-width: 600px) {
  .next-card {
    height: auto;
    grid-template-columns: 1fr;
    row-gap: .55rem;
    padding: .65rem;
  }
  .next-still,
  .next-still img,
  .next-still .still-ph {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }
  .detail-head img { width: 100px; height: auto; }
}

/* History */
.history-page h1 { margin-bottom: .15rem; }
.history-tile {
  display: flex; flex-direction: column; gap: .2rem; min-width: 0;
  color: inherit; text-decoration: none;
}
.history-tile:hover { text-decoration: none; }
.history-tile:hover .history-title { text-decoration: underline; }
.history-thumb {
  width: 100%; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 3px;
  background: var(--ph);
}
.history-thumb img {
  display: block; width: 100%; height: 100%; object-fit: cover; object-position: center;
}
.history-thumb.is-poster img { object-position: center top; }
.history-tile time {
  font-size: .68rem; font-variant-numeric: tabular-nums; color: var(--muted);
  line-height: 1.2; margin-top: .15rem;
}
.history-tile time span { margin-left: .25rem; }
.history-title {
  font-size: .78rem; font-weight: 600; line-height: 1.2;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.history-tile .ep-code { font-size: .72rem; color: var(--ink); }
.history-tile .muted { font-size: .72rem; }
.history-tile .tag { align-self: start; margin-top: .1rem; font-size: .62rem; padding: .05rem .25rem; }
.pager {
  margin: 1.5rem 0 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .55rem;
}
.pager-solo { margin: 1rem 0 0; text-align: center; }
.pager-controls {
  display: flex; flex-wrap: wrap; gap: .45rem .55rem; align-items: center; justify-content: center;
}
.pager-pages {
  display: flex; flex-wrap: wrap; gap: .25rem; align-items: center;
  list-style: none; margin: 0; padding: 0;
}
.pager-btn, .pager-num {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.1rem; height: 2.1rem; padding: 0 .55rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-2); color: var(--ink); text-decoration: none;
  font-size: .85rem; font-variant-numeric: tabular-nums;
}
a.pager-btn:hover, a.pager-num:hover {
  border-color: var(--accent); color: var(--accent); text-decoration: none;
}
.pager-num.is-current {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
  font-weight: 600;
}
.pager-btn.is-disabled {
  opacity: .4; cursor: default; pointer-events: none;
}
.pager-gap {
  min-width: 1.25rem; text-align: center; color: var(--muted); font-size: .85rem;
}
.pager-meta {
  margin: 0; font-size: .78rem; text-align: center;
}
.tag {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .04em;
  border: 1px solid var(--line); border-radius: var(--radius); padding: .1rem .35rem; color: var(--muted);
}

/* Plan */
.plan-tile {
  display: flex; flex-direction: column; gap: .45rem; min-width: 0;
}
.plan-poster {
  display: block; width: 100%; aspect-ratio: 2 / 3; overflow: hidden;
  border-radius: 4px; background: var(--ph);
  padding: 0; border: none; cursor: pointer; color: inherit;
}
.plan-poster img {
  display: block; width: 100%; height: 100%; object-fit: cover; object-position: center top;
  pointer-events: none;
}
.plan-tile-meta {
  display: flex; flex-direction: column; gap: .1rem; font-size: .85rem; min-width: 0;
}
.plan-tile-meta strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}
.plan-genres {
  font-size: .72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plan-actions {
  display: flex; flex-direction: row; flex-wrap: nowrap; gap: .3rem; align-items: stretch;
  margin-top: .1rem;
}
.plan-actions form { margin: 0; flex: 1 1 0; min-width: 0; }
.plan-actions .btn,
.plan-actions .btn-ghost {
  width: 100%;
  padding: .3rem .25rem;
  font-size: .72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-poster {
  width: 40px; height: 60px; object-fit: cover; object-position: center top;
  vertical-align: middle; margin-right: .15rem; border-radius: 3px;
  background: var(--ph); flex-shrink: 0;
}
.list-create {
  display: flex; flex-wrap: wrap; gap: .5rem .65rem; align-items: end;
  margin: 1rem 0 1.25rem;
}
.list-create label { display: flex; flex-direction: column; gap: .25rem; margin: 0; }
.list-membership {
  display: flex; flex-wrap: wrap; gap: .55rem .75rem; align-items: center;
  margin: .85rem 0 0;
}
.list-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.list-chip-form { margin: 0; }
.list-chip {
  font: inherit; font-size: .78rem; padding: .2rem .55rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2); color: var(--ink); cursor: pointer;
}
.list-chip:hover { border-color: var(--err); color: var(--err); }
.list-add-form {
  display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: 0;
}
.list-add-label { margin: 0; }
.list-add-form select { font-size: .85rem; }
.badge {
  display: inline-block; font-size: .72rem; padding: .15rem .4rem;
  border: 1px solid var(--line); border-radius: var(--radius); margin-right: .35rem;
  color: var(--muted); vertical-align: middle;
}
.badge-dropped { border-color: var(--err); color: var(--err); }
.badge-ok { border-color: var(--ok); color: var(--ok); }
.notes-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.notes-list li { padding: .65rem 0; border-bottom: 1px solid var(--line); }
.note-meta { font-size: .78rem; margin-bottom: .25rem; }
.note-body { white-space: pre-wrap; }
.note-form textarea { width: 100%; min-height: 4.5rem; max-width: 36rem; }

/* Settings */
.settings-layout {
  display: grid;
  grid-template-columns: 12.5rem minmax(0, 1fr);
  gap: 1.5rem 2rem;
  align-items: start;
  margin-top: .25rem;
}
.settings-nav {
  position: sticky;
  top: 1rem;
  padding: .35rem 0;
}
.settings-brand {
  margin: 0 0 .85rem;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.settings-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.settings-nav-link {
  display: block;
  padding: .45rem .65rem;
  border-radius: 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: .92rem;
}
.settings-nav-link:hover {
  color: var(--ink);
  background: var(--surface);
  text-decoration: none;
}
.settings-nav-link.is-active {
  color: var(--ink);
  background: var(--surface-2);
  font-weight: 600;
}
.settings-main { min-width: 0; }
.settings-header { margin-bottom: 1.15rem; }
.settings-header h2 { margin: 0 0 .35rem; font-size: 1.25rem; }
.settings-header p { margin: 0; max-width: 40rem; }
.settings-form {
  display: flex;
  flex-direction: column;
  gap: .85rem;
  max-width: 28rem;
}
.settings-form label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .9rem;
}
.settings-form input[type="text"],
.settings-form input[type="password"],
.settings-form input[type="number"],
.settings-form select {
  padding: .45rem .55rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.settings-fieldset {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .85rem 1rem 1rem;
  margin: 0 0 .25rem;
  background: var(--panel);
  max-width: 28rem;
}
.settings-fieldset legend {
  padding: 0 .35rem;
  font-weight: 600;
  font-size: .95rem;
}
.field-meta { font-size: .78rem; }
.check-inline {
  flex-direction: row !important;
  align-items: center;
  gap: .5rem !important;
  font-size: .85rem;
  color: var(--muted);
}
.settings-kv {
  margin: 0;
  max-width: 28rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
}
.settings-kv > div {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  gap: .5rem;
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}
.settings-kv dt { margin: 0; color: var(--muted); font-size: .85rem; }
.settings-kv dd { margin: 0; word-break: break-all; }
.settings-note { margin-top: 1.25rem; max-width: 36rem; font-size: .88rem; }
@media (max-width: 800px) {
  .settings-layout {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .settings-nav { position: static; }
  .settings-nav ul {
    flex-direction: row;
    flex-wrap: wrap;
    gap: .35rem;
  }
}

.settings-links { list-style: none; padding: 0; margin: .5rem 0 1.5rem; }
.settings-links li {
  padding: .65rem .75rem; margin-bottom: .35rem;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}
.settings-links a { text-decoration: none; }
.settings-links a:hover strong { text-decoration: underline; }
.dropped-list { list-style: none; padding: 0; margin: .75rem 0 0; }
.dropped-row {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .55rem .75rem; margin-bottom: .35rem;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}
.dropped-row a { text-decoration: none; min-width: 0; }
.dropped-row form { margin: 0; flex-shrink: 0; }
.danger-title { color: var(--err); }
.settings-logout { margin: 1.25rem 0; }
.path-box {
  display: inline-block; padding: .35rem .55rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: 4px; font-size: .85rem;
  word-break: break-all;
}
.settings-panel {
  margin: 1rem 0 1.5rem; padding: .85rem 1rem; border: 1px solid var(--line);
  background: var(--panel); border-radius: 6px;
}
.settings-panel h3 { margin: 0 0 .35rem; font-size: 1rem; }
.settings-panel-head {
  display: flex; flex-wrap: wrap; gap: .85rem 1.5rem;
  justify-content: space-between; align-items: flex-start;
  margin-bottom: .85rem;
}
.settings-lede { margin: .15rem 0 0; max-width: 36rem; }
.settings-actions {
  display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .65rem;
}
.settings-actions form { margin: 0; }
.settings-steps {
  margin: .75rem 0 1rem 1.25rem;
  padding: 0;
  line-height: 1.5;
}

.queue-stats {
  display: flex; flex-wrap: wrap; gap: .65rem 1.1rem; margin: 0;
  font-variant-numeric: tabular-nums;
}
.queue-stats > div { display: flex; flex-direction: column; gap: .1rem; min-width: 4.5rem; }
.queue-stats dt {
  display: flex; align-items: center; gap: .3rem;
  margin: 0; font-size: .72rem; color: var(--muted); font-weight: 500;
}
.queue-stats dd { margin: 0; font-size: 1.15rem; font-weight: 600; }
.job-failed-label { color: var(--err); }
.queue-progress { margin: .35rem 0 1rem; max-width: 28rem; }
.queue-eta { margin: .35rem 0 0; font-size: .85rem; }
.job-section-title {
  margin: 1rem 0 .4rem;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.job-section-failed { color: var(--err); }
.job-retry { margin: 0; }
.job-row .job-retry .btn-ghost { padding: .25rem .5rem; font-size: .8rem; }

.refresh-actions {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 0;
}
.refresh-actions > li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .75rem 1.25rem;
  align-items: center;
  padding: .75rem 0;
  border-top: 1px solid var(--line);
}
.refresh-actions > li:first-child { border-top: none; padding-top: .25rem; }
.refresh-copy p { margin: .2rem 0 0; font-size: .85rem; max-width: 34rem; }
.refresh-actions form { margin: 0; }
.refresh-actions button { white-space: nowrap; }

.schedule-form { margin-top: .25rem; }
.schedule-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.schedule-list > li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 9rem;
  gap: .65rem 1rem;
  align-items: center;
  padding: .65rem 0;
  border-top: 1px solid var(--line);
}
.schedule-list > li:first-child { border-top: none; }
.schedule-copy p { margin: .15rem 0 0; font-size: .8rem; }
.schedule-select select { width: 100%; }

@media (max-width: 640px) {
  .refresh-actions > li,
  .danger-row,
  .schedule-list > li {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .refresh-actions button,
  .danger-row .btn-danger { width: 100%; }
  .queue-stats { width: 100%; }
}
.job-row {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr) auto;
  gap: .55rem .65rem;
  align-items: start;
  padding: .5rem 0;
  border-bottom: 1px solid var(--line);
}
.job-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.25rem; height: 1.25rem; flex-shrink: 0; margin-top: .1rem;
}
.job-mark-pending { color: var(--muted); }
.job-mark-running { color: var(--accent); }
.job-mark-done { color: var(--ok); }
.job-mark-failed { color: var(--err); }
.job-mark-running svg { animation: job-spin 0.9s linear infinite; transform-origin: 50% 50%; }
@keyframes job-spin {
  to { transform: rotate(360deg); }
}
.job-body { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.job-kind { font-size: .9rem; }
.job-meta { font-size: .78rem; }
.job-error { font-size: .78rem; color: var(--err); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.danger-panel {
  margin: .85rem 0 1.5rem; border: 1px solid var(--err);
  border-radius: 6px; background: rgba(176, 69, 69, 0.08);
  overflow: hidden;
}
.danger-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .75rem 1.25rem;
  align-items: center;
  padding: .85rem 1rem;
  border-top: 1px solid rgba(176, 69, 69, 0.35);
}
.danger-row:first-child { border-top: none; }
.danger-row-wipe { background: rgba(176, 69, 69, 0.1); }
.danger-copy p { margin: .2rem 0 0; font-size: .85rem; max-width: 36rem; }
.danger-row form { margin: 0; }

@media (max-width: 640px) {
  .refresh-actions > li,
  .danger-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .refresh-actions button,
  .danger-row .btn-danger { width: 100%; }
  .queue-stats { width: 100%; }
}

/* Upcoming — week columns (Mon–Sun), each day scrolls */
.upcoming-page {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.upcoming-page .page-head { flex-shrink: 0; }
.cal-nav {
  display: flex; flex-wrap: wrap; gap: .65rem 1rem; align-items: center;
  justify-content: space-between; margin: .25rem 0 .5rem;
  flex-shrink: 0;
}
.cal-month-title {
  margin: 0; font-size: 1.2rem; flex: 1; text-align: center; font-weight: 600;
  letter-spacing: -.02em;
}
.cal-nav-right { display: flex; gap: .45rem; align-items: center; }
.cal-nav .btn-ghost {
  display: inline-flex; align-items: center; padding: .35rem .65rem; text-decoration: none;
}

.week-board {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 0;
  touch-action: pan-y;
}
.week-col {
  background: var(--cal-day);
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.week-col.is-today { box-shadow: inset 0 0 0 2px var(--accent); }
.week-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .35rem;
  padding: .55rem .5rem .4rem;
  flex-shrink: 0;
  background: var(--cal-head);
  border-bottom: 1px solid var(--line);
}
.week-dow {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.week-dow-long { display: none; }
.week-date-mon { display: none; }
.week-date {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6rem;
  height: 1.6rem;
  padding: 0 .3rem;
  font-size: .8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border-radius: 999px;
  line-height: 1;
  color: var(--ink);
}
.week-date.is-today {
  background: var(--accent);
  color: var(--accent-ink);
}
.week-events {
  list-style: none;
  padding: .4rem .35rem .5rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: .28rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}
.week-empty {
  margin: .75rem .5rem;
  font-size: .78rem;
  text-align: center;
}
.week-empty-long { display: none; }

.cal-ev {
  display: grid;
  grid-template-columns: 2.85rem minmax(0, 1fr);
  gap: .35rem;
  align-items: center;
  padding: .2rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  background: var(--ev-ep);
  border: none;
  border-left: 3px solid var(--accent);
  min-width: 0;
  width: 100%;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.cal-ev:hover { filter: brightness(1.06); text-decoration: none; }
.cal-ev-season {
  background: var(--ev-season);
  border-left-color: var(--add);
}
.cal-ev-thumb {
  display: block;
  width: 2.85rem;
  aspect-ratio: 16 / 9;
  border-radius: 3px;
  overflow: hidden;
  background: var(--ph);
  flex-shrink: 0;
}
.cal-ev-thumb img {
  display: block; width: 100%; height: 100%; object-fit: cover;
}
.cal-ev-ph {
  display: block; width: 100%; height: 100%;
  background: repeating-linear-gradient(
    -45deg, var(--ph), var(--ph) 4px, var(--ph-stripe) 4px, var(--ph-stripe) 8px
  );
}
.cal-ev.is-loading-still .cal-ev-ph {
  animation: still-pulse 1.2s ease-in-out infinite;
}
.cal-ev-thumb .still-ph {
  width: 100%;
  height: 100%;
}
.cal-ev-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .05rem;
}
.cal-ev-title {
  font-size: .72rem;
  font-weight: 600;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-ev-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .15rem .35rem;
  align-items: baseline;
  font-size: .62rem;
  color: var(--muted);
  line-height: 1.2;
  min-width: 0;
}
.cal-ev-time { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.cal-ev-code { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.cal-ev-sub {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.cal-ev--week {
  grid-template-columns: 5.5rem minmax(0, 1fr);
  gap: .65rem;
  padding: .45rem .55rem;
  border-radius: var(--radius-md);
}
.cal-ev--week .cal-ev-thumb { width: 5.5rem; }
.cal-ev--week .cal-ev-title { font-size: .92rem; }
.cal-ev--week .cal-ev-meta { font-size: .78rem; gap: .25rem .5rem; }

/* Shared mobile layout */
@media (max-width: 800px) {
  .wrap { padding: 1rem .9rem 1.5rem; }
  .top {
    flex-wrap: nowrap; gap: .5rem; padding: .55rem .85rem;
    align-items: center;
  }
  .brand { font-size: 1rem; }
  .nav {
    flex: 1; flex-wrap: nowrap; gap: .35rem;
    justify-content: flex-end; position: relative;
  }
  .nav-toggle { display: inline-flex; order: 1; }
  .nav-tools {
    order: 2; margin-left: 0; padding-left: 0; border-left: none;
  }
  .nav-links + .nav-tools {
    margin-left: 0; padding-left: 0; border-left: none;
  }
  .nav-links {
    display: none;
    position: absolute; top: calc(100% + .55rem); right: 0; left: auto;
    min-width: min(18rem, calc(100vw - 1.7rem));
    flex-direction: column; align-items: stretch; gap: .2rem;
    padding: .45rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .28);
    z-index: 50;
  }
  .nav.is-open .nav-links { display: flex; }
  .nav-btn {
    justify-content: flex-start;
    padding: .55rem .7rem;
    font-size: .9rem;
  }
  .theme-toggle { width: 2.25rem; height: 2.25rem; }

  .person-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: .85rem .7rem;
  }
  .plan-filters,
  .history-filters {
    padding: .65rem;
    gap: .5rem .55rem;
  }

  .upcoming-page {
    flex: none;
    min-height: 0;
  }
  /* Phone: stack days (columns need a fixed viewport height and are unusable). */
  .week-board {
    display: flex;
    flex-direction: column;
    flex: none;
    height: auto;
    min-height: 0;
    gap: .85rem;
    background: transparent;
    border: none;
    border-radius: 0;
    overflow: visible;
    margin: 0 0 1.5rem;
    touch-action: pan-y;
  }
  .week-col {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    overflow: visible;
    min-height: auto;
  }
  .week-col-head {
    padding: .75rem .85rem .55rem;
    background: transparent;
    border-bottom: none;
  }
  .week-dow {
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: 0;
    text-transform: none;
  }
  .week-dow-short { display: none; }
  .week-dow-long { display: inline; }
  .week-date-mon { display: inline; }
  .week-date {
    min-height: 1.7rem;
    padding: 0 .55rem;
    font-size: .85rem;
    color: var(--muted);
  }
  .week-events {
    flex: none;
    overflow: visible;
    padding: 0 .85rem .85rem;
    gap: .4rem;
  }
  .week-empty {
    margin: 0 .85rem .85rem;
    font-size: .85rem;
    text-align: left;
  }
  .week-empty-short { display: none; }
  .week-empty-long { display: inline; }
  .week-board .cal-ev {
    grid-template-columns: 5.5rem minmax(0, 1fr);
    gap: .65rem;
    padding: .45rem .55rem;
    border-radius: var(--radius-md);
  }
  .week-board .cal-ev-thumb { width: 5.5rem; }
  .week-board .cal-ev-title { font-size: .92rem; }
  .week-board .cal-ev-meta { font-size: .78rem; gap: .25rem .5rem; }
  .cal-month-title { font-size: 1rem; }
  .cal-nav .btn-ghost { padding: .45rem .7rem; min-height: 2.25rem; }

  .detail-actions {
    gap: .5rem;
  }
  .star-btn {
    padding: .15rem .08rem;
    font-size: 1.35rem;
  }
}
