:root {
  color-scheme: light;
  --bg: #fefbf7;
  --bg-2: #f7f6fb;
  --panel-bg: #ffffffd9;
  --panel-shadow: 0 10px 40px rgba(26, 37, 60, 0.08);
  --border: #e7e4ef;
  --accent: #ff7d6e;
  --accent-muted: #ffe6e1;
  --text: #1f2230;
  --muted: #6f7486;
  --chip-bg: #f3f1fb;
  --danger: #d33f49;
  --title-font: "Mea Culpa", cursive;
  --body-font: "Quicksand", "Helvetica Neue", Arial, sans-serif;

  font-size: 15px;
  font-family: var(--body-font);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: clamp(1.25rem, 3vw, 2rem);
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text);
  overflow-x: hidden;
}

main {
  width: min(100%, 1360px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  width: min(100%, 1360px);
  margin: 0 auto;
}

.page-header {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: end;
  gap: 0.5rem 1rem;
  margin: 0 auto 0.5rem auto;
  grid-column: 1 / -1;
}

.branding.wide {
  grid-column: 1 / 2;
  grid-row: 1 / span 2;
}

.page-header .favorite-nav {
  grid-row: 2;
  justify-self: end;
  align-self: end;
}

@media (max-width: 720px) {
  .page-header {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    align-items: flex-start;
  }
  .branding.wide {
    grid-row: 1;
  }
  .page-header .favorite-nav {
    grid-row: 2;
    justify-self: flex-start;
    align-self: flex-start;
    margin-top: 0.35rem;
  }

  .detail-row.chart-row .detail-content {
    width: 100%;
  }
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.75rem;
  color: var(--accent);
  margin: 0;
}

.hero-title {
  margin: 0.2rem 0;
  font-size: clamp(2.4rem, 5vw, 3.6rem);
  font-weight: 400;
  font-family: var(--title-font);
  letter-spacing: -0.02em;
  padding-left: 0.5rem;
}

.hero-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  max-width: 72ch;
}

.ad-slot {
  border: 1px dashed var(--border);
  border-radius: 1rem;
  padding: 1rem;
  text-align: center;
  color: var(--muted);
  background: #fff;
  font-weight: 600;
}
.ad-slot[hidden],
.affiliate-link[hidden] {
  display: none !important;
}

.ad-inline,
.ad-inline-top {
  margin: 0.5rem 0;
}

.detail-ad {
  margin: 0.25rem 0.35rem;
  font-size: 0.95rem;
}

.ad-rail {
  display: none;
}

/* right rail ad placement */
.ad-rail-slot {
  min-width: 220px;
  height: 420px;
}

.ad-rail-scroll {
  position: sticky;
  top: 1.5rem;
}

.content-block {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: clamp(1rem, 2vw, 1.25rem);
  box-shadow: var(--panel-shadow);
}

.content-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-top: 0.75rem;
}

.content-card {
  background: #fff;
  border-radius: 0.9rem;
  border: 1px solid var(--border);
  padding: 0.85rem;
  box-shadow: 0 8px 20px rgba(26, 37, 60, 0.04);
}

.content-card h3 {
  margin: 0 0 0.35rem 0;
}

.content-card p {
  margin: 0 0 0.5rem 0;
}

.content-block a:not(.article-card):not(.link-button) {
  color: var(--accent);
  text-decoration: underline;
  font-weight: 600;
}

.content-block a:not(.article-card):not(.link-button):hover {
  color: var(--text);
}

.strip-controls {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

#articles-strip-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  box-shadow: 0 6px 18px rgba(29, 34, 50, 0.06);
  width: 100%;
  max-width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

#articles-strip-panel summary {
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  position: relative;
  padding-right: 3.5rem;
}

#articles-strip-panel .strip-controls {
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  gap: 0.35rem;
}

#articles-strip-panel[open] .strip-controls {
  display: inline-flex;
}

#articles-strip-panel .strip-body {
  display: none;
  margin-top: 0.75rem;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  max-width: 100vw;
}

#articles-strip-panel[open] .strip-body {
  display: block;
}

.filter-like {
  margin-top: 0.5rem;
  background: #fff;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  box-shadow: 0 6px 18px rgba(29, 34, 50, 0.06);
}

