/* ============ 中国象棋 ============ */
:root {
    --xq-paper: #f4ecd8;
    --xq-paper-2: #ebe0c6;
    --xq-board: #e8d4a8;
    --xq-board-line: #5a4633;
    --xq-ink: #1a1410;
    --xq-ink-2: #3a3024;
    --xq-ink-3: #6b5d44;
    --xq-red: #b91c1c;
    --xq-red-d: #8a1414;
    --xq-black: #2a2a2a;
    --xq-piece-bg: #fdf6e3;
    --xq-piece-bg-r: #fbeaea;
    --xq-piece-bg-b: #ebebeb;
    --xq-hilite: #f59e0b;
    --xq-move-hint: rgba(11,77,162,.45);
    --xq-shadow: 0 1px 0 rgba(58,48,36,.18), 0 4px 12px rgba(58,48,36,.10);
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    height: 100vh;
    overflow: hidden;
    overscroll-behavior: none;
    font-family: "Kaiti", "STKaiti", "KaiTi", "STSong", "FangSong", serif;
    color: var(--xq-ink);
    -webkit-tap-highlight-color: transparent;
}

.xq-fullscreen {
    height: 100vh; height: 100dvh;
    display: flex; flex-direction: column;
    background: var(--xq-paper);
    background-image:
      radial-gradient(circle at 20% 10%, rgba(184,134,11,.06) 0, transparent 40%),
      radial-gradient(circle at 80% 80%, rgba(185,28,28,.04) 0, transparent 40%);
}

/* ============ 顶栏 ============ */
.xq-header {
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(58,48,36,.18);
    background: rgba(244,236,216,.72);
    backdrop-filter: blur(8px);
}
.xq-back {
    display: inline-flex; align-items: center; gap: 6px;
    color: var(--xq-ink-2); text-decoration: none;
    padding: 6px 10px; border-radius: 8px;
    font-size: 15px;
    transition: background .15s;
    cursor: pointer;
}
.xq-back:hover { background: rgba(58,48,36,.08); }
.xq-back i { font-size: 18px; }
.xq-title {
    font-size: 19px; font-weight: 700; letter-spacing: 6px;
    color: var(--xq-ink);
    padding-left: 6px;
}
.xq-spacer { width: 60px; }

/* ============ 主体 ============ */
.xq-main {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 16px 24px;
}
.xq-screen { animation: xq-fade .25s ease; }
.xq-screen.hidden { display: none; }
@keyframes xq-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ============ 主菜单 · 介绍 ============ */
.xq-intro {
    text-align: center;
    padding: 8px 0 16px;
    position: relative;
}
.xq-seal {
    display: inline-block;
    padding: 4px 14px;
    background: var(--xq-red);
    color: #fdf6e3;
    border-radius: 4px;
    font-size: 13px; letter-spacing: 4px;
    margin-bottom: 8px;
    font-weight: 600;
}
.xq-intro-title {
    font-size: 32px; margin: 0 0 6px;
    letter-spacing: 8px;
    color: var(--xq-ink);
    font-weight: 700;
}
.xq-intro-sub {
    font-size: 14px;
    color: var(--xq-ink-3);
    margin: 0;
}

.xq-modes { max-width: 600px; margin: 0 auto; }
.xq-mode-section { margin-top: 18px; }
.xq-section-title {
    font-size: 15px; font-weight: 600;
    color: var(--xq-ink-2);
    margin-bottom: 10px;
    display: flex; align-items: center; gap: 6px;
}
.xq-section-title i { color: var(--xq-red); }

