/* ============================================================
   vkmeta-index — refined minimal theme
   Dark by default, light via prefers-color-scheme / [data-theme].
   Accent: violet.
   ============================================================ */

:root {
  /* surfaces */
  --bg: #0a0a0b;
  --surface: #141417;
  --surface-elev: #1b1b1f;
  --field: #161619;
  --border: #28282e;
  --border-strong: #3a3a42;

  /* text */
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-faint: #71717a;

  /* accent (violet) */
  --accent: #8b5cf6;
  --accent-hover: #9d7bff;
  --accent-soft: rgba(139, 92, 246, 0.16);
  --accent-contrast: #ffffff;

  /* effects */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.35), 0 12px 30px rgba(0, 0, 0, 0.35);
  --focus-ring: rgba(139, 92, 246, 0.55);
  --overlay: rgba(0, 0, 0, 0.72);

  /* shape */
  --radius: 14px;
  --radius-sm: 9px;
  --radius-pill: 999px;

  /* motion */
  --ease: 160ms cubic-bezier(0.4, 0, 0.2, 1);

  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans", Roboto, Helvetica, Arial,
    sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---- light tokens (system-auto) ---- */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #fafafa;
    --surface: #ffffff;
    --surface-elev: #ffffff;
    --field: #f4f4f5;
    --border: #e6e6e9;
    --border-strong: #d4d4d8;

    --text: #18181b;
    --text-muted: #52525b;
    --text-faint: #9b9ba3;

    --accent: #7c3aed;
    --accent-hover: #6d28d9;
    --accent-soft: rgba(124, 58, 237, 0.10);
    --accent-contrast: #ffffff;

    --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.06);
    --shadow: 0 1px 2px rgba(24, 24, 27, 0.06), 0 12px 28px rgba(24, 24, 27, 0.10);
    --focus-ring: rgba(124, 58, 237, 0.40);
    --overlay: rgba(0, 0, 0, 0.66);

    color-scheme: light;
  }
}

/* ---- light tokens (manual) ---- */
:root[data-theme="light"] {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-elev: #ffffff;
  --field: #f4f4f5;
  --border: #e6e6e9;
  --border-strong: #d4d4d8;

  --text: #18181b;
  --text-muted: #52525b;
  --text-faint: #9b9ba3;

  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: rgba(124, 58, 237, 0.10);
  --accent-contrast: #ffffff;

  --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.06);
  --shadow: 0 1px 2px rgba(24, 24, 27, 0.06), 0 12px 28px rgba(24, 24, 27, 0.10);
  --focus-ring: rgba(124, 58, 237, 0.40);
  --overlay: rgba(0, 0, 0, 0.66);

  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

::selection {
  background: var(--accent-soft);
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------
   Form controls
   ------------------------------------------------------------ */
input,
button,
select {
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color var(--ease), background var(--ease),
    box-shadow var(--ease), color var(--ease);
}

input {
  flex: 1;
  min-width: 0;
  padding: 0 14px;
}

input::placeholder {
  color: var(--text-faint);
}

input:hover,
select:hover {
  border-color: var(--border-strong);
}

input:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

select {
  padding: 0 30px 0 12px;
  cursor: pointer;
}

button {
  padding: 0 16px;
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  border-color: var(--border-strong);
}

/* primary / accent button */
.btn-primary,
button[type="submit"] {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
}

.btn-primary:hover,
button[type="submit"]:hover {
  background: var(--accent-hover);
  border-color: transparent;
}

.btn-primary:focus-visible,
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ------------------------------------------------------------
   Top bar
   ------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
}

.brand {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
}

.brand span {
  color: var(--accent);
}

.top-search {
  display: flex;
  gap: 8px;
  width: min(560px, 100%);
}

.bar-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-controls select {
  height: 36px;
}

/* ------------------------------------------------------------
   Main layout
   ------------------------------------------------------------ */
main {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 26px 20px 64px;
}

/* ------------------------------------------------------------
   Home
   ------------------------------------------------------------ */
