/* Psyern Leaderboard — Shared Base Styles */

.psyern-lb {
	position: relative;
	width: 100%;
	max-width: 100%;
	margin: 0 auto;
	padding: 24px;
	font-size: 14px;
	line-height: 1.5;
	box-sizing: border-box;
}

/* ─── Header ─── */
.psyern-lb__header {
	margin-bottom: 20px;
	padding-bottom: 16px;
}

.psyern-lb__title {
	font-size: clamp(1.1rem, 3vw, 1.5rem);
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	margin: 0 0 8px;
}

.psyern-lb__meta {
	display: flex;
	gap: 16px;
	flex-wrap: wrap;
	font-size: 0.8rem;
	opacity: 0.7;
}

/* ─── Controls ─── */
.psyern-lb__controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 12px;
	margin-bottom: 16px;
}

.psyern-lb__modes {
	display: flex;
	gap: 4px;
}

.psyern-lb__mode-btn {
	padding: 8px 20px;
	border: none;
	border-radius: 4px;
	cursor: pointer;
	font-size: 0.85rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	transition: all 0.2s;
	background: transparent;
}

.psyern-lb__limits {
	display: flex;
	gap: 4px;
}

.psyern-lb__limit-btn {
	padding: 4px 12px;
	border: 1px solid;
	border-radius: 3px;
	cursor: pointer;
	font-size: 0.75rem;
	font-weight: 600;
	background: transparent;
	transition: all 0.2s;
}

/* ─── Top 3 Section ─── */
.psyern-lb__top3 {
	display: grid;
	grid-template-columns: 1fr 1.15fr 1fr;
	gap: 12px;
	margin-bottom: 24px;
	align-items: end;
}

.psyern-lb__top3-card {
	text-align: center;
	padding: 20px 12px;
	border-radius: 8px;
	position: relative;
	transition: transform 0.3s;
}

.psyern-lb__top3-card--1 {
	transform: scale(1.05);
}

.psyern-lb__top3-rank {
	font-size: 1.8rem;
	display: block;
	margin-bottom: 6px;
}

.psyern-lb__top3-avatar {
	width: 56px;
	height: 56px;
	border-radius: 50%;
	object-fit: cover;
	margin-bottom: 8px;
}