.filter-like summary {
  list-style: revert;
  font-weight: 600;
  cursor: pointer;
  font-size: 1rem;
  padding: 0;
}

.filter-like .collapsible-body {
  margin-top: 0.5rem;
}

.article-strip {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.75rem;
  padding: 0.25rem 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.article-strip::-webkit-scrollbar {
  display: none;
}

.article-card {
  display: grid;
  grid-template-areas:
    "title"
    "lead"
    "hint"
    "cta";
  grid-auto-rows: minmax(0, auto);
  row-gap: 0.6rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 0.65rem 0.8rem 0.9rem;
  box-shadow: 0 6px 18px rgba(26, 37, 60, 0.04);
  text-decoration: none;
  color: var(--text);
  flex: 0 0 clamp(260px, 90vw, 340px);
  width: clamp(260px, 90vw, 340px);
  min-width: 240px;
}

@media (max-width: 640px) {
  .article-strip {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(260px, 100%);
    width: 100%;
    max-width: 100vw;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.25rem 0;
    scroll-snap-type: x mandatory;
  }

  .article-card {
    padding: 0.75rem;
    width: 100%;
    max-width: 100%;
    min-width: 260px;
    flex: 0 0 auto;
    scroll-snap-align: start;
  }
}

.article-card h3 {
  grid-area: title;
  margin: 0 0 0.2rem 0;
  font-size: 1.05rem;
}

.article-card p:first-of-type {
  grid-area: lead;
  min-height: 0;
}

.article-card p {
  margin: 0.1rem 0 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.article-card p.hint {
  grid-area: hint;
  min-height: 0;
}

.article-card .article-cta {
  grid-area: cta;
  margin-top: 0.4rem;
  width: 100%;
  text-align: center;
  align-self: end;
}

.article-card:hover {
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(26, 37, 60, 0.08);
}

#results {
  scroll-margin-top: 0;
}

.tag-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted);
}

.faq-list {
  margin: 0.75rem 0 0 0;
  padding: 0;
}

.faq-item {
  border-top: 1px solid var(--border);
  padding: 0.75rem 0;
}

.faq-item:first-of-type {
  border-top: none;
  padding-top: 0;
}

.faq-item dt {
  font-weight: 700;
}

.faq-item dd {
  margin: 0.25rem 0 0 0;
  color: var(--muted);
}

.collapsible {
  cursor: pointer;
}

.collapsible summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0;
}

.collapsible summary::-webkit-details-marker {
  display: none;
}

.collapsible .collapse-indicator {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--muted);
}

.collapsible[open] .collapse-indicator {
  transform: rotate(45deg);
}

.collapsible .collapsible-body {
  margin-top: 0.75rem;
}

.favorite-nav {
  align-self: center;
  text-decoration: none;
  padding: 0.65rem 0.9rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 700;
}

/* legacy min-height override removed to keep consistent fixed height */

.favorite-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}


.filters,
.results {
  background: var(--panel-bg);
  border-radius: 1rem;
  padding: clamp(1.25rem, 3vw, 1.75rem);
  border: 1px solid var(--border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(8px);
}

.filters details {
  margin-bottom: 1rem;
  background: #fff;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  box-shadow: 0 6px 18px rgba(29, 34, 50, 0.06);
}

.filters summary {
  font-weight: 600;
  cursor: pointer;
}

.filter-section-title {
  font-weight: 700;
  margin: 0.35rem 0 0.1rem;
}

#filters-title {
  margin-top: 0;
}

.filter-block {
  background: white;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  padding: 1rem;
  margin-bottom: 1rem;
}

.block-grid {
  display: grid;
  gap: 1rem;
}

.letter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
  padding-left: 0.75rem;
}

.range-grid {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
  padding-left: 0.75rem;
}

