/* ============================================================
   Бульбашляндия — основные стили
   ============================================================ */

:root {
  --bg: #f7f8fa;
  --bg-soft: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --fg: #14161a;
  --fg-muted: #4a5260;
  --fg-soft: #5a6270;
  --border: rgba(20, 22, 26, 0.08);
  --border-strong: rgba(20, 22, 26, 0.14);
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(20, 22, 26, 0.04);
  --shadow-md: 0 4px 16px rgba(20, 22, 26, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 22, 26, 0.12);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --blur: 16px;
  --header-h: 64px;
  --container: 1080px;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
}

html[data-theme="dark"] {
  --bg: #0d0f12;
  --bg-soft: #14171c;
  --surface: #171a20;
  --surface-2: #1e2229;
  --fg: #e8ebef;
  --fg-muted: #b8c0cc;
  --fg-soft: #97a0ae;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --accent: #5b8def;
  --accent-hover: #7aa5f4;
  --accent-soft: rgba(91, 141, 239, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color .2s ease, color .2s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent-hover); }

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

.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 20px;
}

/* Скрыто визуально, доступно скринридерам */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(var(--blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(180%);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  height: var(--header-h);
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--fg);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-decoration: none;
}
.logo:hover { color: var(--fg); }

/* Иконка сайта */
.logo::before {
  content: '';
  display: inline-block;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  background-image: url('/img/favicon/favicon.svg');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* Название сайта — из data-logo-text, локализованное через ERB */
.logo::after {
  content: attr(data-logo-text);
  color: inherit;
  font: inherit;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
}
.site-nav a {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  font-size: 15px;
  font-weight: 500;
  transition: background-color .15s, color .15s;
}
.site-nav a:hover {
  background: var(--surface-2);
  color: var(--fg);
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Кнопка-иконка */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
  cursor: pointer;
  transition: background-color .15s, color .15s, border-color .15s;
  font: inherit;
  text-decoration: none;
}
.btn-icon:hover {
  background: var(--surface-2);
  color: var(--fg);
  border-color: var(--border-strong);
}

/* ---------- Switcher (язык / тема) ---------- */

.switcher { position: relative; }

.switcher-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px) scale(0.98);
  transform-origin: top right;
  transition: opacity .15s ease, transform .15s ease, visibility .15s;
  z-index: 200;
}

.switcher[data-open="true"] > .switcher-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.switcher-menu a,
.switcher-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background-color .12s;
}
.switcher-menu a:hover,
.switcher-menu button:hover {
  background: var(--surface-2);
  color: var(--fg);
}
.switcher-menu .is-active > a,
.switcher-menu .is-active > .lang-name {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Языковой дропдаун (исправленный) ---------- */

.lang-switcher .switcher-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* Иконка глобуса */
.lang-switcher .switcher-toggle::before {
  content: '';
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cpath d='M2 12h20' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cpath d='M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z' fill='none' stroke='%23000' stroke-width='2'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cpath d='M2 12h20' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cpath d='M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z' fill='none' stroke='%23000' stroke-width='2'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

/* Код языка рядом с глобусом */
.lang-switcher .switcher-toggle::after {
  content: attr(data-lang-code);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: currentColor;
}

/* Увеличиваем минимальную ширину меню, чтобы текст не сжимался */
.switcher-menu {
  min-width: 260px;
}

/* Строка языка */
.lang-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 0;
}

.lang-name {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 14px;
  text-decoration: none;
  transition: background-color .12s;
  white-space: nowrap; /* Жестко запрещаем ломать слова */
}

.lang-name:hover {
  background: var(--surface-2);
  color: var(--fg);
}

.lang-flag {
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.lang-text {
  color: inherit;
  font: inherit;
}

.lang-item.is-active .lang-text {
  color: var(--accent);
  font-weight: 600;
}

/* Переключатель скриптов (К/Ł и 简/繁) */
.script-switch {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  flex-shrink: 0;
  margin-right: 4px;
}

.script {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--fg-muted);
  text-decoration: none;
  transition: background-color .12s, color .12s;
}

.script:hover { 
  color: var(--fg); 
}

.script::before {
  content: attr(data-script);
  font: inherit;
  color: inherit;
}

.script.is-active {
  background: var(--accent);
  color: #fff;
}

/* ---------- Основная область ---------- */

.site-main {
  flex: 1;
  padding: 40px 0 60px;
}

.page-header {
  margin-bottom: 32px;
}
.page-header h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--fg);
}
.page-header .lead {
  margin: 0;
  font-size: 17px;
  color: var(--fg-muted);
  max-width: 60ch;
}

