/* --------------------------------------------------
   게임판: 남은 덱, 카드 더미(테이블), 내 손패(독)
   카드 숫자 색: --v (0~1, JS 가 값/100 으로 설정) → 낮은 수 파랑, 높은 수 빨강
   -------------------------------------------------- */

/* 테이블 */
.table {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    border-radius: var(--radius-lg);
    background:
        radial-gradient(100% 80% at 50% 0%, rgba(139, 108, 255, 0.10) 0%, transparent 70%),
        var(--surface);
    border: 1px solid var(--line);
}

/* 남은 덱: 카드 더미 아이콘 + 장수 + 진행 막대 */
.deck {
    display: flex;
    align-items: center;
    gap: 12px;
}

.deck-stack {
    position: relative;
    width: 26px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 5px;
    background:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.16) 0 3px, transparent 3px 7px),
        linear-gradient(160deg, #6f55e0 0%, #3a2896 100%);
    box-shadow: 3px -3px 0 -1px #2c2470, 6px -6px 0 -2px #221c58;
}

.deck-empty .deck-stack {
    opacity: 0.25;
    box-shadow: none;
}

.deck-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.deck-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--muted);
}

.deck-label strong {
    color: var(--text);
}

.deck-bar {
    height: 6px;
    border-radius: 999px;
    background: var(--bg);
    overflow: hidden;
}

#deck-fill {
    display: block;
    height: 100%;
    width: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), #b39dff);
    transition: width 0.4s ease;
}

/* 카드 공통: 밝은 앞면 + 값에 따른 숫자 색 */
.card {
    --v: 0.5;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--card-face);
    color: hsl(calc(222 - var(--v) * 222) 70% 40%);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 2px 6px rgba(0, 0, 0, 0.25);
    border-radius: 10px;
    font-weight: 800;
    user-select: none;
    -webkit-user-select: none;
}

/* 카드 더미 4개: 모바일 2×2, 넓은 화면 4열 */
.piles-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.pile,
.pile-under {
    padding: 22px 6px 8px;
    border: 2px solid transparent;
    overflow: hidden;
}

.pile {
    min-height: 104px;
    z-index: 1;
    cursor: grab;
    touch-action: none;             /* 끌기(들춰보기)를 브라우저 스크롤이 가로채지 않게 */
    -webkit-touch-callout: none;    /* iOS: 길게 누를 때 뜨는 메뉴가 끌기를 끊지 않게 */
    transition: border-color 0.15s ease, transform 0.12s ease;
}

/* 더미 한 칸: 맨 위 카드 + 그 밑에 깔린 카드 (peek.js 로 끌어서 들춰봄) */
.pile-slot {
    position: relative;
    display: grid;
}

.pile-slot.peeking {
    z-index: 5;                     /* 끄는 카드가 옆 더미 위로 */
}

.pile-under {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25) inset;
}

.pile-under .pile-type {
    opacity: 0.85;
}

.pile-slot.peeking .pile-under {
    opacity: 1;
}

.pile-under-empty {
    background: transparent;
    border: 2px dashed var(--line-strong);
    color: var(--muted);
}

.pile-under-empty::before,
.pile-under-empty .face-frame {
    display: none;
}

.pile-under-empty .pile-type {
    color: var(--muted);
}

.pile-under-empty .pile-value {
    font-size: 16px;
    text-shadow: none;
}

.pile.dragging {
    cursor: grabbing;
    transition: none;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.5);
}

/* 위쪽 띠: 방향과 색 */
.pile::before,
.pile-under::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 20px;
}

.pile-up::before { background: var(--up); }
.pile-down::before { background: var(--down); }

.pile-type {
    position: absolute;
    top: 2px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 11px;
    font-weight: 800;
    color: #0c1a12;
    letter-spacing: 0.02em;
}

.pile-down .pile-type {
    color: #2a0610;
}

.pile-value {
    font-size: 40px;
    line-height: 1;
    letter-spacing: -0.03em;
}

/* 고른 카드를 낼 수 있는 더미 */
.pile.playable {
    border-color: rgba(255, 201, 61, 0.55);
    cursor: pointer;
}

.pile.selected {
    border-color: var(--gold);
    transform: translateY(-2px);
}

/* 내 손패 독: 모바일에서는 화면 아래 고정 */
.hand-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
    padding: 10px 12px calc(10px + var(--safe-bottom));
    background: rgba(17, 23, 36, 0.98);
    border-top: 1px solid var(--line-strong);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 손패: 장수와 상관없이 카드 비율(약 5:7)을 유지하고 가운데 정렬.
   화면 폭에 다 안 들어가면 카드를 좁히지 않고 손에 쥔 것처럼 살짝 겹침.
   --n: 장수 (board.js renderHand), --cw/--ch: 카드 크기, --gap: 기본 간격 */
.hand-row {
    --cw: 54px;
    --ch: 76px;
    --gap: 6px;
    display: flex;
    justify-content: center;
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
    padding-top: 8px;               /* 고른 카드가 위로 뜰 자리 */
}

.hand-card {
    flex: 0 0 var(--cw);
    width: var(--cw);
    height: var(--ch);
    font-size: 22px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

/* 두 번째 카드부터: 남는 폭으로 간격 계산 (모자라면 음수 = 겹침, 최대 카드 폭의 절반까지)
   margin 의 % 는 손패 줄 폭 기준이라 화면 폭에 맞춰 자동으로 바뀜 */
.hand-card + .hand-card {
    margin-left: clamp(calc(var(--cw) * -0.5),
                       (100% - var(--n) * var(--cw)) / max(var(--n) - 1, 1),
                       var(--gap));
}

/* 겹쳤을 때 고른 카드가 위로 */
.hand-card.selected {
    z-index: 2;
}

/* 내 차례: 카드가 살짝 떠 있음 (반복 애니메이션 없이 가볍게) */
.hand-card.my-turn-glow {
    box-shadow: 0 0 0 1px rgba(255, 201, 61, 0.35);
}

.hand-card.selected {
    border-color: var(--gold);
    transform: translateY(-8px);
}

/* 고른 카드 아래에 지정한 더미 표시 (▲1 / ▼2) */
.hand-card[data-pile-display]::after {
    content: attr(data-pile-display);
    position: absolute;
    bottom: -9px;
    left: 50%;
    transform: translateX(-50%);
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--gold);
    color: #2a2000;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr auto;       /* 턴 종료 | 감정 표현 (카드는 끌어서 냄) */
    gap: 8px;
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
}

/* 넓은 화면: 손패는 테이블 아래 일반 흐름으로 */
@media (min-width: 900px) {
    .piles-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 12px;
    }

    .pile {
        min-height: 128px;
    }

    .pile-value {
        font-size: 48px;
    }

    .pile:hover {
        transform: translateY(-2px);
    }

    .hand-dock {
        position: static;
        padding: 14px;
        border: 1px solid var(--line);
        border-radius: var(--radius-lg);
        background: var(--surface);
    }

    .hand-row {
        --cw: 76px;
        --ch: 104px;
        max-width: none;
    }

    .hand-card {
        font-size: 28px;
    }

    .hand-card:hover:not(.selected) {
        transform: translateY(-4px);
    }

    .action-buttons {
        max-width: 420px;
    }
}
