/* ========================================
   Yukon Solitär - CSS Styling
   7-column tableau + 4 foundation piles
   Responsive design for all devices
   ======================================== */

/* Yukon-specific CSS Variables - Mobile-First Responsive Design */
:root {
    /* 动态计算可用高度 */
    --yukon-header-height: var(--header-height, 48px);
    --available-height: calc(100vh - var(--yukon-header-height));
    
    /* Yukon 布局间距 */
    --yukon-spacing: 0.8vw;
    --yukon-foundation-spacing: 1.5vw;
    
    /* 计算纸牌尺寸 - 基于宽度和高度的双重约束 */
    /* 宽度约束：7列卡牌 + 间距 */
    --yukon-card-width-by-width: calc((100vw - 4vw - 6 * var(--yukon-spacing)) / 7);
    
    /* 高度约束：Foundation区域 + Tableau区域（长列约12-15张牌） */
    /* Foundation: 1卡高 + Tableau: 需要容纳长列 + 间距 */
    --yukon-card-width-by-height: calc((var(--available-height) - 10vh) / 5);
    
    /* 选择较小值确保完全适配 */
    --yukon-card-width: min(
        var(--yukon-card-width-by-width),
        var(--yukon-card-width-by-height)
    );
    --yukon-card-height: calc(var(--yukon-card-width) * 1.4);
    --yukon-card-border-radius: calc(var(--yukon-card-width) * 0.08);
    
    /* 卡牌重叠距离 - Tableau中卡片的垂直间距 */
    --yukon-card-overlap: calc(var(--yukon-card-height) * 0.25); /* 25% 重叠 */
    
    /* 最小和最大尺寸控制 */
    --yukon-min-card-width: 48px;
    --yukon-min-card-height: 67px;
    --yukon-max-card-width: 160px; /* 增大桌面端纸牌尺寸 */
    --yukon-max-card-height: 224px;
    
    /* 使用clamp确保卡片在合理范围内 */
    --card-width: clamp(
        var(--yukon-min-card-width),
        var(--yukon-card-width),
        var(--yukon-max-card-width)
    );
    --card-height: clamp(
        var(--yukon-min-card-height),
        var(--yukon-card-height),
        var(--yukon-max-card-height)
    );
}

/* ========================================
   Yukon Game Container - Main Layout
   ======================================== */
.yukon-game-container {
    max-width: 100%;
    height: var(--available-height);
    max-height: var(--available-height);
    margin: 0 auto;
    padding: 1.5vh 1vw 2vh;
    display: flex;
    flex-direction: column;
    gap: 2vh;
    align-items: center;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

/* ========================================
   Foundation Area - 4 foundation piles at top
   ======================================== */
.yukon-foundation-area {
    display: flex;
    gap: var(--yukon-foundation-spacing);
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    width: 100%;
    padding: 0;
}

.foundation-pile {
    width: var(--card-width);
    height: var(--card-height);
    border: 2px dashed rgba(255, 255, 255, 0.4);
    border-radius: var(--yukon-card-border-radius);
    position: relative;
    transition: all 0.2s ease;
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.2),
        inset 0 0 10px rgba(0, 0, 0, 0.1);
    background: rgba(0, 0, 0, 0.12);
    cursor: pointer;
}

/* Foundation pile suit icons */
.foundation-pile::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: calc(var(--card-width) * 0.5);
    opacity: 0.2;
    font-family: 'Bootstrap Icons';
}

.foundation-pile[data-suit="hearts"]::before {
    content: '♥';
    color: #d32f2f;
}

.foundation-pile[data-suit="diamonds"]::before {
    content: '♦';
    color: #d32f2f;
}

.foundation-pile[data-suit="clubs"]::before {
    content: '♣';
    color: #1a1a1a;
}

.foundation-pile[data-suit="spades"]::before {
    content: '♠';
    color: #1a1a1a;
}

/* Foundation pile hover effect */
.foundation-pile:hover {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(0, 0, 0, 0.15);
}

/* Valid drop target */
.foundation-pile.valid-drop,
.yukon-column.valid-drop {
    border-color: #4caf50;
    border-width: 3px;
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.5);
    background: rgba(76, 175, 80, 0.1);
}

/* Drag stack container */
.drag-stack {
    width: var(--card-width);
    cursor: grabbing !important;
    opacity: 0.9;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.4));
    transition: none;
}

