/* ── RESET & BASE ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --green: #1a6b3c;
    --green-dark: #0d4d2a;
    --green-light: #e8f5ec;
    --gold: #d4a017;
    --gold-light: #fef9e7;
    --red: #c0392b;
    --blue: #2980b9;
    --black: #1a1a2e;
    --white: #ffffff;
    --grey: #f4f4f8;
    --grey-mid: #bdc3c7;
    --grey-dark: #7f8c8d;
    --border: #ddd;
    --shadow: 0 2px 8px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.2);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;

    --card-width: 60px;
    --card-height: 90px;

    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--green-dark);
    color: #2c3e50;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* ── SCREENS ───────────────────────────────────────────── */
.screen {
    display: none;
    position: fixed;
    inset: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.screen.active { display: flex; }

/* ── HOME ──────────────────────────────────────────────── */
.home-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100%;
    padding: 40px 24px;
    background: linear-gradient(160deg, var(--green-dark) 0%, #0a3d1f 50%, var(--black) 100%);
}

.logo { text-align: center; margin-bottom: 48px; }
.logo-cards { font-size: 4em; margin-bottom: 12px; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3)); }
.logo h1 { color: var(--white); font-size: 2.4em; font-weight: 800; letter-spacing: -1px; }
.tagline { color: var(--gold); font-size: 1.3em; font-weight: 600; margin-top: 4px; letter-spacing: 4px; }
.version { color: rgba(255,255,255,0.3); font-size: 0.7em; margin-top: 4px; }

.auth-form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
    padding: 14px 18px;
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: var(--radius);
    background: rgba(255,255,255,0.1);
    color: var(--white);
    font-size: 1.1em;
    text-align: center;
    outline: none;
    transition: border-color var(--transition);
}
.auth-form input::placeholder { color: rgba(255,255,255,0.5); }
.auth-form input:focus { border-color: var(--gold); }
.welcome-msg { color: var(--white); text-align: center; font-size: 1.1em; }
.welcome-msg strong { color: var(--gold); }

/* ── BUTTONS ───────────────────────────────────────────── */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95em;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.btn-primary {
    background: var(--gold);
    color: var(--black);
}
.btn-primary:active { background: #b8920e; transform: scale(0.97); }

.btn-ghost {
    background: transparent;
    color: rgba(255,255,255,0.7);
    border: 1px solid rgba(255,255,255,0.2);
}
.btn-ghost:active { background: rgba(255,255,255,0.1); }

.btn-sm { padding: 8px 14px; font-size: 0.85em; border-radius: var(--radius-sm); }
.btn-full { width: 100%; }
.btn-danger { background: var(--red); color: var(--white); }

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── MENU ──────────────────────────────────────────────── */
.menu-container {
    width: 100%;
    min-height: 100%;
    padding: 40px 20px;
    background: linear-gradient(160deg, var(--green-dark), var(--black));
    display: flex;
    flex-direction: column;
    align-items: center;
}

.menu-container h2 { color: var(--white); font-size: 1.6em; margin-bottom: 24px; }

.menu-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    width: 100%;
    max-width: 400px;
}

.menu-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 24px 16px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: var(--radius);
    color: var(--white);
    font-size: 1em;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.menu-card:active { background: rgba(255,255,255,0.15); transform: scale(0.97); }
.menu-icon { font-size: 2em; }
.menu-label { font-weight: 600; font-size: 0.9em; }

.rules-links { display: grid; grid-template-columns: 1fr; gap: 12px; width: 100%; max-width: 400px; }

/* ── PANELS ────────────────────────────────────────────── */
.panel-container {
    width: 100%;
    min-height: 100%;
    padding: 16px 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
    background: linear-gradient(160deg, var(--green-dark), var(--black));
    display: flex;
    flex-direction: column;
    align-items: center;
}

.panel-container h2 { color: var(--white); font-size: 1.3em; margin-bottom: 14px; }

.btn-back {
    align-self: flex-start;
    background: none;
    border: none;
    color: var(--gold);
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
    margin-bottom: 8px;
}

