/* ---------------------------------
   1. Setup
   --------------------------------- */
* {
    box-sizing: border-box; 
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    text-align: center;     
    background: #212121 url('/common/image02.webp') no-repeat center / cover fixed;
    color: #ffffff;            

    display: flex;
    justify-content: center;
    align-items: center;

    min-height: 100dvh;
    overflow-x: hidden; 
}

body .bgm-btn:focus,body .size-btn:focus,body .manual-btn:focus,body .reset-btn:focus {
    outline: none;
    box-shadow: none;
}

.ui-container {
    width: min(1280px, 95vw);
    position: relative;
}

/* ---------------------------------
   2. Title Area
   --------------------------------- */
.title-area h1 {
    font-size: 1.25rem;     
    font-weight: bold;      
    letter-spacing: 2px;    
    padding: 6px 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 24px rgba(0, 0, 0, 0.8), 
                inset 0 0 15px rgba(0, 255, 204, 0.2); 
    border: 1px solid #00bfa5; 
}

/* ---------------------------------
   3. Status Area
   --------------------------------- */
.status-area {
    display: grid;
    grid-template-columns: 1fr auto; 
    align-items: center; 
    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: 6px; 
    align-items: center; 
}

/* ---------------------------------
   4. Button
   --------------------------------- */
.reset-btn, .manual-btn, .size-btn, .bgm-btn {
    width: 100px;           
    padding: 6px 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); 
}

.shuffle-counter-btn.active {
    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);
}

.shuffle-counter-btn.active: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); 
}

.shuffle-counter-btn.disabled {
    background-color: rgba(66, 66, 66, 0.2);
    border: 1px solid #616161;
    color: #757575;
    cursor: not-allowed;
    text-shadow: none;
    box-shadow: none;
    opacity: 0.5;
}

/* ---------------------------------
   5. Field Area (横幅1280px固定・中央配置版)
   --------------------------------- */
.field-area {
    position: relative;
    width: 1280px;
    height: 720px;
    border-radius: 12px;    
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.8); 
    border: 6px solid #37474f; 
    overflow: hidden; 
}

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

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

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

/* Layer 3: core */
.core-layer {
    z-index: 3;
    display: grid;          
    padding: 12px;              
    gap: 4px; 

    grid-template-columns: repeat(var(--cols, 16), minmax(0, 1fr));
    grid-template-rows: repeat(var(--rows, 9), minmax(0, 1fr));

    width: 100%;
    height: 100%;
}

/* ---------------------------------
   6. Cell Area (サイバーマルチカラーネオン)
   --------------------------------- */
