/* ==========================================
   1. 全体リセット & 画面固定 (dvh中央寄せ)
   ========================================== */
* {
    box-sizing: border-box; 
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    text-align: center;     
    background-color: #212121;
    color: #ffffff;            
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100dvh; 
}

.ui-container {
    width: min(720px, 95vw);
    margin: 0 auto;
    position: relative; 
    padding: 10px 0; 
}

/* ==========================================
   2. タイトルエリア (緑ネオン管仕様)
   ========================================== */
.title-area h1 {
    font-size: 1.25rem;     
    font-weight: bold;      
    letter-spacing: 2px;    
    padding: 8px 0;        
    background-color: rgba(0, 32, 16, 0.85); 
    color: #00ffcc; 
    border-radius: 9999px;    
    text-shadow: 0 0 10px rgba(0, 255, 204, 0.6); 
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.8), 
                inset 0 0 15px rgba(0, 255, 204, 0.2); 
    border: 1px solid #00bfa5; 
}

/* ==========================================
   3. 左右2分割メーターUI (PC・スマホ共通整列)
   ========================================== */
.status-area {
    display: grid;
    grid-template-columns: 1fr auto; 
    align-items: center; 
    gap: 12px;
    margin: 12px 0;
}

.status-info {
    font-size: clamp(0.85rem, 3.5vw, 1rem);
    font-weight: bold;
    color: #e0e0e0;
    text-align: left; 
    padding-left: 4px;
    white-space: pre-line;  
}

.btn-group {
    display: flex;
    gap: 8px; 
    align-items: center; 
}

/* ==========================================
   4. フィールドエリア & 4つの絶対配置レイヤー
   ========================================== */
.field-area {
    position: relative;
    width: min(720px, 90vw);            
    aspect-ratio: 1 / 1; 
    margin: 0 auto;
    border-radius: 14px;    
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.8); 
    border: 6px solid #37474f; 
    overflow: hidden; 
}

.bg-layer, .fx-layer, .piece-layer, .card-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.bg-layer {
    z-index: 1;
    background-color: #212121; 
}

.fx-layer {
    z-index: 2;
    pointer-events: none;
}

.piece-layer {
    z-index: 3;
    display: grid;          
    grid-template-rows: repeat(9, 1fr);
    grid-template-columns: repeat(9, 1fr); 
    padding: 6px;              
    gap: 0px; 
}

/* ==========================================
   5. マス目 (セル) & ガイド (ネオン点灯)
   ========================================== */
.cell {
    position: relative;
    box-sizing: border-box;
    border: 1px solid #212121; 
    display: flex;
    justify-content: center;
    align-items: center;
}

.cell:hover { 
    background-color: rgba(0, 255, 204, 0.15); 
}

/* 選択状態(1)のハイライト */
.cell.selected, .stock-slot.selected {
    background-color: rgba(0, 255, 204, 0.35) !important;
    box-shadow: inset 0 0 10px rgba(0, 255, 204, 0.5);
}

/* ===================================================
   6. 将棋駒デザイン (あの台形を完全表現)
   =================================================== */
