/* Kingshot Tracker — clean modern theme (light + dark) */

:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg0: #0f1115;
  --bg1: #141820;
  --panel: #181c24;
  --panel2: #1c212b;
  --panel-edge: #2a3140;
  --text: #eef1f6;
  --muted: #9aa3b2;
  --faint: #6b7383;
  --accent: #5b8def;
  --accent-dim: #3d6fd4;
  --accent-glow: rgba(91, 141, 239, 0.18);
  --accent-text: #ffffff;
  --ember: #e0a04a;
  --ember-dim: #b07a30;
  --ok: #3ecf8e;
  --warn: #e0b04a;
  --danger: #e06a5c;
  --chip: #222836;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  --header-border: rgba(255, 255, 255, 0.06);
  --input-bg: #0f131a;
  --btn-secondary-bg: transparent;
  --btn-secondary-border: var(--panel-edge);
  --btn-secondary-text: var(--text);
  --hero-grad: linear-gradient(135deg, #181c24 0%, #1a2233 100%);
  --inset: rgba(0, 0, 0, 0.22);
  --inset-strong: rgba(0, 0, 0, 0.32);
}

[data-theme="light"] {
  color-scheme: light;
  --bg0: #f4f5f7;
  --bg1: #eef0f4;
  --panel: #ffffff;
  --panel2: #f8f9fb;
  --panel-edge: #e2e6ee;
  --text: #151921;
  --muted: #5c6575;
  --faint: #8b93a3;
  --accent: #3b6fd9;
  --accent-dim: #2f5bb8;
  --accent-glow: rgba(59, 111, 217, 0.14);
  --accent-text: #ffffff;
  --ember: #c8862a;
  --ember-dim: #a56c1e;
  --ok: #1fa86a;
  --warn: #c4921f;
  --danger: #d14b3d;
  --chip: #eef1f6;
  --shadow: 0 6px 20px rgba(20, 28, 45, 0.08);
  --header-border: rgba(20, 28, 45, 0.08);
  --input-bg: #ffffff;
  --btn-secondary-bg: #ffffff;
  --btn-secondary-border: var(--panel-edge);
  --btn-secondary-text: var(--text);
  --hero-grad: linear-gradient(135deg, #ffffff 0%, #f0f4fb 100%);
  --inset: rgba(20, 28, 45, 0.04);
  --inset-strong: rgba(20, 28, 45, 0.08);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  font-family: var(--font);
  overflow-x: hidden;
  background: var(--bg0);
  transition: background 0.2s ease, color 0.2s ease;
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 16px 72px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  width: 100%;
}

/* —— Header —— */
.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--header-border);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--text);
}
.logo::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
  transform: translateY(-1px);
}

.nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}
.nav a,
.nav-btn {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 6px 12px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.2;
  transition: background 0.15s, color 0.15s;
}
.nav a:hover,
.nav-btn:hover,
.nav a.active,
.nav-btn.active {
  color: var(--text);
  background: var(--chip);
}

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

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.theme-toggle:hover {
  border-color: var(--accent);
  background: var(--chip);
}
[data-theme="dark"] .theme-icon-moon { display: none; }
[data-theme="light"] .theme-icon-sun { display: none; }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  max-width: min(100%, 520px);
}
.stat {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  min-width: 4.6rem;
  flex: 0 1 auto;
  text-align: center;
}
.stat b {
  display: block;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 700;
  line-height: 1.2;
}
.stat span {
  color: var(--muted);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* —— Global search panel —— */
.global-search {
  margin-bottom: 16px;
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.global-search[hidden] { display: none !important; }
.global-search-inner {
  padding: 14px 16px 16px;
}
.deep-search-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--panel-edge);
  background: var(--panel2);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  justify-content: space-between;
}
.deep-search-box[hidden] { display: none !important; }
.deep-search-copy {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  flex: 1 1 12rem;
}
.btn-deep {
  background: transparent !important;
  color: var(--accent) !important;
  border: 1px solid var(--accent) !important;
  box-shadow: none !important;
  font-weight: 650;
  white-space: nowrap;
}
.btn-deep:hover {
  background: var(--accent-glow) !important;
}

/* —— Panels —— */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.section-title {
  margin: 18px 0 10px;
  font-size: 0.78rem;
  color: var(--faint);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  font-weight: 700;
}

/* —— Search —— */
.search-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
input[type="search"],
input[type="text"],
input[type="password"],
input[type="number"],
select {
  flex: 1 1 12rem;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--panel-edge);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

