/* WoW-style Backpack overlay (window.TPQPlayBag). Floats above the action bar
   (z 160) as an anchored pop-over; bottom-sheet on phones. Matches the HUD slot
   aesthetic in play-polish.css. */

.tpq-bag-backdrop {
	position: fixed;
	inset: 0;
	z-index: 198;
	background: transparent;
}

/* The panel sets an explicit display (flex), which would otherwise beat the UA
   [hidden]{display:none} rule and leave it permanently visible. Restore hide-on-hidden. */
.tpq-bag[hidden],
.tpq-bag-backdrop[hidden] {
	display: none !important;
}

.tpq-bag {
	position: fixed;
	z-index: 200;
	width: min(22rem, calc(100vw - 1.5rem));
	display: flex;
	flex-direction: column;
	color: var(--text, #e8ecf4);
	background:
		linear-gradient(180deg, rgba(46, 40, 64, 0.97), rgba(18, 16, 26, 0.98));
	border: 1px solid rgba(241, 196, 15, 0.4);
	border-radius: 14px;
	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.1),
		0 18px 48px -14px rgba(0, 0, 0, 0.85),
		0 0 0 1px rgba(0, 0, 0, 0.6);
	backdrop-filter: blur(12px);
	animation: tpq-bag-pop 0.16s ease-out;
}
@keyframes tpq-bag-pop {
	from { opacity: 0; transform: translateY(6px) scale(0.98); }
	to { opacity: 1; transform: none; }
}

.tpq-bag-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.55rem 0.65rem 0.5rem 0.85rem;
	border-bottom: 1px solid rgba(241, 196, 15, 0.18);
	background: linear-gradient(180deg, rgba(241, 196, 15, 0.08), transparent);
	border-radius: 14px 14px 0 0;
	cursor: grab;
	touch-action: none; /* the title bar owns the drag gesture */
	user-select: none;
	-webkit-user-select: none;
}
.tpq-bag.is-moving .tpq-bag-head { cursor: grabbing; }
.tpq-bag.is-moving { transition: none; }
/* Desktop affordance: the title bar is a drag handle. */
.tpq-bag-title::before {
	content: "⠿";
	margin-right: 0.4rem;
	color: rgba(246, 231, 184, 0.45);
	font-size: 0.85rem;
	vertical-align: 1px;
}
.tpq-bag.is-sheet .tpq-bag-head { cursor: default; }
.tpq-bag.is-sheet .tpq-bag-title::before { content: none; }
/* The close button is not part of the drag handle. */
.tpq-bag-close { cursor: pointer; touch-action: auto; }
.tpq-bag-title {
	font-family: var(--font-display, "Fredoka", sans-serif);
	font-size: 1.05rem;
	font-weight: 700;
	letter-spacing: 0.02em;
	color: #f6e7b8;
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}
.tpq-bag-count {
	margin-right: auto;
	margin-left: 0.55rem;
	padding: 0.05rem 0.4rem;
	border-radius: 999px;
	font-family: var(--font-numeric, "Fredoka", sans-serif);
	font-size: 0.7rem;
	font-weight: 700;
	color: rgba(232, 236, 244, 0.7);
	background: rgba(255, 255, 255, 0.06);
	border: 1px solid rgba(255, 255, 255, 0.08);
}
.tpq-bag-count.is-full {
	color: #ffd9d2;
	background: rgba(231, 76, 60, 0.2);
	border-color: rgba(231, 76, 60, 0.45);
}
.tpq-bag-close {
	display: grid;
	place-items: center;
	width: 1.7rem;
	height: 1.7rem;
	padding: 0;
	border-radius: 8px;
	border: 1px solid rgba(231, 76, 60, 0.45);
	background: linear-gradient(180deg, rgba(231, 76, 60, 0.25), rgba(231, 76, 60, 0.12));
	color: #ffd9d2;
	font-size: 0.9rem;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.1s ease;
}
.tpq-bag-close:hover { background: rgba(231, 76, 60, 0.4); }
.tpq-bag-close:active { transform: scale(0.92); }

.tpq-bag-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 0.4rem;
	padding: 0.7rem;
	overflow-y: auto;
	max-height: min(60vh, 26rem);
}

