:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #181b22;
  --panel2: #1f2430;
  --panel-strong: #20242e;
  --line: #2a2f3a;
  --line-soft: #232834;
  --txt: #e7eaf0;
  --muted: #9aa3b2;
  --ink: #0f1115;
  --gold: #f5c451;
  --purple: #9b6cff;
  --green: #4ade80;
  --red: #f87171;
  --blue: #5eb1ff;
  --coral: #ff8a65;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(1100px 600px at 20% -10%, rgba(155, 108, 255, 0.10), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, rgba(94, 177, 255, 0.08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }

h1, h2, h3, p { margin: 0; }

.app-shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

/* ---------- Cards & panels ---------- */
.topbar,
.query-strip,
.filter-panel,
.pane,
.metric-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 24px;
  flex-wrap: wrap;
}

/* ---------- Space badge / gate ---------- */
.space-badge {
  display: inline-flex;
  align-items: center;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.space-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin-top: 14px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.space-panel[hidden] { display: none; }
.space-panel h2 { font-size: 18px; margin-bottom: 4px; }
.auth-panel { align-items: start; }
.auth-tabs { margin-top: 12px; }

.space-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.space-form input {
  width: 180px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: var(--bg);
  color: var(--txt);
}

.space-form input:focus {
  border-color: var(--purple);
  outline: none;
  box-shadow: 0 0 0 3px rgba(155, 108, 255, 0.18);
}

.auth-panel .space-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr)) auto;
  min-width: min(720px, 100%);
}

.auth-panel .space-form input {
  width: 100%;
}

.auth-panel .space-form input[hidden],
.auth-panel .recovery-box[hidden] {
  display: none;
}

.recovery-box {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid rgba(245, 196, 81, 0.34);
  border-radius: 10px;
  background: rgba(245, 196, 81, 0.08);
  color: var(--muted);
  font-size: 12.5px;
}

.recovery-box code {
  color: var(--gold);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  overflow-wrap: anywhere;
}

/* ---------- Footer ---------- */
.app-footer {
  width: min(1480px, calc(100vw - 32px));
  margin: 18px auto 0;
  padding: 14px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.app-footer .footer-name { color: var(--gold); font-weight: 700; }
.app-footer .footer-version { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--purple); }
.app-footer .footer-author { color: var(--blue); font-weight: 600; }
.app-footer .footer-sep { margin: 0 6px; opacity: 0.55; }
.footer-disclaimer {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--purple);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

