/* =============================================================================
 * WoW-style character "model" layer for the /play character sheet.
 *
 * Adds on top of the existing .char-sheet / .char-portrait-col styles in play.css:
 *   - the centered per-class CHARACTER SPRITE stage (archetype × gender),
 *   - the active COMPANION PET sprite beside the figure,
 *   - the MALE / FEMALE segmented toggle under the model,
 *   - equipped gear-slot ICON art (render endpoint) with emoji fallback.
 *
 * Markup is built by ui/charsheet.js (buildCharModelStage / slotIconHtml) and
 * mounted by routes/profile.js. Falls back gracefully: when the sprite 404s the
 * emoji glyph is revealed instead, and when the model stage is absent the round
 * emoji portrait below it carries the column on its own.
 * ========================================================================== */

/* When the model stage is present, the round emoji portrait becomes a small
 * secondary medallion (still the avatar/level editor) below the big sprite. */
.char-portrait-col.has-model { gap: 0.5rem; }
.char-portrait-col.has-model .char-portrait {
	width: clamp(64px, 14vw, 84px);
	height: clamp(64px, 14vw, 84px);
}
.char-portrait-col.has-model .char-portrait-emoji {
	font-size: clamp(1.8rem, 6vw, 2.4rem);
}

/* --- Character model stage ------------------------------------------------- */
.char-model {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.45rem;
	width: 100%;
	/* Keep the hero model a sensible size when its column is wide (e.g. spanning
	   two columns on tablet) so it doesn't balloon across the whole sheet. */
	max-width: 320px;
	margin-inline: auto;
}
.char-model-stage {
	position: relative;
	display: flex;
	align-items: flex-end;
	justify-content: center;
	gap: 0.3rem;
	width: 100%;
	min-height: clamp(150px, 34vw, 220px);
	/* Bottom room so the level chip (pinned just under the figure's feet) isn't
	   clipped by overflow:hidden. */
	padding: 0.4rem 0.3rem 1.1rem;
	border-radius: 16px;
	border: 1px solid rgba(201, 162, 77, 0.28);
	background:
		radial-gradient(120% 80% at 50% 100%, rgba(201, 162, 77, 0.16), transparent 70%),
		linear-gradient(180deg, rgba(10, 14, 26, 0.55), rgba(0, 0, 0, 0.45));
	box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.55);
	overflow: hidden;
}
/* Visible ground plane the figure + pet stand on (horizon line near the base). */
.char-model-stage::before {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	height: 26%;
	background: linear-gradient(180deg, rgba(201, 162, 77, 0.12), rgba(201, 162, 77, 0.04) 45%, transparent);
	border-top: 1px solid rgba(201, 162, 77, 0.28);
	pointer-events: none;
	z-index: 0;
}
/* Contact shadow pinned under the figure's feet so it reads as standing, not floating. */
.char-model-stage::after {
	content: "";
	position: absolute;
	left: 50%;
	bottom: 14%;
	transform: translateX(-50%);
	width: 56%;
	height: 12px;
	border-radius: 50%;
	background: radial-gradient(closest-side, rgba(0, 0, 0, 0.6), transparent);
	pointer-events: none;
	z-index: 0;
}

/* No z-index here on purpose: the figure must NOT form a stacking context, so its
   children can layer independently around the pet — character behind the pet, level
   chip in front of it. (position: relative stays, to anchor the chip.) */
.char-model-figure {
	position: relative;
	display: grid;
	place-items: end center;
}
.char-model-sprite {
	display: block;
	max-height: clamp(140px, 30vw, 208px);
	max-width: 100%;
	width: auto;
	object-fit: contain;
	filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.6));
	/* Crisp pixel edges to match the duel's hero sprites — the source art is pixel
	   art, so `auto` was smearing it into a soft "settings avatar" thumbnail. */
	image-rendering: pixelated;
	/* z-index 1: above the ground plane (0), below the companion pet (1, later in DOM)
	   so the pet stands IN FRONT of the character. */
	position: relative;
	z-index: 1;
}
/* Emoji fallback when the sprite art is missing (sibling, revealed on <img> error). */
.char-model-fallback {
	font-size: clamp(3.4rem, 13vw, 5rem);
	line-height: 1;
	filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.6));
	position: relative;
	z-index: 1;
}
/* Engraved class-title placard across the front of the plinth — the WoW/Diablo
   "character model on a named pedestal" motif. Sits at the base BEHIND the figure
   (z-index 0 vs the figure's 1) so the hero reads as standing ON it. Decorative
   (aria-hidden); shows the class title, NOT the username, so it adds a posed-statue
   read without duplicating the identity header. */
