/* ==========================================================================
   圍住神經貓 - 遊戲樣式與六角偏移網格
   ========================================================================== */

:root {
    --bg-dark: #fcf8f2;
    --panel-bg: rgba(255, 255, 255, 0.85);
    --border-color: rgba(0, 0, 0, 0.08);
    --primary-color: #f97316;
    --primary-hover: #ea580c;
    --text-light: #1f2937;
    --text-muted: #6b7280;
    
    /* 圓點狀態顏色 */
    --circle-empty: transparent;
    --circle-empty-hover: rgba(0, 0, 0, 0.04);
    --circle-wall: transparent;
    --circle-wall-shadow: none;
    --circle-cat: transparent;
    --circle-cat-shadow: none;
}

/* 全域重置與基礎樣式 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    font-family: 'Outfit', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
}

/* 炫光背景 - 淺色經典版不需要 */
.bg-gradient {
    display: none;
}

.bg-glow {
    display: none;
}

/* 主容器 */
.app-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 93px);
    gap: 20px;
}

/* 遊戲標頭 */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.game-header .logo {
    font-size: 1.8rem;
    font-weight: 900;
    background: var(--primary-color);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 1.5px;
    text-shadow: 0 2px 10px rgba(249, 115, 22, 0.15);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.03);
    color: var(--text-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.icon-btn span {
    font-size: 1.25rem;
}

/* 遊戲版面排版 */
.game-layout {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 20px;
    align-items: start;
    flex: 1;
}

/* 面板樣式 */
.panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

/* 數據看板 */
.info-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stats-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat-box {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.stat-title {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.stat-number {
    font-size: 2rem;
    font-weight: 900;
    color: var(--primary-color);
    font-family: 'Share Tech Mono', monospace;
    letter-spacing: 1px;
}

/* 遊戲主要網格區域 */
.main-board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* 遊戲網格容器與覆蓋層 */
.board-wrapper {
    position: relative;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1 / 1;
    background: #eae5d8;
    border: 2px solid rgba(0, 0, 0, 0.05);
    border-radius: 24px;
    padding: 24px 16px 24px 8px; /* 為了偏移平衡，稍微做 padding 修正 */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

/* 粒子特效 Canvas */
.effect-canvas {
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none;
}

/* 11x11 Grid 容器 */
.game-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

/* 六角錯開行 */
.grid-row {
    display: flex;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

/* 奇數行偏移半格 */
.grid-row.offset {
    margin-left: 20px; /* 大約一個圓圈直徑的一半加上 gap 的一半 */
}

/* 圓圈格子 */
.grid-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease-out;
    position: relative;
    user-select: none;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

/* 圓圈懸停 */
.grid-circle.empty:hover {
    background-image: url('assets/pot2.png');
    transform: scale(1.15);
}

/* 空地狀態 */
.grid-circle.empty {
    background-image: url('assets/pot1.png');
}

/* 牆壁（障礙物）狀態 */
.grid-circle.wall {
    background-image: url('assets/pot2.png');
    cursor: default;
    animation: wall-bounce 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes wall-bounce {
    0% { transform: scale(0.6); }
    100% { transform: scale(1); }
}

/* 貓咪所在的圓圈狀態 */
.grid-circle.cat {
    background-image: url('assets/pot1.png');
    cursor: default;
    z-index: 3;
    overflow: visible; /* 允許貓咪圖片超出圓圈顯示 */
}

/* 原生神經貓 Spritesheet 容器 */
.cat-sprite {
    position: absolute;
    width: 61px;
    height: 93px;
    background-repeat: no-repeat;
    pointer-events: none;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    transform-origin: bottom center;
}

/* 貓咪移動動畫樣式 */
.grid-circle.cat-moving .cat-sprite {
    animation: cat-move 0.25s ease-in-out forwards;
}

@keyframes cat-move {
    0% { transform: translateX(-50%) scale(1.15); }
    100% { transform: translateX(-50%) scale(1); }
}

/* 覆蓋層 - 開始、暫停、結束（極度透明、移去模糊濾鏡，保證玩家能看見棋盤與貓咪動態） */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(252, 248, 242, 0.12); /* 大幅調低透明度 */
    backdrop-filter: none; /* 移除模糊 */
    -webkit-backdrop-filter: none;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
    transition: opacity 0.35s ease;
    color: var(--text-light);
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* 遊戲結束專用覆蓋層 - 結算卡片置底防止遮擋貓咪 */
.overlay.gameover {
    align-items: flex-end; /* 置底 */
    padding-bottom: 24px;
}

/* 覆蓋層中央小卡片容器樣式 */
.overlay-content {
    max-width: 320px;
    width: 100%;
    animation: scale-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
    border-radius: 16px;
    padding: 24px;
}

/* 遊戲結束專用卡片微調 */
.overlay.gameover .overlay-content {
    padding: 16px; /* 結算卡片更為緊湊 */
}

@keyframes scale-up {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.overlay h2 {
    font-size: 2rem;
    font-weight: 900;
    margin-bottom: 6px;
    background: var(--primary-color);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.overlay .subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 18px;
}

/* 操作說明指南 */
.controls-guide {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 20px;
    text-align: left;
}

.controls-guide h3 {
    font-size: 0.85rem;
    color: #ef4444;
    margin-bottom: 8px;
    font-weight: 800;
}

.controls-guide ul {
    list-style-type: none;
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.controls-guide li {
    position: relative;
    padding-left: 12px;
}

.controls-guide li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: #ef4444;
}

/* 按鈕樣式 */
.primary-btn {
    width: 100%;
    padding: 12px 20px;
    border-radius: 12px;
    border: 0;
    background: linear-gradient(135deg, #f87171, #ef4444);
    color: #fff;
    font-weight: 900;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
    transition: all 0.2s ease;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.6);
}

.primary-btn.compact {
    padding: 8px 16px;
    font-size: 0.85rem;
}

/* 遊戲結束統計 */
.final-stats {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
}

.gameover-title.win {
    background: linear-gradient(135deg, #fff, #fbbf24) !important;
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
}

/* 排行榜輸入面板 */
.new-record-panel {
    background: rgba(249, 115, 22, 0.05);
    border: 1px solid rgba(249, 115, 22, 0.15);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 16px;
}

.new-record-panel.hidden {
    display: none;
}

.glow-text {
    font-weight: 800;
    color: var(--primary-color);
    font-size: 0.9rem;
    margin-bottom: 8px;
    animation: text-glow 1s infinite alternate;
}

@keyframes text-glow {
    from { text-shadow: 0 0 4px rgba(249, 115, 22, 0.2); }
    to { text-shadow: 0 0 10px rgba(249, 115, 22, 0.5); }
}

#nickname-input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.7);
    color: var(--text-light);
    font-family: inherit;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 8px;
}

#nickname-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 8px rgba(249, 115, 22, 0.25);
}

/* 遊戲指南與 SEO 文字 */
.game-instruction {
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
    background: rgba(0, 0, 0, 0.01);
    border: 1px solid rgba(0, 0, 0, 0.03);
    padding: 12px;
    border-radius: 12px;
}

.game-instruction strong {
    color: var(--primary-color);
}

.seo-description {
    display: none !important;
}

/* ==========================================================================
   響應式排版 (Responsive Layout)
   ========================================================================== */

@media (max-width: 680px) {
    .game-layout {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .info-panel {
        order: 2;
    }
    
    .main-board-container {
        order: 1;
    }
    
    .info-panel .stats-section {
        flex-direction: row;
        justify-content: center;
    }
    
    .stat-box {
        flex: 1;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 12px 8px;
    }
    
    .game-header .logo {
        font-size: 1.4rem;
    }
    
    .board-wrapper {
        border-radius: 16px;
        padding: 20px 14px 20px 6px;
    }
    
    .game-grid {
        gap: 6px;
    }
    
    .grid-row {
        gap: 6px;
    }
    
    /* 微調手機端的偏移距離 */
    .grid-row.offset {
        margin-left: 15px; /* 30px 格子的一半 */
    }
    
    .grid-circle {
        width: 30px;
        height: 30px;
        font-size: 1rem;
    }
    
    /* 手機端貓咪自適應縮放，防止變小 */
    .cat-sprite {
        transform: translateX(-50%) scale(0.92);
        bottom: 10px;
    }
    
    /* 手機端移動動畫修正 */
    .grid-circle.cat-moving .cat-sprite {
        animation: cat-move-mobile 0.25s ease-in-out forwards;
    }
    
    @keyframes cat-move-mobile {
        0% { transform: translateX(-50%) scale(1.05); }
        100% { transform: translateX(-50%) scale(0.92); }
    }
    
    .stat-number {
        font-size: 1.6rem;
    }
    
    .overlay h2 {
        font-size: 1.5rem;
    }
    
    .overlay .subtitle {
        font-size: 0.8rem;
        margin-bottom: 12px;
    }
    
    .controls-guide {
        padding: 8px;
        margin-bottom: 12px;
    }
}
