/* css/memory-game.css */
/* 記憶卡牌遊戲 - 圖片風格（羊皮紙/米黃色調） */

/* 遊戲主容器 - 填滿父容器 (#game-wrapper) */
.memory-game-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #e5d7c3;  /* ✅ 羊皮紙底色 */
    overflow: hidden;
    z-index: 1000;
}

/* 遊戲舞台 - 填滿容器 */
.memory-stage {
    position: relative;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background: #f1e4d0;  /* ✅ 米黃色背景 */
}

/* 遊戲主面板 - 相對於舞台，使用 flex 佈局 */
.memory-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 92%;
    max-width: 1200px;
    height: 85%;
    max-height: 85%;
    background: rgba(253, 246, 235, 0.85);  /* ✅ 通透淡米色 */
    border: 3px solid #e67e22;
    border-radius: 20px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    backdrop-filter: blur(5px);
    overflow: hidden;
}

/* HUD 區域 - 頂部資訊欄 */
.memory-hud {
    position: relative;
    width: 100%;
    text-align: center;
    z-index: 110;
    margin-bottom: 8px;
    flex-shrink: 0;
}

/* 頂部資訊行 - 使用 Grid 固定三欄，等比例分配 */
.memory-top-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    padding: 5px 16px;
    background: rgba(230, 215, 195, 0.6);  /* ✅ 半透明米棕色 */
    border-radius: 40px;
    backdrop-filter: blur(5px);
}

/* 左側：配對資訊 - 靠左對齊 */
.memory-info {
    display: flex;
    justify-content: flex-start;
    gap: clamp(10px, 2vw, 20px);
}

.memory-info-item {
    color: #5c4a2a;  /* ✅ 深咖啡色文字 */
    font-size: clamp(14px, 2.5vh, 18px);
    white-space: nowrap;
}

.memory-info-item span {
    font-weight: bold;
    color: #e67e22;  /* ✅ 維持橙色強調 */
}

/* 中間：重點區域 - 永遠置中，不被壓縮 */
.memory-center-area {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* 計時器 - 放大醒目 */
.memory-timer-large {
    display: flex;
    align-items: baseline;
    gap: 6px;
    background: rgba(240, 230, 210, 0.7);  /* ✅ 米棕色调背景 */
    padding: 8px 24px;
    border-radius: 60px;
    border: 1px solid rgba(231, 126, 34, 0.5);
}

.memory-timer-label {
    color: #5c4a2a;  /* ✅ 深咖啡色 */
    font-size: clamp(16px, 3vh, 22px);
    font-weight: normal;
}

#memory-timer {
    color: #e74c3c;
    font-size: clamp(36px, 7vh, 56px);
    font-weight: bold;
    font-family: monospace;
    letter-spacing: 3px;
    text-shadow: 0 0 5px rgba(231, 76, 60, 0.5);
}

/* 右側：狀態文字 - 靠右對齊，自動縮放 */
.memory-status {
    color: #e67e22;  /* ✅ 橙色 */
    font-size: clamp(11px, 2.2vh, 16px);
    font-weight: bold;
    padding: 4px 12px;
    background: rgba(230, 215, 195, 0.6);  /* ✅ 半透明米棕色 */
    border-radius: 30px;
    white-space: nowrap;
    justify-self: end;
}

/* 警告燈區域 - 放大 */
.memory-strikes {
    display: flex;
    gap: clamp(12px, 2.5vw, 20px);
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: rgba(240, 230, 210, 0.5);  /* ✅ 可選：燈光區域背景 */
    padding: 5px 15px;
    border-radius: 40px;
}

