.chess-app {
    max-width: 800px;
    margin: 0 auto;
    text-align: center;
}

.game-header {
    margin-bottom: 2rem;
}

.status-bar {
    display: inline-block;
    padding: 0.8rem 2rem;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    border-radius: 99px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    font-weight: 800;
    font-size: 1.2rem;
    color: #1e293b;
    margin-top: 1rem;
}

.status-bar.white-turn {
    border-left: 10px solid #f8fafc;
}

.status-bar.black-turn {
    border-left: 10px solid #1e293b;
    background: rgba(30, 41, 59, 0.1);
}

.board-container {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: min(90vw, 560px);
    aspect-ratio: 1 / 1;
    border: 8px solid #334155;
    border-radius: 8px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    background: #475569;
    position: relative;
    overflow: hidden;
}

.square {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(2rem, 8vw, 3.5rem);
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
    width: 100%;
    height: 100%;
    /* 内容によらずサイズを固定 */
    box-sizing: border-box;
    line-height: 0;
    position: relative; /* 絶対配置の演出用（撃破された駒など）の基準点 */
}

.square.white {
    background-color: #f1f5f9;
}

.square.black {
    background-color: #94a3b8;
}

.square:hover {
    filter: brightness(1.1);
}

.square.selected {
    background-color: #fde047 !important;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.2);
}

.square.valid-move {
    position: relative;
}

.square.valid-move::after {
    content: '';
    position: absolute;
    width: 25%;
    height: 25%;
    background: rgba(16, 185, 129, 0.6);
    border-radius: 50%;
}

/* ゲーム終了時のオーバーレイ */
.game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    color: white;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.winner-message {
    font-size: 2.5rem;
    font-weight: 900;
    margin-bottom: 1.5rem;
    text-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.piece.white {
    color: #000;
    text-shadow: 0 0 2px #fff;
    /* コマのサイズがマスのレイアウトに影響しないようにする */
    display: inline-block;
    width: 1em;
    height: 1em;
    line-height: 1;
}

.piece.black {
    color: #000;
    display: inline-block;
    width: 1em;
    height: 1em;
    line-height: 1;
}

/* 撃破（退場）アニメーション (調整版) */
.captured-piece {
    position: absolute;
    z-index: 150;
    pointer-events: none;
    animation: flyOut 0.2s forwards ease-out; /* 0.2s に調整 */
    font-size: clamp(2rem, 8vw, 3.5rem);
    transform-origin: bottom center;
}

@keyframes flyOut {
    0% { transform: rotate(0); }
    100% { transform: rotate(20deg); } /* 20deg に強化 */
}

/* アニメーション用レイヤー (移動中) */
.moving-piece {
    position: absolute;
    z-index: 200;
    pointer-events: none;
    transition: transform 0.4s ease-in-out;
    font-size: clamp(2rem, 8vw, 3.5rem);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transform-origin: top center;
    animation: moveTilt 0.4s ease-in-out; /* 傾斜パルスのみ実行 */
}

@keyframes moveTilt {
    0%, 100% { 
        rotate: 0deg; /* 開始と終了は直立 */
    }
    50% { 
        rotate: var(--tilt-angle, 0deg); /* 頂点で最大傾斜 */
    }
}

.game-info {
    margin-top: 1rem;
    color: #64748b;
    font-size: 0.9rem;
}

#reset-btn {
    background: #10b981;
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    border-radius: 12px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.2rem;
    box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.3);
    display: none; /* 通常時は非表示 */
}

#reset-btn:hover {
    background: #dc2626;
    transform: translateY(-2px);
}

/* 火星通信遅延（Mars Lag）演出 */
.chess-board.mars-lag {
    filter: grayscale(0.7) contrast(0.8);
    pointer-events: none;
    cursor: wait;
}

.comm-status-wrapper {
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    margin-bottom: 5px;
}

.comm-status {
    font-size: 0.85rem;
    color: #475569;
    font-weight: 800;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: white;
    padding: 4px 16px;
    border-radius: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.comm-status.is-visible {
    opacity: 1;
    transform: translateY(0);
    animation: commFloat 3s ease-in-out infinite;
}

@keyframes commFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.comm-icon {
    position: relative;
    width: 14px;
    height: 14px;
}

.comm-icon::before,
.comm-icon::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border: 2px solid #10b981;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: commPulse 2s infinite;
}

.comm-icon::after {
    animation-delay: 1s;
}

@keyframes commPulse {
    0% { width: 0; height: 0; opacity: 1; }
    100% { width: 30px; height: 30px; opacity: 0; }
}

.lag-timer {
    color: #0f172a;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-weight: 800;
    margin-left: 0.5rem;
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
}

.status-bar.is-lagging {
    background: rgba(148, 163, 184, 0.1);
    border-color: #cbd5e1;
}

.mars-rules-box {
    margin: 1.5rem auto;
    width: 95%;
    max-width: 800px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(5px);
    border: 1px solid #e2e8f0;
    border-left: 4px solid #10b981;
    border-radius: 8px;
    padding: 1.5rem 2rem;
    text-align: left;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.mars-rules-box h3 {
    margin-top: 0;
    font-size: 1.1rem;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mars-rules-box ul {
    margin: 0.75rem 0 0 0;
    padding-left: 1.5rem;
    font-size: 0.9rem;
    color: #475569;
    line-height: 1.7;
}

.mars-rules-box li strong {
    color: #10b981;
}

.mars-trivia {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
    font-size: 0.8rem;
    color: #64748b;
    line-height: 1.5;
}

.mars-trivia strong {
    color: #475569;
}