/* A slot mirrors the HUD action-bar frame so the bag feels part of the same kit. */
.tpq-bag-slot {
	position: relative;
	aspect-ratio: 1 / 1;
	display: grid;
	place-items: center;
	padding: 0;
	border-radius: 10px;
	background:
		linear-gradient(160deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 55%),
		linear-gradient(180deg, #232838, #14171f);
	border: 1px solid rgba(255, 255, 255, 0.08);
	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.08),
		inset 0 -2px 6px rgba(0, 0, 0, 0.5);
	color: inherit;
	font: inherit;
}
.tpq-bag-slot.is-empty {
	background:
		repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.015) 0 6px, transparent 6px 12px),
		linear-gradient(180deg, #15171f, #0e1016);
	border-style: dashed;
	border-color: rgba(255, 255, 255, 0.05);
	box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.55);
}
.tpq-bag-slot.is-filled {
	cursor: grab;
	touch-action: none; /* let pointer-drag own the gesture */
	transition: transform 0.1s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.tpq-bag-slot.is-filled:hover { transform: translateY(-1px); }
.tpq-bag-slot.is-filled:active { cursor: grabbing; }
.tpq-bag-slot.is-active {
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25), 0 0 0 2px rgba(246, 231, 184, 0.4);
}
.tpq-bag-slot.is-dragging { opacity: 0.35; }
.tpq-bag-slot.is-drop {
	border-color: rgba(246, 231, 184, 0.7) !important;
	box-shadow: inset 0 0 12px rgba(246, 231, 184, 0.25), 0 0 0 2px rgba(246, 231, 184, 0.5);
}

.tpq-bag-slot-icon {
	font-size: 1.6rem;
	line-height: 1;
	filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
	pointer-events: none;
}
.tpq-bag-slot-qty {
	position: absolute;
	right: 2px;
	bottom: 1px;
	min-width: 1.05rem;
	padding: 0 0.18rem;
	font-family: var(--font-numeric, "Fredoka", sans-serif);
	font-size: 0.78rem;
	font-weight: 800;
	line-height: 1.25;
	text-align: right;
	color: #fff;
	text-shadow: 0 1px 2px #000, 0 0 3px #000;
	pointer-events: none;
}

/* Rarity rims — same palette as the loot system. */
.tpq-bag-slot[data-rarity="common"] { border-color: rgba(149, 165, 166, 0.55); }
.tpq-bag-slot[data-rarity="uncommon"] { border-color: rgba(46, 204, 113, 0.6); }
.tpq-bag-slot[data-rarity="rare"] { border-color: rgba(52, 152, 219, 0.65); }
.tpq-bag-slot[data-rarity="epic"] { border-color: rgba(155, 89, 182, 0.7); }
.tpq-bag-slot[data-rarity="legendary"] { border-color: rgba(241, 196, 15, 0.72); }
.tpq-bag-slot[data-rarity="epic"],
.tpq-bag-slot[data-rarity="legendary"] {
	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.1),
		inset 0 -2px 6px rgba(0, 0, 0, 0.5),
		0 0 10px -2px currentColor;
}

/* Drag ghost follows the pointer. */
.tpq-bag-drag-ghost {
	position: fixed;
	z-index: 210;
	transform: translate(-50%, -50%) scale(1.05);
	border-radius: 10px;
	opacity: 0.92;
	pointer-events: none;
	box-shadow: 0 8px 22px -6px rgba(0, 0, 0, 0.8);
}