.range-field {
  background: white;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.dual-slider {
  width: 100%;
  padding: 0.3rem 0;
}

.number-range {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  border: none;
  padding-left: 0.75rem;
}

.number-range label {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
  padding-left: 0.35rem;
}

.number-range input[type="text"] {
  padding-right: 0.75rem;
}

.dual-slider .noUi-target {
  border: none;
  box-shadow: none;
  height: 8px;
  background: #dfe3f4;
  border-radius: 999px;
}

.dual-slider .noUi-connects {
  border-radius: 999px;
}

.dual-slider .noUi-connect {
  background: var(--accent);
}

.dual-slider .noUi-handle {
  width: 18px;
  height: 18px;
  top: -5px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

.dual-slider .noUi-handle::before,
.dual-slider .noUi-handle::after {
  display: none;
}

.dual-slider .noUi-tooltip {
  font-size: 0.9rem;
  background: #1f2337;
  color: #fff;
  border: none;
  border-radius: 0.3rem;
  padding: 0.2rem 0.4rem;
  transform: translate(-50%, -120%);
}

.range-header {
  display: flex;
  justify-content: space-between;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text);
}

.range-value {
  color: var(--muted);
  font-size: 0.9rem;
}

.range-header span,
.letter-grid label {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}


@media (min-width: 720px) {
  .block-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  body {
    padding: 1rem 0.75rem;
  }
  .filters,
  .results {
    padding: 1.25rem;
  }
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem;
}

.gender-field {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-start;
  justify-content: flex-start;
  width: 100%;
}

.gender-field label {
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
  margin: 0;
}

.gender-field input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

legend {
  padding: 0 0.25rem;
  font-weight: 600;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-weight: 600;
  color: var(--text);
}

.sort-label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

label input[type="text"],
select,
input,
button {
  font: inherit;
}

input[type="text"],
select {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.4rem 0.65rem;
  background: #fff;
  color: var(--text);
  min-height: 35.19px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%235b5f74' stroke-width='1.5' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 0.7rem;
  padding-right: 1.8rem;
}

input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
  color: var(--muted);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.9;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.hint .hint-extra {
  display: block;
  margin-top: 0.15rem;
}

.hint .hint-extra[hidden] {
  display: none;
}

button {
  cursor: pointer;
  border-radius: 999px;
  border: none;
  padding: 0.5rem 1rem;
  transition: transform 0.1s ease;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 8px 22px rgba(255, 125, 110, 0.22);
}

button.secondary {
  background: #f3f5f9;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 6px 14px rgba(26, 37, 60, 0.08);
}

button.secondary:hover {
  background: #e7ebf3;
}

button.article-cta {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 22px rgba(255, 125, 110, 0.2);
  border: 1px solid transparent;
}

button.article-cta:hover {
  background: #ff8f7a;
}

button.ghost {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text);
}

button.small {
  padding: 0.45rem 0.9rem;
}

button.link-button {
  background: none;
  border: none;
  padding: 0;
  border-radius: 0;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: underline;
}

a.link-button {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: underline;
}

a.link-button:hover {
  color: var(--text);
}

button:not(:disabled):hover {
  transform: translateY(-1px);
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-start;
  justify-content: space-between;
}

.filter-sources {
  flex: 1 1 240px;
}

.filter-sources .hint {
  margin: 0;
  font-size: 0.9rem;
  color: #555;
}

.filter-sources a {
  color: inherit;
  text-decoration: underline;
}

.results-ordering {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  justify-content: flex-end;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.filter-row:last-child {
  border-bottom: none;
}

.filter-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem 1rem;
  padding-left: 0.75rem;
}

