/* ========================================
   Golf Solitär - CSS Styling
   7-column layout optimization with responsive mobile support
   ======================================== */

/* Golf-specific CSS Variables - Mobile-First Responsive Design */
:root {
    /* 动态计算可用高度 - 使用 unified-header 的高度变量 */
    --golf-header-height: var(--header-height, 48px);
    --available-height: calc(100vh - var(--golf-header-height));
    
    /* Golf 7列布局间距 */
    --golf-spacing: 0.8vw;
    
    /* 计算纸牌尺寸 - 基于宽度和高度的双重约束 */
    /* 宽度约束：7列卡牌 + 间距 */
    --golf-card-width-by-width: calc((100vw - 4vw - 6 * var(--golf-spacing)) / 7);
    
    /* 高度约束：确保7列卡牌（5张重叠）+ 底部2个牌堆完全显示在首屏 */
    /* 卡牌堆高度（5张卡牌重叠约22%） + 底部区域 + 边距 */
    --golf-card-width-by-height: calc((var(--available-height) - 8vh) / 3.6);
    
    /* 选择较小值确保完全适配 */
    --golf-card-width: min(
        var(--golf-card-width-by-width),
        var(--golf-card-width-by-height)
    );
    --golf-card-height: calc(var(--golf-card-width) * 1.4);
    --golf-card-border-radius: calc(var(--golf-card-width) * 0.08);
    
    /* 最小和最大尺寸控制 */
    --golf-min-card-width: 48px;
    --golf-min-card-height: 67px;
    --golf-max-card-width: 180px;
    --golf-max-card-height: 252px;
    
    /* 使用clamp确保卡片在合理范围内 */
    --card-width: clamp(
        var(--golf-min-card-width),
        var(--golf-card-width),
        var(--golf-max-card-width)
    );
    --card-height: clamp(
        var(--golf-min-card-height),
        var(--golf-card-height),
        var(--golf-max-card-height)
    );
}

/* ========================================
   Golf Game Container - Bootstrap Flexbox Layout
   ======================================== */
.golf-game-container {
    max-width: 100%;
    height: var(--available-height); /* 固定高度为可用高度，确保首屏完全显示 */
    max-height: var(--available-height);
    margin: 0 auto;
    padding: 1vh 1vw 2vh; /* 减少底部padding，确保内容在首屏内 */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    position: relative; /* 为 ::after 伪元素提供定位上下文 */
    overflow: hidden; /* 防止内容溢出 */
}

/* ========================================
   Golf Bottom Area - 底部区域：发牌堆 + 废牌堆
   ======================================== */
.golf-bottom-area {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0; /* 防止底部区域被压缩 */
    padding: 1vh 0;
    width: 100%;
}

.golf-piles-wrapper {
    display: flex;
    gap: max(2vw, 1.5rem);
    align-items: center;
    justify-content: center;
}

/* Stock and Waste Containers */
.golf-stock-container,
.golf-waste-container {
    position: relative;
}

/* ========================================
   Golf Stock Pile - 发牌堆
   ======================================== */
.golf-stock {
    width: var(--card-width);
    height: var(--card-height);
    border: none;
    border-radius: var(--golf-card-border-radius);
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    overflow: hidden;
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.2),
        0 2px 6px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.golf-stock::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('../images/cards/Back.svg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 1;
}

.golf-stock #stockCount {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(26, 77, 46, 0.95);
    padding: 0.5rem 1rem;
    border-radius: 50%;
    border: 3px solid white;
    font-size: 1.8rem;
    font-weight: bold;
    color: white;
    min-width: 3.5rem;
    text-align: center;
    z-index: 2;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.golf-stock:hover:not(:disabled) {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.golf-stock:active:not(:disabled) {
    transform: scale(0.98);
}

.golf-stock:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(100%);
}

.golf-stock:disabled #stockCount {
    background: rgba(100, 100, 100, 0.8);
}

/* ========================================
   Golf Waste Pile - 废牌堆
   ======================================== */
.golf-waste {
    width: var(--card-width);
    height: var(--card-height);
    border: 3px dashed rgba(255, 255, 255, 0.5);
    border-radius: var(--golf-card-border-radius);
    position: relative;
    transition: all 0.2s ease;
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.2),
        0 2px 6px rgba(0, 0, 0, 0.15);
    background: rgba(0, 0, 0, 0.15);
}

