/* MafiaPS Chess Arena — frontend-only presentation layer.
   All match state, moves, turns and settlement remain server-authoritative. */

#view-chess {
    --chess-gold: #ffb703;
    --chess-gold-soft: #ffd166;
    --chess-panel: #0d1420;
    --chess-panel-2: #111b2a;
    --chess-border: #26354b;
    --chess-muted: #8f9caf;
    --wood-light: #ead2a7;
    --wood-light-2: #f3dfbb;
    --wood-dark: #9a6842;
    --wood-dark-2: #7f5133;
}

#view-chess .chess-match-layout {
    width: min(1180px, calc(100% - 24px));
    margin: 18px auto 60px;
}

#view-chess .chess-arena-card {
    position: relative;
    overflow: hidden;
    padding: 20px;
    border: 1px solid var(--chess-border);
    border-radius: 18px;
    background:
        radial-gradient(circle at 20% 0%, rgba(255, 183, 3, 0.075), transparent 35%),
        linear-gradient(145deg, rgba(17, 27, 42, 0.98), rgba(8, 13, 21, 0.98));
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

#view-chess .chess-arena-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--chess-gold), transparent);
    opacity: 0.85;
}

#view-chess .chess-arena-toolbar,
#view-chess .chess-match-header,
#view-chess .chess-header-meta,
#view-chess .chess-player-strip,
#view-chess .chess-match-controls,
#view-chess .chess-panel-heading,
#view-chess .chess-status-main,
#view-chess .chess-live-chip,
#view-chess .chess-side-chip,
#view-chess .chess-stake-chip {
    display: flex;
    align-items: center;
}

#view-chess .chess-arena-toolbar {
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

#view-chess .chess-leave-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 13px;
    border: 1px solid #34445d;
    border-radius: 9px;
    background: #111a28;
    color: #d9e1ed;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 800;
    cursor: pointer;
    transition: border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

#view-chess .chess-leave-btn:hover {
    color: var(--chess-gold-soft);
    border-color: rgba(255, 183, 3, 0.7);
    transform: translateX(-2px);
}

#view-chess .chess-live-chip {
    gap: 7px;
    color: #72e6a8;
    font-size: 0.66rem;
    font-weight: 900;
    letter-spacing: 0.12em;
}

#view-chess .chess-live-chip > span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #38d68b;
    box-shadow: 0 0 0 5px rgba(56, 214, 139, 0.09), 0 0 14px rgba(56, 214, 139, 0.65);
}

#view-chess .chess-match-header {
    justify-content: space-between;
    gap: 18px;
    padding: 0 2px 18px;
    border-bottom: 1px solid rgba(53, 69, 94, 0.65);
}

#view-chess .chess-header-label,
#view-chess .chess-panel-label {
    display: block;
    margin-bottom: 5px;
    color: var(--chess-gold);
    font-size: 0.63rem;
    font-weight: 900;
    letter-spacing: 0.16em;
}

#view-chess #chess-match-players {
    display: block;
    color: #f4f7fb;
    font-size: clamp(1.05rem, 2.5vw, 1.4rem);
    line-height: 1.25;
}

#view-chess .chess-header-meta {
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 9px;
}

#view-chess .chess-stake-chip,
#view-chess .chess-side-chip {
    gap: 7px;
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid #31415a;
    border-radius: 9px;
    background: rgba(17, 27, 42, 0.9);
    color: #dce4ef;
    font-size: 0.75rem;
    font-weight: 800;
    white-space: nowrap;
}

#view-chess .chess-stake-chip {
    color: var(--chess-gold-soft);
    border-color: rgba(255, 183, 3, 0.35);
}

#view-chess .chess-side-chip.is-black {
    color: #f3f5f8;
    background: #090d13;
}

#view-chess .chess-side-chip.is-white {
    color: #162030;
    background: #f4ead8;
    border-color: #f4ead8;
}

#view-chess .chess-side-chip.is-spectator {
    color: #9fb4d1;
}

#view-chess .chess-mini-piece {
    font-size: 1.15rem;
    line-height: 1;
}

#view-chess .chess-game-grid {
    display: grid;
    grid-template-columns: minmax(0, 650px) minmax(240px, 310px);
    justify-content: center;
    align-items: start;
    gap: 26px;
    padding-top: 24px;
}

