/* --------------------------------------------------
   카드 내기 상호작용: 끌어서 내기, 끌기 힌트, 덱에서 가져오기, 10 되돌리기, 게임 결과
   -------------------------------------------------- */

/* --- 손패 카드 끌기 (handdrag.js) ------------------------------------ */
.hand-card {
    touch-action: none;             /* 손가락으로 끌 때 화면이 스크롤되지 않게 */
}

.my-turn-glow {
    cursor: grab;
}

/* 손가락을 따라오는 카드 */
.card.drag-card {
    position: fixed;
    z-index: 45;
    margin: 0;
    pointer-events: none;           /* 아래의 더미를 찾을 수 있게 */
    border: 2px solid var(--gold);
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.55);
    will-change: transform;
}

/* 끌고 있는 카드의 원래 자리 */
.hand-card.drag-src {
    opacity: 0.25;
    border-style: dashed;
    border-color: var(--line-strong);
    transform: none !important;
}

body.card-dragging,
body.card-dragging * {
    cursor: grabbing !important;
}

/* 대고 있는 더미: 낼 수 있으면 금색으로 커짐, 없으면 빨간 테두리 */
.pile.drop-target {
    border-color: var(--gold);
    transform: scale(1.05);
    box-shadow: 0 0 0 4px rgba(255, 201, 61, 0.25), 0 8px 20px rgba(0, 0, 0, 0.35);
}

.pile.drop-bad {
    border-color: var(--down);
    animation: drop-bad 0.25s ease;
}

@keyframes drop-bad {
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

/* --- 끌기 힌트: 다른 사람이 이 더미에 카드를 대고 있음 (hints.js) ---------- */
/* 더미 숫자를 가리지 않게 오른쪽 위 모서리에 걸쳐 둠 (숫자는 가운데, 힌트는 가장자리) */
.pile-hint {
    position: absolute;
    bottom: calc(100% - 54px);      /* 카드 아랫부분만 더미 오른쪽 위에 걸침 → 이름표는 더미 바깥 위쪽 */
    right: -4px;
    z-index: 3;
    width: 25%;
    min-width: 32px;
    max-width: 46px;
    display: flex;
    flex-direction: column-reverse; /* 이름표는 카드 위: 아래에 두면 긴 이름이 가운데 숫자를 가림 */
    align-items: flex-end;          /* 이름표가 가운데 숫자 쪽으로 번지지 않게 오른쪽 정렬 */
    gap: 3px;
    pointer-events: none;
}

.hint-card {
    width: 100%;
    aspect-ratio: 5 / 7;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.85);
    background:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.18) 0 3px, transparent 3px 7px),
        linear-gradient(160deg, #a58cff 0%, #5a3fd6 100%);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
    transform: rotate(8deg);
    animation: hint-in 0.22s ease-out, hint-bob 1.4s ease-in-out 0.22s infinite;
}

