/* Kingdom Stats front end. Uses Kingdom Standard's colours when present. */

/* Kingdom Standard's text column is 720px; stats need the full content width even on older theme versions. */
.kstats-page .section__inner.prose {
	width: min(var(--content, 1120px), calc(100% - 3rem));
	max-width: none;
	margin-inline: auto;
}

.kstats {
	--ks-ink: var(--ink, #0c0b09);
	--ks-ink-2: var(--ink-2, #141210);
	--ks-ivory: var(--ivory, #f3eee6);
	--ks-muted: var(--muted, #a39888);
	--ks-gold: var(--gold, #d4b06a);
	--ks-gold-2: var(--gold-2, #f0d9a0);
	--ks-line: var(--line, rgba(212, 176, 106, 0.28));
	--ks-panel: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.015));
	--ks-up: #86cf96;
	--ks-down: #ec8b7a;
	--ks-crimson: #e0775f;
	--ks-stone: #b5bfc9;
	--ks-display: var(--font-display, Georgia, serif);
	--ks-radius: 16px;

	display: grid;
	gap: 1.5rem;
	min-width: 0;
	color: var(--ks-ivory);
	font-variant-numeric: tabular-nums;
}

.kstats > * {
	min-width: 0;
	margin: 0;
}

.kstats h2,
.kstats h3,
.kstats p,
.kstats ol,
.kstats ul,
.kstats dl {
	margin: 0;
}

.kstats ol,
.kstats ul {
	padding: 0;
	list-style: none;
}

/* Header */

.kstats-head {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: 1rem 1.5rem;
}

.kstats-head__text {
	display: grid;
	gap: 0.35rem;
	min-width: 0;
}

.kstats-kicker {
	color: var(--ks-gold);
	font-size: 0.8rem;
	font-weight: 600;
	letter-spacing: 0.16em;
	text-transform: uppercase;
}

.kstats-head__meta,
.kstats-muted,
.kstats-note,
.kstats-count {
	color: var(--ks-muted);
}

.kstats-note,
.kstats-count {
	font-size: 0.9rem;
}

.kstats-title {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem 0.75rem;
	font-family: var(--ks-display);
	font-size: clamp(1.6rem, 4vw, 2.4rem);
	font-weight: 600;
	line-height: 1.1;
	overflow-wrap: anywhere;
}

.kstats-facts {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
}

.kstats-facts li {
	padding: 0.25rem 0.7rem;
	border: 1px solid var(--ks-line);
	border-radius: 999px;
	background: rgba(212, 176, 106, 0.06);
	font-size: 0.85rem;
}

.kstats-back a {
	color: var(--ks-muted);
	font-size: 0.9rem;
	text-decoration: none;
}

.kstats-back a:hover {
	color: var(--ks-gold-2);
}

/* Tabs */

.kstats-tabs {
	display: flex;
	gap: 0.35rem;
	padding: 0.3rem;
	overflow-x: auto;
	border: 1px solid var(--ks-line);
	border-radius: 999px;
	background: rgba(0, 0, 0, 0.3);
	scrollbar-width: none;
	justify-self: start;
	max-width: 100%;
}

.kstats-tabs__link {
	flex-shrink: 0;
	min-height: 44px;
	display: inline-flex;
	align-items: center;
	padding: 0 1.2rem;
	border-radius: 999px;
	color: var(--ks-muted);
	font-weight: 500;
	text-decoration: none;
	transition: color 0.2s ease, background-color 0.2s ease;
}

.kstats-tabs__link:hover {
	color: var(--ks-ivory);
}

.kstats-tabs__link[aria-current="page"] {
	background: linear-gradient(180deg, var(--ks-gold-2), var(--ks-gold));
	color: var(--ks-ink);
}

/* Forms */

.kstats-filters {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 0.75rem;
}

.kstats-filters--bar {
	padding: 1rem;
	border: 1px solid var(--ks-line);
	border-radius: var(--ks-radius);
	background: var(--ks-panel);
}

.kstats-field {
	display: grid;
	gap: 0.3rem;
	min-width: 0;
}

.kstats-field--grow {
	flex: 1 1 14rem;
}

.kstats-field__label {
	color: var(--ks-muted);
	font-size: 0.8rem;
	font-weight: 500;
}

.kstats .kstats-field input,
.kstats .kstats-field select {
	width: 100%;
	min-height: 44px;
	padding: 0.55rem 0.8rem;
	border: 1px solid var(--ks-line);
	border-radius: 12px;
	background: var(--ks-ink-2);
	color: var(--ks-ivory);
	font: inherit;
	font-size: 0.95rem;
}

.kstats .kstats-field select {
	max-width: 18rem;
	padding-right: 2rem;
	appearance: none;
	background-image: linear-gradient(45deg, transparent 50%, var(--ks-gold) 50%), linear-gradient(135deg, var(--ks-gold) 50%, transparent 50%);
	background-position: calc(100% - 1rem) 50%, calc(100% - 0.7rem) 50%;
	background-size: 0.3rem 0.3rem;
	background-repeat: no-repeat;
}

.kstats .kstats-field select option {
	background: var(--ks-ink-2);
	color: var(--ks-ivory);
}

.kstats .kstats-field input:focus-visible,
.kstats .kstats-field select:focus-visible {
	outline: 2px solid var(--ks-gold-2);
	outline-offset: 2px;
}

.kstats-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 0 1.1rem;
	border: 1px solid var(--ks-line);
	border-radius: 999px;
	background: rgba(212, 176, 106, 0.08);
	color: var(--ks-gold-2);
	font: inherit;
	font-size: 0.95rem;
	font-weight: 500;
	text-decoration: none;
	cursor: pointer;
	transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.kstats-button:hover {
	border-color: var(--ks-gold);
	background: rgba(212, 176, 106, 0.16);
	color: var(--ks-ivory);
}

.kstats-button--solid {
	border-color: transparent;
	background: linear-gradient(180deg, var(--ks-gold-2), var(--ks-gold));
	color: var(--ks-ink);
	font-weight: 600;
}

.kstats-button--solid:hover {
	background: linear-gradient(180deg, #f7e6bd, var(--ks-gold-2));
	color: var(--ks-ink);
}

.kstats-button:focus-visible {
	outline: 2px solid var(--ks-gold-2);
	outline-offset: 3px;
}

/* DKP weights */

.kstats-weights {
	flex-basis: 100%;
}

.kstats-weights > summary {
	width: max-content;
	list-style: none;
}

.kstats-weights > summary::-webkit-details-marker {
	display: none;
}

.kstats-weights > summary::after {
	content: "";
	width: 0.4rem;
	height: 0.4rem;
	margin-left: 0.6rem;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: translateY(-2px) rotate(45deg);
	transition: transform 0.2s ease;
}

.kstats-weights[open] > summary::after {
	transform: translateY(1px) rotate(225deg);
}

.kstats-weights__grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
	gap: 0.75rem;
	margin-top: 0.9rem;
}

/* Cards */

.kstats-cards {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 0.75rem;
}

.kstats-card {
	display: grid;
	align-content: start;
	gap: 0.2rem;
	min-width: 0;
	padding: 1rem 1.1rem;
	border: 1px solid var(--ks-line);
	border-radius: var(--ks-radius);
	background: var(--ks-panel);
}

.kstats-card--wide {
	grid-column: 1 / -1;
}

.kstats-card--me {
	border-color: var(--ks-gold);
	background: linear-gradient(180deg, rgba(212, 176, 106, 0.16), rgba(212, 176, 106, 0.04));
}

.kstats-card__label {
	color: var(--ks-muted);
	font-size: 0.8rem;
	font-weight: 500;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.kstats-card__value {
	color: var(--ks-ivory);
	font-family: var(--ks-display);
	font-size: clamp(1.35rem, 3vw, 1.7rem);
	font-weight: 600;
	line-height: 1.2;
}

.kstats-card__text {
	color: var(--ks-ivory);
	font-size: 0.95rem;
}

.kstats-card .kstats-delta {
	font-size: 0.85rem;
}

/* Changes */

.kstats-delta {
	white-space: nowrap;
	font-weight: 500;
}

.kstats-delta--up {
	color: var(--ks-up);
}

.kstats-delta--down {
	color: var(--ks-down);
}

.kstats-delta--flat {
	color: var(--ks-muted);
}

/* Layout */

.kstats-grid {
	display: grid;
	gap: 1rem;
}

.kstats-panel {
	--ks-accent: var(--ks-gold);

	display: grid;
	align-content: start;
	gap: 0.9rem;
	min-width: 0;
	padding: 1.25rem;
	border: 1px solid var(--ks-line);
	border-radius: var(--ks-radius);
	background: var(--ks-panel);
}

.kstats-panel--crimson {
	--ks-accent: var(--ks-crimson);
}

.kstats-panel--stone {
	--ks-accent: var(--ks-stone);
}

.kstats-panel__title {
	color: var(--ks-ivory);
	font-family: var(--ks-display);
	font-size: 1.1rem;
	font-weight: 600;
	line-height: 1.25;
}

.kstats-panel__title::after {
	content: "";
	display: block;
	width: 2.5rem;
	height: 2px;
	margin-top: 0.5rem;
	border-radius: 2px;
	background: var(--ks-accent);
}

.kstats-subtitle {
	margin-top: 0.5rem;
	font-family: var(--ks-display);
	font-size: 1rem;
	font-weight: 600;
}

.kstats-notice {
	justify-items: start;
	max-width: 36rem;
}

.kstats-more {
	justify-self: start;
	color: var(--ks-gold-2);
	font-size: 0.9rem;
	font-weight: 500;
}

/* Charts */

.kstats-chart {
	display: block;
	width: 100%;
	height: auto;
	color: var(--ks-accent);
	overflow: visible;
}

.kstats-chart__grid {
	stroke: rgba(255, 255, 255, 0.08);
	stroke-width: 1;
}

.kstats-chart__axis {
	fill: var(--ks-muted);
	font-size: 13px;
	font-family: inherit;
}

.kstats-chart__line {
	fill: none;
	stroke: currentColor;
	stroke-width: 2.5;
	stroke-linejoin: round;
	stroke-linecap: round;
}

.kstats-chart__point {
	fill: var(--ks-ink);
	stroke: currentColor;
	stroke-width: 2;
}

/* Leaderboards */

.kstats-board {
	display: grid;
	counter-reset: kstats-board;
}

.kstats-board__row {
	display: grid;
	grid-template-columns: 1.6rem minmax(0, 1fr) auto;
	align-items: center;
	gap: 0.6rem;
	padding: 0.55rem 0;
	border-top: 1px solid rgba(255, 255, 255, 0.06);
	counter-increment: kstats-board;
}

.kstats-board__row:first-child {
	border-top: 0;
}

.kstats-board__row::before {
	content: counter(kstats-board);
	color: var(--ks-muted);
	font-size: 0.85rem;
	text-align: right;
}

.kstats-board__row:nth-child(-n + 3)::before {
	color: var(--ks-accent);
	font-weight: 700;
}

.kstats-board__value {
	font-weight: 600;
	white-space: nowrap;
}

/* Governor cell */

.kstats-gov {
	display: grid;
	grid-template-columns: minmax(0, auto) auto;
	justify-content: start;
	align-items: center;
	column-gap: 0.45rem;
	min-width: 0;
}

.kstats-gov__name {
	min-width: 0;
	overflow: hidden;
	color: var(--ks-ivory);
	font-weight: 500;
	text-decoration: none;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.kstats-gov__name:hover {
	color: var(--ks-gold-2);
	text-decoration: underline;
}

.kstats-gov__meta {
	grid-column: 1 / -1;
	overflow: hidden;
	color: var(--ks-muted);
	font-size: 0.8rem;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.kstats-badge {
	display: inline-block;
	padding: 0.05rem 0.5rem;
	border-radius: 999px;
	background: var(--ks-gold);
	color: var(--ks-ink);
	font-family: var(--font-body, inherit);
	font-size: 0.7rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	line-height: 1.5;
	text-transform: uppercase;
	vertical-align: middle;
}

.kstats-title .kstats-badge {
	font-size: 0.75rem;
}

/* Tables */

.kstats-table-wrap {
	max-width: 100%;
	overflow-x: auto;
	border: 1px solid var(--ks-line);
	border-radius: var(--ks-radius);
	background: rgba(0, 0, 0, 0.2);
	-webkit-overflow-scrolling: touch;
}

.kstats-panel .kstats-table-wrap {
	border-radius: 12px;
}

.kstats-table {
	width: 100%;
	border-collapse: separate;
	border-spacing: 0;
	font-size: 0.92rem;
}

.kstats-table th,
.kstats-table td {
	padding: 0.65rem 0.8rem;
	border-bottom: 1px solid rgba(255, 255, 255, 0.06);
	text-align: left;
	vertical-align: middle;
}

.kstats-table thead th {
	position: sticky;
	top: 0;
	z-index: 2;
	background: #1a1713;
	color: var(--ks-muted);
	font-size: 0.78rem;
	font-weight: 600;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	white-space: nowrap;
}

.kstats-table tbody th {
	font-weight: 500;
}

.kstats-table tbody tr:last-child > * {
	border-bottom: 0;
}

.kstats-table tbody tr:hover > * {
	background-color: rgba(212, 176, 106, 0.05);
}

.kstats-table .kstats-num {
	text-align: right;
	white-space: nowrap;
}

.kstats-table td.kstats-num .kstats-delta {
	display: block;
	font-size: 0.75rem;
}

.kstats-rank {
	color: var(--ks-muted);
	width: 3rem;
}

.kstats-col-dkp {
	color: var(--ks-gold-2);
	font-weight: 700;
}

.kstats-table--sticky {
	min-width: 60rem;
}

.kstats-table--sticky .kstats-sticky {
	position: sticky;
	left: 0;
	z-index: 1;
	width: 14rem;
	max-width: 14rem;
	background: #151310;
	box-shadow: 1px 0 0 var(--ks-line);
}

.kstats-table--sticky thead .kstats-sticky {
	z-index: 3;
	background: #1a1713;
}

.kstats-table tr.is-me > * {
	background-color: rgba(212, 176, 106, 0.1);
}

.kstats-table--sticky tr.is-me .kstats-sticky {
	background: #2a2317;
}

.kstats-table tr.is-me > :first-child {
	box-shadow: inset 3px 0 0 var(--ks-gold);
}

.kstats-sort {
	display: inline-flex;
	align-items: center;
	gap: 0.25rem;
	min-height: 32px;
	color: inherit;
	text-decoration: none;
}

.kstats-sort:hover,
.kstats-sort.is-active {
	color: var(--ks-gold-2);
}

.kstats-sort__dir {
	font-size: 0.9em;
}

/* Trade grades */

.kstats-trade {
	display: inline-block;
	min-width: 3.2rem;
	padding: 0.1rem 0.5rem;
	border: 1px solid currentColor;
	border-radius: 999px;
	font-size: 0.8rem;
	font-weight: 600;
	text-align: center;
}

.kstats-trade--5 {
	color: var(--ks-gold-2);
	background: rgba(240, 217, 160, 0.12);
}

.kstats-trade--4 {
	color: var(--ks-up);
}

.kstats-trade--3 {
	color: #9fc4d9;
}

.kstats-trade--2 {
	color: #d9b27a;
}

.kstats-trade--1 {
	color: var(--ks-down);
}

/* Bars, lists, changes */

.kstats-bars {
	display: grid;
	gap: 0.8rem;
}

.kstats-bars__row {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 0.3rem 0.75rem;
	font-size: 0.9rem;
}

.kstats-bars__value {
	font-weight: 600;
}

.kstats-bars__track {
	grid-column: 1 / -1;
	height: 0.45rem;
	overflow: hidden;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.07);
}

.kstats-bars__fill {
	display: block;
	height: 100%;
	border-radius: inherit;
	background: var(--ks-accent);
}

.kstats-list {
	display: grid;
}

.kstats-list__row {
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.5rem 0;
	border-top: 1px solid rgba(255, 255, 255, 0.06);
	font-size: 0.92rem;
}

.kstats-list__row:first-child {
	border-top: 0;
}

.kstats-list dt {
	color: var(--ks-muted);
}

.kstats-list dd {
	margin: 0;
	font-weight: 600;
}

.kstats-changes {
	display: grid;
	gap: 0.4rem;
	font-size: 0.92rem;
}

.kstats-changes li {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem 0.75rem;
}

/* Pagination */

.kstats-pager {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
}

.kstats-pager__status {
	color: var(--ks-muted);
	font-size: 0.9rem;
}

@media (min-width: 700px) {
	.kstats-cards {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}

	.kstats-cards--compact {
		grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
	}

	.kstats-cards--compact .kstats-card--wide {
		grid-column: span 2;
	}

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

	.kstats-grid--4 {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (min-width: 1000px) {
	.kstats-grid--3 {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}

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

@media (max-width: 599px) {
	.kstats {
		gap: 1.25rem;
	}

	.kstats-card {
		padding: 0.85rem;
	}

	.kstats-panel {
		padding: 1rem;
	}

	.kstats-filters > .kstats-field,
	.kstats-filters > .kstats-button {
		flex: 1 1 100%;
	}

	.kstats .kstats-field select {
		max-width: none;
	}

	.kstats-head > .kstats-filters {
		width: 100%;
	}

	.kstats-head > .kstats-filters > .kstats-field {
		flex: 1 1 auto;
		width: auto;
	}

	.kstats-head > .kstats-filters > .kstats-button {
		flex: 0 0 auto;
	}

	.kstats-table--sticky .kstats-sticky {
		width: 9.5rem;
		max-width: 9.5rem;
	}

	.kstats-chart__axis {
		font-size: 18px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.kstats * {
		transition: none !important;
	}
}