.drag-stack .card {
    cursor: grabbing !important;
}

/* Cards in foundation */
.foundation-pile .card {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* 允许点击穿透到foundation pile */
}

/* ========================================
   Yukon Tableau - 7 columns
   ======================================== */
.yukon-tableau {
    display: flex;
    gap: var(--yukon-spacing);
    justify-content: center;
    align-items: flex-start;
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    /* 自定义滚动条 */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.yukon-tableau::-webkit-scrollbar {
    width: 6px;
}

.yukon-tableau::-webkit-scrollbar-track {
    background: transparent;
}

.yukon-tableau::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.yukon-tableau::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.yukon-column {
    flex: 0 0 auto;
    width: var(--card-width);
    max-width: var(--card-width);
    position: relative;
    min-height: calc(var(--card-height) * 1.5);
    padding-bottom: 2vh; /* 底部留白，方便滚动查看最后的牌 */
}

/* Empty column visual */
.yukon-column:empty::after {
    content: 'K';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: var(--card-width);
    height: var(--card-height);
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: var(--yukon-card-border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--card-width) * 0.6);
    font-weight: bold;
    color: rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.08);
}

/* Highlight empty column when dragging King */
.yukon-column:empty.valid-drop {
    opacity: 1;
}

.yukon-column:empty.valid-drop::after {
    border-color: #4caf50;
    border-width: 3px;
    color: rgba(76, 175, 80, 0.6);
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.3);
    background: rgba(76, 175, 80, 0.1);
}

/* ========================================
   Cards in Yukon Tableau
   ======================================== */
.yukon-column .card {
    position: absolute;
    width: var(--card-width);
    height: var(--card-height);
    left: 0;
    top: 0; /* 由JavaScript动态设置 */
    cursor: default;
    transition: all 0.2s ease;
    z-index: 1; /* 由JavaScript动态设置 */
    will-change: transform, top;
    backface-visibility: hidden;
    border-radius: var(--yukon-card-border-radius);
    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);
}

/* 正面朝上的卡片可点击和拖拽 */
.yukon-column .card.face-up {
    cursor: grab;
}

.yukon-column .card.face-up:hover {
    transform: translateY(-4px);
    box-shadow: 
        0 4px 8px rgba(0, 0, 0, 0.3),
        0 6px 16px rgba(0, 0, 0, 0.2);
}

.yukon-column .card.face-up:active {
    cursor: grabbing;
}

/* Face-down cards */
.yukon-column .card.face-down {
    cursor: default;
    background-image: url('../images/cards/Back.svg');
    background-size: cover;
    background-position: center;
}

/* Selected card */
.yukon-column .card.selected {
    transform: translateY(-10px);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.3),
        0 0 0 3px rgba(255, 215, 0, 0.6);
    z-index: 100;
}

/* Cards being dragged */
.yukon-column .card.dragging {
    opacity: 0.7;
    z-index: 1000;
}

/* Hover effect for movable cards */
.yukon-column .card:not(.face-down):hover {
    transform: translateY(-5px);
    box-shadow: 
        0 3px 10px rgba(0, 0, 0, 0.25),
        0 0 0 2px rgba(255, 255, 255, 0.3);
}

/* Valid drop target highlight */
.yukon-column.valid-drop {
    background: rgba(76, 175, 80, 0.15);
    border-radius: var(--yukon-card-border-radius);
}

/* ========================================
   Hint Animations - Flying Card Effect
   ======================================== */
/* 堆叠容器 - 包含所有提示卡片作为整体移动 */
.hint-stack-container {
    will-change: transform, opacity, left, top;
    transform-origin: center;
}

/* 单张提示卡片 */
.hint-card-item {
    display: flex;
    align-items: center;
    justify-content: center;
}

.hint-card-item * {
    pointer-events: none !important;
}

.hint-card-item .card {
    position: static !important;
    transform: none !important;
    box-shadow: none !important;
}

.hint-card-item .card img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* 保留旧样式以兼容 */
.hint-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    will-change: transform, opacity;
    transform-origin: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hint-card * {
    pointer-events: none !important;
}

.hint-card .card {
    position: static !important;
    transform: none !important;
    box-shadow: none !important;
}

.hint-card .card img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.card-count-hint {
    white-space: nowrap;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    letter-spacing: 0.5px;
}

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