@media (min-width: 900px) {
  .filter-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1200px) {
  .filter-columns {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.filter-row select {
  flex: 1 1 210px;
  min-width: 190px;
  max-width: 100%;
  min-height: 35.19px;
  height: 35.19px;
  line-height: 1.25;
  padding: 0.3rem 0.55rem;
}

.filter-row .grade-select {
  flex: 0 0 130px;
  min-width: 130px;
}

.filter-row .ghost {
  margin-left: auto;
}

.tri-toggle {
  min-width: 36px;
  padding: 0.35rem 0.5rem;
  font-weight: 700;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.tri-toggle[data-state="include"] {
  color: var(--accent);
  border-color: var(--accent-muted);
}

.tri-toggle[data-state="exclude"] {
  color: var(--danger);
  border-color: #f3c4c8;
}

.tri-toggle[data-state="none"] {
  color: var(--muted);
  opacity: 0.8;
}

.filter-label-text {
  font-size: 0.9rem;
  color: var(--text);
}

.tri-legend {
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
  padding-left: 0.75rem;
}

.popularity-grid {
  display: grid;
  gap: 0.5rem;
  padding-left: 0.75rem;
}

.popularity-row {
  display: grid;
  grid-template-columns: minmax(150px, 230px) minmax(150px, 200px) min-content;
  column-gap: 0.25rem;
  align-items: center;
}

.popularity-row .tri-toggle {
  width: 36px;
  height: 36px;
  padding: 0.35rem 0.55rem;
  justify-self: start;
  margin-left: 0.15rem;
}

.popularity-row select {
  min-width: 140px;
  max-width: 180px;
}

.popularity-row-desc {
  margin-top: -0.2rem;
  padding-left: 0.75rem;
}

#popularity-filter-panel .range-field {
  background: transparent;
  border: none;
  box-shadow: none;
  padding-left: 0.75rem;
  margin-top: 1rem;
}

.range-field {
  border: none;
  box-shadow: none;
}


.filter-desc {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  padding-left: 0.1rem;
}

.surname-field {
  min-height: 100%;
}

.surname-analysis {
  min-height: 2.2rem;
  margin-top: 0.35rem;
  line-height: 1.45;
  font-size: 0.95rem;
  color: var(--text);
}

.surname-analysis .surname-usage {
  display: block;
  font-weight: 600;
  margin-bottom: 0.15rem;
  color: var(--muted);
}

.pronunciation-values {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.35rem 1rem;
  width: 100%;
}

.results-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.filter-summary {
  font-size: 0.95rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  margin: 0.2rem 0.35rem 0 0;
  background: var(--chip-bg);
  border-radius: 999px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
}

.chip-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
  padding: 0 0.25rem;
}

.chip-remove:hover {
  color: var(--text);
}

.load-more-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
}


.name-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.filtered-note {
  margin: 0.25rem 0 0.5rem;
}

.filtered-divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0;
}

.filtered-line {
  width: 100%;
  height: 1px;
  background: var(--border);
}

.filtered-divider .filtered-line:last-of-type {
  margin-top: 0.1rem;
}

.filtered-toggle {
  border-radius: 0.5rem;
  padding: 0.22rem 0.5rem;
  font-size: 0.85rem;
  opacity: 0.8;
}

.filtered-expanded {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.filtered-chunk {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.filtered-status {
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.filtered-nav {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.filtered-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
}

.marked-remove {
  opacity: 0.6;
}

.marked-remove .favorite-btn {
  color: var(--muted);
}

.name-card {
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(29, 34, 50, 0.08);
}

.name-card.filtered-out {
  background: #fdf8f5;
  border-color: #f2ddd7;
  opacity: 0.9;
}

.name-card.filtered-out summary {
  color: var(--muted);
}

.name-card summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.85rem 1rem;
  cursor: pointer;
  font-weight: 600;
}

.favorite-btn {
  margin-left: auto;
  border: none;
  background: none;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  color: #d1c7ff;
}

.favorite-btn.active {
  color: var(--accent);
}

.favorite-btn:focus {
  outline: 2px solid var(--accent-muted);
  outline-offset: 2px;
}

.favorites-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.results-toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0 0 0.5rem 0;
}

.results-toolbar .surname-field {
  max-width: 480px;
  display: grid;
  gap: 0.35rem;
  margin: 0;
  align-self: center;
}

.results-toolbar .share-actions {
  flex: 0 0 auto;
  justify-content: flex-end;
  align-self: flex-start;
  align-items: center;
  margin-top: 1.6rem; /* kohdistetaan syötekentän riville */
}

@media (max-width: 720px) {
  .results-toolbar {
    grid-template-columns: 1fr;
  }
  .results-toolbar .share-actions {
    align-self: start;
    justify-content: flex-start;
  }
}

.favorites-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.favorites-options .results-ordering {
  justify-content: flex-start;
}

.share-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  align-self: flex-end;
}

.favorites-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.share-input {
  min-width: 220px;
  max-width: 320px;
}

.name-card-body {
  display: flex;
  flex-direction: column;
}

.summary-tags {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 0.75rem;
  row-gap: 0.35rem;
  margin-left: 0.75rem;
}

.tag-empty {
  visibility: hidden;
}

.name-card[open] summary {
  border-bottom: 1px solid var(--border);
}