.golf-waste:empty::after {
    content: '↓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    color: rgba(255, 255, 255, 0.3);
}

.golf-waste .card {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.golf-waste.hint-target {
    border-color: gold;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
    background: rgba(255, 215, 0, 0.15);
}

/* ========================================
   Golf Tableau - 7 columns
   ======================================== */
.golf-tableau {
    display: flex;
    gap: var(--golf-spacing);
    justify-content: center;
    align-items: flex-start;
    flex: 1 1 auto; /* 允许弹性增长和收缩 */
    width: 100%;
    max-width: 100%;
    padding: 0;
    overflow: visible;
    min-height: 0; /* 重要：允许 flex 子项收缩 */
}

.golf-column {
    flex: 0 0 auto;
    width: var(--card-width);
    max-width: var(--card-width);
    position: relative;
    min-height: calc(var(--card-height) * 2); /* 至少显示2张卡牌的高度 */
    max-height: 100%;
}

/* Empty column visual */
.golf-column:empty::after {
    content: '✓';
    position: absolute;
    top: 2rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2.5rem;
    color: rgba(255, 255, 255, 0.2);
}

/* ========================================
   Cards in Golf columns - 参考Spider样式
   ======================================== */
.golf-column .card {
    position: absolute;
    width: var(--card-width);
    height: var(--card-height);
    left: 50%;
    top: 0; /* 初始位置，由JavaScript动态控制 */
    transform: translateX(-50%) translateZ(0);
    cursor: pointer;
    transition: transform 0.15s ease;
    z-index: calc(10 + var(--index, 0));
    /* GPU acceleration for smooth performance */
    will-change: transform;
    backface-visibility: hidden;
    border-radius: var(--golf-card-border-radius);
    /* 参考Pyramid的阴影和边框 */
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.2),
        0 2px 6px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Card stacking positioning is handled by JavaScript for optimal stacking */

/* Waste pile cards use same dimensions */
.golf-waste .card {
    width: var(--card-width);
    height: var(--card-height);
    border-radius: var(--golf-card-border-radius);
}


/* ========================================
   Hint Animations - 参考Pyramid实现
   ======================================== */

.hint-highlight {
    animation: hintPulse 1.5s ease-in-out;
    box-shadow: 0 0 20px 5px #ffd700 !important;
}

.hint-flash {
    animation: hintFlash 1s ease-in-out 2;
}

@keyframes hintPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(255, 215, 0, 0);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 20px 5px rgba(255, 215, 0, 0.8);
    }
}

@keyframes hintFlash {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* ========================================
   响应式设计 - 移动端优先，适配所有设备
   ======================================== */

/* 大屏幕桌面 (>= 1920px) */
@media (min-width: 1920px) {
    :root {
        --golf-spacing: 1.2vw;
        --golf-card-width-by-height: calc((var(--available-height) - 12vh) / 3.4); /* 增加预留空间 */
        --golf-max-card-width: 200px;
        --golf-max-card-height: 280px;
    }
    
    .golf-game-container {
        padding: 1.5vh 2vw 2.5vh; /* 适中的底部间距，确保首屏显示 */
    }
    
    .golf-piles-wrapper {
        gap: max(3vw, 2.5rem);
    }
    
    .golf-bottom-area {
        padding: 1.5vh 0;
        margin-bottom: 0; /* 移除额外的 margin，避免超出视口 */
    }
}

/* 标准桌面/笔记本 (1200px - 1919px) */
@media (min-width: 1200px) and (max-width: 1919px) {
    :root {
        --golf-spacing: 1vw;
        --golf-card-width-by-height: calc((var(--available-height) - 10vh) / 3.5); /* 增加预留空间 */
    }
    
    .golf-game-container {
        padding: 1vh 1.5vw 2vh; /* 减少底部padding，确保首屏显示 */
    }
    
    .golf-piles-wrapper {
        gap: max(2.5vw, 2rem);
    }
    
    .golf-bottom-area {
        padding: 1.5vh 0;
        margin-bottom: 0; /* 移除额外的 margin */
    }
}

/* 平板横屏 (768px - 1199px, landscape) */
@media (min-width: 768px) and (max-width: 1199px) and (orientation: landscape) {
    :root {
        --golf-spacing: 0.8vw;
        --golf-card-width-by-width: calc((100vw - 3vw - 6 * var(--golf-spacing)) / 7);
        --golf-card-width-by-height: calc((var(--available-height) - 6vh) / 3.8);
        --golf-min-card-width: 50px;
        --golf-min-card-height: 70px;
    }
    
    .golf-game-container {
        padding: 0.8vh 1vw 2.5vh; /* 增加底部间距 */
    }
    
    .golf-piles-wrapper {
        gap: max(2vw, 1.5rem);
    }
}

/* 平板竖屏 (768px - 1199px, portrait) */
@media (min-width: 768px) and (max-width: 1199px) and (orientation: portrait) {
    :root {
        --golf-spacing: 1vw;
        --golf-card-width-by-width: calc((100vw - 3vw - 6 * var(--golf-spacing)) / 7);
        --golf-card-width-by-height: calc((var(--available-height) - 15vh) / 3.5);
        --golf-min-card-width: 55px;
        --golf-min-card-height: 77px;
    }
    
    .golf-game-container {
        padding: 1vh 1.5vw 3vh;
        min-height: calc(var(--available-height) - 5vh); /* 留出空间提示下方有内容 */
    }
    
    .golf-piles-wrapper {
        gap: max(2.5vw, 1.8rem);
    }
    
    .golf-stock #stockCount {
        border: 2px solid white;
        font-size: 1.5rem;
        padding: 0.4rem 0.8rem;
    }
}