button, .btn {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  font-family: inherit;
}
button:hover { filter: brightness(1.05); }
button.secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border: 1px solid var(--btn-secondary-border);
}
button.danger {
  background: var(--danger);
  color: #fff;
  border: 1px solid transparent;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

.hint {
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 10px;
  line-height: 1.45;
}
.danger-hint { color: #e8a59c; }

/* display:flex would override the HTML [hidden] attribute — keep both. */
.search-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--accent);
  font-size: 0.9rem;
}
.search-loading[hidden] {
  display: none !important;
}
.spinner, .btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--panel-edge);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
.spinner[hidden],
.btn-spinner[hidden] {
  display: none !important;
}
#btnSearch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 7.5rem;
}
#btnSearch.searching .btn-label {
  opacity: 0.85;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* —— Results —— */
.results { display: grid; gap: 10px; margin-top: 12px; }
.results.searching { opacity: 0.55; pointer-events: none; }

.card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg0);
  border: 1px solid var(--panel-edge);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s;
}
.card:hover {
  border-color: var(--accent-dim);
  transform: translateY(-1px);
}
.card-avatar {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--chip);
  border: 1px solid var(--panel-edge);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: var(--accent);
  overflow: hidden;
}
.card-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 700;
}
.meta {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.badge {
  display: inline-block;
  background: var(--chip);
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 650;
  color: var(--muted);
  margin-right: 4px;
}
.badge.ok { color: var(--ok); border-color: rgba(94, 211, 154, 0.35); }
.badge.warn { color: var(--warn); border-color: rgba(224, 176, 74, 0.35); }
.badge.pink {
  color: var(--ember);
  border-color: rgba(224, 160, 74, 0.4);
}

/* —— Profile (Governor card) —— */
.profile-shell { margin-top: 4px; }
.profile-card,
.gov-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  color: var(--text);
}
.profile-loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg0) 72%, transparent);
  backdrop-filter: blur(3px);
}
.profile-loading[hidden] {
  display: none !important;
}
.profile-loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 28px;
  border-radius: var(--radius);
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--accent);
  font-weight: 650;
  box-shadow: var(--shadow);
}
.profile-spinner {
  width: 28px;
  height: 28px;
  border-width: 3px;
}
.gov-card.is-loading .gov-banner,
.gov-card.is-loading .gov-tabs,
.gov-card.is-loading .gov-tab-body {
  opacity: 0.35;
  pointer-events: none;
}
.profile-loading-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.profile-body {
  min-height: 120px;
}
/* Soft floating toast while deep enrich runs */
.profile-sync-toast {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  justify-content: center;
  padding: 0 14px;
  margin: -6px 0 4px;
  pointer-events: none;
}
.profile-sync-toast[hidden] {
  display: none !important;
}
.profile-sync-toast-inner {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  max-width: min(100%, 420px);
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: color-mix(in srgb, var(--panel) 92%, var(--accent) 8%);
  box-shadow: var(--shadow);
  pointer-events: none;
}
.profile-sync-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.profile-sync-copy strong {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.profile-sync-copy span {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.25;
}
.profile-sync-ring {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}
.btn-refresh.is-syncing {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.btn-refresh.is-syncing .btn-refresh-icon {
  animation: spin 0.9s linear infinite;
  color: var(--accent);
}
.gov-card.is-enriching .gov-tab-body {
  /* keep content readable while skeletons fill gaps */
}

/* Section skeletons for missing deep data */
.section-skeleton {
  display: grid;
  gap: 10px;
}
.section-skeleton-gear,
.section-skeleton-skins {
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
}
.section-skeleton-heroes {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
.section-skeleton-ranks {
  grid-template-columns: 1fr;
}
.skel-tile,
.skel-hero,
.skel-line {
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--panel2) 0%,
    color-mix(in srgb, var(--chip) 70%, var(--panel2)) 50%,
    var(--panel2) 100%
  );
  background-size: 200% 100%;
  animation: skel-shimmer 1.2s ease-in-out infinite;
  border: 1px solid var(--panel-edge);
}
.skel-tile {
  height: 108px;
}
.skel-hero {
  height: 160px;
}
.skel-line {
  height: 44px;
}
.section-pending-hint {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}
@keyframes skel-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.privacy-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px 14px;
  border-radius: 14px;
  border: 1px dashed rgba(224, 160, 74, 0.35);
  background: rgba(224, 160, 74, 0.06);
  color: var(--ember);
  font-weight: 650;
  text-align: center;
  line-height: 1.45;
}
.privacy-lock {
  font-size: 1.1rem;
  flex-shrink: 0;
}
.gov-banner,
.profile-hero {
  position: relative;
  padding: 22px 18px 16px;
  text-align: left;
  background: var(--panel2);
  border-bottom: 1px solid var(--panel-edge);
}
.gov-banner-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  align-items: flex-start;
  justify-content: space-between;
  padding-left: 44px; /* room for back btn */
}
.gov-banner-main {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 20px;
  align-items: flex-start;
  flex: 1 1 18rem;
  min-width: 0;
}
.gov-refresh-panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  margin-left: auto;
}
.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: none;
  min-width: 148px;
  text-align: left;
}
.btn-refresh:hover {
  filter: brightness(1.08);
  border-color: var(--accent);
}
.btn-refresh:disabled {
  opacity: 0.55;
  cursor: wait;
}
.btn-refresh-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--inset-strong);
  border: 1px solid var(--panel-edge);
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1;
  flex-shrink: 0;
}
.btn-refresh-copy {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.btn-refresh-label {
  font-size: 0.92rem;
  letter-spacing: 0.02em;
}
.btn-refresh .enrich-status {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.gov-portrait {
  position: relative;
  flex: 0 0 auto;
}
.gov-skin-badge {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 2px solid var(--panel-edge);
  background: var(--bg0);
  overflow: hidden;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}
.gov-skin-badge img,
.city-skin-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gov-identity {
  flex: 1 1 16rem;
  min-width: 0;
}
.gov-name,
.profile-name {
  margin: 0 0 6px;
  font-size: clamp(1.35rem, 3.5vw, 1.75rem);
  font-weight: 850;
  letter-spacing: -0.02em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.gov-sub,
.profile-sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 10px;
  line-height: 1.45;
}
.gov-stat-bar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}
.gov-stat {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}
.gov-stat.is-on {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--panel-edge));
  background: color-mix(in srgb, var(--ok) 10%, var(--panel));
}
.gov-stat.is-burn {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--panel-edge));
  background: color-mix(in srgb, var(--danger) 10%, var(--panel));
}
.gov-stat.is-burn b { color: var(--danger); }
.gov-stat.is-on b { color: var(--ok); }
.gov-stat b {
  display: block;
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.chip.chip-ok {
  border-color: rgba(94, 211, 154, 0.4);
  color: var(--ok);
}
.chip.chip-warn {
  border-color: rgba(224, 106, 92, 0.45);
  color: #f0a090;
}
.gov-fact .v.warn { color: var(--danger); }
.gov-stat span {
  display: block;
  margin-top: 2px;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}
.gov-tabs {
  background: var(--panel);
}
.gov-tab-body {
  padding: 16px;
  background: var(--panel);
}
.gov-section {
  margin-bottom: 18px;
}
.gov-section-title {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.gov-facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 8px;
}
.gov-fact {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel2);
  border: 1px solid var(--panel-edge);
  font-size: 0.9rem;
}
.gov-fact .k { color: var(--muted); }
.gov-fact .v {
  font-weight: 700;
  text-align: right;
  min-width: 0;
  overflow-wrap: anywhere;
}
.lord-gear-rack,
.skin-rack {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
}
.lord-gear-tile,
.skin-tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--panel2);
  border: 1px solid var(--panel-edge);
  min-width: 0;
}
.lord-gear-icon-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  margin: 0 auto;
  flex-shrink: 0;
}
.lord-gear-icon,
.skin-icon-wrap,
.gear-tile-icon {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: var(--inset-strong);
  border: 1px solid var(--panel-edge);
  display: grid;
  place-items: center;
  overflow: hidden;
  margin: 0 auto;
}
.lord-gear-icon-wrap .lord-gear-icon {
  width: 64px;
  height: 64px;
  margin: 0;
}
/* Level badge on the gear icon */
.lord-gear-lv {
  position: absolute;
  right: -4px;
  bottom: -4px;
  min-width: 22px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid color-mix(in srgb, var(--ember) 55%, var(--panel-edge));
  box-shadow: 0 2px 8px var(--inset-strong);
  color: var(--ember);
  font-size: 0.72rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 18px;
  text-align: center;
  pointer-events: none;
}
.lord-gear-stars {
  position: absolute;
  left: 50%;
  top: -2px;
  transform: translateX(-50%);
  font-size: 0.55rem;
  letter-spacing: -0.04em;
  color: #fbbf24;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}
.gear-icon,
.skin-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  image-rendering: auto;
}
.icon-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-weight: 800;
  color: var(--accent);
  background: var(--chip);
}
.lord-gear-meta,
.skin-meta {
  display: grid;
  gap: 2px;
  text-align: center;
  min-width: 0;
}
.gear-name,
.skin-name {
  font-size: 0.78rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.skin-name-na {
  color: var(--muted);
  font-weight: 600;
  font-style: italic;
}
.skin-tile-missing {
  opacity: 0.88;
}
.skin-tile-missing .skin-icon-wrap {
  border-style: dashed;
  color: var(--muted);
}
.skin-type,
.gear-slot {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.profile-hero {
  /* legacy alias kept for absolute back-btn rule */
}
/* Back control: in-flow by default (page heroes / alliance). Absolute only on profile. */
.icon-btn {
  position: relative;
  flex: 0 0 auto;
  align-self: flex-start;
  display: inline-grid;
  place-items: center;
  background: var(--bg0);
  border: 1px solid var(--panel-edge);
  color: var(--text);
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 10px;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  z-index: 2;
  cursor: pointer;
}
.icon-btn:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
  filter: none;
}
.profile-hero > .icon-btn,
.gov-banner > .icon-btn {
  position: absolute;
  left: 12px;
  top: 12px;
}
.avatar-wrap { display: flex; justify-content: center; margin-bottom: 10px; }
.avatar {
  width: 96px;
  height: 96px;
  border-radius: 22px;
  background: var(--chip);
  border: 2px solid var(--accent-dim);
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  overflow: hidden;
  box-shadow: 0 0 0 4px var(--accent-glow), 0 12px 28px var(--inset-strong);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.gov-banner .chip-row { justify-content: flex-start; }
.gov-banner .profile-actions { justify-content: flex-start; }
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
}
.chip {
  background: var(--chip);
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--text);
}
.tag {
  display: inline-block;
  background: rgba(224, 160, 74, 0.12);
  border: 1px solid rgba(224, 160, 74, 0.35);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ember);
}
.profile-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
.enrich-status {
  color: var(--muted);
  font-size: 0.82rem;
}

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--panel-edge);
  background: var(--panel);
}
.tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  padding: 12px 8px;
  font-weight: 650;
  font-size: 0.85rem;
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: transparent;
}
.tab-body { padding: 16px; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.ov-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 12px;
}
.ov-card {
  background: var(--bg0);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 14px;
}
.ov-card h3 {
  margin: 0 0 10px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  font-weight: 700;
}
.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--panel-edge);
  font-size: 0.9rem;
}
.row:last-child { border-bottom: 0; }
.row .k { color: var(--muted); flex: 0 1 auto; min-width: 0; }
.row .v {
  font-weight: 650;
  text-align: right;
  min-width: 0;
  overflow-wrap: anywhere;
}
.row .v.ok { color: var(--ok); }