/* Money footer. */
.tpq-bag-money {
	display: flex;
	justify-content: flex-end;
	align-items: center;
	gap: 0.3rem;
	padding: 0.5rem 0.85rem 0.6rem;
	border-top: 1px solid rgba(241, 196, 15, 0.16);
	background: linear-gradient(0deg, rgba(241, 196, 15, 0.06), transparent);
	border-radius: 0 0 14px 14px;
}
.tpq-bag-gold {
	display: inline-flex;
	align-items: baseline;
	gap: 0.28rem;
	font-family: var(--font-numeric, "Fredoka", sans-serif);
}
.tpq-bag-gold b { font-size: 1rem; color: #f6e7b8; }
.tpq-bag-coin { font-size: 1rem; }
.tpq-bag-coin-label {
	font-size: 0.7rem;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: rgba(232, 236, 244, 0.55);
}

/* Tooltip (tap/click an item). Rarity-coloured name, Use/Install button. */
.tpq-bag-tooltip {
	position: absolute;
	z-index: 205;
	width: min(15rem, calc(100% - 1rem));
	padding: 0.55rem 0.65rem;
	border-radius: 10px;
	background: linear-gradient(180deg, rgba(20, 18, 28, 0.99), rgba(10, 9, 14, 0.99));
	border: 1px solid rgba(255, 255, 255, 0.16);
	box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.9);
	pointer-events: auto;
}
.tpq-bag-tip-name {
	font-weight: 700;
	font-size: 0.95rem;
	color: #d7d7d7;
}
.tpq-bag-tooltip[data-rarity="uncommon"] .tpq-bag-tip-name { color: #4cd97b; }
.tpq-bag-tooltip[data-rarity="rare"] .tpq-bag-tip-name { color: #4ea8e6; }
.tpq-bag-tooltip[data-rarity="epic"] .tpq-bag-tip-name { color: #c07fe0; }
.tpq-bag-tooltip[data-rarity="legendary"] .tpq-bag-tip-name { color: #f4cf42; }
.tpq-bag-tip-meta {
	margin-top: 0.1rem;
	font-size: 0.72rem;
	color: rgba(232, 236, 244, 0.6);
}
.tpq-bag-tip-desc {
	margin-top: 0.35rem;
	font-size: 0.8rem;
	line-height: 1.35;
	color: rgba(232, 236, 244, 0.9);
}
.tpq-bag-tip-foot {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 0.4rem 0.5rem;
	margin-top: 0.5rem;
}
.tpq-bag-tip-qty { font-size: 0.72rem; color: rgba(232, 236, 244, 0.6); }
.tpq-bag-tip-actions { display: inline-flex; gap: 0.35rem; }
.tpq-bag-tip-sellall { flex-basis: 100%; text-align: right; }
.tpq-bag-sell {
	padding: 0.3rem 0.6rem;
	border-radius: 8px;
	border: 1px solid rgba(241, 196, 15, 0.45);
	background: linear-gradient(180deg, rgba(241, 196, 15, 0.22), rgba(241, 196, 15, 0.1));
	color: #f6e7b8;
	font-weight: 700;
	font-size: 0.78rem;
	cursor: pointer;
	white-space: nowrap;
	transition: background 0.15s ease, transform 0.1s ease;
}
.tpq-bag-sell:hover { background: rgba(241, 196, 15, 0.32); }
.tpq-bag-sell:active { transform: scale(0.95); }
.tpq-bag-link {
	padding: 0;
	border: 0;
	background: none;
	color: rgba(246, 231, 184, 0.85);
	font-size: 0.72rem;
	text-decoration: underline;
	cursor: pointer;
}
.tpq-bag-link:hover { color: #fff; }
.tpq-bag-use {
	padding: 0.3rem 0.7rem;
	border-radius: 8px;
	border: 1px solid rgba(46, 204, 113, 0.5);
	background: linear-gradient(180deg, rgba(46, 204, 113, 0.32), rgba(46, 204, 113, 0.16));
	color: #d8ffe6;
	font-weight: 700;
	font-size: 0.8rem;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.1s ease;
}
.tpq-bag-use:hover { background: rgba(46, 204, 113, 0.45); }
.tpq-bag-use:active { transform: scale(0.95); }
.tpq-bag-use:disabled { opacity: 0.6; cursor: default; }

/* Phones → bottom sheet. */
.tpq-bag.is-sheet {
	left: 0 !important;
	right: 0;
	bottom: 0 !important;
	top: auto !important;
	width: 100%;
	border-radius: 16px 16px 0 0;
	border-bottom: 0;
	animation: tpq-bag-sheet 0.2s ease-out;
}
@keyframes tpq-bag-sheet {
	from { transform: translateY(100%); }
	to { transform: none; }
}
.tpq-bag.is-sheet .tpq-bag-grid {
	grid-template-columns: repeat(5, 1fr);
	max-height: 50vh;
	padding-bottom: calc(0.7rem + var(--play-safe-bottom, 0px));
}
@media (max-width: 640px) {
	.tpq-bag-backdrop { background: rgba(0, 0, 0, 0.45); }
}

@media (prefers-reduced-motion: reduce) {
	.tpq-bag, .tpq-bag.is-sheet { animation: none; }
}
