/* 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: #2b1a05; background: radial-gradient(circle at 35% 30%, #f3cf7a, #c08a2c); 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; } }
.fx-flash-war.fx-flash-hit { animation-duration: .7s; } /* raid on our own village: the same red edge, shorter */

/* --- 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) 580ms both; } /* after the scene + title stagger (random-events.css) */
dialog.village-event-dialog[open] .village-event-choices > button:nth-child(2) { animation-delay: 660ms; }
dialog.village-event-dialog[open] .village-event-choices > button:nth-child(3) { animation-delay: 740ms; }
dialog.village-event-dialog[open] .village-event-choices > button:nth-child(4) { animation-delay: 820ms; }
.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; }
.lbl.army.caravan small { display: block; font-weight: 500; font-size: 12px; opacity: .85; }
#app #labels .lbl.army.caravan { display: block; } /* clickable labels get role=button, and `#app [role="button"]` (style.css) would put <small> beside the title */
#labels .lbl.army.unreachable { opacity: .55; } /* ambush cannot catch it up; still clickable (explains why) */
.lbl.ambush small { display: block; font-weight: 700; font-size: 12px; color: #7a1f1f; }
#labels .lbl.pirate { border-color: #5a1212; background: linear-gradient(135deg, #e6d3d0, #d5b9b5); color: #1c0b0b; font-weight: 700; } /* Boğaz korsanı: koyu kırmızı çerçeve, açık-pembe zeminde koyu metin (beyaz yok) */
#labels .lbl.pirate small { color: #5a1212; }
#labels .lbl.army.pirate.unreachable { opacity: .85; } /* locked (no vakıf) must still read */

/* --- gift code reveal: box shakes, lid pops, rewards rise out of it (ui-motion.js giftReveal) -------- */
.fx-card.fx-gift { top: 50%; z-index: 2; /* confetti falls behind the card, the box sparks stay on top */ width: min(320px, 88vw); min-width: 0; max-width: 88vw; box-sizing: border-box; max-height: calc(100vh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: var(--space-4) var(--space-4) var(--space-4); overflow: hidden; gap: var(--space-2); border: 1px solid rgba(240,196,92,.45); border-radius: var(--radius-xl);
  background: var(--a-glass-strong, var(--surface)); -webkit-backdrop-filter: var(--a-blur, none); backdrop-filter: var(--a-blur, none); box-shadow: var(--shadow-modal), 0 0 32px rgba(240,196,92,.18), 0 0 0 1px var(--a-edge, transparent) inset;
  transform: translate(-50%, -50%); animation: fx-gift-in var(--duration-slow) var(--ease-back) both, fx-gift-out var(--duration-normal) ease-in forwards;
  animation-delay: 0s, calc(var(--fx-ttl, 4.5s) - var(--duration-normal)); }
#fx-layer > .fx-burst { z-index: 3; }
@keyframes fx-gift-in { from { opacity: 0; transform: translate(-50%, -46%) scale(.85); } }
@keyframes fx-gift-out { to { opacity: 0; transform: translate(-50%, -54%) scale(.97); } }
.fx-card.fx-gift::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 120px; z-index: 0; pointer-events: none; opacity: .45; background: url(/landing/istanbul-night-portrait.webp) center 35% / cover;
  -webkit-mask-image: linear-gradient(#000, transparent); mask-image: linear-gradient(#000, transparent); }
.fx-card.fx-gift > * { position: relative; z-index: 1; }
.fx-gift-kicker { display: inline-flex; align-items: center; gap: 6px; }
.fx-card .fx-gift-title { color: #f0c45c; font-family: 'Cinzel', 'Times New Roman', serif; font-weight: 600; font-size: 20px; letter-spacing: .03em; font-variant: normal; text-transform: none; overflow-wrap: anywhere; }
.fx-gift-box { position: relative; width: 110px; height: 101px; margin: 0 0 2px; }
.fx-gift-box svg { position: relative; display: block; width: 110px; height: auto; overflow: visible; }
.fx-gift-halo { position: absolute; left: 50%; top: 45%; width: 150px; height: 150px; margin: -75px 0 0 -75px; border-radius: 50%; opacity: 0; pointer-events: none;
  background: radial-gradient(circle, rgba(240,196,92,.55), rgba(240,196,92,0) 62%); }
.fx-gift-lid { transform-box: fill-box; transform-origin: 50% 0; transform: translateY(-4px) rotate(-38deg); } /* static (reduced motion): chest shown open */
.fx-gift-coin { transform-box: fill-box; transform-origin: center; opacity: 0; }
.fx-gift-anim .fx-gift-box { animation: fx-gift-shake .5s ease-in-out both; }
.fx-gift-anim .fx-gift-lid { animation: fx-gift-lid .7s cubic-bezier(.2,.8,.3,1) .55s both; }
.fx-gift-anim .fx-gift-coin { animation: fx-gift-coin .9s var(--ease-back) calc(.65s + var(--i) * .08s) both; }
.fx-gift-anim .fx-gift-halo { animation: fx-gift-glow 1.4s ease-out .55s both; }
@keyframes fx-gift-shake { 0%, 100% { transform: none; } 15% { transform: translateX(-4px) rotate(-6deg); } 35% { transform: translateX(4px) rotate(6deg); } 55% { transform: translateX(-4px) rotate(-5deg); } 75% { transform: translateX(3px) rotate(4deg); } }
@keyframes fx-gift-lid { from { transform: none; } to { transform: translateY(-4px) rotate(-38deg); } }
@keyframes fx-gift-coin { 0% { opacity: 0; transform: translateY(8px) scale(.5); } 40% { opacity: 1; transform: translateY(-22px) scale(1); } 100% { opacity: 1; transform: translateY(-10px) scale(1); } }
@keyframes fx-gift-glow { 0% { opacity: 0; transform: scale(.4); } 30% { opacity: 1; } 100% { opacity: .35; transform: scale(1.1); } }
.fx-gift-list { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.fx-gift-list li { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; box-sizing: border-box; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--a-edge, var(--border)); background: var(--a-key, rgba(255,255,255,.08)); color: var(--ink); font-size: var(--text-sm, 14px); line-height: 1.25; text-align: left; }
.fx-gift-list li b { font-family: var(--font-body); font-weight: 600; font-size: inherit; overflow-wrap: anywhere; min-width: 0; }
.fx-gift-list li > span { font-size: 18px; line-height: 1; }
.fx-gift-anim .fx-gift-list li { animation: fx-gift-rise .55s var(--ease-back) calc(.75s + var(--i) * .15s) both; }
@keyframes fx-gift-rise { from { opacity: 0; transform: translateY(-70px) scale(.3); } }
@media (max-width: 400px) { .fx-card.fx-gift { padding: var(--space-3); } .fx-gift-list li { padding: 3px 8px; } }

/* 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, .fx-gift-halo, .fx-gift-coin { display: none; }
}

/* Köylü sohbet balonları (public/chat-bubbles.js): konuşan köylünün başının üstünde krem/parşömen balon, yalnız kamera çok yakınken (JS figür boyuna bakar).
   Kendi sınıfı (.kb), etiket sınıfı değil: etiket (lbl) kuralları, iso temanın iğneli plakası ve `#app [role="button"]` ona ulaşmaz. Dış öğe konumlanır
   (translate3d), iç `.kb-body` giriş/çıkışta solar ve ölçeklenir. Koyu iso temada da okunur: renkler sabit (var(--ink) açık renk). */
#labels .kb { position: absolute; left: 0; top: 0; pointer-events: none; visibility: hidden; margin-top: -9px; will-change: transform; transition: visibility 0s linear .16s; }
#labels .kb.kb-on { visibility: visible; transition-delay: 0s; }
#labels .kb .kb-body { position: relative; box-sizing: border-box; max-width: 180px; width: max-content; padding: 6px 10px; border-radius: 12px; border: 1px solid rgba(46, 32, 19, 0.7);
  background: linear-gradient(135deg, #f7f0de, #e8dcc0); color: #2a1d10; font-family: var(--font-body); font-size: 13px; font-weight: 500; line-height: 1.25; text-align: center;
  white-space: normal; overflow-wrap: anywhere; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  opacity: 0; transform: scale(0.85); transform-origin: 50% 100%; transition: opacity .14s ease-out, transform .14s ease-out; }
#labels .kb.kb-on .kb-body { opacity: 1; transform: none; }
#labels .kb .kb-body::after { content: ''; position: absolute; left: calc(50% - 5px + var(--kb-tail, 0px)); bottom: -6px; width: 10px; height: 10px; box-sizing: border-box; transform: rotate(45deg);
  background: #e8dcc0; border: 1px solid rgba(46, 32, 19, 0.7); border-top: 0; border-left: 0; }
@media (max-width: 400px) { #labels .kb .kb-body { max-width: 156px; font-size: 12.5px; padding: 5px 9px; } }
@media (prefers-reduced-motion: reduce) { #labels .kb, #labels .kb .kb-body { transition: none; transform: none; } }
