/* Токены, типографика и общие примитивы. */

:root {
  --bg: #f6f6f7;
  --bg-elevated: #ffffff;
  --bg-sunken: #ececee;
  --bg-hover: rgba(0, 0, 0, .05);
  --bg-active: rgba(0, 0, 0, .09);
  --text: #16161a;
  --text-dim: #5d5d68;
  --text-faint: #8c8c98;
  --line: rgba(0, 0, 0, .1);
  --line-strong: rgba(0, 0, 0, .18);
  --accent: #d4333a;
  --accent-text: #ffffff;
  --accent-soft: rgba(212, 51, 58, .12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .08), 0 1px 3px rgba(0, 0, 0, .06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .12);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .2);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --bar-h: 76px;
  --top-h: 60px;
  --page-pad: 24px;
  color-scheme: light;
}

:root[data-theme="dark"],
:root[data-theme="auto"] {
  color-scheme: dark;
}

/* Тёмная — по умолчанию для auto и явная для dark. */
:root[data-theme="auto"], :root[data-theme="dark"] {
  --bg: #0d0d10;
  --bg-elevated: #17171c;
  --bg-sunken: #08080a;
  --bg-hover: rgba(255, 255, 255, .07);
  --bg-active: rgba(255, 255, 255, .12);
  --text: #f2f2f5;
  --text-dim: #a9a9b6;
  --text-faint: #71717f;
  --line: rgba(255, 255, 255, .1);
  --line-strong: rgba(255, 255, 255, .2);
  --accent: #ff4d55;
  --accent-text: #15070a;
  --accent-soft: rgba(255, 77, 85, .16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, .55);
  --shadow-lg: 0 30px 70px rgba(0, 0, 0, .7);
}

/* В auto светлая тема возвращается, если система просит светлое. */
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f6f6f7;
    --bg-elevated: #ffffff;
    --bg-sunken: #ececee;
    --bg-hover: rgba(0, 0, 0, .05);
    --bg-active: rgba(0, 0, 0, .09);
    --text: #16161a;
    --text-dim: #5d5d68;
    --text-faint: #8c8c98;
    --line: rgba(0, 0, 0, .1);
    --line-strong: rgba(0, 0, 0, .18);
    --accent: #d4333a;
    --accent-text: #ffffff;
    --accent-soft: rgba(212, 51, 58, .12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .08), 0 1px 3px rgba(0, 0, 0, .06);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .12);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .2);
    color-scheme: light;
  }
}

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

/* Кнопки и карточки задают свой display, поэтому hidden нужно усилить. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: anywhere;
}

body.is-locked { overflow: hidden; }

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
h1 { font-size: clamp(26px, 4vw, 40px); }
h2 { font-size: clamp(19px, 2.4vw, 24px); }
h3 { font-size: 16px; }
p { margin: 0; }

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }

img { display: block; max-width: 100%; }

button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.filled { fill: currentColor; stroke: none; }

/* Обложка или аватарка, которой нет: иконка-заглушка по центру. */
.media-empty { display: grid; place-items: center; color: var(--text-faint); }
.media-empty svg { width: 38%; height: 38%; }

/* --- Шапка --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--top-h);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar__inner {
  height: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 var(--page-pad);
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar__back { flex: none; }
.topbar__back[hidden] { display: none; }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.02em; flex: none; }
.brand__dot { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); }
.brand__tld { color: var(--text-faint); font-weight: 600; }
.brand__text { font-size: 16px; }

.search {
  position: relative;
  flex: 1 1 auto;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  align-items: center;
}
.search__icon { position: absolute; left: 12px; color: var(--text-faint); pointer-events: none; }
.search__input {
  width: 100%;
  height: 40px;
  padding: 0 40px 0 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elevated);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
.search__input::-webkit-search-cancel-button { display: none; }
.search__input:hover { border-color: var(--line-strong); }
.search__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search__clear { position: absolute; right: 4px; width: 32px; height: 32px; }
.search__clear svg { width: 16px; height: 16px; }

.topbar__tools { display: flex; align-items: center; gap: 6px; flex: none; }

.select { position: relative; display: inline-flex; align-items: center; }
.select__icon { position: absolute; left: 9px; width: 17px; height: 17px; color: var(--text-dim); pointer-events: none; }
.select select {
  height: 36px;
  padding: 0 10px 0 31px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  max-width: 132px;
}
.select select:hover { background: var(--bg-hover); }
.select select:focus-visible { border-color: var(--accent); }
.select option { background: var(--bg-elevated); color: var(--text); }

/* --- Кнопки --- */

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.iconbtn:hover { background: var(--bg-hover); color: var(--text); }
.iconbtn:active { background: var(--bg-active); }
.iconbtn.is-on { color: var(--accent); }
.iconbtn:disabled { opacity: .35; cursor: default; background: transparent; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elevated);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .15s, border-color .15s, transform .08s;
}
.btn:hover { background: var(--bg-hover); border-color: var(--line-strong); }
.btn:active { transform: scale(.97); }
.btn svg { width: 18px; height: 18px; }

