/* =========================================================
   WAHFAMILY WORLD MAP (js/wah-map.js)
   Sewn, like the suits: a flat cloth world with stitched coasts, a sewing pin in every
   WAH country with a label tag on a thread, and the WAHs themselves as patches.
   The map is drawn on a canvas in these colours; everything on top is plain HTML.
   ========================================================= */

.wah-map,
.wah-map-list {
	--map-cloth: #cfe2ef;          /* the sea */
	--map-hem: #1f8f96;            /* the stitched frame */
	--map-felt: #b0c7da;           /* land */
	--map-seam: rgba(255, 255, 255, 0.8);
	--map-coast: rgba(19, 35, 58, 0.42);
	--map-wah: #5fbcc0;            /* countries with WAHs */
	--map-wah-hover: #46aab0;
	--map-current: #2c9da3;
	--map-thread: #c8670a;         /* thread: WAH country stitching, tag strings, patch threads */
	--map-pin: #f89d32;
	--map-tag: #ffe16a;
	--map-tag-ink: #13233a;
	--map-tag-stitch: rgba(19, 35, 58, 0.5);
	--map-patch: #fbfdff;
	--map-ink: #13233a;
	--map-panel: rgba(255, 255, 255, 0.94);
	--map-panel-line: rgba(23, 45, 74, 0.14);
	--map-drop: rgba(9, 25, 48, 0.28);
}

html[data-theme="dark"] .wah-map,
html[data-theme="dark"] .wah-map-list {
	--map-cloth: #11294a;
	--map-hem: rgba(255, 225, 106, 0.5);
	--map-felt: #26496f;
	--map-seam: rgba(10, 23, 38, 0.75);
	--map-coast: rgba(214, 232, 250, 0.5);
	--map-wah: #2e9298;
	--map-wah-hover: #39a8ae;
	--map-current: #43bfc2;
	--map-thread: #ffe16a;
	--map-patch: #eef5fa;
	--map-ink: #e6f0fa;
	--map-panel: rgba(13, 31, 51, 0.94);
	--map-panel-line: rgba(160, 205, 240, 0.18);
	--map-drop: rgba(0, 0, 0, 0.5);
}

.wah-map {
	position: relative;
	width: 100%;
	max-width: 1300px;
	margin: 46px auto 10px;
	aspect-ratio: 1000 / 600;
	border-radius: 18px;
	overflow: hidden;
	background: var(--map-cloth); /* the sea, under the map while it is being repainted */
	border: 1px solid var(--map-panel-line);
	isolation: isolate;
}

/* The stitched frame, sewn over the edge of the map. */
.wah-map::after {
	content: '';
	position: absolute;
	inset: 7px;
	border: 1.5px dashed var(--map-hem);
	border-radius: 12px;
	pointer-events: none;
	z-index: 1;
}

.wah-map-stage {
	position: absolute;
	inset: 0;
	cursor: grab;
	/* One finger scrolls the page past the map; two fingers move and zoom the map (js/wah-map.js). */
	touch-action: pan-y;
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
	-webkit-tap-highlight-color: transparent;
}
.wah-map-stage:focus { outline: none; }

/* "Use two fingers to move the map" / "Hold Ctrl and scroll to zoom the map": shown for a moment when someone
   tries the other way. */
.wah-map-coop {
	position: absolute;
	inset: 0;
	z-index: 6;
	display: grid;
	place-items: center;
	padding: 24px;
	background: rgba(9, 25, 48, 0.5);
	color: #fff;
	font-size: 20px;
	font-weight: 800;
	line-height: 1.3;
	text-align: center;
	text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.25s ease;
}
.wah-map.is-coop .wah-map-coop { opacity: 1; transition-duration: 0.12s; }
/* Keyboard focus on the map: the stitched frame turns into a solid thread. */
.wah-map:has(.wah-map-stage:focus-visible)::after { border: 3px solid var(--map-thread); }
.wah-map-stage.is-pointing { cursor: pointer; }
.wah-map.is-dragging .wah-map-stage,
.wah-map.is-dragging .wah-map-stage * { cursor: grabbing; }