/* 手机横屏 (<= 767px, landscape) - 最小化header */
@media (max-width: 767px) and (orientation: landscape) {
    :root {
        --golf-spacing: 0.5vw;
        --golf-card-width-by-width: calc((100vw - 2vw - 6 * var(--golf-spacing)) / 7);
        --golf-card-width-by-height: calc((var(--available-height) - 2.5vh) / 5); /* 增大系数到5 */
        --golf-min-card-width: 40px;
        --golf-min-card-height: 56px;
        --golf-max-card-width: 68px;  /* 减小最大值 */
        --golf-max-card-height: 95px;
    }
    
    .golf-game-container {
        padding: 0.2vh 0.4vw 1vh;
    }
    
    .golf-piles-wrapper {
        gap: max(1vw, 0.7rem);
    }
    
    .golf-bottom-area {
        padding: 0.3vh 0;
    }
    
    .golf-stock #stockCount {
        border: 2px solid white;
        font-size: 1rem;
        min-width: 2rem;
        padding: 0.2rem 0.45rem;
    }
}

/* 超窄横屏手机 (≤667px landscape，如iPhone SE) */
@media (max-width: 667px) and (orientation: landscape) {
    :root {
        --golf-spacing: 0.45vw;
        --golf-card-width-by-width: calc((100vw - 1.8vw - 6 * var(--golf-spacing)) / 7);
        --golf-card-width-by-height: calc((var(--available-height) - 2vh) / 5.3);
        --golf-min-card-width: 38px;
        --golf-min-card-height: 53px;
        --golf-max-card-width: 62px;
        --golf-max-card-height: 87px;
    }
    
    .golf-game-container {
        padding: 0.2vh 0.3vw 0.8vh;
    }
    
    .golf-piles-wrapper {
        gap: max(0.8vw, 0.6rem);
    }
    
    .golf-bottom-area {
        padding: 0.2vh 0;
    }
    
    .golf-stock #stockCount {
        font-size: 0.95rem;
        min-width: 1.9rem;
        padding: 0.18rem 0.4rem;
    }
}

/* 手机竖屏 (481px - 767px) */
@media (min-width: 481px) and (max-width: 767px) and (orientation: portrait) {
    :root {
        --golf-spacing: 0.9vw;
        --golf-card-width-by-width: calc((100vw - 2.5vw - 6 * var(--golf-spacing)) / 7);
        --golf-card-width-by-height: calc((var(--available-height) - 12vh) / 3.6);
        --golf-min-card-width: 50px;
        --golf-min-card-height: 70px;
    }
    
    .golf-game-container {
        padding: 1vh 1vw 3vh;
        min-height: calc(var(--available-height) - 5vh);
    }
    
    .golf-piles-wrapper {
        gap: max(2vw, 1.3rem);
    }
    
    .golf-stock #stockCount {
        border: 2px solid white;
        font-size: 1.3rem;
        padding: 0.35rem 0.7rem;
    }
}

