/* Shared corrections, loaded after each page's topic-specific styles. */
:root { --focus-ring: #ffe08c; }
body.light { --focus-ring: #754200; }

/* Keep links underline-free in every interaction state. */
a, a:visited, a:hover, a:focus, a:active {
  text-decoration: none;
}

/* Theme/swatch changes must never reduce primary-action contrast. */
.generate-button,
.generate-btn {
  background: #9e2029;
  color: #fff;
  font-weight: 800;
  min-width: 0;
  min-height: 52px;
  padding: 12px 18px;
}
button:not(.swatch), .nav-menu > summary, .advanced > summary {
  min-height: 44px;
}
button:focus-visible, a:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}
.swatch[aria-pressed="true"] {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.header-actions, .head-actions { margin-left: auto; flex-shrink: 0; }
.header-inner, .bar { position: relative; }
.hero-start {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-block: 16px;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  font-weight: 650;
  text-decoration: none;
}
.hero-start:hover { color: var(--text); border-color: var(--gold); }
.hero h1, .profile-item, .profile-grid > div { overflow-wrap: anywhere; }
.field, .content, .hero-grid > *, .footer-grid > *, .footer-inner > * {
  min-width: 0;
}
select, input, textarea { max-width: 100%; }
.field select, .field input, .field textarea { min-height: 44px; }
.toast {
  width: max-content;
  max-width: calc(100% - 28px);
  overflow-wrap: anywhere;
  text-align: center;
}
body.light footer { background: #eee8dc; color: var(--text); }
.nav-menu > summary { display: flex; align-items: center; }
.nav-dropdown { top: 100%; }
.nav-dropdown a { display: flex; align-items: center; min-height: 44px; }
.advanced > summary { padding-block: 8px; }

@media (max-width: 950px) {
  /* Position below the actual header height, not a per-page pixel guess. */
  .main-nav.open, .main-nav.mobile-open { top: 100%; }
  .main-nav.open .nav-dropdown,
  .main-nav.mobile-open .nav-dropdown {
    position: static;
    width: 100%;
    max-width: none;
    margin-top: 8px;
    grid-template-columns: 1fr;
    box-shadow: none;
  }
  .main-nav.open, .main-nav.mobile-open {
    max-height: calc(100dvh - 80px);
    overflow-y: auto;
    align-items: start;
  }
}

@media (max-width: 620px) {
  .bar { flex-wrap: wrap; padding-block: 10px; gap: 10px; }
  .bar .nav { flex: 1 1 100%; justify-content: flex-start; flex-wrap: wrap; }
  /* 16px prevents iOS from zooming the page when a field receives focus. */
  .field input, .field select, .field textarea, .quick select { font-size: 16px; }
  .generator-actions, .actions { align-items: stretch; }
  .generator-actions .generate-button, .actions .generate-btn { flex-basis: 100%; }
  .results-head { flex-wrap: wrap; align-items: flex-start; }
  .results-head > div { display: flex; gap: 6px; flex-wrap: wrap; }
  .meaning-table, .table { table-layout: fixed; overflow-wrap: anywhere; }
  .meaning-table td:first-child { white-space: normal; }
  .meaning-table td, .meaning-table th, .table td, .table th { padding: 8px 6px; }
  .profile-grid { grid-template-columns: 1fr; }
  .dialog-actions { flex-wrap: wrap; }
  .nav-dropdown { max-width: calc(100vw - 36px); }
  .swatch { font-size: 11px; }
}

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

@media print {
  .hero-start { display: none; }
}

/* Utility-page header: logo left, theme and hamburger right. */
.utility-header .bar { display: flex; align-items: center; gap: 12px; min-height: 68px; }
.utility-header .brand { margin-right: auto; min-width: 0; }
.utility-header .nav { display: flex; align-items: center; gap: 16px; }
.utility-header .nav a { color: var(--text); padding-block: 10px; }
.utility-header #theme { flex-shrink: 0; }
.utility-menu {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 22px;
  cursor: pointer;
}
@media (max-width: 950px) {
  .utility-header .bar { flex-wrap: nowrap; padding-block: 8px; gap: 8px; }
  .utility-header .nav { display: none; }
  .utility-header .utility-menu { display: inline-flex; flex-shrink: 0; order: 4; }
  .utility-header #theme { order: 3; margin-left: 0; }
  .utility-header .nav.open {
    position: absolute;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    top: 100%;
    left: 0;
    right: 0;
    padding: 12px;
    gap: 6px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 0 0 8px 8px;
    max-height: calc(100dvh - 90px);
    overflow-y: auto;
    box-shadow: 0 12px 24px #0003;
  }
  .utility-header .nav a { display: block; padding: 10px; border-radius: 5px; }
  .utility-header .nav a:hover { background: var(--panel2, var(--panel-2)); }
  .header-actions, .head-actions { margin-left: auto; }
  #mobile-menu { order: 2; }
}

/* Shared cross-page navigation, including the utility-page category menu. */
.utility-header .nav-menu { position: relative; }
.utility-header .nav-menu > summary {
  cursor: pointer;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
  list-style: none;
}
.utility-header .nav-menu > summary::after { content: '⌄'; color: var(--gold); }
.utility-header .nav-menu > summary::-webkit-details-marker { display: none; }
.utility-header .nav-dropdown {
  position: absolute;
  right: 0;
  width: 235px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 12px 24px #0003;
}
.utility-header .nav-dropdown a { padding: 8px; font-size: 13px; }
.utility-header a[aria-current="page"] { color: var(--gold); font-weight: 700; }
.site-info-menu .nav-dropdown { grid-template-columns: 1fr; width: 180px; }
@media (max-width: 950px) {
  .utility-header .nav.open .nav-dropdown {
    position: static;
    width: 100%;
    max-width: none;
    grid-template-columns: 1fr;
    box-shadow: none;
  }
}

/* Transparent, theme-appropriate wordmarks in both header and footer. */
.brand .logo-dark, .brand .logo-light {
  width: clamp(145px, 22vw, 200px);
  max-width: 100%;
  height: auto;
}
.brand .logo-dark { display: block; }
.brand .logo-light { display: none; }
body.light .brand .logo-dark { display: none; }
body.light .brand .logo-light { display: block; }
.footer-brand { display: inline-flex; margin: 0 0 16px; }
.footer-brand .logo-dark, .footer-brand .logo-light { width: 220px; }

/* Override page-specific link hover rules without hiding keyboard focus. */
html body a:any-link,
html body a:any-link:hover,
html body a:any-link:focus,
html body a:any-link:active {
  text-decoration: none !important;
}

/* Apply light surfaces to utility headers, including the 404 header. */
body.light .utility-header { background: #f7f3ebf5; color: var(--text); }
body.light .utility-header .nav,
body.light .utility-header .nav-dropdown { background: var(--panel); }
body.light .utility-header .nav a,
body.light .utility-header .nav-menu > summary { color: var(--text); }
body.light .utility-header .nav a[aria-current="page"] { color: var(--gold); }

/* The hero link is a proper CTA, never an underlined text link. */
html body a.hero-start:any-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  margin: 16px 0 20px;
  border: 1px solid #b82b35;
  border-radius: 9px;
  background: #9e2029;
  color: #fff;
  font: 700 15px/1.4 system-ui, sans-serif;
  text-decoration: none !important;
  box-shadow: 0 4px 14px #0002;
  transition: background .18s, box-shadow .18s;
}
html body a.hero-start:any-link:hover { background: #841a22; box-shadow: 0 6px 18px #0003; }
html body a.hero-start:any-link:active { background: #70161d; }

@keyframes generationPageGlow {
  0%, 100% { opacity: 0; }
  35% { opacity: 1; }
}
body.generation-glow::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 35%, #ff9c4318 80%, #f5b94230);
  box-shadow: inset 0 0 90px #ff6a1a38;
  animation: generationPageGlow 1s ease-in-out both;
}
@media (prefers-reduced-motion: reduce) {
  body.generation-glow::after { display: none; }
}
@media print {
  body.generation-glow::after { display: none; }
}

/* One-second matching feedback before revealing the generated batch. */
.matching-loader[hidden] { display: none; }
.matching-loader {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #0b0a1070;
  backdrop-filter: blur(3px);
  pointer-events: none;
}
.matching-panel {
  width: min(100%, 410px);
  padding: 30px 24px;
  border: 1px solid var(--gold);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  text-align: center;
  box-shadow: 0 20px 70px #0005;
}
.matching-panel strong { display: block; font-size: 21px; line-height: 1.4; }
.matching-panel p { margin: 12px 0; color: var(--muted); font-size: 15px; }
.matching-panel small { color: var(--muted); font-size: 12px; }
.matching-spinner {
  display: block;
  width: 44px;
  height: 44px;
  margin: 0 auto 18px;
  border: 3px solid var(--line);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: matchingSpin .8s linear infinite;
}
.matching-status { flex-basis: 100%; margin: 10px 0; color: var(--muted); font-size: 14px; }
.matching-status:empty { display: none; }
body.matching-names #results, body.matching-names #result, body.matching-names #out { visibility: hidden; }
@keyframes matchingSpin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .matching-spinner { animation: none; }
  .matching-loader { backdrop-filter: none; }
}
@media print { .matching-loader, .matching-status { display: none; } }

/* Editorial content uses comfortable reading widths and scannable cards. */
.blog-article { max-width: 840px; }
.blog-article .section p { font-size: 17px; line-height: 1.85; }
.blog-article .toc { margin-top: 24px; padding: 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.blog-article .toc li { margin-block: 8px; }
.blog-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.blog-card { padding: 24px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.blog-card h2 { font-size: 1.4rem; }
.blog-card p { color: var(--muted); }
@media (max-width: 620px) { .blog-cards { grid-template-columns: 1fr; } .blog-card { padding: 18px; } }

/* Keep revealed names clear of sticky navigation when jumping to results. */
#results, #result, #out, .matching-status { scroll-margin-top: 100px; }