.char-model-nameplate {
	position: absolute;
	left: 50%;
	bottom: 0.3rem;
	transform: translateX(-50%);
	z-index: 0;
	max-width: 92%;
	/* Row: level medallion + Cinzel class title, centered as a group. The level
	   lives HERE now (not as a floating foot-chip) so the two never overlap. */
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.4rem;
	padding: 0.16rem 0.7rem 0.16rem 0.34rem;
	border-radius: 6px;
	border: 1px solid rgba(201, 162, 77, 0.5);
	background: linear-gradient(180deg, rgba(34, 26, 12, 0.92), rgba(12, 10, 6, 0.95));
	box-shadow:
		inset 0 1px 0 rgba(255, 226, 130, 0.22),
		inset 0 -1px 2px rgba(0, 0, 0, 0.55),
		0 3px 8px -3px rgba(0, 0, 0, 0.7);
	pointer-events: none;
}
/* Gold level medallion seated on the plinth nameplate (replaces the foot chip). */
.char-model-nameplate-lvl {
	flex: none;
	display: inline-grid;
	place-items: center;
	min-width: 1.2rem;
	height: 1.2rem;
	padding: 0 0.28rem;
	border-radius: 999px;
	background: linear-gradient(180deg, #ffe07a, #d99e06);
	border: 1px solid rgba(120, 86, 10, 0.6);
	color: #2a1d00;
	font-weight: 800;
	font-size: 0.68rem;
	line-height: 1;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.char-model-nameplate-text {
	min-width: 0;
	max-width: 100%;
	font-family: "Cinzel", "Inter", serif;
	font-weight: 700;
	font-size: clamp(0.6rem, 2.4vw, 0.76rem);
	letter-spacing: 0.16em;
	text-transform: uppercase;
	text-align: center;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	/* Stamped-brass gold (same background-clip recipe as the Cinzel cartouche). */
	color: #f1d98a;
	background: linear-gradient(180deg, #ffe9a8, #c79b3e);
	-webkit-background-clip: text;
	background-clip: text;
	-webkit-text-fill-color: transparent;
}
/* Lift the figure so its feet + level chip clear the seated placard. */
.char-model-stage { padding-bottom: 1.6rem; }

/* Level chip pinned to the figure's foot. */
.char-model-level {
	position: absolute;
	bottom: -0.2rem;
	left: 50%;
	transform: translateX(-50%);
	min-width: 1.7rem;
	padding: 0.05rem 0.45rem;
	border-radius: 999px;
	background: linear-gradient(180deg, #ffe07a, #d99e06);
	color: #2a1d00;
	font-weight: 800;
	font-size: 0.78rem;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
	z-index: 2;
}

/* --- Companion pet beside the figure -------------------------------------- */
.char-model-pet {
	position: relative;
	z-index: 1;
	display: grid;
	place-items: end center;
	align-self: flex-end;
	width: clamp(46px, 12vw, 72px);
	/* No bottom lift: baseline the pet with the figure so it stands on the same ground
	   line beside the character (was floating ~6% up). */
	margin-bottom: 0;
	/* The character sprite's canvas carries transparent side margins, so flex-centering
	   leaves the pet floating far to the right. Pull it back in toward the figure. */
	margin-left: clamp(-3.5rem, -9vw, -2rem);
}
.char-model-pet-sprite {
	display: block;
	max-height: clamp(54px, 14vw, 88px);
	max-width: 100%;
	width: auto;
	object-fit: contain;
	filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.55));
}
.char-model-pet-fallback {
	font-size: clamp(1.8rem, 6vw, 2.6rem);
	line-height: 1;
	filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.55));
}

