:root {
  --accent: #5b5bd6;
  --accent-soft: #eef0ff;
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #191d28;
  --muted: #6b7280;
  --border: #e4e6ee;
  --released: #e8890c;
  --released-bg: #fff4e0;
  --watched: #9ca3af;
  --upcoming: #3f7ad1;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(25, 29, 40, .07);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
}
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, select, textarea { font: inherit; }
img { display: block; }
a { color: var(--accent); }

/* ---------- Верхняя панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
}
.topbar .logo { font-weight: 700; font-size: 19px; display: flex; align-items: center; gap: 8px; }
.topbar .logo svg { width: 27px; height: 27px; }
.topbar .spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 42px; height: 42px; border-radius: 10px;
  color: var(--muted); font-size: 15px; gap: 6px; padding: 0 10px;
}
.icon-btn:hover { background: var(--bg); }
.icon-btn.loading svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Нижняя навигация (мобильная) ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px; color: var(--muted); text-decoration: none; font-size: 13px;
}
.tabbar a svg { width: 25px; height: 25px; }
.tabbar a.active { color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 14px 12px 90px; }

/* ---------- Панель календаря ---------- */
.cal-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.cal-toolbar .month-title { font-size: 20px; font-weight: 700; text-transform: capitalize; }
.nav-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); font-size: 18px; color: var(--text);
}
.nav-btn:hover { background: var(--accent-soft); }
.seg {
  display: inline-flex; background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 3px; gap: 2px;
}
.seg button { padding: 7px 14px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.seg button.active { background: var(--accent); color: #fff; }

/* ---------- Месяц ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid .dow {
  text-align: center; font-size: 13px; color: var(--muted);
  text-transform: uppercase; padding: 4px 0 2px; letter-spacing: .04em;
}
.day {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  min-height: 96px; padding: 4px; display: flex; flex-direction: column; gap: 3px;
  overflow: hidden; cursor: pointer; position: relative;
}
.day:hover { border-color: #c9cbe8; }
.day.other-month { opacity: .45; }
.day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.day .dnum { font-size: 14px; font-weight: 600; color: var(--muted); padding: 0 2px; }
.day.today .dnum {
  color: #fff; background: var(--accent); border-radius: 7px;
  display: inline-block; min-width: 23px; text-align: center; align-self: flex-start;
}

.ep-chip {
  display: flex; align-items: center; gap: 5px;
  border-radius: 7px; padding: 3px 4px 3px 3px;
  background: var(--accent-soft); font-size: 12px; line-height: 1.2;
  overflow: hidden; text-align: left; width: 100%;
}
.ep-chip img { width: 26px; height: 37px; object-fit: cover; border-radius: 4px; flex-shrink: 0; background: #ddd; }
.ep-chip .code { font-weight: 700; white-space: nowrap; }
.ep-chip .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.ep-chip.released { background: var(--released-bg); box-shadow: inset 0 0 0 1.5px var(--released); }
.ep-chip.released .code { color: var(--released); }
.ep-chip.watched { opacity: .5; }
.ep-chip.upcoming { background: #edf3fc; }
.ep-chip.upcoming .code { color: var(--upcoming); }
.more-chip { font-size: 12px; color: var(--muted); text-align: center; padding: 2px; }

/* ---------- Повестка ---------- */
.agenda-day { margin-bottom: 14px; }
.agenda-day .aday-head {
  font-size: 15px; font-weight: 700; color: var(--muted);
  text-transform: capitalize; margin: 0 2px 6px; display: flex; gap: 8px; align-items: baseline;
}
.agenda-day.today .aday-head { color: var(--accent); }
.ep-row {
  display: flex; gap: 10px; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px; margin-bottom: 6px; cursor: pointer; width: 100%; text-align: left;
}
.ep-row img { width: 54px; height: 76px; object-fit: cover; border-radius: 8px; background: #ddd; flex-shrink: 0; }
.ep-row .info { flex: 1; min-width: 0; }
.ep-row .show-name { font-weight: 600; font-size: 16px; }
.ep-row .ep-line { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ep-row.released { border-color: var(--released); background: var(--released-bg); }
.ep-row.watched { opacity: .55; }
.badge {
  font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 20px; white-space: nowrap;
}
.badge.released { background: var(--released); color: #fff; }
.badge.watched { background: #e5e7eb; color: var(--muted); }
.badge.upcoming { background: #e4edfb; color: var(--upcoming); }
.badge.tba { background: #e5e7eb; color: var(--muted); }

/* ---------- Сериалы ---------- */
.shows-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.chip {
  padding: 7px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--card); font-size: 14px; color: var(--muted);
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
select.sortsel { padding: 6px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); color: var(--text); }

.shows-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 14px; }
.show-card { cursor: pointer; position: relative; }
.show-card .poster {
  width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 12px;
  background: #e2e4ec; box-shadow: var(--shadow);
}
.show-card .sname { font-size: 14px; font-weight: 600; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.show-card .smeta { font-size: 13px; color: var(--muted); }
.show-card .del {
  position: absolute; top: 6px; right: 6px; width: 30px; height: 30px;
  border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; font-size: 16px;
  display: none; align-items: center; justify-content: center;
}
.show-card:hover .del { display: flex; }
.show-card .st-badge { position: absolute; top: 6px; left: 6px; }
.poster-ph { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; text-align: center; padding: 8px; }

/* ---------- Поиск ---------- */
.search-box { position: sticky; top: 59px; z-index: 20; background: var(--bg); padding: 4px 0 10px; }
.search-box input {
  width: 100%; padding: 12px 14px; border-radius: 12px; font-size: 16px;
  border: 1px solid var(--border); background: var(--card); outline: none;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sr-row {
  display: flex; gap: 12px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; margin-bottom: 8px; align-items: center;
}
.sr-row img { width: 62px; height: 88px; object-fit: cover; border-radius: 8px; background: #ddd; flex-shrink: 0; }
.sr-row .info { flex: 1; min-width: 0; }
.sr-row .t1 { font-weight: 600; font-size: 16px; }
.sr-row .t2 { font-size: 14px; color: var(--muted); }
.sr-row .ov { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 3px; }
.btn {
  padding: 11px 18px; border-radius: 10px; background: var(--accent); color: #fff;
  font-weight: 600; font-size: 15px; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 7px 13px; font-size: 14px; }
.btn.added { background: #d3f0dc; color: #177245; }

/* ---------- Модалки ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 17, 25, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadein .15s ease;
}
@keyframes fadein { from { opacity: 0; } }
.modal {
  background: var(--card); width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  border-radius: 20px 20px 0 0; padding: 0 0 24px;
  animation: slideup .2s ease;
}
@keyframes slideup { from { transform: translateY(40px); } }
.modal .m-close {
  position: sticky; top: 10px; float: right; margin: 10px 10px 0 0;
  width: 34px; height: 34px; border-radius: 50%; background: rgba(0,0,0,.45);
  color: #fff; font-size: 17px; z-index: 2;
}
.modal .m-hero { width: 100%; aspect-ratio: 16/9; object-fit: cover; background: #e2e4ec; }
.modal .m-body { padding: 14px 18px 0; }
.modal .m-title { font-size: 22px; font-weight: 700; margin: 0 0 2px; }
.modal .m-sub { color: var(--muted); font-size: 15px; margin-bottom: 10px; }
.modal .m-epcode { font-weight: 700; color: var(--accent); font-size: 16px; }
.modal .m-overview { font-size: 16px; color: #3c4152; margin: 12px 0; }
.modal .m-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.m-ratings { display: flex; gap: 8px; margin: 10px 0; }
.m-ratings .rt {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 14px; font-size: 15px; font-weight: 600;
}
.m-ratings .rt span { color: var(--muted); font-weight: 400; font-size: 13px; display: block; }
.day-list .ep-row { margin: 0 14px 6px; width: auto; }

/* ---------- Логин ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 20px;
  padding: 30px 26px; width: 100%; max-width: 360px; box-shadow: var(--shadow); text-align: center;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 12px; font-size: 16px;
  border: 1px solid var(--border); margin-bottom: 12px; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card .btn { width: 100%; }
.login-err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- Настройки / разное ---------- */
.settings-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.settings-card h3 { margin: 0 0 10px; font-size: 17px; }
.settings-card label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.settings-card input[type=text] { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.settings-card .radio-row { display: flex; flex-direction: column; gap: 9px; margin: 6px 0 12px; }
.settings-card .radio-row label { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 15px; margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: 15px; }
.notice {
  background: #fdf3e3; border: 1px solid #f3d9a8; color: #8a5a12;
  border-radius: 10px; padding: 10px 14px; font-size: 14px; margin-bottom: 12px;
}
.progress-wrap { height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }
.sync-line { font-size: 13px; color: var(--muted); margin-top: 6px; }
.offline-banner {
  background: #fee2e2; color: #991b1b; text-align: center; font-size: 13px;
  padding: 4px; position: sticky; top: 0; z-index: 40;
}

/* ---------- Desktop ---------- */
@media (min-width: 720px) {
  main { padding: 20px 20px 40px; }
  .tabbar { display: none; }
  .topbar .nav-links { display: flex; gap: 4px; }
  .day { min-height: 130px; }
  .ep-chip { font-size: 13px; }
  .ep-chip img { width: 30px; height: 43px; }
  .modal-overlay { align-items: center; }
  .modal { border-radius: 20px; max-height: 85vh; }
  .shows-grid { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 18px; }
}
@media (max-width: 719px) {
  .topbar .nav-links { display: none; }
  /* В узкой клетке текст не читается — показываем только постер,
     статус виден по цветной рамке чипа */
  .ep-chip { padding: 3px; justify-content: center; }
  .ep-chip img { width: 32px; height: 46px; }
  .ep-chip .code, .ep-chip .t { display: none; }
}
.topbar .nav-links a {
  padding: 9px 14px; border-radius: 10px; color: var(--muted);
  text-decoration: none; font-size: 15px; font-weight: 500;
}
.topbar .nav-links a.active { color: var(--accent); background: var(--accent-soft); }
