/*
 * Round-complete overlay — redesigned panel for OverlayKind.RoundEnd.
 *
 * Two variants (currently only Variant A — Triumph Stack — is wired up;
 * Variant B targets Ranked single-round play and lives in PostMatchScreen).
 *
 *   Variant A · .te-result-quickplay   →  Multi-round Quick Play
 *
 * Source design: docs/mockups/round-complete-redesign.html
 * Tokens come from figma-tokens.css; do NOT hardcode colours here.
 *
 * Win/loss share a single component — .loss strips the gold accents and
 * mirrors the level-promote panel into team-B coral so it reads as
 * "their round" without celebrating it.
 */

/* ====================================================================== */
/*  Backdrop — dimmed felt, NOT black. The .overlay-backdrop fallback in  */
/*  game.css still runs first; this layer just lifts the scrim opacity to */
/*  let the table peek through.                                            */
/* ====================================================================== */

.te-result-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.66);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

/* ====================================================================== */
/*  Shared pieces — pills, glyph card, CTA                                 */
/* ====================================================================== */

.te-result-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    padding: 4px 11px;
    font-size: 0.66rem;
    font-weight: 700;
    color: var(--te-fg-strong);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.te-result-pill.cool {
    border-color: rgba(255, 255, 255, 0.18);
    color: var(--te-fg-muted);
    background: rgba(255, 255, 255, 0.04);
}

.te-result-pill.cool::before {
    content: '\00B7';
    opacity: 0.6;
}

