/* ==========================================================================
   ARENA REDESIGN — "Đấu trường"
   A bolder, more game-like layer on top of theme-cozy / full.css.
   Loaded LAST from layouts/partials/app/head.blade.php.

   - Global polish is scoped to `body.xq-arena` (set in layouts/app.blade.php).
   - New components are namespaced `.xq-*` so nothing else on the site changes.
   - Board / piece / game-logic selectors are intentionally untouched.
   ========================================================================== */

/* Arena tokens: every colour is derived from the per-board palette in full.css
   (html[data-board-theme] / themes.css section 2), so switching the board theme
   recolours the whole arena layer. NEVER redefine --xq-* tokens here: they belong
   to themes.css (an earlier version overwrote --xqa-surface / --xq-ember globally). */
:root {
    --xqa-gold: var(--xq-accent);
    --xqa-surface: rgba(var(--xq-surface-lo-rgb), 0.78);
    --xqa-surface-hi: rgba(var(--xq-accent-rgb), 0.07);
    --xqa-line: rgba(var(--xq-accent-rgb), 0.28);
    --xqa-text: var(--xq-cream);
    --xqa-muted: rgba(var(--xq-cream-rgb), 0.68);
    --xqa-accent-text: var(--xq-accent);
    --xqa-win: #7fd18b;
    --xqa-draw: var(--xq-accent);
    --xqa-lose: #ff7a6b;
    --xqa-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --xqa-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Legacy light switcher (if theme-light.css is still loaded) */
[data-theme="light"] {
    --xqa-surface: rgba(var(--xq-cream-rgb), 0.92);
    --xqa-surface-hi: rgba(var(--xq-primary-rgb), 0.06);
    --xqa-line: rgba(var(--xq-primary-rgb), 0.28);
    --xqa-text: var(--xq-ink);
    --xqa-muted: rgba(var(--xq-ink-rgb), 0.7);
    --xqa-accent-text: var(--xq-primary);
    --xqa-win: #2f8f4a;
    --xqa-draw: #b97a10;
    --xqa-lose: #c23b2c;
}

/* --------------------------------------------------------------------------
   1. Global polish (scoped)
   -------------------------------------------------------------------------- */

/* Reading-progress bar pinned to the top edge */
.xq-progress {
    position: fixed;
    inset: 0 0 auto 0;
    height: 3px;
    z-index: 2000;
    pointer-events: none;
    transform-origin: 0 50%;
    transform: scaleX(var(--xq-progress, 0));
    background: linear-gradient(90deg, var(--xq-ember), var(--xq-accent) 60%, var(--xq-highlight));
    box-shadow: 0 0 12px rgba(var(--xq-glow-rgb), 0.7);
}

/* Cards get a lantern edge-light on hover */
.xq-arena main .card {
    transition:
        transform 0.35s var(--xqa-ease),
        box-shadow 0.35s var(--xqa-ease),
        border-color 0.25s ease;
}
.xq-arena main .card:hover {
    border-color: rgba(var(--xq-accent-rgb), 0.6);
    box-shadow:
        0 18px 40px rgba(var(--xq-shadow-rgb), 0.5),
        0 0 30px rgba(var(--xq-glow-rgb), 0.16);
}

/* Primary calls to action: a slow sheen that says "press me" */
.xq-arena main .btn-danger {
    position: relative;
    overflow: hidden;
    isolation: isolate;
}
.xq-arena main .btn-danger::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(
        105deg,
        transparent 35%,
        rgba(var(--xq-cream-rgb), 0.35) 50%,
        transparent 65%
    );
    transform: translateX(-120%);
    animation: xqSheen 4.5s ease-in-out infinite;
}
@keyframes xqSheen {
    0%,
    55% {
        transform: translateX(-120%);
    }
    100% {
        transform: translateX(120%);
    }
}

/* --------------------------------------------------------------------------
   2. Profile hero
   -------------------------------------------------------------------------- */
