/* ===== WP Cờ Tướng – Styles =====
   Chỉ phần riêng của Cờ Tướng (bàn gỗ, quân 3D, đồng hồ, thanh trạng thái, luật quân).
   Token + component dùng chung nằm ở wp-choico-core/assets/css/choico-games.css */

#tuong-app {
    /* 9 cột × 10 hàng + viền: ngang chia 9.5, dọc chia 10.6 — lấy cạnh nào chật hơn */
    --cell: clamp(30px, min(calc(var(--board-max) / 9.5), calc((100vh - 150px) / 10.6)), 72px);
}

/* ── Thẻ người chơi: biểu tượng quân + đồng hồ ── */
.player-icon { flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center;
               justify-content: center; font-size: var(--cc-fs-base); font-weight: 700; }
.player-icon.red   { background: radial-gradient(circle, #e74c3c, #c0392b); box-shadow: 0 2px 8px rgba(231,76,60,.5); }
.player-icon.black { background: radial-gradient(circle, #555, #111); box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.player-timer { font-size: var(--cc-fs-xs); font-weight: 700; letter-spacing: .04em; color: var(--cc-text-faint);
                font-variant-numeric: tabular-nums; transition: color var(--cc-dur) var(--cc-ease); }
.player-timer.active { color: var(--cc-success); }
.player-timer.danger { color: var(--cc-danger); animation: cc-pulse .65s infinite; }

/* ── Thanh trạng thái nước đi ── */
.move-status-bar {
    display: flex; align-items: center; gap: var(--cc-sp-3); min-height: 40px;
    padding: var(--cc-sp-2) var(--cc-sp-4); border-radius: var(--cc-r); border: 1px solid var(--cc-line);
    font-size: var(--cc-fs-sm); font-weight: 500;
    transition: background-color var(--cc-dur-slow), border-color var(--cc-dur-slow);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--cc-text-faint); }
#tuong-status-msg { color: var(--cc-text-muted); }
.move-status-bar[data-type="player"] { background: rgba(var(--cc-success-rgb),.1); border-color: rgba(var(--cc-success-rgb),.25); }
.move-status-bar[data-type="player"] .status-dot { background: var(--cc-success); animation: cc-pulse 2s infinite; }
.move-status-bar[data-type="player"] #tuong-status-msg { color: var(--cc-success); }
.move-status-bar[data-type="ai"] { background: rgba(var(--cc-wood-rgb),.08); border-color: rgba(var(--cc-wood-rgb),.22); }
.move-status-bar[data-type="ai"] .status-dot { background: var(--cc-wood-hi); animation: cc-pulse 1s infinite; }
.move-status-bar[data-type="ai"] #tuong-status-msg { color: var(--cc-wood-hi); }
.move-status-bar[data-type="wait"] { background: rgba(var(--cc-info-rgb),.08); border-color: rgba(var(--cc-info-rgb),.22); }
.move-status-bar[data-type="wait"] .status-dot { background: var(--cc-info); animation: cc-pulse 1.5s infinite; }
.move-status-bar[data-type="wait"] #tuong-status-msg { color: var(--cc-info); }
.move-status-bar[data-type="idle"] { background: var(--cc-fill-1); }
.move-status-bar[data-type="check"] { background: rgba(var(--cc-danger-rgb),.12); border-color: rgba(var(--cc-danger-rgb),.45); }
.move-status-bar[data-type="check"] .status-dot { background: var(--cc-danger-line); animation: cc-pulse .4s infinite; }
.move-status-bar[data-type="check"] #tuong-status-msg { color: var(--cc-danger); font-weight: 700; }

/* ── Luật chơi: ký hiệu quân chữ Hán ── */
.rules-content .piece-rule { display: flex; gap: var(--cc-sp-2); margin-bottom: var(--cc-sp-1); align-items: baseline; }
.rules-content .pc { font-family: 'Noto Serif SC', serif; font-weight: 700; color: var(--cc-wood-hi); min-width: 18px; font-size: var(--cc-fs-base); }
.rules-content .pn { color: var(--cc-text-2); font-weight: 600; margin-right: 2px; }

/* ── Lịch sử nước đi: dạng bảng (số · bên · quân · toạ độ) ── */
#tuong-app .move-history { max-height: 220px; }
#tuong-app .move-item {
    display: grid; grid-template-columns: 20px 28px 24px 1fr; align-items: center; gap: var(--cc-sp-1);
    padding: var(--cc-sp-1) 0; border-radius: 0; background: none; border-bottom: 1px solid var(--cc-fill-1);
}
#tuong-app .move-item:last-child { border-bottom: none; }
.move-col.red   { color: #ff7a6b; font-weight: 700; font-size: var(--cc-fs-xs); }
.move-col.black { color: var(--cc-success); font-weight: 700; font-size: var(--cc-fs-xs); }
.move-pc  { font-family: 'Noto Serif SC', serif; font-size: var(--cc-fs-base); text-align: center; }
.move-pos { color: var(--cc-text-muted); font-size: var(--cc-fs-xs); font-variant-numeric: tabular-nums; }

/* ── Bàn cờ ── */
.tuong-board-container {
    position: relative; display: inline-block; background: #e8cd8a;
    border: 8px solid #6b3308; border-radius: var(--cc-r-sm);
    box-shadow: 0 0 0 2px #a8571a, 0 14px 48px rgba(0,0,0,.65), inset 0 0 12px rgba(180,100,20,.15);
}
.board-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; overflow: visible; }
.tuong-board { border-collapse: collapse; position: relative; z-index: 2; background: transparent; }
.tuong-board td { width: var(--cell); height: var(--cell); position: relative; cursor: pointer; box-sizing: border-box;
                  border: 1.5px solid #7a4010; background: transparent; }
.tuong-board tr:nth-child(5) td { border-bottom: 2.5px solid #7a4010; } /* sông */
.tuong-board td.selected { background: rgba(245,166,35,.3); }
.tuong-board td.valid-move::after { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
    width: calc(var(--cell) * .3); height: calc(var(--cell) * .3); border-radius: 50%;
    background: rgba(200,130,20,.55); pointer-events: none; z-index: 10; }
.tuong-board td.capture-target::after { width: 84%; height: 84%; background: transparent; border: 3px solid rgba(200,50,30,.7); }
.tuong-board td.last-from { background: rgba(255,210,0,.28) !important; box-shadow: inset 0 0 0 2px rgba(220,160,0,.55); }
.tuong-board td.last-to   { background: rgba(255,200,0,.55) !important; box-shadow: inset 0 0 0 3px rgba(200,130,0,.8); }

/* ── Quân cờ (đĩa gỗ 3D) ── */
.piece {
    width: calc(var(--cell) * .86); height: calc(var(--cell) * .86);
    border-radius: 50%; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Noto Serif SC', serif; font-size: calc(var(--cell) * .285); font-weight: 900;
    pointer-events: none; user-select: none; z-index: 2;
    background-color: #c48a47;
    background-image:
        repeating-radial-gradient(ellipse at center, rgba(0,0,0,0) 0, rgba(0,0,0,0) 1.5px, rgba(0,0,0,.08) 2.5px, rgba(0,0,0,.08) 3.5px),
        radial-gradient(circle at 35% 25%, #ecc999 0%, #c48a47 45%, #75481a 100%);
    border: 2px solid #5a3510;
    box-shadow: 0 6px 12px rgba(0,0,0,.55), 0 3px 6px rgba(0,0,0,.40), inset 0 -5px 12px rgba(0,0,0,.5), inset 0 4px 8px rgba(255,255,255,.5);
    transition: transform .12s ease, box-shadow .12s ease;
}
.piece::before { content: ''; position: absolute; inset: calc(var(--cell) * .08); border-radius: 50%;
    border: 1px solid rgba(0,0,0,.4); box-shadow: inset 0 0 0 1px rgba(255,255,255,.3); pointer-events: none; z-index: 1; }
.piece::after { content: ''; position: absolute; top: 7%; left: 9%; width: 44%; height: 30%; border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(255,255,255,.82) 0%, rgba(255,255,255,.45) 45%, transparent 72%);
    transform: rotate(-22deg); pointer-events: none; z-index: 3; }
.tuong-board td:hover .piece {
    transform: translate(-50%, calc(-50% - 2px)) scale(1.05);
    box-shadow: 0 10px 24px rgba(0,0,0,.65), 0 4px 8px rgba(0,0,0,.40), inset 0 -5px 10px rgba(0,0,0,.28), inset 0 3px 6px rgba(255,255,255,.65);
}
.piece.red     { color: #cc2211; text-shadow: 1px 1px 0 rgba(255,255,255,.3), -1px -1px 2px rgba(0,0,0,.6); }
.piece.black-p { color: #111;    text-shadow: 1px 1px 0 rgba(255,255,255,.3), -1px -1px 2px rgba(0,0,0,.6); }
.piece.selected {
    transform: translate(-50%, calc(-50% - 3px)) scale(1.12) !important;
    box-shadow: 0 0 0 3px #ffd700, 0 0 22px rgba(255,215,0,.85), 0 12px 28px rgba(0,0,0,.65),
                inset 0 -5px 10px rgba(0,0,0,.25), inset 0 3px 6px rgba(255,255,255,.62) !important;
}

/* ── Báo chiếu ── */
#tuong-board .check-overlay {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
    width: calc(var(--cell) * .94); height: calc(var(--cell) * .94); border-radius: 50%; pointer-events: none; z-index: 15;
    background: rgba(231,76,60,.3); box-shadow: 0 0 0 3px rgba(231,76,60,.85), 0 0 18px rgba(231,76,60,.55);
    animation: checkFlash .65s ease-in-out infinite alternate;
}
@keyframes checkFlash { from { opacity: .45; } to { opacity: 1; } }
.check-toast {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%) scale(.5);
    z-index: 200; pointer-events: none; white-space: nowrap;
    padding: var(--cc-sp-3) var(--cc-sp-8); border-radius: var(--cc-r-lg);
    background: linear-gradient(135deg, rgba(180,0,0,.93), rgba(220,40,40,.93));
    color: #fff; font-size: var(--cc-fs-xl); font-weight: 800; letter-spacing: 3px; text-shadow: 0 2px 8px rgba(0,0,0,.5);
    box-shadow: 0 0 0 3px rgba(255,100,100,.6), 0 0 40px rgba(231,76,60,.7), 0 8px 24px rgba(0,0,0,.5);
    animation: checkToastAnim 2.3s cubic-bezier(.22,1,.36,1) forwards;
}
.check-toast.check-toast-me {
    background: linear-gradient(135deg, rgba(180,80,0,.95), rgba(230,120,0,.95));
    box-shadow: 0 0 0 3px rgba(255,180,60,.6), 0 0 40px rgba(230,120,0,.7), 0 8px 24px rgba(0,0,0,.5);
}
@keyframes checkToastAnim {
    0%   { transform: translate(-50%,-50%) scale(.4);  opacity: 0; }
    12%  { transform: translate(-50%,-50%) scale(1.12); opacity: 1; }
    22%  { transform: translate(-50%,-50%) scale(.97); opacity: 1; }
    35%  { transform: translate(-50%,-50%) scale(1);   opacity: 1; }
    72%  { transform: translate(-50%,-50%) scale(1);   opacity: 1; }
    100% { transform: translate(-50%,-50%) scale(.88); opacity: 0; }
}

/* Lật bàn cho người cầm quân Đen (quân mình ở dưới) */
.tuong-board-container.flip-board { transform: rotate(180deg); }
.flip-board .piece { transform: translate(-50%,-50%) rotate(180deg); }
.flip-board .tuong-board td:hover .piece { transform: translate(-50%, calc(-50% + 2px)) scale(1.05) rotate(180deg); }
.flip-board .piece.selected { transform: translate(-50%, calc(-50% + 3px)) scale(1.12) rotate(180deg) !important; }

@media (max-width: 639px) {
    .tuong-board-container { border-width: 5px; }
}
@media (prefers-reduced-motion: reduce) {
    #tuong-board .check-overlay { animation: none; }
}

/* ── Cờ úp: mặt sau quân cờ + hiệu ứng lật ── */
.piece.face-down {
    background-image:
        radial-gradient(circle at 50% 50%, transparent 0 30%, rgba(0,0,0,.18) 31% 33%, transparent 34%),
        repeating-conic-gradient(from 0deg, rgba(0,0,0,.06) 0 15deg, transparent 15deg 30deg),
        radial-gradient(circle at 35% 25%, #d9a86a 0%, #a8733a 50%, #6b4320 100%);
}
.piece.face-down::before { border-style: dashed; }
.piece.face-down.red     { box-shadow: 0 0 0 2px rgba(204,34,17,.75), 0 6px 12px rgba(0,0,0,.55), inset 0 -5px 12px rgba(0,0,0,.5); }
.piece.face-down.black-p { box-shadow: 0 0 0 2px rgba(20,20,20,.85), 0 6px 12px rgba(0,0,0,.55), inset 0 -5px 12px rgba(0,0,0,.5); }
.piece.just-flipped { animation: up-flip .45s cubic-bezier(.2,.7,.2,1); }
@keyframes up-flip {
    0%   { transform: translate(-50%,-50%) rotateY(90deg) scale(1.1); }
    100% { transform: translate(-50%,-50%) rotateY(0) scale(1); }
}
.flip-board .piece.just-flipped { animation-name: up-flip-rot; }
@keyframes up-flip-rot {
    0%   { transform: translate(-50%,-50%) rotate(180deg) rotateY(90deg) scale(1.1); }
    100% { transform: translate(-50%,-50%) rotate(180deg) rotateY(0) scale(1); }
}
.move-flip, .move-cap { font-size: var(--cc-fs-xs); padding: 0 6px; border-radius: var(--cc-r-full); margin-left: 4px; }
.move-flip { background: rgba(var(--cc-wood-rgb),.18); color: var(--cc-wood-hi); }
.move-cap  { background: rgba(var(--cc-danger-rgb),.16); color: var(--cc-danger); }
@media (prefers-reduced-motion: reduce) { .piece.just-flipped { animation: none; } }

/* ═══ Quân cờ v2: mặt ngà, vành theo màu bên, chữ khắc, gờ dày như quân gỗ thật ═══ */
.piece {
    background-color: #f1dfb8;
    background-image:
        radial-gradient(circle at 50% 42%, #fdf6e6 0%, #f3e2bd 48%, #e2c58f 82%, #c9a466 100%);
    border: 2px solid #8a5a2b;
    font-size: calc(var(--cell) * .38); font-weight: 900; line-height: 1;
    box-shadow:
        0 0 0 1px rgba(40,20,5,.35),
        0 calc(var(--cell) * .06) 0 #7a4b22,          /* gờ dưới: độ dày quân */
        0 calc(var(--cell) * .1) calc(var(--cell) * .16) rgba(0,0,0,.45),
        inset 0 2px 3px rgba(255,255,255,.75),
        inset 0 -3px 6px rgba(140,95,40,.3);
}
.piece::before {              /* vòng khắc bên trong, cùng màu chữ */
    inset: calc(var(--cell) * .07);
    border: 1.5px solid currentColor; opacity: .55; box-shadow: none;
}
.piece::after { opacity: .45; }  /* ánh bóng nhẹ hơn trên mặt sáng */
.piece.red     { color: #b8261b; border-color: #9a3a22; text-shadow: 0 1px 0 rgba(255,255,255,.7); }
.piece.black-p { color: #1f1a14; border-color: #5b4632; text-shadow: 0 1px 0 rgba(255,255,255,.7); }
.tuong-board td:hover .piece {
    box-shadow:
        0 0 0 1px rgba(40,20,5,.35),
        0 calc(var(--cell) * .08) 0 #7a4b22,
        0 calc(var(--cell) * .16) calc(var(--cell) * .24) rgba(0,0,0,.5),
        inset 0 2px 3px rgba(255,255,255,.75),
        inset 0 -3px 6px rgba(140,95,40,.3);
}
.piece.selected {
    box-shadow:
        0 0 0 3px #ffcf4a,
        0 0 18px rgba(255,200,60,.8),
        0 calc(var(--cell) * .08) 0 #7a4b22,
        0 calc(var(--cell) * .18) calc(var(--cell) * .26) rgba(0,0,0,.5),
        inset 0 2px 3px rgba(255,255,255,.75) !important;
}

/* Quân úp (Cờ úp): mặt sau sơn mài nâu tối, vòng chỉ vàng, viền theo màu bên — khác hẳn quân đã lật */
.piece.face-down {
    background-color: #5a3a1e;
    background-image:
        radial-gradient(circle at 50% 50%, transparent 0 22%, rgba(231,187,123,.55) 23% 25%, transparent 26%),
        repeating-radial-gradient(circle at 50% 50%, rgba(0,0,0,0) 0 3px, rgba(0,0,0,.09) 3px 4px),
        radial-gradient(circle at 38% 30%, #8a5a30 0%, #5a3a1e 55%, #3a2410 100%);
    color: transparent; text-shadow: none;
}
.piece.face-down::before { border: 1.5px dashed rgba(231,187,123,.7); opacity: 1; }
.piece.face-down.red     { border-color: #c0392b; }
.piece.face-down.black-p { border-color: #111; }
.piece.face-down.red, .piece.face-down.black-p {
    box-shadow:
        0 0 0 1px rgba(0,0,0,.4),
        0 calc(var(--cell) * .06) 0 #2c1a0b,
        0 calc(var(--cell) * .1) calc(var(--cell) * .16) rgba(0,0,0,.5),
        inset 0 2px 3px rgba(255,220,160,.25);
}
