/* Belot — premium dark casino theme */
:root {
    --bg-deep: #06281b;
    --bg: #0a3d2a;
    --bg-light: #134d36;
    --gold: #d4af37;
    --gold-bright: #f4d36c;
    --text: #f4f1e8;
    --text-dim: rgba(244, 241, 232, 0.6);
    --red: #c8332e;
    --black: #1a1a1a;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    --radius: 10px;
    --radius-sm: 6px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, sans-serif;
    background: radial-gradient(ellipse at center, var(--bg) 0%, var(--bg-deep) 100%);
    color: var(--text);
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#app { height: 100%; position: relative; }

.screen {
    position: absolute; inset: 0;
    display: none;
    align-items: center; justify-content: center;
    padding: 1rem;
}
.screen.visible { display: flex; flex-direction: column; }

/* === LOBBY === */
.brand {
    text-align: center;
    margin-bottom: 2rem;
}
.brand h1 {
    font-size: clamp(1.8rem, 5vw, 3rem);
    font-weight: 700;
    letter-spacing: 0.04em;
}
.gold { color: var(--gold); }
.subtitle {
    color: var(--text-dim);
    margin-top: 0.5rem;
    font-size: 0.95rem;
}

.card {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 380px;
}

.field {
    display: block;
    margin-bottom: 1rem;
}
.field span {
    display: block;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 0.4rem;
}
.field input {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(212, 175, 55, 0.25);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
    transition: border 0.15s;
}
.field input:focus {
    outline: none;
    border-color: var(--gold);
}

.actions { display: flex; gap: 0.5rem; }

.btn {
    flex: 1;
    padding: 0.8rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, filter 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-bright) 100%);
    color: var(--black);
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary {
    background: var(--bg-light);
    color: var(--text);
    border: 1px solid rgba(212, 175, 55, 0.3);
}
.btn-tertiary {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid rgba(244, 241, 232, 0.15);
}
.btn-warning {
    background: linear-gradient(135deg, #c0392b 0%, #e74c3c 100%);
    color: #fff;
    border: 1px solid rgba(255, 100, 100, 0.6);
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.btn-warning:hover { filter: brightness(1.1); }

.divider {
    text-align: center;
    margin: 1rem 0;
    position: relative;
    color: var(--text-dim);
    font-size: 0.85rem;
}
.divider::before, .divider::after {
    content: ''; position: absolute; top: 50%;
    width: calc(50% - 1.5rem);
    height: 1px; background: rgba(212, 175, 55, 0.2);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

.hint {
    margin-top: 1rem;
    color: var(--text-dim);
    font-size: 0.85rem;
    min-height: 1.2em;
    text-align: center;
}
.hint.error { color: var(--red); }

/* === TABLE === */
#table.visible { padding: 0; }
.table-frame {
    width: 100%; height: 100%;
    position: relative;
    background: radial-gradient(ellipse at center, var(--bg-light) 0%, var(--bg-deep) 80%);
    overflow: hidden;
}

.table-info {
    position: absolute; top: 3.5rem; left: 0.75rem; right: 11rem;
    display: flex; gap: 0.5rem; flex-wrap: wrap;
    z-index: 5;
}
.badge, .score, .phase {
    background: rgba(0, 0, 0, 0.7);
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    font-size: 0.85rem;
    border: 1px solid rgba(212, 175, 55, 0.35);
    color: var(--text);
}
.badge { color: var(--gold); font-family: monospace; letter-spacing: 0.1em; }
.score { color: var(--text); }
.phase { color: var(--gold); font-weight: 600; }

.table-actions {
    position: absolute; top: 3.5rem; right: 5.5rem;
    z-index: 7;
    display: flex; gap: 0.4rem;
}
.leave-btn {
    position: absolute; top: 3.5rem; right: 0.75rem;
    z-index: 7; padding: 0.4rem 0.8rem; flex: none;
}

/* Seats */
.seats {
    position: absolute; inset: 0;
}
.seat {
    position: absolute;
    display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
}
.seat.active .seat-name {
    color: var(--gold);
    text-shadow: 0 0 8px var(--gold);
}
.seat.active {
    animation: pulse-seat 1.6s ease-in-out infinite;
}
.seat.contract-holder .seat-name {
    border: 1px solid var(--gold);
    box-shadow: 0 0 6px rgba(212,175,55,0.4);
}
@keyframes pulse-seat {
    0%, 100% { filter: drop-shadow(0 0 0 transparent); }
    50% { filter: drop-shadow(0 0 6px var(--gold)); }
}
.seat-label {
    font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase;
}
.seat-name {
    font-size: 0.9rem; color: var(--text); font-weight: 500;
    background: rgba(0, 0, 0, 0.55);
    padding: 0.25rem 0.7rem; border-radius: 6px;
    display: inline-flex; align-items: center; gap: 0.4rem;
    border: 1px solid rgba(255,255,255,0.08);
}
.seat-name .seat-flag {
    background: var(--gold); color: #000;
    font-size: 0.65rem; font-weight: 700;
    width: 18px; height: 18px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
}
.seat-name .seat-flag[hidden] { display: none !important; }
.seat-name .team-tag[hidden] { display: none !important; }
.seat-bubble[hidden] { display: none !important; }
.btn-icon {
    background: rgba(0,0,0,0.3); border: 1px solid rgba(212,175,55,0.4);
    color: var(--gold); font-size: 1rem; cursor: pointer;
    width: 32px; height: 32px; border-radius: 6px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all 0.15s;
}
.btn-icon:hover { background: rgba(212,175,55,0.15); }
.btn-icon.muted { opacity: 0.45; }

/* Waiting room */
.waiting-room {
    position: relative;
    max-width: 540px; margin: 2rem auto; padding: 2.5rem 2rem;
    background: rgba(0,0,0,0.4); border: 1px solid var(--gold);
    border-radius: 12px; text-align: center;
}
.waiting-room h2 { color: var(--gold); margin: 0 0 0.5rem; }
.waiting-room .hint { color: var(--text-dim); margin: 0 0 1rem; }
.waiting-code {
    font-size: 2.6rem; font-weight: 800; letter-spacing: 0.4em;
    color: var(--gold); font-family: monospace;
    background: rgba(0,0,0,0.4); border: 1px dashed rgba(212,175,55,0.5);
    border-radius: 8px; padding: 0.8rem 0; margin: 0.5rem 0 1rem;
    user-select: all; cursor: text;
}
.waiting-seats {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem; margin: 1.2rem 0;
}
.waiting-seat {
    padding: 0.7rem; border-radius: 8px; background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
    color: var(--text-dim); font-size: 0.95rem; min-height: 48px;
}
.waiting-seat.filled { color: var(--text); border-color: var(--gold); background: rgba(212,175,55,0.08); }
.waiting-seat.me { background: rgba(212,175,55,0.18); font-weight: 700; }
.waiting-seat.empty::before { content: '…'; color: var(--text-dim); }
.waiting-actions { justify-content: center; margin-top: 1rem; }
@media (max-width: 480px) {
    .waiting-seats { grid-template-columns: 1fr; }
    .waiting-code { font-size: 2rem; letter-spacing: 0.3em; }
}

/* Score modal */
.score-summary { display: flex; gap: 1rem; justify-content: center; margin-bottom: 0.5rem; }
.score-card {
    flex: 1; max-width: 160px;
    padding: 0.8rem; border-radius: 8px; text-align: center;
    background: rgba(0,0,0,0.3); border: 1px solid rgba(212,175,55,0.3);
}
.score-card.mine { border-color: var(--gold); background: rgba(212,175,55,0.1); }
.score-card .label { font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.score-card .value { font-size: 2rem; font-weight: 800; color: var(--gold); margin-top: 0.2rem; }
.score-table { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: 0.9rem; }
.score-table th, .score-table td { padding: 0.4rem 0.6rem; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.08); }
.score-table th { color: var(--gold); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
.score-table td:first-child { color: var(--text-dim); width: 30px; }
.score-table td:last-child { color: var(--text-dim); font-style: italic; font-size: 0.8rem; }
.seat-name .team-tag {
    font-size: 0.65rem;
    padding: 0.05rem 0.4rem; border-radius: 3px;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.seat-name .team-tag.us { background: rgba(46,204,113,0.25); color: #2ecc71; }
.seat-name .team-tag.them { background: rgba(231,76,60,0.25); color: #e74c3c; }

/* Speech bubble showing each seat's last action */
.seat-bubble {
    position: absolute;
    background: #fff; color: #1a1a1a;
    padding: 0.3rem 0.7rem; border-radius: 14px;
    font-size: 0.78rem; font-weight: 600;
    box-shadow: 0 2px 6px rgba(0,0,0,0.5);
    white-space: nowrap;
    z-index: 20;
    animation: bubble-pop 0.25s ease-out;
    max-width: 240px;
    line-height: 1.3;
}
.seat-bubble.contract { white-space: nowrap; }
.seat-bubble::after {
    content: '';
    position: absolute;
    width: 0; height: 0;
    border: 6px solid transparent;
}
.seat-bubble.bid { background: #fef3c7; color: #78350f; }
.seat-bubble.pass { background: #e5e7eb; color: #6b7280; font-style: italic; }
.seat-bubble.contra { background: #fee2e2; color: #b91c1c; }
.seat-bubble.contract { background: var(--gold); color: #000; font-weight: 700; }
.seat-bubble.declared {
    background: linear-gradient(135deg, #fff8d6 0%, #ffe28a 100%);
    color: #5a3d08;
    border: 1px solid #d4af37;
    box-shadow: 0 0 12px rgba(212, 175, 55, 0.55), 0 2px 6px rgba(0,0,0,0.4);
    white-space: nowrap; max-width: 220px; line-height: 1.3;
    font-size: 0.78rem;
}
.seat-bubble.declared small { font-size: 0.7em; opacity: 0.78; margin-left: 2px; }
.seat-bubble.declared.no-decl {
    background: rgba(229, 231, 235, 0.85);
    color: #6b7280;
    border-color: rgba(255,255,255,0.2);
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
    font-style: italic;
}
.seat-bubble.with-decl { white-space: normal; max-width: 200px; line-height: 1.3; }
.seat-bubble .decl-extra {
    display: inline-block;
    margin-top: 4px;
    padding: 2px 6px;
    background: rgba(212, 175, 55, 0.25);
    border-radius: 6px;
    font-size: 0.78em;
    font-weight: 500;
}
.seat-bubble .decl-extra small { font-size: 0.85em; opacity: 0.8; }
@keyframes bubble-pop {
    0% { transform: scale(0.6); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
/* Bubble positions per seat side */
.seat-north .seat-bubble { top: 100%; left: 50%; transform: translateX(-50%); margin-top: 0.3rem; }
.seat-north .seat-bubble::after { top: -10px; left: 50%; transform: translateX(-50%); border-bottom-color: inherit; border-bottom-color: currentColor; }
.seat-south .seat-bubble { bottom: 100%; left: 50%; transform: translateX(-50%); margin-bottom: 0.3rem; }
.seat-south .seat-bubble::after { bottom: -10px; left: 50%; transform: translateX(-50%); border-top-color: currentColor; }
.seat-east .seat-bubble { right: 100%; top: 50%; transform: translateY(-50%); margin-right: 0.4rem; }
.seat-east .seat-bubble::after { right: -10px; top: 50%; transform: translateY(-50%); border-left-color: currentColor; }
.seat-west .seat-bubble { left: 100%; top: 50%; transform: translateY(-50%); margin-left: 0.4rem; }
.seat-west .seat-bubble::after { left: -10px; top: 50%; transform: translateY(-50%); border-right-color: currentColor; }

.seat-cards { display: flex; gap: -0.5rem; }
.seat-cards .card-back {
    width: 28px; height: 40px;
    border-radius: 3px;
    margin-left: -10px;
    /* Класически български гръб — тъмночервен орнамент (мини) */
    background:
        repeating-linear-gradient(45deg, transparent 0 3px, rgba(0,0,0,0.18) 3px 4px),
        repeating-linear-gradient(-45deg, transparent 0 3px, rgba(0,0,0,0.18) 3px 4px),
        radial-gradient(ellipse at center, #b22a2a 0%, #7a1818 100%);
    border: 1px solid #4a0e0e;
    box-shadow: inset 0 0 0 1px rgba(255, 215, 0, 0.5), 1px 1px 3px rgba(0,0,0,0.5);
}
.seat-cards .card-back:first-child { margin-left: 0; }

.seat-north { top: 4rem; left: 50%; transform: translateX(-50%); }
.seat-east  { top: 50%; right: 1rem; transform: translateY(-50%); flex-direction: row; }
.seat-west  { top: 50%; left: 1rem; transform: translateY(-50%); flex-direction: row-reverse; }
.seat-south { bottom: 13.5rem; left: 50%; transform: translateX(-50%); }

/* Trick area (middle of the table) */
.trick-area {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 240px; height: 200px;
    pointer-events: none;
}
.trick-card {
    position: absolute;
    width: 78px; height: 112px;
    background: #fdfaf2;
    border-radius: 6px;
    overflow: hidden;
    z-index: 5;
    box-shadow:
        inset 0 0 0 1px rgba(0,0,0,0.1),
        0 4px 12px rgba(0,0,0,0.55),
        0 1px 2px rgba(0,0,0,0.35);
    transition: all 0.3s;
}
.trick-card[data-seat="0"] { top: 4px; left: 50%; transform: translateX(-50%); }
.trick-card[data-seat="1"] { top: 50%; right: 4px; transform: translateY(-50%); }
.trick-card[data-seat="2"] { bottom: 4px; left: 50%; transform: translateX(-50%); }
.trick-card[data-seat="3"] { top: 50%; left: 4px; transform: translateY(-50%); }

/* Анимация: разиграване на карта (плъзва от мястото играч към центъра) */
.trick-card.entering {
    animation: cardEnter 0.32s cubic-bezier(0.22, 0.8, 0.4, 1.05);
}
@keyframes cardEnter {
    0%   { opacity: 0; transform: translate(var(--enter-tx, 0), var(--enter-ty, 0)) scale(0.7) rotate(var(--enter-rot, 0deg)); }
    100% { opacity: 1; transform: var(--final-transform); }
}
.trick-card[data-seat="0"].entering { --final-transform: translateX(-50%); --enter-ty: -120px; }
.trick-card[data-seat="1"].entering { --final-transform: translateY(-50%); --enter-tx: 160px; }
.trick-card[data-seat="2"].entering { --final-transform: translateX(-50%); --enter-ty: 120px; }
.trick-card[data-seat="3"].entering { --final-transform: translateY(-50%); --enter-tx: -160px; }

/* Анимация: прибиране на трик (всички карти летят към печелившия) */
.trick-card.collecting {
    transition: transform 0.45s cubic-bezier(0.5, 0, 0.7, 1.4), opacity 0.45s ease-in;
    transform: translate(var(--collect-tx, 0), var(--collect-ty, 0)) scale(0.4) rotate(var(--collect-rot, 0deg)) !important;
    opacity: 0;
    pointer-events: none;
    z-index: 6;
}

/* Highlight на победителя при прибиране */
.seat.collecting-winner .seat-cards { animation: winnerPulse 0.6s ease; }
@keyframes winnerPulse {
    0%, 100% { filter: brightness(1); transform: scale(1); }
    40%      { filter: brightness(1.5) drop-shadow(0 0 12px var(--gold)); transform: scale(1.08); }
}

/* Водеща карта — златен ореол */
.trick-card.lead-card {
    box-shadow: 0 0 0 2px var(--gold), 0 0 16px 4px rgba(212, 175, 55, 0.55), 0 3px 10px rgba(0,0,0,0.5);
    animation: leadCardGlow 2.2s ease-in-out infinite;
}
@keyframes leadCardGlow {
    0%, 100% { box-shadow: 0 0 0 2px var(--gold), 0 0 12px 3px rgba(212, 175, 55, 0.45), 0 3px 10px rgba(0,0,0,0.5); }
    50%      { box-shadow: 0 0 0 2px var(--gold), 0 0 22px 6px rgba(212, 175, 55, 0.85), 0 3px 10px rgba(0,0,0,0.5); }
}

/* Индикатор 'Търси се ♦' */
.suit-required {
    position: absolute;
    top: calc(50% - 130px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.78);
    color: var(--gold);
    border: 1px solid rgba(212, 175, 55, 0.6);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    pointer-events: none;
    z-index: 5;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.suit-required .suit-glyph {
    font-size: 1.05rem;
    margin-left: 4px;
    vertical-align: -1px;
    color: #fff;
}
.suit-required .suit-glyph.red { color: #f04646; }

/* Камари с взети трикове (моя отбор / противник) */
.tricks-pile {
    position: absolute;
    z-index: 4;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: transform 0.2s ease;
}
.tricks-pile.pile-mine {
    bottom: 6.5rem;
    right: 0.75rem;
}
/* На десктоп — десният горен ъгъл (избягва event-log вляво) */
.tricks-pile.pile-them {
    top: 7rem;
    right: 5.5rem;
}
.pile-stack {
    position: relative;
    width: 36px; height: 50px;
}
.pile-card {
    position: absolute;
    width: 36px; height: 50px;
    border-radius: 4px;
    background:
        repeating-linear-gradient(45deg, #2a4a8c, #2a4a8c 4px, #1f3a6e 4px, #1f3a6e 8px);
    border: 1.5px solid #ffffff44;
    box-shadow: 0 2px 6px rgba(0,0,0,0.45);
    opacity: 0.5;
}
.tricks-pile.has-cards .pile-card { opacity: 1; }
.pile-card:nth-child(1) { transform: translate(-3px, -3px) rotate(-4deg); }
.pile-card:nth-child(2) { transform: translate(2px, 2px) rotate(3deg); }
.pile-count {
    background: rgba(0,0,0,0.7);
    color: var(--gold);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid rgba(212, 175, 55, 0.4);
    white-space: nowrap;
}
.pile-count .pile-num {
    color: #fff;
    font-size: 0.85rem;
    margin-right: 2px;
}
.tricks-pile.pile-pulse { animation: pilePulse 0.55s ease; }
@keyframes pilePulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.18); filter: drop-shadow(0 0 10px var(--gold)); }
}

/* My hand */
.my-hand {
    position: absolute;
    bottom: 1rem; left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: -0.5rem;
    z-index: 4;
}
.hand-card {
    width: 84px; height: 124px;
    z-index: 6;
    /* Бяла карта — SVG спрайт отгоре */
    background: #fdfaf2;
    border-radius: 7px;
    margin-left: -32px;
    box-shadow:
        inset 0 0 0 1px rgba(0,0,0,0.12),
        0 6px 14px rgba(0,0,0,0.55),
        0 2px 4px rgba(0,0,0,0.35);
    cursor: pointer;
    /* Веер — всяка карта се завърта от долния център */
    transform-origin: 50% 130%;
    --fan-deg: calc(var(--card-centered, 0) * 4deg);
    --fan-y: calc(var(--card-centered, 0) * var(--card-centered, 0) * 0.8px);
    transform: rotate(var(--fan-deg)) translateY(var(--fan-y));
    transition: transform 0.18s ease-out, opacity 0.2s;
    position: relative;
    overflow: hidden;
}
.hand-card .card-svg, .trick-card .card-svg {
    width: 100%; height: 100%;
    display: block;
    pointer-events: none;
}
.card-fallback {
    width: 100%; height: 100%;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: #1a1a1a; font-weight: 700;
}
.suit-H .card-fallback, .suit-D .card-fallback { color: #c0181f; }
.hand-card:first-child { margin-left: 0; }
.hand-card:hover {
    /* Hover — картата се изправя и вдига */
    transform: rotate(0deg) translateY(-14px) scale(1.08);
    z-index: 10;
    box-shadow:
        inset 0 0 0 1px rgba(0,0,0,0.12),
        inset 0 0 0 2px rgba(255,255,255,0.55),
        0 12px 24px rgba(0,0,0,0.65),
        0 4px 8px rgba(0,0,0,0.4);
}
.hand-card.illegal {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(0.5);
}
.hand-card.illegal:hover {
    transform: rotate(var(--fan-deg)) translateY(var(--fan-y));
}
/* SVG картите обработват всичко отвътре (ъгли, център, цветове) */

/* Action bar — shown for bidding & start */
.action-bar {
    position: absolute;
    bottom: 9.5rem; left: 50%;
    transform: translateX(-50%);
    display: flex; gap: 0.4rem; flex-wrap: nowrap; justify-content: center;
    max-width: 96%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    z-index: 15;
}
.action-bar::-webkit-scrollbar { height: 4px; }
.action-bar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }
.action-bar .btn {
    flex: 0 0 auto;
    padding: 0.5rem 0.75rem;
    font-size: 0.88rem;
    white-space: nowrap;
}

/* Event log */
.event-log {
    position: absolute;
    top: 7rem; left: 0.75rem;
    width: 220px;
    max-height: 25vh;
    overflow-y: auto;
    font-size: 0.78rem;
    color: var(--text-dim);
    line-height: 1.5;
    pointer-events: none;
}
.event-log .ev { background: rgba(0,0,0,0.3); padding: 0.2rem 0.5rem; margin-bottom: 2px; border-radius: 3px; }

/* ============================================================
   Auth modal & top bar (Phase 2)
   ============================================================ */
.top-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 48px;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 50;
    border-bottom: 1px solid rgba(212, 175, 55, 0.15);
}
.top-bar .brand-mini { color: var(--gold); font-weight: 700; font-size: 0.95rem; letter-spacing: 0.05em; }
.top-bar .user-info { display: flex; align-items: center; gap: 0.75rem; font-size: 0.85rem; color: var(--text-dim); }
.top-bar .user-info strong { color: var(--gold); }
.top-bar .chips { background: rgba(212, 175, 55, 0.15); padding: 0.25rem 0.6rem; border-radius: 12px; color: var(--gold); font-weight: 600; }
.top-bar .btn-mini {
    background: transparent;
    border: 1px solid rgba(212, 175, 55, 0.4);
    color: var(--gold);
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    border-radius: 6px;
    cursor: pointer;
}
.top-bar .btn-mini:hover { background: rgba(212, 175, 55, 0.1); }

/* Modal overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal-overlay.visible { display: flex; }
.modal {
    background: linear-gradient(135deg, #0a3d2a 0%, #06291c 100%);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h2 { color: var(--gold); margin: 0 0 1rem 0; text-align: center; }
.modal .modal-close {
    position: absolute;
    top: 0.75rem; right: 0.75rem;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
}
.modal .tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(212, 175, 55, 0.2);
}
.modal .tab {
    flex: 1;
    padding: 0.6rem;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.95rem;
    border-bottom: 2px solid transparent;
}
.modal .tab.active { color: var(--gold); border-bottom-color: var(--gold); }
.modal .auth-error { color: #ff6b6b; font-size: 0.85rem; margin-top: 0.5rem; min-height: 1em; }
.modal .auth-success { color: #6bff95; font-size: 0.85rem; margin-top: 0.5rem; min-height: 1em; }

/* Hand-end summary modal */
.summary-modal { max-width: 520px; }
.summary-modal table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.9rem; }
.summary-modal th, .summary-modal td { padding: 0.5rem; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.08); }
.summary-modal th { color: var(--gold); font-weight: 600; }
.summary-modal .row-total { font-weight: 700; color: var(--gold); border-top: 2px solid rgba(212, 175, 55, 0.4); }
.summary-modal .winner-badge {
    display: inline-block;
    padding: 0.3rem 0.8rem;
    background: rgba(212, 175, 55, 0.15);
    color: var(--gold);
    border-radius: 6px;
    font-size: 0.85rem;
    margin-left: 0.5rem;
}
.summary-modal .hung-badge { color: #ff8c66; }

/* Toast notifications */
.toast {
    position: fixed;
    top: 60px; left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: var(--gold);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    border: 1px solid rgba(212, 175, 55, 0.3);
    z-index: 200;
    font-size: 0.9rem;
    animation: toast-in 0.3s ease-out;
}
.toast.error { color: #ff8c8c; border-color: rgba(255,107,107,0.4); }
@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, -10px); }
    to { opacity: 1; transform: translateX(-50%); }
}

/* ============================================================
   Mobile (≤ 600px) — оптимизиран вертикален лейаут
   ============================================================ */
@media (max-width: 600px) {
    /* Topbar — компактно */
    .top-bar { height: 42px; padding: 0 0.6rem; }
    .top-bar .brand-mini { font-size: 0.85rem; }
    .top-bar .user-info { gap: 0.4rem; font-size: 0.78rem; }
    .top-bar .user-info span:not(.chips):not(strong) { display: none; }
    .top-bar .chips { padding: 0.2rem 0.45rem; font-size: 0.78rem; }
    .top-bar .btn-mini { padding: 0.25rem 0.5rem; font-size: 0.72rem; }

    /* Lobby — по-малък hero, отстраняване на overlap с topbar */
    #lobby { padding-top: 3rem; }
    .brand h1 { font-size: 1.6rem; }
    .brand .subtitle { font-size: 0.85rem; }
    .card { padding: 1.2rem; }

    /* Table info — Ние/Вие в хедъра на мобайл */
    #table.visible { padding-top: 0; }
    .table-info {
        top: 2.9rem; left: 0.4rem; right: 3rem;
        gap: 0.25rem; flex-wrap: wrap;
        font-size: 0.7rem;
        justify-content: flex-start;
    }
    .badge, .score, .phase {
        padding: 0.2rem 0.45rem; font-size: 0.68rem;
        white-space: nowrap;
    }
    /* На мобайл — Ние/Вие са ярко златни (имитираме хедър вид) */
    .score { color: var(--gold); font-weight: 600; }
    /* Скривам room badge — отива в хамбургер меню */
    #room-code-badge { display: none; }
    .table-actions {
        top: 2.9rem; right: 0.4rem;
        gap: 0.3rem;
    }
    .btn-icon { width: 30px; height: 30px; font-size: 0.95rem; padding: 0; }
    /* Скривам иконките вдясно — само хамбургерът остава видим */
    #score-btn, #sound-toggle, #tts-toggle { display: none; }
    /* Изход бутонът — скривам от виждане (идва от хамбургер меню) */
    .leave-btn { display: none; }

    /* Seats — върху mobile ботовете/партньорите са компактни и в кътовете */
    .seat-north {
        top: 5.2rem; left: 50%;
        transform: translateX(-50%);
    }
    .seat-east {
        top: 9.5rem; right: 0.3rem; left: auto;
        transform: none;
        flex-direction: column;
        align-items: flex-end;
        gap: 0.2rem;
    }
    .seat-west {
        top: 9.5rem; left: 0.3rem; right: auto;
        transform: none;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.2rem;
    }
    /* South seat е скрит — играчът вижда собствените си карти долу */
    .seat-south { display: none; }
    .seat-name {
        font-size: 0.72rem;
        padding: 0.18rem 0.5rem;
        max-width: 130px;
        white-space: nowrap;
    }
    /* Никакъв truncate — имената бяха ≤5 символа */
    .seat-name .name { max-width: none; overflow: visible; }
    .seat-name .seat-flag { width: 12px; height: 12px; font-size: 0.5rem; }
    .seat-name .team-tag { font-size: 0.5rem; padding: 0.05rem 0.25rem; }
    .seat-cards { gap: 0; }
    .seat-cards .card-back { width: 14px; height: 22px; margin-left: -8px; }
    .seat-east .seat-cards, .seat-west .seat-cards { display: none; } /* пести място */
    .seat-north .seat-cards { transform: scale(0.75); }

    /* Bid bubbles — по-малки на mobile */
    .seat-bubble {
        font-size: 0.7rem;
        padding: 0.22rem 0.5rem;
        max-width: 140px;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .seat-bubble.contract { max-width: 160px; }
    .seat-bubble.declared { max-width: 150px; font-size: 0.7rem; padding: 0.22rem 0.5rem; }
    .seat-bubble.with-decl { max-width: 170px; white-space: normal; }

    /* Tricks piles — по-малки и прибрани в ъгълите */
    .tricks-pile.pile-mine { bottom: 6.8rem; right: 0.4rem; }
    /* Противниковата камара — долу вляво (не застъпва видясно/запад) */
    .tricks-pile.pile-them { bottom: 6.8rem; left: 0.4rem; top: auto; }
    .pile-stack { width: 28px; height: 40px; }
    .pile-card { width: 28px; height: 40px; }
    .pile-count { font-size: 0.62rem; padding: 1px 6px; }
    .pile-count .pile-num { font-size: 0.72rem; }

    /* 'Търси се ♦' — по-близо до масата, по-малък */
    .suit-required {
        top: calc(50% - 105px);
        font-size: 0.7rem;
        padding: 3px 9px;
    }
    .suit-required .suit-glyph { font-size: 0.95rem; }

    /* Trick area — по-малък в центъра, изместен надолу за да не закрива bidder бубълс */
    .trick-area {
        width: 180px; height: 150px;
        top: 52%;
    }
    .trick-card {
        width: 44px; height: 64px;
        font-size: 0.85rem; padding: 3px 4px;
    }
    .trick-card .rank { font-size: 0.95rem; }
    .trick-card .suit { font-size: 1.15rem; }
    .trick-card[data-seat="0"].entering { --enter-ty: -90px; }
    .trick-card[data-seat="1"].entering { --enter-tx: 100px; }
    .trick-card[data-seat="2"].entering { --enter-ty: 90px; }
    .trick-card[data-seat="3"].entering { --enter-tx: -100px; }

    /* My hand — лек веер с припокриване */
    .my-hand {
        bottom: 0.4rem;
        gap: 0;
        max-width: 100vw;
        padding: 0 0.5rem;
        flex-wrap: nowrap;
        justify-content: center;
    }
    .hand-card {
        width: 68px; height: 100px;
        max-width: 68px; min-width: 50px;
        margin-left: -28px;
        border-radius: 5px;
        flex-shrink: 0;
        /* По-лек веер на mobile — 2.5deg вместо 4deg */
        --fan-deg: calc(var(--card-centered, 0) * 2.5deg);
        --fan-y: calc(var(--card-centered, 0) * var(--card-centered, 0) * 0.4px);
    }
    .hand-card:first-child { margin-left: 0; }
    .hand-card:hover, .hand-card:active {
        transform: rotate(0deg) translateY(-10px) scale(1.06);
        z-index: 10;
    }

    /* Action bar — над картите, не закривайки ги, на 1 ред */
    .action-bar {
        bottom: 7rem;
        max-width: 98%;
        gap: 0.25rem;
        padding: 0.35rem 0.4rem;
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
    }
    .action-bar .btn {
        padding: 0.35rem 0.55rem;
        font-size: 0.72rem;
        flex: 0 0 auto;
    }

    /* Скрий 'Няма анонс' bubbles на телефон — твърде шумно */
    .seat-bubble.declared.no-decl { display: none !important; }

    /* Event log — скривам на mobile (заема много място) */
    .event-log { display: none; }

    /* Modals — full-width на mobile */
    .modal { padding: 1.2rem; max-width: calc(100vw - 1rem); }
    .modal h2 { font-size: 1.2rem; }

    /* Waiting room */
    .waiting-room {
        margin: 1rem 0.5rem; padding: 1.5rem 1rem;
        max-width: none;
    }
    .waiting-room h2 { font-size: 1.2rem; }
    .waiting-code { font-size: 1.8rem; letter-spacing: 0.3em; padding: 0.6rem 0; }
    .waiting-seats { grid-template-columns: 1fr; gap: 0.4rem; }
    .waiting-room .leave-btn {
        position: absolute; top: 0.5rem; right: 0.5rem;
        padding: 0.3rem 0.6rem; font-size: 0.78rem;
    }

    /* Hand-end summary modal */
    .summary-modal table { font-size: 0.78rem; }
    .summary-modal th, .summary-modal td { padding: 0.3rem; }
}

/* Малък екран (≤ 360px) — още по-компактно */
@media (max-width: 360px) {
    .hand-card { width: 60px; height: 88px; max-width: 60px; min-width: 44px; margin-left: -22px; }
    .seat-name .name { max-width: 60px; }
    .table-actions { right: 3.6rem; }
}

/* Landscape на телефон (нисък екран) */
@media (max-height: 500px) and (orientation: landscape) {
    .seat-north { top: 3rem; }
    .seat-south { bottom: 7rem; }
    .seat-east { top: 50%; right: 0.5rem; transform: translateY(-50%); }
    .seat-west { top: 50%; left: 0.5rem; transform: translateY(-50%); }
    .my-hand { bottom: 0.3rem; }
    .hand-card { width: 56px; height: 82px; max-width: 56px; min-width: 40px; margin-left: -20px; }
    .trick-area { width: 200px; height: 130px; }
    .action-bar { bottom: 5.5rem; }
}

/* ================================================================
   Watermark "Бира и Белот" — лек надпис в центъра на масата
   ================================================================ */
.table-watermark {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 0;
    font-family: 'Georgia', 'Cambria', serif;
    font-style: italic;
    font-size: clamp(2rem, 7vw, 4rem);
    color: rgba(212, 175, 55, 0.085);
    letter-spacing: 0.08em;
    text-shadow: 0 2px 6px rgba(0,0,0,0.3);
    user-select: none;
    white-space: nowrap;
    transform: rotate(-8deg);
}

/* ================================================================
   Хамбургер меню (само на мобайл)
   ================================================================ */
#hamburger-btn { display: none; }
.hamburger-menu { display: none; }

@media (max-width: 768px) {
    #hamburger-btn { display: inline-flex; }
    .hamburger-menu {
        display: block;
        position: absolute;
        top: 5.7rem; right: 0.4rem;
        z-index: 50;
        background: rgba(10, 28, 18, 0.97);
        border: 1px solid rgba(212, 175, 55, 0.4);
        border-radius: 10px;
        box-shadow: 0 8px 24px rgba(0,0,0,0.6);
        padding: 0.4rem;
        min-width: 180px;
        opacity: 0;
        transform: translateY(-8px) scale(0.96);
        transition: opacity 0.18s ease, transform 0.18s ease;
    }
    .hamburger-menu.open {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    .hamburger-menu[hidden] { display: none; }
    .hamburger-item {
        display: block;
        width: 100%;
        text-align: left;
        padding: 0.55rem 0.7rem;
        background: transparent;
        border: none;
        color: var(--text);
        font-size: 0.85rem;
        font-weight: 500;
        cursor: pointer;
        border-radius: 6px;
        transition: background 0.12s;
    }
    .hamburger-item:hover, .hamburger-item:active {
        background: rgba(212, 175, 55, 0.15);
    }
    .hamburger-room {
        padding: 0.5rem 0.7rem;
        font-size: 0.78rem;
        color: var(--text-dim);
        border-top: 1px solid rgba(255,255,255,0.08);
        border-bottom: 1px solid rgba(255,255,255,0.08);
        margin: 0.3rem 0;
    }
    .hamburger-room span {
        color: var(--gold);
        font-family: monospace;
        letter-spacing: 0.1em;
        font-weight: 700;
    }
    .hamburger-leave {
        color: #e74c3c;
        font-weight: 600;
    }
}

/* ================================================================
   Bottom-sheet за наддаване (само на мобайл)
   ================================================================ */
.bid-sheet {
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
}
.bid-sheet[hidden] { display: none; }
.bid-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: auto;
}
.bid-sheet.open .bid-sheet-backdrop { opacity: 1; }
.bid-sheet-panel {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: linear-gradient(180deg, #134d36 0%, #0a3d2a 100%);
    border-top: 2px solid var(--gold);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.6);
    padding: 1rem 0.9rem 1.4rem;
    transform: translateY(100%);
    transition: transform 0.22s cubic-bezier(0.3, 0.7, 0.4, 1);
    pointer-events: auto;
    max-height: 85vh;
    overflow-y: auto;
}
.bid-sheet.open .bid-sheet-panel { transform: translateY(0); }
.bid-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}
.bid-sheet-header strong {
    color: var(--gold);
    font-size: 1rem;
    letter-spacing: 0.02em;
}
.bid-sheet-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.4rem;
}
.bid-sheet-history {
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(212, 175, 55, 0.18);
    border-radius: 8px;
    padding: 0.5rem 0.7rem;
    margin-bottom: 0.8rem;
    max-height: 28vh;
    overflow-y: auto;
}
.bid-hist-title {
    font-size: 0.72rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.3rem;
}
.bid-hist-row {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    font-size: 0.85rem;
    border-bottom: 1px dashed rgba(255,255,255,0.06);
}
.bid-hist-row:last-child { border-bottom: none; }
.bid-hist-name { color: var(--text); }
.bid-hist-bid { color: var(--gold); font-weight: 600; }
.bid-hist-empty {
    color: var(--text-dim);
    font-size: 0.85rem;
    font-style: italic;
    text-align: center;
}
.bid-sheet-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}
.bid-sheet-options .btn {
    padding: 0.7rem 0.5rem;
    font-size: 0.9rem;
    flex: 1 1 auto;
}

/* ================================================================
   Deal animation — размесване, цепене, раздаване
   ================================================================ */
.deal-stack {
    position: absolute;
    top: 50%; left: 50%;
    width: 78px; height: 112px;
    transform: translate(-50%, -50%);
    z-index: 12;
    pointer-events: none;
}
.deal-stack .deck-card {
    position: absolute;
    inset: 0;
    border-radius: 6px;
    background:
        repeating-linear-gradient(45deg, transparent 0 4px, rgba(0,0,0,0.22) 4px 6px),
        repeating-linear-gradient(-45deg, transparent 0 4px, rgba(0,0,0,0.22) 4px 6px),
        radial-gradient(ellipse at center, #b22a2a 0%, #7a1818 100%);
    border: 1px solid #4a0e0e;
    box-shadow: inset 0 0 0 1px rgba(255, 215, 0, 0.55), 0 2px 5px rgba(0,0,0,0.5);
    transform-origin: 50% 50%;
}
.deal-stack .deck-c1 { transform: translate(0, 0) rotate(0deg); }
.deal-stack .deck-c2 { transform: translate(1px, -1px) rotate(-1deg); }
.deal-stack .deck-c3 { transform: translate(-1px, -2px) rotate(1.2deg); }
.deal-stack .deck-c4 { transform: translate(2px, -3px) rotate(-1.5deg); }
.deal-stack .deck-c5 { transform: translate(-2px, -4px) rotate(2deg); }

/* Размесване — карти трептят, разместват се хаотично */
.deal-stack.shuffling .deck-card {
    animation: shuffleCard 0.45s ease-in-out;
}
.deal-stack.shuffling .deck-c1 { animation-delay: 0ms; }
.deal-stack.shuffling .deck-c2 { animation-delay: 60ms; }
.deal-stack.shuffling .deck-c3 { animation-delay: 30ms; }
.deal-stack.shuffling .deck-c4 { animation-delay: 90ms; }
.deal-stack.shuffling .deck-c5 { animation-delay: 50ms; }
@keyframes shuffleCard {
    0%   { transform: translate(0, 0) rotate(0deg); }
    25%  { transform: translate(-14px, -3px) rotate(-12deg); }
    50%  { transform: translate(12px, -2px) rotate(10deg); }
    75%  { transform: translate(-6px, -4px) rotate(-6deg); }
    100% { transform: translate(0, -2px) rotate(0deg); }
}

/* Цепене — горната половина "отскача" нагоре и се връща */
.deal-stack.cutting .deck-c4,
.deal-stack.cutting .deck-c5 {
    animation: cutDeck 0.55s ease-in-out;
}
@keyframes cutDeck {
    0%   { transform: translate(0, 0) rotate(0deg); }
    35%  { transform: translate(34px, -8px) rotate(8deg); }
    70%  { transform: translate(34px, 4px) rotate(8deg); }
    100% { transform: translate(0, -3px) rotate(0deg); }
}
.deal-stack.cutting .deck-c1,
.deal-stack.cutting .deck-c2,
.deal-stack.cutting .deck-c3 {
    animation: cutDeckBottom 0.55s ease-in-out;
}
@keyframes cutDeckBottom {
    0%   { transform: translate(0, 0) rotate(0deg); }
    35%  { transform: translate(-2px, 4px) rotate(-2deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

/* Слой за летящи карти */
.deal-flying {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 13;
}
.deal-flying .flying-card {
    position: absolute;
    top: 50%; left: 50%;
    width: 78px; height: 112px;
    margin-top: -56px;
    margin-left: -39px;
    border-radius: 6px;
    background:
        repeating-linear-gradient(45deg, transparent 0 4px, rgba(0,0,0,0.22) 4px 6px),
        repeating-linear-gradient(-45deg, transparent 0 4px, rgba(0,0,0,0.22) 4px 6px),
        radial-gradient(ellipse at center, #b22a2a 0%, #7a1818 100%);
    border: 1px solid #4a0e0e;
    box-shadow: inset 0 0 0 1px rgba(255, 215, 0, 0.55), 0 4px 12px rgba(0,0,0,0.6);
    transform: translate(0, 0) scale(1) rotate(0deg);
    transition: transform 0.42s cubic-bezier(0.45, 0, 0.55, 1.0), opacity 0.42s ease-in;
    opacity: 1;
    will-change: transform, opacity;
}
.deal-flying .flying-card.arrived {
    transform: translate(var(--fly-x, 0), var(--fly-y, 0)) scale(0.5) rotate(var(--fly-rot, 0deg));
    opacity: 0;
}

/* Mobile — по-малко тесте */
@media (max-width: 768px) {
    .deal-stack { width: 60px; height: 88px; }
    .deal-flying .flying-card {
        width: 60px; height: 88px;
        margin-top: -44px; margin-left: -30px;
    }
}
