:root {
  color-scheme: light;
  --ink: #172b2a;
  --muted: #607170;
  --line: #dce5e1;
  --surface: #ffffff;
  --canvas: #f4f7f5;
  --accent: #176b5b;
  --accent-dark: #105244;
  --accent-soft: #e7f2ed;
  --warm: #9a5a24;
  --warning-bg: #fff8e9;
  --warning-line: #ead7aa;
  --error: #a13636;
  --error-bg: #fff3f2;
  --shadow: 0 10px 32px rgba(26, 54, 47, 0.06);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--canvas);
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
}

button,
a,
input,
summary {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid rgba(23, 107, 91, 0.32);
  outline-offset: 3px;
}

.shell {
  width: min(1120px, calc(100% - 40px));
  margin-inline: auto;
}

.site-header {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
}

.header-inner {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: white;
  background: var(--accent);
  font-family: ui-serif, "Noto Serif CJK SC", serif;
  font-size: 1.1rem;
}

.local-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.local-badge > span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #48a27f;
}

.intro {
  max-width: 730px;
  padding: 54px 0 30px;
}

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

.eyebrow span {
  padding-inline: 4px;
}

h1,
h2,
h3,
h4,
p {
  overflow-wrap: break-word;
}

h1 {
  margin: 0;
  max-width: 680px;
  font-size: clamp(2rem, 5vw, 3.15rem);
  line-height: 1.08;
  letter-spacing: -0.045em;
  font-weight: 760;
}

.intro > p:last-child {
  margin: 18px 0 0;
  max-width: 660px;
  color: var(--muted);
  font-size: 1.03rem;
}

.compare-panel,
.pronunciation-panel,
.result-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.compare-panel {
  padding: 24px;
}

.presets {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.presets-label {
  margin-right: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.preset-button {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-dark);
  background: #fafcfb;
  font-size: 0.84rem;
  font-weight: 650;
  transition: border-color 150ms, background 150ms;
}

.preset-button:hover {
  border-color: #a9c8bd;
  background: var(--accent-soft);
}

.preset-button:disabled {
  opacity: 0.55;
}

.name-fields,
.override-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.field label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.88rem;
  font-weight: 700;
}

.field input {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  border: 1px solid #cbd8d3;
  border-radius: 9px;
  color: var(--ink);
  background: white;
  transition: border-color 150ms, box-shadow 150ms;
}

.field input:hover {
  border-color: #a7bbb3;
}

.field input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.12);
}

.field input:disabled {
  color: var(--muted);
  background: #f4f6f5;
}

#chinese-name {
  font-size: 1.18rem;
}

.field-hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.overrides {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.overrides summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 15px 2px;
  color: var(--accent-dark);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  list-style-position: inside;
}

.summary-hint {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
  text-align: right;
}

.override-fields {
  padding: 4px 0 20px;
}

.form-actions {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 22px;
}

