/*
 * Pet Guide.
 *
 * Square like the rest of the panel: radii come from the theme tokens, which
 * are 0. Colours come from the --mr-* tokens with translucent grey fallbacks
 * so the page still reads under the stock theme.
 */

.pet {
	--pet-radius: var(--radius-md, 6px);
	--pet-line: var(--mr-border, rgba(127, 127, 127, 0.35));
	--pet-line-strong: var(--mr-border-strong, rgba(127, 127, 127, 0.5));
	--pet-surface: rgba(127, 127, 127, 0.08);
	--pet-surface-2: rgba(127, 127, 127, 0.14);
	--pet-accent: var(--mr-primary, #7c5cff);
	--pet-gold: var(--mr-secondary, #ffd15c);
	--pet-pink: var(--mr-pink, #ec409e);
	--pet-muted: var(--mr-text-medium, rgba(127, 127, 127, 0.9));
	font-size: 14px;
	line-height: 1.45;
}

.pet *,
.pet *::before,
.pet *::after {
	box-sizing: border-box;
}

.pet-visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

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

/* ------------------------------------------------------------------ head */

.pet-head {
	display: flex;
	flex-wrap: wrap;
	gap: 16px;
	align-items: flex-end;
	justify-content: space-between;
	margin-bottom: 16px;
}

.pet-head h2 {
	margin: 0 0 6px;
}

.pet-sub {
	margin: 0;
	max-width: 70ch;
	opacity: 0.85;
}

.pet-stats {
	display: flex;
	gap: 8px;
}

.pet-stat {
	display: flex;
	flex-direction: column;
	align-items: center;
	min-width: 84px;
	padding: 8px 12px;
	border: 1px solid var(--pet-line);
	border-radius: var(--pet-radius);
	background: var(--pet-surface);
}

.pet-stat strong {
	font-size: 22px;
	line-height: 1.1;
	color: var(--pet-gold);
}

.pet-stat span {
	font-size: 12px;
	color: var(--pet-muted);
}

.pet-warn {
	padding: 10px 12px;
	border: 1px solid var(--mr-warning, #c88a00);
	border-radius: var(--pet-radius);
	background: rgba(255, 193, 77, 0.08);
}

/* ------------------------------------------------------------------ tabs */

.pet-tabs {
	display: flex;
	gap: 2px;
	border-bottom: 1px solid var(--pet-line);
	margin-bottom: 12px;
	overflow-x: auto;
}

.pet-tab {
	appearance: none;
	border: 0;
	border-bottom: 2px solid transparent;
	background: none;
	color: inherit;
	padding: 8px 14px;
	font: inherit;
	font-weight: 600;
	opacity: 0.75;
	cursor: pointer;
	white-space: nowrap;
}

.pet-tab:hover {
	opacity: 1;
}

.pet-tab.is-active {
	opacity: 1;
	border-bottom-color: var(--pet-accent);
	color: var(--mr-text-lightest, inherit);
}

/* --------------------------------------------------------------- toolbar */

.pet-toolbar {
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 12px;
	margin-bottom: 12px;
	border: 1px solid var(--pet-line);
	border-radius: var(--pet-radius);
	background: var(--pet-surface);
}

.pet-toolbar[hidden] {
	display: none;
}

.pet-toolbar__row {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	align-items: center;
}

.pet-search {
	flex: 1 1 320px;
	min-width: 0;
}

.pet input[type="search"],
.pet input[type="number"],
.pet select {
	width: 100%;
	min-height: 34px;
	padding: 6px 10px;
	border: 1px solid var(--pet-line-strong);
	border-radius: var(--pet-radius);
	background: var(--mr-bg-darkest, rgba(0, 0, 0, 0.2));
	color: inherit;
	font: inherit;
}

.pet input:focus-visible,
.pet select:focus-visible,
.pet button:focus-visible,
.pet a:focus-visible {
	outline: 2px solid var(--pet-accent);
	outline-offset: 1px;
}

.pet-field {
	display: flex;
	align-items: center;
	gap: 6px;
	margin: 0;
	white-space: nowrap;
}

.pet-field > span {
	font-size: 12px;
	color: var(--pet-muted);
}

.pet-field select {
	width: auto;
}

.pet-check {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin: 0;
	cursor: pointer;
	white-space: nowrap;
}

.pet-seg {
	display: inline-flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 0;
}

.pet-seg__label {
	font-size: 12px;
	color: var(--pet-muted);
	margin-right: 6px;
}

.pet-seg__btn,
.pet-chip,
.pet-btn {
	appearance: none;
	border: 1px solid var(--pet-line-strong);
	border-radius: var(--pet-radius);
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 13px;
	padding: 4px 10px;
	cursor: pointer;
	line-height: 1.4;
	text-decoration: none;
}

.pet-seg__btn + .pet-seg__btn {
	margin-left: -1px;
}

.pet-seg__btn.is-active {
	background: var(--pet-accent);
	border-color: var(--pet-accent);
	color: #fff;
	position: relative;
}

.pet-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.pet-chip {
	font-size: 12px;
	padding: 3px 9px;
	background: var(--pet-surface);
}

.pet-chip:hover,
.pet-btn--ghost:hover,
.pet-seg__btn:hover {
	border-color: var(--pet-accent);
}

.pet-chip.is-active {
	background: rgba(134, 117, 231, 0.25);
	border-color: var(--pet-accent);
	color: var(--mr-text-lightest, inherit);
}

.pet-btn--ghost {
	background: transparent;
}

.pet-count {
	margin: 0 0 8px;
	color: var(--pet-muted);
	font-size: 13px;
}

.pet-empty {
	padding: 24px;
	text-align: center;
	color: var(--pet-muted);
}

/* ------------------------------------------------------------------ grid */

.pet-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
	/* Every row as tall as the tallest card, so all cards line up. */
	grid-auto-rows: 1fr;
	gap: 10px;
}

.pet-card {
	appearance: none;
	display: flex;
	flex-direction: column;
	text-align: left;
	padding: 0;
	border: 1px solid var(--pet-line);
	border-radius: var(--pet-radius);
	background: var(--pet-surface);
	color: inherit;
	font: inherit;
	cursor: pointer;
	transition: border-color 0.15s, transform 0.15s, background 0.15s;
}

.pet-card:hover {
	border-color: var(--pet-accent);
	background: var(--pet-surface-2);
	transform: translateY(-1px);
}

.pet-card__stage,
.pet-hero__stage {
	display: flex;
	align-items: flex-end;
	justify-content: center;
	height: 112px;
	padding: 8px;
	background:
		radial-gradient(ellipse 40% 10% at 50% 88%, rgba(0, 0, 0, 0.45), transparent 70%),
		linear-gradient(180deg, rgba(134, 117, 231, 0.12), rgba(134, 117, 231, 0.02));
	border-bottom: 1px solid var(--pet-line);
	overflow: hidden;
}

.pet-sprite {
	max-width: 100%;
	max-height: 96px;
	image-rendering: pixelated;
	object-fit: contain;
}

.pet-sprite.is-missing {
	width: 40px;
	height: 40px;
	opacity: 0.2;
	background: var(--pet-surface-2);
}

.pet-sprite--sm {
	max-height: 48px;
	max-width: 64px;
}

.pet-sprite--lg {
	max-height: 150px;
}

.pet-card__main {
	flex: 1;
	padding: 10px 12px 6px;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.pet-card__name {
	font-weight: 700;
	font-size: 15px;
	color: var(--mr-text-lightest, inherit);
}

.pet-card__meta {
	font-size: 12px;
	color: var(--pet-muted);
}

.pet-card__name,
.pet-card__meta {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.pet-card__tier {
	margin-top: 4px;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--pet-gold);
}

.pet-badges {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
}

.pet-badges--card {
	flex-wrap: nowrap;
	overflow: hidden;
	min-height: 20px;
}

.pet-badge {
	font-size: 11px;
	padding: 1px 6px;
	border: 1px solid var(--pet-line-strong);
	border-radius: var(--pet-radius);
	white-space: nowrap;
}

.pet-badge--how-tame { border-color: rgba(71, 207, 101, 0.6); color: var(--mr-success, inherit); }
.pet-badge--how-evolution,
.pet-badge--evolves { border-color: rgba(134, 117, 231, 0.7); color: #b7abff; }
.pet-badge--how-trader { border-color: rgba(255, 209, 92, 0.6); color: var(--pet-gold); }
.pet-badge--how-shop,
.pet-badge--how-box,
.pet-badge--how-drop,
.pet-badge--how-cash { border-color: rgba(111, 151, 255, 0.6); color: var(--mr-info, inherit); }

.pet-bonus {
	list-style: none;
	margin: 0;
	padding: 0;
	font-size: 13px;
}

.pet-bonus li {
	padding: 1px 0;
}

/* On a card a bonus line takes at most two rows. */
.pet-card .pet-bonus li {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	overflow: hidden;
}

.pet-bonus__sub {
	padding-left: 12px !important;
	opacity: 0.9;
}

.pet-bonus__raw {
	font-family: ui-monospace, Consolas, monospace;
	font-size: 12px;
	opacity: 0.85;
}

.pet-card__foot {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	align-items: center;
	gap: 10px;
	padding: 6px 12px 8px;
	border-top: 1px solid var(--pet-line);
	font-size: 12px;
	color: var(--pet-muted);
}

.pet-card__slot {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	min-width: 0;
}

.pet-card__slot span {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.pet-icon {
	width: 24px;
	height: 24px;
	flex: 0 0 24px;
	image-rendering: pixelated;
	object-fit: contain;
}

.pet-icon.is-missing {
	display: inline-block;
	background: var(--pet-surface-2);
}

.pet-item {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	color: inherit;
	text-decoration: none;
	min-width: 0;
}

a.pet-item:hover span {
	color: var(--pet-accent);
	text-decoration: underline;
}

/* ----------------------------------------------------------------- trees */

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

.pet-tree {
	padding: 12px;
	border: 1px solid var(--pet-line);
	border-radius: var(--pet-radius);
	background: var(--pet-surface);
	overflow-x: auto;
}

.pet-tree__node {
	display: flex;
	align-items: center;
	gap: 0;
}

.pet-tree__pet,
.pet-petchip {
	appearance: none;
	display: inline-flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	flex: 0 0 auto;
	width: 104px;
	padding: 6px;
	border: 1px solid var(--pet-line-strong);
	border-radius: var(--pet-radius);
	background: var(--mr-bg-mid, rgba(0, 0, 0, 0.15));
	color: inherit;
	font: inherit;
	font-size: 12px;
	text-align: center;
	cursor: pointer;
}

.pet-tree__pet:hover,
.pet-petchip:hover {
	border-color: var(--pet-accent);
}

.pet-tree__pet.is-notpet,
.pet-petchip.is-notpet {
	cursor: default;
	opacity: 0.75;
	border-style: dashed;
}

.pet-tree__kids {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.pet-tree__edge {
	display: flex;
	align-items: center;
}

.pet-tree__arrow {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	width: 210px;
	flex: 0 0 210px;
	padding: 0 8px;
}

.pet-tree__arrowline {
	position: relative;
	height: 2px;
	margin: 6px 0;
	background: var(--pet-accent);
}

.pet-tree__arrowline::after {
	content: "";
	position: absolute;
	right: -1px;
	top: -4px;
	border: 5px solid transparent;
	border-left-color: var(--pet-accent);
	border-right: 0;
}

.pet-tree__mats,
.pet-evo__mats {
	display: flex;
	flex-direction: column;
	gap: 2px;
	font-size: 12px;
}

/* ------------------------------------------------------------------ help */

.pet-help__grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
	gap: 12px;
}

.pet-panel {
	padding: 14px;
	border: 1px solid var(--pet-line);
	border-radius: var(--pet-radius);
	background: var(--pet-surface);
}

.pet-panel h3,
.pet-sec__title {
	margin: 0 0 8px;
	font-size: 16px;
}

.pet-code {
	display: block;
	padding: 8px 10px;
	border: 1px solid var(--pet-line);
	background: var(--mr-bg-darkest, rgba(0, 0, 0, 0.2));
	font-size: 12px;
	white-space: normal;
	color: var(--pet-gold);
}

.pet-list {
	margin: 0;
	padding-left: 18px;
}

.pet-list li + li {
	margin-top: 6px;
}

.pet-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13px;
}

.pet-table th,
.pet-table td {
	padding: 4px 8px;
	border-bottom: 1px solid var(--pet-line);
	text-align: left;
}

/* ---------------------------------------------------------------- drawer */

.pet-noscroll,
.pet-noscroll body {
	overflow: hidden;
}

.pet-drawer {
	position: fixed;
	inset: 0;
	z-index: 1060;
	display: flex;
	justify-content: flex-end;
}

.pet-drawer[hidden] {
	display: none;
}

.pet-drawer__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.6);
}

.pet-drawer__panel {
	position: relative;
	width: min(760px, 100%);
	height: 100%;
	overflow-y: auto;
	background: var(--mr-bg-mid, #1b1b20);
	border-left: 1px solid var(--pet-line-strong);
	box-shadow: var(--shadow-lg, 0 0 40px rgba(0, 0, 0, 0.5));
	padding: 20px 22px 32px;
	animation: pet-slide 0.18s var(--ease-out, ease-out);
}

@keyframes pet-slide {
	from { transform: translateX(24px); opacity: 0; }
	to { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
	.pet-drawer__panel { animation: none; }
	.pet-card { transition: none; }
}

.pet-drawer__close {
	position: sticky;
	top: 0;
	float: right;
	width: 34px;
	height: 34px;
	margin: -8px -8px 0 0;
	border: 1px solid var(--pet-line-strong);
	border-radius: var(--pet-radius);
	background: var(--mr-bg-light, rgba(127, 127, 127, 0.2));
	color: inherit;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
	z-index: 2;
}

.pet-hero {
	display: flex;
	gap: 16px;
	align-items: stretch;
	margin-bottom: 16px;
}

.pet-hero__stage {
	flex: 0 0 180px;
	height: 170px;
	border: 1px solid var(--pet-line);
}

.pet-hero__text {
	display: flex;
	flex-direction: column;
	gap: 6px;
	min-width: 0;
}

.pet-hero__text h2 {
	margin: 0;
	padding-right: 40px;
}

.pet-hero__links {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: auto;
}

.pet-sec {
	padding: 14px 0;
	border-top: 1px solid var(--pet-line);
}

.pet-sec h4 {
	margin: 10px 0 6px;
	font-size: 13px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--pet-gold);
}

.pet-sec h4:first-of-type {
	margin-top: 0;
}

.pet-tiers {
	display: grid;
	grid-template-columns: repeat(5, minmax(0, 1fr));
	gap: 6px;
}

.pet-tiers__col {
	padding: 8px;
	border: 1px solid var(--pet-line);
	border-radius: var(--pet-radius);
	background: var(--pet-surface);
	min-width: 0;
}

.pet-tiers__col.is-empty {
	opacity: 0.55;
}

.pet-tiers__col.is-active {
	border-color: var(--pet-accent);
}

.pet-tiers__head {
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--pet-gold);
	margin-bottom: 4px;
}

.pet-row {
	display: grid;
	grid-template-columns: 110px 1fr;
	gap: 4px 12px;
	padding: 6px 0;
	align-items: center;
}

.pet-row + .pet-row {
	border-top: 1px dashed var(--pet-line);
}

.pet-row__label {
	font-size: 12px;
	color: var(--pet-muted);
}

.pet-row__value {
	display: flex;
	flex-wrap: wrap;
	gap: 4px 12px;
	align-items: center;
}

.pet-row__src {
	grid-column: 2;
	font-size: 13px;
}

.pet-row__src summary,
.pet-egg summary {
	cursor: pointer;
	color: var(--pet-accent);
}

.pet-src {
	list-style: none;
	margin: 6px 0 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.pet-src li {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 4px 8px;
}

.pet-src__kind {
	font-size: 11px;
	padding: 0 6px;
	border: 1px solid var(--pet-line-strong);
	border-radius: var(--pet-radius);
	color: var(--pet-muted);
}

.pet-src__cost {
	display: inline-flex;
	flex-wrap: wrap;
	gap: 2px 10px;
	color: var(--pet-muted);
}

.pet-calc {
	display: grid;
	grid-template-columns: 1fr 160px;
	gap: 12px;
	padding: 10px;
	border: 1px solid var(--pet-line);
	border-radius: var(--pet-radius);
	background: var(--pet-surface);
}

.pet-calc__in {
	display: flex;
	flex-wrap: wrap;
	gap: 8px 14px;
	align-items: center;
}

.pet-field--sm input {
	width: 80px;
}

.pet-field--range {
	flex: 1 1 100%;
	flex-direction: column;
	align-items: stretch;
}

.pet-field--range input {
	width: 100%;
	accent-color: var(--mr-primary, #7c5cff);
}

.pet-calc__out {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: flex-start;
	font-size: 12px;
}

.pet-calc__big {
	font-size: 30px;
	font-weight: 700;
	color: var(--mr-success, inherit);
	line-height: 1.1;
}

.pet-maps {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	margin-top: 4px;
}

.pet-map {
	font-size: 12px;
	padding: 1px 6px;
	border: 1px solid var(--pet-line);
	border-radius: var(--pet-radius);
	background: var(--pet-surface);
}

.pet-evo {
	display: grid;
	grid-template-columns: 110px 112px 1fr;
	gap: 10px;
	align-items: center;
	padding: 6px 0;
}

.pet-evo + .pet-evo {
	border-top: 1px dashed var(--pet-line);
}

.pet-evo__dir {
	font-size: 12px;
	color: var(--pet-muted);
}

.pet-dl {
	display: grid;
	grid-template-columns: 130px 1fr;
	gap: 4px 12px;
	margin: 0;
	font-size: 13px;
}

.pet-dl dt {
	color: var(--pet-muted);
	font-weight: 400;
}

.pet-dl dd {
	margin: 0;
}

.pet-egg p {
	margin: 4px 0;
	font-size: 13px;
}

.pet-foot {
	margin-top: 16px;
	font-size: 12px;
	color: var(--pet-muted);
}

/* --------------------------------------------------------------- narrow */

@media (max-width: 760px) {
	.pet-field {
		flex: 1 1 45%;
	}
	.pet-field select {
		width: 100%;
	}
	.pet-grid {
		grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
	}
}

@media (max-width: 640px) {
	.pet-drawer__panel {
		padding: 16px 14px 28px;
	}
	.pet-hero {
		flex-direction: column;
	}
	.pet-hero__stage {
		flex-basis: auto;
	}
	.pet-tiers {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
	.pet-calc {
		grid-template-columns: 1fr;
	}
	.pet-evo {
		grid-template-columns: 1fr;
	}
	.pet-row {
		grid-template-columns: 1fr;
	}
	.pet-row__src {
		grid-column: 1;
	}
	.pet-tree__arrow {
		width: 150px;
		flex-basis: 150px;
	}
}
