/* 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);
}

.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: 0.75rem; left: 0.75rem; right: 0.75rem;
    display: flex; gap: 0.5rem; flex-wrap: wrap;
    z-index: 5;
}
.badge, .score, .phase {
    background: rgba(0, 0, 0, 0.5);
    padding: 0.4rem 0.8rem;
    border-radius: 999px;
    font-size: 0.85rem;
    border: 1px solid rgba(212, 175, 55, 0.25);
}
.badge { color: var(--gold); font-family: monospace; letter-spacing: 0.1em; }
.score { color: var(--text); }

.table-actions {
    position: absolute; top: 0.75rem; right: 5.5rem;
    z-index: 7;
    display: flex; gap: 0.4rem;
}
.leave-btn {
    position: absolute; top: 0.75rem; 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; }

/* 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: 5;
    animation: bubble-pop 0.25s ease-out;
    max-width: 180px;
}
.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: #dbeafe; color: #1e40af; }
@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;
    background: linear-gradient(135deg, var(--bg-deep), var(--bg));
    border: 1px solid var(--gold);
    border-radius: 3px;
    margin-left: -10px;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.4);
}
.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: 11rem; 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: 56px; height: 80px;
    background: white;
    border-radius: 5px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.5);
    color: var(--black);
    font-weight: 700;
    font-size: 1rem;
    display: flex; flex-direction: column;
    padding: 4px 6px;
    transition: all 0.3s;
}
.trick-card.suit-H, .trick-card.suit-D { color: var(--red); }
.trick-card .rank { font-size: 1.1rem; line-height: 1; }
.trick-card .suit { font-size: 1.4rem; line-height: 1; }
.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); }
}

/* My hand */
.my-hand {
    position: absolute;
    bottom: 1rem; left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: -0.5rem;
    z-index: 4;
}
.hand-card {
    width: 60px; height: 88px;
    background: white;
    border: 1px solid #999;
    border-radius: 6px;
    margin-left: -16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    color: var(--black);
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s, opacity 0.2s, margin 0.2s;
    padding: 6px 8px;
    display: flex; flex-direction: column;
}
.hand-card:first-child { margin-left: 0; }
.hand-card:hover { transform: translateY(-12px); }
.hand-card.illegal {
    opacity: 0.45;
    cursor: not-allowed;
}
.hand-card.illegal:hover { transform: none; }
.hand-card.suit-H, .hand-card.suit-D { color: var(--red); }
.hand-card .rank { font-size: 1.1rem; line-height: 1; }
.hand-card .suit { font-size: 1.6rem; line-height: 1; }

/* Action bar — shown for bidding & start */
.action-bar {
    position: absolute;
    bottom: 7.5rem; left: 50%;
    transform: translateX(-50%);
    display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center;
    max-width: 90%;
    z-index: 5;
}
.action-bar .btn {
    flex: none;
    padding: 0.55rem 0.9rem;
    font-size: 0.9rem;
}

/* Event log */
.event-log {
    position: absolute;
    top: 3.5rem; left: 0.75rem;
    width: 220px;
    max-height: 30vh;
    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 / portrait tweaks */
@media (max-width: 600px) {
    .seat-north { top: 3rem; }
    .seat-south { bottom: 9rem; }
    .hand-card { width: 48px; height: 70px; margin-left: -22px; padding: 4px 6px; }
    .hand-card .rank { font-size: 0.95rem; }
    .hand-card .suit { font-size: 1.3rem; }
    .event-log { width: 160px; font-size: 0.7rem; }
}