.xq-hero {
    position: relative;
    overflow: hidden;
    margin-bottom: 1.5rem;
    border-radius: 26px;
    border: 1px solid rgba(var(--xq-accent-rgb), 0.5);
    color: var(--xq-cream);
    background:
        radial-gradient(
            ellipse 60% 90% at 8% 0%,
            rgba(var(--xq-glow-a-rgb), 0.3),
            transparent 65%
        ),
        linear-gradient(135deg, var(--xq-primary) 0%, var(--xq-surface-hi) 52%, var(--xq-surface-deep) 100%);
    box-shadow:
        0 24px 60px rgba(var(--xq-shadow-deep-rgb), 0.55),
        0 0 0 1px rgba(var(--xq-surface-rgb), 0.9),
        inset 0 1px 0 rgba(var(--xq-sheen-rgb), 0.35);
    animation: xqRise 0.7s var(--xqa-ease) both;
}
/* Giant watermark general piece */
.xq-hero::before {
    content: "\5C07";
    position: absolute;
    right: -0.08em;
    top: -0.22em;
    font:
        900 clamp(11rem, 30vw, 21rem) / 1 "Noto Serif SC",
        "Songti SC",
        "Fraunces",
        serif;
    color: rgba(var(--xq-accent-rgb), 0.09);
    pointer-events: none;
    user-select: none;
}
/* Bottom gold hairline */
.xq-hero::after {
    content: "";
    position: absolute;
    inset: auto 0 0 0;
    height: 3px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--xq-accent) 25%,
        var(--xq-highlight) 50%,
        var(--xq-accent) 75%,
        transparent
    );
    opacity: 0.85;
}

.xq-hero__main {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 1.5rem;
    padding: 2rem 2rem 1.25rem;
}

.xq-hero__avatar {
    position: relative;
    padding: 4px;
    border-radius: 32px;
    background: conic-gradient(
        from 200deg,
        var(--xq-highlight),
        var(--xq-accent),
        var(--xq-accent-lo),
        var(--xq-highlight)
    );
    box-shadow:
        0 14px 30px rgba(var(--xq-shadow-deep-rgb), 0.55),
        0 0 36px rgba(var(--xq-glow-rgb), 0.35);
    transition: transform 0.5s var(--xqa-spring);
}
.xq-hero__avatar:hover {
    transform: rotate(-3deg) scale(1.04);
}
.xq-hero__avatar img {
    display: block;
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: 28px;
    background: var(--xq-surface-deep);
}
.xq-hero__status {
    position: absolute;
    right: -6px;
    bottom: -6px;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 15px;
    background: var(--xq-surface-deep);
    border: 2px solid rgba(var(--xq-accent-rgb), 0.8);
    box-shadow: 0 4px 10px rgba(var(--xq-shadow-deep-rgb), 0.5);
}
.xq-hero__status .user-status-indicator {
    line-height: 1;
}

.xq-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    padding: 0.25rem 0.8rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--xq-accent-hi);
    background: rgba(var(--xq-accent-rgb), 0.14);
    border: 1px solid rgba(var(--xq-accent-rgb), 0.4);
}
.xq-hero__name {
    margin: 0;
    font-size: clamp(1.9rem, 4.6vw, 3.1rem);
    line-height: 1.1;
    word-break: break-word;
    color: var(--xq-cream);
    text-shadow: 0 3px 16px rgba(var(--xq-shadow-deep-rgb), 0.6);
}

/* Elo medallion */
.xq-elo {
    text-align: center;
    min-width: 150px;
    padding: 0.9rem 1.4rem 1rem;
    border-radius: 22px;
    background: rgba(var(--xq-shadow-rgb), 0.5);
    border: 1px solid rgba(var(--xq-accent-rgb), 0.5);
    box-shadow:
        inset 0 1px 0 rgba(var(--xq-sheen-rgb), 0.2),
        0 0 40px rgba(var(--xq-glow-a-rgb), 0.18);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}