.btn--primary { background: var(--accent); border-color: transparent; color: var(--accent-text); }
.btn--primary:hover { background: var(--accent); border-color: transparent; filter: brightness(1.07); }
.btn--ghost { background: transparent; }

/* Сегментированный переключатель (сортировки, фильтры, трек/видео). */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
}
.segmented button {
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .15s, color .15s;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--bg-elevated); color: var(--text); box-shadow: var(--shadow-sm); }

/* --- Страница --- */

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px var(--page-pad) calc(var(--bar-h) + 56px);
  min-height: calc(100vh - var(--top-h));
}
body.has-player .page { padding-bottom: calc(var(--bar-h) + 56px); }

.section { margin-bottom: 44px; }
.section:last-child { margin-bottom: 0; }

.section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.section__title { display: flex; align-items: baseline; gap: 10px; }
.section__count { color: var(--text-faint); font-size: 14px; font-weight: 500; }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.nowrap { white-space: nowrap; }

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- Состояния --- */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 72px 20px;
  text-align: center;
  color: var(--text-dim);
}
.state svg { width: 40px; height: 40px; color: var(--text-faint); }
.state__title { font-size: 17px; font-weight: 600; color: var(--text); }

.spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--bg-hover) 37%, var(--bg-sunken) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* --- Меню по правой кнопке / «⋯» --- */

.menu {
  position: fixed;
  z-index: 200;
  min-width: 232px;
  max-width: min(94vw, 320px);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  animation: menu-in .12s ease-out;
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.menu__item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: start;
  font-size: 14px;
  cursor: pointer;
}
.menu__item:hover { background: var(--bg-hover); }
.menu__item svg { width: 18px; height: 18px; flex: none; color: var(--text-dim); }
.menu__sep { height: 1px; margin: 6px 8px; background: var(--line); }
.menu__label { padding: 9px 12px 5px; font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-faint); }
.menu__item[aria-checked="true"] { color: var(--accent); font-weight: 600; }
.menu__item[aria-checked="true"] svg { color: var(--accent); }

/* --- Модальное окно (<dialog>, открывается через showModal) --- */

.dialog {
  width: min(460px, calc(100% - 32px));
  max-width: none;
  max-height: calc(100% - 32px);
  margin: auto;
  padding: 0;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.dialog[open] { animation: dialog-in .16s ease-out; }
.dialog::backdrop { background: rgba(0, 0, 0, .5); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes sheet-in { from { transform: translateY(100%); } }

.dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 10px 0 20px;
}
.dialog__head h2 { font-size: 18px; }
.dialog__body { display: flex; flex-direction: column; gap: 16px; padding: 10px 20px 20px; }

/* --- Уведомления --- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + 20px);
  z-index: 300;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in .2s ease-out;
}
.toast.is-out { animation: toast-out .2s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

@media (max-width: 720px) {
  :root { --page-pad: 16px; --bar-h: 68px; }
  .brand__text { display: none; }
  .search { max-width: none; }
  .select select { max-width: 44px; padding-right: 0; color: transparent; }
  .select option { color: var(--text); }

  /* На телефоне окно выезжает снизу, как системные. */
  .dialog {
    width: 100%;
    max-height: calc(100% - 40px);
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .dialog[open] { animation: sheet-in .22s ease-out; }
  .dialog__body { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}