.psyern-lb__top3-name {
	font-weight: 700;
	font-size: 0.95rem;
	margin-bottom: 4px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.psyern-lb__top3-stats {
	font-size: 0.75rem;
	opacity: 0.8;
}

/* ─── Table Scroll Container ─── */
.psyern-lb__table-wrap {
	width: 100%;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	border-radius: 4px;
}

/* Scroll shadow hints */
.psyern-lb__table-wrap {
	background:
		linear-gradient(to right, var(--psyern-bg, transparent) 30%, transparent),
		linear-gradient(to left, var(--psyern-bg, transparent) 30%, transparent),
		linear-gradient(to right, rgba(0,0,0,0.15), transparent 20px),
		linear-gradient(to left, rgba(0,0,0,0.15), transparent 20px);
	background-position: left center, right center, left center, right center;
	background-repeat: no-repeat;
	background-size: 40px 100%, 40px 100%, 20px 100%, 20px 100%;
	background-attachment: local, local, scroll, scroll;
}

/* ─── Table ─── */
.psyern-lb__table {
	width: 100%;
	min-width: 600px;
	border-collapse: separate;
	border-spacing: 0;
}

.psyern-lb__table th {
	text-align: left;
	padding: 10px 12px;
	font-weight: 600;
	font-size: 0.7rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	white-space: nowrap;
}

.psyern-lb__table td {
	padding: 10px 12px;
	white-space: nowrap;
}

.psyern-lb__table tbody tr {
	transition: background 0.15s;
	animation: psyern-row-in 0.4s ease both;
}

/* ─── Sticky Columns: Rank + Avatar + Name ─── */
.psyern-lb__table th:nth-child(1),
.psyern-lb__table td:nth-child(1) {
	position: sticky;
	left: 0;
	z-index: 3;
	background: inherit;
}

.psyern-lb__table th:nth-child(2),
.psyern-lb__table td:nth-child(2) {
	position: sticky;
	left: 42px;
	z-index: 3;
	background: inherit;
}

.psyern-lb__table th:nth-child(3),
.psyern-lb__table td:nth-child(3) {
	position: sticky;
	left: 82px;
	z-index: 3;
	background: inherit;
	min-width: 120px;
	max-width: 180px;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Shadow edge on the sticky name column */
.psyern-lb__table th:nth-child(3)::after,
.psyern-lb__table td:nth-child(3)::after {
	content: '';
	position: absolute;
	top: 0;
	right: -8px;
	bottom: 0;
	width: 8px;
	background: linear-gradient(to right, rgba(0,0,0,0.08), transparent);
	pointer-events: none;
}

/* Inherit row background for sticky cells on hover */
.psyern-lb__table tbody tr:hover td:nth-child(1),
.psyern-lb__table tbody tr:hover td:nth-child(2),
.psyern-lb__table tbody tr:hover td:nth-child(3) {
	background: inherit;
}

/* Sticky header row */
.psyern-lb__table thead th {
	position: sticky;
	top: 0;
	z-index: 4;
	background: inherit;
}

/* ─── Faction Bar ─── */
.psyern-lb__faction-bar {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 16px;
	font-size: 0.75rem;
	font-weight: 600;
}

.psyern-lb__faction-bar-track {
	flex: 1;
	height: 10px;
	border-radius: 5px;
	overflow: hidden;
	display: flex;
	background: rgba(128, 128, 128, 0.2);
}

.psyern-lb__faction-bar-east {
	background: #e74c3c;
	transition: width 0.6s ease;
}

.psyern-lb__faction-bar-west {
	background: #3498db;
	transition: width 0.6s ease;
}

.psyern-lb__faction-label-east {
	color: #e74c3c;
	white-space: nowrap;
}

.psyern-lb__faction-label-west {
	color: #3498db;
	white-space: nowrap;
}

/* ─── Faction Badge ─── */
.psyern-lb__faction {
	display: inline-block;
	padding: 1px 6px;
	border-radius: 3px;
	font-size: 0.65rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	vertical-align: middle;
	margin-left: 6px;
}

.psyern-lb__faction--east {
	background: rgba(231, 76, 60, 0.15);
	color: #e74c3c;
	border: 1px solid rgba(231, 76, 60, 0.3);
}

.psyern-lb__faction--west {
	background: rgba(52, 152, 219, 0.15);
	color: #3498db;
	border: 1px solid rgba(52, 152, 219, 0.3);
}

.psyern-lb__faction--neutral {
	background: rgba(149, 165, 166, 0.15);
	color: #95a5a6;
	border: 1px solid rgba(149, 165, 166, 0.3);
}

/* ─── Level Badge ─── */
.psyern-lb__level {
	display: inline-block;
	font-size: 0.7rem;
	font-weight: 700;
	opacity: 0.7;
}

/* ─── Boss Kills / Reputation ─── */
.psyern-lb__boss-kills,
.psyern-lb__reputation {
	white-space: nowrap;
	font-size: 0.85rem;
}

.psyern-lb__boss-kills::before {
	content: '\2620 ';
}

.psyern-lb__reputation::before {
	content: '\2605 ';
}

/* ─── Cell Styles ─── */
.psyern-lb__rank {
	font-weight: 700;
	min-width: 30px;
	display: inline-block;
}

.psyern-lb__avatar {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	object-fit: cover;
	vertical-align: middle;
}

.psyern-lb__name {
	font-weight: 600;
}

.psyern-lb__kd {
	font-weight: 700;
}

.psyern-lb__playtime {
	font-size: 0.8rem;
	opacity: 0.7;
}

/* ─── Accessibility ─── */

.psyern-lb__mode-btn:focus-visible,
.psyern-lb__limit-btn:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.psyern-lb__table tbody tr:focus-within {
	outline: 1px solid currentColor;
	outline-offset: -1px;
}

.psyern-lb__sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.psyern-lb__skip-link {
	position: absolute;
	top: -40px;
	left: 0;
	padding: 8px 16px;
	z-index: 100;
	font-size: 0.85rem;
}

.psyern-lb__skip-link:focus {
	top: 0;
}

/* ─── Animations ─── */
@keyframes psyern-row-in {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: translateY(0); }
}

.psyern-lb__table tbody tr:nth-child(1) { animation-delay: 0.05s; }
.psyern-lb__table tbody tr:nth-child(2) { animation-delay: 0.1s; }
.psyern-lb__table tbody tr:nth-child(3) { animation-delay: 0.15s; }
.psyern-lb__table tbody tr:nth-child(4) { animation-delay: 0.2s; }
.psyern-lb__table tbody tr:nth-child(5) { animation-delay: 0.25s; }
.psyern-lb__table tbody tr:nth-child(6) { animation-delay: 0.3s; }
.psyern-lb__table tbody tr:nth-child(7) { animation-delay: 0.35s; }
.psyern-lb__table tbody tr:nth-child(8) { animation-delay: 0.4s; }
.psyern-lb__table tbody tr:nth-child(9) { animation-delay: 0.45s; }
.psyern-lb__table tbody tr:nth-child(10) { animation-delay: 0.5s; }

/* ─── Loading / Error ─── */
.psyern-lb__loading {
	text-align: center;
	padding: 40px;
	font-size: 0.9rem;
	opacity: 0.6;
}

/* ─── Responsive ─── */

/* Tablet */
@media (max-width: 768px) {
	.psyern-lb {
		padding: 16px 12px;
	}

	.psyern-lb__top3 {
		grid-template-columns: 1fr;
		gap: 8px;
	}

	.psyern-lb__top3-card--1 {
		transform: none;
		order: -1;
	}

	.psyern-lb__top3-avatar {
		width: 44px;
		height: 44px;
	}

	.psyern-lb__controls {
		flex-direction: column;
		align-items: flex-start;
	}

	/* Adjust sticky offsets for smaller avatar column */
	.psyern-lb__table th:nth-child(2),
	.psyern-lb__table td:nth-child(2) {
		left: 36px;
	}

	.psyern-lb__table th:nth-child(3),
	.psyern-lb__table td:nth-child(3) {
		left: 66px;
		min-width: 100px;
		max-width: 140px;
	}
}

/* Mobile */
@media (max-width: 480px) {
	.psyern-lb {
		padding: 10px 8px;
		font-size: 12px;
	}

	.psyern-lb__title {
		font-size: 1rem;
	}

	.psyern-lb__mode-btn {
		padding: 6px 14px;
		font-size: 0.75rem;
	}

	.psyern-lb__top3-card {
		padding: 14px 8px;
	}

	.psyern-lb__top3-name {
		font-size: 0.85rem;
	}

	.psyern-lb__table th,
	.psyern-lb__table td {
		padding: 8px 6px;
		font-size: 0.75rem;
	}

	/* On very small screens, only pin rank + name (skip avatar) */
	.psyern-lb__table th:nth-child(2),
	.psyern-lb__table td:nth-child(2) {
		position: static;
	}

	.psyern-lb__table th:nth-child(3),
	.psyern-lb__table td:nth-child(3) {
		left: 36px;
		min-width: 80px;
		max-width: 110px;
		font-size: 0.7rem;
	}

	.psyern-lb__avatar {
		width: 22px;
		height: 22px;
	}
}

/* Reduced motion (WCAG 2.3.3) */
@media (prefers-reduced-motion: reduce) {
	.psyern-lb__table tbody tr {
		animation: none;
	}
	.psyern-lb__top3-card {
		transition: none;
	}
	.psyern-lb,
	.psyern-lb * {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}
