* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --card-w: 70px;
    --card-h: 100px;
    --accent: rgba(120, 220, 235, 0.9);
    --accent-dim: rgba(120, 220, 235, 0.45);
    --accent-strong: rgba(160, 240, 250, 1);
    --warm: rgba(245, 235, 210, 0.95);
    --warm-dim: rgba(245, 235, 210, 0.55);
    --panel: rgba(28, 18, 56, 0.96);
    --panel-edge: rgba(120, 220, 235, 0.4);
}

body {
    background-color: #2a1a4a;
    background-image: url('cover.jpg');
    background-size: cover;
    background-position: center 22%;
    background-attachment: fixed;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    position: relative;
    font-family: 'Fredoka', 'Segoe UI', sans-serif;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at center, rgba(28, 18, 56, 0.60) 0%, rgba(18, 10, 40, 0.82) 75%);
    pointer-events: none;
    z-index: 0;
}

#game {
    position: relative;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    overflow: hidden;
    color: var(--warm);
    touch-action: none;
}

/* ── Header bar ─────────────────────────────────────────────────────────────── */

#header-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    background: linear-gradient(180deg, rgba(14, 8, 28, 0.92), rgba(14, 8, 28, 0.65) 80%, rgba(14, 8, 28, 0.0));
    border-bottom: 1px solid rgba(120, 220, 235, 0.18);
    z-index: 300;
    pointer-events: none;
}
#header-bar > * { pointer-events: auto; }

.deckades-logo {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: 22px;
    letter-spacing: 0.12em;
    color: rgba(245, 235, 210, 0.45);
    text-decoration: none;
    user-select: none;
    line-height: 1;
    transition: color 0.2s;
}
.deckades-logo:hover { color: rgba(245, 235, 210, 0.9); }
.deckades-spade {
    color: rgba(120, 220, 235, 0.55);
    font-size: 1.2em;
    vertical-align: middle;
    display: inline-block;
    transform: translateY(-2px);
    transition: color 0.2s;
}
.deckades-logo:hover .deckades-spade { color: rgba(160, 240, 250, 1); }

/* ── Status bar ─────────────────────────────────────────────────────────────── */

#status-bar {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 1px;
    color: var(--warm);
    opacity: 0.92;
    white-space: nowrap;
    pointer-events: none;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* ── Board ──────────────────────────────────────────────────────────────────── */

#board {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    gap: 36px;
    align-items: center;
    justify-content: center;
    padding: 30px 56px;
    border-radius: 18px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(120, 220, 235, 0.12);
    box-shadow: 0 0 80px rgba(0, 0, 0, 0.55), inset 0 0 40px rgba(0, 0, 0, 0.25);
}

#draw-pile {
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 8px;
    background-size: cover;
    background-position: center;
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    transition: transform 0.12s, filter 0.12s, box-shadow 0.12s;
}
#draw-pile.drawable {
    cursor: pointer;
    touch-action: manipulation;
}
@media (hover: hover) {
    #draw-pile.drawable:hover {
        transform: translateY(-3px);
        filter: brightness(1.18);
        box-shadow:
            2px 3px 12px rgba(0, 0, 0, 0.65),
            4px 6px 0 -1px rgba(40, 28, 70, 0.95),
            7px 9px 0 -2px rgba(40, 28, 70, 0.9),
            10px 12px 0 -3px rgba(40, 28, 70, 0.85),
            0 0 18px rgba(120, 220, 235, 0.45);
    }
}
#draw-pile-label {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(-6deg);
    font-family: 'Fredoka', sans-serif;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.97);
    text-shadow:
        0 0 14px rgba(120, 220, 235, 0.95),
        0 2px 0 rgba(20, 60, 90, 0.95),
        2px 4px 12px rgba(0, 0, 0, 0.7);
    pointer-events: none;
    user-select: none;
    opacity: 0;
    transition: opacity 0.18s;
    z-index: 3;
}
#draw-pile.drawable #draw-pile-label { opacity: 1; }

#draw-pile {
    background-image: url('assets/cards/back.png');
    background-size: cover;
    background-position: center;
    border: 2px solid rgba(255, 255, 255, 0.28);
    box-shadow:
        2px 3px 8px rgba(0, 0, 0, 0.5),
        4px 6px 0 -1px rgba(40, 28, 70, 0.95),
        7px 9px 0 -2px rgba(40, 28, 70, 0.9),
        10px 12px 0 -3px rgba(40, 28, 70, 0.85);
}


#draw-pile-count {
    position: absolute;
    top: -12px;
    right: -14px;
    min-width: 30px;
    height: 26px;
    padding: 0 8px;
    border-radius: 13px;
    background: var(--accent);
    color: #0a0418;
    font-size: 13px;
    font-weight: 700;
    line-height: 26px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    z-index: 2;
}