.battle-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.battle-stat {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}
.battle-stat b {
  display: block;
  font-size: 1rem;
  color: var(--ember);
}
.battle-stat span {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lb-list { display: grid; gap: 8px; }
.lb-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
}
.lb-name { font-weight: 650; }
.lb-val {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

/* —— Heroes & gear —— */
.heroes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.hero-card {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  background: var(--bg0);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  padding: 12px;
  border-top: 3px solid var(--accent-dim);
}
.hero-card.q-legend { border-top-color: var(--ember); }
.hero-card.q-mythic { border-top-color: #c47cff; }

.hero-portrait {
  position: relative;
  width: 96px;
  height: 96px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--panel2);
  border: 1px solid var(--panel-edge);
  display: grid;
  place-items: center;
}
.hero-portrait .hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.hero-fallback {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent);
}
.hero-stars {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  color: var(--ember);
  font-size: 0.72rem;
  letter-spacing: 1px;
  text-align: center;
  padding: 10px 2px 4px;
}

.hero-body h4 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 800;
}
.hero-stats-text {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 0.82rem;
}
.hero-stats-text > div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.hero-stats-text .k { color: var(--muted); }
.hero-stats-text .v {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.gear-heading {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  font-weight: 700;
  margin-bottom: 6px;
}
.gear-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 8px;
}
.gear-tile {
  background: var(--inset-strong);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 56px;
  text-align: center;
  min-width: 0;
}
.gear-tile .gear-tile-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--inset-strong);
  border: 1px solid var(--panel-edge);
  display: grid;
  place-items: center;
}
.gear-tile.exclusive {
  border-color: rgba(224, 160, 74, 0.55);
  background: linear-gradient(145deg, rgba(224, 160, 74, 0.12), var(--panel));
}
.gear-tile .gear-slot {
  font-size: 0.65rem;
  font-weight: 750;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.gear-tile.exclusive .gear-slot { color: var(--ember); }
.gear-stat {
  font-size: 0.72rem;
  color: var(--muted);
}
.gear-stat b {
  color: var(--text);
  font-weight: 700;
}

/* —— History / members —— */
.hist-list, .member-list { display: grid; gap: 8px; }
.hist-row, .member-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg0);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
}
.member-row { cursor: pointer; grid-template-columns: auto auto 1fr auto; }
.member-row:hover { border-color: var(--accent-dim); }
.hist-avatar, .member-av {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--chip);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: var(--accent);
  overflow: hidden;
}
.member-av.letter { font-size: 0.9rem; }
.member-av img, img.member-av {
  width: 36px;
  height: 36px;
  object-fit: cover;
}
.rank-pill {
  min-width: 36px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--muted);
  background: var(--chip);
  border-radius: 8px;
  padding: 4px 6px;
}
.rank-pill.leader {
  color: var(--ember);
  border: 1px solid rgba(224, 160, 74, 0.4);
}
.power {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ember);
}
.hist-date { color: var(--muted); font-size: 0.8rem; text-align: right; }
.hist-summary {
  margin-top: 6px;
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.4;
  opacity: 0.92;
}

