:root {
  --text-light: #e6edf3;
  --text-dark: #e6edf3;
  --background-color-light: #0d1117;
  --background-color-dark: #0d1117;
  --primary-color: #30363d;
  --button-color: #21262d;
  --button-color-dark: #21262d;
  --background-image-light: none;
  --background-image-dark: none;
  --header-h: 48px;
  --filters-h: 52px; /* фиксированная высота панели фильтров */
  margin: 0;
  padding: 0;
}

body {
  font-family: "Maven Pro", sans-serif;
  margin: 0;
  padding: 0;
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s, background-image 0.3s;
  background-color: var(--background-color-light);
  background-image: var(--background-image-light);
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
  background-attachment: fixed;
}
.dark-theme body {
  background-color: var(--background-color-dark);
  background-image: var(--background-image-dark);
}

header:not(.site-header) {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding-top: env(safe-area-inset-top, 0);
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
  background-color: var(--primary-color);
  color: var(--text-dark);
  z-index: 1000;
  line-height: var(--header-h);
  overflow: hidden;
  font-size: 15px;
}

/* Контент: по умолчанию отступ под хедер + фикс-панель фильтров */
main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: calc(var(--header-h) + var(--filters-h) + 16px) 1em 24px;
  flex-direction: column;
  align-items: center;
}

#logo {
  flex: 1 1 auto;            /* занимает доступное место, но не ломает верстку */
  min-width: 0;              /* чтобы работало text-overflow */
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dark);
  white-space: nowrap;       /* не переносить */
  overflow: hidden;          /* обрезать лишнее */
  text-overflow: ellipsis;   /* добавлять "…" */
}


/* Режим поиска (фильтры скрываются в JS): убираем отступ под фильтры */
main.search-mode {
  padding: calc(var(--header-h) + 16px) 1em 24px;
}

/* ===== ФИЛЬТРЫ: фиксированы под хедером, в одну строку ===== */
#filters {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  height: var(--filters-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  box-sizing: border-box;
  z-index: 950;
  background: transparent;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  /* одна строка + прокрутка по X, никакого изменения высоты */
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: thin;
}
#filters:empty { display: none; }

/* Чипы фильтров — стиль как у link-button */
.filter-chip {
  display:flex; align-items:center; justify-content:center;
  padding:8px 12px; min-height:32px;
  border-radius:10px; font-weight:600; font-size:14px; line-height:1.2;
  white-space:nowrap; text-decoration:none; box-sizing:border-box;
  background-color: var(--button-color); color: var(--text-light);
  border:none;
  transition: background-color .2s, transform .06s, box-shadow .06s;
}
.dark-theme .filter-chip { background-color: var(--button-color-dark); color: var(--text-dark) }
.filter-chip:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.18) }

/* базовый стиль фильтра */
.filter-chip {
  background-color: transparent;
  color: var(--text-dark);
  border: 2px solid var(--primary-color);
}

/* активная кнопка — заливка, жирный текст */
.filter-chip.active {
  background-color: var(--button-color);
  color: var(--text-light);
  border-color: var(--primary-color);
  font-weight: 700;
}

.dark-theme .filter-chip.active {
  background-color: var(--button-color-dark);
  color: var(--text-dark);
  border-color: var(--primary-color);
}

/* ===== Секции и сетка ссылок ===== */
.category-section { width:100%; max-width:1000px; margin:12px auto 20px; }
.category-title { margin:6px 4px 10px; font-size:16px; font-weight:700; color:var(--text-dark); }
body:not(.dark-theme) .category-title { color:var(--text-dark); }

.links-grid {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
  gap:12px; width:100%;
}
#link-container { width: 100%; max-width: 1000px; }

/* ===== Кнопки ссылок ===== */
.link-button {
  display:flex; align-items:center; justify-content:center;
  padding:16px 12px; min-height:84px;
  text-align:center; font-size:16px; text-decoration:none;
  color:var(--text-light); background-color:var(--button-color);
  border-radius:10px; font-weight:600;
  transition: background-color .3s, transform .06s, box-shadow .06s;
  box-sizing:border-box; line-height:1.25; white-space:normal; word-break:break-word;
}
.link-button:hover { transform:translateY(-1px); box-shadow:0 4px 12px rgba(0,0,0,.18) }
.dark-theme .link-button { color:var(--text-dark); background-color:var(--button-color-dark) }

/* ===== Тема/поиск ===== */
#theme-toggle {
  background:none; border:none; color:inherit; cursor:pointer; padding:0;
  display:flex; align-items:center; justify-content:center; transition:transform .3s;
}
#theme-toggle:hover { transform:rotate(20deg) }
#themeIcon { width:24px; height:24px; transition:transform .3s }

