/* UI micro-animations (ui-motion.js overlay + a few state-driven CSS hooks). Uses the #14 design
   tokens (--duration-*, --ease-out, surfaces, rarity colours). Nothing here changes panel layout:
   overlays live in #fx-layer (fixed, pointer-transparent); the only in-panel rules are entrance/
   emphasis animations on elements that are inserted once (event card, result, progress at 100%). */
:root {
  --duration-celebrate: 900ms;
  --ease-back: cubic-bezier(.34, 1.56, .64, 1);
  --fx-gold: #e2b24a;
  --fx-war: #b3261e;
}

#fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: var(--z-fx); overflow: hidden; contain: strict; }
#fx-layer > * { position: fixed; pointer-events: none; }

/* --- timer "ready" glow + HUD pulse ------------------------------------------------------ */
.fx-glow { border-radius: var(--radius-md); animation: fx-ready 1.6s var(--ease-out) 2 both; }
@keyframes fx-ready {
  0% { box-shadow: 0 0 0 0 #e2b24a00, inset 0 0 0 2px #e2b24a00; }
  35% { box-shadow: 0 0 18px 4px #e2b24a99, inset 0 0 0 2px #e2b24add; }
  100% { box-shadow: 0 0 28px 8px #e2b24a00, inset 0 0 0 2px #e2b24a00; }
}
.fx-glow.fx-hud-pulse { animation: fx-hud-pulse var(--duration-slow) var(--ease-out) both; }
@keyframes fx-hud-pulse {
  0% { box-shadow: inset 0 0 0 2px #2f6e1f00, 0 0 0 0 #2f6e1f00; transform: scale(1); }
  40% { box-shadow: inset 0 0 0 2px #2f6e1fcc, 0 0 16px 2px #2f6e1f66; transform: scale(1.06); }
  100% { box-shadow: inset 0 0 0 2px #2f6e1f00, 0 0 22px 6px #2f6e1f00; transform: scale(1); }
}
/* A running timer that reached zero glows softly until the server confirms completion. */
.ui-progress-track[aria-valuenow="100"] .ui-progress-fill { animation: fx-fill-ready 1.4s ease-in-out infinite alternate; }
@keyframes fx-fill-ready { from { box-shadow: 0 0 0 #e2b24a00; filter: brightness(1); } to { box-shadow: 0 0 10px #e2b24acc; filter: brightness(1.18); } }

/* --- reward fly-to-HUD ----------------------------------------------------------------------- */
.fx-fly { font-size: 22px; line-height: 1; filter: drop-shadow(0 2px 3px #16100b55); will-change: transform, opacity; }

/* --- bursts / unlock ----------------------------------------------------------------------- */
.fx-burst { display: grid; place-items: center; }
.fx-burst > i { position: absolute; left: 50%; top: 50%; }
.fx-burst-ring { width: 24px; height: 24px; margin: -12px 0 0 -12px; border-radius: 50%; border: 3px solid var(--fx-gold);
  animation: fx-ring var(--duration-celebrate) var(--ease-out) both; }
@keyframes fx-ring { from { transform: scale(.2); opacity: 1; } to { transform: scale(6); opacity: 0; } }
.fx-spark { width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: var(--fx-gold); box-shadow: 0 0 8px var(--fx-gold);
  animation: fx-spark var(--duration-celebrate) var(--ease-out) both; }
@keyframes fx-spark { from { transform: rotate(var(--a)) translateX(0) scale(1.4); opacity: 1; } to { transform: rotate(var(--a)) translateX(var(--d)) scale(.3); opacity: 0; } }
.fx-burst.fx-burst-gold .fx-spark:nth-child(odd) { background: #fff4cf; }

.fx-unlock { border-radius: var(--radius-lg); overflow: hidden; animation: fx-unlock 1.4s var(--ease-out) both; }
.fx-unlock > i { position: absolute; inset: 0; background: linear-gradient(105deg, transparent 30%, #fff6d8cc 50%, transparent 70%);
  transform: translateX(-120%); animation: fx-shine 1.1s var(--ease-out) .15s both; }
@keyframes fx-unlock { 0% { box-shadow: inset 0 0 0 3px #e2b24a00, 0 0 0 #e2b24a00; transform: scale(.96); }
  30% { box-shadow: inset 0 0 0 3px #e2b24aee, 0 0 24px #e2b24aaa; transform: scale(1.02); }
  100% { box-shadow: inset 0 0 0 3px #e2b24a00, 0 0 30px #e2b24a00; transform: scale(1); } }
@keyframes fx-shine { to { transform: translateX(120%); } }

/* Light flowing along a research dependency link. */
.fx-beam { height: 4px; margin-top: -2px; transform-origin: 0 50%; border-radius: var(--radius-pill);
  background: linear-gradient(90deg, transparent, #fff3c4 40%, var(--fx-gold) 60%, transparent) 0 0 / 40% 100% no-repeat;
  box-shadow: 0 0 10px #e2b24a88; animation: fx-beam 1s var(--ease-out) .25s both; }
@keyframes fx-beam { from { background-position: -60% 0; opacity: 0; } 20% { opacity: 1; } to { background-position: 160% 0; opacity: 0; } }

/* Ledger progress sweep. */
.fx-sweep { border-radius: var(--radius-pill); overflow: hidden;
  background: linear-gradient(90deg, transparent, #fff4cfdd, transparent) 0 0 / 35% 100% no-repeat; animation: fx-sweep 1.2s var(--ease-out) both; }
@keyframes fx-sweep { from { background-position: -40% 0; } to { background-position: 140% 0; } }

/* --- transient cards (artifact / ledger / diplomacy) ------------------------------------------ */
.fx-card { left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + var(--top-h, 64px) + 18px); transform: translateX(-50%);
  min-width: min(280px, 86vw); max-width: 92vw; padding: var(--space-4) var(--space-5); text-align: center;
  background: var(--surface-raised); color: var(--ink); border: 2px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal); display: grid; justify-items: center; gap: var(--space-1);
  animation: fx-card-in var(--duration-slow) var(--ease-back) both, fx-card-out var(--duration-normal) ease-in forwards;
  animation-delay: 0s, calc(var(--fx-ttl, 3s) - var(--duration-normal)); }
.fx-card small { font-size: var(--text-xs); color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.fx-card b { font-family: var(--font-display); font-size: var(--text-lg); }
@keyframes fx-card-in { from { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(.9); } }
@keyframes fx-card-out { to { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(.97); } }

.fx-artifact { overflow: hidden; }
.fx-artifact-icon { font-size: 44px; line-height: 1.1; position: relative; animation: fx-found var(--duration-celebrate) var(--ease-back) both; }
@keyframes fx-found { from { transform: scale(.2) rotate(-25deg); opacity: 0; } 60% { transform: scale(1.18) rotate(6deg); opacity: 1; } }
.fx-artifact-halo { position: absolute; left: 50%; top: 38px; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, var(--halo, #67583f33) 0deg 10deg, transparent 10deg 20deg);
  animation: fx-halo 4s linear infinite; mask: radial-gradient(circle, #000 35%, transparent 70%); }
@keyframes fx-halo { to { transform: rotate(360deg); } }
.fx-artifact.common { border-color: var(--rarity-common); --halo: #67583f33; }
.fx-artifact.fine { border-color: var(--rarity-fine); --halo: #32685c44; }
.fx-artifact.rare { border-color: var(--rarity-rare); --halo: #45598f55; box-shadow: var(--shadow-modal), 0 0 24px #45598f66; }
.fx-artifact.legendary { border-color: var(--rarity-legendary); --halo: #e2b24a77; box-shadow: var(--shadow-modal), 0 0 34px #e2b24aaa; }
.fx-artifact.legendary b { color: var(--rarity-legendary); }

.fx-confetti { inset: 0; }
.fx-confetti i { position: absolute; top: -12px; left: var(--x); width: 8px; height: 12px; background: var(--c); border-radius: 2px;
  animation: fx-confetti 2.6s cubic-bezier(.3,.6,.4,1) var(--d) both; }
@keyframes fx-confetti { from { transform: translateY(0) rotate(0); opacity: 1; } to { transform: translateY(105vh) rotate(calc(var(--r) + 540deg)); opacity: .6; } }

.fx-tier-badge { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font: 700 var(--text-xl) var(--font-display);
  color: #fffaf0; background: radial-gradient(circle at 35% 30%, #f3cf7a, #a8721a); box-shadow: 0 0 0 3px #fffaf0, 0 0 0 5px var(--border);
  animation: fx-found var(--duration-celebrate) var(--ease-back) both; }

/* Diplomacy: wax seal stamps down; war: red flash + declaration card. */
.fx-seal { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; font-size: 32px;
  background: radial-gradient(circle at 40% 35%, #c9473b, #7a1f19 70%); box-shadow: inset 0 0 0 4px #9c2d24, inset 0 0 0 7px #d9665a55, 0 4px 10px #16100b55;
  animation: fx-stamp 700ms var(--ease-back) both; }
@keyframes fx-stamp { 0% { transform: scale(2.4) rotate(-25deg); opacity: 0; } 55% { transform: scale(.92) rotate(4deg); opacity: 1; } 75% { transform: scale(1.05); } 100% { transform: scale(1); } }
.fx-card.fx-war { border-color: var(--fx-war); background: linear-gradient(180deg, #fff3ef, var(--surface-raised)); }
.fx-card.fx-war b { color: var(--fx-war); }
.fx-war-icon { font-size: 40px; animation: fx-clash 600ms var(--ease-back) both; }
@keyframes fx-clash { 0% { transform: scale(.3) rotate(-40deg); opacity: 0; } 60% { transform: scale(1.25) rotate(8deg); opacity: 1; } }
.fx-flash-war { inset: 0; background: radial-gradient(ellipse at center, transparent 35%, #b3261e88 100%); animation: fx-flash 1.2s ease-out both; }
@keyframes fx-flash { 0% { opacity: 0; } 12% { opacity: 1; } 30% { opacity: .35; } 45% { opacity: .8; } 100% { opacity: 0; } }

/* --- random event card: parchment unrolls / flips in; the result is emphasised ---------------- */
dialog.village-event-dialog[open] .village-event-paper { animation: fx-scroll-open 520ms var(--ease-out) both; transform-origin: 50% 0; }
@keyframes fx-scroll-open { 0% { clip-path: inset(0 0 100% 0 round var(--radius-xl)); transform: perspective(900px) rotateX(-18deg); opacity: .4; }
  70% { clip-path: inset(0 0 0 0 round var(--radius-xl)); } 100% { clip-path: inset(0 0 0 0 round var(--radius-xl)); transform: none; opacity: 1; } }
dialog.village-event-dialog[open] .village-event-emblem { animation: fx-found var(--duration-celebrate) var(--ease-back) .2s both; }
dialog.village-event-dialog[open] .village-event-choices > button { animation: pop var(--duration-normal) var(--ease-out) both; }
dialog.village-event-dialog[open] .village-event-choices > button:nth-child(2) { animation-delay: 60ms; }
dialog.village-event-dialog[open] .village-event-choices > button:nth-child(3) { animation-delay: 120ms; }
.village-event-result { animation: fx-result 700ms var(--ease-back) both; border-radius: var(--radius-md); }
@keyframes fx-result { 0% { transform: scale(.85); opacity: 0; box-shadow: 0 0 0 0 #e2b24a00; } 60% { transform: scale(1.03); opacity: 1; box-shadow: 0 0 0 6px #e2b24a55; }
  100% { transform: scale(1); box-shadow: 0 0 0 12px #e2b24a00; } }

/* --- Istanbul map caravan labels ------------------------------------------------------------------- */
.lbl.army.caravan { border-color: #b78324; }

/* Reduced motion: style.css already stops every animation; overlays that exist only to move are
   hidden outright, informative cards stay (static) for their lifetime. */
@media (prefers-reduced-motion: reduce) {
  .fx-fly, .fx-burst, .fx-beam, .fx-sweep, .fx-confetti, .fx-flash-war, .fx-unlock, .fx-glow { display: none; }
  .fx-artifact-halo { display: none; }
}