/* —— Alliance page —— */
.alliance-link {
  color: var(--ember);
  text-decoration: none;
  font-weight: 750;
}
.alliance-link:hover { text-decoration: underline; color: var(--accent); }
.alliance-page-hero {
  margin-bottom: 12px;
  padding: 0;
}
.alliance-hero {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 16px;
  align-items: flex-start;
  flex: 1;
  min-width: 0;
  margin: 0;
  position: relative;
  padding-left: 0;
}
.alliance-hero-copy {
  flex: 1 1 12rem;
  min-width: 0;
}
.alliance-hero-copy .chip-row {
  justify-content: flex-start;
}
.alliance-hero .profile-actions {
  margin-left: auto;
}
.alliance-flag {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--chip);
  border: 1px solid var(--panel-edge);
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  color: var(--accent);
  flex: 0 0 auto;
}
.notice-text {
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

a { color: var(--accent); }
a:hover { color: var(--ember); }

.empty-note {
  color: var(--muted);
  padding: 22px 10px;
  line-height: 1.55;
  text-align: center;
}

/* —— Admin —— */
.admin-wrap .panel h2,
.admin-wrap .panel h3 { margin-top: 0; }
.admin-stats { margin: 12px 0; min-width: 100%; grid-template-columns: repeat(4, 1fr); }
.code-block {
  background: var(--bg0);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 12px;
  overflow: auto;
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--accent);
  max-height: 320px;
}
.crawl-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}
.crawl-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  min-width: 140px;
}
.crawl-field-sm { min-width: 90px; max-width: 110px; }
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.db-clear-actions { margin-top: 10px; }