.name-card summary::-webkit-details-marker {
  display: none;
}

.name-card .name-title {
  font-size: 1.2rem;
}

.tag {
  padding: 0.1rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--chip-bg);
  color: var(--muted);
  font-weight: 600;
}

.tag.reason {
  background: #ffe6df;
  color: #c44d3c;
  border: 1px solid #ffd1c5;
}

.tag.female {
  background: #ffe8ef;
  color: #d02568;
}

.tag.male {
  background: #e0f0ff;
  color: #005cb8;
}

.tag.unisex {
  background: #f4f0ff;
  color: #6c3ad8;
}

.tag-rank-male {
  background: #e0f0ff;
  color: #0b4f9c;
}

.tag-rank-female {
  background: #ffe2eb;
  color: #b83265;
}

.metric-grid {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

@media (min-width: 840px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.metric-block {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.75rem;
}

.metric-block.full-span {
  grid-column: 1 / -1;
}

.metric-block h4 {
  margin: 0 0 0.5rem;
}

.metrics-list,
.phonetic-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.25rem;
}

.metrics-list li,
.phonetic-list li {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chip {
  background: var(--chip-bg);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.85rem;
}

@media (max-width: 300px) {
  .results-ordering {
    width: 100%;
    justify-content: flex-start;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .results-ordering .sort-label {
    width: 100%;
  }

  .results-ordering select,
  .results-ordering button {
    width: 100%;
  }

  .results-ordering button {
    align-self: flex-end;
  }

  .filter-actions {
    justify-content: stretch;
  }

  .filter-actions .primary,
  .filter-actions button {
    width: 100%;
  }

  .results-bar {
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
  }

  .pagination-controls {
    width: 100%;
    justify-content: space-between;
  }

  .pagination-controls.bottom {
    margin-top: 1rem;
  }

  .summary-tags {
    margin-left: 0;
  }

  .name-card summary {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-row {
    flex-direction: column;
    align-items: stretch;
  }

  .letter-grid,
  .range-grid {
    grid-template-columns: 1fr;
  }
}

.details-section {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.detail-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

@media (max-width: 640px) {
  .detail-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .detail-label {
    width: auto;
    flex: 0 0 auto;
    min-width: 0;
  }
}

@media (min-width: 1200px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 280px;
    grid-auto-flow: row;
    align-items: start;
  }
  .layout > * {
    grid-column: 1 / 2;
  }
  .ad-rail {
    display: block;
    grid-column: 2;
  }
  .ad-rail-fixed {
    grid-row: 2;
    align-self: stretch;
  }
  .ad-rail-scroll {
    grid-row: 3;
    align-self: start;
  }
  .filters,
  .results,
  .content-block,
  .site-footer,
  .page-header {
    grid-column: 1 / 2;
  }
}

.name-card-body {
  width: 100%;
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-label {
  font-weight: 500;
  color: var(--text);
  width: 180px;
}

.detail-content {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start;
}

.chart-shell {
  width: 100%;
}

.pronunciation-values span {
  display: inline-block;
  min-width: auto;
  padding: 0.15rem 0;
  font-size: 0.95rem;
  line-height: 1.4;
}

@media (max-width: 300px) {
  .pronunciation-values {
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 0.2rem 0.75rem;
  }

  .pronunciation-values span {
    font-size: 0.95rem;
  }
}

.wiki-summary {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 0.95rem;
}

.wiki-summary strong {
  display: inline-block;
  margin-bottom: 0.2rem;
}

.charts-section {
  padding: 0 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.chart-block h4 {
  margin: 0 0 0.35rem;
}

.plotly-chart {
  width: 100%;
  height: 260px;
  touch-action: pan-y;
}

.history-legend {
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.history-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.history-legend span::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

.history-legend span[data-series="male"]::before {
  background: #0b57d0;
}

.history-legend span[data-series="female"]::before {
  background: #c2185b;
}

.history-link {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.history-chart {
  width: 100%;
  height: 240px;
  position: relative;
}

.history-chart svg {
  width: 100%;
  height: 100%;
}

.history-axis-title,
.history-y-label,
.history-x-label {
  font-size: 0.9rem;
  fill: var(--muted);
}

.history-point {
  opacity: 0.9;
}

.history-tooltip {
  position: absolute;
  background: rgba(17, 19, 33, 0.92);
  color: #fff;
  padding: 0.35rem 0.6rem;
  border-radius: 0.4rem;
  font-size: 0.85rem;
  pointer-events: none;
  transform: translate(-50%, -120%);
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transition: opacity 0.1s ease;
}

.history-tooltip.visible {
  opacity: 1;
}

.description {
  padding: 0 1rem 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.affiliate-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 0.9rem;
  border-radius: 0.75rem;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  margin: 0 1rem 1rem;
  font-weight: 700;
  box-shadow: 0 12px 30px rgba(58, 93, 217, 0.22);
  display: none;
}

.affiliate-link::after {
  content: "→";
  font-size: 0.95rem;
}

@media (max-width: 300px) {
  body {
    padding: 1rem;
  }

  .filter-row {
    flex-direction: column;
    align-items: stretch;
  }

  .results-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .filters input[type="text"],
  .filters select {
    font-size: 1rem;
  }

  .filter-row select,
  .filter-row .mode-select,
  .filter-row .group-mode-select,
  .filter-row .feature-select,
  .filter-row .grade-select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 35.19px;
    height: 35.19px;
    line-height: 1.2;
  }

  .filter-row .ghost {
    align-self: flex-end;
  }
}

body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 9, 20, 0.55);
  backdrop-filter: blur(1px);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(640px, calc(100% - 1.5rem));
  max-height: min(90vh, 720px);
  background: #fff;
  border-radius: 1.2rem;
  padding: clamp(1rem, 3vw, 1.5rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border: 1px solid var(--border);
  box-shadow: 0 35px 90px rgba(8, 12, 32, 0.22);
}

.story-panel {
  max-width: 520px;
}

.story-panel .story-text {
  font-size: 1rem;
  color: var(--text);
  line-height: 1.6;
  margin: 0;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
}

#surname-explain-modal .grid {
  max-height: 65vh;
  overflow-y: auto;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

#surname-explain-content .card {
  margin: 0;
}

button.icon-button {
  border-radius: 50%;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 1.3rem;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.weight-editor-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow-y: auto;
}

.weight-row-trait {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.weight-row {
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 0.75rem 0.9rem;
  background: #fdfdff;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.weight-row-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.weight-row-label {
  font-weight: 600;
  font-size: 1rem;
}

.weight-row-description {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.weight-row-input {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  color: var(--text);
}

.weight-row-input input {
  width: 4.5rem;
  text-align: right;
  font-weight: 600;
}

.weight-row-input input.invalid {
  border-color: var(--danger);
  color: var(--danger);
}

.weight-row-note {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

.weight-row-note strong {
  color: var(--accent);
}

.analysis-block {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.analysis-text,
.analysis-components {
  margin: 0;
  font-size: 0.9rem;
}

.analysis-components {
  color: var(--muted);
}

.weight-editor-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.weight-editor-status {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 220px;
}

.weight-editor-total {
  font-weight: 600;
}

.weight-editor-remaining {
  font-size: 0.85rem;
  color: var(--muted);
}

.weight-editor-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1em;
}

.weight-editor-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.weight-editor-actions-spacer {
  flex: 1 1 auto;
}

.ae-weight-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px 12px;
}
.ae-weight-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
}
.ae-weight-row input {
  width: 90px;
}
.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.table-wrap {
  overflow-x: auto;
}

.site-footer {
  width: min(100%, 1360px);
  margin: 0.5rem auto 0;
  padding: 1rem 0.5rem 0;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  font-size: 0.95rem;
}

.footer-links {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}

.footer-links a:hover {
  color: var(--text);
}

.card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--panel-shadow);
}

.card h2 {
  margin-top: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

@media (max-width: 640px) {
  .modal-panel {
    width: calc(100% - 1rem);
    max-height: 95vh;
  }

  .weight-row-input input {
    width: 3.5rem;
  }

  .weight-editor-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .weight-editor-actions-spacer {
    display: none;
  }
}
.modal-panel .hint {
  margin-top: 0;
}
.match-explain {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.match-score {
  font-weight: 700;
  font-size: 1.1rem;
}
.match-explain-list {
  margin: 0.5rem 0 0 1rem;
}