.zone-label { display: none; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */

.card {
    position: absolute;
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.28);
    background-size: cover;
    background-position: center;
    box-shadow: 2px 3px 8px rgba(0, 0, 0, 0.5);
    user-select: none;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s, filter 0.12s;
}

.card.face-down {
    background-image: url('assets/cards/back.png');
}

.card .column-count {
    position: absolute;
    bottom: -6px;
    right: -8px;
    min-width: 24px;
    height: 22px;
    padding: 0 7px;
    border-radius: 11px;
    background: rgba(255, 215, 90, 0.95);
    color: #2a1a08;
    font-size: 12px;
    font-weight: 700;
    line-height: 22px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 5;
}

.card.stealable {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent), 0 0 18px var(--accent-dim);
    cursor: pointer;
    touch-action: manipulation;
    animation: stealable-pulse 1.1s ease-in-out infinite;
}
@media (hover: hover) {
    .card.stealable:hover {
        filter: brightness(1.18);
        transform: scale(1.04);
    }
}

@keyframes stealable-pulse {
    0%,100% { box-shadow: 0 0 0 2px var(--accent), 0 0 14px var(--accent-dim); }
    50%     { box-shadow: 0 0 0 3px var(--accent-strong), 0 0 26px var(--accent); }
}

.score-pile {
    position: absolute;
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 8px;
    background-image: url('assets/cards/back.png');
    background-size: cover;
    background-position: center;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow:
        2px 3px 8px rgba(0, 0, 0, 0.5),
        4px 6px 0 -1px rgba(40, 28, 70, 0.95),
        7px 9px 0 -2px rgba(40, 28, 70, 0.9);
    opacity: 0.9;
}
.score-pile.empty { opacity: 0; pointer-events: none; }

/* Side-player piles lie on their long edge. The pile element stays card-w × card-h in
   the DOM; renderScorePile applies `transform: rotate(90deg|270deg)` so the whole pile
   (back-of-card art and the box-shadow stack) ends up visibly horizontal. */
.score-pile.sideways {
    transform-origin: center center;
}

.score-pile-count {
    position: absolute;
    top: -10px;
    right: -12px;
    min-width: 26px;
    height: 22px;
    padding: 0 7px;
    border-radius: 11px;
    background: rgba(255, 215, 90, 0.95);
    color: #2a1a08;
    font-size: 12px;
    font-weight: 700;
    line-height: 22px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

/* ── Opponent labels ─────────────────────────────────────────────────────────── */

.player-label {
    position: absolute;
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 8px 18px;
    border-radius: 10px;
    background: rgba(20, 10, 40, 0.55);
    border: 1px solid rgba(120, 220, 235, 0.25);
    backdrop-filter: blur(6px);
    color: var(--warm);
    white-space: nowrap;
    pointer-events: none;
    z-index: 20;
    transition: border-color 0.2s, background 0.2s;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
    letter-spacing: 0.5px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
}
.player-label.active-player {
    border-color: var(--accent);
    background: rgba(30, 18, 70, 0.75);
}
.player-label .label-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--warm-dim);
}
.player-label.active-player .label-name {
    color: var(--accent-strong);
}
.player-label .label-score {
    color: rgba(255, 215, 90, 0.95);
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
}
.player-label .label-score::before {
    content: '★ ';
    font-size: 18px;
    color: rgba(255, 215, 90, 0.75);
}

/* ── Decision bar ───────────────────────────────────────────────────────────── */

#decision-bar {
    position: absolute;
    left: 50%;
    /* Sits below the central board area with a clear gap between the pile and the
       buttons so the click target reads as separate from the deck. */
    top: calc(50% + var(--card-h) / 2 + 32px);
    transform: translateX(-50%);
    display: flex;
    flex-direction: row;
    gap: 14px;
    z-index: 50;
    align-items: center;
}

.decision-btn {
    padding: 13px 38px;
    background: var(--accent);
    color: #0a0418;
    border: none;
    border-radius: 8px;
    font-family: 'Fredoka', sans-serif;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45), inset 0 -3px 0 rgba(0,0,0,0.15);
    transition: background 0.15s, transform 0.05s;
}
@media (hover: hover) {
    .decision-btn:hover { background: var(--accent-strong); }
}
.decision-btn:active { transform: translateY(1px); }
.decision-btn.steal {
    background: rgba(255, 212, 90, 0.95);
    color: #2a1a08;
    box-shadow: 0 4px 14px rgba(0,0,0,0.45), inset 0 -3px 0 rgba(120, 80, 0, 0.35);
}
.decision-btn.stop-red {
    background: rgba(220, 70, 60, 0.95);
    color: rgba(255, 240, 230, 0.98);
    box-shadow: 0 4px 14px rgba(0,0,0,0.45), inset 0 -3px 0 rgba(120, 20, 14, 0.6);
}
@media (hover: hover) {
    .decision-btn.steal:hover { background: rgba(255, 226, 130, 1); }
    .decision-btn.stop-red:hover:not(:disabled) { background: rgba(245, 95, 80, 1); }
}
.decision-btn:disabled {
    cursor: not-allowed;
    opacity: 0.4;
    filter: saturate(0.55);
}
.decision-btn:disabled:hover { background: inherit; }
.decision-btn.secondary {
    background: rgba(60, 38, 100, 0.95);
    color: var(--warm);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45), inset 0 -3px 0 rgba(0,0,0,0.3), inset 0 0 0 1px var(--accent-dim);
}
@media (hover: hover) {
    .decision-btn.secondary:hover { background: rgba(80, 52, 130, 1); }
}