/* Поисковая строка */
.input-wrapper {
  position: relative;                /* якорь для выпадающего списка */
  display:flex; align-items:center; width:100%;
  background-color:var(--background-color-light);
  border:2px solid var(--primary-color); border-radius:8px;
  overflow: visible;                 /* не обрезать подсказки */
}
.dark-theme .input-wrapper { background-color:var(--background-color-dark) }

#toggle-search {
  padding:10px 16px; font-size:14px; background-color:var(--button-color-dark);
  color:var(--text-dark); border:none; cursor:pointer; transition:background-color .3s;
  border-right:2px solid var(--primary-color); order:-1;
}
#toggle-search:hover { filter:brightness(0.9) }

#search-input {
  flex:1; padding:12px; font-size:16px; border:none; outline:none;
  background:transparent; color:var(--text-dark);
}
#search-btn {
  padding:12px 16px; font-size:14px; background-color:var(--button-color-dark);
  color:var(--text-dark); border:none; cursor:pointer; transition:background-color .3s;
  border-left:2px solid var(--primary-color);
}
#search-btn:hover { filter:brightness(0.9) }

/* Подсказки поиска — строго под инпутом */
#search-suggestions {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 100%;
  list-style: none;
  margin: 0;
  padding: 8px 0;
  background-color: var(--background-color-light);
  border: 2px solid var(--primary-color);
  border-radius: 10px;
  z-index: 1000;
  box-sizing: border-box;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.dark-theme #search-suggestions { background-color: var(--background-color-dark) }
.suggestion-item {
  padding:10px 14px; font-size:14px;
  background-color: var(--button-color-dark); color: var(--text-dark);
  cursor:pointer; transition: background-color .2s;
}
.suggestion-item:hover { background-color: var(--primary-color) }
.hidden { display:none }

/* Центрировать поиск, если карточек нет (резерв для браузеров с :has) */
main:has(#link-container:empty) { align-items:center; }

/* Контейнер поиска */
.search-container { width:100%; max-width:1000px; margin:0 auto; }

/* Рамка поиска */
.search-container .input-wrapper { max-width:640px; margin:0 auto; }

@media (max-width: 600px) {
  .search-container .input-wrapper { max-width:100%; }
}

/* stats-main visual alignment */
:root {
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --container-max: 1180px;
  --color-bg: #0d1117;
  --color-surface: #161b22;
  --color-surface-2: #21262d;
  --color-text: #e6edf3;
  --color-text-muted: #8b949e;
  --color-accent: #2f81f7;
  --color-accent-strong: #1f6feb;
  --color-border: #30363d;
  --radius-sm: 6px;
  --radius-md: 8px;
  --shadow-card: 0 8px 24px rgba(1, 4, 9, 0.32);
  --shadow-soft: 0 1px 0 rgba(255, 255, 255, 0.03);
  color-scheme: dark;
}

html {
  min-width: 320px;
}

body {
  display: block;
  min-width: 320px;
  min-height: 100vh;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(22, 27, 34, 0.92), rgba(13, 17, 23, 0) 280px),
    var(--background-image-light),
    var(--color-bg);
  background-size: auto, cover, auto;
  background-position: top center, center, center;
  background-repeat: no-repeat, no-repeat, no-repeat;
  background-attachment: scroll, fixed, scroll;
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
}

.dark-theme body {
  background:
    linear-gradient(180deg, rgba(22, 27, 34, 0.92), rgba(13, 17, 23, 0) 280px),
    var(--color-bg);
  color: var(--color-text);
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

header:not(.site-header) {
  position: static;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: var(--container-max);
  height: auto;
  margin: 0 auto 20px;
  padding: 15px 20px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: rgba(22, 27, 34, 0.92);
  color: #ffffff;
  box-shadow: var(--shadow-soft);
  line-height: 1.5;
  overflow: visible;
}

#logo {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0 auto 0 0;
  color: #ffffff;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

#theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 48px;
  min-height: 48px;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-surface-2);
  color: #ffffff;
  box-shadow: none;
  transition: transform 0.15s ease, filter 0.15s ease, background-color 0.15s ease;
}

#theme-toggle:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

#themeIcon {
  width: 22px;
  height: 22px;
  filter: brightness(0) invert(1);
}

main,
main.search-mode {
  display: grid;
  align-items: stretch;
  align-content: start;
  justify-content: stretch;
  gap: 20px;
  max-width: var(--container-max);
  min-height: 0;
  margin: 0 auto;
  padding: 0;
}