/* Admin live crawl + log console */
.crawl-live {
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-edge);
  background: var(--inset);
}
.crawl-live.is-running {
  border-color: rgba(61, 190, 154, 0.45);
  box-shadow: 0 0 0 1px rgba(61, 190, 154, 0.12);
}
.crawl-live-status {
  font-weight: 800;
  font-size: 0.95rem;
  margin-bottom: 8px;
}
.crawl-live-meta {
  color: var(--muted);
  font-size: 0.82rem;
  font-family: var(--mono);
  line-height: 1.45;
  word-break: break-word;
}
.log-console {
  background: #070c0a;
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 10px 12px;
  max-height: 380px;
  min-height: 160px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.45;
}
.log-line {
  display: grid;
  grid-template-columns: 150px 52px 1fr;
  gap: 8px;
  padding: 2px 0;
  border-bottom: 1px solid rgba(42, 64, 56, 0.35);
}
.log-line.muted { color: var(--faint); display: block; }
.log-ts { color: var(--faint); white-space: nowrap; }
.log-lv { font-weight: 800; letter-spacing: 0.04em; }
.log-line.level-info .log-lv { color: var(--accent); }
.log-line.level-warn .log-lv,
.log-line.level-warning .log-lv { color: var(--warn); }
.log-line.level-error .log-lv { color: var(--danger); }
.log-msg { color: var(--text); word-break: break-word; }

