:root {
  color-scheme: light dark;
  --background: #fff;
  --surface: #fff;
  --text: #202122;
  --muted: #54595d;
  --border: #a2a9b1;
  --border-light: #c8ccd1;
  --accent: #36c;
  --accent-hover: #2a4b8d;
  --accent-soft: #eaf3ff;
  --control-hover: #eaecf0;
  --shadow: 0 1px 2px rgb(0 0 0 / 8%);
  --menu-shadow: 0 2px 8px rgb(0 0 0 / 20%);
  --focus: 0 0 0 3px rgb(51 102 204 / 24%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--background);
  color: var(--text);
}

a { color: var(--accent); }
button, input { font: inherit; }
[hidden] { display: none !important; }

.portal {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 54px 24px 24px;
  flex: 1 0 auto;
}

.brand { text-align: center; }

.brand h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", "Noto Serif", "Noto Serif SC", serif;
  font-size: clamp(2.15rem, 5vw, 3rem);
  font-weight: 400;
  letter-spacing: -.025em;
  line-height: 1.05;
}

.brand__tagline {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: .875rem;
}

.language-stage {
  position: relative;
  width: min(100%, 760px);
  height: 350px;
  margin: 20px auto 4px;
}

.language-orbit { position: absolute; inset: 0; }

.emblem {
  position: absolute;
  left: 50%;
  top: 52%;
  z-index: 1;
  display: grid;
  width: 164px;
  height: 164px;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 1px solid color-mix(in srgb, var(--border-light) 72%, transparent);
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--surface) 98%, transparent) 0 67%, transparent 68%);
  box-shadow: inset 0 0 0 11px color-mix(in srgb, var(--surface) 82%, transparent);
  cursor: default;
  user-select: none;
}

.emblem img {
  display: block;
  width: 108px;
  height: 108px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
}

.language-card {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 198px;
  min-height: 72px;
  padding: 8px 10px;
  transform: translate(-50%, -50%);
  border-radius: 2px;
  color: var(--accent);
  text-decoration: none;
  transition: background-color .12s ease, color .12s ease;
}

.language-card[data-side="top"] { text-align: center; }
.language-card[data-side="left"] { text-align: right; }
.language-card[data-side="right"] { text-align: left; }

.language-card:hover { background: var(--accent-soft); }
.language-card:focus-visible { outline: none; box-shadow: var(--focus); }

.language-card__name {
  display: block;
  margin-bottom: 2px;
  font-size: 1rem;
  font-weight: 700;
}

.language-card__site-label {
  display: block;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.35;
}

.language-card__count {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.3;
}

.search {
  width: min(100%, 590px);
  margin: 0 auto;
}

.search__control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search__control:focus-within {
  border-color: var(--accent);
  box-shadow: var(--focus);
}

.search input,
.search button {
  min-width: 0;
  border: 0;
}

.search input[type="search"] {
  width: 100%;
  padding: 10px 13px;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
}

.search-language {
  position: relative;
  display: flex;
  border-left: 1px solid var(--border-light);
}