.xq-mode-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.xq-mode-card {
    background: #fdf6e3;
    border: 1px solid var(--xq-board-line);
    border-radius: 12px;
    padding: 14px 8px;
    text-align: center;
    cursor: pointer;
    transition: transform .1s, box-shadow .15s;
    box-shadow: var(--xq-shadow);
    font-family: inherit;
    color: inherit;
}
.xq-mode-card:hover { transform: translateY(-1px); box-shadow: 0 2px 0 rgba(58,48,36,.18), 0 8px 18px rgba(58,48,36,.14); }
.xq-mode-card:active { transform: translateY(0); }
.xq-mode-wide { grid-column: 1 / -1; }
.xq-mode-num {
    font-size: 28px;
    color: var(--xq-red);
    font-weight: 700;
    margin-bottom: 4px;
}
.xq-mode-name {
    font-size: 16px; font-weight: 700;
    color: var(--xq-ink);
}
.xq-mode-meta {
    font-size: 12px;
    color: var(--xq-ink-3);
    margin-top: 4px;
}

.xq-howto {
    max-width: 600px; margin: 24px auto 8px;
    padding: 14px 16px;
    background: rgba(255,250,239,.7);
    border: 1px dashed rgba(58,48,36,.25);
    border-radius: 10px;
}
.xq-howto h3 { margin: 0 0 8px; font-size: 14px; color: var(--xq-ink-2); }
.xq-howto ul { margin: 0; padding-left: 18px; font-size: 13px; color: var(--xq-ink-3); line-height: 1.8; }

/* ============ 游戏：HUD ============ */
.xq-hud {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
    margin-bottom: 12px;
    max-width: 480px; margin-left: auto; margin-right: auto;
}
.xq-hud-cell {
    padding: 8px 10px;
    background: #fdf6e3;
    border: 1px solid var(--xq-board-line);
    border-radius: 8px;
    text-align: center;
    font-size: 14px; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.xq-side-r { color: var(--xq-red); }
.xq-side-b { color: var(--xq-black); }
.xq-side-r i, .xq-side-b i { font-size: 10px; }
.xq-turn {
    background: var(--xq-red);
    color: #fdf6e3;
    border-color: var(--xq-red-d);
    min-width: 100px;
    transition: background .2s;
}
.xq-turn.b {
    background: var(--xq-black);
    border-color: #000;
}

/* ============ 棋盘 ============ */
.xq-board-wrap {
    position: relative;
    max-width: 480px;
    margin: 0 auto;
}
.xq-board {
    --cols: 9;
    --rows: 10;
    width: 100%;
    aspect-ratio: 9 / 10;
    background: var(--xq-board);
    border: 2px solid var(--xq-board-line);
    border-radius: 6px;
    position: relative;
    box-shadow: var(--xq-shadow);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}
/* 棋盘网格线（用 SVG 做更精确，这里用 ::before 简化） */
.xq-board-grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* 棋盘格子（点击区） */
.xq-cell {
    position: absolute;
    width: calc(100% / 9);
    height: calc(100% / 10);
    cursor: pointer;
    z-index: 2;
}
.xq-cell.legal::after {
    content: '';
    position: absolute; inset: 30%;
    background: var(--xq-move-hint);
    border-radius: 50%;
}
.xq-cell.legal-cap::after {
    content: '';
    position: absolute; inset: 8%;
    border: 3px solid var(--xq-move-hint);
    border-radius: 50%;
    background: transparent;
}

/* 棋子 */
.xq-piece {
    position: absolute;
    width: 10%;
    aspect-ratio: 1 / 1;
    background: var(--xq-piece-bg);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: calc(min(6vw, 26px));
    font-weight: 900;
    cursor: pointer;
    transition:
        left .38s cubic-bezier(.4,.0,.2,1),
        top .38s cubic-bezier(.4,.0,.2,1),
        opacity .25s,
        scale .18s,
        box-shadow .15s,
        background .15s;
    box-shadow:
        inset 0 -2px 0 rgba(58,48,36,.15),
        0 1px 0 rgba(0,0,0,.1),
        0 2px 4px rgba(0,0,0,.12);
    z-index: 3;
    border: 2px solid var(--xq-board-line);
    transform: translate(-50%, -50%);
    line-height: 1;
}
.xq-piece.moving { z-index: 5; }    /* 移动中浮在最上 */
.xq-piece.captured {
    opacity: 0;
    scale: 0.4;
    pointer-events: none;
}
.xq-piece.r {
    background: var(--xq-piece-bg-r);
    color: var(--xq-red);
    border-color: var(--xq-red-d);
}
.xq-piece.b {
    background: var(--xq-piece-bg-b);
    color: var(--xq-black);
    border-color: #1a1a1a;
}
.xq-piece.selected {
    box-shadow:
        0 0 0 3px var(--xq-hilite),
        inset 0 -2px 0 rgba(58,48,36,.15),
        0 2px 6px rgba(245,158,11,.4);
    scale: 1.08;
}
.xq-piece.last-move {
    box-shadow:
        0 0 0 3px rgba(11,77,162,.35),
        inset 0 -2px 0 rgba(58,48,36,.15);
}
.xq-piece.in-check {
    animation: xq-pulse .8s ease-in-out infinite;
}
@keyframes xq-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(185,28,28,.6), inset 0 -2px 0 rgba(58,48,36,.15); }
    50%      { box-shadow: 0 0 0 6px rgba(185,28,28,0), inset 0 -2px 0 rgba(58,48,36,.15); }
}