.hint-name {
    max-width: 110px;
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(12, 16, 26, 0.85);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@keyframes hint-in {
    from { opacity: 0; transform: translate(-10px, 14px) rotate(-6deg) scale(0.8); }
}

@keyframes hint-bob {
    50% { transform: translateY(-5px) rotate(12deg); }
}

/* --- 덱에서 가져오는 카드 (fx.draw) ------------------------------------ */
.fly-card.draw-card {
    position: fixed;
    z-index: 40;
    pointer-events: none;
    border-radius: 8px;
    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: 0 8px 18px rgba(0, 0, 0, 0.45);
    will-change: transform;
}

/* --- 10 되돌리기 성공 (fx.backtrackBurst) -------------------------------- */
.pile-slot.pile-backtrack .pile {
    animation: backtrack-glow 1.5s ease-out;
}

@keyframes backtrack-glow {
    0%   { box-shadow: 0 0 0 0 rgba(255, 201, 61, 0.9), 0 0 0 rgba(255, 201, 61, 0); border-color: var(--gold); }
    30%  { box-shadow: 0 0 0 7px rgba(255, 201, 61, 0.45), 0 0 34px rgba(255, 201, 61, 0.8); border-color: var(--gold); }
    100% { box-shadow: 0 0 0 14px rgba(255, 201, 61, 0), 0 0 0 rgba(255, 201, 61, 0); }
}

.backtrack-pop {
    position: absolute;
    left: 50%;
    top: -6px;
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 10px;
    border-radius: 12px;
    background: linear-gradient(160deg, #ffe07a, var(--gold));
    color: #3a2a00;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    transform: translate(-50%, -22px);
    white-space: nowrap;
}

.backtrack-pop b {
    font-size: 15px;
    line-height: 1.1;
}

.backtrack-pop small {
    font-size: 11px;
    font-weight: 800;
}

/* --- 게임 결과 (result.js) --------------------------------------------- */
.result-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(6, 9, 16, 0.72);
    backdrop-filter: blur(3px);
    animation: fade-in 0.25s ease;
}

.result-overlay[hidden] {
    display: none;
}

@keyframes fade-in {
    from { opacity: 0; }
}

.result-card {
    position: relative;
    width: min(380px, 100%);
    padding: 26px 22px 20px;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 2px solid var(--line-strong);
    text-align: center;
    overflow: hidden;
    animation: result-pop 0.45s cubic-bezier(.2, .9, .3, 1.3);
}

.result-win {
    border-color: var(--up);
    background: radial-gradient(120% 80% at 50% 0%, rgba(47, 212, 134, 0.22), transparent 70%), var(--surface);
}

.result-loss {
    border-color: var(--down);
    background: radial-gradient(120% 80% at 50% 0%, rgba(255, 99, 128, 0.18), transparent 70%), var(--surface);
}

@keyframes result-pop {
    from { opacity: 0; transform: scale(0.7) translateY(20px); }
}

.result-emoji {
    font-size: 54px;
    line-height: 1;
}

.result-title {
    margin: 8px 0 6px;
    font-size: 34px;
    font-weight: 900;
    letter-spacing: -0.02em;
}

.result-win .result-title { color: var(--up); }
.result-loss .result-title { color: var(--down); }

.result-line {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.result-line b {
    color: var(--text);
}

.result-bar {
    height: 8px;
    margin-bottom: 14px;
    border-radius: 999px;
    background: var(--bg);
    overflow: hidden;
}

.result-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--up));
    animation: bar-grow 0.9s ease-out;
}

.result-loss .result-bar span {
    background: linear-gradient(90deg, var(--accent), var(--down));
}

@keyframes bar-grow {
    from { width: 0; }
}

.result-stats {
    margin-bottom: 14px;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: rgba(255, 201, 61, 0.08);
    border: 1px solid rgba(255, 201, 61, 0.25);
    text-align: left;
}

.result-stats-title {
    margin-bottom: 6px;
    color: var(--gold);
    font-size: 12px;
    font-weight: 800;
}

.result-stat {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    padding: 2px 0;
}

.result-stat.top {
    font-weight: 800;
}

.result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* 승리 색종이 (14조각, CSS 만) */
.confetti {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.confetti i {
    position: absolute;
    top: -12px;
    left: calc(4% + var(--i) * 6.8%);
    width: 7px;
    height: 12px;
    border-radius: 2px;
    background: hsl(calc(var(--i) * 47) 85% 62%);
    animation: confetti-fall calc(1.6s + var(--i) * 0.07s) ease-in calc(var(--i) * 0.06s) both;
}

@keyframes confetti-fall {
    to { transform: translateY(420px) rotate(calc(220deg + var(--i) * 40deg)); opacity: 0.2; }
}

@media (prefers-reduced-motion: reduce) {
    .hint-card,
    .result-card,
    .result-overlay,
    .confetti i,
    .pile-slot.pile-backtrack .pile {
        animation: none;
    }
    .confetti {
        display: none;
    }
}

/* --- 손 얹기: 다른 사람이 꾹 누르고 있는 더미 (guard.js, locks.js) ------------- */
.pile.pile-locked {
    border-color: var(--down);
    filter: saturate(0.5) brightness(0.85);
    cursor: not-allowed;
}

/* 내가 누르고 있는 동안 (서버 확인 전에도 바로 반응) */
.pile.guarding {
    transform: scale(0.97);
    box-shadow: 0 0 0 3px rgba(255, 99, 128, 0.55) inset;
}

.pile-lock {
    position: absolute;
    left: 50%;
    bottom: 6px;
    z-index: 4;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    max-width: calc(100% - 12px);
    padding: 2px 8px 2px 4px;
    border-radius: 999px;
    background: rgba(220, 38, 70, 0.95);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
    pointer-events: none;
    animation: lock-in 0.18s ease-out;
}

.pile-lock.mine {
    background: rgba(139, 108, 255, 0.95);
}

.pile-lock .lock-hand {
    font-size: 16px;
    line-height: 1;
    animation: hand-press 0.25s ease-out;
}

.pile-lock .lock-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

@keyframes lock-in {
    from { opacity: 0; transform: translate(-50%, 6px) scale(0.85); }
}

@keyframes hand-press {
    from { transform: translateY(-10px) scale(1.4); }
}