/* Class-color accent ring on the stage, keyed off the sheet's data-archetype. */
.char-sheet[data-archetype="thrill"] .char-model-stage { border-color: rgba(231, 76, 60, 0.45); }
.char-sheet[data-archetype="magic"] .char-model-stage { border-color: rgba(155, 89, 182, 0.45); }
.char-sheet[data-archetype="wayfinder"] .char-model-stage { border-color: rgba(46, 204, 113, 0.45); }

/* --- Male / Female toggle -------------------------------------------------- */
.char-gender-toggle {
	display: inline-flex;
	gap: 2px;
	padding: 2px;
	border-radius: 999px;
	border: 1px solid rgba(201, 162, 77, 0.32);
	background: rgba(0, 0, 0, 0.4);
}
.char-gender-opt {
	appearance: none;
	border: 0;
	cursor: pointer;
	padding: 0.22rem 0.8rem;
	border-radius: 999px;
	font-size: 0.74rem;
	font-weight: 700;
	letter-spacing: 0.02em;
	color: #d8c9a6;
	background: transparent;
	transition: background 0.14s, color 0.14s;
}
.char-gender-opt:hover:not(.is-active) { color: #fff; background: rgba(255, 255, 255, 0.06); }
.char-gender-opt.is-active {
	color: #2a1d00;
	background: linear-gradient(180deg, #ffe07a, #d99e06);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
.char-gender-opt:disabled { opacity: 0.55; cursor: default; }

/* --- Equipped gear-slot icon art (render endpoint, emoji fallback) --------- */
.char-slot-art {
	width: 100%;
	height: 100%;
	object-fit: contain;
	border-radius: 6px;
}
.char-slot-glyph { line-height: 1; }

/* --- In-place re-render: keep the sheet on screen, just dim it -------------- *
 * On a class switch / equip / gender swap the sheet re-fetches and rebuilds in
 * place. Rather than blanking it to a single "Loading…" line (which collapses
 * the overlay layout and makes everything jump), we leave the old sheet up and
 * dim it until the new markup swaps in. */
.char-sheet.is-refreshing {
	opacity: 0.55;
	pointer-events: none;
	transition: opacity 0.12s ease;
}

/* --- "Change class" is now an obvious primary affordance ------------------- *
 * The class toggle under the model reads as a button with a clear CTA, and the
 * three per-class level pills are themselves tappable switch targets. */
.char-class-change-cta {
	display: inline-flex;
	align-items: center;
	gap: 0.25rem;
	margin-left: 0.15rem;
	padding: 0.05rem 0.5rem;
	border-radius: 999px;
	font-size: 0.7rem;
	font-weight: 700;
	letter-spacing: 0.01em;
	color: #2a1d00;
	background: linear-gradient(180deg, #ffe07a, #d99e06);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.char-class-change-cta .char-class-edit { opacity: 1; font-size: 0.7rem; }
.char-class-toggle.is-editing {
	border-color: rgba(255, 215, 106, 0.6);
	background: rgba(255, 215, 106, 0.1);
}

/* Per-class level pills as switch targets (own sheet only). */
.char-class-levels.is-switchable { align-items: center; }
.char-class-levels-cta {
	width: 100%;
	flex-basis: 100%;
	text-align: center;
	margin-top: 0.1rem;
	font-size: 0.66rem;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: rgba(255, 215, 106, 0.85);
}
button.char-class-level {
	appearance: none;
	font: inherit;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	transition: border-color 0.14s, background 0.14s, transform 0.08s;
}
button.char-class-level.is-switchable:hover,
button.char-class-level.is-switchable:focus-visible {
	border-color: rgba(255, 215, 106, 0.7);
	background: rgba(255, 215, 106, 0.14);
	color: #fff;
	outline: none;
}
button.char-class-level.is-switchable:active { transform: translateY(1px); }
button.char-class-level.is-current { cursor: pointer; }
.char-class-level-cta {
	font-size: 0.62rem;
	font-weight: 800;
	letter-spacing: 0.03em;
	text-transform: uppercase;
	color: #2a1d00;
	background: linear-gradient(180deg, #ffe07a, #d99e06);
	border-radius: 999px;
	padding: 0.02rem 0.34rem;
}

/* The picker option a pill pre-selected gets a gold ring so the next tap reads
 * as "confirm this switch". */
.play-class-option.is-preselect {
	border-color: rgba(255, 215, 106, 0.85);
	box-shadow: 0 0 0 2px rgba(255, 215, 106, 0.35);
}

/* --- Mobile: keep the model first, a touch smaller, comfy tap targets ------- */
@media (max-width: 640px) {
	.char-model { max-width: 100%; }
	.char-model-stage { min-height: clamp(140px, 46vw, 200px); }
	.char-class-change-cta { font-size: 0.66rem; }
	/* Bigger touch targets: segmented gender toggle + tappable class pills. */
	.char-gender-toggle { gap: 4px; padding: 3px; }
	.char-gender-opt { padding: 0.5rem 1.1rem; font-size: 0.82rem; min-height: 40px; }
	button.char-class-level { padding: 0.45rem 0.7rem; min-height: 40px; }
	.char-class-toggle { padding: 0.5rem 0.85rem; min-height: 40px; }
}

/* ============================================================================
   Game-feel v2 — Phase 2: LIVE THE HERO (docs/design/profile-game-feel-v2.md §4)
   The hero was the only static, non-lit element on a screen titled "Hero's Hall."
   Give the model on the plinth genuine life — a slow breathe-bob, a class-tinted
   rim-light, and a breathing spotlight pool at its feet. ROOM-SCOPED, transforms/
   opacity only, brighten-only (raises light on the focal subject → luma-floor
   stays green), fully cut under reduced-motion + tpq_flow_off (.no-motion).
   ============================================================================ */
/* The hero sprite is intentionally static — no idle bob. (A floating pixel-art sprite
   re-samples its nearest-neighbour grid on sub-pixel offsets and shimmers; rather than
   fight that, the figure just stands on the dais. Only the spotlight pool below breathes.) */
@keyframes char-dais-breath {
	0%, 100% { opacity: 0.62; }
	50% { opacity: 1; }
}
/* The lit dais pulses slowly like a living spotlight pool. */
.char-sheet--room .char-model-stage::after {
	animation: char-dais-breath 5.2s ease-in-out infinite;
}
/* Class-tinted rim-light (keyed off the sheet's accent slug) — the base drop-shadow
   is preserved; the second shadow is the class glow that makes the hero read as lit. */
.char-sheet--room[data-archetype="thrill"] .char-model-sprite {
	filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.65)) drop-shadow(0 0 9px rgba(231, 76, 60, 0.55));
}
.char-sheet--room[data-archetype="magic"] .char-model-sprite {
	filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.65)) drop-shadow(0 0 9px rgba(155, 89, 182, 0.6));
}
.char-sheet--room[data-archetype="wayfinder"] .char-model-sprite {
	filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.65)) drop-shadow(0 0 9px rgba(46, 204, 113, 0.55));
}
/* Motion gate: tpq_flow_off (.no-motion) + OS reduced-motion still the dais spotlight
   pulse. (The hero sprite no longer animates, so it needs no gate.) */