/* Painted a bit bigger than the stage and slid / scaled around by the script (sizes set there). */
.wah-map-canvas {
	position: absolute;
	left: 0;
	top: 0;
	display: block;
	transform-origin: 0 0;
	will-change: transform;
	z-index: 0;
}

/* ---------- Pins, tags and threads ---------- */

.wah-map-overlay {
	position: absolute;
	inset: 0;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.3s ease;
	z-index: 2;
}
.wah-map.is-ready .wah-map-overlay { opacity: 1; }

.wah-map-threads {
	position: absolute;
	left: 0;
	top: 0;
	overflow: visible;
	pointer-events: none;
}

.wah-map-thread {
	fill: none;
	stroke: var(--map-thread);
	stroke-width: 1.4;
	stroke-linecap: round;
	opacity: 0;
	transition: opacity 0.25s ease, stroke-width 0.2s ease;
}
.wah-map-thread.is-tag { opacity: 0.9; }
.wah-map.is-zoomed .wah-map-thread.is-tag { opacity: 0; transition: none; }
.wah-map-thread.is-shown {
	opacity: 0.5;
	transition-delay: 0.5s;
}
.wah-map-thread.is-hot,
.wah-map-thread.is-shown.is-hot {
	opacity: 1;
	stroke-width: 2.4;
	transition-delay: 0s;
}

/* A sewing pin pushed into the country. Pins, tags and the patch groups are moved with transforms only. */
.wah-map-head,
.wah-map-bubble,
.wah-map-orbit {
	position: absolute;
	left: 0;
	top: 0;
	will-change: transform;
}