/* 小屏手机 (361px - 480px) */
@media (min-width: 361px) and (max-width: 480px) {
    :root {
        --golf-spacing: 0.8vw;
        --golf-card-width-by-width: calc((100vw - 2vw - 6 * var(--golf-spacing)) / 7);
        --golf-card-width-by-height: calc((var(--available-height) - 10vh) / 3.7);
        --golf-min-card-width: 48px;
        --golf-min-card-height: 67px;
    }
    
    .golf-game-container {
        padding: 0.8vh 0.8vw 3vh;
        min-height: calc(var(--available-height) - 5vh);
    }
    
    .golf-piles-wrapper {
        gap: max(1.8vw, 1.2rem);
    }
    
    .golf-stock #stockCount {
        border: 2px solid white;
        font-size: 1.3rem;
        min-width: 2.8rem;
        padding: 0.3rem 0.6rem;
    }
}

/* 超小屏手机 (<= 360px) */
@media (max-width: 360px) {
    :root {
        --golf-spacing: 0.6vw;
        --golf-card-width-by-width: calc((100vw - 1.5vw - 6 * var(--golf-spacing)) / 7);
        --golf-card-width-by-height: calc((var(--available-height) - 10vh) / 3.8);
        --golf-min-card-width: 46px;
        --golf-min-card-height: 64px;
    }
    
    .golf-game-container {
        padding: 0.6vh 0.6vw 3vh;
        min-height: calc(var(--available-height) - 5vh);
    }
    
    .golf-piles-wrapper {
        gap: max(1.5vw, 1rem);
    }
    
    .golf-stock #stockCount {
        border: 2px solid white;
        font-size: 1.1rem;
        min-width: 2.5rem;
        padding: 0.3rem 0.5rem;
    }
}

/* 极宽横屏优化 (aspect-ratio > 2:1) - 如折叠屏展开 */
@media (min-aspect-ratio: 2/1) and (orientation: landscape) {
    :root {
        --golf-card-width-by-height: calc((var(--available-height) - 4vh) / 4.2);
        --golf-spacing: 1.2vw;
    }
    
    .golf-piles-wrapper {
        gap: max(3vw, 2rem);
    }
}

/* 极高竖屏优化 (aspect-ratio < 9:16) - 如超长屏手机 */
@media (max-aspect-ratio: 9/16) and (orientation: portrait) {
    :root {
        --golf-card-width-by-height: calc((var(--available-height) - 15vh) / 3.2);
    }
    
    .golf-game-container {
        padding-bottom: 5vh;
        min-height: calc(var(--available-height) - 8vh);
    }
}

/* ========================================
   移动端触摸优化
   ======================================== */
   
/* 游戏区域 - 允许页面正常滚动 */
.game-board {
    min-height: var(--available-height);
    position: relative;
}

/* 移动端触摸反馈优化 */
@media (hover: none) and (pointer: coarse) {
    .golf-column .card {
        -webkit-tap-highlight-color: rgba(255, 215, 0, 0.2);
        tap-highlight-color: rgba(255, 215, 0, 0.2);
    }
    
    .golf-column .card:active {
        transform: translateX(-50%) scale(0.95) !important;
    }
    
    .golf-stock:active {
        transform: scale(0.95) !important;
    }
    
    /* 增大触摸区域 */
    .golf-column .card {
        cursor: pointer;
        touch-action: manipulation;
    }
    
    .golf-stock {
        touch-action: manipulation;
    }
}

/* 移动端专用：优化滚动体验 */
@media (max-width: 768px) {
    body {
        -webkit-overflow-scrolling: touch; /* iOS 平滑滚动 */
    }
    
    .game-board {
        overflow: visible;
    }
    
    /* 竖屏时添加底部渐变提示，暗示可以向下滚动 */
    @media (orientation: portrait) {
        .golf-game-container::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 40px;
            background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));
            pointer-events: none;
            z-index: 10;
        }
    }
}

/* 横屏模式下最小化 header 高度 */
@media (max-width: 767px) and (orientation: landscape) {
    .unified-header {
        min-height: 50px;
        padding: 0.3rem 0.5rem;
    }
    
    .brand-section {
        font-size: 0.9rem;
    }
    
    .action-btn-compact {
        padding: 0.3rem 0.5rem;
        font-size: 0.85rem;
    }
    
    .stat-compact {
        font-size: 0.85rem;
    }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    .golf-stock-container,
    .unified-header,
    .seo-content-section {
        display: none;
    }
    
    .golf-game-container {
        max-width: 100%;
    }
}

