/* begin license *
 *
 * Small browser games on swl and swindl
 *
 * All rights reserved.
 *
 * Copyright (C) 2026 moatley moatley@lost-monkeys.net
 *
 * This file is part of "Games"
 *
 * end license */

/* Cards: the playing cards of the card games (cards.js). The size of a card is the
   CSS variable --cw, its width, set on the table; everything on it scales with it.
   The back: teal with a lattice and the monkey in a medallion. */
:root {
    --card-face: #fffdf8;
    --card-edge: rgba(42, 42, 51, .16);
    --card-red: #d8344c;
    --card-black: #262a36;
    --card-red-tint: #fde9e4;
    --card-black-tint: #e5ebf4;
    --card-back: #259696;
    --card-back-dark: #196b6b;
    --card-back-line: rgba(255, 255, 255, .13);
    --card-selected: #ffb627;
    --card-slot: rgba(42, 42, 51, .07);
    --card-slot-line: rgba(42, 42, 51, .22);
}
:root[data-theme="dark"] {
    --card-face: #f6f2ea;
    --card-edge: rgba(0, 0, 0, .5);
    --card-back: #23898b;
    --card-back-dark: #155b5c;
    --card-slot: rgba(255, 255, 255, .05);
    --card-slot-line: rgba(236, 238, 244, .2);
}