/* Admin settings catalog */
.settings-root { display: grid; gap: 16px; margin-top: 12px; }
.settings-group h4 {
  margin: 0 0 10px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--faint);
}
.setting-row {
  display: grid;
  grid-template-columns: 1fr minmax(140px, 220px);
  gap: 12px;
  align-items: start;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--panel-edge);
  background: var(--inset);
  margin-bottom: 8px;
}
.setting-row.is-override {
  border-color: rgba(61, 190, 154, 0.45);
  box-shadow: inset 0 0 0 1px rgba(61, 190, 154, 0.12);
}
.setting-row.is-readonly { opacity: 0.85; }
.setting-label {
  font-weight: 750;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.setting-key {
  font-size: 0.72rem;
  color: var(--accent);
  background: rgba(61, 190, 154, 0.1);
  padding: 2px 6px;
  border-radius: 6px;
}
.setting-src {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.setting-desc {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}
.setting-hint {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--ember);
}
.setting-control input,
.setting-control select {
  width: 100%;
  min-width: 0;
  background: var(--bg0);
  border: 1px solid var(--panel-edge);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}
#nextScanLine {
  color: var(--accent);
  font-weight: 650;
}

@media (max-width: 720px) {
  .setting-row { grid-template-columns: 1fr; }
  .log-line { grid-template-columns: 1fr; gap: 2px; }
}

/* —— Home redesign —— */
.eyebrow {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}
.hero-banner {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 26px 24px;
  margin-bottom: 16px;
  background: var(--hero-grad);
  border: 1px solid var(--panel-edge);
  box-shadow: var(--shadow);
}
.hero-banner h1 {
  margin: 0 0 10px;
  font-size: clamp(1.45rem, 3vw, 1.95rem);
  letter-spacing: -0.025em;
  line-height: 1.15;
  font-weight: 750;
}
.hero-sub {
  margin: 0;
  max-width: 52ch;
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.95rem;
}
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}
.btn-glow {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.15s, transform 0.15s;
}
.btn-glow:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}
.btn-ghost {
  display: inline-flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-edge);
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
  font-size: 0.92rem;
  background: var(--panel);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}
