:root {
  --bg: #17181b;
  --surface: #1f2024;
  --surface-2: #27292e;
  --surface-3: #31333a;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #e9eaee;
  --muted: #9a9ea8;
  --faint: #676b75;
  --accent: #7cc4fa;
  --accent-hover: #a3d6fc;
  --accent-soft: rgba(124, 196, 250, 0.12);
  --accent-ink: #0b1a26;
  --danger: #ff7b7b;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --gutter: clamp(12px, 3vw, 28px);
  --topbar-h: 51px;
  --stick: 112px; /* topbar + day strip; measured in JS */
  --label-w: 76px;
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: var(--stick);
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 12px;
  border-radius: 8px; border: 1px solid transparent;
  background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 13px; text-decoration: none;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:focus-visible, .tab:focus-visible, .chip-day:focus-visible, .icon-btn:focus-visible, .menu-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.btn-lg { height: 42px; padding: 0 20px; font-size: 14px; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-danger-text { color: var(--danger); }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px var(--gutter);
  background: rgba(23, 24, 27, 0.9);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; letter-spacing: -0.01em; text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; flex: none; }
.brand-mark::after { content: ''; position: absolute; inset: 7px 5px 5px; border: 2px solid var(--accent-ink); border-radius: 2px; }
.brand-mark.big { width: 48px; height: 48px; border-radius: 12px; }
.brand-mark.big::after { inset: 15px 11px 11px; border-width: 3.5px; border-radius: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
#refresh-btn { width: 34px; padding: 0; justify-content: center; }
#refresh-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.account { position: relative; }
.account summary { list-style: none; width: 34px; padding: 0; justify-content: center; text-transform: uppercase; }
.account summary::-webkit-details-marker { display: none; }
.account-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 10px;
  box-shadow: var(--shadow); padding: 5px; z-index: 40;
}
.account-name { margin: 6px 10px 6px; font-size: 12.5px; color: var(--muted); }
.menu-item {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 7px;
  background: none; border: 0; cursor: pointer; text-decoration: none; font-size: 13.5px;
}
.menu-item:hover { background: var(--surface-3); }
.menu-item.danger { color: var(--danger); }

@media (max-width: 520px) {
  #manage-btn span { display: none; }
  #manage-btn { width: 34px; padding: 0; justify-content: center; }
}

main { padding: 0 var(--gutter) 40px; max-width: 1680px; margin: 0 auto; }

/* ---------- day strip ---------- */
/* Equal-width chips spanning the same width as the episode tiles below.
   Narrow screens fall back to a sideways-scrolling strip. */
.daystrip {
  position: sticky; top: var(--topbar-h); z-index: 20;
  display: grid; grid-template-columns: repeat(var(--n, 14), minmax(0, 1fr)); gap: 4px;
  overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(var(--gutter) * -1);
  padding: 8px var(--gutter);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.daystrip::-webkit-scrollbar { display: none; }
.chip-day {
  min-width: 0; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 5px 2px 6px; border-radius: 8px;
  background: var(--surface); border: 1px solid transparent;
  cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, opacity .15s;
}
.chip-day:hover { background: var(--surface-2); }
.chip-day .dow { font-size: 10px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.chip-day .dnum { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chip-day .dots { display: flex; gap: 2px; height: 4px; }
.chip-day .dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--faint); }
.chip-day.has .dots i { background: var(--accent); }
.chip-day.past { opacity: .6; }
.chip-day.today { border-color: var(--line-strong); }
.chip-day.today .dow, .chip-day.yesterday .dow, .chip-day.tomorrow .dow { color: var(--text); }
/* the day currently at the top of the timeline (or just clicked) */
.chip-day.active { background: var(--accent-soft); border-color: var(--accent); opacity: 1; }
.chip-day.active .dow { color: var(--accent); }
/* Too narrow for 14 equal chips: fixed-width chips that scroll sideways */
@media (max-width: 1100px) {
  .daystrip { grid-template-columns: repeat(var(--n, 14), 72px); }
}

/* ---------- timeline ---------- */
.timeline { padding-top: 0; }
.day {
  display: grid; grid-template-columns: var(--label-w) 1fr; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.day-label {
  position: sticky; top: calc(var(--stick) + 10px); align-self: start;
  display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1;
  padding-top: 2px;
}
.day-label .dow { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.day-label .dnum { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.day-label .mon { font-size: 11.5px; color: var(--faint); font-weight: 500; }
.day-label .rel {
  margin-top: 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
  padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.day.is-past .day-label .dnum { color: var(--muted); }
.day.is-today .day-label .dow, .day.is-today .day-label .dnum { color: var(--text); }
.day.is-today .day-label .rel { background: var(--text); color: var(--bg); }
.day.is-yesterday .day-label .dow, .day.is-yesterday .day-label .dnum { color: var(--accent); }
.day.is-yesterday .day-label .rel { background: var(--accent); color: var(--accent-ink); }
.day.is-yesterday { background: linear-gradient(90deg, var(--accent-soft), transparent 40%); margin: 0 calc(var(--gutter) * -1); padding-left: var(--gutter); padding-right: var(--gutter); }

.day.is-empty { padding: 6px 0; }
.day.is-empty .day-label { flex-direction: row; align-items: baseline; gap: 6px; }
.day.is-empty .day-label .dnum { font-size: 15px; color: var(--faint); }
.day.is-empty .day-label .dow { color: var(--faint); }
.day.is-empty .day-label .mon, .day.is-empty .day-label .rel { display: none; }
.day.is-yesterday.is-empty .day-label .dnum, .day.is-yesterday.is-empty .day-label .dow { color: var(--accent); }
.nothing { margin: 0; font-size: 12.5px; color: var(--faint); align-self: center; display: flex; align-items: center; gap: 8px; }
.nothing .rel { font-size: 10.5px; font-weight: 700; letter-spacing: .02em; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.day.is-today .nothing .rel { background: var(--text); color: var(--bg); }
.day.is-yesterday .nothing .rel { background: var(--accent); color: var(--accent-ink); }

.day.flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 40% { background-color: var(--accent-soft); } 100% { background-color: transparent; } }

/* 3 tiles per row on desktop, 2 on tablets, 1 on phones; tiles grow to fill the width */
.day-items { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); align-content: start; }
@media (max-width: 1100px) { .day-items { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .day-items { grid-template-columns: minmax(0, 1fr); } }

/* ---------- tiles ---------- */
.tile {
  display: flex; gap: 10px; padding: 6px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color .15s, background .15s;
}
.tile:hover { border-color: var(--line-strong); background: var(--surface-2); }
.tile-thumb {
  position: relative; flex: none; width: clamp(128px, 36%, 168px); aspect-ratio: 16 / 9; border-radius: 6px;
  overflow: hidden; background: var(--surface-3); display: block;
}
.tile-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fallback {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 6px; text-align: center;
  font-size: 11px; font-weight: 700; line-height: 1.15; color: rgba(255,255,255,.85);
}
.tile-body { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 1px; }
.tile-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.tile-show { font-size: 13.5px; font-weight: 650; text-decoration: none; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; }
.tile-show:hover { text-decoration: underline; text-underline-offset: 3px; }
.se-line { margin: 1px 0 0; display: flex; align-items: center; flex-wrap: wrap; gap: 2px 6px; min-width: 0; }
.se-text { font-size: 12px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.se-line .tag { white-space: nowrap; }
.ep-title { margin: 0; font-size: 12.5px; color: var(--text); opacity: .78; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { margin: 2px 0 0; color: var(--muted); font-size: 11.5px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.meta span + span::before { content: '·'; margin-right: 5px; color: var(--faint); }
.tag {
  font: 700 9.5px/1 var(--sans); font-style: normal; letter-spacing: .05em; text-transform: uppercase;
  padding: 3px 5px; border-radius: 4px; background: var(--accent-soft); color: var(--accent);
}

.icon-btn {
  flex: none; width: 26px; height: 26px; display: grid; place-items: center;
  border-radius: 6px; border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

@media (max-width: 560px) {
  :root { --label-w: 54px; }
  .day { gap: 8px; }
  .day-label .dnum { font-size: 20px; }
  .day-label .mon { display: none; }
  .day-label .rel { font-size: 9.5px; padding: 2px 5px; }
  .tile-thumb { width: 104px; }
}

/* ---------- skeleton ---------- */
.skeleton { display: block; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--radius); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- popover menu ---------- */
.popover {
  position: fixed; z-index: 60; min-width: 210px; padding: 5px;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: var(--shadow);
}

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 49; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(420px, 100vw); background: var(--surface); border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .25s cubic-bezier(.2,.8,.2,1);
  visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.drawer-head h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 2px; padding: 4px 16px 0; border-bottom: 1px solid var(--line); }
.tab {
  background: none; border: 0; padding: 9px 10px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab[aria-selected='true'] { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { flex: 1; overflow-y: auto; padding: 14px 16px 28px; }
.search {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text); font: inherit; font-size: 14px;
}
.search:focus { outline: none; border-color: var(--accent); }
.hint { margin: 8px 0 12px; font-size: 12.5px; color: var(--muted); }
.show-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.show-row { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 9px; }
.show-row:hover { background: var(--surface-2); }
.poster { width: 36px; aspect-ratio: 2 / 3; border-radius: 4px; object-fit: cover; background: var(--surface-3); flex: none; }
.show-info { flex: 1; min-width: 0; }
.show-info strong { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.show-info span { font-size: 12px; color: var(--muted); }
.list-empty { padding: 24px 8px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* ---------- connect / errors ---------- */
.connect { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.connect-card { max-width: 420px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.connect-card h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 12px 0 2px; }
.connect-card p { margin: 0 0 16px; }
.load-error { margin: 60px auto; max-width: 520px; text-align: center; color: var(--muted); }
.footnote { margin-top: 28px; color: var(--faint); font-size: 11.5px; text-align: center; }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 6px; align-items: center; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 14px; border-radius: 10px;
  background: var(--surface-3); color: var(--text); border: 1px solid var(--line-strong);
  font-weight: 500; font-size: 13px; box-shadow: var(--shadow);
  animation: rise .2s ease;
}
.toast.error { background: #4a2326; border-color: rgba(255,123,123,.4); }
.toast button { background: var(--accent-soft); color: var(--accent); border: 0; border-radius: 7px; padding: 5px 9px; font-weight: 700; cursor: pointer; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 24px; display: flex; flex-direction: column; gap: 9px; box-shadow: var(--shadow);
}
.login-card p { margin: 0 0 6px; }
.login-card label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.login-card input[type='password'] {
  height: 40px; padding: 0 12px; border-radius: 9px; background: var(--surface-2);
  border: 1px solid var(--line); color: var(--text); font: inherit;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card .btn { justify-content: center; height: 40px; margin-top: 4px; }
.login-error { color: var(--danger); font-size: 13.5px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.tile-top .icon-btn { margin: -4px -2px -6px 0; }

/* ---------- watched / aired marks ---------- */
.status {
  position: absolute; top: 5px; left: 5px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center;
}
.status.is-watched { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 4px rgba(0, 0, 0, .4); }
.status.is-aired { background: rgba(0, 0, 0, .55); color: rgba(255, 255, 255, .75); border: 1.5px solid rgba(255, 255, 255, .55); }
.tile.is-watched .tile-thumb img, .tile.is-watched .fallback { opacity: .5; }
.tile.is-watched .tile-show, .tile.is-watched .ep-title { color: var(--muted); }
.se-line .partial { font-style: normal; font-size: 11.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }

.stale-note {
  margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; font-size: 12.5px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}

/* ---------- status indicators (top bar) ---------- */
.sync { flex: 1; min-width: 0; display: flex; justify-content: center; align-items: center; gap: 6px; overflow: hidden; }
.sync-item {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 12px; color: var(--muted); white-space: nowrap;
}
.sync-item i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.sync-item.ok i { background: #5fcf8a; }
.sync-item.warn i { background: #f0b45a; }
.sync-item.pending i { background: var(--accent); }
.sync-item.plain { background: none; border-color: transparent; padding-left: 4px; }
.sync.busy .sync-item.plain { color: var(--accent); }
@media (max-width: 1100px) { .sync-item:nth-child(2), .sync-item:nth-child(3) { display: none; } }
@media (max-width: 640px) { .sync { display: none; } }