.xq-elo__label {
    display: block;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--xq-accent-hi);
}
.xq-elo__value {
    display: block;
    font-family: "Fraunces", serif;
    font-weight: 900;
    font-size: clamp(2.8rem, 6vw, 4.2rem);
    line-height: 1.05;
    background: linear-gradient(180deg, var(--xq-highlight), var(--xq-accent) 55%, var(--xq-accent-lo));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 4px 14px rgba(var(--xq-glow-a-rgb), 0.4));
}

/* Fact chips under the identity row */
.xq-facts {
    position: relative;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    padding: 0 2rem 1.6rem;
}
.xq-fact {
    display: inline-flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.5rem 0.95rem;
    border-radius: 16px;
    background: rgba(var(--xq-shadow-rgb), 0.42);
    border: 1px solid rgba(var(--xq-accent-rgb), 0.28);
    transition:
        transform 0.3s var(--xqa-ease),
        border-color 0.2s ease;
}
.xq-fact:hover {
    transform: translateY(-2px);
    border-color: rgba(var(--xq-accent-rgb), 0.7);
}
.xq-fact__k {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: rgba(var(--xq-highlight-rgb), 0.7);
}
.xq-fact__v {
    font-weight: 800;
    color: var(--xq-cream);
}
.xq-fact__v a {
    color: var(--xq-accent-hi);
}
.xq-fact--karma .xq-fact__v {
    color: color-mix(in srgb, var(--xq-accent-hi) 60%, #8fe3ff);
}

.xq-hero__cta {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    grid-column: 1 / -1;
    padding-top: 0.25rem;
}

/* --------------------------------------------------------------------------
   3. Stat tiles + win/draw/lose bar
   -------------------------------------------------------------------------- */
.xq-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.xq-tile {
    --tile: var(--xqa-gold);
    position: relative;
    overflow: hidden;
    padding: 1.1rem 1.2rem 1.15rem;
    border-radius: 20px;
    color: var(--xqa-text);
    background: var(--xqa-surface);
    border: 1px solid var(--xqa-line);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    backdrop-filter: blur(14px) saturate(1.2);
    box-shadow: 0 8px 22px rgba(var(--xq-shadow-rgb), 0.3);
    transition:
        transform 0.35s var(--xqa-spring),
        box-shadow 0.3s var(--xqa-ease),
        border-color 0.25s ease;
    animation: xqRise 0.6s var(--xqa-ease) both;
}
.xq-tile:nth-child(2) {
    animation-delay: 0.06s;
}
.xq-tile:nth-child(3) {
    animation-delay: 0.12s;
}
.xq-tile:nth-child(4) {
    animation-delay: 0.18s;
}
.xq-tile::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 4px;
    background: var(--tile);
}
.xq-tile::after {
    content: "";
    position: absolute;
    right: -30px;
    top: -30px;
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--tile), transparent 70%);
    opacity: 0.16;
}
.xq-tile:hover {
    transform: translateY(-6px);
    border-color: var(--tile);
    box-shadow:
        0 18px 36px rgba(var(--xq-shadow-rgb), 0.45),
        0 0 26px color-mix(in srgb, var(--tile) 35%, transparent);
}
.xq-tile--win {
    --tile: var(--xqa-win);
}
.xq-tile--draw {
    --tile: var(--xqa-draw);
}
.xq-tile--lose {
    --tile: var(--xqa-lose);
}
.xq-tile__icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    margin-bottom: 0.6rem;
    border-radius: 12px;
    color: var(--tile);
    background: color-mix(in srgb, var(--tile) 16%, transparent);
}
.xq-tile__num {
    display: block;
    font-family: "Fraunces", serif;
    font-weight: 900;
    font-size: clamp(1.9rem, 3.6vw, 2.6rem);
    line-height: 1.05;
    color: var(--tile);
}
.xq-tile__label {
    display: block;
    margin-top: 0.15rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--xqa-muted);
}