#view-chess .chess-board-column {
    width: 100%;
    max-width: 650px;
    margin: 0 auto;
}

#view-chess .chess-player-strip {
    min-height: 56px;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 11px;
    transition: background 0.2s ease, border-color 0.2s ease;
}

#view-chess .chess-player-strip.has-turn {
    border-color: rgba(255, 183, 3, 0.45);
    background: rgba(255, 183, 3, 0.065);
}

#view-chess .chess-player-strip.is-bottom {
    margin-top: 4px;
}

#view-chess .chess-player-avatar {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    margin-right: 10px;
    border: 1px solid #42516a;
    border-radius: 10px;
    background: #182235;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 900;
}

#view-chess .chess-player-avatar.is-white {
    color: #1a2433;
    background: #eee4d2;
    border-color: #fff3d4;
}

#view-chess .chess-player-avatar.is-black {
    color: var(--chess-gold-soft);
    background: #080b11;
    border-color: #38445a;
}

#view-chess .chess-player-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#view-chess .chess-player-copy strong {
    overflow: hidden;
    color: #f2f5fa;
    font-size: 0.86rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#view-chess .chess-player-copy span {
    color: var(--chess-muted);
    font-size: 0.67rem;
    font-weight: 700;
}

#view-chess .chess-player-turn {
    margin-left: auto;
    padding: 5px 8px;
    border-radius: 6px;
    background: #182235;
    color: #758398;
    font-size: 0.6rem;
    font-weight: 900;
    letter-spacing: 0.08em;
}

#view-chess .chess-player-turn.active {
    color: #101620;
    background: var(--chess-gold);
    box-shadow: 0 0 16px rgba(255, 183, 3, 0.22);
}

#view-chess .chess-board-frame {
    position: relative;
    width: min(100%, 620px);
    margin: 3px auto;
    padding: 9px;
    border: 1px solid #3a2c20;
    border-radius: 8px;
    background: linear-gradient(145deg, #4d301d, #2b1a11);
    box-shadow:
        0 22px 45px rgba(0, 0, 0, 0.42),
        0 0 0 1px rgba(255, 183, 3, 0.18),
        inset 0 0 0 2px rgba(237, 190, 117, 0.12);
}

#view-chess .chess-board {
    display: grid !important;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
    width: 100% !important;
    max-width: none !important;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border: 0 !important;
    border-radius: 3px;
    background: var(--wood-light);
}

#view-chess .chess-square {
    position: relative;
    display: grid;
    place-items: center;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    color: inherit;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    user-select: none;
    touch-action: manipulation;
    transition: filter 0.12s ease, box-shadow 0.12s ease;
}

#view-chess .chess-square.light {
    background:
        linear-gradient(135deg, rgba(255,255,255,0.13), transparent 45%),
        linear-gradient(115deg, var(--wood-light-2), var(--wood-light));
}

#view-chess .chess-square.dark {
    background:
        linear-gradient(135deg, rgba(255,255,255,0.055), transparent 48%),
        linear-gradient(115deg, var(--wood-dark), var(--wood-dark-2));
}

#view-chess .chess-square:hover {
    z-index: 2;
    filter: brightness(1.1);
    box-shadow: inset 0 0 0 3px rgba(255, 214, 105, 0.38);
}

#view-chess .chess-square.selected {
    z-index: 3;
    filter: brightness(1.16) saturate(1.1);
    box-shadow:
        inset 0 0 0 4px #ffcc33,
        inset 0 0 22px rgba(255, 204, 51, 0.62);
}

#view-chess .chess-square:focus-visible {
    z-index: 4;
    outline: 3px solid #66b3ff;
    outline-offset: -3px;
}

#view-chess .chess-piece {
    position: relative;
    z-index: 1;
    display: block;
    transform: translateY(-1%);
    font-family: "DejaVu Sans", "Segoe UI Symbol", "Noto Sans Symbols 2", serif;
    font-size: clamp(2rem, 6.2vw, 4.1rem);
    line-height: 1;
    pointer-events: none;
}

#view-chess .chess-piece.is-white {
    color: #fff8e8;
    text-shadow:
        -1px -1px 0 #4a3424,
        1px -1px 0 #4a3424,
        -1px 1px 0 #4a3424,
        1px 1px 0 #4a3424,
        0 3px 3px rgba(37, 20, 9, 0.5);
}

