:root {
    --bg-main: #0b0f19;
    --bg-card: rgba(22, 30, 46, 0.9);
    --bg-card-hover: rgba(30, 42, 66, 0.95);
    --border-color: rgba(212, 175, 55, 0.3);
    --border-gold: #d4af37;
    --gold-glow: rgba(212, 175, 55, 0.4);
    
    --text-primary: #f0f4f8;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --red-primary: #a91d22;
    --red-glow: rgba(169, 29, 34, 0.5);
    --red-bg: rgba(169, 29, 34, 0.15);
    
    --green-primary: #16a34a;
    --green-glow: rgba(22, 163, 74, 0.5);
    --green-bg: rgba(22, 163, 74, 0.15);
    
    --tile-inner-bg: #fffde7;
    --tile-ink-color: #1a1a1a;
    
    --board-bg: #fcf8ed;
    --font-heading: 'Noto Serif TC', serif;
    --font-ui: 'Teko', system-ui, sans-serif;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-main: 0 10px 30px -5px rgba(0, 0, 0, 0.6);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* App Layout - Left Dashboard & Right Full Height Board */
.app-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* Left Dashboard Column (資訊與控制邊欄) */
.left-dashboard {
    flex: 1;
    min-width: 480px;
    height: 100vh;
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    background: linear-gradient(180deg, #070a12 0%, #0d1322 100%);
    border-right: 2px solid var(--border-color);
}

.dash-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(212, 175, 55, 0.2);
}

.dash-brand .logo-icon {
    font-size: 28px;
    filter: drop-shadow(0 0 10px rgba(212, 175, 55, 0.5));
}

.dash-brand h1 {
    font-family: var(--font-heading);
    font-size: 22px;
    color: var(--border-gold);
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
}

.dash-brand .subtitle {
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--text-secondary);
    display: block;
}

/* Dash Controls */
.dash-controls {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: var(--shadow-main);
}

.control-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.control-group label {
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

.styled-select {
    background: #0f172a;
    color: var(--text-primary);
    border: 1px solid rgba(212, 175, 55, 0.4);
    border-radius: var(--radius-sm);
    padding: 5px 8px;
    font-size: 12px;
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.styled-select:hover {
    border-color: var(--border-gold);
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.3);
}

.btn-row {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(0.6);
}
.btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

.btn-primary {
    background: linear-gradient(135deg, #d4af37 0%, #aa820a 100%);
    color: #0b0f19;
    box-shadow: 0 3px 10px rgba(212, 175, 55, 0.3);
    flex: 1;
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 15px rgba(212, 175, 55, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.15);
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-action {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    box-shadow: 0 3px 10px rgba(59, 130, 246, 0.3);
}

.btn-success {
    background: linear-gradient(135deg, #10b981 0%, #047857 100%);
    color: white;
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
}

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-gold);
}
.btn-outline:hover {
    background: rgba(212, 175, 55, 0.1);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.4);
}

/* Status Banner */
.dash-status-banner {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-main);
}

.turn-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
}

.turn-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: 0 0 8px currentColor;
}
.red-dot { background-color: var(--red-primary); color: var(--red-primary); }
.green-dot { background-color: var(--green-primary); color: var(--green-primary); }

.setup-controls, .gameplay-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
}

.setup-hint {
    font-size: 12px;
    font-weight: 600;
    color: #fbbf24;
    white-space: nowrap;
}
.setup-hint.ready {
    color: #34d399;
}
.setup-hint:empty {
    display: none;
}

/* Side by Side Players Cards */
.players-cards-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.player-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-main);
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    font-family: var(--font-heading);
    color: white;
    flex-shrink: 0;
}
.green-avatar { background: linear-gradient(135deg, #16a34a, #14532d); border: 2px solid #4ade80; }
.red-avatar { background: linear-gradient(135deg, #a91d22, #7f1d1d); border: 2px solid #fca5a5; }

.player-info h3 {
    font-size: 13px;
    margin-bottom: 2px;
}

.status-tags {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tag {
    font-size: 10px;
    padding: 1px 4px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
}

.tag.revealed {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.5);
}

/* Setup Tray */
.setup-tray-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    max-height: 220px;
}

.setup-tray-card h4 {
    font-size: 13px;
    color: var(--border-gold);
    margin-bottom: 6px;
    font-family: var(--font-heading);
}

.tray-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    overflow-y: auto;
    padding: 2px;
}

/* Log & Graveyard Grid */
.log-graveyard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    flex: 1;
    min-height: 200px;
}

.battle-log-card, .graveyards-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.battle-log-card h4, .graveyards-card h4 {
    font-size: 13px;
    color: var(--border-gold);
    margin-bottom: 6px;
    font-family: var(--font-heading);
}

.log-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 12px;
}

