:root {
  --bg:            #F5F5F7;
  --surface:       #FFFFFF;
  --surface-alt:   #FAFAFA;
  --border:        #E5E5EA;
  --border-focus:  #007AFF;

  --accent:        #D4845A;
  --accent-light:  rgba(212, 132, 90, 0.08);
  --accent-hover:  #C2785C;

  --text:          #1D1D1F;
  --text-secondary:#86868B;
  --text-tertiary: #AEAEB2;

  --follow:        #D4845A;
  --follow-light:  rgba(212, 132, 90, 0.12);
  --jellyfin:      #6BA3BE;
  --jellyfin-light:rgba(107, 163, 190, 0.12);
  --watched:       #7CB382;
  --watched-light: rgba(124, 179, 130, 0.12);

  --badge-airing:  #FFF3E0;
  --badge-text:    #BF6A3A;
  --badge-released:#E8F5E9;
  --badge-re-leased-text: #2E7D32;
  --badge-not-aired: #FFF0F0;
  --badge-not-aired-text: #C62828;
  --badge-tba:     #F5F5F7;
  --badge-tba-text: #6B7280;

  --score-mal-text:#DC2626;
  --score-mal-bg:  #FFF0F0;
  --score-al-bg:   #DBEAFE;
  --score-al-text: #2563EB;

  --radius-sm:     8px;
  --radius-md:     12px;
  --radius-lg:     16px;
  --radius-xl:     20px;

  --shadow-sm:     0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:     0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:     0 8px 24px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.06);

  --font:          'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --nav-height:    60px;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Auth ─────────────────────────────────────────────── */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}

.auth-card__title {
  font-size: 1.75rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 6px;
  color: var(--text);
  letter-spacing: -0.5px;
}

.auth-card__subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 28px;
  font-size: 0.9rem;
}

.auth-card__error {
  background: #FFF0F0;
  color: #C62828;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.875rem;
  border: 1px solid #FFCDD2;
}

.auth-card__form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
}

.form-group input {
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.form-group small {
  color: var(--text-tertiary);
  font-size: 0.8rem;
}

.auth-card__link {
  text-align: center;
  margin-top: 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.auth-card__link a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.auth-card__link a:hover {
  text-decoration: underline;
}

/* ─── Buttons ──────────────────────────────────────────── */

.btn {
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.18s ease;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-alt);
  border-color: var(--border);
  color: var(--text);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn--full {
  width: 100%;
  padding: 13px;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
}

/* Status buttons — pill style */
.btn--follow,
.btn--jellyfin,
.btn--watched {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-secondary);
}

.btn--follow:hover,
.btn--jellyfin:hover,
.btn--watched:hover {
  border-color: var(--border);
  background: var(--surface-alt);
}

/* Active states — filled with tint on button + card */
.btn--follow.active {
  background: var(--follow-light);
  border-color: var(--follow);
  color: var(--follow);
}

.btn--jellyfin.active {
  background: var(--jellyfin-light);
  border-color: var(--jellyfin);
  color: var(--jellyfin);
}

.btn--watched.active {
  background: var(--watched-light);
  border-color: var(--watched);
  color: var(--watched);
}

/* ─── Nav ──────────────────────────────────────────────── */

.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  z-index: 100;
}

.nav__logo {
  font-size: 1.375rem;
  font-weight: 800;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.3px;
}

.nav__season-picker {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav__season-picker a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.15s;
}

.nav__season-picker a:hover {
  color: var(--accent);
}

.nav__current {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--text);
}

.nav__right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.nav__user {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

.nav__right a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
}

.nav__right a:hover {
  text-decoration: underline;
}

.logout-form {
  display: inline;
}

.logout-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  text-decoration: none;
}

.logout-btn:hover {
  text-decoration: underline;
}

