:root {
  --canvas: #f1f3f0;
  --surface: #ffffff;
  --surface-muted: #e7eae7;
  --ink: #171a1c;
  --ink-soft: #303633;
  --muted: #59615d;
  --line: #cdd2ce;
  --line-strong: #929b96;
  --primary: #08785a;
  --primary-pressed: #065b45;
  --primary-soft: #dceee7;
  --warning: #a85c14;
  --danger: #b53c3c;
  --focus: #08785a;
  --radius-control: 4px;
  --radius-sheet: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@font-face {
  font-family: "Archive Display";
  src: url("assets/noto-sans-sc-display.ttf") format("truetype");
  font-style: normal;
  font-weight: 800;
  font-display: swap;
}

@font-face {
  font-family: "Headline Display";
  src: url("assets/headline-display.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scrollbar-color: #65706a #dfe3df;
  scrollbar-width: thin;
}

body {
  min-height: 100dvh;
  margin: 0;
  padding-bottom: 24px;
  overscroll-behavior-y: contain;
  background: var(--canvas);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button,
a {
  touch-action: manipulation;
}

button {
  letter-spacing: 0;
}

input {
  caret-color: var(--primary);
}

button:focus-visible,
input:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(8, 120, 90, 0.28);
  outline-offset: 2px;
}

::selection {
  background: #b9e3d4;
  color: var(--ink);
}

html::-webkit-scrollbar,
.dimension-toolbar::-webkit-scrollbar {
  width: 9px;
  height: 8px;
}

html::-webkit-scrollbar-track,
.dimension-toolbar::-webkit-scrollbar-track {
  background: #dfe3df;
}

html::-webkit-scrollbar-thumb,
.dimension-toolbar::-webkit-scrollbar-thumb {
  border: 2px solid #dfe3df;
  border-radius: 6px;
  background: #65706a;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  min-height: 84px;
  padding: 16px max(16px, calc((100vw - 640px) / 2 + 16px));
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  background: var(--ink);
  color: var(--surface);
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid #4d5652;
  border-radius: var(--radius-control);
  color: #67d3ad;
}

.brand-mark svg {
  width: 24px;
  height: 24px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: "Archive Display", "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 24px;
  line-height: 1.1;
}

.brand small {
  margin-top: 5px;
  color: #b8c0bc;
  font-size: 11px;
  font-weight: 700;
}

main,
footer {
  width: min(100%, 640px);
  margin-inline: auto;
  padding-inline: 16px;
}

.desk-shell {
  margin: 28px 0 32px;
}

.task-panel {
  padding: 0;
}

.task-heading {
  display: block;
  text-align: center;
}

.task-heading h1 {
  width: 100%;
  margin: 0;
  font-family: "Headline Display", "Archive Display", "Microsoft YaHei UI", sans-serif;
  font-size: 36px;
  font-weight: 400;
  line-height: 1.25;
  text-align: center;
}

.query-form {
  margin-top: 22px;
  display: grid;
  align-items: end;
  gap: 8px;
}

.compare-form {
  grid-template-columns: minmax(0, 1fr) 48px minmax(0, 1fr);
}

.field-block {
  min-width: 0;
  display: block;
}

.field-block > span,
.top-control legend {
  display: block;
  margin-bottom: 7px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
}

.field-block small {
  min-height: 36px;
  padding-top: 6px;
  display: block;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.field-block small.is-valid {
  color: var(--primary-pressed);
}

.field-block small.is-invalid {
  color: var(--danger);
}

.number-field {
  min-height: 56px;
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  transition: border-color 180ms var(--ease-out), box-shadow 180ms var(--ease-out);
}

.number-field:focus-within {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(8, 120, 90, 0.14);
}

.number-field > span {
  width: 34px;
  align-self: stretch;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-right: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.number-field input {
  width: 100%;
  min-width: 0;
  height: 54px;
  padding: 0 10px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-family: "Archive Display", "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.number-field input::placeholder {
  color: #7d8681;
  font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 14px;
  font-weight: 500;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
}

.top-control {
  min-width: 0;
  margin: 2px 0 0;
  padding: 0;
  grid-column: 1 / -1;
  border: 0;
}

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

.segmented button {
  min-width: 0;
  min-height: 48px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: background-color 180ms var(--ease-out), color 180ms var(--ease-out), border-color 180ms var(--ease-out), transform 150ms var(--ease-out);
}

.segmented button[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--surface);
}

.segmented button:active:not(:disabled) {
  transform: scale(0.97);
}

.segmented button:disabled {
  opacity: 0.48;
  cursor: wait;
}

.primary-button,
.icon-button,
.dimension-button {
  cursor: pointer;
}

.primary-button,
.icon-button {
  border: 0;
  border-radius: var(--radius-control);
}

.primary-button {
  min-height: 56px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  grid-column: 1 / -1;
  background: var(--primary);
  color: var(--surface);
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(8, 120, 90, 0.2);
  transition: background-color 180ms var(--ease-out), transform 150ms var(--ease-out), box-shadow 180ms var(--ease-out);
}

.primary-button svg,
.icon-button svg {
  width: 20px;
  height: 20px;
}

.primary-button:active:not(:disabled) {
  background: var(--primary-pressed);
  transform: scale(0.98);
  box-shadow: 0 4px 12px rgba(8, 120, 90, 0.18);
}

.primary-button:disabled {
  opacity: 0.48;
  box-shadow: none;
  cursor: not-allowed;
}

.icon-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-soft);
  transition: background-color 180ms var(--ease-out), transform 150ms var(--ease-out);
}

.icon-button:active:not(:disabled) {
  background: var(--primary-soft);
  transform: scale(0.96);
}

.icon-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.swap-button {
  margin-bottom: 36px;
}

.result-stage {
  min-height: 300px;
  margin-top: 28px;
  border-top: 3px solid var(--ink);
  opacity: 1;
}

.result-stage.result-entered {
  animation: result-in 260ms var(--ease-out) both;
}

@keyframes result-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.empty-state,
.error-state,
.loading-state {
  min-height: 300px;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.empty-state svg,
.error-state svg {
  width: 40px;
  height: 40px;
  margin-bottom: 14px;
  color: var(--line-strong);
}

.error-state svg {
  color: var(--danger);
}

.empty-state strong,
.error-state strong {
  font-family: "Archive Display", "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 17px;
}

.empty-state span,
.error-state span {
  max-width: 30ch;
  margin-top: 7px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.loading-state {
  align-items: stretch;
  gap: 12px;
}

.skeleton {
  height: 18px;
  overflow: hidden;
  position: relative;
  border-radius: 3px;
  background: #dfe3df;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.76), transparent);
  transform: translateX(-100%);
  animation: scan 1.1s var(--ease-out) infinite;
}

.skeleton.short { width: 42%; }
.skeleton.medium { width: 70%; }

@keyframes scan {
  to { transform: translateX(100%); }
}

.result-header {
  padding: 20px 0 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.result-header > div {
  min-width: 0;
  flex: 1 1 220px;
}

.result-header h2 {
  margin: 0;
  font-family: "Archive Display", "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 22px;
  line-height: 1.25;
}

.result-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.source-badge {
  padding: 6px 9px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-pressed);
  font-size: 11px;
  font-weight: 800;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.summary-cell {
  min-width: 0;
  min-height: 88px;
  padding: 14px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.summary-cell:nth-child(2n) {
  border-right: 0;
}

.summary-cell:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.summary-cell span,
.summary-cell strong {
  display: block;
}

.summary-cell span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.summary-cell strong {
  margin-top: 7px;
  overflow-wrap: anywhere;
  font-family: "Archive Display", "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.summary-cell strong.signal-value {
  color: var(--primary-pressed);
}

.dimension-toolbar {
  margin-inline: -16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border-bottom: 1px solid var(--line);
  scrollbar-color: #65706a #dfe3df;
  scrollbar-width: thin;
}

.dimension-toolbar > span {
  padding-right: 4px;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.dimension-button {
  min-height: 44px;
  padding: 0 12px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  transition: background-color 180ms var(--ease-out), color 180ms var(--ease-out), transform 150ms var(--ease-out);
}

.dimension-button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--surface);
}

.dimension-button:active {
  transform: scale(0.97);
}

.matchup-section,
.ranking-section {
  margin-top: 2px;
}

.match-list-head {
  min-height: 44px;
  padding: 0 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr);
  align-items: center;
  background: var(--ink);
  color: var(--surface);
  font-size: 12px;
  font-weight: 800;
}

.match-list-head span:nth-child(2) {
  color: #aeb7b2;
  text-align: center;
}

.match-list-head span:last-child {
  text-align: right;
}

.match-list,
.ranking-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.match-row {
  min-height: 104px;
  padding: 14px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr);
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.match-player {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.match-player.side-a {
  padding-right: 8px;
  align-items: flex-start;
  text-align: left;
}

.match-player.side-b {
  padding-left: 8px;
  align-items: flex-end;
  text-align: right;
}

.player-name {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
}

.player-meta {
  max-width: 100%;
  margin-top: 4px;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.match-value {
  margin-top: 9px;
  color: var(--ink-soft);
  font-family: "Archive Display", "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.match-player.is-better .match-value {
  color: var(--primary-pressed);
}

.lead-mark {
  margin-top: 4px;
  color: var(--primary-pressed);
  font-size: 10px;
  font-weight: 800;
}

.match-rank,
.ranking-rank {
  color: var(--line-strong);
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.match-rank::before,
.match-rank::after {
  content: "";
  width: 1px;
  height: 17px;
  margin: 4px auto;
  display: block;
  background: var(--line);
}

.ranking-list-head {
  min-height: 44px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  background: var(--ink);
  color: var(--surface);
  font-size: 12px;
  font-weight: 800;
}

.ranking-row {
  min-height: 78px;
  padding: 12px 4px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.ranking-copy {
  min-width: 0;
}

.ranking-copy .player-name,
.ranking-copy .player-meta {
  display: block;
}

.ranking-value {
  padding-left: 8px;
  color: var(--primary-pressed);
  font-family: "Archive Display", "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.analysis-block {
  margin-top: 20px;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  background: var(--surface);
}

.analysis-block summary {
  min-height: 52px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink-soft);
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

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

.analysis-block summary::after {
  content: "+";
  margin-left: auto;
  color: var(--muted);
  font-size: 20px;
  font-weight: 500;
}

.analysis-block[open] summary::after {
  content: "−";
}

.analysis-block summary svg {
  width: 19px;
  height: 19px;
}

.analysis-block p {
  margin: 0;
  padding: 2px 4px 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
}

footer {
  margin-bottom: 18px;
  padding-top: 18px;
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

footer p {
  margin: 0;
  display: flex;
  align-items: flex-start;
  gap: 7px;
}

footer svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

footer code {
  color: var(--ink-soft);
  font-family: Consolas, "Courier New", monospace;
}

@media (min-width: 768px) {
  main,
  footer {
    padding-inline: 24px;
  }

  .topbar {
    padding-inline: max(24px, calc((100vw - 640px) / 2 + 24px));
  }

  .desk-shell {
    margin-top: 32px;
  }

}

@media (max-width: 350px) {
  .topbar {
    padding-inline: 12px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
  }

  .brand strong {
    font-size: 21px;
  }

  .brand small {
    font-size: 10px;
  }

  main,
  footer {
    padding-inline: 12px;
  }

  .compare-form {
    grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr);
    gap: 6px;
  }

  .icon-button {
    width: 44px;
    height: 48px;
  }

  .number-field > span {
    width: 30px;
  }

  .number-field input {
    padding-inline: 7px;
    font-size: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