main.search-mode {
  min-height: 360px;
  align-content: start;
}

#filters {
  position: static;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  max-width: none;
  height: auto;
  margin: 0;
  padding: 14px;
  overflow: visible;
  white-space: normal;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.navigator-title {
  margin: 0;
  color: var(--color-text);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
}

.navigator-setup-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-surface-2);
  color: var(--color-text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  transition: transform 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.navigator-setup-link:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 129, 247, 0.42);
  background-color: rgba(47, 129, 247, 0.14);
  color: #79c0ff;
}

#filters:empty {
  display: none !important;
}

#filters:not(:empty) {
  display: flex !important;
}

.filter-chip {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background-color: var(--color-surface-2);
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.dark-theme .filter-chip {
  background-color: var(--color-surface-2);
  color: #ffffff;
}

.filter-chip:hover {
  transform: translateY(-1px);
  border-color: rgba(47, 129, 247, 0.28);
  box-shadow: none;
}

.filter-chip.active,
.dark-theme .filter-chip.active {
  border-color: rgba(47, 129, 247, 0.42);
  background-color: rgba(47, 129, 247, 0.18);
  color: var(--color-accent);
}

#link-container {
  display: grid;
  gap: 20px;
  width: 100%;
  max-width: none;
}

#link-container:not(:empty) {
  display: grid !important;
}

.category-section {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 20px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  box-shadow: var(--shadow-soft);
}

.category-title,
body:not(.dark-theme) .category-title {
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--color-border);
  color: #ffffff;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
}

.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  width: 100%;
}

.link-button,
.dark-theme .link-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 78px;
  min-width: 0;
  padding: 14px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: rgba(110, 118, 129, 0.08);
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
  transition: transform 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.link-button:hover,
.link-button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(47, 129, 247, 0.32);
  background-color: rgba(47, 129, 247, 0.1);
  box-shadow: none;
  outline: none;
}

.search-container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.search-container .input-wrapper {
  max-width: none;
  margin: 0;
}

.input-wrapper,
.dark-theme .input-wrapper {
  position: relative;
  display: flex;
  align-items: stretch;
  width: 100%;
  min-height: 52px;
  overflow: visible;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-bg);
  box-shadow: none;
}

#search-input {
  min-width: 0;
  flex: 1 1 auto;
  order: 2;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: #ffffff;
  outline: none;
}

#search-input::placeholder {
  color: rgba(255, 255, 255, 0.58);
}

#toggle-search,
#search-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 0;
  color: #ffffff;
  font-weight: 800;
  line-height: 1;
  transition: filter 0.15s ease, background-color 0.15s ease;
}

#toggle-search {
  order: 1;
  min-width: 94px;
  padding: 0 14px;
  border-right: 1px solid var(--color-border);
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background-color: var(--color-surface-2);
}

#search-btn {
  order: 3;
  min-width: 64px;
  padding: 0 18px;
  border-left: 1px solid var(--color-border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background-color: rgba(47, 129, 247, 0.14);
  color: #79c0ff;
}

#toggle-search:hover,
#search-btn:hover {
  filter: brightness(1.04);
}

#search-suggestions,
.dark-theme #search-suggestions {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 1000;
  width: 100%;
  max-height: min(360px, 55vh);
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  list-style: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.suggestion-item {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background-color: transparent;
  color: #ffffff;
  font-size: 14px;
  line-height: 1.25;
  cursor: pointer;
  overflow-wrap: anywhere;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.suggestion-item:hover {
  background-color: rgba(47, 129, 247, 0.16);
  color: var(--color-accent);
}

.hidden {
  display: none !important;
}

@media (max-width: 720px) {
  body {
    padding: 12px;
  }

  header {
    margin-bottom: 14px;
    padding: 12px;
  }

  #logo {
    font-size: 20px;
  }

  main,
  main.search-mode {
    gap: 14px;
  }

  #filters,
  .category-section,
  .search-container {
    padding: 14px;
  }

  .links-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

@media (max-width: 520px) {
  .input-wrapper,
  .dark-theme .input-wrapper {
    display: grid;
    grid-template-columns: 1fr auto;
    overflow: visible;
  }

  #toggle-search {
    grid-column: 1 / -1;
    min-height: 44px;
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  }

  #search-input {
    min-height: 48px;
  }

  #search-btn {
    min-height: 48px;
    border-radius: 0 0 var(--radius-sm) 0;
  }
}

@media (max-width: 420px) {
  .links-grid {
    grid-template-columns: 1fr;
  }
}
