:root {
  --ink: #17222c;
  --muted: #61707a;
  --faint: #89949b;
  --line: #dddcd5;
  --line-strong: #c8cbc6;
  --surface: #fbfaf7;
  --background: #f4f1eb;
  --left: #2c8b83;
  --right: #ee8b4a;
  --navy: #203542;
  --navy-deep: #172a35;
  --display-font: Georgia, "Songti SC", "SimSun", serif;
  --number-font: "Segoe UI", Arial, "Microsoft YaHei", sans-serif;
  --shadow: 0 15px 35px rgba(30, 49, 58, .08);
  font-family: "Segoe UI", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background: var(--background);
  font-synthesis: none;
}

* { box-sizing: border-box; letter-spacing: 0; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgba(33, 55, 65, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(33, 55, 65, .035) 1px, transparent 1px),
    var(--background);
  background-size: 32px 32px;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; }
a, button, input, select { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #7bcac0; outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
.content-width { width: min(1240px, calc(100% - 48px)); margin: 0 auto; }

.topbar { background: transparent; }
.topbar-inner { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid rgba(32, 53, 66, .12); }
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.brand strong { display: block; font-size: 18px; }
.brand small { display: block; margin-top: 3px; color: var(--faint); font-size: 11px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; background: var(--navy); color: #fffefa; border-radius: 6px; font: 800 17px/1 var(--display-font); }
.data-status { color: #866b23; background: #fff7dc; border: 1px solid #e8d9a9; border-radius: 3px; padding: 7px 10px; font-size: 11px; white-space: nowrap; }

.query-section { padding: 38px 0 0; }
.query-section > .content-width { padding: 26px 30px 24px; border: 1px solid rgba(32, 53, 66, .16); background: var(--surface); box-shadow: var(--shadow); }
.query-toolbar { display: flex; flex-direction: column; align-items: stretch; gap: 0; margin-bottom: 0; }
h1 { color: var(--navy-deep); font: 500 26px/1.2 var(--display-font); }
.mode-switch { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 23px 0; padding: 5px; border: 1px solid var(--line); background: #edf0ec; }
.mode-tab { min-width: 0; min-height: 64px; display: flex; align-items: center; gap: 13px; padding: 10px 15px; border: 1px solid transparent; color: var(--muted); background: transparent; font-size: 13px; text-align: left; }
.mode-index { width: 27px; flex-shrink: 0; color: var(--left); font: 700 10px/1 var(--display-font); }
.mode-tab.active { color: var(--navy-deep); border-color: var(--line); background: #fffefa; font-weight: 600; box-shadow: 0 4px 10px rgba(32, 53, 66, .06); }
.mode-tab:hover { color: var(--ink); }
.query-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(130px, .65fr) minmax(120px, .55fr); gap: 14px; align-items: end; }
.query-form.is-single { grid-template-columns: minmax(0, 1fr) minmax(130px, .65fr) minmax(120px, .55fr); }
.field { min-width: 0; display: grid; gap: 7px; font-size: 11px; font-weight: 700; color: var(--muted); }
.input-wrap { display: flex; align-items: center; height: 44px; border: 1px solid var(--line-strong); background: #fffefa; }
.input-prefix { padding-left: 12px; color: var(--right); font: 700 11px/1 var(--display-font); }
input, select { min-width: 0; width: 100%; height: 44px; border: 1px solid var(--line-strong); border-radius: 0; padding: 0 11px; color: var(--ink); background: #fffefa; font-size: 13px; }
.input-wrap input { height: 42px; border: 0; background: transparent; }
.query-button { height: 44px; border: 1px solid var(--navy); border-radius: 5px; padding: 0 18px; background: var(--navy); color: #fffefa; font-size: 13px; font-weight: 700; white-space: nowrap; }
.query-button:hover { background: var(--left); border-color: var(--left); }
.query-button:disabled { opacity: .65; }
.form-message { min-height: 18px; margin-top: 12px; color: var(--left); font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.form-message.error { color: #bb413e; }

.results { padding-top: 55px; padding-bottom: 70px; }
.result-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.result-heading h2 { color: var(--navy-deep); font: 500 39px/1.2 var(--display-font); overflow-wrap: anywhere; }
#result-subtitle { margin-top: 8px; color: var(--muted); font-size: 12px; }
.dimension-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 24px 0 20px; }
.dimension-tab { min-height: 42px; padding: 9px 15px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--muted); background: rgba(255, 254, 250, .65); font-size: 13px; white-space: nowrap; }
.dimension-tab:hover { background: #fffefa; border-color: var(--left); }
.dimension-tab.active { border-color: var(--left); color: var(--left); background: #dbece7; font-weight: 700; }
.dimension-tab[data-status="unavailable"] { color: #848c92; }
.kingdom-profiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line); }
.kingdom-profiles.single { grid-template-columns: minmax(0, 1fr); }
.kingdom-profile { min-width: 0; padding: 18px 22px 16px; }
.kingdom-profile + .kingdom-profile { border-left: 1px solid var(--line); }
.profile-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; margin-bottom: 16px; }
.profile-heading h3 { font-size: 18px; font-weight: 700; color: var(--left); }
.kingdom-profile.right h3 { color: var(--right); }
.profile-redirect { font-size: 11px; color: var(--muted); }
.profile-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; margin: 0; }
.profile-fact { min-width: 0; }
.profile-fact dt { font-size: 11px; line-height: 1.5; color: var(--muted); }
.profile-fact dd { margin: 5px 0 0; }
.profile-fact strong { display: block; font-size: 15px; line-height: 1.5; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.profile-fact small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; line-height: 1.6; overflow-wrap: anywhere; }
.profile-mergers { margin-top: 16px; font-size: 12px; color: var(--muted); line-height: 1.7; }
.profile-mergers summary { cursor: pointer; color: var(--navy); }
.profile-mergers p { margin-top: 4px; overflow-wrap: anywhere; }
.profile-unavailable { font-size: 13px; color: var(--muted); }
.board-notice { margin-bottom: 14px; padding: 10px 12px; border-left: 3px solid #d29c47; background: #fff7e8; font-size: 13px; line-height: 1.6; }
.alliance-scope strong { display: flex; align-items: center; height: 44px; font-size: 13px; font-weight: 500; }
.alliance-selection { margin-top: 20px; padding: 18px 20px; border: 1px solid var(--line); background: var(--surface); }
.alliance-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.alliance-left > span { color: var(--left); }
.alliance-right > span { color: var(--right); }
#alliance-help { margin-top: 12px; color: var(--muted); font-size: 12px; line-height: 1.8; }
.result-summary.alliance-members { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.result-summary.alliance-members .summary-item { border-bottom: 0; }
.result-summary.alliance-members .summary-item.right .summary-value { color: var(--right); }
.player-region-rank { color: var(--muted); }
.ranking-table th { overflow-wrap: anywhere; }
.result-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); background: rgba(255, 254, 250, .47); }
.summary-item { min-width: 0; min-height: 124px; padding: 20px 23px 18px; border-right: 1px solid var(--line); }
.summary-item:last-child { border-right: 0; }
.summary-label { display: block; color: var(--muted); font-size: 11px; line-height: 1.5; }
.summary-value { display: block; margin: 13px 0 7px; color: var(--navy-deep); font: 600 27px/1.15 var(--number-font); font-variant-numeric: tabular-nums lining-nums; overflow-wrap: anywhere; }
.summary-value.is-text { font-size: 23px; }
.summary-note { display: block; font-size: 11px; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.summary-item:nth-child(3) .summary-value { color: var(--right); }

.insight-section { margin-top: 18px; }
.insight-section > summary { display: none; }
.insight-grid { display: grid; grid-template-columns: 1.3fr .7fr; gap: 18px; }
.chart-panel, .analysis-panel { min-width: 0; padding: 24px 25px; border: 1px solid var(--line); background: rgba(255, 254, 250, .7); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-heading h3 { color: var(--navy-deep); font: 500 21px/1.3 var(--display-font); }
.panel-heading > span { color: var(--faint); font-size: 10px; }
.bar-chart { display: grid; gap: 17px; margin: 30px 0 20px; }
.bar-row { display: grid; grid-template-columns: 55px minmax(0, 1fr) 85px; align-items: center; gap: 12px; }
.bar-label { color: var(--muted); font-size: 11px; font-weight: 700; }
.bar-track { height: 13px; overflow: hidden; background: #e6e7e2; }
.bar-fill { height: 100%; }
.bar-fill.left, .legend-swatch.left { background: var(--left); }
.bar-fill.right, .legend-swatch.right { background: var(--right); }
.bar-value { color: var(--navy); font: 600 12px/1.4 var(--number-font); font-variant-numeric: tabular-nums lining-nums; text-align: right; overflow-wrap: anywhere; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 17px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-swatch { width: 15px; height: 7px; display: inline-block; }
.analysis-winner { margin: 26px 0 13px; color: var(--left); font: 500 27px/1.3 var(--display-font); overflow-wrap: anywhere; }
.analysis-text { color: var(--muted); font-size: 12px; line-height: 1.8; }
.analysis-facts { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 18px; }
.analysis-fact { padding: 8px 9px; border: 1px solid var(--line); color: var(--muted); background: #f2f2ed; font-size: 10px; }

.ranking-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 38px 0 15px; }
.ranking-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 5px; }
.ranking-actions .public-icon-button { display: inline-flex; justify-content: center; align-items: center; width: auto; min-width: 36px; padding: 0 7px; gap: 4px; }
.favorite-kid { font-size: 11px; }
.ranking-search { display: block; max-width: 300px; margin-bottom: 12px; height: 38px; }
.recent-queries { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 11px; color: var(--muted); }
.recent-queries select { width: auto; max-width: calc(100% - 65px); height: 34px; font-size: 12px; }
.ranking-title { min-width: 0; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.ranking-title h3 { color: var(--navy-deep); font: 500 24px/1.25 var(--display-font); }
#ranking-count { color: var(--muted); font-size: 12px; }
.ranking-table { width: 100%; border-collapse: collapse; table-layout: fixed; border: 1px solid var(--line); background: var(--surface); }
.rank-column { width: 48px; }
.ranking-table th { position: sticky; top: 0; z-index: 1; padding: 13px 15px; border-bottom: 1px solid var(--line); background: #f1f1ed; text-align: left; font-size: 11px; font-weight: 700; color: var(--faint); }
.ranking-table th.left { color: var(--left); }
.ranking-table th.right { color: var(--right); }
.ranking-table th:first-child { padding-left: 8px; padding-right: 8px; text-align: center; }
.ranking-table td { padding: 13px 15px; border-bottom: 1px solid #e9e8e2; vertical-align: top; }
.ranking-table td + td { border-left: 1px solid #e9e8e2; }
.ranking-table tbody tr:hover { background: #f5f7f2; }
.ranking-table .rank-number { padding-left: 4px; padding-right: 4px; text-align: center; color: var(--faint); font: 600 12px/1.5 var(--number-font); font-variant-numeric: tabular-nums lining-nums; }
.rank-number.top-three { color: var(--right); font-weight: 700; }
.player-block { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.player-details { min-width: 0; }
.player-name { display: block; color: var(--navy); font-size: 12px; line-height: 1.5; font-weight: 700; overflow-wrap: anywhere; }
.player-meta { display: flex; flex-wrap: wrap; gap: 3px 10px; margin-top: 5px; font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.player-alliance { color: var(--muted); }
.player-value { color: var(--navy); font: 600 14px/1.4 var(--number-font); font-variant-numeric: tabular-nums lining-nums; overflow-wrap: anywhere; }
td.left .player-alliance, td.left .player-value.is-leading { color: var(--left); }
td.right .player-alliance, td.right .player-value.is-leading { color: var(--right); }
.missing-player { display: block; color: #879098; font-size: 12px; line-height: 1.6; }
.empty-state { padding: 42px 16px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; }
.empty-state strong { font-size: 16px; }
.empty-state p { margin-top: 8px; color: var(--muted); font-size: 13px; }
.footer { padding: 20px 0 24px; border-top: 1px solid rgba(32, 53, 66, .12); color: var(--faint); font-size: 10px; }
.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: 700px) {
  .content-width { width: calc(100% - 30px); }
  .topbar-inner { min-height: 70px; }
  .query-section { padding-top: 24px; }
  .query-section > .content-width { padding: 21px 17px 19px; }
  h1 { font-size: 24px; }
  .mode-switch { margin: 18px 0; }
  .mode-tab { justify-content: center; min-height: 59px; gap: 0; padding: 8px 4px; }
  .mode-index { display: none; }
  .alliance-selection { padding: 14px 12px; }
  .alliance-fields { gap: 12px; }
  .query-form, .query-form.is-single { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .query-form.is-single .field:first-child { grid-column: 1 / -1; }
  .results { padding-top: 36px; }
  .result-heading { flex-direction: column; gap: 8px; }
  .result-heading h2 { font-size: 28px; }
  .kingdom-profile { padding: 14px 10px; }
  .profile-heading { display: block; min-height: 44px; margin-bottom: 12px; }
  .profile-redirect { display: block; margin-top: 4px; }
  .profile-heading h3 { font-size: 16px; }
  .profile-facts { grid-template-columns: minmax(0, 1fr); gap: 13px; }
  .profile-fact strong { font-size: 14px; }
  .profile-fact small { font-size: 10px; }
  .kingdom-profiles.single .profile-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dimension-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 14px 0; }
  .dimension-tab { min-width: 0; padding: 8px 3px; font-size: 12px; }
  .result-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-item { min-height: 106px; padding: 16px 12px; }
  .summary-item:nth-child(2) { border-right: 0; }
  .summary-item:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
  .summary-value { font-size: 23px; }
  .summary-value.is-text { font-size: 20px; }
  .insight-section > summary { display: list-item; min-height: 44px; padding: 12px 15px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--navy); background: rgba(255, 254, 250, .6); font-size: 13px; cursor: pointer; }
  .insight-grid { grid-template-columns: 1fr; margin-top: 12px; gap: 12px; }
  .chart-panel, .analysis-panel { padding: 21px 17px; }
  .bar-row { grid-template-columns: 48px minmax(0, 1fr) 70px; gap: 8px; }
  .ranking-toolbar { margin-top: 20px; flex-wrap: wrap; }
  .ranking-title { gap: 3px; flex-direction: column; }
  .ranking-title h3 { font-size: 22px; }
  .rank-column { width: 32px; }
  .ranking-table th { padding: 11px 8px; font-size: 13px; }
  .ranking-table th:first-child { padding: 11px 2px; font-size: 11px; }
  .ranking-table td { padding: 12px 8px; }
  .player-block { display: block; }
  .player-name { min-height: 36px; font-size: 13px; line-height: 18px; }
  .player-meta { display: grid; gap: 2px; margin-top: 4px; font-size: 10px; }
  .player-value { display: block; margin-top: 7px; font-size: 16px; }
  .ranking-table.single .player-block { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
  .ranking-table.single .player-name { min-height: 0; }
  .ranking-table.single .player-value { margin-top: 0; }
}

@media (max-width: 360px) {
  .ranking-table td { padding-left: 6px; padding-right: 6px; }
  .player-value { font-size: 15px; }
  .summary-value { font-size: 19px; }
}