.tpq-room.no-motion .char-model-stage::after { animation: none; }
@media (prefers-reduced-motion: reduce) {
	.char-sheet--room .char-model-stage::after { animation: none; }
}

/* ============================================================================
   Game-feel v2 — Phase 2: XP progress RING behind the hero (the world-map
   "lit jewel" motif applied to the player). Conic gold fill to --xp%, masked to
   a thin ring, on the dais behind the figure (figure is z-index 1). Room-only.
   ============================================================================ */
.char-sheet--room .char-model-ring {
	position: absolute;
	left: 50%;
	bottom: 18%;
	transform: translateX(-50%);
	width: clamp(118px, 32vw, 172px);
	aspect-ratio: 1;
	border-radius: 50%;
	background: conic-gradient(from -90deg, var(--wow-gold-bright, #e7c97a) calc(var(--xp, 0) * 1%), rgba(255, 236, 170, 0.1) 0);
	-webkit-mask: radial-gradient(closest-side, transparent 70%, #000 72%);
	mask: radial-gradient(closest-side, transparent 70%, #000 72%);
	z-index: 0;
	opacity: 0.8;
	pointer-events: none;
	filter: drop-shadow(0 0 6px rgba(231, 201, 122, 0.4));
}

/* ============================================================================
   Game-feel v2 — Phase 4: POSED HERO + COMPANION on a named plinth.
   In the room the plinth gets extra base room so the lifted hero + level chip
   clear the engraved class placard, and the companion gets its OWN slow idle
   (out of phase with the hero's bob) + a grounded contact shadow, so the two
   read as posed together rather than a pet floating beside a static sprite.
   The pet sprite is NOT image-rendering:pixelated (unlike the hero), so a smooth
   ease bob is safe — no pixel-grid shimmer. Transforms/opacity only, motion-gated.
   ============================================================================ */
.char-sheet--room .char-model-stage { padding-bottom: 2.1rem; }
.char-sheet--room .char-model-nameplate { bottom: 0.4rem; }

@keyframes char-pet-idle {
	0%, 100% { transform: translateY(0); }
	50% { transform: translateY(-3px); }
}
.char-sheet--room .char-model-pet-sprite,
.char-sheet--room .char-model-pet-fallback {
	/* 3.3s vs the hero's 3.6s → the two drift out of sync, so they read as two
	   living things sharing the plinth. transform-origin keeps the sway grounded. */
	animation: char-pet-idle 3.3s ease-in-out infinite;
	transform-origin: 50% 100%;
	will-change: transform;
}
/* Grounded contact shadow so the companion stands on the dais; it stays put while
   the sprite bobs above it (the shadow doesn't hop) → reads as alive. */
.char-sheet--room .char-model-pet::after {
	content: "";
	position: absolute;
	left: 50%;
	bottom: 2px;
	transform: translateX(-50%);
	width: 72%;
	height: 7px;
	border-radius: 50%;
	background: radial-gradient(closest-side, rgba(0, 0, 0, 0.5), transparent);
	z-index: 0;
	pointer-events: none;
}
.tpq-room.no-motion .char-model-pet-sprite,
.tpq-room.no-motion .char-model-pet-fallback { animation: none; }
@media (prefers-reduced-motion: reduce) {
	.char-sheet--room .char-model-pet-sprite,
	.char-sheet--room .char-model-pet-fallback { animation: none; }
}

/* ============================================================================
   Game-feel v2 — Phase 4: talent DONNING JUICE. When you learn a talent the
   board remounts; the just-learned node gets a brief gold flash and the duel
   "signature" line (whose power grows per point) gives a small empowered pulse.
   Paired with the spark burst + rising cue (TPQCharJuice.allocate) in profile.js.
   Decorative, time-bounded, motion-gated.
   ============================================================================ */
@keyframes char-talent-learned {
	0% { box-shadow: 0 0 0 0 rgba(255, 224, 122, 0); }
	30% { box-shadow: 0 0 14px 3px rgba(255, 224, 122, 0.85); }
	100% { box-shadow: 0 0 0 0 rgba(255, 224, 122, 0); }
}
/* !important: the room's idle .is-available pulse (.tpq-room[data-room-tab="skilltree"]
   .play-talent-node.is-available, specificity 0,4,0, later cascade) otherwise outranks
   this flash on a freshly-learned-but-not-yet-maxed node. The flash is a 0.9s transient
   that then reverts to whatever idle animation the node carries. */
.play-talent-node.is-justlearned { animation: char-talent-learned 0.9s ease-out !important; }
@keyframes char-signature-empowered {
	0%, 100% { transform: scale(1); }
	40% { transform: scale(1.035); }
}
.play-talent-signature.is-empowered { animation: char-signature-empowered 1s ease-out; }
/* Motion gates: !important so they still beat the !important flash above. */
.tpq-room.no-motion .play-talent-node.is-justlearned,
.tpq-room.no-motion .play-talent-signature.is-empowered { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
	.play-talent-node.is-justlearned,
	.play-talent-signature.is-empowered { animation: none !important; }
}