.lang-toggle {
  display: flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.lang-toggle button {
  padding: 5px 12px;
  border: none;
  background: transparent;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.05em;
}

.lang-toggle button.active {
  background: var(--accent);
  color: #fff;
}

.lang-toggle button:hover:not(.active) {
  background: var(--border);
  color: var(--text);
}

/* ─── Main ──────────────────────────────────────────────── */

.main {
  max-width: 1240px;
  margin: 0 auto;
  padding: calc(var(--nav-height) + 28px) 28px 40px;
}

/* ─── Controls ─────────────────────────────────────────── */

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.controls__tabs {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.tab {
  padding: 7px 18px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.18s ease;
}

.tab:hover:not(.active) {
  color: var(--text);
}

.tab.active {
  background: var(--text);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.controls__sort {
  display: flex;
  align-items: center;
  gap: 10px;
}

.controls__sort label {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

.controls__sort select {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s;
}

.controls__sort select:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* ─── Card Grid ────────────────────────────────────────── */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

/* ─── Card ─────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  gap: 14px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  height: 340px;
}

.card:hover {
  box-shadow: var(--shadow-md);
  border-color: #d0d0d8;
}

/* Card status tints — applied to card root */
.card--following {
  background: var(--follow-light);
  border-color: rgba(212, 132, 90, 0.35);
}

.card--jellyfin {
  background: var(--jellyfin-light);
  border-color: rgba(107, 163, 190, 0.35);
}

.card--watched {
  background: var(--watched-light);
  border-color: rgba(124, 179, 130, 0.35);
  opacity: 0.3;
}

/* Multiple statuses: prioritize watched > jellyfin > follow */
.card--following.card--jellyfin {
  background: var(--jellyfin-light);
  border-color: rgba(107, 163, 190, 0.35);
}

.card--following.card--watched,
.card--jellyfin.card--watched {
  background: var(--watched-light);
  border-color: rgba(124, 179, 130, 0.35);
  opacity: 0.3;
}

.card--following.card--jellyfin.card--watched {
  background: var(--watched-light);
  border-color: rgba(124, 179, 130, 0.35);
  opacity: 0.3;
}

.card--hidden {
  display: none;
}

.card__poster {
  width: 96px;
  height: 136px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background: var(--surface-alt);
}

.card__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card__title {
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  letter-spacing: -0.1px;
  flex: 1;
}

.card__subtitle {
  font-size: 0.775rem;
  color: var(--text-tertiary);
  line-height: 1.3;
  margin-top: 2px;
}

.card__countdown {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--badge-airing);
  color: var(--badge-text);
  border-radius: 6px;
  padding: 3px 9px;
  font-weight: 700;
  font-size: 0.775rem;
  width: fit-content;
  margin-top: 2px;
}

.countdown--released {
  background: var(--badge-released);
  color: var(--badge-released-text);
}

.countdown--not-aired {
  background: var(--badge-not-aired);
  color: var(--badge-not-aired-text);
}

.countdown--tba {
  background: var(--badge-tba);
  color: var(--badge-tba-text);
}

.countdown-ep {
  font-weight: 500;
  opacity: 0.85;
}

.card__scores {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.score {
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 5px;
  font-weight: 700;
  text-decoration: none;
  display: inline-block;
  cursor: pointer;
  transition: opacity 0.15s;
}

.score:hover {
  opacity: 0.75;
}

.score--mal {
  background: var(--score-mal-bg);
  color: var(--score-mal-text);
}

.score--al {
  background: var(--score-al-bg);
  color: var(--score-al-text);
}

.card__synopsis {
  font-size: 0.775rem;
  color: var(--text-secondary);
  line-height: 1.45;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card__actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 6px;
}

.btn--more {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  padding: 4px 0;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  transition: color 0.15s;
}

.btn--more:hover {
  color: var(--accent);
}

/* ─── Responsive ────────────────────────────────────────── */

@media (max-width: 640px) {
  .nav__season-picker a:not(.nav__current) {
    display: none;
  }

  .nav__season-picker {
    gap: 6px;
  }

  .main {
    padding: calc(var(--nav-height) + 16px) 16px 32px;
  }

  .card-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card {
    flex-direction: column;
    height: auto;
  }

  .card__poster {
    width: 100%;
    height: 180px;
  }

  .controls {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 400px) {
  .card__actions .btn {
    flex: 1;
    text-align: center;
  }
}

/* ─── Modal ────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(12px) scale(0.98);
  transition: transform 0.2s ease;
}

.modal-backdrop.open .modal {
  transform: translateY(0) scale(1);
}

.modal__header {
  display: flex;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}

.modal__poster {
  width: 100px;
  height: 140px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background: var(--surface-alt);
}

.modal__info {
  flex: 1;
  min-width: 0;
}

.modal__title {
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1.3;
  margin-bottom: 4px;
}

.modal__titles {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 10px;
}

.modal__title-jp,
.modal__title-ru {
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

.modal__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.modal__countdown {
  display: inline-flex;
}

.modal__countdown .countdown-timer {
  display: inline;
}

.modal__status {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.modal__episodes {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.modal__close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.modal__close:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.modal__body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal__section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.modal__synopsis {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.modal__synopsis-en,
.modal__synopsis-ru {
  margin-bottom: 12px;
}

.modal__genres {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.modal__genre {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 600;
}

.modal__scores {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.modal__score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: opacity 0.15s;
  border-radius: 6px;
  padding: 4px;
}

.modal__score-item:hover {
  opacity: 0.75;
}

.modal__score-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
}

.modal__score-value {
  font-size: 1.1rem;
  font-weight: 800;
}

.modal__score-value--mal { color: var(--score-mal-text); }
.modal__score-value--al  { color: var(--score-al-text); }
.modal__score-value--shiki { color: var(--watched); }

.modal__airing-info {
  font-size: 0.875rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal__related {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal__related-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
}

.modal__related-type {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-tertiary);
  min-width: 80px;
}

.modal__related-title {
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.modal__related-title:hover {
  text-decoration: underline;
}

.modal__footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal__series-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.modal__series-btn {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
}

.modal__series-btn[hidden] {
  display: none;
}

.modal__series-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.modal__series-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
}

.modal__series-title {
  width: 100%;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal__series-meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.modal__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.modal__actions .btn {
  flex: 1;
  min-width: 100px;
  text-align: center;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

@media (max-width: 480px) {
  .modal__header {
    flex-direction: column;
  }

  .modal__poster {
    width: 80px;
    height: 112px;
  }

  .modal__series-nav {
    grid-template-columns: 1fr;
  }

  .modal {
    max-height: 90vh;
  }
}
