:root {
  color-scheme: dark;
  --page: #000000;
  --surface: #050505;
  --surface-raised: #0b0b0b;
  --surface-active: #2b2b2b;
  --line: #191919;
  --line-strong: #2a2a2a;
  --text: #ffffff;
  --text-soft: #e8f5ec;
  --muted: #78847d;
  --muted-strong: #9aa59e;
  --green: #26ee6d;
  --green-hover: #55f58d;
  --green-soft: rgb(38 238 109 / 11%);
  --red: #f56f7c;
  --radius-sm: 8px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--text-soft);
  font-family:
    MiSans,
    "PingFang SC",
    "Microsoft YaHei",
    Arial,
    sans-serif;
  font-size: 14px;
  font-weight: 330;
}

body {
  min-width: 320px;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #080808;
}

::-webkit-scrollbar-thumb {
  border: 2px solid #080808;
  border-radius: 999px;
  background: #333333;
}

::-webkit-scrollbar-thumb:hover {
  background: #474747;
}

.variant-a {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 80px;
}

.a-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.a-header-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.language-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.language-switch button {
  flex: none;
  min-height: 28px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 12px;
  color: var(--muted-strong);
  background: transparent;
  font-size: 12px;
  font-weight: 450;
  white-space: nowrap;
  transition:
    color 160ms ease,
    background 160ms ease;
}

.language-switch button:hover {
  color: var(--text);
  background: #151515;
}

.language-switch button.active {
  color: #050505;
  background: var(--green);
}

.a-header h1 {
  margin: 15px 0 5px;
  color: var(--text);
  font-size: clamp(27px, 3vw, 36px);
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -.025em;
}

.search-form {
  width: 100%;
}

.search-box {
  display: flex;
  align-items: center;
  min-height: 52px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.search-box:hover {
  border-color: #3a3a3a;
}

.search-box:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.search-icon {
  flex: none;
  padding-left: 17px;
  color: var(--green);
  font-size: 23px;
  line-height: 1;
}

.search-box input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 0 15px;
  color: var(--text);
  background: transparent;
  font-size: 16px;
  font-weight: 380;
}

.search-box input::placeholder {
  color: #626b66;
}

.search-box button {
  flex: none;
  align-self: stretch;
  min-width: 100px;
  border: 0;
  color: #050505;
  background: var(--green);
  font-size: 14px;
  font-weight: 550;
  white-space: nowrap;
  transition: background 160ms ease;
}

.search-box button:hover {
  background: var(--green-hover);
}

.filters {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
  margin: 18px 0 15px;
}

.filter-block {
  display: grid;
  min-width: 0;
  gap: 7px;
}

.filter-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 450;
}

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.segmented button {
  min-width: 0;
  min-height: 30px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  white-space: nowrap;
  transition:
    color 160ms ease,
    background 160ms ease;
}

.segmented button:hover {
  color: var(--text);
  background: #151515;
}

.segmented button.active {
  color: var(--text);
  background: var(--surface-active);
}

.custom-select {
  position: relative;
  min-width: 116px;
}

.custom-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  max-width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0 11px;
  color: var(--text-soft);
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.custom-select-trigger:hover {
  border-color: #3a3a3a;
  background: #0a0a0a;
}

.custom-select.open .custom-select-trigger {
  border-color: var(--green);
  box-shadow: 0 0 0 2px var(--green-soft);
}

.custom-select-trigger svg {
  flex: none;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
  transition: transform 160ms ease;
}

.custom-select.open .custom-select-trigger svg {
  transform: rotate(180deg);
}

.custom-select.open-up .custom-select-menu {
  top: auto;
  bottom: calc(100% + 6px);
}

.custom-select-menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  left: 0;
  display: grid;
  width: max(100%, 132px);
  max-height: min(360px, 55vh);
  padding: 6px;
  overflow: auto;
  border: 1px solid #252525;
  border-radius: 7px;
  background: #202020;
  box-shadow: 0 12px 30px rgb(0 0 0 / 48%);
}

.custom-select-menu[hidden] {
  display: none;
}

.custom-select-option {
  min-height: 34px;
  border: 0;
  border-radius: 5px;
  padding: 0 12px;
  color: #9aa09c;
  text-align: left;
  background: transparent;
  font-size: 12px;
  white-space: nowrap;
  transition:
    color 120ms ease,
    background 120ms ease;
}

.custom-select-option:hover,
.custom-select-option:focus-visible {
  outline: 0;
  color: var(--text);
  background: #2a2a2a;
}

