:root {
  --ui-bg: #f7f8fa;
  --ui-surface: #ffffff;
  --ui-surface-muted: #f1f3f5;
  --ui-text: #191b20;
  --ui-text-muted: #68707d;
  --ui-border: #dfe3e8;
  --ui-accent: #168ad2;
  --ui-accent-strong: #0878bd;
  --ui-action-fill: #1677b8;
  --ui-focus: rgba(22, 138, 210, 0.28);
  --ui-radius: 8px;
  --ui-shadow: 0 12px 32px rgba(20, 25, 32, 0.08);
}

[data-theme="dark"],
body[data-theme="dark"] {
  --ui-bg: #18191d;
  --ui-surface: #24262b;
  --ui-surface-muted: #1d1f23;
  --ui-text: #f5f6f7;
  --ui-text-muted: #aeb4bd;
  --ui-border: #383b42;
  --ui-accent: #4aa7e4;
  --ui-accent-strong: #6ab6e8;
  --ui-action-fill: #1677b8;
  --ui-focus: rgba(74, 167, 228, 0.34);
  --ui-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
}

html {
  scroll-behavior: smooth;
}

body,
body * {
  letter-spacing: 0;
}

body {
  user-select: text;
  -webkit-user-select: text;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea,
[role="button"] {
  font: inherit;
}

button,
[role="button"],
label,
select,
summary {
  user-select: none;
  -webkit-user-select: none;
}

:where(a, button, input, select, textarea, summary):focus-visible {
  outline: 3px solid var(--ui-focus);
  outline-offset: 2px;
}

:where(button, input, select, textarea) {
  min-height: 44px;
}

.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;
}

.site-content {
  min-width: 0;
}

/* Homepage: compact search-first directory based on the selected visual target. */
.home-page .site-content > h1 {
  margin-top: 32px;
  margin-bottom: 6px;
  font-size: 2.35rem;
  line-height: 1.2;
}

.home-page .site-content > .subtitle {
  max-width: 58ch;
  margin: 0 auto 30px;
  color: var(--text-secondary, var(--ui-text-muted));
  font-size: 1rem;
  line-height: 1.55;
}

.resource-search {
  display: flex;
  align-items: center;
  min-height: 58px;
  overflow: hidden;
  border: 1px solid var(--border-color, var(--ui-border));
  border-radius: var(--ui-radius);
  background: var(--bg-secondary, var(--ui-surface));
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.resource-search:focus-within {
  border-color: var(--accent-color, var(--ui-accent));
  box-shadow: 0 0 0 3px var(--ui-focus);
}

.resource-search input {
  width: 100%;
  min-height: 56px;
  padding: 0 18px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-primary, var(--ui-text));
  font-size: 0.98rem;
}

.resource-search input::placeholder {
  color: var(--text-secondary, var(--ui-text-muted));
  opacity: 0.78;
}

.resource-search input::-webkit-search-cancel-button {
  display: none;
}

.resource-search-clear {
  flex: 0 0 auto;
  min-height: 44px;
  margin-right: 7px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--accent-color, var(--ui-accent));
  cursor: pointer;
}

.resource-search-clear:hover {
  background: color-mix(in srgb, var(--accent-color, var(--ui-accent)) 10%, transparent);
}

.resource-search-status {
  margin: 10px 2px 0;
  color: var(--text-secondary, var(--ui-text-muted));
  font-size: 0.86rem;
}

.home-page .category-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 20px;
  padding: 0;
}

.home-page .category-button {
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--border-color, var(--ui-border));
  border-radius: var(--ui-radius);
  background: var(--bg-secondary, var(--ui-surface));
  color: var(--text-primary, var(--ui-text));
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.25;
  white-space: normal;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}

.home-page .category-button:hover {
  transform: none;
  border-color: var(--accent-color, var(--ui-accent));
  background: var(--bg-secondary, var(--ui-surface));
  color: var(--accent-color, var(--ui-accent));
}

.home-page .category-button.active {
  border-color: var(--ui-action-fill);
  background: var(--ui-action-fill);
  color: #fff;
  box-shadow: none;
}