.card {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--cw, 60px);
    height: calc(var(--cw, 60px) * 1.4);
    perspective: calc(var(--cw, 60px) * 8);
    transition: transform .22s cubic-bezier(.3, .7, .4, 1);
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}
.card-flip {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    transition: transform .32s ease-out;
}
.card:not(.card-up) .card-flip { transform: rotateY(180deg); }
.card-front, .card-back {
    position: absolute;
    inset: 0;
    border-radius: calc(var(--cw, 60px) * .1);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    box-shadow: 0 0 0 1px var(--card-edge), 0 1px 2px rgba(0, 0, 0, .18);
    overflow: hidden;
}
.card-front {
    background: var(--card-face);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
.card-red { color: var(--card-red); }
.card-black { color: var(--card-black); }
.card svg { fill: currentColor; }

/* the corner: rank left, suit right, both in the strip that shows in a column */
.card-rank {
    position: absolute;
    left: calc(var(--cw, 60px) * .07);
    top: calc(var(--cw, 60px) * .03);
    font-size: calc(var(--cw, 60px) * .34);
    font-weight: 800;
    line-height: 1;
    letter-spacing: -.03em;
}
.card[data-card$="10"] .card-rank { letter-spacing: -.1em; left: calc(var(--cw, 60px) * .03); }
.card-corner-suit {
    position: absolute;
    right: calc(var(--cw, 60px) * .07);
    top: calc(var(--cw, 60px) * .06);
    width: calc(var(--cw, 60px) * .26);
    height: calc(var(--cw, 60px) * .26);
}

.card-middle { position: absolute; left: 22%; right: 22%; top: 34%; bottom: 10%; }
.card-pip {
    position: absolute;
    width: calc(var(--cw, 60px) * .2);
    height: calc(var(--cw, 60px) * .2);
    transform: translate(-50%, -50%);
}
.card-pip-down { transform: translate(-50%, -50%) rotate(180deg); }
.card-ace { display: flex; align-items: center; justify-content: center; left: 10%; right: 10%; }
.card-big { width: calc(var(--cw, 60px) * .56); height: calc(var(--cw, 60px) * .56); }
.card-court { left: 12%; right: 12%; top: 30%; bottom: 7%; }
.card-court-frame {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: calc(var(--cw, 60px) * .08);
    background: var(--card-black-tint);
}
.card-red .card-court-frame { background: var(--card-red-tint); }
.card-court-letter { font-size: calc(var(--cw, 60px) * .46); font-weight: 800; line-height: 1; }
.card-court-suit { width: calc(var(--cw, 60px) * .22); height: calc(var(--cw, 60px) * .22); margin-top: calc(var(--cw, 60px) * .03); }

/* the back: a lattice on teal, a white frame, the monkey with his party hat */
.card-back {
    transform: rotateY(180deg);
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='52' r='46' fill='%23fffdf8'/%3E%3Ccircle cx='50' cy='52' r='42' fill='none' stroke='%23ffd23f' stroke-width='3'/%3E%3Cg stroke='%232b1610' stroke-width='3.5' stroke-linejoin='round'%3E%3Ccircle cx='25' cy='57' r='10' fill='%23f39c2b'/%3E%3Ccircle cx='75' cy='57' r='10' fill='%23f39c2b'/%3E%3Ccircle cx='50' cy='60' r='23' fill='%23f39c2b'/%3E%3C/g%3E%3Ccircle cx='25' cy='57' r='5' fill='%23ffe6b3'/%3E%3Ccircle cx='75' cy='57' r='5' fill='%23ffe6b3'/%3E%3Cpath d='M34 60c0-8 7-12 12-9 3 2 5 2 8 0 5-3 12 1 12 9 0 10-7 17-16 17s-16-7-16-17z' fill='%23ffe6b3'/%3E%3Ccircle cx='44' cy='60' r='3.6' fill='%232b1610'/%3E%3Ccircle cx='56' cy='60' r='3.6' fill='%232b1610'/%3E%3Ccircle cx='45' cy='58.8' r='1.2' fill='%23fff'/%3E%3Ccircle cx='57' cy='58.8' r='1.2' fill='%23fff'/%3E%3Cellipse cx='39' cy='67' rx='3' ry='1.7' fill='%23ff8b7a'/%3E%3Cellipse cx='61' cy='67' rx='3' ry='1.7' fill='%23ff8b7a'/%3E%3Cpath d='M44.5 69q5.5 5 11 0' fill='none' stroke='%232b1610' stroke-width='2.5' stroke-linecap='round'/%3E%3Cpath d='M39 39L50 15 61 39z' fill='%23259696' stroke='%232b1610' stroke-width='3.5' stroke-linejoin='round'/%3E%3Ccircle cx='50' cy='28' r='2.6' fill='%23ffd23f'/%3E%3Ccircle cx='50' cy='13' r='4.5' fill='%23ffd23f' stroke='%232b1610' stroke-width='2.5'/%3E%3C/svg%3E") center / 64% auto no-repeat,
        repeating-linear-gradient(45deg, var(--card-back-line) 0 2px, transparent 2px calc(var(--cw, 60px) * .14)),
        repeating-linear-gradient(-45deg, var(--card-back-line) 0 2px, transparent 2px calc(var(--cw, 60px) * .14)),
        var(--card-back);
    box-shadow:
        inset 0 0 0 calc(var(--cw, 60px) * .045) var(--card-face),
        inset 0 0 0 calc(var(--cw, 60px) * .07) var(--card-back-dark),
        0 0 0 1px var(--card-edge),
        0 1px 2px rgba(0, 0, 0, .18);
}

/* an empty place on the table, with a hint of what goes there */
.cards-slot {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--cw, 60px);
    height: calc(var(--cw, 60px) * 1.4);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border: 2px dashed var(--card-slot-line);
    border-radius: calc(var(--cw, 60px) * .1);
    background: var(--card-slot);
    color: var(--card-slot-line);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: calc(var(--cw, 60px) * .42);
    font-weight: 800;
    -webkit-tap-highlight-color: transparent;
}
.cards-slot svg { width: 45%; height: 45%; fill: currentColor; }

/* moving, dragged, chosen, not allowed */
.card-moving { will-change: transform; }
.card-dragging { transition: none; cursor: grabbing; }
.card-dragging .card-front, .card-dragging .card-back { box-shadow: 0 0 0 1px var(--card-edge), 0 10px 20px rgba(0, 0, 0, .28); }
.card-selected .card-front {
    box-shadow: 0 0 0 calc(var(--cw, 60px) * .05) var(--card-selected), 0 4px 12px rgba(0, 0, 0, .25);
}
.card-selected .card-flip { transform: translateY(calc(var(--cw, 60px) * -.08)); }
.card-nope .card-flip { animation: card-nope .35s ease-in-out; }
@keyframes card-nope {
    20% { transform: translateX(-12%); }
    50% { transform: translateX(9%); }
    80% { transform: translateX(-4%); }
}

@media (prefers-reduced-motion: reduce) {
    .card, .card-flip { transition: none; }
    .card-nope .card-flip { animation: none; }
}