#view-chess .chess-piece.is-black {
    color: #15181d;
    text-shadow:
        -1px -1px 0 rgba(255, 229, 177, 0.72),
        1px -1px 0 rgba(255, 229, 177, 0.72),
        -1px 1px 0 rgba(255, 229, 177, 0.72),
        1px 1px 0 rgba(255, 229, 177, 0.72),
        0 3px 3px rgba(0, 0, 0, 0.55);
}

#view-chess .chess-coordinate {
    position: absolute;
    z-index: 2;
    color: rgba(38, 25, 16, 0.72);
    font-size: clamp(0.48rem, 1.2vw, 0.66rem);
    font-weight: 900;
    line-height: 1;
    pointer-events: none;
}

#view-chess .chess-square.dark .chess-coordinate {
    color: rgba(255, 240, 207, 0.8);
}

#view-chess .chess-coordinate.file {
    right: 4px;
    bottom: 3px;
}

#view-chess .chess-coordinate.rank {
    top: 4px;
    left: 4px;
}

#view-chess .chess-board-error {
    grid-column: 1 / -1;
    grid-row: 1 / -1;
    display: grid;
    place-items: center;
    padding: 20px;
    color: #8a3b3b;
    background: #f2ddbd;
    font-weight: 800;
    text-align: center;
}

#view-chess .chess-match-controls {
    min-height: 48px;
    justify-content: center;
    margin-top: 10px;
}

#view-chess #chess-resign-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid rgba(255, 91, 91, 0.52);
    border-radius: 9px;
    background: rgba(187, 49, 49, 0.13);
    color: #ff8d8d;
    font: inherit;
    font-size: 0.75rem;
    font-weight: 900;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

#view-chess #chess-resign-btn:hover {
    color: #fff;
    background: #c53e3e;
    transform: translateY(-1px);
}

#view-chess #chess-spectator-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 12px;
    border: 1px solid #35445b;
    border-radius: 8px;
    color: #9fb0c7;
    background: #111a28;
    font-size: 0.74rem;
    font-weight: 800;
}

#view-chess .chess-info-panel {
    position: sticky;
    top: 96px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#view-chess .chess-status-card,
#view-chess .chess-history-card,
#view-chess .chess-help-card {
    border: 1px solid #293950;
    border-radius: 12px;
    background: linear-gradient(145deg, rgba(18, 29, 45, 0.96), rgba(12, 19, 30, 0.96));
}

#view-chess .chess-status-card {
    padding: 16px;
}

#view-chess .chess-status-main {
    gap: 9px;
}

#view-chess .chess-status-main strong {
    color: #f2f5fa;
    font-size: 1rem;
}

#view-chess .chess-status-card p {
    margin: 8px 0 0 19px;
    color: var(--chess-muted);
    font-size: 0.72rem;
    line-height: 1.5;
}

#view-chess .chess-turn-dot {
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
    border: 1px solid #6f7c8e;
    border-radius: 50%;
    background: #667085;
}

#view-chess .chess-turn-dot.white {
    border-color: #fff6df;
    background: #fff6df;
    box-shadow: 0 0 11px rgba(255, 246, 223, 0.45);
}

#view-chess .chess-turn-dot.black {
    border-color: #7b8ca4;
    background: #070a0f;
    box-shadow: 0 0 0 2px #35445a;
}

#view-chess .chess-turn-dot.finished {
    border-color: #4ed895;
    background: #4ed895;
    box-shadow: 0 0 11px rgba(78, 216, 149, 0.45);
}

#view-chess .chess-history-card {
    overflow: hidden;
}

#view-chess .chess-panel-heading {
    justify-content: space-between;
    gap: 10px;
    min-height: 46px;
    padding: 0 13px;
    border-bottom: 1px solid #293950;
    color: #dce4ef;
    font-size: 0.73rem;
    font-weight: 900;
}

#view-chess .chess-panel-heading i {
    margin-right: 5px;
    color: var(--chess-gold);
}

#view-chess #chess-move-count {
    color: var(--chess-muted);
    font-size: 0.62rem;
    font-weight: 700;
}