/* ============ 控制条 ============ */
.xq-controls {
    display: flex; gap: 8px;
    max-width: 480px; margin: 14px auto 0;
}
.xq-btn {
    flex: 1; min-height: 42px;
    background: #fdf6e3;
    border: 1px solid var(--xq-board-line);
    border-radius: 9px;
    color: var(--xq-ink);
    font-size: 14px; font-weight: 600;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    transition: background .15s, transform .08s;
    font-family: inherit;
}
.xq-btn:hover { background: var(--xq-paper-2); }
.xq-btn:active { transform: translateY(1px); }
.xq-btn:disabled { opacity: .45; cursor: not-allowed; }
.xq-btn.primary {
    background: var(--xq-red);
    border-color: var(--xq-red-d);
    color: #fdf6e3;
}
.xq-btn.primary:hover { background: #a01717; }

.xq-msg {
    text-align: center;
    color: var(--xq-red);
    font-size: 14px;
    font-weight: 600;
    margin-top: 10px;
    min-height: 22px;
}

/* ============ 弹窗 ============ */
.xq-modal {
    position: fixed; inset: 0;
    background: rgba(26,20,16,.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    backdrop-filter: blur(3px);
    animation: xq-fade .25s ease;
}
.xq-modal.hidden { display: none; }
.xq-modal-card {
    background: var(--xq-paper);
    border: 2px solid var(--xq-board-line);
    border-radius: 14px;
    padding: 28px 30px 22px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,.4);
    min-width: 280px;
    max-width: 92vw;
}
.xq-modal-seal {
    display: inline-block;
    padding: 8px 22px;
    background: var(--xq-red);
    color: #fdf6e3;
    border-radius: 6px;
    font-size: 22px; font-weight: 700; letter-spacing: 6px;
    margin-bottom: 16px;
}
.xq-modal-title {
    font-size: 24px; font-weight: 700;
    color: var(--xq-ink);
    margin-bottom: 6px;
    letter-spacing: 4px;
}
.xq-modal-sub {
    color: var(--xq-ink-3);
    font-size: 14px;
    margin-bottom: 20px;
}
.xq-modal-actions {
    display: flex; gap: 8px;
    justify-content: center;
}
.xq-modal-actions .xq-btn { min-width: 110px; flex: 0 0 auto; }

/* ============ 移动端 ============ */
@media (max-width: 520px) {
    .xq-intro-title { font-size: 26px; letter-spacing: 6px; }
    .xq-mode-grid { gap: 8px; }
    .xq-mode-card { padding: 10px 4px; }
    .xq-mode-num { font-size: 22px; }
    .xq-mode-name { font-size: 14px; }
    .xq-mode-meta { font-size: 11px; }
    .xq-controls .xq-btn { font-size: 13px; }
    .xq-piece { font-size: calc(min(7.4vw, 30px)); }
}
