* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1218;
  --surface: #1a1f2a;
  --surface2: #232a38;
  --text: #e8ebf0;
  --muted: #8a93a5;
  --accent: #7c5cff;
  --accent2: #4dc9b1;
  --danger: #e05b5b;
  --radius: 10px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; margin: 24px 0; }
.error { color: var(--danger); margin-top: 8px; }

/* ---------- login ---------- */
#login-view {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--surface);
  padding: 40px;
  border-radius: 16px;
  width: 360px;
  text-align: center;
}
.login-card h1 { margin-bottom: 4px; letter-spacing: -0.5px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin: 20px 0 14px; }
.login-card input {
  background: var(--surface2); border: 1px solid #333d50; color: var(--text);
  padding: 11px 13px; border-radius: 8px; font-size: 15px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 20px;
  padding: 14px 24px;
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.logo { font-weight: 700; font-size: 18px; letter-spacing: -0.5px; }
nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  background: none; border: none; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.nav-btn.active { background: var(--surface2); color: var(--text); }
.pill {
  background: var(--accent); color: white; border-radius: 10px;
  padding: 1px 7px; font-size: 11px;
}
.pill:empty { display: none; }
.pill.gray { background: var(--surface2); color: var(--muted); }

.toolbar.filters { margin-top: -8px; gap: 10px; }
.small-btn { padding: 7px 12px; font-size: 13px; }

/* ---------- notifications ---------- */
.notif-menu { position: relative; }
.notif-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 18px; padding: 6px 8px; border-radius: 8px; position: relative; line-height: 1;
}
.notif-btn:hover { background: var(--surface2); }
.notif-badge {
  position: absolute; top: 0; right: 0; min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--danger); color: #fff; border-radius: 8px; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.notif-badge:empty, .notif-badge.hidden { display: none; }
.notif-panel { width: 340px; max-height: 460px; overflow-y: auto; padding: 8px; }
.notif-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 10px; }
.notif-item {
  display: flex; gap: 10px; padding: 9px 8px; border-radius: 8px; align-items: flex-start;
}
.notif-item.openable { cursor: pointer; }
.notif-item.openable:hover { background: var(--surface2); }
.notif-item.unread { background: rgba(124,92,255,0.10); }
.notif-icon { font-size: 15px; flex: none; width: 20px; text-align: center; }
.notif-title { font-size: 13.5px; font-weight: 600; }
.notif-body { font-size: 12.5px; color: var(--muted); margin-top: 1px; word-break: break-word; }
.notif-when { margin-top: 2px; }

.user-menu { position: relative; }
.user-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 8px 10px; border-radius: 8px;
}
.user-btn:hover { background: var(--surface2); color: var(--text); }
.user-btn::after { content: " ▾"; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  background: var(--surface2); border: 1px solid #333d50; border-radius: 10px;
  min-width: 160px; padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.dropdown-item {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text); cursor: pointer;
  padding: 9px 12px; border-radius: 7px; font-size: 14px;
}
.dropdown-item:hover { background: var(--accent); color: white; }

.banner {
  background: #4a3820; color: #f0c674; padding: 10px 24px; font-size: 14px;
}

main { padding: 24px; max-width: 1400px; margin: 0 auto; }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap;
}
.tabs { display: flex; background: var(--surface); border-radius: 8px; padding: 3px; }
.tab {
  background: none; border: none; color: var(--muted); padding: 7px 16px;
  border-radius: 6px; cursor: pointer; font-size: 14px;
}
.tab.active { background: var(--accent); color: white; }
#search {
  flex: 1; min-width: 200px; max-width: 420px;
  background: var(--surface); border: 1px solid #2a3242; color: var(--text);
  padding: 9px 14px; border-radius: 8px; font-size: 14px;
}
#search:focus { outline: none; border-color: var(--accent); }
select {
  background: var(--surface); border: 1px solid #2a3242; color: var(--text);
  padding: 9px 12px; border-radius: 8px; font-size: 14px;
}