.log-entry {
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.3);
    border-left: 3px solid var(--text-muted);
    line-height: 1.3;
}
.log-entry.info { border-left-color: var(--border-gold); }
.log-entry.red-action { border-left-color: var(--red-primary); background: var(--red-bg); }
.log-entry.green-action { border-left-color: var(--green-primary); background: var(--green-bg); }
.log-entry.combat { border-left-color: var(--border-gold); background: rgba(212, 175, 55, 0.15); font-weight: bold; }

.graveyard-section {
    margin-bottom: 6px;
}

.graveyard-section h5 {
    font-size: 11px;
    margin-bottom: 4px;
}
.green-title { color: #4ade80; }
.red-title { color: #fca5a5; }

.graveyard-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-height: 130px;
    overflow-y: auto;
}

.graveyard-piece {
    width: 65px;
    height: 42px;
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid #16a34a;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.graveyard-piece img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.graveyard-piece.red-dead {
    border-color: #a91d22;
}

/* RIGHT VIEWPORT: FULL HEIGHT BOARD (100vh 上下頂住整個頁面) */
.right-board-viewport {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #050811;
    padding: 0;
    margin: 0;
    position: relative;
    overflow: hidden;
}

.board-container {
    height: 100vh;
    width: calc(100vh * (640 / 880));
    aspect-ratio: 640 / 880;
    background: #fcf8ed;
    border: none;
    border-radius: 0;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

#chess-board-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.pieces-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

/* Cropped Piece Tile Style inside Board */
.chess-piece {
    position: absolute;
    width: 11.5%;
    height: 6.2%;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    cursor: pointer;
    transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.22s ease;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
    user-select: none;
}

.chess-piece .piece-img-tile {
    width: 100%;
    height: 100%;
    object-fit: fill;
    border-radius: 3px;
    display: block;
}

.chess-piece.side-red {
    background: #a91d22;
    border: 2px solid #7f1d1d;
}

.chess-piece.side-north, .chess-piece.side-green {
    background: #16a34a;
    border: 2px solid #14532d;
}

.chess-piece.face-down {
    padding: 0;
}
.chess-piece.side-north.face-down {
    background: linear-gradient(135deg, #15803d 0%, #14532d 100%) !important;
    border: 2px solid #052e16 !important;
}
.chess-piece.side-north.face-down::after {
    content: "🎖️";
    font-size: 20px;
    opacity: 0.8;
}

.chess-piece:hover {
    transform: translate(-50%, -56%) scale(1.08);
    z-index: 10;
    box-shadow: 0 10px 25px rgba(212, 175, 55, 0.7);
}

.chess-piece.selected {
    border-color: #f59e0b !important;
    box-shadow: 0 0 20px #f59e0b, 0 0 40px #f59e0b;
    transform: translate(-50%, -56%) scale(1.12);
    z-index: 20;
    animation: piece-pulse 1.5s infinite alternate;
}

/* === 動作提示動畫特效 (方案 C) === */

/* 1. 最後一手移動軌跡提示 (Last Move Indicators) */
.last-move-from {
    position: absolute;
    width: 10%;
    height: 5.5%;
    transform: translate(-50%, -50%);
    border: 2px dashed rgba(245, 158, 11, 0.7);
    background: rgba(245, 158, 11, 0.12);
    border-radius: 6px;
    pointer-events: none;
    z-index: 3;
    animation: pulse-from 2s infinite ease-in-out;
}

.last-move-to {
    position: absolute;
    width: 11.5%;
    height: 6.2%;
    transform: translate(-50%, -50%);
    border: 2px solid #fbbf24;
    box-shadow: 0 0 15px #fbbf24, inset 0 0 10px rgba(251, 191, 36, 0.4);
    border-radius: 4px;
    pointer-events: none;
    z-index: 3;
    animation: pulse-to 1.8s infinite alternate ease-in-out;
}

@keyframes pulse-from {
    0% { opacity: 0.4; }
    50% { opacity: 0.85; }
    100% { opacity: 0.4; }
}

@keyframes pulse-to {
    0% { box-shadow: 0 0 8px #fbbf24; }
    100% { box-shadow: 0 0 22px #f59e0b, 0 0 8px #ffffff; }
}

/* 2. 普通移動/落點閃爍呼吸燈 (Move Glow) */
.anim-move-glow {
    animation: moveGlow 0.55s ease-out forwards !important;
}

@keyframes moveGlow {
    0% {
        box-shadow: 0 0 25px #38bdf8, 0 0 45px #0284c7;
        transform: translate(-50%, -50%) scale(1.18);
        border-color: #38bdf8;
    }
    50% {
        box-shadow: 0 0 20px #38bdf8;
        transform: translate(-50%, -50%) scale(1.08);
    }
    100% {
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
        transform: translate(-50%, -50%) scale(1);
    }
}

/* 3. 翻棋金光閃爍動畫 (Flip Glow) */
.anim-flip-glow {
    animation: flipGlow 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards !important;
}

@keyframes flipGlow {
    0% {
        transform: translate(-50%, -50%) rotateY(90deg) scale(0.8);
        box-shadow: 0 0 0px transparent;
    }
    50% {
        transform: translate(-50%, -50%) rotateY(0deg) scale(1.22);
        box-shadow: 0 0 30px #f59e0b, 0 0 50px #fffde7;
        border-color: #fce7f3;
    }
    100% {
        transform: translate(-50%, -50%) rotateY(0deg) scale(1);
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
    }
}

/* 4. 吃子震動紅光打擊特效 (Combat Hit Shake & Red Flash) */
.anim-combat-hit {
    animation: combatHit 0.6s ease-in-out forwards !important;
    z-index: 30 !important;
}

@keyframes combatHit {
    0% {
        transform: translate(-50%, -50%) scale(1.25);
        box-shadow: 0 0 35px #ef4444, 0 0 60px #dc2626;
        border-color: #f87171 !important;
    }
    15% { transform: translate(-46%, -52%) scale(1.2); }
    30% { transform: translate(-54%, -48%) scale(1.18); }
    45% { transform: translate(-48%, -54%) scale(1.12); }
    60% { transform: translate(-52%, -46%) scale(1.08); }
    75% { transform: translate(-49%, -51%) scale(1.04); }
    100% {
        transform: translate(-50%, -50%) scale(1);
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
    }
}

/* 5. 同歸於盡/炸彈爆炸特效 (Explosion Flash) */
.explosion-effect {
    position: absolute;
    width: 14%;
    height: 8%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    animation: explosionPop 0.75s ease-out forwards;
}

@keyframes explosionPop {
    0% {
        transform: translate(-50%, -50%) scale(0.3);
        opacity: 1;
        filter: drop-shadow(0 0 20px #ef4444);
    }
    40% {
        transform: translate(-50%, -50%) scale(1.6);
        opacity: 1;
        filter: drop-shadow(0 0 40px #f59e0b);
    }
    100% {
        transform: translate(-50%, -50%) scale(2.2);
        opacity: 0;
        filter: drop-shadow(0 0 60px #dc2626);
    }
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.3s;
}

.modal-overlay.hidden {
    display: none;
    pointer-events: none;
}

.modal-card {
    background: #0f172a;
    border: 2px solid var(--border-gold);
    border-radius: var(--radius-md);
    width: 90%;
    max-width: 650px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-family: var(--font-heading);
    color: var(--border-gold);
    font-size: 18px;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
}
.close-btn:hover { color: white; }

.modal-body {
    padding: 20px;
    overflow-y: auto;
    line-height: 1.6;
    font-size: 14px;
    color: #cbd5e1;
}

.modal-body h3 {
    color: var(--border-gold);
    margin: 14px 0 6px 0;
    font-family: var(--font-heading);
}

.modal-body ul, .modal-body ol {
    padding-left: 20px;
}

.victory-card {
    text-align: center;
    padding: 36px;
    align-items: center;
    position: relative;
}

.victory-card .close-btn {
    position: absolute;
    top: 12px;
    right: 16px;
}

.victory-icon {
    font-size: 56px;
    margin-bottom: 12px;
    animation: bounce 1s infinite alternate;
}

.victory-reason {
    margin: 14px 0 20px 0;
    color: var(--text-secondary);
    font-size: 15px;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-10px); }
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

@keyframes piece-pulse {
    from { filter: drop-shadow(0 0 4px #f59e0b); }
    to { filter: drop-shadow(0 0 14px #f59e0b); }
}

.hidden {
    display: none !important;
}

::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.3);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(212, 175, 55, 0.6);
}