.wah-map-head {
	width: 10px;
	height: 10px;
	margin: -5px 0 0 -5px;
	border-radius: 50%;
	background: radial-gradient(circle at 34% 30%, #ffe2bd 0 14%, var(--map-pin) 46%, #a9560a 100%);
	box-shadow: 2px 3px 2px rgba(0, 0, 0, 0.32);
	z-index: 1;
}
.wah-map.is-zoomed .wah-map-head { opacity: 0; }
.wah-map.is-zoomed .wah-map-head.is-current {
	opacity: 1;
	width: 18px;
	height: 18px;
	margin: -9px 0 0 -9px;
	z-index: 4;
}

/* The country tag: a woven label hanging on its thread. Placed by the script with `translate` (centred on its spot),
   so growing it on hover (`scale`, from its bottom edge) never moves it out from under the mouse. */
.wah-map-bubble {
	will-change: translate, scale;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 6px 8px 6px 9px;
	border: 0;
	border-radius: 6px;
	background: var(--map-tag);
	color: var(--map-tag-ink);
	font: inherit;
	font-size: 13px;
	font-weight: 700;
	line-height: 1;
	white-space: nowrap;
	cursor: pointer;
	pointer-events: auto;
	outline: 1.5px dashed var(--map-tag-stitch);
	outline-offset: -4px;
	box-shadow: 0 2px 0 rgba(9, 25, 48, 0.18), 0 6px 12px var(--map-drop);
	z-index: 2;
	transform-origin: 50% 100%;
	transition: scale 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}
.wah-map-bubble.is-hover,
.wah-map-bubble:focus-visible {
	scale: 1.08;
	z-index: 3;
	box-shadow: 0 2px 0 rgba(9, 25, 48, 0.18), 0 6px 12px var(--map-drop), 0 0 0 3px var(--map-thread);
}
.wah-map-flag { font-size: 1.15em; }
.wah-map-flag:empty { display: none; }
.wah-map-count {
	padding-left: 6px;
	border-left: 1.5px dashed var(--map-tag-stitch);
	font-size: 1.15em;
	font-weight: 900;
	font-variant-numeric: tabular-nums;
}

.wah-map.is-zoomed .wah-map-bubble {
	opacity: 0;
	pointer-events: none;
}

/* ---------- WAH patches (around an open country) ---------- */

.wah-map-orbit {
	width: 0;
	height: 0;
	z-index: 3;
}

.wah-map-orbit-threads {
	position: absolute;
	left: 0;
	top: 0;
	overflow: visible;
	pointer-events: none;
}

.wah-map-pin {
	--ring: #79afd1;
	position: absolute;
	left: 0;
	top: 0;
	width: var(--patch, 64px);
	height: var(--patch, 64px);
	margin: calc(var(--patch, 64px) / -2) 0 0 calc(var(--patch, 64px) / -2);
	padding: 0;
	border-radius: 24%;
	border: 3px solid var(--ring);
	background: var(--map-patch);
	cursor: pointer;
	pointer-events: none;
	opacity: 0;
	translate: var(--fx, 0px) var(--fy, 0px);
	scale: 0.2;
	rotate: var(--tilt, 0deg);
	box-shadow: 0 2px 0 rgba(9, 25, 48, 0.14), 0 8px 16px var(--map-drop);
	transition: opacity 0.25s ease, translate 0.45s cubic-bezier(0.3, 0.9, 0.3, 1), scale 0.45s cubic-bezier(0.34, 1.4, 0.64, 1), rotate 0.25s ease;
}
/* The stitching that holds the patch on. */
.wah-map-pin::after {
	content: '';
	position: absolute;
	inset: 3px;
	border-radius: 20%;
	border: 1.5px dashed var(--ring);
	pointer-events: none;
}
/* Rarity is a data attribute (not a rarity-* class), so the WAH card styles on the page don't reach the map. */
.wah-map [data-rarity="rare"] { --ring: #3fc7b6; }
.wah-map [data-rarity="epic"] { --ring: #a67cff; }
.wah-map [data-rarity="legendary"] { --ring: #f2c522; --ring-glow: rgba(242, 197, 34, 0.6); }
.wah-map [data-rarity="mythic"] { --ring: #f8892a; --ring-glow: rgba(255, 95, 162, 0.55); }

/* How rare: a little sewn-on label of stars (rare and up), and a glow round legendary and mythic patches.
   The glow only fades in and out (opacity), so it costs next to nothing while the map moves. */
.wah-map-stars {
	position: absolute;
	left: 50%;
	bottom: -9px;
	translate: -50% 0;
	padding: 3px 6px 2px;
	border-radius: 5px;
	background: var(--ring);
	color: #13233a;
	font-size: 9px;
	font-weight: 900;
	letter-spacing: 0.5px;
	line-height: 1;
	white-space: nowrap;
	box-shadow: 0 2px 4px rgba(9, 25, 48, 0.3);
	pointer-events: none;
	z-index: 1;
}
.wah-map-pin:has(.wah-map-stars) .wah-map-name { top: calc(100% + 14px); }
.wah-map-pin::before {
	content: '';
	position: absolute;
	inset: -3px;
	border-radius: 26%;
	pointer-events: none;
	opacity: 0;
}
.wah-map-pin.is-shown:is([data-rarity="legendary"], [data-rarity="mythic"])::before {
	box-shadow: 0 0 10px 2px var(--ring), 0 0 24px 6px var(--ring-glow);
	animation: wahPatchGlow 2.4s ease-in-out infinite;
}
.wah-map-pin.is-shown[data-rarity="mythic"] { animation: wahMythicBorder 5s linear infinite; }
@keyframes wahPatchGlow {
	0%, 100% { opacity: 0.45; }
	50% { opacity: 1; }
}

.wah-map-pin.is-shown {
	opacity: 1;
	translate: 0 0;
	scale: 1;
	pointer-events: auto;
	transition-delay: calc(var(--i, 0) * 22ms + 120ms);
}
.wah-map-pin.is-shown:focus-visible,
.wah-map-pin.is-shown.is-hover {
	scale: 1.12;
	rotate: 0deg;
	z-index: 4;
	outline: none;
	transition-delay: 0s;
	box-shadow: 0 2px 0 rgba(9, 25, 48, 0.14), 0 8px 16px var(--map-drop), 0 0 0 3px var(--map-thread);
}

.wah-map-pin img {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: 20%;
	object-fit: contain;
	padding: 10%;
	box-sizing: border-box;
	-webkit-user-drag: none;
	pointer-events: none;
}

.wah-map-name {
	position: absolute;
	left: 50%;
	top: calc(100% + 7px);
	translate: -50% 0;
	rotate: calc(var(--tilt, 0deg) * -1);
	padding: 4px 9px;
	border-radius: 6px;
	background: var(--map-panel);
	border: 1px solid var(--map-panel-line);
	color: var(--map-ink);
	font-size: 12px;
	font-weight: 800;
	white-space: nowrap;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.15s ease;
}
.wah-map-pin.is-hover .wah-map-name,
.wah-map-pin:focus-visible .wah-map-name { opacity: 1; }

/* ---------- Top bar, zoom buttons, hint, rarity key ---------- */

.wah-map-bar {
	position: absolute;
	top: 14px;
	left: 14px;
	right: 14px;
	display: flex;
	align-items: center;
	gap: 10px;
	pointer-events: none;
	z-index: 5;
}

.wah-map-back,
.wah-map-zoom button {
	pointer-events: auto;
	border: 0;
	border-radius: 6px;
	background: var(--map-tag);
	color: var(--map-tag-ink);
	font: inherit;
	font-weight: 800;
	cursor: pointer;
	outline: 1.5px dashed var(--map-tag-stitch);
	outline-offset: -4px;
	box-shadow: 0 2px 0 rgba(9, 25, 48, 0.18), 0 6px 12px var(--map-drop);
	transition: scale 0.15s ease;
}
@media (hover: hover) {
	.wah-map-back:hover,
	.wah-map-zoom button:hover { scale: 1.06; }
}
.wah-map-back:active,
.wah-map-zoom button:active { scale: 0.94; }
.wah-map-back:focus-visible,
.wah-map-zoom button:focus-visible { box-shadow: 0 0 0 3px var(--map-thread); }

.wah-map-back {
	padding: 9px 14px;
	font-size: 14px;
}

.wah-map-where {
	margin: 0 !important;
	padding: 8px 12px;
	border-radius: 6px;
	background: var(--map-panel);
	border: 1px solid var(--map-panel-line);
	color: var(--map-ink) !important;
	font-size: 15px;
	font-weight: 900;
}
.wah-map-where:empty { display: none; }

.wah-map-zoom {
	position: absolute;
	right: 16px;
	bottom: 16px;
	display: flex;
	flex-direction: column;
	gap: 6px;
	z-index: 5;
}
.wah-map-zoom button {
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	padding: 0;
	font-size: 22px;
	line-height: 1;
}

/* The hint fades away once the map has been touched. */
.wah-map-hint {
	position: absolute;
	bottom: 16px;
	left: 50%;
	translate: -50% 0;
	margin: 0 !important;
	padding: 7px 13px;
	border-radius: 6px;
	background: var(--map-panel);
	border: 1px solid var(--map-panel-line);
	color: var(--map-ink) !important;
	font-size: 13px !important;
	font-weight: 700;
	white-space: nowrap;
	pointer-events: none;
	transition: opacity 0.4s ease;
	z-index: 4;
}
.wah-map.is-used .wah-map-hint,
.wah-map.is-zoomed .wah-map-hint { opacity: 0; }
.wah-map-hint-touch { display: none; }
@media (hover: none), (pointer: coarse) {
	.wah-map-hint-mouse { display: none; }
	.wah-map-hint-touch { display: inline; }
}

/* What the patch colours mean: shown while a country is open. */
.wah-map-key {
	position: absolute;
	top: 14px;
	right: 14px;
	display: flex;
	gap: 12px;
	margin: 0 !important;
	padding: 8px 12px;
	border-radius: 6px;
	background: var(--map-panel);
	border: 1px solid var(--map-panel-line);
	color: var(--map-ink) !important;
	font-size: 12px !important;
	font-weight: 700;
	line-height: 1;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.3s ease;
	z-index: 5;
}
.wah-map.is-zoomed .wah-map-key { opacity: 1; transition-delay: 0.4s; }
.wah-map-key span {
	--ring: #79afd1;
	display: inline-flex;
	align-items: center;
	gap: 5px;
}
.wah-map-key span::before {
	content: '';
	width: 10px;
	height: 10px;
	border-radius: 3px;
	border: 2px solid var(--ring);
	background: var(--map-patch);
}

/* ---------- Country list under the map ---------- */

.wah-map-list {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px;
	max-width: 1300px;
	margin: 16px auto 0;
}

.wah-map-chip {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	padding: 6px 7px 6px 12px;
	border-radius: 8px;
	border: 1px solid var(--map-panel-line);
	background: var(--map-panel);
	color: var(--map-ink);
	font: inherit;
	font-size: 15px;
	font-weight: 800;
	line-height: 1;
	cursor: pointer;
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.wah-map-chip-flag { font-size: 18px; }
.wah-map-chip-flag:empty { display: none; }
.wah-map-chip-count {
	display: grid;
	place-items: center;
	min-width: 30px;
	height: 30px;
	padding: 0 8px;
	border-radius: 5px;
	background: var(--map-tag);
	color: var(--map-tag-ink);
	font-size: 14px;
	font-weight: 900;
	outline: 1.5px dashed var(--map-tag-stitch);
	outline-offset: -3px;
}
.wah-map-chip.is-active {
	border-color: var(--map-thread);
	box-shadow: 0 0 0 2px var(--map-thread);
}
.wah-map-chip:focus-visible { outline: 2px solid var(--map-thread); outline-offset: 3px; }
@media (hover: hover) {
	.wah-map-chip:hover { border-color: var(--map-thread); }
}

/* The cards themselves are only shown as pop-ups (opened from the map). */
.wah-map-cards .wah-card { display: none !important; }
.wah-map-cards .wah-item { margin: 0; height: 0; }

/* ---------- Phones ---------- */

@media (max-width: 700px) {
	.wah-map-coop { font-size: 17px; }
	.wah-map {
		aspect-ratio: 1 / 1.12;
		margin-top: 26px;
		border-radius: 14px;
	}
	.wah-map::after { inset: 5px; border-radius: 10px; }
	.wah-map-key,
	.wah-map-label { display: none; }
	.wah-map-bubble { padding: 5px 7px; gap: 5px; font-size: 12px; }
	.wah-map-bar { top: 10px; left: 10px; right: 10px; gap: 8px; }
	.wah-map-back { padding: 8px 12px; font-size: 13px; white-space: nowrap; flex: none; }
	.wah-map-back-long { display: none; }
	.wah-map-where {
		min-width: 0;
		padding: 7px 11px;
		font-size: 13px;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.wah-map-zoom { right: 12px; bottom: 12px; }
	.wah-map.is-zoomed .wah-map-zoom { display: none; }
	.wah-map-zoom button { width: 44px; height: 44px; }
	.wah-map-hint {
		left: 12px;
		right: 66px;
		bottom: 12px;
		translate: none;
		white-space: normal;
		font-size: 12px !important;
		line-height: 1.3;
	}
	.wah-map-list { margin-top: 14px; gap: 7px; }
	.wah-map-chip { font-size: 14px; min-height: 42px; padding: 5px 6px 5px 10px; gap: 6px; }
	.wah-map-chip-count { min-width: 28px; height: 28px; font-size: 13px; }
}

/* Redrawn in the admin while a country is open: show it as it was, without the fly-out again. */
.wah-map.is-instant .wah-map-pin,
.wah-map.is-instant .wah-map-thread { transition: none !important; }

/* ---------- The WAH cards (pop-ups): rarity you can see ---------- */

.wah-world .wah-popup[data-rarity] {
	aspect-ratio: auto;
	max-height: calc(100vh - 48px);
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-width: thin;
	border-color: var(--rar);
	box-shadow: 0 25px 70px rgba(0, 0, 0, 0.42), 0 0 44px var(--rar-glow);
}
.wah-world .wah-popup[data-rarity="mythic"] { animation: wahMythicBorder 5s linear infinite; }
.wah-world .wah-popup .wah-popup-img { outline-color: var(--rar); }
.wah-world .wah-popup h3 small { font-size: 0.55em; font-weight: 800; opacity: 0.7; }
.wah-world .wah-popup-rarity.wah-rarity-badge {
	display: inline-flex;
	margin-bottom: 12px;
	padding: 7px 13px 7px 11px;
	background: rgba(9, 25, 48, 0.55);
	font-size: 12px;
}
.wah-world .wah-popup-rarity.wah-rarity-badge[data-rarity="legendary"] {
	background: linear-gradient(90deg, rgba(242, 197, 34, 0.32), rgba(9, 25, 48, 0.6));
}
.wah-world .wah-popup-rarity.wah-rarity-badge[data-rarity="mythic"] {
	background:
		linear-gradient(rgba(9, 25, 48, 0.82), rgba(9, 25, 48, 0.82)) padding-box,
		linear-gradient(90deg, #f8892a, #ff5fa2, #a67cff, #3fc7b6, #ffe16a, #f8892a) border-box;
	background-size: 100% 100%, 300% 100%;
}
.wah-world .wah-popup-social { margin-top: 14px; }

/* The light sweep (rare and up) and a twinkle (legendary, mythic): a layer over the card, moved with transforms. */
.wah-world .wah-popup-shine {
	position: absolute;
	inset: 0;
	z-index: 4;
	overflow: hidden;
	border-radius: inherit;
	pointer-events: none;
}
.wah-world .wah-popup-shine::before {
	content: '';
	position: absolute;
	top: -20%;
	bottom: -20%;
	left: -40%;
	width: 26%;
	opacity: 0;
	background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
	transform: skewX(-18deg);
}
.wah-world .wah-modal-toggle:checked ~ .wah-modal .wah-popup:is([data-rarity="rare"], [data-rarity="epic"], [data-rarity="legendary"], [data-rarity="mythic"]) .wah-popup-shine::before {
	opacity: 1;
	animation: wahSweep 5s ease-in-out 0.3s infinite;
}
.wah-world .wah-popup[data-rarity="legendary"] .wah-popup-shine::before {
	background: linear-gradient(90deg, transparent, rgba(255, 236, 150, 0.5), transparent);
	animation-duration: 3.4s !important;
}
.wah-world .wah-popup[data-rarity="mythic"] .wah-popup-shine::before {
	background: linear-gradient(90deg, transparent, rgba(255, 140, 200, 0.4), rgba(255, 236, 150, 0.55), rgba(140, 240, 225, 0.4), transparent);
	animation-duration: 3s !important;
}
.wah-world .wah-popup:is([data-rarity="legendary"], [data-rarity="mythic"]) .wah-popup-shine::after {
	content: '✦';
	position: absolute;
	top: 26px;
	left: 30px;
	color: #fff6c8;
	font-size: 26px;
	line-height: 1;
	text-shadow: 0 0 12px var(--rar), 0 0 24px var(--rar);
	animation: wahSparkle 2.2s ease-in-out infinite;
}
@keyframes wahSparkle {
	0%, 100% { opacity: 0; transform: scale(0.4) rotate(0deg); }
	50% { opacity: 1; transform: scale(1) rotate(45deg); }
}

@media (max-width: 768px) {
	.wah-world .wah-popup[data-rarity] { border-color: var(--rar) !important; max-height: 86vh !important; }
}

@media (prefers-reduced-motion: reduce) {
	.wah-map-pin,
	.wah-map-pin.is-shown,
	.wah-map-bubble,
	.wah-map-thread { transition: none; }
	.wah-map-pin::before,
	.wah-map-pin.is-shown,
	.wah-world .wah-popup,
	.wah-world .wah-popup-shine::before,
	.wah-world .wah-popup-shine::after { animation: none !important; }
}
