/* heraldry.css — coats of arms, the candle clock, crowned seals, pennants, insignia and the treasure chest. */

/* ---------- arms ---------- */
.arms { display: block; width: 100%; height: auto; overflow: visible; filter: drop-shadow(0 14px 18px rgba(0, 0, 0, .55)); }
.arms__crown { filter: drop-shadow(0 0 10px rgba(241, 213, 138, .45)); }
.arms--main .arms__crown { animation: crownfloat 5s ease-in-out infinite; }
@keyframes crownfloat { 50% { transform: translate(52px, -76px) scale(1.5); } }

/* ---------- insignia (procedural or owner art) ---------- */
.insignia { display: inline-block; width: 48px; height: 48px; flex: none; }
.insignia svg, .insignia .art-img { width: 100%; height: 100%; display: block; object-fit: contain; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .6)); }

/* ---------- candle clock ---------- */
.candle { --track: 64px; --wax-w: 14px; display: inline-flex; flex-direction: column; align-items: center; }
.candle--lg { --track: 260px; --wax-w: 46px; }
.candle__track { position: relative; height: calc(var(--track) + var(--wax-w) * 1.4 + 22px); width: calc(var(--wax-w) * 3); display: flex; justify-content: center; }
.candle__stack { position: absolute; bottom: 0; display: flex; flex-direction: column; align-items: center; }
.candle__wax {
  position: relative; width: var(--wax-w);
  height: calc(var(--track) * (1 - var(--p)) + 6px);
  background: linear-gradient(90deg, #b9a98a 0%, #f2e8d2 30%, #fffaf0 45%, #e2d4b6 70%, #a8977a 100%);
  border-radius: 3px 3px 2px 2px;
  box-shadow: inset 0 6px 6px -4px rgba(255, 200, 120, .6);
  transition: height 1.2s var(--ease);
}
.candle__wax::before { /* molten pool at the top */
  content: ''; position: absolute; top: -2px; left: 0; right: 0; height: 5px; border-radius: 50%;
  background: radial-gradient(ellipse at center, #fff6dc, #e6cf9e);
}
.drip { position: absolute; top: 0; width: 22%; border-radius: 0 0 6px 6px; background: linear-gradient(90deg, #e9dcc0, #fffaf0); }
.drip.d1 { left: 4%; height: 22%; max-height: 38px; }
.drip.d2 { right: 8%; height: 34%; max-height: 54px; width: 16%; }
.drip.d3 { left: 40%; height: 12%; max-height: 20px; width: 14%; }
.candle__wick { width: 2px; height: 6px; background: #1a120a; }
.candle__flame { position: relative; width: calc(var(--wax-w) * .62); height: calc(var(--wax-w) * 1.25); margin-bottom: -2px; transform-origin: 50% 100%; animation: flame 1.6s ease-in-out infinite; }
.candle--sm .candle__flame { width: 9px; height: 16px; }
.candle__flame i, .candle__flame b { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%; }
.candle__flame i { top: 0; background: radial-gradient(ellipse at 50% 80%, #fff6d6 0%, #ffcf5a 35%, #ff8a1f 70%, rgba(255, 90, 0, 0) 100%); }
.candle__flame b { top: 45%; left: 28%; right: 28%; background: radial-gradient(ellipse at 50% 70%, rgba(80, 160, 255, .9), rgba(80, 120, 255, 0)); }
.candle__halo { position: absolute; top: calc(var(--wax-w) * -1.6); width: calc(var(--wax-w) * 5); height: calc(var(--wax-w) * 5); border-radius: 50%; background: radial-gradient(circle, rgba(255, 190, 90, .32), transparent 65%); pointer-events: none; animation: halo 2.2s ease-in-out infinite; }
@keyframes flame { 0%, 100% { transform: scale(1, 1) rotate(-1deg); } 30% { transform: scale(.94, 1.08) rotate(2deg); } 60% { transform: scale(1.05, .95) rotate(-2deg); } }
@keyframes halo { 50% { opacity: .7; transform: scale(.92); } }
.candle__holder { width: calc(var(--wax-w) * 2.6); height: calc(var(--wax-w) * .5 + 4px); border-radius: 0 0 50% 50% / 0 0 100% 100%; background: linear-gradient(180deg, #8a6a2a, #3a2a10); box-shadow: 0 4px 8px rgba(0, 0, 0, .6); }
.candle__mark { position: absolute; left: calc(50% + var(--wax-w) * .5 + 4px); bottom: calc(var(--track) * (1 - var(--m)) + 6px); font: 500 .72rem var(--f-mono); color: var(--text-dim); white-space: nowrap; transform: translateY(50%); display: flex; align-items: center; gap: 6px; }
.candle__mark i { width: 12px; height: 1px; background: currentColor; }
.candle__mark.is-burnt { color: var(--gold); }
.candle__pct { margin-top: 14px; font: 500 .9rem var(--f-caps); letter-spacing: .08em; color: var(--text-dim); }
.candle__pct b { font: 700 1.4rem var(--f-mono); color: var(--gold-hi); }

.crowned { display: inline-flex; flex-direction: column; align-items: center; gap: 4px; }
.crowned svg { width: 44px; height: 44px; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .6)); }
.crowned span { font: 700 .62rem var(--f-caps); letter-spacing: .18em; text-transform: uppercase; color: var(--gold-hi); }
.crowned--lg svg { width: 150px; height: 150px; animation: sealpulse 4s ease-in-out infinite; }
.crowned--lg span { font-size: .9rem; }
@keyframes sealpulse { 50% { filter: drop-shadow(0 0 22px rgba(201, 40, 60, .5)); } }

/* ---------- pennants ---------- */
.pennant { display: block; width: 100%; height: 100%; }

/* ---------- the treasure chest overlay ---------- */
.chest-ov { position: fixed; inset: 0; z-index: 170; display: grid; grid-template-rows: 1fr auto; justify-items: center; align-items: end; padding: 16px 16px calc(var(--crier-h) + 16px); overflow: auto; }
.chest-ov__veil { position: fixed; inset: 0; background: radial-gradient(circle at 50% 45%, rgba(40, 18, 60, .86), rgba(4, 3, 6, .96) 70%); animation: fadein .4s ease both; }
.chest-ov.is-leaving { animation: fadeout .4s ease forwards; }
@keyframes fadein { from { opacity: 0; } }
@keyframes fadeout { to { opacity: 0; } }
.chest-stage { position: relative; width: min(420px, 100%); height: min(420px, 56vh); min-height: 300px; }
.chest-sparks { position: absolute; inset: -20%; width: 140%; height: 140%; pointer-events: none; z-index: 4; }
.chest-rays {
  position: absolute; left: 50%; top: 38%; width: 760px; height: 760px; margin: -380px 0 0 -380px; z-index: 0; opacity: 0;
  background: repeating-conic-gradient(from 0deg, color-mix(in srgb, var(--rc) 55%, transparent) 0deg 5deg, transparent 5deg 15deg);
  -webkit-mask: radial-gradient(circle, #000 0 8%, rgba(0, 0, 0, .6) 25%, transparent 60%); mask: radial-gradient(circle, #000 0 8%, rgba(0, 0, 0, .6) 25%, transparent 60%);
  transition: opacity .8s; animation: spin 24s linear infinite; pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.chest { position: absolute; left: 50%; bottom: 0; width: min(240px, 62%); transform: translateX(-50%); perspective: 700px; z-index: 2; }
.chest__lid { position: relative; z-index: 2; transform-origin: 50% 100%; transition: transform .7s cubic-bezier(.3, 1.4, .5, 1); margin-bottom: -2px; }
.chest__lid svg, .chest__body svg { display: block; width: 100%; height: auto; }
.chest__body { position: relative; z-index: 1; }
.chest__glow { position: absolute; left: 10%; right: 10%; top: 22%; height: 30%; border-radius: 50%; background: radial-gradient(ellipse, #fff6d0, var(--rc) 40%, transparent 70%); filter: blur(6px); opacity: 0; z-index: 1; transition: opacity .5s; }
.chest__art { display: none; width: 100%; height: auto; -webkit-mask: radial-gradient(circle, #000 52%, transparent 71%); mask: radial-gradient(circle, #000 52%, transparent 71%); }
.chest.has-art { width: min(300px, 74%); bottom: -6%; }
.chest.has-art .chest__lid, .chest.has-art .chest__body { display: none; }
.chest.has-art .chest__art { display: block; }
.chest.has-art .chest__glow { top: 30%; z-index: 3; mix-blend-mode: screen; }

.coin { position: absolute; left: 50%; top: 40%; width: 128px; height: 128px; margin: -64px 0 0 -64px; z-index: 3; opacity: 0; transform: translateY(140px) scale(.3); perspective: 600px; }
.coin__spin { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; }
.coin__face {
  position: absolute; inset: 0; border-radius: 50%; display: grid; place-items: center; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: radial-gradient(circle at 35% 30%, #fff3c4, #e5b552 40%, #a06d16 80%, #6b4a10);
  box-shadow: inset 0 0 0 5px #8a6118, inset 0 0 0 7px #f3d27c, inset 0 0 0 9px rgba(0, 0, 0, .25), 0 0 40px color-mix(in srgb, var(--rc) 70%, transparent);
}
.coin__face--back { transform: rotateY(180deg); }
.coin__face--back svg { width: 56%; }
.coin__face img { position: absolute; inset: 12px; width: calc(100% - 24px); height: calc(100% - 24px); border-radius: 50%; object-fit: cover; }
.coin__sym { font: 900 1.25rem var(--f-display); color: #4a3208; text-shadow: 0 1px 0 rgba(255, 255, 255, .5); letter-spacing: .02em; max-width: 86%; text-align: center; word-break: break-all; }

.wax-seal { position: absolute; left: calc(50% + 34px); top: calc(40% + 10px); width: 74px; height: 74px; z-index: 5; color: var(--rc); opacity: 0; transform: scale(2.8) rotate(-30deg); }
.rar-lead .wax-seal { color: #8a919a; }
.rar-silver .wax-seal { color: #c9d2db; }
.rar-gold .wax-seal { color: #c9302f; }
.rar-royal .wax-seal { color: #7b3fc4; }
.rar-arcane .wax-seal { color: #0fbf77; }
.wax-seal svg { width: 100%; height: 100%; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .6)); }
.wax-seal span { position: absolute; inset: 0; display: grid; place-items: center; font: 900 1.25rem var(--f-display); color: rgba(255, 255, 255, .9); text-shadow: 0 -1px 0 rgba(0, 0, 0, .45), 0 1px 0 rgba(255, 255, 255, .25); }
.rar-silver .wax-seal span { color: #2b2f36; }

.chest-copy { position: relative; z-index: 6; text-align: center; max-width: 520px; padding-top: 18px; opacity: 0; transform: translateY(14px); transition: opacity .6s, transform .6s var(--ease); }
.chest-copy__ins { display: block; width: 56px; height: 56px; margin: 0 auto 8px; }
.chest-copy__ins .insignia { width: 56px; height: 56px; }
.chest-copy h2 { font: 700 clamp(1.6rem, 5vw, 2.4rem) var(--f-display); color: var(--gold-hi); margin-bottom: .3em; }
.chest-mult { color: var(--rc); }
.chest-amt { font-size: 1.3rem; }
.chest-amt b { font-family: var(--f-mono); color: #fff; }
.chest-amt span { color: var(--text-dim); font-size: 1rem; }
.chest-status { color: var(--text-dim); font-style: italic; }
.chest-skip { position: fixed; top: 16px; right: 16px; z-index: 7; padding: 10px 16px; min-height: 44px; border-radius: 999px; border: 1px solid rgba(201, 162, 74, .4); background: rgba(0, 0, 0, .4); color: var(--gold-hi); font: 600 .75rem var(--f-caps); letter-spacing: .16em; text-transform: uppercase; cursor: pointer; }

/* phases */
.chest-ov[data-phase="in"] .chest { animation: chestdrop .65s cubic-bezier(.3, 1.5, .5, 1) both; }
@keyframes chestdrop { from { transform: translate(-50%, -60px) scale(.8); opacity: 0; } }
.chest-ov[data-phase="rattle"] .chest { animation: rattle .45s ease-in-out 2; }
@keyframes rattle { 0%, 100% { transform: translateX(-50%) rotate(0); } 20% { transform: translateX(calc(-50% - 4px)) rotate(-3deg); } 40% { transform: translateX(calc(-50% + 4px)) rotate(3deg); } 60% { transform: translateX(calc(-50% - 3px)) rotate(-2deg); } 80% { transform: translateX(calc(-50% + 2px)) rotate(1deg); } }
.chest-ov:is([data-phase="open"], [data-phase="coin"], [data-phase="seal"], [data-phase="done"]) .chest__lid { transform: rotateX(72deg); }
.chest-ov:is([data-phase="open"], [data-phase="coin"], [data-phase="seal"], [data-phase="done"]) .chest__glow { opacity: 1; }
.chest-ov:is([data-phase="open"], [data-phase="coin"], [data-phase="seal"], [data-phase="done"]) .chest-rays { opacity: 1; }
.chest-ov:is([data-phase="open"]) .chest.has-art { animation: artburst .7s ease-out; }
@keyframes artburst { 40% { transform: translateX(-50%) scale(1.08); filter: brightness(1.5); } }
.chest-ov[data-phase="coin"] .coin { animation: coinrise 1.25s cubic-bezier(.2, .9, .3, 1) forwards; }
.chest-ov[data-phase="coin"] .coin__spin { animation: coinspin 1.25s cubic-bezier(.2, .7, .3, 1) forwards; }
@keyframes coinrise { 0% { opacity: 0; transform: translateY(140px) scale(.3); } 15% { opacity: 1; } 70% { transform: translateY(-14px) scale(1.12); } 100% { opacity: 1; transform: none; } }
@keyframes coinspin { from { transform: rotateY(0); } to { transform: rotateY(1440deg); } }
.chest-ov:is([data-phase="seal"], [data-phase="done"]) .coin { opacity: 1; transform: none; }
.chest-ov[data-phase="seal"] .wax-seal { animation: stamp .45s cubic-bezier(.5, 0, .7, 1.4) forwards; }
.chest-ov[data-phase="seal"] .chest-stage { animation: thud .3s .3s ease-out; }
@keyframes stamp { to { opacity: 1; transform: scale(1) rotate(-12deg); } }
@keyframes thud { 30% { transform: translateY(5px); } }
.chest-ov[data-phase="done"] .wax-seal { opacity: 1; transform: scale(1) rotate(-12deg); }
.chest-ov[data-phase="done"] .chest-copy { opacity: 1; transform: none; }
.chest-ov[data-phase="done"] .chest-skip { display: none; }
.chest-ov.rar-arcane[data-phase="done"] .coin__face { animation: arcane 2s ease-in-out infinite; }
@keyframes arcane { 50% { box-shadow: inset 0 0 0 5px #8a6118, inset 0 0 0 7px #f3d27c, 0 0 70px #14F195; } }