.search-language__toggle {
  display: inline-flex;
  min-width: 116px;
  height: 100%;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 10px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.search-language__toggle:hover,
.search-language.is-open .search-language__toggle {
  background: var(--control-hover);
}

.search-language__toggle:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.search-language__icon {
  display: inline-flex;
  width: 28px;
  align-items: baseline;
  justify-content: center;
  color: var(--text);
  font-family: Georgia, "Noto Serif", serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.18em;
  line-height: 1;
}

.search-language__icon span:last-child {
  font-family: Arial, sans-serif;
  font-size: .75em;
  transform: translateY(2px);
}

.search-language__current {
  max-width: 92px;
  overflow: hidden;
  font-size: .875rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-language__chevron {
  width: 16px;
  flex: 0 0 auto;
  fill: currentColor;
  transition: transform .15s ease;
}

.search-language.is-open .search-language__chevron { transform: rotate(180deg); }

.search-language__menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 20;
  width: max-content;
  min-width: 260px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
  box-shadow: var(--menu-shadow);
}

.search-language__option {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1px 16px;
  padding: 8px 10px;
  border-radius: 2px;
  outline: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.search-language__option:hover,
.search-language__option:focus-visible {
  background: var(--control-hover);
}

.search-language__option.is-selected { background: var(--accent-soft); }

.search-language__option-name {
  grid-column: 1;
  font-weight: 700;
}

.search-language__option-site {
  grid-column: 1;
  color: var(--muted);
  font-size: .75rem;
}

.search-language__option-check {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  color: var(--accent);
  font-weight: 700;
  visibility: hidden;
}

.search-language__option.is-selected .search-language__option-check { visibility: visible; }

.search__button {
  display: inline-flex;
  min-width: 96px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 15px;
  outline: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.search__button:hover { background: var(--accent-hover); }
.search__button:focus-visible { outline: 3px solid rgb(51 102 204 / 28%); outline-offset: 2px; }
.search__button svg { width: 20px; fill: currentColor; }

.directory { width: min(100%, 700px); margin: 27px auto 0; }

.directory__toggle {
  display: grid;
  grid-template-columns: 1fr auto auto 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: 700 .875rem/1.2 inherit;
  cursor: pointer;
}

.directory__toggle:hover { color: var(--accent-hover); }
.directory__toggle:focus-visible { outline: none; box-shadow: var(--focus); }
.directory__toggle svg { width: 18px; fill: currentColor; transition: transform .18s ease; }
.directory__toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.directory__line { height: 1px; background: var(--border-light); }

.directory__panel {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--border-light);
  border-radius: 2px;
  background: color-mix(in srgb, var(--surface) 96%, var(--accent) 4%);
}

.directory__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 5px 18px;
}

.directory__item {
  padding: 8px;
  border-radius: 2px;
  text-decoration: none;
}

.directory__item:hover { background: var(--accent-soft); }
.directory__item__name { display: block; font-size: .9rem; font-weight: 700; }
.directory__item__site-label { display: block; margin-top: 2px; color: var(--muted); font-size: .75rem; }
.directory__item__count { display: block; margin-top: 1px; color: var(--muted); font-size: .7rem; }

.footer {
  flex: 0 0 auto;
  margin-top: 34px;
  padding: 21px 24px 24px;
  border-top: 1px solid var(--border-light);
  color: var(--muted);
  text-align: center;
  font-size: .78rem;
}

.footer p { margin: 0; }

.footer__link,
.footer__link:link,
.footer__link:visited,
.footer__link:hover,
.footer__link:active {
  color: var(--muted);
}

.footer__link:hover { text-decoration-thickness: 2px; }

.noscript {
  position: fixed;
  inset: auto 12px 12px;
  padding: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 4px 18px rgb(0 0 0 / 15%);
  text-align: center;
}

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

@media (max-width: 650px) {
  .portal { padding-top: 34px; }
  .brand h1 { font-size: 2rem; }

  .language-stage {
    display: flex;
    height: auto;
    flex-direction: column;
    align-items: center;
    margin: 28px auto 22px;
  }

  .emblem {
    position: relative;
    left: auto;
    top: auto;
    order: 1;
    width: 148px;
    height: 148px;
    transform: none;
  }

  .emblem img { width: 96px; height: 96px; }

  .language-orbit {
    position: relative;
    order: 2;
    display: grid;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px 8px;
    margin-top: 12px;
  }

  .language-card,
  .language-card[data-side="left"],
  .language-card[data-side="right"],
  .language-card[data-side="top"] {
    position: relative;
    left: auto;
    top: auto;
    width: auto;
    min-height: 68px;
    transform: none;
    text-align: center;
  }

  .search__button { min-width: 62px; padding-inline: 13px; }
  .search__button span { display: none; }
}

@media (max-width: 460px) {
  .portal { padding-inline: 16px; }
  .language-orbit { grid-template-columns: 1fr; }
  .directory__toggle { gap: 7px; }
  .search-language__toggle { min-width: 54px; padding-inline: 8px; }
  .search-language__current { display: none; }
  .search-language__menu { right: -63px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #101418;
    --surface: #191f24;
    --text: #eaecf0;
    --muted: #a2a9b1;
    --border: #72777d;
    --border-light: #40474d;
    --accent: #6ea6ff;
    --accent-hover: #9bc2ff;
    --accent-soft: #1d3557;
    --control-hover: #2a3137;
    --shadow: 0 1px 2px rgb(0 0 0 / 32%);
    --menu-shadow: 0 3px 12px rgb(0 0 0 / 46%);
  }
}