:is(
  .filter-option.active,
  .article-card-link,
  .pagination-button.active,
  .ai-insight-button,
  .bubblemap-page main .form-group > button,
  .bubblemap-page main .yes-btn,
  .gifts-page .map-btn.active,
  .gifts-page .drawing-tool-btn.active,
  .egm-card-link,
  .btn-primary
) {
  border-color: var(--ui-action-fill);
  background-color: var(--ui-action-fill);
  color: #fff;
}

.home-page .category-section {
  margin: 0;
}

.home-page .category-section > h2 {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.home-page.catalog-show-all .category-section {
  margin-bottom: 28px;
}

.home-page.catalog-show-all .category-section > h2 {
  position: static;
  width: auto;
  height: auto;
  margin: 0 0 10px;
  overflow: visible;
  clip: auto;
  white-space: normal;
  color: var(--text-primary, var(--ui-text));
  font-size: 1rem;
  line-height: 1.4;
}

.home-page .cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border-color, var(--ui-border));
  border-radius: var(--ui-radius);
  background: var(--bg-secondary, var(--ui-surface));
}

.home-page .card-link {
  position: relative;
  display: block;
  color: inherit;
  text-decoration: none;
  transition: background-color 160ms ease;
}

.home-page .card-link + .card-link {
  border-top: 1px solid var(--border-color, var(--ui-border));
}

.home-page .card-link:hover {
  transform: none;
  background: color-mix(in srgb, var(--accent-color, var(--ui-accent)) 8%, transparent);
}

.home-page .card-link[hidden] {
  display: none;
}

.home-page .card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 14px;
  align-content: center;
  min-height: 82px;
  height: auto;
  margin: 0;
  padding: 14px 18px;
  padding-inline-end: 56px;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  opacity: 1;
  transform: none;
  animation: none;
  transition: none;
}

.home-page .card-arrow {
  position: absolute;
  inset-inline-end: 18px;
  top: 50%;
  width: 18px;
  height: 18px;
  opacity: 0.75;
  pointer-events: none;
  transform: translateY(-50%);
}

[data-theme="dark"] .home-page .card-arrow {
  filter: invert(1);
}

.home-page .card:hover {
  transform: none;
  border-color: transparent;
  box-shadow: none;
}

.home-page .card-icon {
  grid-row: 1 / 3;
  align-self: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--border-color, var(--ui-border));
  border-radius: 8px;
  object-fit: cover;
}

.home-page .resource-icon {
  padding: 10px;
  background: color-mix(in srgb, var(--accent-color, var(--ui-accent)) 10%, var(--bg-primary, var(--ui-bg)));
  object-fit: contain;
  box-sizing: border-box;
  filter: brightness(0) saturate(100%) invert(43%) sepia(78%) saturate(1333%) hue-rotate(163deg) brightness(88%) contrast(101%);
}

.home-page .card-icon-ton4 {
  padding: 5px;
  background: var(--bg-primary, var(--ui-bg));
  object-fit: contain;
}

.home-page .card-title {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--text-primary, var(--ui-text));
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
}

.home-page .card-desc {
  grid-column: 1 / -1;
  display: block;
  margin-top: 3px;
  color: var(--text-secondary, var(--ui-text-muted));
  font-size: 0.84rem;
  line-height: 1.4;
}

.home-page .card-icon + .card-title,
.home-page .card-icon ~ .card-desc {
  grid-column: 2;
}

.home-page .emoji {
  display: none;
}

.home-page .category-section.is-empty {
  display: none;
}