.xq-wld {
    display: flex;
    height: 14px;
    margin-bottom: 1.5rem;
    overflow: hidden;
    border-radius: 999px;
    background: var(--xqa-surface-hi);
    border: 1px solid var(--xqa-line);
    box-shadow: inset 0 2px 6px rgba(var(--xq-shadow-deep-rgb), 0.35);
}
.xq-wld > span {
    height: 100%;
    transform-origin: 0 50%;
    animation: xqGrow 1.1s var(--xqa-ease) 0.3s both;
}
.xq-wld__win {
    background: linear-gradient(180deg, #a6e8ae, var(--xqa-win));
}
.xq-wld__draw {
    background: linear-gradient(180deg, var(--xq-accent-hi), var(--xqa-draw));
}
.xq-wld__lose {
    background: linear-gradient(180deg, #ffa79b, var(--xqa-lose));
}
@keyframes xqGrow {
    from {
        transform: scaleX(0);
    }
    to {
        transform: scaleX(1);
    }
}

/* --------------------------------------------------------------------------
   4. Panels (plan, matches) and pills
   -------------------------------------------------------------------------- */
.xq-panel {
    margin-bottom: 1.5rem;
    border-radius: 22px;
    overflow: hidden;
    color: var(--xqa-text);
    background: var(--xqa-surface);
    border: 1px solid var(--xqa-line);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    backdrop-filter: blur(14px) saturate(1.2);
    box-shadow: 0 10px 28px rgba(var(--xq-shadow-rgb), 0.32);
    animation: xqRise 0.6s var(--xqa-ease) 0.1s both;
}
.xq-panel__head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1rem 1.4rem;
    border-bottom: 1px solid var(--xqa-line);
    background: linear-gradient(90deg, rgba(var(--xq-primary-rgb), 0.5), transparent);
}
.xq-panel__head h2 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--xqa-accent-text);
    text-shadow: none;
}
.xq-panel__body {
    padding: 1.2rem 1.4rem;
}
.xq-panel__foot {
    display: flex;
    justify-content: center;
    padding: 0.9rem 1rem 0.6rem;
    border-top: 1px solid var(--xqa-line);
}

.xq-plan {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1.1rem 1.4rem;
    border-radius: 22px;
    color: var(--xqa-text);
    background:
        linear-gradient(
            135deg,
            rgba(var(--xq-accent-rgb), 0.18),
            rgba(var(--xq-accent-rgb), 0.05)
        ),
        var(--xqa-surface);
    border: 1px solid var(--xqa-gold);
    box-shadow: 0 10px 28px rgba(var(--xq-shadow-rgb), 0.3);
}
.xq-plan strong {
    color: var(--xqa-accent-text);
}
.xq-plan small {
    color: var(--xqa-muted);
}

.xq-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.xq-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
    border: 1px solid var(--xqa-line);
}
.xq-pill--red {
    color: var(--xq-accent-hi);
    background: linear-gradient(180deg, var(--xq-primary), var(--xq-surface-hi));
    border-color: rgba(var(--xq-accent-rgb), 0.6);
}
.xq-pill--ink {
    color: var(--xq-highlight);
    background: linear-gradient(180deg, var(--xq-surface-hi), var(--xq-shadow));
    border-color: rgba(var(--xq-accent-rgb), 0.35);
}
.xq-pill--draw {
    color: var(--xqa-text);
    background: var(--xqa-surface-hi);
}
.xq-pill--muted {
    color: var(--xqa-muted);
    background: transparent;
    border-style: dashed;
}
.xq-pill--done {
    color: var(--xqa-lose);
    background: transparent;
}

.xq-matches thead th {
    white-space: nowrap;
}
.xq-matches td {
    vertical-align: middle !important;
}

/* --------------------------------------------------------------------------
   5. Motion + responsive
   -------------------------------------------------------------------------- */
