/* ========== Apple-style design system ========== */
:root {
  --apple-bg: #000000;
  --apple-bg-elevated: #1c1c1e;
  --apple-bg-tertiary: #2c2c2e;
  --apple-bg-card: #1a1a1a;
  --apple-text: #ffffff;
  --apple-text-secondary: rgba(235, 235, 245, 0.6);
  --apple-text-tertiary: rgba(235, 235, 245, 0.4);
  --apple-accent: #ff2d2d;
  --apple-accent-hover: #ff5252;
  --apple-blue: #ff2d2d;
  --apple-blue-hover: #ff5252;
  --apple-separator: rgba(84, 84, 88, 0.65);
  --apple-radius: 12px;
  --apple-radius-sm: 10px;
  --apple-radius-card: 8px;
  --apple-font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", sans-serif;
  --apple-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --apple-transition: 0.2s ease;
}

* {
  box-sizing: border-box;
}

body {
  font-family: var(--apple-font);
  margin: 0;
  background: var(--apple-bg);
  color: var(--apple-text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* --- Header: узнаваемый Apple-стиль --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.75rem 1.5rem;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--apple-separator);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--apple-text);
}

.header .brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: #0a0a0a;
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  flex-shrink: 0;
}
.header .brand-icon svg {
  width: 100%;
  height: 100%;
}

.header .brand-name {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#nav button {
  font-family: var(--apple-font);
  background: var(--apple-bg-tertiary);
  color: var(--apple-blue);
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background var(--apple-transition);
}

#nav button:hover {
  background: rgba(255, 45, 45, 0.18);
}

/* --- Notification bell & panel --- */
.notif-wrap {
  position: relative;
}
.notif-wrap.hidden {
  display: none;
}
.notif-bell {
  position: relative;
  background: none;
  border: none;
  color: var(--apple-text);
  cursor: pointer;
  padding: 0.375rem;
  border-radius: 50%;
  transition: background var(--apple-transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.notif-bell:hover {
  background: var(--apple-bg-tertiary);
}
.notif-badge {
  position: absolute;
  top: -2px;
  right: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: #ff453a;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  pointer-events: none;
}
.notif-badge.hidden {
  display: none;
}
.notif-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: 360px;
  max-width: 92vw;
  max-height: 460px;
  background: var(--apple-bg-elevated);
  border: 1px solid var(--apple-separator);
  border-radius: var(--apple-radius);
  box-shadow: var(--apple-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 200;
  animation: notif-in 0.18s ease-out;
}
.notif-panel.hidden {
  display: none;
}
@keyframes notif-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--apple-separator);
}
.notif-panel-title {
  font-size: 0.9375rem;
  font-weight: 600;
}
.notif-read-all {
  font-family: var(--apple-font);
  background: none;
  border: none;
  color: var(--apple-blue);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: background var(--apple-transition);
}
.notif-read-all:hover {
  background: rgba(255, 45, 45, 0.12);
}
.notif-list {
  overflow-y: auto;
  flex: 1;
  padding: 0.25rem 0;
}
.notif-item {
  display: flex;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background var(--apple-transition);
  border-left: 3px solid transparent;
}
.notif-item:hover {
  background: var(--apple-bg-tertiary);
}
.notif-item.notif-unread {
  border-left-color: var(--apple-accent);
  background: rgba(255, 45, 45, 0.06);
}
.notif-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--apple-bg-tertiary);
  border-radius: 50%;
}
.notif-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.notif-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--apple-text);
}
.notif-text {
  font-size: 0.8125rem;
  color: var(--apple-text-secondary);
  line-height: 1.35;
}
.notif-time {
  font-size: 0.6875rem;
  color: var(--apple-text-tertiary);
  margin-top: 0.1rem;
}
.notif-empty {
  padding: 2rem 1rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--apple-text-tertiary);
}

/* --- Main layout --- */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

.screen {
  max-width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

#screen-auth {
  max-width: 420px;
}

#screen-auth:not(.hidden) {
  min-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.screen.hidden {
  display: none;
}

/* --- Netflix-style: ряды рекомендаций --- */
.rec-sections {
  margin-bottom: 2.5rem;
}