#view-chess .chess-move-history {
    max-height: 315px;
    min-height: 150px;
    overflow-y: auto;
    padding: 8px;
    scrollbar-width: thin;
    scrollbar-color: #3a4a62 transparent;
}

#view-chess .chess-history-row {
    display: grid;
    grid-template-columns: 30px 1fr 1fr;
    align-items: center;
    min-height: 34px;
    border-radius: 7px;
    color: #dce4ef;
    font-size: 0.75rem;
}

#view-chess .chess-history-row:nth-child(odd) {
    background: rgba(255, 255, 255, 0.025);
}

#view-chess .chess-move-number {
    color: #647187;
    text-align: center;
}

#view-chess .chess-move-white,
#view-chess .chess-move-black {
    padding: 0 6px;
    font-weight: 800;
}

#view-chess .chess-history-empty {
    display: flex;
    min-height: 132px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
    color: #66748a;
    font-size: 0.72rem;
}

#view-chess .chess-history-empty i {
    font-size: 1.4rem;
    color: #3f4d62;
}

#view-chess .chess-help-card {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 12px;
    color: #8695aa;
    font-size: 0.68rem;
    line-height: 1.5;
}

#view-chess .chess-help-card i {
    margin-top: 2px;
    color: var(--chess-gold);
}

@media (max-width: 900px) {
    #view-chess .chess-game-grid {
        grid-template-columns: minmax(0, 650px);
    }

    #view-chess .chess-info-panel {
        position: static;
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    #view-chess .chess-help-card {
        grid-column: 1 / -1;
    }
}

@media (max-width: 620px) {
    #view-chess .chess-match-layout {
        width: min(100% - 12px, 1180px);
        margin-top: 8px;
    }

    #view-chess .chess-arena-card {
        padding: 12px;
        border-radius: 13px;
    }

    #view-chess .chess-match-header {
        align-items: flex-start;
        flex-direction: column;
    }

    #view-chess .chess-header-meta {
        width: 100%;
        justify-content: flex-start;
    }

    #view-chess .chess-game-grid {
        gap: 14px;
        padding-top: 14px;
    }

    #view-chess .chess-board-frame {
        padding: 5px;
    }

    #view-chess .chess-piece {
        font-size: clamp(1.65rem, 10.5vw, 3.2rem);
    }

    #view-chess .chess-player-strip {
        min-height: 50px;
        padding: 5px;
    }

    #view-chess .chess-player-avatar {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
    }

    #view-chess .chess-info-panel {
        display: flex;
    }
}

@media (prefers-reduced-motion: reduce) {
    #view-chess *,
    #view-chess *::before,
    #view-chess *::after {
        scroll-behavior: auto !important;
        transition: none !important;
    }
}

/* Lobby controls: include Cancel Search, which is outside the search form. */
#view-chess .chess-lobby-layout button {
    appearance: none;
    -webkit-appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    max-width: 100%;
    box-sizing: border-box;
    padding: 10px 16px;
    border: 1px solid #e8a900;
    border-radius: 9px;
    background: linear-gradient(135deg, #ffcb45, #ffb703);
    color: #151a23;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 800;
    line-height: 1.3;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
#view-chess .chess-lobby-layout button:hover:not(:disabled) {
    background: #ffd166;
    border-color: #ffdb85;
    box-shadow: 0 3px 14px #ffb70322;
}
#view-chess #chess-own-search button {
    margin-top: 12px;
    background: #1b202b;
    border-color: #8a6931;
    color: #ffd166;
}
#view-chess #chess-own-search button:hover:not(:disabled) {
    background: #30291c;
    border-color: #ffb703;
}
#view-chess .chess-lobby-layout button:active:not(:disabled) {
    box-shadow: inset 0 2px 5px #00000040;
}
#view-chess .chess-lobby-layout button:focus-visible {
    outline: 2px solid #ffe09a;
    outline-offset: 3px;
}
#view-chess .chess-lobby-layout button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}
#view-chess .chess-search-form { flex-wrap: wrap; }
#view-chess .chess-search-form input { min-width: 0; max-width: 100%; box-sizing: border-box; }
@media (prefers-reduced-motion: reduce) {
    #view-chess .chess-lobby-layout button { transition: none; }
}