.results-compact { margin-top: 12px; max-height: 420px; overflow: auto; }

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}
.lb-panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-height: 280px;
}
.lb-panel h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}
.section-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}
.pill-live {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}
.lb-list { display: grid; gap: 6px; margin-top: 12px; }
.lb-row-item {
  display: grid;
  grid-template-columns: 36px 40px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--panel2);
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
  text-align: left;
  color: inherit;
  font: inherit;
  width: 100%;
}
.lb-row-item:hover {
  transform: translateX(2px);
  border-color: var(--panel-edge);
  background: var(--chip);
}
.lb-rank {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--faint);
  text-align: center;
}
.lb-row-item.top-1 .lb-rank { color: #f5d76e; }
.lb-row-item.top-2 .lb-rank { color: #c0c8d4; }
.lb-row-item.top-3 .lb-rank { color: #d4a574; }
.lb-av {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--chip);
  border: 1px solid var(--panel-edge);
  display: grid;
  place-items: center;
  overflow: hidden;
  font-weight: 800;
  color: var(--accent);
}
.lb-av img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.lb-name {
  font-weight: 750;
  line-height: 1.25;
}
.lb-meta-line {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}
.lb-power {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ember);
  white-space: nowrap;
}

.kingdom-rank-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.kingdom-rank-row .lb-row-item {
  flex: 1;
  min-width: 0;
}
.kingdom-rank-map {
  flex-shrink: 0;
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-edge);
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.kingdom-rank-map:hover {
  border-color: var(--accent);
  color: var(--accent-dim);
}

/* —— Kingdoms —— */
.page-hero {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
  position: relative;
  padding: 4px 0;
}
.page-hero > :not(.icon-btn) {
  flex: 1 1 auto;
  min-width: 0;
}
.page-hero h1 {
  margin: 0 0 6px;
  font-size: clamp(1.25rem, 4.5vw, 1.65rem);
  word-break: break-word;
}
.page-hero .hero-sub {
  word-break: break-word;
}
.kingdoms-tabs {
  margin: 0 0 16px;
}
.kingdom-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.kingdom-toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.kingdom-search {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1;
  min-width: min(100%, 280px);
}
.kingdom-search input {
  flex: 1;
  min-width: 140px;
  max-width: 220px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--panel-edge);
  background: var(--bg0);
  color: var(--text);
  font: inherit;
}
.kingdom-search input:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(61, 190, 154, 0.15);
}
.kingdom-page-size {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}
.kingdom-page-size select {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: var(--bg0);
  color: var(--text);
  font: inherit;
}
.kd-ranks-sub {
  margin: 0;
}
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin: 18px 0 8px;
}
.pagination button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.kingdom-rank-list {
  max-width: 920px;
}
.kingdom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
@media (max-width: 640px) {
  .kingdom-search input {
    max-width: none;
  }
  .kingdom-toolbar-right {
    width: 100%;
    justify-content: space-between;
  }
}
.kingdom-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  transition: transform 0.14s, border-color 0.14s, box-shadow 0.14s;
  overflow: hidden;
}
.kingdom-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.kingdom-card::after {
  display: none;
}
.kingdom-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.kingdom-card h3 {
  margin: 0;
  font-size: 1.2rem;
}
.kingdom-card .k-rank {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}
.grade-badge {
  min-width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 1.1rem;
  border: 1px solid var(--panel-edge);
  background: var(--chip);
}
.grade-badge.elite { color: #f5d76e; border-color: rgba(245, 215, 110, 0.45); background: rgba(245, 215, 110, 0.1); }
.grade-badge.strong { color: var(--ok); border-color: rgba(94, 211, 154, 0.4); background: rgba(94, 211, 154, 0.1); }
.grade-badge.stable {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--panel-edge));
  background: var(--accent-glow);
}
.grade-badge.average { color: var(--ember); border-color: rgba(224, 160, 74, 0.35); background: rgba(224, 160, 74, 0.1); }
.grade-badge.soft { color: var(--warn); border-color: rgba(224, 176, 74, 0.35); background: rgba(224, 176, 74, 0.08); }
.grade-badge.quiet,
.grade-badge.empty { color: var(--muted); }
.grade-badge.pending {
  color: var(--ember);
  border-color: rgba(224, 160, 74, 0.4);
  background: rgba(224, 160, 74, 0.1);
}

.k-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.k-stat {
  background: var(--inset);
  border-radius: 10px;
  padding: 8px 10px;
}
.k-stat b {
  display: block;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.k-stat span {
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.k-health-label {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}
.k-health-label strong { color: var(--text); }

.kingdom-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
  position: relative;
  z-index: 1;
}
.kingdom-card-map {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-edge);
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.kingdom-card-map:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
  color: var(--accent);
}
.kingdom-card-open {
  flex: 1;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-edge);
  background: var(--inset);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.kingdom-card-open:hover {
  color: var(--text);
  border-color: var(--accent-dim);
}

.kingdom-detail-hero { align-items: flex-start; }
.kingdom-detail-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 14px;
  align-items: flex-start;
  flex: 1;
  min-width: 0;
}
.kingdom-detail-head > div:not(.grade-badge) {
  flex: 1 1 12rem;
  min-width: 0;
}
.kingdom-detail-head .chip-row {
  justify-content: flex-start;
}
.health-bar-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: -4px 0 16px;
}
.health-bar {
  flex: 1;
  min-width: 0;
  height: 8px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--panel-edge);
  overflow: hidden;
}
.health-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.5s ease;
}

/* —— Responsive —— */
@media (max-width: 900px) {
  .home-grid { grid-template-columns: 1fr; }
  .site-header {
    align-items: stretch;
  }
  .header-right {
    width: 100%;
    justify-content: space-between;
  }
  .stats {
    min-width: 0;
    max-width: none;
    flex: 1;
  }
}