h1 {
  font-size: clamp(24px, 3.4vw, 32px);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.legal-page {
  max-width: 880px;
}

.legal-copy {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  color: var(--txt);
}

.legal-copy p {
  color: var(--muted);
}

.top-actions,
.button-row,
.card-actions,
.pane-head,
.tag-form,
.legend {
  display: flex;
  align-items: center;
}

.top-actions,
.button-row,
.card-actions {
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Query strip ---------- */
.query-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin-top: 14px;
  padding: 14px 16px;
}

.query-forms {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.tag-form {
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.clan-import-form {
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.tag-form label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.tag-form input {
  width: min(360px, 45vw);
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: var(--bg);
  color: var(--txt);
  text-transform: uppercase;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  letter-spacing: 0.04em;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.clan-import-form input {
  width: min(300px, 40vw);
}

.tag-form input:focus {
  border-color: var(--purple);
  outline: none;
  box-shadow: 0 0 0 3px rgba(155, 108, 255, 0.18);
}

.status {
  max-width: 540px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  font-weight: 500;
}

.status[data-tone="ok"] { color: var(--green); }
.status[data-tone="error"] { color: var(--red); }

/* ---------- Buttons ---------- */
.primary-btn,
.ghost-btn,
.danger-btn,
.icon-btn,
.segment {
  min-height: 38px;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 600;
  font-size: 13.5px;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.primary-btn {
  background: linear-gradient(135deg, var(--purple), #6f3dff);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(155, 108, 255, 0.25);
}

.primary-btn:hover { transform: translateY(-1px); }

.ghost-btn,
.icon-btn,
.segment {
  background: var(--panel2);
  border-color: var(--line);
  color: var(--txt);
}
.ghost-btn:hover,
.segment:hover {
  background: var(--panel-strong);
  border-color: var(--line);
  color: var(--txt);
}

.ghost-btn.danger {
  color: var(--red);
}

.danger-btn {
  background: rgba(248, 113, 113, 0.10);
  border-color: rgba(248, 113, 113, 0.30);
  color: var(--red);
}
.danger-btn:hover {
  background: rgba(248, 113, 113, 0.20);
  border-color: var(--red);
}

.icon-btn {
  width: 42px;
  padding: 0;
  font-size: 18px;
  display: grid;
  place-items: center;
}

.compact { min-height: 30px; padding: 0 10px; font-size: 12px; }

.primary-btn:disabled,
.ghost-btn:disabled,
.danger-btn:disabled,
.icon-btn:disabled {
  cursor: progress;
  opacity: 0.55;
  transform: none;
}

.hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ---------- Month filter ---------- */
.filter-panel {
  margin-top: 14px;
  padding: 16px;
}

.month-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
  margin-top: 12px;
}

.month-chip {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px;
  background: var(--panel2);
  color: var(--muted);
  font-weight: 600;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
  transition: all 0.12s ease;
}

.month-chip:hover {
  border-color: var(--purple);
  color: var(--txt);
}

.month-chip.active {
  background: linear-gradient(135deg, rgba(155, 108, 255, 0.18), rgba(94, 177, 255, 0.14));
  border-color: var(--purple);
  color: var(--txt);
  box-shadow: inset 0 0 0 1px rgba(155, 108, 255, 0.30);
}

.role-filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.filter-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.player-search-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin: -2px 0 12px;
}

.player-search-row label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.player-search-row input {
  min-height: 34px;
  border: 1px solid var(--line);
  background: var(--panel2);
  border-radius: 8px;
  padding: 0 11px;
  outline: none;
}

.player-search-row input:focus {
  border-color: rgba(79, 195, 247, 0.7);
  box-shadow: 0 0 0 3px rgba(79, 195, 247, 0.10);
}

/* ---------- Metrics grid ---------- */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.metric-panel {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 88px;
  position: relative;
  overflow: hidden;
}

.metric-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 50%);
  pointer-events: none;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.metric-panel strong {
  font-size: 22px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.metric-sub {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.3;
}

.v.gold { color: var(--gold); }
.v.green { color: var(--green); }
.v.purple { color: var(--purple); }
.v.blue { color: var(--blue); }
.v.red { color: var(--red); }
.v.coral { color: var(--coral); }

/* ---------- Pane / grid layout ---------- */
.workspace-grid,
.detail-grid {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

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

/* New single-column layout: trend (full width) → detail (collapsible) → compare (full width) */
.attention-section,
.trend-section,
.compare-section {
  margin-top: 14px;
}

.detail-section,
.clan-wars-section,
.legend-rankings-section {
  margin-top: 14px;
}

.clan-wars-wrap,
.legend-rankings-wrap {
  overflow-x: auto;
}

.detail-head {
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--muted);
}
.detail-head b {
  color: var(--gold);
  font-size: 16px;
}

.detail-collapse {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.detail-collapse > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-weight: 600;
  color: var(--txt);
  transition: background 0.15s ease;
}

.detail-collapse > summary::-webkit-details-marker { display: none; }
.detail-collapse > summary:hover { background: var(--panel-strong); }

.detail-collapse > summary .caret {
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.15s ease;
  display: inline-block;
}

.detail-collapse[open] > summary .caret { transform: rotate(90deg); }
.detail-collapse[open] > summary { border-bottom: 1px solid var(--line); }

.detail-collapse > summary > span:nth-child(2) { font-size: 15px; }
.detail-collapse > summary .subtle { font-weight: 400; }

.detail-collapse > .pane { border: 0; border-radius: 0; box-shadow: none; padding: 14px; }

.pane {
  min-width: 0;
  padding: 16px;
}

.pane h2 {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pane-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.subtle {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}

.mut {
  color: var(--muted);
}

/* ---------- Segmented control ---------- */
.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 2px;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

#roleFilter,
#trendMetricToggle {
  display: inline-flex;
  flex-wrap: wrap;
  max-width: 100%;
}

.segment {
  min-height: 28px;
  border: 0;
  padding: 0 12px;
  color: var(--muted);
  font-size: 12.5px;
  background: transparent;
  border-radius: 7px;
  white-space: nowrap;
}

.segment:hover { color: var(--txt); }

.segment.active {
  background: linear-gradient(135deg, var(--purple), #6f3dff);
  color: white;
  box-shadow: 0 2px 6px rgba(155, 108, 255, 0.30);
}

/* ---------- Leader attention ---------- */
.attention-list {
  min-width: 0;
}

.attention-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel2);
}

.attention-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 12.5px;
}

.attention-table th,
.attention-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
  text-align: left;
}

.attention-table th {
  color: var(--muted);
  font-weight: 700;
  background: var(--panel-strong);
}

.attention-table tbody tr {
  cursor: pointer;
  transition: background 0.15s ease;
}

.attention-table tbody tr:hover,
.attention-table tbody tr:focus {
  background: rgba(155, 108, 255, 0.08);
  outline: none;
}

.attention-player {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.attention-player b,
.attention-player small,
.attention-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attention-player b { font-size: 13.5px; }
.attention-player small,
.attention-meta {
  color: var(--muted);
  font-size: 11.5px;
}

.attention-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.attention-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.03);
}

.attention-chip.high {
  color: var(--red);
  border-color: rgba(248, 113, 113, 0.32);
  background: rgba(248, 113, 113, 0.09);
}

.attention-chip.medium {
  color: var(--gold);
  border-color: rgba(245, 196, 81, 0.34);
  background: rgba(245, 196, 81, 0.08);
}

.attention-chip.low {
  color: var(--blue);
  border-color: rgba(94, 177, 255, 0.30);
  background: rgba(94, 177, 255, 0.08);
}

.priority-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11.5px;
  font-weight: 800;
}