/* ---------- grid / cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 18px;
}
.card {
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  position: relative; transition: transform 0.12s;
}
.card:hover { transform: translateY(-3px); }
.poster {
  width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block;
  background: var(--surface2);
}
.poster.placeholder {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 32px;
}
.card-body { padding: 10px 12px 12px; }
.card-title { font-size: 14px; font-weight: 600; line-height: 1.3; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.save-btn {
  position: absolute; top: 8px; right: 8px;
  background: rgba(10, 12, 18, 0.75); border: none; color: white;
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 16px;
  backdrop-filter: blur(4px);
}
.save-btn.saved { background: var(--accent); }
.trash-btn {
  position: absolute; top: 48px; right: 8px;
  background: rgba(10, 12, 18, 0.75); border: none; color: white;
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 14px;
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.12s;
}
.card:hover .trash-btn { opacity: 1; }
.trash-btn:hover { background: var(--danger); }
.type-badge {
  position: absolute; top: 8px; left: 8px;
  background: rgba(10, 12, 18, 0.75); color: var(--muted);
  font-size: 11px; padding: 3px 8px; border-radius: 6px;
}
.count-badge {
  position: absolute; top: 34px; left: 8px;
  background: var(--accent); color: white;
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 10px;
}
.card-newep { font-size: 12px; color: var(--accent2); margin-top: 3px; }
.ep-list { display: flex; flex-direction: column; }
.ep-list .row { cursor: pointer; }

/* ---------- buttons ---------- */
.btn {
  background: var(--surface2); border: 1px solid #333d50; color: var(--text);
  padding: 9px 18px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.danger { border-color: var(--danger); color: var(--danger); background: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.card-dl { margin-top: 8px; width: 100%; }

/* ---------- saved / arrivals lists ---------- */
.row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 10px;
}
.row img { width: 42px; height: 63px; object-fit: cover; border-radius: 6px; background: var(--surface2); }
.row.openable { cursor: pointer; transition: background 0.12s; }
.row.openable:hover { background: var(--surface2); }
/* Grouped controls on the right of a list row (Following: toggle + download + unfollow). */
.row-actions { display: flex; align-items: center; gap: 10px; flex: none; }

/* ---------- following page ---------- */
.following-block { margin-bottom: 24px; }
.following-head { display: flex; align-items: baseline; gap: 10px; margin: 4px 0 10px; }
/* Apple-style toggle switch */
.auto-wrap { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; flex: none; }
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: #3a4256;
  border-radius: 999px; transition: background 0.2s ease;
}
.switch .slider::before {
  content: ''; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.switch input:checked + .slider { background: #34c759; }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:disabled + .slider { opacity: 0.5; }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- calendar (month grid) ---------- */
.cal-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-nav #cal-month { font-size: 15px; font-weight: 700; min-width: 150px; text-align: center; }
.cal-nav .btn { padding: 7px 12px; font-size: 13px; }
.cal-legend { display: flex; gap: 12px; flex-wrap: wrap; margin-left: auto; font-size: 11.5px; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cal-legend .dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.dot.upcoming { background: #8fb8ff; }
.dot.done { background: var(--accent2); }
.dot.onserver { background: #6b7488; }
.dot.missing { background: var(--danger); }

.cal-scroll { overflow-x: auto; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; min-width: 660px; }
.cal-dow {
  text-align: center; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); padding: 4px 0 2px;
}
.cal-cell {
  background: var(--surface); border-radius: 8px; min-height: 96px;
  padding: 6px; display: flex; flex-direction: column; gap: 4px;
}
.cal-cell.other-month { opacity: 0.35; }
.cal-cell.today { outline: 2px solid var(--accent); }
.cal-daynum { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.cal-cell.today .cal-daynum { color: var(--accent); }
.cal-chip {
  border: none; text-align: left; cursor: pointer;
  font-size: 11px; line-height: 1.3; padding: 3px 5px; border-radius: 5px;
  background: var(--surface2); color: var(--text);
  font-family: inherit;
  display: flex; align-items: center; gap: 5px; overflow: hidden;
}
.cal-chip-logo {
  width: 14px; height: 20px; flex: none;
  object-fit: cover; border-radius: 3px; background: var(--surface);
}
.cal-chip-code { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-chip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.85; }
.cal-chip:hover { filter: brightness(1.25); }
.cal-chip.upcoming { background: #26324a; color: #8fb8ff; }
.cal-chip.done { background: #1d3d33; color: var(--accent2); }
.cal-chip.onserver { background: var(--surface2); color: var(--muted); }
.cal-chip.missing { background: #442222; color: var(--danger); }


/* Following controls bar */
.fw-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 4px 0 18px; }
.fw-controls input[type="search"], .fw-controls select {
  background: var(--surface2); border: 1px solid #333d50; color: var(--text);
  padding: 8px 10px; border-radius: 8px; font-size: 13.5px;
}
.fw-controls input[type="search"] { min-width: 180px; }
.fw-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.cw-dismiss {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px;
  border-radius: 50%; border: none; background: rgba(0,0,0,0.6); color: #fff;
  cursor: pointer; font-size: 12px; line-height: 1; display: none; z-index: 2;
}
.cw-thumb-wrap:hover .cw-dismiss { display: block; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; font-size: 15px; }
.row .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status {
  font-size: 12px; padding: 3px 10px; border-radius: 10px; white-space: nowrap;
}
.status.done { background: #1d3d33; color: var(--accent2); }
.status.error { background: #442222; color: var(--danger); }
.status.downloading { background: #3a3020; color: #f0c674; }

/* ---------- settings ---------- */
.settings-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 24px; max-width: 560px;
  display: flex; flex-direction: column; gap: 16px;
}
.settings-card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.settings-card input {
  background: var(--surface2); border: 1px solid #333d50; color: var(--text);
  padding: 10px 12px; border-radius: 8px; font-size: 14px;
}
.settings-card hr { border: none; border-top: 1px solid #2a3242; }
.setting-row { flex-direction: row !important; align-items: center; gap: 12px; color: var(--text); font-size: 14px; }
.setting-row .muted { display: block; }

h2 { font-size: 20px; margin-bottom: 4px; }

.request-box {
  margin-top: 34px; padding: 20px;
  background: var(--surface); border-radius: var(--radius);
}
.request-box h3 { margin-bottom: 4px; }
.request-box form { display: flex; gap: 10px; margin: 14px 0; }
.request-box input {
  flex: 1; max-width: 480px;
  background: var(--surface2); border: 1px solid #333d50; color: var(--text);
  padding: 10px 13px; border-radius: 8px; font-size: 14px;
}
.request-box input:focus { outline: none; border-color: var(--accent); }
.request-box .row { background: var(--surface2); }

.trash-unlock { display: flex; gap: 10px; margin-top: 8px; }
.trash-unlock input {
  width: 160px; letter-spacing: 6px; text-align: center;
}

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 7, 11, 0.8);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-box {
  background: var(--surface); border-radius: 16px;
  width: min(880px, 100%); max-height: 90vh; overflow-y: auto;
  padding: 28px; position: relative;
}
.modal-close {
  position: absolute; top: 14px; right: 14px; z-index: 2;
  background: var(--surface2); border: none; color: var(--text);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 14px;
}
.player-bar .modal-close { position: static; }

.detail-head { display: flex; gap: 24px; margin-bottom: 20px; }
.detail-poster {
  width: 200px; aspect-ratio: 2/3; object-fit: cover;
  border-radius: var(--radius); background: var(--surface2); flex-shrink: 0;
}
.detail-info { min-width: 0; }
.detail-info h2 { font-size: 26px; margin-bottom: 6px; }
.detail-overview { margin: 14px 0; line-height: 1.55; font-size: 14.5px; }
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.detail-actions .btn { text-decoration: none; display: inline-flex; align-items: center; }

.season-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 18px 0 14px; }
.season-tabs .tab { background: var(--surface2); }
.season-tabs .tab.active { background: var(--accent); }
.row.episode { align-items: flex-start; }
.season-dl-bar { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.ep-actions { display: flex; gap: 8px; flex: none; }
.ep-thumb { width: 120px !important; height: 68px !important; object-fit: cover; border-radius: 6px; }
.ep-overview {
  white-space: normal !important;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; margin: 3px 0;
}
.row.missing { opacity: 0.45; }
.watched-check { color: var(--accent2); }

/* ---------- continue watching row ---------- */
.row-title { font-size: 16px; font-weight: 700; }
#continue-wrap { margin-bottom: 26px; }
.cw-toggle {
  background: none; border: none; color: var(--text); cursor: pointer;
  display: flex; align-items: center; gap: 8px; padding: 0; margin-bottom: 10px;
}
#continue-chevron { color: var(--muted); transition: transform 0.15s; display: inline-block; }
#continue-wrap.collapsed #continue-chevron { transform: rotate(-90deg); }
#continue-wrap.collapsed .hscroll { display: none; }
#continue-wrap.collapsed { margin-bottom: 14px; }
.hscroll { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.cw-card {
  width: 220px; flex-shrink: 0; cursor: pointer;
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  transition: transform 0.12s;
}
.cw-card:hover { transform: translateY(-2px); }
.cw-thumb-wrap { position: relative; }
.cw-thumb { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: var(--surface2); }
.cw-play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 34px; color: white; background: rgba(10, 12, 18, 0.35);
  opacity: 0; transition: opacity 0.12s;
}
.cw-card:hover .cw-play { opacity: 1; }
.cw-bar { position: absolute; bottom: 0; left: 0; right: 0; height: 4px; background: rgba(255,255,255,0.25); }
.cw-fill { height: 100%; background: var(--accent); }
.cw-title {
  font-size: 13px; font-weight: 600; padding: 8px 10px 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cw-sub { font-size: 11.5px; color: var(--muted); padding: 0 10px 9px; }

/* ---------- up next overlay ---------- */
.player-stage { position: relative; }
#upnext {
  position: absolute; right: 16px; bottom: 60px;
  background: rgba(15, 18, 24, 0.95); border: 1px solid #333d50;
  border-radius: 12px; padding: 16px 18px; max-width: 380px;
}
#upnext p { margin-bottom: 4px; }
#upnext #upnext-title { font-weight: 700; margin-bottom: 12px; }
.upnext-actions { display: flex; gap: 10px; }

.player-box { width: min(1100px, 100%); }
.player-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px; color: var(--text);
}
.player-bar span { flex: 1; font-weight: 600; }
#subtitle-select { max-width: 220px; }
#phone-info a { color: var(--accent); }
#phone-info p { margin-bottom: 4px; }
#player { width: 100%; aspect-ratio: 16/9; background: black; border-radius: 10px; }

@media (max-width: 640px) {
  /* Full-screen sheet instead of a small floating box, so the content gets the
     whole width and doesn't feel cramped behind heavy padding. */
  .modal { padding: 0; }
  .modal-box { width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; padding: 16px; }
  .modal-close { top: 10px; right: 10px; }

  /* Poster + title side by side (compact) rather than a big poster with empty
     space beside it. */
  .detail-head { gap: 14px; margin-bottom: 16px; align-items: flex-start; }
  .detail-poster { width: 96px; } /* flex-start keeps its 2:3 shape instead of stretching */
  .detail-info h2 { font-size: 20px; }
  .detail-overview { font-size: 14px; margin: 12px 0; }
  .detail-actions .btn { flex: 1 1 auto; justify-content: center; }

  /* Episode rows: thumb + text on top, actions drop to their own line so the
     title isn't crushed into one word per line by the buttons. */
  .row.episode { flex-wrap: wrap; }
  .row.episode .grow { flex: 1 1 140px; }
  .row.episode .ep-actions { width: 100%; margin-top: 8px; }
  .row.episode .ep-play { flex: 1; }
  .season-dl-bar .btn { flex: 1; }

  header { flex-wrap: wrap; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
  main { padding: 14px; }

  /* Following rows: poster + title stay on line 1; the controls drop below into
     a tidy stack so nothing gets crushed on a phone. */
  .following-row { flex-wrap: wrap; }
  .following-row .row-actions { width: 100%; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
  /* Toggle on its own full-width line, iOS-style: label left, switch right. */
  .following-row .auto-wrap { width: 100%; justify-content: space-between; }
  /* Download + Unfollow share the next line as equal, easy-to-tap targets. */
  .following-row .row-actions .btn { flex: 1; padding: 11px 14px; }
}
.cal-chip.more { background: none; color: var(--muted); font-weight: 600; }