.home {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  padding: 24px;
  position: relative;
  text-align: center;
}

.home::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    60% 50% at 50% 30%,
    var(--accent-soft),
    transparent 70%
  );
}

.home-controls {
  position: fixed;
  top: 18px;
  right: 20px;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.home-mark {
  position: relative;
  font-size: clamp(34px, 7vw, 56px);
  font-weight: 800;
  letter-spacing: -0.04em;
  margin: 0;
  line-height: 1;
}

.home-mark span {
  color: var(--accent);
}

.search-box {
  position: relative;
  display: flex;
  gap: 10px;
  width: min(640px, calc(100vw - 48px));
}

.search-box input {
  height: 54px;
  font-size: 17px;
  padding: 0 18px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.search-box button {
  height: 54px;
  padding: 0 24px;
  border-radius: var(--radius);
  font-size: 15px;
}

/* ------------------------------------------------------------
   Search results
   ------------------------------------------------------------ */
.results-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 22px;
  color: var(--text-muted);
  font-size: 14px;
}

.results-head strong {
  color: var(--text);
}

.results-count b {
  color: var(--accent);
  font-weight: 700;
}

.sort-form {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-faint);
  font-size: 13px;
}

.sort-form select {
  height: 36px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(206px, 1fr));
  gap: 22px 18px;
}

.card {
  min-width: 0;
}

.card-link {
  display: block;
}

.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  font-size: 13px;
  transition: border-color var(--ease), box-shadow var(--ease),
    transform var(--ease);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 240ms cubic-bezier(0.4, 0, 0.2, 1);
}

.badge {
  position: absolute;
  right: 7px;
  bottom: 7px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--overlay);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.card-link:hover .thumb {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.card-link:hover .thumb img {
  transform: scale(1.05);
}

.card-body {
  padding-top: 10px;
}

.title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color var(--ease);
}

.card-link:hover .title {
  color: var(--accent);
}

.channel {
  margin-top: 5px;
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-line {
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-faint);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
}

.meta-line .album {
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-line .sep {
  color: var(--border-strong);
}

/* empty state */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 80px 20px;
  font-size: 15px;
}

/* ------------------------------------------------------------
   Pager
   ------------------------------------------------------------ */
.pager {
  margin-top: 36px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  color: var(--text-muted);
  font-size: 14px;
}

.pager a {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  background: var(--surface);
  font-weight: 600;
  transition: border-color var(--ease), color var(--ease), background var(--ease);
}

.pager a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.pager span {
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------
   Video detail
   ------------------------------------------------------------ */
.detail {
  display: grid;
  grid-template-columns: minmax(280px, 600px) 1fr;
  gap: 32px;
  align-items: start;
}

.detail-media {
  aspect-ratio: 16 / 9;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.detail-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail h1 {
  margin: 2px 0 18px;
  font-size: clamp(20px, 3vw, 26px);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.detail-meta {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 20px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.meta-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 12px;
  font-size: 13.5px;
  line-height: 1.45;
}

.meta-row .k {
  color: var(--text-faint);
  text-transform: capitalize;
}

.meta-row .v {
  color: var(--text);
  overflow-wrap: anywhere;
}

.meta-row .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--text-muted);
}

.vk-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 14px;
  font-weight: 600;
  transition: background var(--ease), box-shadow var(--ease);
}

.vk-link::after {
  content: "↗";
  font-size: 13px;
  opacity: 0.85;
}

.vk-link:hover {
  background: var(--accent-hover);
}

.description {
  margin: 22px 0 0;
  color: var(--text-muted);
  line-height: 1.7;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* ------------------------------------------------------------
   Responsive
   ------------------------------------------------------------ */
@media (max-width: 980px) {
  .detail {
    grid-template-columns: 1fr;
    gap: 22px;
  }
}

@media (max-width: 700px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .top-search {
    order: 3;
    width: 100%;
  }

  .bar-controls {
    margin-left: auto;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 12px;
  }

}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