.priority-pill.high {
  color: var(--red);
  border-color: rgba(248, 113, 113, 0.34);
  background: rgba(248, 113, 113, 0.10);
}

.priority-pill.medium {
  color: var(--gold);
  border-color: rgba(245, 196, 81, 0.36);
  background: rgba(245, 196, 81, 0.10);
}

.priority-pill.low {
  color: var(--blue);
  border-color: rgba(94, 177, 255, 0.32);
  background: rgba(94, 177, 255, 0.10);
}

.detail-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

/* ---------- Player list ---------- */
.player-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}

.player-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px 12px;
  background: var(--panel2);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.player-card:hover {
  border-color: var(--line);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.player-card.selected {
  border-color: var(--purple);
  box-shadow: 0 0 0 1px var(--purple), 0 8px 22px rgba(155, 108, 255, 0.20);
  background: linear-gradient(180deg, rgba(155, 108, 255, 0.06), var(--panel2));
}

.select-surface {
  position: absolute;
  inset: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  z-index: 2;
}

.player-main,
.stat-grid {
  position: relative;
  z-index: 1;
}

.player-meta,
.card-foot {
  position: relative;
  z-index: 3;
}

.player-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.player-id { min-width: 0; }

.player-name {
  max-width: 220px;
  overflow-wrap: anywhere;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.player-tag {
  margin-top: 3px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.th-chip {
  display: inline-grid;
  place-items: center;
  min-width: 46px;
  height: 30px;
  border-radius: 8px;
  background: rgba(94, 177, 255, 0.14);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(94, 177, 255, 0.30);
  letter-spacing: 0.02em;
}

/* League pills (CWL clan tier + trophy league) */
.player-leagues,
.selected-leagues {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.league-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  border: 1px solid;
}

.league-pill.cwl-tier {
  background: linear-gradient(135deg, rgba(245, 196, 81, 0.18), rgba(245, 196, 81, 0.08));
  border-color: rgba(245, 196, 81, 0.45);
  color: var(--gold);
}

.league-pill.cwl-tier::before {
  content: "⚔";
  font-size: 10px;
}

.league-pill.trophy-league {
  background: linear-gradient(135deg, rgba(155, 108, 255, 0.20), rgba(155, 108, 255, 0.08));
  border-color: rgba(155, 108, 255, 0.45);
  color: var(--purple);
}

.league-pill.trophy-league::before {
  content: "🏆";
  font-size: 9px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 14px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding-left: 10px;
  border-left: 2px solid var(--line);
}

.stat b {
  display: block;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.player-meta {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  gap: 8px;
}

.role-select,
.note-input {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--txt);
  padding: 0 9px;
  font-size: 12.5px;
}

.role-select:focus,
.note-input:focus {
  border-color: var(--purple);
  outline: none;
  box-shadow: 0 0 0 3px rgba(155, 108, 255, 0.14);
}

.note-input::placeholder { color: var(--muted); }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px dashed var(--line-soft);
}

.card-meta-line {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.player-seasons {
  color: var(--muted);
  font-size: 11.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.player-cache-age {
  width: fit-content;
  max-width: 100%;
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
  color: var(--muted);
  background: rgba(154, 163, 178, 0.08);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.player-cache-age[data-tone="fresh"] {
  color: var(--green);
  border-color: rgba(74, 222, 128, 0.26);
  background: rgba(74, 222, 128, 0.09);
}

.player-cache-age[data-tone="stale"] {
  color: var(--gold);
  border-color: rgba(245, 196, 81, 0.30);
  background: rgba(245, 196, 81, 0.10);
}

.card-actions { gap: 6px; }

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-weight: 500;
  text-align: center;
  padding: 20px;
  background: var(--bg);
}

.compact-empty {
  width: 100%;
  min-height: 36px;
  padding: 8px 12px;
}

/* ---------- Compare bar chart ---------- */
.bar-chart {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.36fr) minmax(0, 1fr) 84px;
  gap: 12px;
  align-items: center;
  padding: 6px 4px;
  border-radius: 8px;
  transition: background 0.15s ease;
}

.bar-row:hover { background: var(--panel-strong); }

.bar-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.bar-label .name { color: var(--txt); }
.bar-label .tag { color: var(--muted); font-size: 11px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.bar-track {
  position: relative;
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #272d3a;
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--purple), var(--blue));
  transition: width 0.4s ease;
}

.bar-fill.gold { background: linear-gradient(90deg, var(--gold), #ffd97a); }
.bar-fill.green { background: linear-gradient(90deg, var(--green), #a7f3d0); }
.bar-fill.blue { background: linear-gradient(90deg, var(--blue), #b6dcff); }
.bar-fill.purple { background: linear-gradient(90deg, var(--purple), #c4a8ff); }
.bar-fill.net { background: linear-gradient(90deg, #2dd4bf, #5eb1ff); }

/* ---------- Net (正负值) bar row: centered around 0 ---------- */
.bar-row.net-bar {
  grid-template-columns: minmax(120px, 0.36fr) minmax(0, 1fr) 84px;
}
.bar-track.net-track {
  height: 16px;
  background:
    linear-gradient(to right,
      transparent 0%,
      transparent calc(50% - 1px),
      rgba(255, 255, 255, 0.12) calc(50% - 1px),
      rgba(255, 255, 255, 0.12) calc(50% + 1px),
      transparent calc(50% + 1px),
      transparent 100%);
}
.bar-track.net-track { position: relative; }
.bar-track.net-track .bar-zero {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 1px;
  background: rgba(255, 255, 255, 0.18);
}
.bar-track.net-track .bar-fill {
  position: absolute;
  top: 0; bottom: 0;
  width: 0;
}
.bar-track.net-track .bar-fill.net-positive { left: 50%; }
.bar-track.net-track .bar-fill.net-negative { right: 50%; }
.bar-track.net-track .bar-fill.net-positive { background: linear-gradient(90deg, #2dd4bf, #5eb1ff); }
.bar-track.net-track .bar-fill.net-negative { background: linear-gradient(90deg, #f87171, #ff8a65); }
.bar-value .net-pos { color: #2dd4bf; }
.bar-value .net-neg { color: #f87171; }
.bar-value .net-zero { color: var(--muted); }

.bar-value {
  color: var(--txt);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.bar-value .mut { color: var(--muted); font-weight: 500; font-size: 11px; margin-left: 4px; }

/* ---------- Season chart ---------- */
.legend { gap: 12px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-item[hidden] { display: none; }
.legend .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.legend small { color: var(--muted); }

.season-chart-wrap {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.season-chart {
  display: block;
  width: 100%;
  max-width: 100%;
  min-height: 350px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}

.season-line-svg {
  display: block;
  min-width: 100%;
  max-width: none;
  height: auto;
}

.season-line-plot {
  fill: rgba(255, 255, 255, 0.025);
  stroke: rgba(255, 255, 255, 0.07);
}

.season-line-grid {
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 1;
}

.season-line-tick,
.season-axis-label,
.season-point-label {
  color: var(--muted);
  fill: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.season-point-label {
  fill: var(--txt);
  font-weight: 700;
  paint-order: stroke;
  stroke: var(--panel2);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.season-line {
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.season-point {
  stroke: var(--panel2);
  stroke-width: 2;
}

/* season table (under chart) */
.season-table-wrap {
  margin-top: 12px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel2);
}

table.season-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

table.season-table th,
table.season-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}

table.season-table th:first-child,
table.season-table td:first-child { text-align: left; }

table.season-table thead th {
  position: sticky;
  top: 0;
  background: var(--panel-strong);
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

table.season-table tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

.clan-war-table {
  min-width: 760px;
  margin-top: 10px;
}

.clan-war-table.recent {
  min-width: 900px;
}

.clan-war-subhead {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
}

.legend-ranking-table {
  min-width: 860px;
  margin-top: 10px;
}

.legend-ranking-table th,
.legend-ranking-table td {
  white-space: nowrap;
}

.rank-value {
  color: var(--gold);
  font-weight: 800;
}

.result-pill,
.attack-chip {
  display: inline-grid;
  place-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
}

.result-pill.win {
  color: var(--green);
  background: rgba(74, 222, 128, 0.10);
  border-color: rgba(74, 222, 128, 0.22);
}

.result-pill.loss {
  color: var(--red);
  background: rgba(248, 113, 113, 0.10);
  border-color: rgba(248, 113, 113, 0.22);
}

.result-pill.tie,
.result-pill.unknown {
  color: var(--muted);
  background: rgba(154, 163, 178, 0.10);
  border-color: rgba(154, 163, 178, 0.22);
}

.result-pill.ongoing {
  color: var(--blue);
  background: rgba(94, 177, 255, 0.10);
  border-color: rgba(94, 177, 255, 0.22);
}

.attack-chip {
  margin-right: 4px;
  margin-bottom: 2px;
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line-soft);
}

.stars3 { color: var(--gold); font-weight: 700; }
.stars2 { color: #cdd3dd; }
.stars1 { color: #a07b3a; }
.stars0 { color: var(--red); }

/* ---------- Admin ---------- */
.admin-shell {
  max-width: 1360px;
}

.admin-key-form,
.admin-toolbar,
.admin-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-key-form input,
.admin-toolbar input {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
  color: var(--txt);
  padding: 0 10px;
  outline: none;
}

.admin-key-form input {
  width: min(360px, 100%);
}

.admin-toolbar input {
  width: 180px;
}

.admin-result {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(74, 222, 128, 0.24);
  border-radius: 8px;
  background: rgba(74, 222, 128, 0.08);
  color: var(--green);
  overflow-wrap: anywhere;
}

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel2);
}

table.admin-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

table.admin-table th,
table.admin-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

table.admin-table thead th {
  position: sticky;
  top: 0;
  background: var(--panel-strong);
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.admin-id {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10.5px;
}

.status-pill {
  display: inline-grid;
  place-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  border: 1px solid transparent;
}

.status-pill.active {
  color: var(--green);
  background: rgba(74, 222, 128, 0.10);
  border-color: rgba(74, 222, 128, 0.22);
}

.status-pill.blocked {
  color: var(--red);
  background: rgba(248, 113, 113, 0.10);
  border-color: rgba(248, 113, 113, 0.22);
}

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .overview-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 1180px) {
  .overview-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .overview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .app-shell { width: calc(100vw - 20px); padding-top: 12px; }
  .topbar, .query-strip, .space-panel { display: grid; grid-template-columns: 1fr; }
  .space-form { justify-content: stretch; }
  .auth-panel .space-form { grid-template-columns: 1fr; min-width: 0; }
  .space-form input, .space-form button { width: 100%; }
  .status { text-align: left; max-width: none; }
  .query-strip { gap: 12px; }
  .tag-form input, .tag-form button { width: 100%; }
  .player-search-row { grid-template-columns: 1fr; }
  .overview-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .player-list { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .player-meta { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 96px minmax(0, 1fr) 64px; }
}

@media (max-width: 520px) {
  .pane-head { flex-direction: column; align-items: flex-start; }
  .overview-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Share card modal ---------- */
.share-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.72);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 24px;
  backdrop-filter: blur(4px);
}

.share-overlay[hidden] { display: none; }

.share-modal {
  width: min(960px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.share-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
}

.share-head h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--txt);
  margin: 0;
}

.share-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  overflow: auto;
}

.share-body canvas {
  width: 100%;
  max-width: 900px;
  height: auto;
  border-radius: 10px;
  background: #0f1115;
  display: block;
}

.share-meta {
  width: 100%;
  max-width: 900px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  line-height: 1.6;
}

.share-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--panel2);
}

@media (max-width: 600px) {
  .share-overlay { padding: 8px; }
  .share-foot { flex-direction: column; }
  .share-foot button { width: 100%; }
}