@keyframes yukonHintFlash {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

@keyframes yukonHintGlow {
    0%, 100% {
        box-shadow: 0 0 0 rgba(76, 175, 80, 0);
    }
    50% {
        box-shadow: 0 0 20px 5px rgba(76, 175, 80, 0.8);
    }
}

/* ========================================
   Auto-complete Animation
   ======================================== */
@keyframes autoCompleteMove {
    0% {
        transform: translate(0, 0) scale(1);
    }
    50% {
        transform: translate(var(--tx, 0), var(--ty, -100px)) scale(0.8);
    }
    100% {
        transform: translate(var(--tx, 0), var(--ty, -200px)) scale(0.5);
        opacity: 0;
    }
}

.card.auto-complete {
    animation: autoCompleteMove 0.5s ease-in-out forwards;
}

/* ========================================
   响应式设计 - 桌面优先
   ======================================== */

/* 大屏幕桌面 (>= 1920px) */
@media (min-width: 1920px) {
    :root {
        --yukon-spacing: 1.2vw;
        --yukon-foundation-spacing: 2vw;
        --yukon-card-width-by-height: calc((var(--available-height) - 12vh) / 5);
        --yukon-max-card-width: 170px; /* 增大纸牌 */
        --yukon-max-card-height: 238px;
        --yukon-card-overlap: calc(var(--yukon-card-height) * 0.28);
    }
    
    .yukon-game-container {
        padding: 2vh 2vw 2.5vh;
        gap: 2.5vh;
    }
}

/* 标准桌面/笔记本 (1200px - 1919px) */
@media (min-width: 1200px) and (max-width: 1919px) {
    :root {
        --yukon-spacing: 1vw;
        --yukon-foundation-spacing: 1.8vw;
        --yukon-card-width-by-height: calc((var(--available-height) - 10vh) / 5);
        --yukon-max-card-width: 155px; /* 增大纸牌 */
        --yukon-max-card-height: 217px;
        --yukon-card-overlap: calc(var(--yukon-card-height) * 0.26);
    }
    
    .yukon-game-container {
        padding: 1.5vh 1.5vw 2vh;
        gap: 2vh;
    }
}

/* 平板横屏 (768px - 1199px, landscape) */
@media (min-width: 768px) and (max-width: 1199px) and (orientation: landscape) {
    :root {
        --yukon-spacing: 0.8vw;
        --yukon-foundation-spacing: 1.5vw;
        --yukon-card-width-by-width: calc((100vw - 3vw - 6 * var(--yukon-spacing)) / 7);
        --yukon-card-width-by-height: calc((var(--available-height) - 8vh) / 6);
        --yukon-min-card-width: 45px;
        --yukon-min-card-height: 63px;
        --yukon-card-overlap: calc(var(--yukon-card-height) * 0.06); /* 6% - 极简间距 */
    }
    
    .yukon-game-container {
        padding: 1vh 1vw 1.5vh;
        gap: 1.5vh;
    }
}

/* 平板竖屏 (768px - 1199px, portrait) */
@media (min-width: 768px) and (max-width: 1199px) and (orientation: portrait) {
    :root {
        --yukon-spacing: 1vw;
        --yukon-card-width-by-width: calc((100vw - 3vw - 6 * var(--yukon-spacing)) / 7);
        --yukon-card-width-by-height: calc((var(--available-height) - 12vh) / 4.5);
        --yukon-min-card-width: 50px;
        --yukon-min-card-height: 70px;
        --yukon-card-overlap: calc(var(--yukon-card-height) * 0.2);
    }
    
    .yukon-game-container {
        padding: 1.5vh 1.5vw 2vh;
        gap: 1.8vh;
    }
}

/* 手机横屏 (<= 767px, landscape) */
@media (max-width: 767px) and (orientation: landscape) {
    :root {
        --yukon-spacing: 0.5vw;
        --yukon-foundation-spacing: 1vw;
        --yukon-card-width-by-width: calc((100vw - 2vw - 6 * var(--yukon-spacing)) / 7);
        --yukon-card-width-by-height: calc((var(--available-height) - 4vh) / 7);
        --yukon-min-card-width: 38px;
        --yukon-min-card-height: 53px;
        --yukon-max-card-width: 55px;
        --yukon-max-card-height: 77px;
        --yukon-card-overlap: calc(var(--yukon-card-height) * 0.05); /* 5% - 极简间距 */
    }
    
    .yukon-game-container {
        padding: 0.5vh 0.5vw 1vh;
        gap: 0.8vh;
    }
    
    .foundation-pile::before {
        font-size: calc(var(--card-width) * 0.4);
    }
}

/* 超窄横屏手机 (≤667px landscape) */
@media (max-width: 667px) and (orientation: landscape) {
    :root {
        --yukon-spacing: 0.4vw;
        --yukon-foundation-spacing: 0.8vw;
        --yukon-card-width-by-width: calc((100vw - 1.8vw - 6 * var(--yukon-spacing)) / 7);
        --yukon-card-width-by-height: calc((var(--available-height) - 3vh) / 7.5);
        --yukon-min-card-width: 35px;
        --yukon-min-card-height: 49px;
        --yukon-max-card-width: 50px;
        --yukon-max-card-height: 70px;
        --yukon-card-overlap: calc(var(--yukon-card-height) * 0.05); /* 5% - 极简间距 */
    }
    
    .yukon-game-container {
        padding: 0.3vh 0.3vw 0.8vh;
        gap: 0.6vh;
    }
}

/* 手机竖屏 (481px - 767px) */
@media (min-width: 481px) and (max-width: 767px) and (orientation: portrait) {
    :root {
        --yukon-spacing: 0.9vw;
        --yukon-foundation-spacing: 1.5vw;
        --yukon-card-width-by-width: calc((100vw - 2.5vw - 6 * var(--yukon-spacing)) / 7);
        --yukon-card-width-by-height: calc((var(--available-height) - 10vh) / 4.2);
        --yukon-min-card-width: 48px;
        --yukon-min-card-height: 67px;
        --yukon-card-overlap: calc(var(--yukon-card-height) * 0.18);
    }
    
    .yukon-game-container {
        padding: 1vh 1vw 1.5vh;
        gap: 1.5vh;
    }
}

/* 小屏手机 (361px - 480px) */
@media (min-width: 361px) and (max-width: 480px) {
    :root {
        --yukon-spacing: 0.7vw;
        --yukon-foundation-spacing: 1.2vw;
        --yukon-card-width-by-width: calc((100vw - 2vw - 6 * var(--yukon-spacing)) / 7);
        --yukon-card-width-by-height: calc((var(--available-height) - 9vh) / 4.3);
        --yukon-min-card-width: 45px;
        --yukon-min-card-height: 63px;
        --yukon-card-overlap: calc(var(--yukon-card-height) * 0.17);
    }
    
    .yukon-game-container {
        padding: 0.8vh 0.8vw 1.2vh;
        gap: 1.2vh;
    }
}

/* 超小屏手机 (<= 360px) */
@media (max-width: 360px) {
    :root {
        --yukon-spacing: 0.6vw;
        --yukon-foundation-spacing: 1vw;
        --yukon-card-width-by-width: calc((100vw - 1.5vw - 6 * var(--yukon-spacing)) / 7);
        --yukon-card-width-by-height: calc((var(--available-height) - 8vh) / 4.4);
        --yukon-min-card-width: 42px;
        --yukon-min-card-height: 59px;
        --yukon-card-overlap: calc(var(--yukon-card-height) * 0.16);
    }
    
    .yukon-game-container {
        padding: 0.6vh 0.6vw 1vh;
        gap: 1vh;
    }
}

/* ========================================
   移动端触摸优化
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    .yukon-column .card:not(.face-down) {
        -webkit-tap-highlight-color: rgba(255, 215, 0, 0.2);
        tap-highlight-color: rgba(255, 215, 0, 0.2);
        touch-action: manipulation;
    }
    
    .yukon-column .card:not(.face-down):active {
        transform: translateY(-3px) scale(0.98);
    }
    
    .foundation-pile {
        touch-action: manipulation;
    }
}

/* 移动端滚动优化 */
@media (max-width: 768px) {
    body {
        -webkit-overflow-scrolling: touch;
    }
    
    .yukon-tableau {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* 横屏模式下最小化 header */
@media (max-width: 767px) and (orientation: landscape) {
    .unified-header {
        min-height: 48px;
        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 {
    .yukon-foundation-area,
    .unified-header,
    .seo-content-section {
        display: none;
    }
    
    .yukon-game-container {
        max-width: 100%;
    }
}