/* ── Live ranking table (top-right) ─────────────────────────────────────────── */

#ranking-table {
    position: fixed;
    top: 64px;
    right: 14px;
    width: 180px;
    height: 176px;          /* 4 rows × 42px + 8 padding */
    z-index: 200;
    pointer-events: none;
    user-select: none;
    font-family: 'Fredoka', sans-serif;
}
#ranking-table .rank-row {
    position: absolute;
    left: 0;
    right: 0;
    height: 36px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 12px;
    border-radius: 8px;
    background: rgba(20, 10, 40, 0.55);
    border: 1px solid rgba(120, 220, 235, 0.18);
    color: rgba(245, 235, 210, 0.85);
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    transition: top 380ms cubic-bezier(.45,.1,.3,1),
                border-color 0.2s, background 0.2s;
}
#ranking-table .rank-row.active-player {
    border-color: var(--accent);
    background: rgba(30, 18, 70, 0.78);
}
#ranking-table .rank-row .rank-place {
    font-size: 11px;
    font-weight: 600;
    color: rgba(120, 220, 235, 0.75);
    min-width: 18px;
    padding: 0;
    text-align: left;
}
#ranking-table .rank-row.active-player .rank-place {
    color: var(--accent-strong);
}
#ranking-table .rank-row .rank-name {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: rgba(245, 235, 210, 0.85);
    padding: 0;
    text-align: left;
}
#ranking-table .rank-row.active-player .rank-name {
    color: rgba(255, 255, 240, 1);
}
#ranking-table .rank-row .rank-score {
    font-size: 16px;
    font-weight: 700;
    color: rgba(255, 215, 90, 0.95);
    min-width: 26px;
    text-align: right;
}

/* ── Bust banner ─────────────────────────────────────────────────────────────── */

.bust-banner {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(0.6) rotate(-8deg);
    font-family: 'Fredoka', sans-serif;
    font-size: 96px;
    font-weight: 700;
    letter-spacing: 8px;
    color: #ff5a4a;
    text-shadow:
        0 0 20px rgba(255, 90, 74, 0.85),
        0 4px 0 rgba(120, 0, 0, 0.9),
        4px 8px 24px rgba(0, 0, 0, 0.75);
    z-index: 900;
    pointer-events: none;
    opacity: 0;
    animation: bust-pop 1.05s cubic-bezier(.36,.07,.19,.97) forwards;
    user-select: none;
}
.bust-banner.steal-banner {
    color: #ffd45a;
    text-shadow:
        0 0 20px rgba(255, 212, 90, 0.85),
        0 4px 0 rgba(120, 80, 0, 0.9),
        4px 8px 24px rgba(0, 0, 0, 0.75);
}
/* STOP banner sits ACROSS a specific player's zone, not screen-centred. JS sets
   left/top to the zone centre; we cancel out the default 50/50 centring here. */
.bust-banner.stop-banner {
    left: auto;
    top: auto;
    font-size: 64px;
    letter-spacing: 6px;
    color: #b6dcff;
    text-shadow:
        0 0 18px rgba(120, 200, 255, 0.85),
        0 3px 0 rgba(30, 60, 100, 0.95),
        3px 6px 18px rgba(0, 0, 0, 0.7);
}

@keyframes bust-pop {
    0%   { transform: translate(-50%, -50%) scale(0.4) rotate(-12deg); opacity: 0;   }
    18%  { transform: translate(-50%, -50%) scale(1.25) rotate(-6deg); opacity: 1;   }
    32%  { transform: translate(-50%, -50%) scale(1.0)  rotate(-9deg); opacity: 1;   }
    46%  { transform: translate(-50%, -50%) scale(1.08) rotate(-5deg); opacity: 1;   }
    70%  { transform: translate(-50%, -50%) scale(1.0)  rotate(-7deg); opacity: 1;   }
    100% { transform: translate(-50%, -50%) scale(1.1)  rotate(-7deg); opacity: 0;   }
}

/* ── Point gain floater ──────────────────────────────────────────────────────── */