.te-result-cta {
    background: linear-gradient(180deg, var(--te-accent-green), var(--te-accent-green-deep));
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 11px 28px;
    cursor: pointer;
    font: var(--te-font-weight-heavy) 0.95rem / 1 var(--te-font-display);
    letter-spacing: 0.08em;
    box-shadow: 0 6px 18px rgba(76, 175, 80, 0.35),
                inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.te-result-cta:hover {
    filter: brightness(1.05);
}

.te-result-cta:active {
    transform: translateY(1px);
}

/* Tiny rendered card glyph — rank on top, heart suit underneath, because
   the wild card is specifically the heart-suit level card (rules.md §7).
   Showing the suit makes "this is your wild" legible without prose. */
.te-result-glyph-card {
    width: 26px;
    height: 36px;
    border-radius: 3px;
    background: var(--te-card-face-gradient);
    border: 1px solid var(--te-card-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--te-suit-black);
    font: 800 0.85rem var(--te-font-body);
    box-shadow: var(--te-shadow-card);
    flex-shrink: 0;
    line-height: 1;
}

.te-result-glyph-card .rank { font-size: 1em; line-height: 1; }
.te-result-glyph-card .suit { font-size: 0.62em; line-height: 1; margin-top: 1px; }
.te-result-glyph-card.red { color: var(--te-suit-red); }
.te-result-glyph-card.lvl {
    color: var(--te-suit-red);
    border-color: var(--te-accent-gold);
    box-shadow: var(--te-shadow-card), 0 0 8px rgba(255, 215, 0, 0.55);
}

/* ====================================================================== */
/*  Variant A · Triumph Stack (Quick Play)                                  */
/* ====================================================================== */

.te-result-quickplay {
    position: relative;
    width: 700px;
    max-width: 96%;
    background:
        linear-gradient(180deg, rgba(255, 215, 0, 0.06), transparent 40%),
        var(--te-table-panel-dark);
    border: 1px solid rgba(255, 215, 0, 0.55);
    border-radius: 18px;
    padding: 18px 22px 16px;
    box-shadow: 0 0 80px rgba(255, 215, 0, 0.25), 0 16px 48px rgba(0, 0, 0, 0.6);
    overflow: hidden;
    animation: te-result-panel-in 320ms ease-out both;
}

.te-result-quickplay::before {
    content: '';
    position: absolute;
    inset: -2px;
    background: radial-gradient(ellipse at 50% -30%, rgba(255, 215, 0, 0.4), transparent 50%);
    pointer-events: none;
}

/* Confetti — eight static specks; pulse in for ~600ms, then fade. */
.te-result-confetti {
    position: absolute;
    inset: 0;
    pointer-events: none;
    animation: te-result-confetti-in 600ms ease-out both;
}

.te-result-confetti span {
    position: absolute;
    width: 6px;
    height: 10px;
    opacity: 0.85;
    border-radius: 1px;
}

.te-result-head {
    text-align: center;
    position: relative;
    z-index: 1;
    margin-bottom: 6px;
}

.te-result-tag {
    font-size: 0.66rem;
    letter-spacing: 0.32em;
    color: var(--te-team-a);
    font-weight: 700;
    text-transform: uppercase;
}

.te-result-title {
    font: var(--te-font-weight-heavy) 2.4rem / 1 var(--te-font-display);
    color: var(--te-accent-gold);
    letter-spacing: 0.04em;
    margin-top: 2px;
    text-shadow: 0 2px 14px rgba(255, 215, 0, 0.45), var(--te-shadow-text);
}

.te-result-body {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    gap: 14px;
    margin-top: 10px;
    position: relative;
    z-index: 1;
}

/* ── Level promotion panel ─────────────────────────────────────────── */

.te-result-promote {
    background: rgba(0, 0, 0, 0.35);
    border: 1px dashed rgba(255, 215, 0, 0.4);
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.te-result-promote-label {
    font-size: 0.62rem;
    letter-spacing: 0.16em;
    color: var(--te-accent-gold);
    font-weight: 800;
    text-transform: uppercase;
}

.te-result-promote-cards {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    padding: 6px 0 4px;
}

.te-result-promote-cards .te-result-glyph-card {
    width: 38px;
    height: 52px;
    font-size: 1.05rem;
}

.te-result-promote-cards .te-result-glyph-card.from {
    opacity: 0.45;
    transform: scale(0.92);
    animation: te-result-card-from 480ms ease-out both;
}

.te-result-promote-cards .te-result-glyph-card.to {
    transform: scale(1.05);
    box-shadow: var(--te-shadow-card), 0 0 16px rgba(255, 215, 0, 0.7);
    animation: te-result-card-to 520ms 120ms ease-out both;
}

.te-result-promote-arrow {
    color: var(--te-accent-gold);
    font-size: 1.2rem;
    font-weight: 800;
    text-shadow: 0 0 6px rgba(255, 215, 0, 0.6);
}

/* ── Match-state level track (2 → A) ───────────────────────────────── */

.te-result-track {
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

.te-result-track-h {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.56rem;
    letter-spacing: 0.14em;
    color: var(--te-fg-quiet);
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.te-result-track-h .target {
    color: var(--te-accent-gold);
}

.te-result-track-rail {
    position: relative;
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    margin: 14px 6px 18px;
}

.te-result-track-rail::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: repeating-linear-gradient(
        to right,
        rgba(255, 255, 255, 0.18) 0,
        rgba(255, 255, 255, 0.18) 1px,
        transparent 1px,
        transparent calc(100% / 12)
    );
}

.te-result-track-trail {
    position: absolute;
    top: 0;
    bottom: 0;
    border-radius: 2px;
    box-shadow: 0 0 6px currentColor;
    animation: te-result-trail-in 400ms 120ms ease-out both;
}

.te-result-track-trail.team-a {
    background: linear-gradient(90deg,
        transparent,
        color-mix(in srgb, var(--te-team-a) 60%, transparent));
    color: var(--te-team-a);
}

.te-result-track-trail.team-b {
    background: linear-gradient(90deg,
        transparent,
        color-mix(in srgb, var(--te-team-b) 60%, transparent));
    color: var(--te-team-b);
}

.te-result-track-marker {
    position: absolute;
    top: 50%;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    border: 2px solid #061a10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.te-result-track-marker.team-a {
    background: var(--te-team-a);
    box-shadow: 0 0 6px color-mix(in srgb, var(--te-team-a) 80%, transparent);
}

.te-result-track-marker.team-b {
    background: var(--te-team-b);
    box-shadow: 0 0 6px color-mix(in srgb, var(--te-team-b) 80%, transparent);
}

.te-result-track-marker.advanced {
    width: 14px;
    height: 14px;
}

.te-result-track-marker .lbl {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    white-space: nowrap;
    line-height: 1;
}

.te-result-track-marker .lbl.above { bottom: 16px; }
.te-result-track-marker .lbl.below { top: 16px; }
.te-result-track-marker.team-a .lbl { color: var(--te-team-a); }
.te-result-track-marker.team-b .lbl { color: var(--te-team-b); }

.te-result-track-target {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translate(50%, -50%);
    width: 10px;
    height: 10px;
    border-radius: 1px;
    background: var(--te-accent-gold);
    box-shadow: 0 0 6px rgba(255, 215, 0, 0.6);
}

/* ── Finish-order rail ─────────────────────────────────────────────── */

.te-result-finish {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.te-result-finish-h {
    font-size: 0.62rem;
    letter-spacing: 0.16em;
    color: var(--te-fg-muted);
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.te-result-finish-row {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 6px 9px;
    border-radius: 8px;
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--te-fg-body);
}

.te-result-finish-row .place {
    font: 800 0.8rem var(--te-font-body);
    color: var(--te-fg-quiet);
    text-align: center;
}

.te-result-finish-row .name b { color: var(--te-fg-strong); }

.te-result-finish-row .seat {
    font-size: 0.6rem;
    letter-spacing: 0.08em;
    color: var(--te-fg-quiet);
}

.te-result-finish-row.win {
    background: rgba(255, 215, 0, 0.12);
    border-color: rgba(255, 215, 0, 0.45);
}

.te-result-finish-row.win .place { color: var(--te-accent-gold); }

.te-result-finish-row .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
    vertical-align: middle;
}

.te-result-finish-row.team-a .dot {
    background: var(--te-team-a);
    box-shadow: 0 0 4px var(--te-team-a);
}

.te-result-finish-row.team-b .dot {
    background: var(--te-team-b);
}

/* ── Foot ──────────────────────────────────────────────────────────── */

.te-result-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
    position: relative;
    z-index: 1;
    gap: 8px;
    flex-wrap: wrap;
}

.te-result-foot-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ── Loss state ────────────────────────────────────────────────────── */

.te-result-quickplay.loss {
    border-color: rgba(255, 255, 255, 0.12);
    background: var(--te-table-panel-dark);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
}

.te-result-quickplay.loss::before { display: none; }
.te-result-quickplay.loss .te-result-confetti { display: none; }

.te-result-quickplay.loss .te-result-tag {
    color: var(--te-fg-quiet);
    letter-spacing: 0.32em;
}

.te-result-quickplay.loss .te-result-title {
    color: #b8c0bb;
    text-shadow: var(--te-shadow-text);
    font-size: 2rem;
    letter-spacing: 0.08em;
}

/* Mirror the promote panel into team-B coral — what's *in play* next
   round is the opponents' new level (per GuanDanMatchRules). */
.te-result-quickplay.loss .te-result-promote {
    border-color: color-mix(in srgb, var(--te-team-b) 50%, transparent);
    background: rgba(232, 168, 124, 0.06);
}

.te-result-quickplay.loss .te-result-promote-label { color: var(--te-team-b); }

.te-result-quickplay.loss .te-result-promote-arrow {
    color: var(--te-team-b);
    text-shadow: 0 0 6px color-mix(in srgb, var(--te-team-b) 60%, transparent);
}

.te-result-quickplay.loss .te-result-promote-cards .te-result-glyph-card.lvl {
    border-color: var(--te-team-b);
    box-shadow: var(--te-shadow-card),
                0 0 12px color-mix(in srgb, var(--te-team-b) 60%, transparent);
}

.te-result-quickplay.loss .te-result-finish-row.win {
    background: rgba(232, 168, 124, 0.10);
    border-color: rgba(232, 168, 124, 0.45);
}

.te-result-quickplay.loss .te-result-finish-row.win .place {
    color: var(--te-team-b);
}

.te-result-quickplay.loss .te-result-finish-row.you {
    outline: 1px dashed rgba(255, 255, 255, 0.18);
    outline-offset: -1px;
}

/* ====================================================================== */
/*  Animations — wrapped in prefers-reduced-motion                         */
/* ====================================================================== */

@keyframes te-result-panel-in {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}

@keyframes te-result-confetti-in {
    0%   { opacity: 0; transform: translateY(-6px); }
    35%  { opacity: 1; transform: translateY(0); }
    100% { opacity: 0.45; }
}

@keyframes te-result-card-from {
    0%   { opacity: 1; transform: scale(1); }
    100% { opacity: 0.45; transform: scale(0.92); }
}

@keyframes te-result-card-to {
    0%   { opacity: 0; transform: scale(0.7); box-shadow: var(--te-shadow-card), 0 0 0 rgba(255, 215, 0, 0); }
    60%  { opacity: 1; transform: scale(1.15); box-shadow: var(--te-shadow-card), 0 0 22px rgba(255, 215, 0, 0.9); }
    100% { opacity: 1; transform: scale(1.05); box-shadow: var(--te-shadow-card), 0 0 16px rgba(255, 215, 0, 0.7); }
}

@keyframes te-result-trail-in {
    /* The element's resting width is set inline; the animation just draws it
       on from zero. No "to" frame needed — the rest state takes over when
       the keyframe ends. */
    from { width: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .te-result-quickplay,
    .te-result-confetti,
    .te-result-promote-cards .te-result-glyph-card.from,
    .te-result-promote-cards .te-result-glyph-card.to,
    .te-result-track-trail {
        animation: none !important;
    }
}