.form-group { width: 100%; max-width: 400px; margin-bottom: 12px; }
.form-group label { color: rgba(255,255,255,0.7); font-size: 0.8em; font-weight: 600; display: block; margin-bottom: 4px; }

.form-group input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: var(--radius);
    background: rgba(255,255,255,0.1);
    color: var(--white);
    font-size: 1em;
    outline: none;
}
.form-group input:focus { border-color: var(--gold); }

/* ── MODE SELECT ───────────────────────────────────────── */
.mode-select {
    display: flex;
    gap: 6px;
    width: 100%;
    max-width: 400px;
    margin-bottom: 10px;
}

.mode-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: var(--radius);
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.7);
    font-size: 1em;
    font-weight: 800;
    cursor: pointer;
    transition: all var(--transition);
}

.mode-btn.active {
    background: var(--gold);
    color: var(--black);
    border-color: var(--gold);
}

/* ── TOGGLE ────────────────────────────────────────────── */
.toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    color: rgba(255,255,255,0.8) !important;
    font-size: 1em !important;
    padding: 12px 16px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius);
}

.toggle-label input { display: none; }

.toggle-slider {
    width: 54px;
    height: 30px;
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.2);
    border-radius: 15px;
    position: relative;
    transition: all var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(255,255,255,0.5);
    top: 2px;
    left: 2px;
    transition: all var(--transition);
}

.toggle-slider::after {
    content: 'OFF';
    position: absolute;
    right: 6px;
    top: 5px;
    font-size: 0.55em;
    font-weight: 700;
    color: rgba(255,255,255,0.4);
    transition: all var(--transition);
}

.toggle-label input:checked + .toggle-slider {
    background: var(--gold);
    border-color: #b8920e;
}