.rec-section {
  margin-bottom: 2rem;
}

.rec-section-title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 0.75rem 0;
  padding: 0 0.25rem;
  color: var(--apple-text);
}

.rec-row {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25rem 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
}

.rec-row::-webkit-scrollbar {
  display: none;
}

.rec-card {
  scroll-snap-align: start;
  flex: 0 0 160px;
  min-width: 160px;
  background: var(--apple-bg-tertiary);
  border-radius: var(--apple-radius-card);
  padding: 1rem;
  transition: transform var(--apple-transition), background var(--apple-transition);
  cursor: default;
  border: 1px solid transparent;
}

.rec-card:hover {
  transform: scale(1.03);
  background: var(--apple-bg-elevated);
  border-color: var(--apple-separator);
}

.rec-card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 0.35rem 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.rec-card-meta {
  font-size: 0.8125rem;
  color: var(--apple-text-secondary);
  margin: 0;
}

/* --- Загрузка секций --- */
.rec-sections-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  gap: 1rem;
  color: var(--apple-text-secondary);
}

.rec-sections-loading .loader {
  width: 32px;
  height: 32px;
  border: 2px solid var(--apple-bg-tertiary);
  border-top-color: var(--apple-blue);
  border-radius: 50%;
  animation: loader-spin 0.8s linear infinite;
}

@keyframes loader-spin {
  to { transform: rotate(360deg); }
}

/* --- Карточки контента (подписки, форма, лента) --- */
.welcome {
  font-size: 1.125rem;
  color: var(--apple-text-secondary);
  margin-bottom: 1.5rem;
  padding: 0 0.25rem;
}

.welcome strong {
  color: var(--apple-text);
  font-weight: 600;
}

.card {
  background: var(--apple-bg-elevated);
  border-radius: var(--apple-radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  border: 1px solid var(--apple-separator);
}

.card h2 {
  margin: 0 0 1rem 0;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--apple-text);
}

.card h3 {
  margin: 1rem 0 0.5rem 0;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--apple-text-secondary);
}

.search-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.search-row input {
  flex: 1;
  font-family: var(--apple-font);
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--apple-separator);
  border-radius: var(--apple-radius-sm);
  background: var(--apple-bg-tertiary);
  color: var(--apple-text);
  font-size: 0.9375rem;
  transition: border-color var(--apple-transition);
}

.search-row input::placeholder {
  color: var(--apple-text-tertiary);
}

.search-row input:focus {
  outline: none;
  border-color: var(--apple-blue);
}

.search-row button,
.card button[type="submit"],
.card button:not(.unfollow) {
  font-family: var(--apple-font);
  padding: 0.5rem 1rem;
  background: var(--apple-blue);
  color: #fff;
  border: none;
  border-radius: var(--apple-radius-sm);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background var(--apple-transition);
}

.search-row button:hover,
.card button[type="submit"]:hover {
  background: var(--apple-blue-hover);
}

.list, .feed {
  contain: layout style;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.list-item, .feed-item {
  contain: layout style paint;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.875rem;
  background: var(--apple-bg-tertiary);
  border-radius: var(--apple-radius-sm);
  border: 1px solid transparent;
  transition: background var(--apple-transition);
}

.list-item .name,
.feed-item .user {
  font-weight: 500;
  font-size: 0.9375rem;
}

.list-item .meta,
.feed-item .content {
  font-size: 0.8125rem;
  color: var(--apple-text-secondary);
  margin-top: 0.2rem;
}

.list-item button {
  font-family: var(--apple-font);
  padding: 0.35rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  transition: opacity var(--apple-transition);
}

.list-item button.follow {
  background: var(--apple-blue);
  color: #fff;
}

.list-item button.unfollow {
  background: var(--apple-bg-card);
  color: var(--apple-text-secondary);
  border: 1px solid var(--apple-separator);
}

.list-item button:hover {
  opacity: 0.9;
}

/* Form watch */
#form-watch {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

#form-watch input,
#form-watch select {
  font-family: var(--apple-font);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--apple-separator);
  border-radius: var(--apple-radius-sm);
  background: var(--apple-bg-tertiary);
  color: var(--apple-text);
  font-size: 0.9375rem;
}