/* Hero на главной */
.hero {
  padding: 32px 0 40px;
  text-align: center;
}
.hero h1 {
  margin: 0 0 12px;
  font-size: clamp(32px, 5vw, 52px);
  line-height: 1.15;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--fg) 0%, var(--fg-muted) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--fg);
}
.hero p {
  margin: 0 auto;
  max-width: 60ch;
  font-size: 17px;
  color: var(--fg-muted);
}

/* Заголовки разделов */
.section-title {
  margin: 40px 0 16px;
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.cities-section { margin-top: 8px; }
.articles-section { margin-top: 16px; }

/* ---------- Сетка карточек ---------- */

.cities-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.card {
  display: block;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
  color: var(--fg);
}
.card h3 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.01em;
}
.card .region {
  margin: 0;
  font-size: 14px;
  color: var(--fg-muted);
}
.card .excerpt {
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--fg-muted);
  line-height: 1.5;
}

/* ---------- Страница города ---------- */

.city-page { max-width: 720px; }

.breadcrumbs {
  margin-bottom: 24px;
  font-size: 13px;
  color: var(--fg-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.breadcrumbs a { color: var(--fg-muted); }
.breadcrumbs a:hover { color: var(--accent); }
.breadcrumbs span[aria-current] { color: var(--fg); }

.city-facts {
  margin: 32px 0;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.city-facts h2 {
  margin: 0 0 16px;
  font-size: 18px;
}
.city-facts dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 24px;
  margin: 0;
}
.city-facts dt {
  color: var(--fg-muted);
  font-size: 14px;
}
.city-facts dd {
  margin: 0;
  font-weight: 500;
  font-size: 14px;
}

.back a { color: var(--fg-muted); font-size: 14px; }
.back a:hover { color: var(--accent); }

/* ---------- Форма поиска ---------- */

.cities-search {
  display: flex;
  gap: 8px;
  margin: 24px 0;
  max-width: 480px;
}
.cities-search input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 15px;
}
.cities-search input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.cities-search button {
  padding: 10px 18px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color .15s;
}
.cities-search button:hover { background: var(--accent-hover); }

.empty {
  padding: 40px 0;
  text-align: center;
  color: var(--fg-muted);
}

/* ---------- Подвал ---------- */

.site-footer {
  padding: 32px 0;
  border-top: 1px solid var(--border);
  margin-top: auto;
  background: var(--bg-soft);
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 14px;
  color: var(--fg-muted);
}
.footer-inner p { margin: 0; }
.footer-note { color: var(--fg-muted); }

.footer-feeds {
  display: inline-flex;
  gap: 8px;
}
.feed-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--fg-muted);
  border: 1px solid var(--border);
  transition: color .15s, background-color .15s, border-color .15s;
}
.feed-link:hover {
  color: var(--fg);
  background: var(--surface-2);
  border-color: var(--border-strong);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}
.btn-secondary {
  background: transparent;
  color: var(--fg);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  background: var(--surface-2);
  color: var(--fg);
  border-color: var(--border-strong);
}

/* ---------- Страница ошибки ---------- */

.error-page {
  padding: 60px 0 80px;
  text-align: center;
  max-width: 640px;
  margin: 0 auto;
}

.error-code {
  font-size: clamp(96px, 20vw, 160px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--accent) 0%, var(--fg-muted) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--fg);
  margin-bottom: 8px;
  user-select: none;
}

.error-title {
  margin: 0 0 12px;
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.error-text {
  margin: 0 auto 32px;
  font-size: 16px;
  color: var(--fg-muted);
  max-width: 48ch;
}

.error-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- Адаптив ---------- */

@media (max-width: 720px) {
  .header-inner { gap: 12px; }
  .logo::after {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
  .site-nav { margin-left: 0; }
  .site-nav a { padding: 8px 10px; font-size: 14px; }
  .btn-icon { width: 36px; height: 36px; }
  .site-main { padding: 24px 0 40px; }
  .switcher-menu { min-width: 180px; right: auto; left: 0; transform-origin: top left; }
  .hero { padding: 16px 0 24px; }
}

@media (max-width: 480px) {
  .container { padding: 0 14px; }
  .header-actions { gap: 4px; }
  .cities-grid { grid-template-columns: 1fr; }
  .error-page { padding: 40px 0 60px; }
  .error-actions { flex-direction: column; }
  .error-actions .btn { width: 100%; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
  html { scroll-behavior: auto; }
}