/* リセットとベーススタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background-color: #f0f0f0;
    font-family: sans-serif;
    color: #333;
  }

/* --- スマホ・タブレットでの調整 --- */
@media (max-width: 768px) {
  .home-button {
    padding: 10px;
    font-size: 1.2rem;
  }
  
  /* overlay内のヘッダーボタンの位置調整 */
  .start-overlay .home-button,
  .game-over-overlay .home-button {
    top: 25px;
    right: 15px;
    padding: 8px;
    font-size: 1rem;
  }
  
  .home-button .button-text {
    display: none; /* テキストを非表示に */
  }
}

  /* --- ヘッダー --- */
header {
    background-color: #2c3e50;
    color: white;
    text-align: center;
    padding: 1rem;
    position: relative;
  }
  
  header h1 {
    margin: 0;
    font-size: 1.8rem;
  }
  
  /* --- ホームボタン --- */
  .home-button {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%); /* 上下中央揃え */
    background-color: #3498db;
    color: white;
    padding: 10px 15px;
    border-radius: 5px;
    text-decoration: none;
    font-weight: bold;
    font-size: 1rem;
    transition: background-color 0.2s ease-in-out;
  }
  
  .home-button:hover {
    background-color: #2980b9;
  }

/* ゲーム開始画面のoverlay */
.start-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

/* overlay内のヘッダーボタンを右上に固定 */
.start-overlay .home-button {
    position: fixed;
    top: 30px;
    right: 20px;
    z-index: 1001;
    backdrop-filter: blur(5px);
}

.start-content {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    border: 2px solid #3498db;
    max-width: 400px;
    width: 90%;
}

.start-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.start-header h2 {
    color: #ecf0f1;
    font-size: 2.5rem;
    margin: 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    flex: 1;
    text-align: center;
}

.start-content p {
    color: #bdc3c7;
    font-size: 1.1rem;
    margin: 0 0 30px 0;
}

.game-settings {
    margin: 30px 0;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.setting-item label {
    color: #ecf0f1;
    font-weight: 600;
    font-size: 1.1rem;
}

.setting-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.setting-item select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 2px solid #3498db;
    background: #2c3e50;
    color: #ecf0f1;
    font-size: 1rem;
    cursor: pointer;
}

.setting-item select:focus {
    outline: none;
    border-color: #2980b9;
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.3);
}