@media (max-width: 640px) {
  .wrap {
    padding: 14px 12px 64px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .site-header {
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 12px;
  }
  .logo {
    font-size: 1.2rem;
  }
  .nav {
    gap: 4px;
  }
  .nav a,
  .nav-btn {
    font-size: 0.82rem;
    padding: 6px 10px;
  }
  .header-right {
    width: 100%;
    justify-content: space-between;
  }
  .stats {
    min-width: 0;
    max-width: none;
    width: 100%;
    justify-content: stretch;
    gap: 5px;
  }
  .stat {
    padding: 6px 6px;
    flex: 1 1 calc(33.33% - 5px);
    min-width: 4.2rem;
  }
  .stat b {
    font-size: 0.85rem;
  }
  .stat span {
    font-size: 0.55rem;
  }

  .panel {
    padding: 14px 12px;
  }
  .hero-banner {
    padding: 18px 14px;
    border-radius: 16px;
  }
  .hero-banner h1 {
    font-size: 1.4rem;
  }
  .hero-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .btn-ghost,
  .btn-glow {
    justify-content: center;
    text-align: center;
    width: 100%;
  }

  .search-row {
    flex-direction: column;
    align-items: stretch;
  }
  .search-row button,
  #btnSearch {
    width: 100%;
  }
  .deep-search-box {
    flex-direction: column;
    align-items: stretch;
  }
  .btn-deep {
    width: 100%;
  }

  .section-head {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .hero-card { grid-template-columns: 72px 1fr; gap: 10px; }
  .admin-stats { grid-template-columns: repeat(2, 1fr); }

  .card {
    grid-template-columns: auto 1fr;
    gap: 10px;
    padding: 10px 12px;
  }
  .card > .meta:last-child { display: none; }

  .lb-row-item {
    grid-template-columns: 28px 32px minmax(0, 1fr) auto;
    gap: 8px;
    padding: 8px;
  }
  .lb-av {
    width: 32px;
    height: 32px;
    border-radius: 9px;
  }
  .lb-power {
    font-size: 0.85rem;
  }
  .lb-name {
    font-size: 0.92rem;
    overflow-wrap: anywhere;
  }
  .lb-meta-line {
    overflow-wrap: anywhere;
  }

  .profile-hero,
  .gov-banner {
    padding: 18px 12px 14px;
  }
  .gov-banner-toolbar {
    padding-left: 44px;
    flex-direction: column;
    align-items: stretch;
  }
  .gov-banner-main {
    flex-direction: column;
    align-items: flex-start;
  }
  .gov-refresh-panel {
    margin-left: 0;
    width: 100%;
  }
  .btn-refresh {
    width: 100%;
    justify-content: flex-start;
  }
  .gov-stat-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  @media (min-width: 480px) and (max-width: 900px) {
    .gov-stat-bar {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }
  .gov-name,
  .profile-name {
    font-size: 1.25rem;
    overflow-wrap: anywhere;
  }
  .lord-gear-rack,
  .skin-rack {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
  .heroes-grid {
    grid-template-columns: 1fr;
  }
  .chip-row {
    gap: 5px;
  }
  .chip {
    font-size: 0.72rem;
    padding: 3px 8px;
  }
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    flex: 0 0 auto;
    padding: 12px 14px;
    font-size: 0.85rem;
  }
  .tab-body {
    padding: 12px;
  }

  .ov-grid {
    grid-template-columns: 1fr;
  }

  .page-hero {
    gap: 10px;
  }
  .kingdom-detail-head {
    width: 100%;
  }
  .kingdom-detail-head .btn-ghost {
    width: 100%;
  }
  .kingdom-grid {
    grid-template-columns: 1fr;
  }
  .kingdom-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .kingdom-search {
    width: 100%;
  }
  .kingdom-search input {
    max-width: none;
    min-width: 0;
  }
  .kingdom-search button {
    flex: 1 1 auto;
  }
  .kingdom-toolbar-right {
    width: 100%;
    justify-content: space-between;
  }
  .kingdoms-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .kingdoms-tabs .tab {
    flex: 1 1 auto;
    text-align: center;
  }
  .pagination {
    gap: 8px;
  }
  .pagination button {
    flex: 1 1 auto;
    min-width: 0;
  }

  .alliance-hero {
    flex-direction: column;
  }
  .alliance-hero .profile-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-start;
  }
  .alliance-hero .profile-actions button {
    flex: 1 1 auto;
  }
  .alliance-hero-copy .chip-row {
    justify-content: flex-start;
  }

  .member-row {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }
  .health-bar-wrap {
    flex-wrap: wrap;
  }
  .health-bar-wrap .meta {
    width: 100%;
  }

  .crawl-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .crawl-field,
  .crawl-field-sm {
    max-width: none;
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 400px) {
  .stats {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .stat b {
    font-size: 0.88rem;
  }
  .lb-row-item {
    grid-template-columns: 24px minmax(0, 1fr) auto;
  }
  .lb-row-item .lb-av {
    display: none;
  }
}