.primary-button {
  min-width: 205px;
  min-height: 45px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 19px;
  border: 0;
  border-radius: 9px;
  color: white;
  background: var(--accent);
  font-size: 0.88rem;
  font-weight: 750;
  box-shadow: 0 3px 8px rgba(23, 107, 91, 0.18);
  transition: background 150ms, transform 150ms;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.primary-button:disabled {
  background: #598a7e;
}

.spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.is-loading .spinner {
  display: inline-block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.form-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.error-message {
  margin-top: 18px;
  padding: 12px 14px;
  border-left: 3px solid var(--error);
  border-radius: 4px 8px 8px 4px;
  color: var(--error);
  background: var(--error-bg);
  font-size: 0.86rem;
  white-space: pre-line;
}

.results {
  padding-top: 44px;
}

.results-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.results-heading h2 {
  margin: 0;
  font-size: 1.65rem;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.results-heading h2:focus {
  outline: none;
}

.result-pair {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.pronunciation-panel {
  padding: 22px 24px;
  box-shadow: none;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-title-row h3 {
  margin: 0;
  font-size: 1rem;
}

.subtle-label {
  color: var(--muted);
  font-size: 0.72rem;
}

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

.pronunciation-item + .pronunciation-item {
  padding-left: 30px;
  border-left: 1px solid var(--line);
}

.pronunciation-item h4 {
  margin: 0 0 12px;
  font-size: 0.85rem;
}

.pronunciation-item h4 span {
  display: inline-block;
  min-width: 26px;
  margin-right: 5px;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 800;
}

dl {
  margin: 0;
}

.pronunciation-item dl > div {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  align-items: baseline;
  padding: 4px 0;
}

dt {
  color: var(--muted);
  font-size: 0.75rem;
}

dd {
  min-width: 0;
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.token-sequence {
  word-spacing: 0.25em;
}

.not-available {
  color: var(--muted);
  font-family: inherit;
  font-style: italic;
}

.warnings {
  margin-top: 14px;
  padding: 15px 20px;
  border: 1px solid var(--warning-line);
  border-radius: 10px;
  color: #70471f;
  background: var(--warning-bg);
}

.warnings h3 {
  margin: 0 0 6px;
  font-size: 0.82rem;
}

.warnings ul {
  margin: 0;
  padding-left: 20px;
  font-size: 0.8rem;
}

.warnings li + li {
  margin-top: 3px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.result-card {
  min-width: 0;
  padding: 24px;
  box-shadow: none;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.method-tag {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.69rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.card-header h3 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.025em;
}

.score-block {
  display: flex;
  align-items: baseline;
  white-space: nowrap;
}

.score {
  color: var(--accent);
  font-size: 2rem;
  line-height: 1;
  font-weight: 780;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
}

.score-unit {
  margin-left: 5px;
  color: var(--muted);
  font-size: 0.72rem;
}

.method-description {
  min-height: 42px;
  margin: 15px 0 12px;
  color: var(--muted);
  font-size: 0.79rem;
}

.raw-value {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 10px 12px;
  border-radius: 7px;
  color: var(--muted);
  background: #f5f8f6;
  font-size: 0.76rem;
}

.raw-value strong {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.card-tokens {
  margin-top: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}

.card-tokens p {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 8px;
  margin: 3px 0;
  font-size: 0.72rem;
}

.card-tokens span {
  color: var(--muted);
}

.card-tokens code {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  overflow-wrap: anywhere;
}

.alignment-title {
  margin: 17px 0 9px;
  font-size: 0.8rem;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.73rem;
  text-align: left;
}

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid #e7ece9;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #f8faf9;
  font-size: 0.66rem;
  font-weight: 700;
  white-space: nowrap;
}

th:last-child,
td:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

td:nth-child(3) {
  color: var(--muted);
}

.token-cell {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.8rem;
}

.operation-label {
  display: inline-block;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.67rem;
  line-height: 1.4;
}

.empty-alignment {
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

.calibration-note {
  margin: 18px 0 0;
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.77rem;
}

.calibration-note strong {
  color: var(--ink);
}

.site-footer {
  padding-top: 40px;
  padding-bottom: 28px;
  color: var(--muted);
  font-size: 0.72rem;
  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: 850px) {
  .result-grid {
    grid-template-columns: 1fr;
  }

  .method-description {
    min-height: 0;
  }
}

@media (max-width: 620px) {
  .shell {
    width: min(100% - 28px, 1120px);
  }

  .intro {
    padding-top: 38px;
  }

  .compare-panel,
  .result-card,
  .pronunciation-panel {
    padding: 18px;
    border-radius: 12px;
  }

  .name-fields,
  .override-fields,
  .pronunciation-grid {
    grid-template-columns: 1fr;
  }

  .name-fields,
  .override-fields {
    gap: 16px;
  }

  .pronunciation-grid {
    gap: 18px;
  }

  .pronunciation-item + .pronunciation-item {
    padding: 18px 0 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .summary-hint {
    display: none;
  }

  .results-heading {
    display: block;
  }

  .result-pair {
    margin-top: 8px;
  }

  .form-actions {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .primary-button {
    width: 100%;
  }
}

@media (max-width: 400px) {
  .local-badge {
    font-size: 0;
  }

  .local-badge::after {
    content: "Local";
    font-size: 0.75rem;
  }

  .presets-label {
    width: 100%;
  }

  .section-title-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .card-header {
    gap: 8px;
  }

  .score {
    font-size: 1.75rem;
  }
}

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


/* NameSound v2: asynchronous ranked search */
.search-fields {
  max-width: 560px;
}

.override-fields {
  grid-template-columns: minmax(0, 560px);
}

.progress-panel {
  margin-top: 20px;
  padding: 16px 18px;
  border: 1px solid #cfe0d9;
  border-radius: 10px;
  background: var(--accent-soft);
}

.progress-heading,
.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.progress-heading {
  margin-bottom: 8px;
  color: var(--accent-dark);
  font-size: 0.8rem;
  font-weight: 750;
}

.progress-percentage {
  font-variant-numeric: tabular-nums;
}

.progress-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.75rem;
}

#progress-count {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#progress-status {
  text-align: right;
}

progress {
  width: 100%;
  height: 12px;
  display: block;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: #d5e5de;
  accent-color: var(--accent);
}

progress::-webkit-progress-bar {
  border-radius: 999px;
  background: #d5e5de;
}

progress::-webkit-progress-value {
  border-radius: 999px;
  background: var(--accent);
  transition: width 250ms ease;
}

progress::-moz-progress-bar {
  border-radius: 999px;
  background: var(--accent);
  transition: width 250ms ease;
}

.top-badge {
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 0.7rem;
  font-weight: 750;
  white-space: nowrap;
}

.ranked-list {
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: none;
}

.ranked-item {
  min-width: 0;
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.rank-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.rank-number {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: grid;
  place-items: center;
  margin-top: 1px;
  border-radius: 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 0.76rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.name-info {
  min-width: 0;
  flex: 1;
}

.name-info h4 {
  margin: 2px 0 8px;
  font-size: 1.08rem;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.name-pronunciations p {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 7px;
  margin: 3px 0;
  font-size: 0.7rem;
}

.name-pronunciations span {
  color: var(--muted);
}

.name-pronunciations code {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  overflow-wrap: anywhere;
}

.ranked-item .score-block {
  flex: 0 0 auto;
  margin-top: 3px;
}

.ranked-item .score {
  font-size: 1.55rem;
}

.ranked-item .raw-value {
  margin: 12px 0 0 40px;
}

.alignment-details {
  margin: 10px 0 0 40px;
}

.alignment-details summary {
  color: var(--accent-dark);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.alignment-details[open] summary {
  margin-bottom: 9px;
}

.alignment-details .table-wrap {
  background: white;
}

.empty-results {
  padding: 24px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.dataset-summary h4 span {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

@media (max-width: 620px) {
  .override-fields {
    grid-template-columns: minmax(0, 1fr);
  }

  .progress-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  #progress-status {
    text-align: left;
  }

  .ranked-item .raw-value,
  .alignment-details {
    margin-left: 0;
  }
}

@media (max-width: 400px) {
  .rank-row {
    flex-wrap: wrap;
    gap: 9px;
  }

  .name-info {
    flex-basis: calc(100% - 40px);
  }

  .ranked-item .score-block {
    width: 100%;
    justify-content: flex-end;
    margin-top: -4px;
  }

  .name-pronunciations p {
    grid-template-columns: 50px minmax(0, 1fr);
  }
}