.start-button {
    background: linear-gradient(45deg, #3498db, #2980b9);
    color: white;
    border: none;
    padding: 15px 40px;
    font-size: 1.3rem;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
    margin-top: 20px;
}

.start-button:hover {
    background: linear-gradient(45deg, #2980b9, #1f4e79);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(52, 152, 219, 0.4);
}

.start-button:active {
    transform: translateY(0);
}

/* ゲーム開始画面を非表示にするクラス */
.start-overlay.hidden {
    display: none;
}

/* ゲーム終了画面のoverlay */
.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1001;
}

/* ゲーム終了画面のoverlay内のヘッダーボタンを右上に固定 */
.game-over-overlay .home-button {
    position: fixed;
    top: 30px;
    right: 20px;
    z-index: 1002;
    backdrop-filter: blur(5px);
}

.game-over-content {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    border: 3px solid #e74c3c;
    max-width: 450px;
    width: 90%;
    animation: gameOverSlideIn 0.5s ease-out;
}

@keyframes gameOverSlideIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-50px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.game-over-header h2 {
    color: #ecf0f1;
    font-size: 2.2rem;
    margin: 0 0 20px 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.game-result {
    margin: 30px 0;
}

.result-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    animation: trophyBounce 1s ease-in-out infinite alternate;
}

@keyframes trophyBounce {
    from {
        transform: scale(1);
    }
    to {
        transform: scale(1.1);
    }
}

.result-icon.winner {
    color: #f1c40f;
    text-shadow: 0 0 20px rgba(241, 196, 15, 0.5);
}

.result-icon.loser {
    color: #e74c3c;
    text-shadow: 0 0 20px rgba(231, 76, 60, 0.5);
}

.result-message {
    color: #ecf0f1;
    font-size: 1.8rem;
    font-weight: bold;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.result-details {
    color: #bdc3c7;
    font-size: 1.1rem;
    margin-bottom: 20px;
}

.game-over-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
}

.action-button {
    padding: 12px 25px;
    border: none;
    border-radius: 25px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 140px;
}

.action-button.primary {
    background: linear-gradient(45deg, #27ae60, #2ecc71);
    color: white;
    box-shadow: 0 5px 15px rgba(39, 174, 96, 0.3);
}

.action-button.primary:hover {
    background: linear-gradient(45deg, #229954, #27ae60);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(39, 174, 96, 0.4);
}

.action-button.secondary {
    background: linear-gradient(45deg, #95a5a6, #bdc3c7);
    color: #2c3e50;
    box-shadow: 0 5px 15px rgba(149, 165, 166, 0.3);
}

.action-button.secondary:hover {
    background: linear-gradient(45deg, #7f8c8d, #95a5a6);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(149, 165, 166, 0.4);
}

.action-button:active {
    transform: translateY(0);
}

/* ゲーム終了画面を非表示にするクラス */
.game-over-overlay.hidden {
    display: none;
}

/* ローディングアニメーション */
.loading-animation {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 5px; /* マージンを小さく調整 */
    gap: 8px; /* ギャップを小さく調整 */
}

.loading-animation.hidden {
    display: none;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background-color: #3498db;
    border-radius: 50%;
    animation: bounce 1.4s ease-in-out infinite both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}



/* メインコンテナ */
.game-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* ヘッダー */
.game-header {
    text-align: center;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

.game-header h1 {
    font-size: 1.8em;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 5px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.turn-display {
    font-size: 1.2em;
    font-weight: bold;
    color: #e74c3c;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

/* ゲームレイアウト */
.game-layout {
    display: grid;
    grid-template-columns: 150px 1fr 150px;
    gap: 10px;
    align-items: start;
    flex: 1;
    min-height: 0;
    margin-bottom: 10px;
}



/* デスクトップ版ではモバイル用の先手持ち駒エリアを非表示 */
.mobile-sente-area {
    display: none;
}

/* デスクトップ版ではデスクトップ用の先手持ち駒エリアを表示 */
.desktop-sente-area {
    display: block;
}

/* メインゲームエリア */
.main-game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-height: 0;
}

/* メッセージエリア */
.message-area {
    width: 100%;
    max-width: 400px;
    min-height: 80px; /* 固定の最小高さを設定 */
    background: rgba(255, 255, 255, 0.95);
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    text-align: center;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: center; /* 縦方向の中央揃え */
}

.message-area p {
    margin: 0;
    font-size: 0.9em;
    font-weight: 600;
    color: #2c3e50;
    white-space: pre-line; /* 改行を有効にする */
}

/* 将棋盤コンテナ */
.board-container {
    background: rgba(255, 255, 255, 0.95);
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px);
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    width: fit-content;
    height: fit-content;
    min-width: 500px;
    min-height: 500px;
}

canvas {
    background: linear-gradient(45deg, #f4e4bc 0%, #e8d5a3 100%);
    border: 3px solid #8b4513;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
    aspect-ratio: 1;
    width: 100%;
    height: auto;
    max-width: 100%;
    max-height: 100%;
}

/* ホバーエフェクトを削除 */

/* コントロールエリア */
.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.95);
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    width: 100%;
    max-width: 400px;
    flex-shrink: 0;
}

/* AIトグルスイッチ */
.ai-toggle-container {
    display: flex;
    align-items: center;
    gap: 15px;
    font-weight: 600;
    color: #2c3e50;
}

.ai-toggle-container input[type="checkbox"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-toggle-container input[type="checkbox"]:disabled + label {
    opacity: 0.5;
    color: #7f8c8d;
}

/* AI難易度選択 */
.ai-difficulty-container {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: #2c3e50;
}

.difficulty-select {
    padding: 8px 12px;
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    background: linear-gradient(45deg, #ffffff, #f8f9fa);
    font-size: 0.9em;
    font-weight: 600;
    color: #2c3e50;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.difficulty-select:hover {
    border-color: #3498db;
    box-shadow: 0 4px 8px rgba(52, 152, 219, 0.2);
}

.difficulty-select:focus {
    outline: none;
    border-color: #2980b9;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.difficulty-select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    border-color: #7f8c8d;
    background: linear-gradient(45deg, #ecf0f1, #bdc3c7);
    color: #7f8c8d;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, #95a5a6, #7f8c8d);
    transition: 0.4s;
    border-radius: 34px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background: linear-gradient(45deg, #ffffff, #f8f9fa);
    transition: 0.4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked + .slider {
    background: linear-gradient(45deg, #3498db, #2980b9);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

/* リセットボタン */
.reset-button {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1.1em;
    font-weight: 600;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

.reset-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

.reset-button:active {
    transform: translateY(0);
}

.ai-note {
    font-size: 0.9em;
    color: #7f8c8d;
    font-style: italic;
    margin: 0;
}

/* 持ち駒エリア */
.captured-area {
    background: rgba(255, 255, 255, 0.95);
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    height: fit-content;
    flex-shrink: 0;
}

.captured-area h3 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 1em;
    color: #2c3e50;
    font-weight: 600;
}

.captured-pieces-container {
    width: 100%;
    min-height: 80px;
    background: linear-gradient(45deg, #ecf0f1, #bdc3c7);
    border: 2px solid #95a5a6;
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    justify-content: center;
    align-items: flex-start;
}

.captured-piece {
    width: 32px;
    height: 48px;
    background: linear-gradient(45deg, #f4e4bc, #e8d5a3);
    border: 2px solid #8b4513;
    border-radius: 6px;
    font-size: 10px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    color: #2c3e50;
}

.captured-piece:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.captured-piece.selected {
    background: linear-gradient(45deg, #f39c12, #e67e22);
    box-shadow: 0 0 10px 3px #f39c12;
    transform: scale(1.1);
}

/* セカンダリメッセージエリアは削除 */

/* レスポンシブデザイン */

/* 大画面デスクトップ (1400px以上) */
@media (min-width: 1400px) {
    .game-container {
        max-width: 1800px;
    }
    
    .game-layout {
        grid-template-columns: 180px 1fr 180px;
        gap: 25px;
    }
    
    .board-container {
        padding: 15px;
        min-width: 800px;
        min-height: 800px;
    }
    
    canvas {
        width: 100%;
        max-width: 900px;
        aspect-ratio: 1;
        height: auto;
    }
}

/* 超大画面デスクトップ (1600px以上) */
@media (min-width: 1600px) {
    .game-container {
        max-width: 2000px;
    }
    
    .game-layout {
        grid-template-columns: 200px 1fr 200px;
        gap: 30px;
    }
    
    .board-container {
        padding: 20px;
        min-width: 1000px;
        min-height: 1000px;
    }
    
    canvas {
        width: 100%;
        max-width: 1100px;
        aspect-ratio: 1;
        height: auto;
    }
}

/* 超超大画面デスクトップ (2000px以上) */
@media (min-width: 2000px) {
    .game-container {
        max-width: 2400px;
    }
    
    .game-layout {
        grid-template-columns: 220px 1fr 220px;
        gap: 35px;
    }
    
    .board-container {
        padding: 25px;
        min-width: 1200px;
        min-height: 1200px;
    }
    
    canvas {
        width: 100%;
        max-width: 1400px;
        aspect-ratio: 1;
        height: auto;
    }
}

/* デスクトップ (1200px-1399px) */
@media (min-width: 1200px) and (max-width: 1399px) {
    .game-layout {
        grid-template-columns: 160px 1fr 160px;
        gap: 20px;
    }
    
    .board-container {
        min-width: 650px;
        min-height: 650px;
    }
    
    canvas {
        width: 100%;
        max-width: 550px;
        aspect-ratio: 1;
        height: auto;
    }
}

/* ラップトップ (992px-1199px) */
@media (min-width: 992px) and (max-width: 1199px) {
    .game-layout {
        grid-template-columns: 140px 1fr 140px;
        gap: 15px;
    }
    
    .board-container {
        min-width: 550px;
        min-height: 550px;
    }
    
    canvas {
        width: 100%;
        max-width: 600px;
        aspect-ratio: 1;
        height: auto;
    }
}

/* 中サイズラップトップ (1000px-1100px) */
@media (min-width: 1000px) and (max-width: 1100px) {
    .board-container {
        min-width: 600px;
        min-height: 600px;
    }
    
    canvas {
        width: 100%;
        max-width: 650px;
        aspect-ratio: 1;
        height: auto;
    }
}

/* タブレット横向き (768px-991px) */
@media (min-width: 768px) and (max-width: 991px) {
    .game-container {
        padding: 8px;
    }
    
    .game-layout {
        grid-template-columns: 140px 1fr 140px;
        gap: 15px;
    }
    
    .game-header {
        padding: 12px;
        margin-bottom: 8px;
    }
    
    .game-header h1 {
        font-size: 1.6em;
    }
    
    .turn-display {
        font-size: 1.1em;
    }
    
    canvas {
        width: 100%;
        max-width: 500px;
        aspect-ratio: 1;
        height: auto;
    }
    
    .board-container {
        padding: 8px;
        min-width: 400px;
        min-height: 400px;
    }
    
    .controls {
        padding: 12px;
        gap: 10px;
    }
    
    .captured-area {
        padding: 12px;
    }
    
    .captured-piece {
        width: 30px;
        height: 45px;
        font-size: 10px;
    }
    
    .message-area {
        padding: 10px 15px;
        max-width: 350px;
        min-height: 80px; /* 固定の最小高さを設定 */
    }
}

/* スマートフォン全般 (768px以下) */
@media (max-width: 768px) {
    .game-container {
        padding: 4px;
        min-height: 100vh;
        height: auto;
        width: 100%;
        max-width: 100vw;
    }
    
    .game-header {
        padding: 8px;
        margin-bottom: 4px;
    }
    
    .game-header h1 {
        font-size: 1.3em;
    }
    
    .turn-display {
        font-size: 0.9em;
    }
    
    .game-layout {
        display: flex;
        flex-direction: column;
        gap: 4px;
        width: 100%;
    }
    
    /* 後手の持ち駒を上に横長配置 */
    .gote-area {
        order: 1;
        width: 100%;
    }
    
    /* メインゲームエリアを中央に配置 */
    .main-game-area {
        order: 2;
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center; /* 子要素を中央揃え */
    }
    
    /* デスクトップ用の先手持ち駒エリアを非表示 */
    .desktop-sente-area {
    display: none;
}
    
    /* モバイル用の先手持ち駒エリアを表示 */
    .mobile-sente-area {
        display: block;
        margin: 8px 0;
    }
    
    canvas {
        width: 100%;
        max-width: 400px; /* スマホ用の最大サイズを制限 */
        aspect-ratio: 1; /* 正方形を維持 */
        height: auto;
    }
    
    .board-container {
        padding: 8px;
        width: 100%;
        display: flex;
        justify-content: center; /* 盤面を中央に配置 */
        align-items: center;
        min-width: unset;
        min-height: unset;
    }
    
    .controls {
        padding: 8px;
        gap: 8px;
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center; /* コントロール要素を中央揃え */
}

.captured-area {
        padding: 8px;
        width: 100%;
}

.captured-area h3 {
        font-size: 0.9em;
        margin-bottom: 4px;
}

.captured-pieces-container {
        min-height: 60px;
        padding: 6px;
        gap: 2px;
        justify-content: flex-start;
    }
    
    .captured-piece {
        width: 24px;
        height: 36px;
        font-size: 8px;
    }
    
    .message-area {
        padding: 6px 8px;
    width: 100%;
        max-width: 100%;
        min-height: 70px; /* スマホ用の固定最小高さ */
    display: flex;
        flex-direction: column;
        align-items: center; /* メッセージエリアを中央揃え */
    }
    
    .message-area p {
        font-size: 0.8em;
        white-space: pre-line; /* 改行を有効にする */
    }
    
    .ai-toggle-container {
        flex-direction: row;
        gap: 8px;
    }
    
    .ai-difficulty-container {
        flex-direction: row;
        gap: 8px;
    }
    
    .difficulty-select {
        padding: 6px 10px;
        font-size: 0.8em;
    }
    
    .reset-button {
        padding: 8px 16px;
        font-size: 0.9em;
    }
}

/* 小さなスマートフォン (500px以下) */
@media (max-width: 500px) {
    .board-container {
        padding: 6px;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        min-width: unset;
        min-height: unset;
    }
}

/* 小さいスマートフォン (480px以下) */
@media (max-width: 480px) {
    .game-container {
        padding: 3px;
    }
    
    .game-header {
        padding: 6px;
        margin-bottom: 3px;
    }
    
    .game-header h1 {
        font-size: 1.1em;
    }
    
    .turn-display {
        font-size: 0.85em;
    }
    
    .game-layout {
        gap: 3px;
    }
    
    .board-container {
        padding: 6px;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        min-width: unset;
        min-height: unset;
    }
    
    .captured-pieces-container {
        min-height: 50px;
        padding: 4px;
    }
    
    .captured-piece {
        width: 22px;
        height: 33px;
        font-size: 7px;
    }
    
    .captured-area h3 {
        font-size: 0.8em;
    }
    
    .message-area p {
        font-size: 0.75em;
        white-space: pre-line; /* 改行を有効にする */
    }
    
    .ai-toggle-container {
        flex-direction: column;
        gap: 6px;
    }
    
    .ai-difficulty-container {
        flex-direction: column;
        gap: 6px;
    }
    
    .difficulty-select {
        padding: 4px 8px;
        font-size: 0.75em;
    }
    
    .reset-button {
        padding: 6px 12px;
        font-size: 0.8em;
    }
}

/* 極小スマートフォン (360px以下) */
@media (max-width: 360px) {
    .game-container {
        padding: 2px;
    }
    
    .game-header {
        padding: 4px;
        margin-bottom: 2px;
    }
    
    .game-header h1 {
        font-size: 1em;
    }
    
    .turn-display {
        font-size: 0.8em;
    }
    
    .game-layout {
        gap: 2px;
    }
    
    .captured-pieces-container {
        min-height: 45px;
        padding: 3px;
    }
    
    .captured-piece {
        width: 20px;
        height: 30px;
        font-size: 6px;
    }
    
    .captured-area h3 {
        font-size: 0.7em;
    }
    
    .message-area p {
        font-size: 0.7em;
        white-space: pre-line; /* 改行を有効にする */
    }
    
    .ai-toggle-container {
        flex-direction: column;
    gap: 4px;
}

    .ai-difficulty-container {
        flex-direction: column;
        gap: 4px;
    }
    
    .difficulty-select {
        padding: 3px 6px;
        font-size: 0.7em;
    }
    
    .reset-button {
        padding: 4px 8px;
        font-size: 0.7em;
    }
    
    .ai-note {
        font-size: 0.6em;
    }
    
    .rules-panel {
        margin-top: auto;
        margin-bottom: 4px;
    }
    
    .rules-header {
        padding: 8px 12px;
    }
    
    .rules-header h3 {
        font-size: 0.9em;
    }
    
    .rules-section {
        padding: 12px;
    }
    
    .rules-section h4 {
        font-size: 0.9em;
    }
    
    .piece-rules,
    .special-rules,
    .captured-rules,
    .victory-rules,
    .promotion-rules,
    .status-rules {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .piece-rule,
    .special-rule,
    .captured-rule,
    .victory-rule,
    .promotion-rule,
    .status-rule {
        padding: 6px 10px;
        font-size: 0.8em;
    }
}

/* 横向きモード対応 */
@media (orientation: landscape) and (max-height: 600px) {
    .game-container {
        height: 100vh;
        overflow-y: auto;
        padding: 2px;
    }
    
    .game-header {
        padding: 4px;
        margin-bottom: 2px;
    }
    
    .game-header h1 {
        font-size: 1em;
    }
    
    .turn-display {
        font-size: 0.8em;
    }
    
    .game-layout {
        display: flex;
        flex-direction: row;
        gap: 4px;
    }
    
    .sente-area {
        order: 1;
        flex: 0 0 120px;
    }
    
    .main-game-area {
        order: 2;
        flex: 1;
    }
    
    .gote-area {
        order: 3;
        flex: 0 0 120px;
    }
    
    canvas {
        width: 100%;
        max-width: 350px; /* 小さなスマホ用の最大サイズを制限 */
        aspect-ratio: 1; /* 正方形を維持 */
        height: auto;
    }
    
    .captured-pieces-container {
        min-height: 40px;
        padding: 3px;
    }

.captured-piece {
        width: 20px;
        height: 30px;
        font-size: 7px;
    }
    
    .captured-area h3 {
        font-size: 0.7em;
    }
    
    .message-area {
        padding: 4px 6px;
        max-width: 100%;
        min-height: 60px; /* 小さなスマホ用の固定最小高さ */
    display: flex;
        flex-direction: column;
        align-items: center; /* メッセージエリアを中央揃え */
    }
    
    .message-area p {
        font-size: 0.7em;
        white-space: pre-line; /* 改行を有効にする */
    }
    
    .controls {
        padding: 4px;
        gap: 4px;
    }
    
    .reset-button {
        padding: 4px 8px;
        font-size: 0.7em;
    }
    
    .rules-panel {
        margin-top: auto;
        margin-bottom: 2px;
    }
}

/* アニメーション */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.game-container > * {
    animation: fadeIn 0.6s ease-out;
}

.game-layout > * {
    animation: fadeIn 0.8s ease-out;
}

/* ホバーエフェクトを削除 */

/* フォーカス状態 */
.reset-button:focus,
.toggle-switch input:focus + .slider {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

/* ルール表示パネル */
.rules-panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    margin-top: auto;
    margin-bottom: 10px;
    overflow: hidden;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.rules-header {
    background: linear-gradient(45deg, #3498db, #2980b9);
    color: white;
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    transition: all 0.3s ease;
}

.rules-header:hover {
    background: linear-gradient(45deg, #2980b9, #1f618d);
}

.rules-header h3 {
    margin: 0;
    font-size: 1.1em;
    font-weight: 600;
}

.toggle-icon {
    font-size: 1.2em;
    transition: transform 0.3s ease;
}

.rules-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: rgba(255, 255, 255, 0.98);
}

.rules-content.open {
    max-height: 600px;
    overflow-y: auto;
}

.rules-content.open .toggle-icon {
    transform: rotate(180deg);
}

.rules-section {
    padding: 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.rules-section:last-child {
    border-bottom: none;
}

.rules-section h4 {
    margin: 0 0 12px 0;
    font-size: 1em;
    color: #2c3e50;
    font-weight: 600;
    border-bottom: 2px solid #3498db;
    padding-bottom: 4px;
}

.piece-rules,
.special-rules,
.captured-rules,
.victory-rules,
.promotion-rules,
.status-rules {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 8px;
}

.piece-rule,
.special-rule,
.captured-rule,
.victory-rule,
.promotion-rule,
.status-rule {
    background: linear-gradient(45deg, #ecf0f1, #bdc3c7);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9em;
    border-left: 4px solid #3498db;
    transition: all 0.2s ease;
}

.piece-rule:hover,
.special-rule:hover,
.captured-rule:hover,
.victory-rule:hover,
.promotion-rule:hover,
.status-rule:hover {
    background: linear-gradient(45deg, #d5dbdb, #a6acaf);
    transform: translateX(2px);
}

.piece-rule strong,
.special-rule strong,
.captured-rule strong,
.victory-rule strong,
.promotion-rule strong,
.status-rule strong {
    color: #2c3e50;
}

/* スクロールバーのスタイリング */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}