.home-page .home-seo-section {
  margin: 64px 0 44px;
  padding: 28px 0 0;
  border: 0;
  border-top: 1px solid var(--border-color, var(--ui-border));
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.home-page .home-seo-grid article {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

/* Shared page rhythm. Navbar dimensions and the existing page widths stay untouched. */
.seo-page-header,
.articles-header {
  margin-bottom: 28px;
  text-align: center;
}

.seo-page-title,
.articles-title,
.page-title {
  margin-bottom: 8px;
  color: var(--text-primary, var(--ui-text));
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  line-height: 1.2;
}

.seo-page-subtitle,
.articles-description {
  max-width: 62ch;
  margin: 0 auto;
  color: var(--text-secondary, var(--ui-text-muted));
  font-size: 1rem;
  line-height: 1.6;
}

/* Functional surfaces use one restrained treatment. */
:where(
  .filters-container,
  .filter-section,
  .stats-block,
  .charts-container,
  .gifts-table-container,
  .map-container,
  .chart-container,
  .ai-insight-section,
  .progress-container,
  .info-block,
  .subscription-content,
  .article,
  .article-card
) {
  border-color: var(--border-color, var(--ui-border));
  border-radius: var(--ui-radius);
  box-shadow: none;
}

:where(
  .filters-container,
  .filter-section,
  .stats-block,
  .charts-container,
  .gifts-table-container,
  .ai-insight-section,
  .info-block
) {
  background: var(--bg-secondary, var(--ui-surface));
}

:where(
  .filter-input,
  .filter-select,
  .search-input,
  .date-input,
  .time-input,
  #address
) {
  border: 1px solid var(--border-color, var(--ui-border));
  border-radius: var(--ui-radius);
  background: var(--bg-primary, var(--ui-bg));
  color: var(--text-primary, var(--ui-text));
}

:where(
  .filter-input,
  .filter-select,
  .search-input,
  .date-input,
  .time-input,
  #address
)::placeholder {
  color: var(--text-secondary, var(--ui-text-muted));
  opacity: 0.8;
}

:where(
  .filter-option,
  .pagination-button,
  .map-btn,
  .chart-control-btn,
  .search-button,
  .filters-toggle,
  .reset-button,
  .toggle-info,
  .info-button,
  .info-modal-close
) {
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--ui-radius);
}

/* Search and editorial lists are easier to scan as rows than as card walls. */
.articles-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--border-color, var(--ui-border));
  border-radius: var(--ui-radius);
  background: var(--bg-secondary, var(--ui-surface));
}

.articles-grid .article-card {
  margin: 0;
  border: 0;
  border-bottom: 1px solid var(--border-color, var(--ui-border));
  border-radius: 0;
  background: transparent;
}

.articles-grid .article-card:last-child {
  border-bottom: 0;
}

.articles-grid .article-card:hover {
  transform: none;
  background: color-mix(in srgb, var(--accent-color, var(--ui-accent)) 7%, transparent);
  box-shadow: none;
}

.articles-grid .article-card-title {
  font-size: 1.05rem;
  line-height: 1.4;
}

.articles-grid .article-card-excerpt {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* Long SEO support stays visible to crawlers but reads as secondary material. */
:where(
  .home-seo-section,
  .articles-seo-section,
  .journal-seo-section,
  .agency-seo-section,
  .unlocks-seo-section,
  .seo-support
) {
  margin-top: 56px;
  padding: 32px 0 0;
  border: 0;
  border-top: 1px solid var(--border-color, var(--ui-border));
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

:where(
  .home-seo-grid article,
  .articles-seo-grid article,
  .journal-seo-grid article,
  .agency-seo-card,
  .unlocks-seo-grid article
) {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

:where(
  .home-seo-section,
  .articles-seo-section,
  .journal-seo-section,
  .agency-seo-section,
  .unlocks-seo-section,
  .seo-support
) p {
  max-width: 72ch;
  color: var(--text-secondary, var(--ui-text-muted));
  line-height: 1.7;
}

:where(
  .home-seo-links,
  .journal-seo-links,
  .agency-related-links,
  .unlocks-related-links,
  .seo-related-links
) a {
  min-height: 44px;
  border-radius: var(--ui-radius);
}

/* Data tools: information follows the task, not the other way around. */
.bubblemap-page .content-container {
  display: flex;
  flex-direction: column;
}

.bubblemap-page .seo-page-header {
  order: 0;
}

.bubblemap-page .warning-block {
  order: 1;
}

.bubblemap-page .form-group {
  order: 2;
}

.bubblemap-page .progress-container {
  order: 3;
}

.bubblemap-page #error-container {
  order: 4;
}

.bubblemap-page #result {
  order: 5;
}

.bubblemap-page #error-container:empty,
.bubblemap-page #result:empty {
  display: none;
  margin: 0;
}

.bubblemap-page .info-block {
  order: 6;
  margin-top: 0;
}