.toggle-label input:checked + .toggle-slider::before {
    transform: translateX(24px);
    background: white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.toggle-label input:checked + .toggle-slider::after {
    content: 'ON';
    right: auto;
    left: 6px;
    color: rgba(0,0,0,0.5);
}

/* ── DIFFICULTY SELECT ─────────────────────────────────── */
.diff-select {
    display: flex;
    gap: 6px;
    width: 100%;
    max-width: 400px;
    flex-wrap: wrap;
}

.diff-btn {
    flex: 1;
    min-width: 60px;
    padding: 10px 6px;
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.6);
    font-size: 0.75em;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.diff-btn:active { transform: scale(0.95); }

.diff-btn[data-diff="Beginner"].active { background: #27ae60; border-color: #27ae60; color: white; }
.diff-btn[data-diff="Novice"].active { background: #2980b9; border-color: #2980b9; color: white; }
.diff-btn[data-diff="SemiPro"].active { background: var(--gold); border-color: var(--gold); color: var(--black); }
.diff-btn[data-diff="Pro"].active { background: #e67e22; border-color: #e67e22; color: white; }
.diff-btn[data-diff="Legend"].active { background: #c0392b; border-color: #c0392b; color: white; }

/* ── OR DIVIDER ────────────────────────────────────────── */
.or-divider {
    color: rgba(255,255,255,0.4);
    text-align: center;
    margin: 20px 0;
    position: relative;
}
.or-divider span { background: transparent; padding: 0 12px; position: relative; z-index: 1; }

/* ── PUBLIC LOBBY ──────────────────────────────────────── */
.public-lobby h3 {
    color: rgba(255,255,255,0.7);
    font-size: 1em;
    margin: 0 0 10px;
}
.lobby-games-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 45vh;
    overflow-y: auto;
    padding-right: 4px;
}
.lobby-game-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    text-align: left;
    color: #fff;
    font-family: inherit;
    font-size: inherit;
    width: 100%;
}
.lobby-game-card:hover {
    background: rgba(255,255,255,0.15);
    border-color: #4caf50;
}
.lobby-game-top {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.lobby-game-host {
    font-weight: 600;
    flex: 1;
}
.lobby-game-tag {
    font-size: 0.75em;
    background: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    color: rgba(255,255,255,0.7);
}
.lobby-game-bottom {
    display: flex;
    justify-content: space-between;
    font-size: 0.85em;
    color: rgba(255,255,255,0.6);
}
.lobby-game-spots {
    color: #4caf50;
    font-weight: 600;
}

/* ── BADGES ────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--gold);
    color: var(--black);
    font-weight: 700;
    font-size: 0.85em;
}
.badge-dim { background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.7); }
.badge-sm { padding: 2px 8px; font-size: 0.75em; }

/* ── LOBBY ─────────────────────────────────────────────── */
.lobby-info { width: 100%; max-width: 400px; margin-bottom: 24px; }
.lobby-mode { display: flex; gap: 8px; margin-bottom: 16px; }

.share-box {
    background: rgba(255,255,255,0.08);
    border-radius: var(--radius);
    padding: 16px;
}
.share-box label { color: rgba(255,255,255,0.5); font-size: 0.8em; margin-bottom: 4px; display: block; }

.code-display {
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 2.2em;
    font-weight: 800;
    color: var(--gold);
    letter-spacing: 6px;
    text-align: center;
    padding: 8px 0;
}

.share-actions { display: flex; gap: 8px; margin-top: 12px; }
.share-actions .btn { flex: 1; background: rgba(255,255,255,0.12); color: var(--white); }

.lobby-players {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.lobby-player {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    color: var(--white);
}

.lobby-player .seat { width: 28px; height: 28px; border-radius: 50%; background: var(--green); display: flex; align-items: center; justify-content: center; font-size: 0.8em; font-weight: 700; }
.lobby-player .name { flex: 1; font-weight: 600; }
.lobby-player .tag { font-size: 0.8em; color: var(--gold); }

.bot-diff-select {
    background: rgba(255,255,255,0.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 0.75em;
    font-weight: 600;
    cursor: pointer;
}

.btn-remove-bot {
    background: rgba(192,57,43,0.3);
    color: #f85149;
    border: 1px solid rgba(192,57,43,0.4);
    border-radius: 6px;
    width: 26px;
    height: 26px;
    font-size: 0.8em;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-remove-bot:hover { background: rgba(192,57,43,0.6); }

.lobby-status { color: rgba(255,255,255,0.5); font-size: 0.9em; text-align: center; margin-bottom: 16px; }

/* ── GAME TABLE ────────────────────────────────────────── */
#screen-game {
    background: #1a1a2e;
    flex-direction: column;
}

.game-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: rgba(0,0,0,0.5);
    z-index: 10;
    flex-wrap: wrap;
    gap: 4px;
}

.game-info { display: flex; align-items: center; gap: 8px; }
.trump-display { color: var(--gold); font-weight: 700; font-size: 1em; }
.score-display { color: var(--white); font-size: 0.85em; font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.score-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 700;
    white-space: nowrap;
}

.score-pill.my-team { background: rgba(212,160,23,0.3); border: 1px solid var(--gold); color: var(--gold); }
.score-pill.other-team { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: rgba(255,255,255,0.8); }
.score-pill .pill-score { font-size: 1.1em; }
.score-pill .pill-pos { opacity: 0.6; font-size: 0.85em; }
.score-pill .pill-remaining { font-size: 0.7em; opacity: 0.6; }
.score-pill .pill-hand { font-size: 0.75em; color: #2ecc71; font-weight: 800; }

/* About to win — pulsing alert */
.score-pill.danger-close {
    background: rgba(231,76,60,0.3) !important;
    border-color: #e74c3c !important;
    color: #ff6b6b !important;
    animation: danger-pulse 1s infinite;
    transform: scale(1.08);
    z-index: 2;
}
.score-pill.danger-close.my-team {
    background: rgba(241,196,15,0.4) !important;
    border-color: #f1c40f !important;
    color: #f1c40f !important;
}
.score-pill.danger-close .pill-remaining {
    color: inherit !important;
    opacity: 1 !important;
    font-weight: 800;
}
@keyframes danger-pulse {
    0%, 100% { box-shadow: 0 0 6px rgba(231,76,60,0.4); }
    50% { box-shadow: 0 0 16px rgba(231,76,60,0.8); }
}

/* The round table */
.table-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    overflow: hidden;
}

.table-felt {
    position: relative;
    width: min(92vw, 520px);
    height: min(92vw, 520px);
    max-width: 520px;
    max-height: 520px;
    border-radius: 50%;
    background: radial-gradient(ellipse at 40% 40%, #2d8a54 0%, #1a6b3c 40%, #0f5a2e 70%, #0a3d1f 100%);
    box-shadow:
        0 0 0 12px #5c3a1e,
        0 0 0 16px #3d250f,
        0 0 0 18px rgba(0,0,0,0.5),
        0 8px 32px rgba(0,0,0,0.6),
        inset 0 2px 40px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.8s ease;
}

/* Trump-suit table colours */
.table-felt.trump-Hearts {
    background: radial-gradient(ellipse at 40% 40%, #8a2d2d 0%, #6b1a1a 40%, #5a0f0f 70%, #3d0a0a 100%);
}
.table-felt.trump-Diamonds {
    background: radial-gradient(ellipse at 40% 40%, #8a4a6b 0%, #6b2a4e 40%, #5a1a3d 70%, #3d0a28 100%);
}
.table-felt.trump-Clubs {
    background: radial-gradient(ellipse at 40% 40%, #2d4a8a 0%, #1a336b 40%, #0f245a 70%, #0a173d 100%);
}
.table-felt.trump-Spades {
    background: radial-gradient(ellipse at 40% 40%, #3a3a3a 0%, #2a2a2a 40%, #1a1a1a 70%, #111 100%);
}

/* On-table info — split into top badge and bottom strip */
.table-info {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 6;
}

/* Trump badge — bottom-centre of table */
.table-info-top {
    position: absolute;
    bottom: 4%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0,0,0,0.45);
    border-radius: 14px;
    padding: 3px 10px;
    border: 1px solid rgba(255,255,255,0.15);
}

.table-info-trump {
    font-size: 1.4em;
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.table-info-trump.suit-Hearts { color: #ff4444; }
.table-info-trump.suit-Diamonds { color: #ff88aa; }
.table-info-trump.suit-Clubs { color: #6ea8fe; }
.table-info-trump.suit-Spades { color: #ccc; }

.table-info-label {
    font-size: 0.55em;
    font-weight: 700;
    color: rgba(255,255,255,0.7);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.table-info-turned-up {
    font-size: 0.65em;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* Turned-up card — prominent mini card on the table */
.turned-up-card {
    position: absolute;
    bottom: 18%;
    left: 50%;
    transform: translateX(-50%);
    width: 44px;
    height: 62px;
    background: white;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5), 0 0 20px rgba(212,160,23,0.3);
    border: 2px solid var(--gold);
    z-index: 7;
    transition: all 0.3s ease;
}

.turned-up-rank { font-size: 1.1em; font-weight: 800; line-height: 1; }
.turned-up-suit { font-size: 1.3em; line-height: 1; }
.turned-up-rank.red, .turned-up-suit.red { color: #c0392b; }
.turned-up-rank.black, .turned-up-suit.black { color: #1a1a2e; }

.turned-up-card.robbed {
    opacity: 0.5;
    border-color: rgba(255,255,255,0.3);
    box-shadow: none;
}

.turned-up-x {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2em;
    font-weight: 900;
    color: #c0392b;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
    pointer-events: none;
}

/* Score chips — just above trump badge at bottom */
.table-info-bottom {
    position: absolute;
    bottom: 12%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 90%;
    max-width: 400px;
}

.table-info-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: rgba(0,0,0,0.45);
    border-radius: 10px;
    padding: 3px 7px;
    border: 1px solid rgba(255,255,255,0.12);
    font-size: 0.55em;
    font-weight: 700;
    color: rgba(255,255,255,0.85);
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    white-space: nowrap;
}

.table-info-chip.bid-chip { color: var(--gold); }
.table-info-chip.on-track { border-color: rgba(46,204,113,0.4); color: #2ecc71; }
.table-info-chip.behind { border-color: rgba(231,76,60,0.4); color: #e74c3c; }
.table-info-chip.trick-chip { color: rgba(255,255,255,0.5); }

/* Seats around the table edge */
.seats-ring {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.seat-spot {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    pointer-events: auto;
    transform: translate(-50%, -50%);
}

.seat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.75em;
    color: white;
    border: 2px solid rgba(255,255,255,0.3);
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.seat-avatar.teammate { background: linear-gradient(135deg, #b7950b, #d4a017); border-color: var(--gold); }
.seat-avatar.rival { background: linear-gradient(135deg, #2471a3, #2980b9); border-color: #5dade2; }
.seat-avatar.is-turn {
    animation: seat-pulse 1.2s infinite;
    border-color: #f1c40f;
    box-shadow: 0 0 12px rgba(241,196,15,0.6);
}

@keyframes seat-pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(241,196,15,0.4); }
    50% { box-shadow: 0 0 18px rgba(241,196,15,0.8); }
}

.seat-name {
    font-size: 0.65em;
    color: rgba(255,255,255,0.85);
    font-weight: 600;
    text-align: center;
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}

.seat-meta {
    display: flex;
    gap: 3px;
    align-items: center;
}

.seat-cards-count {
    font-size: 0.6em;
    color: rgba(255,255,255,0.5);
    background: rgba(0,0,0,0.3);
    padding: 1px 5px;
    border-radius: 6px;
}

.seat-tricks {
    font-size: 0.6em;
    color: var(--gold);
    font-weight: 700;
}

.seat-dealer {
    font-size: 0.6em;
    color: #f39c12;
}

.rob-badge {
    font-size: 0.75em;
    font-weight: 700;
    color: var(--gold);
    background: rgba(0,0,0,0.5);
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid var(--gold);
}

/* Centre trick area */
.table-centre {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.trick-cards {
    display: flex;
    gap: 4px;
    justify-content: center;
    flex-wrap: wrap;
}

.trick-message {
    color: var(--gold);
    font-weight: 700;
    font-size: 0.9em;
    text-align: center;
    margin-top: 6px;
    min-height: 20px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

/* Card in trick area */
.trick-cards .card {
    width: 48px;
    height: 70px;
    font-size: 0.8em;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.trick-cards .card .card-rank { font-size: 0.85em; }
.trick-cards .card .card-suit { font-size: 1em; }

.trick-card-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: all 0.3s ease;
}

.trick-card-wrapper.winning {
    transform: scale(1.15);
    z-index: 5;
}

.trick-card-wrapper.winning .card {
    box-shadow: 0 0 0 3px var(--gold), 0 4px 20px rgba(212,160,23,0.6), 0 0 30px rgba(212,160,23,0.2);
    border-color: var(--gold);
}

.trick-card-wrapper:not(.winning) {
    transform: scale(0.95);
    opacity: 0.7;
}

.trick-card-wrapper.winning .trick-card-name {
    color: var(--gold);
    font-weight: 700;
    font-size: 0.65em;
}

.trick-card-name {
    font-size: 0.55em;
    color: rgba(255,255,255,0.6);
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* Action panel */
.action-panel {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    padding: 8px 12px;
    background: rgba(0,0,0,0.4);
}

.action-panel .btn { min-width: 60px; }

/* Player hand */
.hand-area {
    padding: 8px 4px;
    padding-bottom: calc(12px + var(--safe-bottom));
    background: linear-gradient(to top, rgba(0,0,0,0.5), rgba(0,0,0,0.2));
}

.hand-cards {
    display: flex;
    justify-content: center;
    gap: 2px;
    overflow-x: auto;
    padding: 4px 8px;
    -webkit-overflow-scrolling: touch;
}

/* Kitty exchange: 2 rows of 5 cards, no scrolling */
.hand-cards.kitty-grid {
    flex-wrap: wrap;
    overflow-x: visible;
    gap: 4px 2px;
    max-width: 360px;
    margin: 0 auto;
}
.hand-cards.kitty-grid .card {
    width: calc(20% - 4px);
    min-width: 54px;
    max-width: 68px;
}

/* ── PLAYING CARDS ─────────────────────────────────────── */
.card {
    width: var(--card-width);
    height: var(--card-height);
    border-radius: 6px;
    background: white;
    border: 1px solid #ccc;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s;
    flex-shrink: 0;
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.card .card-rank { font-size: 0.95em; line-height: 1; }
.card .card-suit { font-size: 1.3em; line-height: 1; margin-top: 2px; }

.card.red { color: var(--red); }
.card.black { color: var(--black); }

.card.playable { cursor: pointer; }
.card.playable:hover { transform: translateY(-8px); box-shadow: 0 6px 14px rgba(0,0,0,0.3); }
.card.playable:active { transform: translateY(-4px) scale(0.97); }
.hand-cards.phase-playing .card:not(.playable) { opacity: 0.7; cursor: not-allowed; filter: grayscale(15%); }
.trick-cards .card { opacity: 1 !important; filter: none !important; cursor: default !important; }

.card.trump-card {
    border-color: var(--gold);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2), inset 0 0 0 1px rgba(212,160,23,0.3);
}

.card.trump-card::after {
    content: '★';
    position: absolute;
    top: 2px;
    right: 3px;
    font-size: 0.5em;
    color: var(--gold);
    opacity: 0.7;
}

/* Card play animation */
.card.trick-enter {
    animation: card-land 0.3s ease-out;
}

@keyframes card-land {
    0% { transform: translateY(-30px) scale(0.8); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* Card deal animation — card-back flies from centre to opponent seat */
.deal-flyer {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 32px;
    height: 44px;
    background: linear-gradient(135deg, #1a3a5c, #2a5a8c);
    border: 2px solid #fff;
    border-radius: 4px;
    pointer-events: none;
    z-index: 100;
    animation: deal-fly 0.5s ease-in-out forwards;
    --dest-x: 50%;
    --dest-y: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

@keyframes deal-fly {
    0% {
        left: 50%;
        top: 50%;
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }
    100% {
        left: var(--dest-x);
        top: var(--dest-y);
        opacity: 1;
        transform: translate(-50%, -50%) scale(0.8) rotate(-5deg);
    }
}

/* Deal for dealer cards */
.dealer-deal-card {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 36px;
    height: 50px;
    background: white;
    border: 2px solid #ccc;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85em;
    font-weight: 700;
    pointer-events: none;
    z-index: 100;
    animation: dealer-card-fly 0.5s ease-out forwards;
    --dest-x: 50%;
    --dest-y: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.dealer-deal-card.is-ace {
    border-color: var(--gold);
    box-shadow: 0 0 15px rgba(212,160,23,0.8), 0 2px 8px rgba(0,0,0,0.4);
    transform: translate(-50%, -50%) scale(1.3);
    z-index: 101;
}

@keyframes dealer-card-fly {
    0% {
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%) scale(0.8);
    }
    100% {
        left: var(--dest-x);
        top: var(--dest-y);
        transform: translate(-50%, -50%) scale(1);
    }
}

/* Trump reveal countdown */
.trump-countdown {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.4em;
    font-weight: 700;
    color: var(--gold);
    text-shadow: 0 0 20px rgba(212,160,23,0.4), 0 2px 6px rgba(0,0,0,0.5);
    animation: trump-pulse 1.5s ease-in-out infinite;
    z-index: 20;
    white-space: nowrap;
}

/* Big trump card reveal */
.trump-reveal-card {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 20;
    animation: trump-pop 0.5s cubic-bezier(0.2, 0.8, 0.3, 1.2) both;
    filter: drop-shadow(0 0 30px rgba(212,160,23,0.7)) drop-shadow(0 4px 10px rgba(0,0,0,0.5));
    transform-origin: center center;
    font-size: 1.2em;
}

@keyframes trump-pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1.05); opacity: 0.7; }
}

@keyframes trump-pop {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    60% { transform: translate(-50%, -50%) scale(1.5); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
}
}

/* Auto-play countdown */
.auto-play-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(0,0,0,0.75);
    color: #fff;
    font-size: 0.75em;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--gold);
    z-index: 10;
    pointer-events: none;
    animation: badge-pop 0.3s ease-out;
}

@keyframes badge-pop {
    0% { transform: scale(0); }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.card.auto-play-target {
    animation: auto-play-pulse 2s ease-in-out infinite;
    box-shadow: 0 0 12px rgba(212,160,23,0.5);
}

@keyframes auto-play-pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(212,160,23,0.4); }
    50% { box-shadow: 0 0 20px rgba(212,160,23,0.8); }
}

.card.auto-play-urgent .auto-play-badge {
    background: var(--red);
    border-color: #ff6b6b;
    animation: badge-shake 0.4s ease-in-out infinite;
}

.card.auto-play-urgent {
    animation: auto-play-pulse-urgent 0.5s ease-in-out infinite;
}

@keyframes auto-play-pulse-urgent {
    0%, 100% { box-shadow: 0 0 8px rgba(192,57,43,0.5); }
    50% { box-shadow: 0 0 24px rgba(192,57,43,0.9); }
}

@keyframes badge-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

/* Play hints */
.card.hint-card {
    box-shadow: 0 0 14px rgba(46,204,113,0.6), 0 0 4px rgba(46,204,113,0.3);
    border-color: #2ecc71;
}

.hint-badge {
    position: absolute;
    top: -10px;
    left: -10px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
    border: 2px solid #2ecc71;
    z-index: 10;
    pointer-events: none;
    animation: hint-glow 2s ease-in-out infinite;
}

@keyframes hint-glow {
    0%, 100% { box-shadow: 0 0 4px rgba(46,204,113,0.4); }
    50% { box-shadow: 0 0 12px rgba(46,204,113,0.8); }
}

.card.selected {
    transform: translateY(-16px);
    box-shadow: 0 0 0 3px var(--gold), 0 8px 16px rgba(0,0,0,0.3);
}

.card.pre-selected {
    transform: translateY(-12px);
    box-shadow: 0 0 12px rgba(52, 152, 219, 0.6), 0 0 0 2px rgba(52, 152, 219, 0.8);
    border-color: #3498db;
    animation: pre-select-pulse 1.5s ease-in-out infinite;
}

@keyframes pre-select-pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(52, 152, 219, 0.4), 0 0 0 2px rgba(52, 152, 219, 0.6); }
    50% { box-shadow: 0 0 16px rgba(52, 152, 219, 0.7), 0 0 0 2px rgba(52, 152, 219, 0.9); }
}

.card.joker-card {
    background: linear-gradient(135deg, #fff 0%, #fef9e7 100%);
    color: var(--gold);
}

.card.trump-indicator {
    border: 2px solid var(--gold);
    box-shadow: 0 0 8px rgba(212,160,23,0.3);
}

/* Card in trick area (slightly larger) */
.trick-cards .card {
    width: 52px;
    height: 76px;
    font-size: 0.85em;
}

.trick-cards .card .card-rank { font-size: 0.85em; }
.trick-cards .card .card-suit { font-size: 1.1em; }

/* ── LEADERBOARD ───────────────────────────────────────── */
.leaderboard-list { width: 100%; max-width: 500px; }

.lb-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    color: var(--white);
}

.lb-rank { width: 28px; font-weight: 800; color: var(--gold); text-align: center; }
.lb-name { flex: 1; font-weight: 600; }
.lb-rating { font-weight: 700; color: var(--gold); }
.lb-winrate { font-size: 0.8em; color: var(--grey-mid); }

.lb-row:nth-child(1) .lb-rank { font-size: 1.3em; }
.lb-row:nth-child(2) .lb-rank { font-size: 1.15em; }
.lb-row:nth-child(3) .lb-rank { font-size: 1.05em; }

/* ── PROFILE ───────────────────────────────────────────── */
.profile-header { text-align: center; margin-bottom: 24px; }
.profile-header h3 { color: var(--gold); font-size: 1.4em; }
.profile-header .since { color: var(--grey-mid); font-size: 0.85em; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 400px;
    margin-bottom: 20px;
}

.stat-card {
    background: rgba(255,255,255,0.08);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
}

.stat-value { font-size: 1.6em; font-weight: 800; color: var(--gold); display: block; }
.stat-label { font-size: 0.75em; color: var(--grey-mid); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }

.recent-games { width: 100%; max-width: 400px; }
.recent-games h4 { color: var(--white); margin-bottom: 10px; }

.recent-game {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    color: var(--white);
    font-size: 0.9em;
}

.recent-game .result { font-weight: 700; width: 36px; text-align: center; }
.recent-game .result.win { color: var(--gold); }
.recent-game .result.loss { color: var(--red); }
.recent-game .details { flex: 1; }
.recent-game .rating-change { font-weight: 700; }
.recent-game .rating-change.positive { color: var(--gold); }
.recent-game .rating-change.negative { color: var(--red); }

/* ── TOAST ─────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    color: var(--white);
    font-weight: 600;
    font-size: 0.9em;
    text-align: center;
    animation: toast-in 0.3s, toast-out 0.3s 2.7s forwards;
    box-shadow: var(--shadow-lg);
}

.toast-error { background: var(--red); }
.toast-success { background: var(--green); }
.toast-info { background: var(--blue); }

@keyframes toast-in { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-20px); } }

/* ── CHAT ──────────────────────────────────────────────── */
.chat-toggle {
    position: fixed;
    bottom: 70px;
    right: 12px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    font-size: 1.1em;
    cursor: pointer;
    z-index: 100;
    display: none;
}

#screen-game.active ~ .chat-toggle { display: flex; align-items: center; justify-content: center; }

.chat-input-bar {
    position: fixed;
    bottom: 70px;
    left: 12px;
    right: 60px;
    display: flex;
    gap: 6px;
    z-index: 100;
}

.chat-input-bar input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 20px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 0.85em;
    outline: none;
}

.chat-input-bar button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gold);
    color: var(--black);
    border: none;
    font-size: 1em;
    font-weight: 800;
    cursor: pointer;
}

/* ── MODAL ─────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    backdrop-filter: blur(4px);
    animation: modal-fade-in 0.3s ease;
}

@keyframes modal-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-box {
    background: var(--white);
    border-radius: 16px;
    padding: 32px 28px;
    max-width: 400px;
    width: 100%;
    text-align: center;
    box-shadow: 0 16px 48px rgba(0,0,0,0.4);
    animation: modal-slide-up 0.3s ease;
}

@keyframes modal-slide-up {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-box h3 { margin-bottom: 16px; color: var(--green-dark); font-size: 1.4em; }
.modal-box #modal-body { margin-bottom: 20px; color: #555; line-height: 1.6; }
.modal-box #modal-actions { display: flex; gap: 10px; justify-content: center; }

/* ── UTILITIES ─────────────────────────────────────────── */
.hidden { display: none !important; }
.empty-state { color: rgba(255,255,255,0.4); text-align: center; padding: 40px 0; }

/* ── RESPONSIVE ────────────────────────────────────────── */
@media (min-width: 500px) {
    :root { --card-width: 70px; --card-height: 105px; }
    .trick-cards .card { width: 56px; height: 82px; }
    .seat-avatar { width: 44px; height: 44px; font-size: 0.85em; }
}

@media (min-width: 768px) {
    :root { --card-width: 80px; --card-height: 120px; }
    .trick-cards .card { width: 64px; height: 94px; }
    .table-felt { width: min(80vw, 560px); height: min(80vw, 560px); max-width: 560px; max-height: 560px; }
    .seat-avatar { width: 48px; height: 48px; font-size: 0.9em; }
    .seat-name { font-size: 0.75em; max-width: 90px; }
}