.cell {
    display: flex;          
    justify-content: center; 
    align-items: center;    
    border-radius: 6px;     
    aspect-ratio: 1 / 1;
    width: 100%;
    height: 100%;
    font-size: 2.2rem; 
    cursor: pointer;
    user-select: none;
    
    background: radial-gradient(circle at 35% 35%, var(--neon-color) 0%, #000000 100%);
    color: var(--neon-color);
    border: 1px solid var(--neon-color);
    box-shadow: 0 3px 6px rgba(0,0,0,0.5), inset 0 0 10px var(--neon-color);
    
    /* 💡 ズレを滑らかにする設定 */
    transform-origin: center bottom; /* マスの「底面」を基準にふにふにさせる */
    
    /* 💡 👇 【新設】すべての動物を常時ふにふに動かす魔法の1行 */
    /* 2秒かけて1ループ、往復（alternate）し、無限（infinite）に動き続けます */
    animation: funifuni 0.8s infinite alternate ease-in-out;
    
    transition: background-color 0.15s ease, transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.15s ease;
}

/* 💡 👇 【新設】常時ふにふに動くアニメーションの設計図 */
@keyframes funifuni {
    0% {
        /* 縦に少し潰れて、横に少し広がる（スライムのような潰れ） */
        transform: scale(1.02, 0.96);
    }
    100% {
        /* 縦に少し伸びて、横に少し縮む（クラゲのような伸び） */
        transform: scale(0.97, 1.03);
    }
}

/* 💡 👇 【新設】カーソルが乗った時、またはキーボードで選ばれた時の「ぷるんっ！」とした弾力リアクション */
.cell:hover, .cell.focused {
    border-color: #ffffff; 
    box-shadow: 0 0 20px var(--neon-color), inset 0 0 12px var(--neon-color);
    z-index: 10;
    
    /* 常時ふにふにを一度ストップし、選択中専用の「激しいぷるぷるアニメ（purun）」に切り替える */
    animation: purun 0.6s infinite alternate cubic-bezier(0.25, 0.8, 0.25, 1);
}

@keyframes purun {
    0% { transform: scale(1.08, 0.92); }
    100% { transform: scale(0.94, 1.08); }
}

/* ブロックが消去された後の空欄（アニメを完全に止めるガード） */
.cell.empty {
    background: transparent;
    border: 1px dashed rgba(255, 255, 255, 0.015);
    box-shadow: none;
    cursor: default;
    pointer-events: none;
    animation: none; /* 空欄は動かさない */
}

/* ---------------------------------
   7. Layer 4 Card
   --------------------------------- */
.card-layer {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 80%;
    height: 80%;
    z-index: 4;
    padding: 24px;
    background: rgba(0, 20, 10, 0.85);
    border: 2px solid #00ffcc; 
    border-radius: 6px;
    box-shadow: inset 0 0 24px 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;
    letter-spacing: 2px;
    font-family: 'Courier New', monospace;
    text-align: left;
    border-bottom: 2px dashed rgba(0, 255, 204, 0.5); 
    padding-bottom: 8px;
    margin-bottom: 16px;
}

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

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

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

/* ==========================================
   8. 3D Flip Expansion (気まぐれ3D横フリップ拡張)
   ========================================== */

/* 💡 グランドマザー（ core-layer ）に3Dカメラの遠近感を設定 */
.core-layer {
    perspective: 1000px; 
}

/* 💡 奥行きへ横方向にひっくり返る3Dフリップクラス */
.cell.flip-active {
    /* 0.6秒かけて、手前に飛び出しながら【縦軸（Y軸）】を中心に360度くるりんっと横回転 */
    animation: flip-3d-horizontal 0.6s cubic-bezier(0.25, 0.8, 0.25, 1.1) forwards;
}

@keyframes flip-3d-horizontal {
    0% {
        transform: scale(1) rotateY(0deg);
        box-shadow: 0 3px 6px rgba(0,0,0,0.5), inset 0 0 10px var(--neon-color);
    }
    50% {
        /* 👇 ここを根本修正！ rotateX を rotateY に変更し、横フリップ化！ */
        /* 中間地点（180度裏返った瞬間）で、手前にググッと飛び出させます */
        transform: scale(1.15) rotateY(180deg) translateZ(30px);
        
        /* 手前に飛び出た分、影を大きくし、デジタルホログラムっぽく輝かせる */
        box-shadow: 0 15px 30px rgba(0,0,0,0.7), 0 0 25px var(--neon-color);
        filter: brightness(1.4); 
    }
    100% {
        /* 完璧に横方向に360度回転して、元の呼吸リズムへピタッと着地 */
        transform: scale(1) rotateY(360deg);
        box-shadow: 0 3px 6px rgba(0,0,0,0.5), inset 0 0 10px var(--neon-color);
    }
}

/* ==========================================
   8. スマホ専用コンパクトレスポンシブ
   ========================================== */
@media (max-width: 480px) {
    .status-area {
        grid-template-columns: 1fr; /* スマホ時は上下2段にして横幅の窮屈さを回避 */
        text-align: center;
        gap: 6px;
        margin: 8px 0;
    }
    .status-info { text-align: center; padding-left: 0; font-size: 0.75rem; }
    .btn-group { justify-content: center; width: 100%; }
    .title-area h1 { font-size: 0.8rem; padding: 6px 0; }
    .field-area { width: 95vw; border-width: 4px; }
    .core-layer#stage-panel { padding: 4px; gap: 2px; }
    .reset-btn, .manual-btn, .shuffle-counter-btn { font-size: 0.7rem; width: 90px; padding: 6px 0; }
    .cell { font-size: 1.15rem; border-radius: 4px; }
    .title-card { font-size: 0.75rem; margin-bottom: 8px; padding-bottom: 4px; }
    .line-card { font-size: 0.6rem; margin: 6px 0; line-height: 1.4; }
    .powered-card { font-size: 0.5rem; margin-top: 12px; }
}