/* Xiangqi: wooden board with inked lines, round lacquered pieces. */

.xq-setup { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

.xq-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 17rem;
    gap: clamp(1rem, 3vw, 1.75rem);
    align-items: start;
}
.xq-side { display: grid; gap: 0.75rem; min-width: 0; }
.xq-actions { display: grid; grid-template-columns: 1fr 1fr; }

.xq-turn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 0.9rem;
    border-radius: 0.9rem;
    background: var(--gm-card);
    border: 1px solid var(--gm-line);
    font-weight: 700;
}
.xq-turn::before {
    content: '';
    flex: none;
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    background: #c62f2f;
    box-shadow: 0 0 0 3px #f6e2bb, 0 0 0 4px #c62f2f;
}
.xq-turn[data-side="black"]::before { background: #222; box-shadow: 0 0 0 3px #f6e2bb, 0 0 0 4px #222; }

.xq-panel {
    padding: 0.7rem 0.9rem;
    border-radius: 0.9rem;
    background: var(--gm-card);
    border: 1px solid var(--gm-line);
}
.xq-panel-title {
    font-size: 0.7rem !important;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gm-muted);
    margin-bottom: 0.4rem !important;
}
.xq-caps { display: grid; gap: 0.3rem; }
.xq-cap-row { display: flex; flex-wrap: wrap; gap: 3px; min-height: 1.5rem; }
.xq-chip {
    display: inline-grid;
    place-items: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 3px;
    border-radius: 999px;
    background: #f6e2bb;
    font: 700 0.78rem/1 'KaiTi', 'STKaiti', 'Noto Serif SC', 'SimSun', serif;
    border: 1.5px solid currentColor;
}
.xq-chip.is-red { color: #c62f2f; }
.xq-chip.is-black { color: #222; }

.xq-moves {
    margin: 0;
    padding-left: 1.6rem;
    max-height: 9.5rem;
    overflow-y: auto;
    font-variant-numeric: tabular-nums;
    font-size: 0.88rem;
    line-height: 1.6;
}
.xq-moves li::marker { color: var(--gm-muted); }
.xq-moves li span { display: inline-block; min-width: 4.4rem; font-weight: 700; }
.xq-mv-red { color: #c62f2f; }
html.dark .xq-mv-red { color: #ff8a80; }

.gm-credit { font-size: 0.82rem; }
.gm-credit a { color: var(--gm-blue); }

/* ---------- board ---------- */
.xq-board-wrap { width: min(100%, 34rem); justify-self: center; }
.xq-board {
    position: relative;
    aspect-ratio: 9 / 10;
    border-radius: 14px;
    background:
        radial-gradient(ellipse at 25% 15%, rgba(255, 240, 205, 0.55), transparent 60%),
        repeating-linear-gradient(88deg, rgba(120, 72, 28, 0.06) 0 2px, transparent 2px 11px),
        linear-gradient(160deg, #efcf96, #ddb170 55%, #cf9c58);
    box-shadow: inset 0 0 0 2px rgba(93, 55, 18, 0.35), 0 0 0 7px #6b3a1d, 0 22px 40px -18px rgba(60, 30, 10, 0.8);
    user-select: none;
}
html.dark .xq-board { filter: brightness(0.92); }

.xq-lines { position: absolute; inset: 0; width: 100%; height: 100%; stroke: #5a3517; }
.xq-river {
    fill: #6b3d1b;
    stroke: none;
    font: 700 46px 'Mulish', sans-serif;
    letter-spacing: 0.08em;
    opacity: 0.75;
}
.xq-lines.is-han .xq-river { font: 54px 'KaiTi', 'STKaiti', 'Noto Serif SC', 'SimSun', serif; letter-spacing: 0.3em; }

.xq-piece, .xq-dot, .xq-last, .xq-hint-from, .xq-hint-to {
    position: absolute;
    transform: translate(-50%, -50%);
    aspect-ratio: 1;
    border-radius: 50%;
}

.xq-piece {
    z-index: 2;
    width: calc(100% / 9 * 0.9);
    padding: 0;
    display: grid;
    place-items: center;
    border: 0;
    background: radial-gradient(circle at 38% 32%, #fff3d6, #f2d49c 55%, #d9ab62);
    box-shadow:
        inset 0 0 0 2px #fbe9c3,
        inset 0 0 0 4px currentColor,
        inset 0 -4px 6px rgba(120, 70, 20, 0.35),
        0 3px 0 #a87638,
        0 6px 10px -3px rgba(40, 20, 5, 0.55);
    font: 700 clamp(1rem, 4.4vw, 1.75rem)/1 'KaiTi', 'STKaiti', 'Noto Serif SC', 'SimSun', serif;
    cursor: pointer;
    transition: left 0.22s ease, top 0.22s ease, transform 0.15s ease, opacity 0.25s ease;
    -webkit-tap-highlight-color: transparent;
}
.xq-piece.is-red { color: #c62f2f; }
.xq-piece.is-black { color: #1f1f1f; }
.xq-piece.is-viet { font: 800 clamp(0.5rem, 1.9vw, 0.78rem)/1 'Mulish', sans-serif; letter-spacing: -0.01em; }
.xq-piece.is-selected { transform: translate(-50%, -58%) scale(1.06); box-shadow: inset 0 0 0 2px #fbe9c3, inset 0 0 0 4px currentColor, 0 0 0 3px #1d5fc4, 0 12px 16px -4px rgba(40, 20, 5, 0.6); z-index: 4; }
.xq-piece.is-check { animation: xq-check 0.8s ease-in-out infinite alternate; }
.xq-piece.is-taken { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
.xq-piece:focus-visible { outline: 3px solid #1d5fc4; outline-offset: 2px; }
.xq-board.is-locked .xq-piece { cursor: default; }

@keyframes xq-check {
    from { box-shadow: inset 0 0 0 2px #fbe9c3, inset 0 0 0 4px currentColor, 0 0 0 3px rgba(229, 72, 77, 0.6); }
    to { box-shadow: inset 0 0 0 2px #fbe9c3, inset 0 0 0 4px currentColor, 0 0 14px 6px rgba(229, 72, 77, 0.9); }
}

.xq-dot {
    z-index: 3;
    width: calc(100% / 9 * 0.34);
    border: 0;
    padding: 0;
    background: rgba(29, 95, 196, 0.75);
    box-shadow: 0 0 0 4px rgba(29, 95, 196, 0.2);
    cursor: pointer;
}
.xq-dot.is-capture {
    width: calc(100% / 9 * 0.98);
    background: transparent;
    box-shadow: inset 0 0 0 4px rgba(229, 72, 77, 0.85);
    z-index: 5;
}

.xq-last {
    z-index: 1;
    width: calc(100% / 9 * 0.98);
    border-radius: 6px;
    box-shadow: inset 0 0 0 3px rgba(29, 95, 196, 0.55);
    pointer-events: none;
}
.xq-hint-from, .xq-hint-to {
    z-index: 5;
    width: calc(100% / 9 * 1.02);
    border: 3px dashed #e07a0c;
    pointer-events: none;
    animation: xq-pulse 0.9s ease-in-out infinite alternate;
}
.xq-hint-to { background: rgba(224, 122, 12, 0.18); }
@keyframes xq-pulse { to { transform: translate(-50%, -50%) scale(1.08); } }

/* ---------- picture mode: battlefield board and drawn pieces ---------- */
.xq-board.is-art { overflow: visible; }
.xq-board.is-art::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 14px;
    background: url('images/battlefield.webp') center / cover no-repeat;
}
.xq-board.is-art.is-flipped::before { transform: rotate(180deg); }
.xq-board.is-art .xq-lines {
    stroke: rgba(255, 248, 228, 0.92);
    filter: drop-shadow(0 0 1px rgba(30, 20, 5, 0.85));
}
.xq-board.is-art .xq-river {
    fill: #fff8e4;
    paint-order: stroke;
    stroke: rgba(10, 40, 70, 0.75);
    stroke-width: 6px;
    opacity: 0.95;
}

.xq-piece.is-art {
    color: transparent;
    background:
        var(--art) center / 88% no-repeat,
        radial-gradient(circle at 38% 32%, #fffaf0, #f3e3c3 70%, #dcc396);
}
.xq-piece.is-art.is-red { box-shadow: inset 0 0 0 3px #c62f2f, 0 3px 0 #7d1b1b, 0 6px 10px -3px rgba(20, 10, 0, 0.7); }
.xq-piece.is-art.is-black {
    background:
        var(--art) center / 88% no-repeat,
        radial-gradient(circle at 38% 32%, #eef2f8, #cdd6e4 70%, #a6b2c6);
    box-shadow: inset 0 0 0 3px #1f2a3d, 0 3px 0 #10161f, 0 6px 10px -3px rgba(20, 10, 0, 0.7);
}
.xq-piece.is-art.is-selected { box-shadow: inset 0 0 0 3px currentColor, 0 0 0 3px #ffd23f, 0 12px 16px -4px rgba(20, 10, 0, 0.7); }
.xq-piece.is-art.is-check { animation: xq-check-art 0.8s ease-in-out infinite alternate; }
@keyframes xq-check-art {
    from { box-shadow: 0 0 0 3px rgba(255, 70, 70, 0.6); }
    to { box-shadow: 0 0 14px 7px rgba(255, 70, 70, 0.95); }
}
.xq-board.is-art .xq-dot:not(.is-capture) { background: #ffd23f; box-shadow: 0 0 0 4px rgba(255, 210, 63, 0.35), 0 1px 3px rgba(0, 0, 0, 0.6); }
.xq-board.is-art .xq-last { box-shadow: inset 0 0 0 3px rgba(255, 210, 63, 0.9); }

.xq-chip img { display: block; width: 1.25rem; height: 1.25rem; object-fit: contain; }

.xq-legend-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.3rem 0.5rem;
}
.xq-legend-list li { display: flex; align-items: center; gap: 2px; font-size: 0.82rem; font-weight: 700; }
.xq-legend-list img { width: 1.7rem; height: 1.7rem; padding: 1px; border-radius: 50%; object-fit: contain; background: #f3e3c3; }
.xq-legend-list span { margin-left: 0.25rem; }

@media (max-width: 860px) {
    .xq-layout { grid-template-columns: minmax(0, 1fr); }
    .xq-side { width: min(100%, 34rem); justify-self: center; }
}
@media (max-width: 480px) {
    .xq-setup .gm-seg button { padding: 0.4rem 0.55rem; font-size: 0.8rem; }
    .xq-board { box-shadow: inset 0 0 0 2px rgba(93, 55, 18, 0.35), 0 0 0 4px #6b3a1d; }
}

/* full screen: option rows go away and the board takes the free height */
.gm.is-full .xq-setup { display: none; }
.gm.is-full .xq-board-wrap { width: min(100%, calc(var(--gm-h) * 0.88)); }