#form-watch input[type="number"] {
  width: 5rem;
}

.feed-filters {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.feed-filters button {
  font-family: var(--apple-font);
  padding: 0.4rem 0.875rem;
  background: var(--apple-bg-tertiary);
  color: var(--apple-text-secondary);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background var(--apple-transition), color var(--apple-transition);
}

.feed-filters button.active {
  background: var(--apple-blue);
  color: #fff;
}

.feed {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.feed-item {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
}

.feed-item .status {
  display: inline-block;
  margin-top: 0.4rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.feed-item .status.watching { background: #30d158; color: #000; }
.feed-item .status.watched { background: #5e5ce6; color: #fff; }
.feed-item .status.plan_to_watch { background: #ff9f0a; color: #000; }

.empty {
  color: var(--apple-text-tertiary);
  padding: 1.25rem;
  text-align: center;
  font-size: 0.9375rem;
}

/* Auth */
.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.auth-tabs button {
  font-family: var(--apple-font);
  padding: 0.5rem 1rem;
  background: var(--apple-bg-tertiary);
  color: var(--apple-text-secondary);
  border: none;
  border-radius: var(--apple-radius-sm);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background var(--apple-transition), color var(--apple-transition);
}

.auth-tabs button:hover:not(.active) {
  background: var(--apple-bg-elevated);
  color: var(--apple-text);
}

.auth-tabs button.active {
  background: var(--apple-blue);
  color: #fff;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.auth-form input {
  font-family: var(--apple-font);
  padding: 0.875rem 1rem;
  border: 1px solid var(--apple-separator);
  border-radius: var(--apple-radius-sm);
  background: var(--apple-bg-elevated);
  color: var(--apple-text);
  font-size: 1rem;
  transition: border-color var(--apple-transition);
}

.auth-form input::placeholder {
  color: var(--apple-text-tertiary);
}

.auth-form input:focus {
  outline: none;
  border-color: var(--apple-blue);
}

.auth-form input:invalid:not(:placeholder-shown) {
  border-color: rgba(255, 69, 58, 0.5);
}

.auth-form input:valid:not(:placeholder-shown) {
  border-color: rgba(48, 209, 88, 0.5);
}

.auth-form button {
  font-family: var(--apple-font);
  padding: 0.875rem;
  background: var(--apple-blue);
  color: #fff;
  border: none;
  border-radius: var(--apple-radius-sm);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--apple-transition);
}

.auth-form button:hover {
  background: var(--apple-blue-hover);
}

.auth-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-form.hidden {
  display: none;
}

.auth-agree {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.875rem;
  line-height: 1.4;
  cursor: pointer;
}

.auth-agree input[type="checkbox"] {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.auth-agree a {
  color: var(--apple-blue, #007aff);
}

.auth-legal {
  margin-top: 1.25rem;
  font-size: 0.875rem;
  text-align: center;
}

.auth-legal a {
  color: var(--apple-blue, #007aff);
}

.error {
  color: #ff453a;
  font-size: 0.9375rem;
  margin-top: 0.5rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 69, 58, 0.1);
  border-radius: var(--apple-radius-sm);
  border: 1px solid rgba(255, 69, 58, 0.3);
}

.error.hidden {
  display: none;
}

/* List loading state */
.list-loading, .feed-loading {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 0;
  min-height: 3rem;
  align-items: center;
  justify-content: center;
  color: var(--apple-text-secondary);
  font-size: 0.9375rem;
}

.feed-loading {
  min-height: 5rem;
}

.list-loading .loader,
.feed-loading .loader {
  width: 28px;
  height: 28px;
  border: 2px solid var(--apple-bg-tertiary);
  border-top-color: var(--apple-blue);
  border-radius: 50%;
  animation: loader-spin 0.7s linear infinite;
}

.loader-label {
  font-size: 0.875rem;
  color: var(--apple-text-tertiary);
}

/* List/feed animation */
.list.list-ready .list-item,
.feed.feed-ready .feed-item {
  animation: item-in 0.35s ease-out backwards;
}

.feed.feed-ready .feed-item {
  animation-duration: 0.4s;
}

.list-item:nth-child(1), .feed-item:nth-child(1) { animation-delay: 0.02s; }
.list-item:nth-child(2), .feed-item:nth-child(2) { animation-delay: 0.05s; }
.list-item:nth-child(3), .feed-item:nth-child(3) { animation-delay: 0.08s; }
.list-item:nth-child(4), .feed-item:nth-child(4) { animation-delay: 0.11s; }
.list-item:nth-child(5), .feed-item:nth-child(5) { animation-delay: 0.14s; }
.list-item:nth-child(6), .feed-item:nth-child(6) { animation-delay: 0.17s; }
.list-item:nth-child(7), .feed-item:nth-child(7) { animation-delay: 0.2s; }
.list-item:nth-child(8), .feed-item:nth-child(8) { animation-delay: 0.23s; }
.list-item:nth-child(9), .feed-item:nth-child(9) { animation-delay: 0.26s; }
.list-item:nth-child(10), .feed-item:nth-child(10) { animation-delay: 0.29s; }
.list-item:nth-child(n+11), .feed-item:nth-child(n+11) { animation-delay: 0.32s; }

@keyframes item-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.list.list-idle .list-item,
.feed.feed-idle .feed-item {
  animation: none;
}

/* --- Danger zone (delete account) --- */
.card-danger {
  border-color: rgba(255, 69, 58, 0.25);
}
.danger-summary {
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--apple-text-secondary);
  list-style: none;
  padding: 0.25rem 0;
}
.danger-summary::-webkit-details-marker { display: none; }
.danger-summary::before {
  content: "▸ ";
  color: var(--apple-text-tertiary);
}
details[open] > .danger-summary::before {
  content: "▾ ";
}
.danger-text {
  font-size: 0.875rem;
  color: var(--apple-text-tertiary);
  margin: 0.5rem 0 1rem;
}
.btn-danger {
  font-family: var(--apple-font);
  padding: 0.625rem 1.25rem;
  background: #ff453a;
  color: #fff;
  border: none;
  border-radius: var(--apple-radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--apple-transition);
}
.btn-danger:hover {
  opacity: 0.85;
}

/* --- Language switcher --- */
.lang-switcher {
  font-family: var(--apple-font);
  background: var(--apple-bg-tertiary);
  color: var(--apple-text-secondary);
  border: 1px solid var(--apple-separator);
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color var(--apple-transition);
  -webkit-appearance: none;
}
.lang-switcher:focus {
  border-color: var(--apple-blue);
}
.lang-switcher option {
  background: var(--apple-bg-elevated);
  color: var(--apple-text);
}

/* --- Safe-area for Capacitor / notch --- */
.header {
  padding-top: max(0.75rem, env(safe-area-inset-top));
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
}
#main {
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
}

/* --- Responsive --- */
@media (max-width: 600px) {
  .header {
    padding: 0.5rem 1rem;
    padding-top: max(0.5rem, env(safe-area-inset-top));
  }

  .header .brand-name {
    font-size: 1.05rem;
  }

  .screen {
    padding: 1rem 0.75rem;
  }

  .card {
    padding: 1rem;
    border-radius: var(--apple-radius-sm);
  }

  .search-row {
    flex-direction: column;
  }

  .search-row button {
    width: 100%;
  }

  #form-watch {
    flex-direction: column;
  }

  #form-watch input,
  #form-watch select {
    width: 100%;
  }

  #form-watch input[type="number"] {
    width: 100%;
  }

  .rec-card {
    flex: 0 0 140px;
    min-width: 140px;
  }

  .notif-panel {
    width: 100vw;
    max-width: 100vw;
    right: -1rem;
    border-radius: 0 0 var(--apple-radius) var(--apple-radius);
  }

  .rec-section-title {
    font-size: 1.1rem;
  }
}

@media (max-width: 380px) {
  .header-right {
    gap: 0.5rem;
  }

  .lang-switcher {
    font-size: 0.75rem;
    padding: 0.2rem 0.35rem;
  }

  .auth-tabs button {
    font-size: 0.8125rem;
    padding: 0.4rem 0.75rem;
  }

  .rec-card {
    flex: 0 0 120px;
    min-width: 120px;
    padding: 0.75rem;
  }
}