.strike-light {
    width: clamp(24px, 5vh, 40px);
    height: clamp(24px, 5vh, 40px);
    border-radius: 50%;
    background: #c0a080;  /* ✅ 熄滅時為淺棕色 */
    box-shadow: inset 0 0 4px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

/* 紅燈樣式 */
.strike-light.red.active {
    background: #ff3333;
    box-shadow: 0 0 16px #ff0000, inset 0 0 4px rgba(255,255,255,0.5);
    animation: strikePulse 0.3s ease-out;
}

/* 綠燈樣式 */
.strike-light.green.active {
    background: #00ff88;
    box-shadow: 0 0 16px #00ff88, inset 0 0 4px rgba(255,255,255,0.5);
    animation: strikePulse 0.3s ease-out;
}

@keyframes strikePulse {
    0% { transform: scale(1); opacity: 0.7; }
    50% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* ========== 扣秒特效（紅燈） ========== */
.penalty-flash {
    animation: penaltyShake 0.5s ease-out;
}

@keyframes penaltyShake {
    0%, 100% { transform: scale(1); color: #e74c3c; }
    25% { transform: scale(1.5) translateX(-3px); color: #ff0000; }
    75% { transform: scale(1.5) translateX(3px); color: #ff0000; }
}

.penalty-panel-flash {
    animation: panelRedFlash 0.3s ease-out;
}

@keyframes panelRedFlash {
    0% { box-shadow: 0 0 0 0 rgba(255,0,0,0); border-color: #e67e22; }
    50% { box-shadow: 0 0 20px 5px rgba(255,0,0,0.8); border-color: #ff0000; }
    100% { box-shadow: 0 0 0 0 rgba(255,0,0,0); border-color: #e67e22; }
}

/* ========== 加分特效（綠燈） ========== */
.bonus-flash {
    animation: bonusShake 0.5s ease-out;
}

@keyframes bonusShake {
    0%, 100% { transform: scale(1); color: #00ff88; }
    25% { transform: scale(1.5) translateX(3px); color: #00ffaa; }
    75% { transform: scale(1.5) translateX(-3px); color: #00ffaa; }
}

.bonus-panel-flash {
    animation: panelGreenFlash 0.3s ease-out;
}

@keyframes panelGreenFlash {
    0% { box-shadow: 0 0 0 0 rgba(0,255,0,0); border-color: #e67e22; }
    50% { box-shadow: 0 0 20px 5px rgba(0,255,136,0.8); border-color: #00ff88; }
    100% { box-shadow: 0 0 0 0 rgba(0,255,0,0); border-color: #e67e22; }
}

@keyframes penaltyFloat {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(0.8); }
    50% { opacity: 1; transform: translate(-50%, -70%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -100%) scale(0.8); }
}

@keyframes bonusFloat {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(0.8); }
    50% { opacity: 1; transform: translate(-50%, -70%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -100%) scale(0.8); }
}

/* 遊戲盤面區域 */
.memory-grid-area {
    width: 100%;
    flex: 1;
    overflow: visible;
    margin: 5px 0;
    padding: 5px;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 遊戲盤面 - 寬度自動，讓卡片大小決定網格寬度 */
.memory-grid {
    display: grid;
    gap: 10px;
    justify-content: center;
    align-items: center;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    margin: 0 auto;
}

/* 動態列數 - 使用 auto 讓卡片寬度決定列寬 */
.memory-grid[data-cols="2"] { grid-template-columns: repeat(2, auto); }
.memory-grid[data-cols="3"] { grid-template-columns: repeat(3, auto); }
.memory-grid[data-cols="4"] { grid-template-columns: repeat(4, auto); }
.memory-grid[data-cols="5"] { grid-template-columns: repeat(5, auto); }
.memory-grid[data-cols="6"] { grid-template-columns: repeat(6, auto); }
.memory-grid[data-cols="7"] { grid-template-columns: repeat(7, auto); }
.memory-grid[data-cols="8"] { grid-template-columns: repeat(8, auto); }

/* 卡片 - 不設定寬高，由 JS 動態設定 */
.memory-card {
    aspect-ratio: 5 / 4;
    cursor: pointer;
    perspective: 800px;
    transform: scale(0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.memory-card.is-visible {
    transform: scale(1);
}

.memory-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.5s;
    transform-style: preserve-3d;
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.memory-card.is-flipped .memory-card-inner {
    transform: rotateY(180deg);
}

.memory-card.matched {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease-out;
}

/* 卡片面 */
.memory-card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    border: 2px solid #e67e22;
    box-sizing: border-box;
}

/* 背面 - 圖片風格 */
.memory-card-back {
    background: linear-gradient(135deg, #d4a574, #c49464);  /* ✅ 溫暖木質色調 */
    background-image: url('../assets/images/memory/card-back.jpg');
    background-size: cover;
    background-position: center;
}

/* 正面 */
.memory-card-front {
    background: linear-gradient(145deg, #fff8f0, #f0e4d0);  /* ✅ 暖白到米色 */
    transform: rotateY(180deg);
    font-size: clamp(24px, 5vh, 40px);
}

/* 正面圖片模式 */
.memory-card-front img {
    max-width: 70%;
    max-height: 70%;
    object-fit: contain;
}

/* 提示文字 - 固定在底部 */
.memory-hint {
    position: absolute;
    bottom: 2%;
    left: 0;
    width: 100%;
    text-align: center;
    color: #8b7355;  /* ✅ 深棕色 */
    font-size: clamp(8px, 1.5vh, 11px);
    z-index: 110;
    pointer-events: none;
    background: rgba(230, 215, 195, 0.4);
    padding: 3px;
}

/* 成功文字動畫 */
.memory-success-text {
    position: absolute;
    color: #ffd700;
    font-size: clamp(16px, 2vw, 32px);
    font-weight: bold;
    text-shadow: 0 0 10px #ff6600;
    z-index: 50;
    pointer-events: none;
    white-space: nowrap;
    animation: memorySuccessFloat 0.5s ease-out forwards;
}

@keyframes memorySuccessFloat {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-50px) scale(1.5); }
}

/* 分數飄浮動畫 */
@keyframes memoryScoreFloat {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(0.8); }
    50% { opacity: 1; transform: translate(-50%, -70%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -100%) scale(0.8); }
}

/* ========== 橫向模式（預設） ========== */
@media (orientation: landscape) {
    .memory-panel {
        width: 90%;
        height: 88%;
    }
    
    .memory-grid[data-rows="3"] {
        gap: min(8px, 1.2vh);
    }
}

/* 手機橫向特殊調整 */
@media (max-width: 920px) and (orientation: landscape) {
    .memory-panel {
        width: 94%;
        height: 88%;
        padding: 6px;
    }
    
    .memory-top-bar {
        gap: 8px;
        padding: 4px 12px;
    }
    
    .memory-center-area {
        gap: clamp(15px, 3vw, 25px);
    }
    
    .memory-info-item {
        font-size: clamp(10px, 2vh, 14px);
    }
    
    .memory-timer-large {
        padding: 5px 18px;
    }
    
    .memory-timer-label {
        font-size: clamp(14px, 2.5vh, 18px);
    }
    
    #memory-timer {
        font-size: clamp(28px, 5.5vh, 42px);
        letter-spacing: 2px;
    }
    
    .memory-strikes {
        gap: clamp(8px, 2vw, 15px);
    }
    
    .strike-light {
        width: clamp(18px, 3.5vh, 28px);
        height: clamp(18px, 3.5vh, 28px);
    }
    
    .memory-status {
        font-size: clamp(9px, 1.8vh, 12px);
        padding: 3px 10px;
    }
    
    .memory-grid {
        gap: min(6px, 1vh);
    }
    
    .memory-card-front {
        font-size: clamp(18px, 3.5vh, 28px);
    }
    
    .memory-card-back::before {
        font-size: clamp(18px, 3.5vh, 28px);
    }
}

@media (max-width: 480px) and (orientation: landscape) {
    .memory-panel {
        width: 96%;
        height: 90%;
        padding: 4px;
    }
    
    .memory-top-bar {
        gap: 6px;
        padding: 3px 10px;
    }
    
    .memory-center-area {
        gap: clamp(10px, 2vw, 20px);
    }
    
    .memory-info-item {
        font-size: clamp(8px, 1.8vh, 12px);
    }
    
    .memory-timer-large {
        padding: 4px 12px;
    }
    
    .memory-timer-label {
        font-size: clamp(12px, 2vh, 15px);
    }
    
    #memory-timer {
        font-size: clamp(22px, 4.5vh, 34px);
        letter-spacing: 2px;
    }
    
    .memory-strikes {
        gap: clamp(6px, 1.5vw, 12px);
    }
    
    .strike-light {
        width: clamp(14px, 2.5vh, 22px);
        height: clamp(14px, 2.5vh, 22px);
    }
    
    .memory-status {
        font-size: clamp(8px, 1.5vh, 11px);
        padding: 2px 8px;
    }
    
    .memory-grid {
        gap: min(4px, 0.8vh);
    }
    
    .memory-card-front {
        font-size: clamp(16px, 3vh, 24px);
    }
    
    .memory-card-back::before {
        font-size: clamp(16px, 3vh, 24px);
    }
}

/* 手機直立提示 */
@media (orientation: portrait) and (max-width: 1024px) {
    .memory-game-container::before {
        content: "請將手機轉為橫向以獲得最佳體驗";
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: rgba(0, 0, 0, 0.9);
        color: white;
        padding: 15px 25px;
        border-radius: 10px;
        font-size: 16px;
        z-index: 9999;
        text-align: center;
        white-space: nowrap;
        border: 2px solid #e67e22;
    }
    
    .memory-stage {
        opacity: 0.3;
        pointer-events: none;
    }
}