@keyframes xqRise {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@media (max-width: 991px) {
    .xq-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 767px) {
    .xq-hero__main {
        grid-template-columns: 1fr;
        justify-items: center;
        text-align: center;
        padding: 1.6rem 1.2rem 1rem;
    }
    .xq-elo {
        width: 100%;
    }
    .xq-facts {
        justify-content: center;
        padding: 0 1.2rem 1.3rem;
    }
    .xq-hero__cta {
        justify-content: center;
    }
    .xq-hero__cta .btn {
        flex: 1 1 100%;
    }
    .xq-panel__body,
    .xq-panel__head {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}
@media (max-width: 420px) {
    .xq-tile {
        padding: 0.9rem;
    }
    .xq-hero__avatar img {
        width: 96px;
        height: 96px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .xq-hero,
    .xq-tile,
    .xq-panel,
    .xq-wld > span,
    .xq-arena main .btn-danger::after {
        animation: none !important;
    }
    .xq-tile:hover,
    .xq-fact:hover,
    .xq-hero__avatar:hover {
        transform: none;
    }
}
@media (prefers-reduced-transparency: reduce) {
    .xq-tile,
    .xq-panel,
    .xq-elo {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
}


/* --------------------------------------------------------------------------
   6. Wow layer: theme-aware ambience (all colours from html[data-board-theme])
   -------------------------------------------------------------------------- */

/* Soft breathing glow behind the hero, in the active board's glow colour */
.xq-hero {
    --xqa-breath: rgba(var(--xq-glow-rgb), 0.28);
}
.xq-hero::before {
    transition: color 0.4s ease;
}
@keyframes xqaBreath {
    0%,
    100% {
        box-shadow:
            0 24px 60px rgba(var(--xq-shadow-deep-rgb), 0.55),
            0 0 0 1px rgba(var(--xq-surface-rgb), 0.9),
            0 0 0 rgba(var(--xq-glow-rgb), 0),
            inset 0 1px 0 rgba(var(--xq-sheen-rgb), 0.35);
    }
    50% {
        box-shadow:
            0 24px 60px rgba(var(--xq-shadow-deep-rgb), 0.55),
            0 0 0 1px rgba(var(--xq-surface-rgb), 0.9),
            0 0 46px var(--xqa-breath),
            inset 0 1px 0 rgba(var(--xq-sheen-rgb), 0.35);
    }
}
.xq-hero {
    animation:
        xqRise 0.7s var(--xqa-ease) both,
        xqaBreath 6s ease-in-out 1s infinite;
}

/* The board's own General watermarks the hero (follows data-pieces-theme) */
.xq-hero__main::after {
    content: "";
    position: absolute;
    right: 1.5rem;
    bottom: -0.5rem;
    width: clamp(90px, 14vw, 150px);
    aspect-ratio: 1;
    background: var(--xqd-piece-red) center / contain no-repeat;
    opacity: 0.16;
    pointer-events: none;
    filter: drop-shadow(0 6px 10px rgba(var(--xq-shadow-deep-rgb), 0.5));
}

/* Stat tiles lift and pick up the accent on hover / keyboard focus */
.xq-tile {
    transition:
        transform 0.35s var(--xqa-spring),
        border-color 0.25s ease,
        box-shadow 0.35s var(--xqa-ease);
}
.xq-tile:hover,
.xq-tile:focus-within {
    transform: translateY(-4px) scale(1.01);
    border-color: rgba(var(--xq-accent-rgb), 0.7);
    box-shadow:
        0 16px 34px rgba(var(--xq-shadow-deep-rgb), 0.45),
        0 0 28px rgba(var(--xq-glow-rgb), 0.18);
}

/* Visible, themed focus ring for every interactive arena element */
.xq-arena :is(a, button, .btn, input, select, textarea):focus-visible {
    outline: 2px solid var(--xq-accent-hi);
    outline-offset: 2px;
    box-shadow: 0 0 0 5px rgba(var(--xq-glow-rgb), 0.28);
}

/* Pressed feedback on primary actions */
.xq-arena main .btn-danger:active {
    transform: translateY(1px) scale(0.985);
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    .xq-hero,
    .xq-arena main .btn-danger::after,
    .xq-tile {
        animation: none !important;
        transition: none !important;
    }
    .xq-progress {
        display: none;
    }
}