.point-gain {
    position: fixed;
    transform: translate(-50%, -50%);
    font-family: 'Fredoka', sans-serif;
    font-size: 38px;
    font-weight: 700;
    color: rgba(255, 215, 90, 1);
    text-shadow:
        0 0 14px rgba(255, 215, 90, 0.85),
        0 2px 0 rgba(120, 80, 0, 0.95),
        2px 4px 12px rgba(0, 0, 0, 0.7);
    pointer-events: none;
    z-index: 850;
    opacity: 0;
    animation: point-rise 1.25s cubic-bezier(.22,.7,.36,1) forwards;
    user-select: none;
}
@keyframes point-rise {
    0%   { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
    18%  { transform: translate(-50%, -130%) scale(1.15); opacity: 1; }
    65%  { transform: translate(-50%, -180%) scale(1.0); opacity: 1; }
    100% { transform: translate(-50%, -240%) scale(0.95); opacity: 0; }
}

/* ── AI status indicator (header-right) ─────────────────────────────────────── */

#header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

#ai-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    background: rgba(20, 10, 40, 0.65);
    border: 1px solid rgba(120, 220, 235, 0.18);
    color: rgba(245, 235, 210, 0.7);
    user-select: none;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}
#ai-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(180, 180, 180, 0.5);
    box-shadow: 0 0 6px rgba(180, 180, 180, 0.4);
}
#ai-indicator.ai-pending::before { background: rgba(200, 180, 80, 0.85); box-shadow: 0 0 6px rgba(200, 180, 80, 0.55); }
#ai-indicator.ai-onnx {
    color: rgba(140, 240, 160, 0.95);
    border-color: rgba(140, 240, 160, 0.45);
}
#ai-indicator.ai-onnx::before { background: rgba(140, 240, 160, 0.95); box-shadow: 0 0 8px rgba(140, 240, 160, 0.7); }
#ai-indicator.ai-heuristic {
    color: rgba(220, 180, 110, 0.95);
    border-color: rgba(220, 180, 110, 0.35);
}
#ai-indicator.ai-heuristic::before { background: rgba(220, 180, 110, 0.9); box-shadow: 0 0 6px rgba(220, 180, 110, 0.5); }

/* ── Rules button ────────────────────────────────────────────────────────────── */

#rules-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--accent-dim);
    color: rgba(160, 230, 240, 0.8);
    font-size: 18px;
    line-height: 42px;
    text-align: center;
    cursor: pointer;
    touch-action: manipulation;
    padding: 0;
    font-family: 'Fredoka', sans-serif;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
@media (hover: hover) {
    #rules-btn:hover {
        background: rgba(120, 220, 235, 0.18);
        color: var(--accent-strong);
        border-color: var(--accent);
    }
}

#rules-popup {
    position: fixed;
    right: 18px;
    top: 64px;
    background: var(--panel);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 14px 36px 14px 14px;
    color: var(--warm);
    font-size: 12px;
    letter-spacing: 0.4px;
    z-index: 301;
    min-width: 220px;
    max-width: 300px;
    line-height: 1.55;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
#rules-popup-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: transparent;
    border: none;
    color: var(--accent);
    font-size: 13px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
#rules-popup-close:hover { color: var(--accent-strong); }
#rules-popup a {
    display: inline-block;
    margin-top: 10px;
    color: var(--accent-strong);
    text-decoration: underline;
    cursor: pointer;
}

/* ── Game-over modal ─────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(3px);
}
.modal-content {
    background: var(--panel);
    border-radius: 14px;
    border: 1px solid var(--panel-edge);
    padding: 36px 56px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 380px;
    max-width: 460px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}
.modal-eyebrow {
    font-size: 11px;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--accent-dim);
}
.modal-content h2 {
    font-family: 'Fredoka', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--warm);
}

#game-over-ranking {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 6px 0 12px;
}
.rank-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 14px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.25);
    color: var(--warm-dim);
    font-size: 14px;
}
.rank-row.winner {
    background: rgba(255, 215, 90, 0.12);
    color: var(--warm);
    border: 1px solid rgba(255, 215, 90, 0.35);
}
.rank-row .rank-place { font-weight: 700; min-width: 28px; text-align: left; }
.rank-row .rank-name  { flex: 1; text-align: left; padding-left: 12px; }
.rank-row .rank-score { font-weight: 700; color: rgba(255, 215, 90, 0.95); }
.rank-row.winner .rank-score { font-size: 16px; }

.restart-btn {
    padding: 13px 32px;
    font-family: 'Fredoka', sans-serif;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    background: var(--accent);
    color: #0a0418;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 6px;
    touch-action: manipulation;
    transition: background 0.15s;
}
@media (hover: hover) {
    .restart-btn:hover { background: var(--accent-strong); }
}