.custom-select-option.selected {
  color: var(--text);
  background: #3a3a3a;
}

.parser-strip {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  color: var(--muted-strong);
  font-size: 11px;
}

.parser-strip span {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.parser-strip strong {
  color: var(--text);
  font-weight: 500;
}

.segmentation-choices {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin: -7px 0 18px;
  color: var(--muted);
  font-size: 12px;
}

.segmentation-choices button {
  min-height: 29px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  color: var(--muted-strong);
  background: var(--surface);
}

.segmentation-choices button:hover {
  color: var(--text);
  border-color: #3a3a3a;
}

.segmentation-choices button.active {
  border-color: var(--green);
  color: var(--green);
  background: var(--green-soft);
}

.state-panel {
  display: grid;
  place-items: center;
  min-height: 230px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--muted);
  background: var(--surface);
}

.state-panel.loading {
  color: var(--green);
}

.state-panel.error {
  color: var(--red);
}

.a-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.a-results > .state-panel {
  grid-column: 1 / -1;
}

.result-group {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: visible;
}

.result-group:has(.custom-select.open) {
  z-index: 50;
}

.result-group > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 14px 15px;
  border-bottom: 1px solid var(--line);
}

.result-header-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.result-header-main h2 {
  flex: none;
}

[data-select-id="pos-select"] {
  min-width: 128px;
  margin-left: 4px;
}

[data-select-id="pos-select"] .custom-select-trigger {
  min-height: 34px;
}

.result-group h2 {
  margin: 3px 0 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 550;
}

.result-group header > span {
  color: var(--muted);
  font-size: 10px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  max-height: 560px;
  padding: 10px;
  overflow: auto;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

[data-select-id="pos-select"] .custom-select-menu {
  z-index: 60;
}

.result-card {
  display: grid;
  gap: 4px;
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  color: var(--text-soft);
  text-align: left;
  background: #080808;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.result-card:hover {
  transform: translateY(-1px);
  border-color: var(--green);
  background: #0d120f;
}

.result-card .word {
  color: var(--text);
  font-size: 18px;
  font-weight: 580;
  line-height: 1.2;
}

.result-card .pinyin {
  color: var(--muted);
  font-size: 10px;
}

.result-card .meta {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.result-card .meta span {
  border-radius: 4px;
  padding: 2px 5px;
  color: #69f49c;
  background: var(--green-soft);
  font-size: 8px;
  line-height: 1.4;
}

.result-card.tier-less_common {
  background: #060606;
}

.result-card.tier-rare {
  opacity: .55;
}

.empty-group {
  grid-column: 1 / -1;
  padding: 34px 15px;
  color: var(--muted);
  text-align: center;
}

.load-more-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 3px 10px 12px;
}

.load-more-row button {
  min-width: 142px;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  color: var(--text-soft);
  background: #0b0b0b;
  font-size: 11px;
  font-weight: 450;
  white-space: nowrap;
  transition:
    color 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.load-more-row button:hover {
  border-color: var(--green);
  color: #050505;
  background: var(--green);
}

.load-more-row button:disabled {
  cursor: wait;
  opacity: .55;
}

.load-more-row span {
  color: var(--red);
  font-size: 11px;
}

@media (max-width: 960px) {
  .a-results {
    grid-template-columns: 1fr;
  }

  .result-grid {
    max-height: none;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .variant-a {
    width: min(100% - 24px, 1120px);
    padding-top: 20px;
  }

  .a-header {
    align-items: flex-start;
    margin-bottom: 18px;
  }

  .a-header h1 {
    font-size: 26px;
  }

  .search-box {
    min-height: 48px;
  }

  .search-box button {
    min-width: 72px;
  }

  .filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    gap: 10px 8px;
  }

  .filter-block:first-child {
    grid-column: 1 / -1;
    width: 100%;
  }

  .custom-select {
    width: 100%;
    min-width: 0;
  }

  .custom-select-trigger {
    gap: 8px;
    padding-inline: 9px;
  }

  .segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 360px) {
  .a-header h1 {
    font-size: 24px;
  }

  .language-switch button {
    padding-inline: 10px;
  }

  .search-box input {
    padding-inline: 10px;
    font-size: 15px;
  }

  .search-box button {
    min-width: 66px;
  }

  .segmented button {
    padding-inline: 6px;
  }
}

@media (hover: none) and (pointer: coarse) {
  .language-switch button,
  .segmented button {
    min-height: 36px;
  }

  .custom-select-trigger {
    min-height: 42px;
  }

  .load-more-row button {
    min-height: 40px;
  }
}

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