.shogi-piece {
    width: 80%;             
    height: 85%;            
    position: relative;     
    z-index: 10;            
    background: radial-gradient(circle at 50% 30%, #4db6ac 0%, #00796b 70%, #004d40 100%);
    color: #ffffff;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.9rem, 4vw, 1.3rem);
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    
    /* clip-pathで上すぼみの台形を作る */
    clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
    
    padding-top: 6px; 
    box-sizing: border-box;
    cursor: pointer;
    transition: transform 0.15s ease;
}

/* AI(後手)の駒は下を向くように反転 */
.shogi-piece.ai-piece {
    transform: rotate(180deg);
    background: radial-gradient(circle at 50% 30%, #ff8a80 0%, #d32f2f 70%, #b71c1c 100%);
}

/* ===================================================
   7. 操作ボタン
   =================================================== */
.reset-btn, .manual-btn, .size-btn, .bgm-btn {
    width: 110px;           
    padding: 8px 0;        
    font-size: 0.95rem;        
    font-weight: bold;      
    border: none; 
    border-radius: 9999px;    
    cursor: pointer;        
    display: inline-block;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s, transform 0.1s, box-shadow 0.2s, text-shadow 0.2s;
}

.reset-btn:active, .manual-btn:active, .size-btn:active, .bgm-btn:active {
    transform: scale(0.95);
}

.reset-btn { 
    background-color: rgba(211, 47, 47, 0.2); 
    border: 1px solid #ff8a80; 
    color: #ff8a80; 
    text-shadow: 0 0 5px rgba(255, 138, 128, 0.6);
    box-shadow: 0 0 10px rgba(255, 138, 128, 0.3), inset 0 0 5px rgba(255, 138, 128, 0.2);
}
.reset-btn:hover { 
    background-color: #b71c1c; 
    color: #ffffff;
    box-shadow: 0 0 20px rgba(255, 138, 128, 0.8), 0 0 30px rgba(255, 138, 128, 0.4); 
}

.manual-btn {
    background-color: rgba(26, 115, 232, 0.2); 
    border: 1px solid #4fc3f7; 
    color: #4fc3f7; 
    text-shadow: 0 0 5px rgba(79, 195, 247, 0.6);
    box-shadow: 0 0 10px rgba(79, 195, 247, 0.3), inset 0 0 5px rgba(79, 195, 247, 0.2);
}
.manual-btn:hover {
    background-color: #1557b0; 
    color: #ffffff;
    box-shadow: 0 0 20px rgba(79, 195, 247, 0.8), 0 0 30px rgba(79, 195, 247, 0.4); 
}

.size-btn {
    background-color: rgba(0, 191, 165, 0.15); 
    border: 1px solid #00ffcc; 
    color: #00ffcc; 
    text-shadow: 0 0 5px rgba(0, 255, 204, 0.6);
    box-shadow: 0 0 10px rgba(0, 255, 204, 0.3), inset 0 0 5px rgba(0, 255, 204, 0.2);
}
.size-btn:hover {
    background-color: #00796b; 
    color: #ffffff;
    box-shadow: 0 0 20px rgba(0, 255, 204, 0.8), 0 0 30px rgba(0, 255, 204, 0.4); 
}

.bgm-btn {
    background-color: rgba(255, 145, 0, 0.2); 
    border: 1px solid #ff9100; 
    color: #ff9100; 
    text-shadow: 0 0 5px rgba(255, 145, 0, 0.6);
    box-shadow: 0 0 10px rgba(255, 145, 0, 0.3), inset 0 0 5px rgba(255, 145, 0, 0.2);
}
.bgm-btn:hover {
    background-color: rgba(255, 145, 0, 0.8); 
    border: 1px solid #ff9100;
    color: #ffffff; 
    box-shadow: 0 0 20px rgba(255, 145, 0, 0.8), 0 0 30px rgba(255, 145, 0, 0.4); 
}

/* ===================================================
   8. ストックスタンド (基本ここしか触るな)
   =================================================== */
/* プレイヤーとAIそれぞれのスタンドを盤面の横幅に合わせる */
.stock-stand-player,
.stock-stand-ai {
    display: flex;
    justify-content: flex-start; /* 左詰めで綺麗に整列 */
    align-items: center;
    width: 100%;                 /* 盤面（レイヤー3）の横幅に100%連動 */
    box-sizing: border-box;
    gap: 2px;                    /* 20個並べた時の適切な隙間 */
    padding: 4px 0;
}

/* 20個並んでもはみ出さず、均等に縮小・フィットする設定 */
.stock-slot {
    flex: 1;                     /* 20枠が自動で同じ幅に伸縮 */
    aspect-ratio: 1 / 1;         /* 綺麗な正方形の枠を維持 */
    min-width: 0;                /* 幅のブレを強制防止 */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================
   9. 多目的カードレイヤー
   ========================================== */
.card-layer {
    position: absolute;
    z-index: 4;
    top: 50%;
    left: 50%;
    width: 80%;
    height: 80%;
    background: rgba(0, 20, 10, 0.75); 
    border: 2px solid #00ffcc; 
    padding: 24px; 
    border-radius: 8px;
    box-shadow: inset 0 0 25px rgba(0, 255, 204, 0.4), 0 0 30px rgba(0, 255, 204, 0.3);
    opacity: 0;
    pointer-events: none; 
    transform: translate(-50%, -50%) scale(0);    
    transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.34, 1.8, 0.64, 1); 
}

.card-layer.active {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.title-card {
    font-size: 1.1rem;
    font-weight: bold;
    color: #00ffcc;
    border-bottom: 2px dashed rgba(0, 255, 204, 0.5); 
    padding-bottom: 8px;
    margin-bottom: 16px;
    letter-spacing: 2px;
    font-family: 'Courier New', monospace;
    text-align: left;
}

.line-card {
    font-size: 0.85rem; 
    color: #a7ffeb;
    margin: 12px 0; 
    font-family: 'Courier New', Courier, monospace;
    line-height: 1.5;
    text-align: left;
}

.powered-card {
    font-size: 0.65rem;
    font-family: 'Courier New', monospace;
    letter-spacing: 3px;
    color: rgba(0, 255, 204, 0.4); 
    text-align: right;
    margin-top: 24px;
    text-shadow: 0 0 4px rgba(0, 255, 204, 0.3);
    text-transform: uppercase; 
}

.scanline-card {
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%);
    background-size: 100% 4px;
    border-radius: 10px;
    pointer-events: none;
    opacity: 0.3;
}

/* ==========================================
   10. スマホ専用レスポンシブ
   ========================================== */
@media (max-width: 480px) {
    .status-area { margin: 8px 0; }
    .title-area h1 { font-size: 0.625rem; padding: 4px 0; }
    .field-area { width: 95vw; }

    .reset-btn, .manual-btn, .size-btn, .bgm-btn {
        font-size: 0.5rem;
        width: 55px;
        min-width: 55px;
        padding: 5px 0;
    }

    .status-info { font-size: 0.5rem; }
    .title-card { font-size: 0.55rem; border-bottom-width: 1px; margin-bottom: 8px; padding-bottom: 4px; }
    .line-card { font-size: 0.425rem; margin: 6px 0; line-height: 1.3; }
    .powered-card { font-size: 0.4rem; margin-top: 12px; }
    
    .stock-stand-player, .stock-stand-ai { min-height: 42px; }
    .stock-slot { width: 32px; height: 32px; }
}