.bubblemap-page .subscription-modal {
  order: 7;
}

.gifts-page .stats-blocks {
  gap: 12px;
}

.gifts-page .stats-block,
.gifts-page .charts-container,
.gifts-page .gifts-table-container {
  margin-bottom: 20px;
}

.gifts-page .chart-container {
  overflow: hidden;
}

.unlocks-page .chart-hint {
  color: var(--text-secondary, var(--ui-text-muted));
  font-size: 0.875rem;
}

.agency-page .top-space {
  margin-top: 2rem;
}

.agency-page .filters-container {
  margin-bottom: 20px;
}

/* Product and editorial pages keep the existing reading width. */
.article-container {
  margin-inline: auto;
}

.article {
  overflow: visible;
}

.article-title {
  text-wrap: balance;
}

.article-content {
  line-height: 1.75;
}

.article-content :where(h2, h3) {
  text-wrap: balance;
}

.article-content h2 {
  margin-top: 2.5rem;
}

.article-content p,
.article-content li {
  color: var(--text-secondary, var(--ui-text-muted));
}

.service-biglink {
  border: 1px solid var(--border-color, var(--ui-border));
  border-radius: var(--ui-radius);
  background: var(--bg-secondary, var(--ui-surface)) !important;
  color: var(--text-primary, var(--ui-text)) !important;
  box-shadow: none;
}

.service-biglink:hover {
  background: color-mix(in srgb, var(--accent-color, var(--ui-accent)) 8%, var(--bg-secondary, var(--ui-surface))) !important;
}

.service-biglink :where(.service-biglink-title, .service-biglink-desc, .service-biglink-hint) {
  color: inherit !important;
}

.service-biglink-emoji {
  display: none;
}

.upscale-hero {
  border: 1px solid var(--border-color, var(--ui-border));
  border-radius: var(--ui-radius);
  background: var(--bg-secondary, var(--ui-surface)) !important;
  box-shadow: none;
}

.product-logo {
  display: block;
  width: 64px;
  height: 64px;
  margin-bottom: 18px;
  border: 1px solid var(--border-color, var(--ui-border));
  border-radius: 8px;
  object-fit: cover;
}

.upscale-clean-card,
.upscale-mode-card,
.resource-card,
.promo-metric,
.upscale-note-block {
  border-radius: var(--ui-radius);
  background: var(--bg-secondary, var(--ui-surface));
  box-shadow: none;
}

.product-logo-wordmark {
  width: 112px;
  height: 46px;
  padding: 4px 8px;
  border-radius: var(--ui-radius);
  background: #111317;
  object-fit: contain;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto;
    animation-duration: 0.01ms;
    animation-iteration-count: 1;
    transition-duration: 0.01ms;
  }
}

@media (max-width: 640px) {
  .home-page .site-content > h1 {
    margin-top: 22px;
    font-size: 1.85rem;
  }

  .home-page .site-content > .subtitle {
    margin-bottom: 22px;
    font-size: 0.9rem;
  }

  .resource-search {
    min-height: 54px;
  }

  .resource-search input {
    min-height: 52px;
    padding-inline: 14px;
    font-size: 0.9rem;
  }

  .home-page .category-buttons {
    display: flex;
    justify-content: flex-start;
    gap: 8px;
    margin-block: 14px 16px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .home-page .category-buttons::-webkit-scrollbar {
    display: none;
  }

  .home-page .category-button {
    flex: 0 0 auto;
    min-height: 44px;
    padding-inline: 14px;
    white-space: nowrap;
  }

  .home-page .card {
    min-height: 76px;
    padding: 12px 14px;
    padding-inline-end: 48px;
  }

  .home-page .card-arrow {
    inset-inline-end: 14px;
  }

  .home-page .card-icon {
    width: 44px;
    height: 44px;
  }

  :where(
    .home-seo-section,
    .articles-seo-section,
    .journal-seo-section,
    .agency-seo-section,
    .unlocks-seo-section,
    .seo-support
  ) {
    margin-top: 40px;
    padding-top: 24px;
  }

  .articles-grid .article-card-excerpt {
    -webkit-line-clamp: 3;
  }

  .article-content h2 {
    margin-top: 2rem;
  }
}
