* { box-sizing: border-box; margin: 0; padding: 0; }

body { font-family: Arial, sans-serif; background: #0b3d0b; color: #fff; min-height: 100vh; }

/* ── LOBBY ─────────────────────────────────────────────────────────────────── */
#lobby { display:flex; flex-direction:column; align-items:center; justify-content:center; min-height:100vh; gap:20px; padding:20px; }
#lobby h1 { color:#ffd700; font-size:2.5em; }
.lobby-box { background:rgba(0,0,0,0.4); border-radius:12px; padding:30px 30px 20px; display:flex; flex-direction:column; gap:12px; width:340px; }
.lobby-box input { padding:10px; font-size:1em; border-radius:6px; border:none; width:100%; }
.lobby-buttons { display:flex; gap:10px; }
.lobby-buttons button { flex:1; }
#lobby-status { color:#ffd700; text-align:center; min-height:20px; }

/* ── LOBBY ROOM ────────────────────────────────────────────────────────────── */
#lobby-room { display:flex; flex-direction:row; min-height:100vh; }
#lobby-room-main { flex:1; padding:30px; display:flex; flex-direction:column; gap:20px; max-width:600px; }
#lobby-room-header h2 { color:#ffd700; font-size:1.8em; margin-bottom:8px; }
#lobby-room-code-row { font-size:1em; color:#ccc; }
#lobby-room-code-row strong { color:#ffd700; font-size:1.2em; letter-spacing:0.1em; }
#lobby-hand-size-display { font-size:0.9em; color:#aaa; margin-top:4px; }
#lobby-host-controls { display:flex; align-items:center; gap:10px; background:rgba(0,0,0,0.3); border-radius:8px; padding:10px 14px; }
#lobby-host-controls input { padding:6px; border-radius:4px; border:none; font-size:1em; width:60px; }
.lobby-section-label { font-size:0.8em; color:#aaa; text-transform:uppercase; letter-spacing:0.05em; margin-bottom:8px; }
#lobby-player-list { display:flex; flex-direction:column; gap:8px; }
.lobby-player { background:rgba(255,255,255,0.08); border-radius:8px; padding:10px 14px; font-size:1em; display:flex; align-items:center; gap:8px; }
.lobby-room-actions { display:flex; gap:12px; align-items:center; }
#lobby-start-btn { font-size:1.1em; padding:12px 24px; }

/* Lobby Chat */
#lobby-chat-panel { width:280px; flex-shrink:0; background:rgba(0,0,0,0.45); border-left:1px solid rgba(255,255,255,0.1); display:flex; flex-direction:column; height:100vh; position:sticky; top:0; }
#lobby-chat-header { padding:10px 14px; font-weight:bold; color:#ffd700; border-bottom:1px solid rgba(255,255,255,0.1); }
#lobby-chat-messages { flex:1; overflow-y:auto; padding:10px; display:flex; flex-direction:column; gap:8px; }
#lobby-chat-input-row { display:flex; gap:6px; padding:8px; border-top:1px solid rgba(255,255,255,0.1); }
#lobby-chat-input { flex:1; padding:8px; border-radius:6px; border:none; font-size:0.9em; background:rgba(255,255,255,0.15); color:#fff; outline:none; }
#lobby-chat-input::placeholder { color:#888; }

/* ── WAITING ───────────────────────────────────────────────────────────────── */
#waiting { display:flex; align-items:center; justify-content:center; min-height:100vh; }
#waiting h2 { color:#ffd700; font-size:1.8em; }

/* ── BUTTONS ───────────────────────────────────────────────────────────────── */
button { padding:10px 18px; font-size:1em; background:#ffd700; color:#000; border:none; border-radius:6px; cursor:pointer; font-weight:bold; transition:background 0.15s; }
button:hover { background:#ffe84d; }
button:disabled { background:#666; color:#aaa; cursor:default; }
.leave-btn { background:#8b0000; color:#fff; font-size:0.85em; padding:6px 12px; }
.leave-btn:hover { background:#aa0000; }
.cancel-btn { background:#555; color:#fff; }
.cancel-btn:hover { background:#666; }

/* ── GAME LAYOUT ───────────────────────────────────────────────────────────── */
#game { display:flex; flex-direction:row; min-height:100vh; align-items:stretch; }
#game-main { flex:1; display:flex; flex-direction:column; gap:8px; padding:8px; min-width:0; overflow-y:auto; }

/* ── PLAYER SIDEBAR ────────────────────────────────────────────────────────── */
#player-sidebar {
    width:160px; flex-shrink:0;
    background:rgba(0,0,0,0.4);
    border-left:1px solid rgba(255,255,255,0.08);
    display:flex; flex-direction:column;
    padding:12px 8px; gap:6px;
    position:sticky; top:0; height:100vh; overflow-y:auto;
}

.sidebar-player {
    position:relative;
    padding:10px 12px;
    border-radius:10px;
    background:rgba(255,255,255,0.05);
    transition:background 0.3s, box-shadow 0.4s;
    overflow:hidden;
}

.sidebar-player.current-turn {
    background:rgba(180,0,0,0.25);
    box-shadow:0 0 0 2px #cc0000, 0 0 12px rgba(200,0,0,0.4);
    animation:turnPulse 1.5s ease-in-out infinite alternate;
}

@keyframes turnPulse {
    from { box-shadow:0 0 0 2px #cc0000, 0 0 8px rgba(200,0,0,0.3); }
    to   { box-shadow:0 0 0 2px #ff3333, 0 0 18px rgba(255,50,50,0.5); }
}

.sidebar-player.player-out {
    opacity:0.4;
    background:rgba(0,0,0,0.3);
}

.sidebar-player.player-disconnected {
    background:rgba(80,70,0,0.4);
    box-shadow:0 0 0 2px #aa8800;
}

.sidebar-name { font-size:0.88em; font-weight:bold; color:#fff; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.sidebar-info { font-size:0.75em; color:#aaa; margin-top:3px; }
.sidebar-out-x {
    position:absolute; top:50%; left:50%; transform:translate(-50%,-50%);
    font-size:2em; color:rgba(150,150,150,0.6); font-weight:bold;
    pointer-events:none;
}

/* ── TOP BAR ───────────────────────────────────────────────────────────────── */
#top-bar { display:flex; justify-content:space-between; align-items:center; background:rgba(0,0,0,0.4); border-radius:8px; padding:8px 14px; flex-wrap:wrap; gap:8px; }
#turn-indicator { font-size:1em; font-weight:bold; color:#ffd700; }
#scores { font-size:0.9em; color:#ccc; }

/* ── MESSAGE LOG ───────────────────────────────────────────────────────────── */
#message-log { background:rgba(0,0,0,0.35); border-radius:8px; padding:8px 12px; max-height:80px; overflow-y:auto; font-size:0.85em; display:flex; flex-direction:column-reverse; gap:2px; }
.msg-info { color:#ccc; }
.msg-success { color:#7fff7f; }
.msg-error { color:#ff6b6b; }
.msg-rummy { color:#ffd700; font-weight:bold; }

/* ── RUMMY BANNER ──────────────────────────────────────────────────────────── */
#rummy-banner { background:#7a0000; border:2px solid #ffd700; border-radius:8px; padding:10px 16px; display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; }
#rummy-text { color:#ffd700; font-weight:bold; font-size:1.05em; }
#rummy-buttons { display:flex; gap:8px; flex-wrap:wrap; }
#rummy-call-btn { background:#ffd700; color:#000; }
#rummy-pick-btn { background:#00aa55; color:#fff; }
#rummy-pick-btn:hover { background:#00cc66; }

/* ── TABLE ─────────────────────────────────────────────────────────────────── */
#table-area { background:#145214; border-radius:10px; padding:10px; min-height:100px; flex:1; }
#table-label { font-size:0.8em; color:#aaa; margin-bottom:6px; }
#table-sets { display:flex; flex-wrap:wrap; gap:12px; align-items:flex-start; }
.set-group { width:100%; margin-bottom:8px; }
.set-group-label { font-size:0.78em; color:#aaa; margin-bottom:4px; text-transform:uppercase; letter-spacing:0.05em; }
.set-group-row { display:flex; flex-wrap:wrap; gap:10px; }
.table-set { background:rgba(0,0,0,0.25); border-radius:8px; padding:6px 8px; display:flex; gap:4px; flex-wrap:wrap; cursor:pointer; border:2px solid transparent; transition:border-color 0.15s; }
.table-set:hover { border-color:#ffd700; }
.table-set.targeted { border-color:#00ff88; }

/* ── DRAW AREA ─────────────────────────────────────────────────────────────── */
#draw-area { display:flex; gap:16px; align-items:flex-start; padding:6px 0; }
#deck-pile { cursor:pointer; }
#deck-pile:hover .card-back { transform:translateY(-4px); box-shadow:0 6px 14px rgba(0,0,0,0.5); }
#discard-label { font-size:0.78em; color:#aaa; margin-bottom:4px; }
#discard-pile { display:flex; flex-direction:row; flex-wrap:wrap; gap:4px; max-width:600px; }
.discard-card { cursor:pointer; transition:transform 0.1s; }
.discard-card:hover { transform:translateY(-6px); }
.discard-card.top-card { outline:2px solid #ffd700; border-radius:8px; }
.discard-card.selected { outline:3px solid #00ff88; border-radius:8px; transform:translateY(-8px); }
.discard-card.rummy-card { outline:3px solid #ff6600; border-radius:8px; }

/* ── HAND ──────────────────────────────────────────────────────────────────── */
#hand-area { background:rgba(0,0,0,0.3); border-radius:10px; padding:10px; }
#hand-label { font-size:0.8em; color:#aaa; margin-bottom:6px; }
#my-hand { display:flex; flex-wrap:wrap; gap:6px; margin-bottom:10px; min-height:110px; }
#hand-actions { display:flex; gap:8px; flex-wrap:wrap; }
#action-hint { font-size:0.85em; color:#aaa; margin-top:6px; min-height:18px; }

/* ── CARDS ─────────────────────────────────────────────────────────────────── */
.card { width:62px; height:90px; border-radius:8px; border:2px solid #333; background:#fff; color:#111; display:flex; flex-direction:column; justify-content:space-between; padding:4px 5px; font-size:0.85em; font-weight:bold; user-select:none; transition:transform 0.12s,box-shadow 0.12s; position:relative; flex-shrink:0; }
.card-back { background:repeating-linear-gradient(45deg,#1a5c1a,#1a5c1a 4px,#0f3d0f 4px,#0f3d0f 8px); color:#ffd700; border:2px solid #ffd700; align-items:center; justify-content:center; font-size:1.4em; }
.card.red { color:#cc0000; }
.card.black { color:#111; }
.card-top { display:flex; flex-direction:column; line-height:1.1; }
.card-bottom { display:flex; flex-direction:column; line-height:1.1; transform:rotate(180deg); align-self:flex-end; }
.card-center { position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); font-size:1.4em; }
.card.selected { transform:translateY(-12px); box-shadow:0 6px 16px rgba(255,215,0,0.7); border-color:#ffd700; }
.card.hand-card { cursor:grab; }
.card.hand-card:active { cursor:grabbing; }
.card.hand-card:hover { transform:translateY(-6px); }
.card.hand-card.selected:hover { transform:translateY(-14px); }
.card.dragging { opacity:0.4; transform:scale(0.95); }
.card.added-card { border-color:#4499ff; box-shadow:0 0 6px rgba(68,153,255,0.5); }

/* ── CHAT (game) ───────────────────────────────────────────────────────────── */
#chat-panel { width:220px; flex-shrink:0; background:rgba(0,0,0,0.45); border-left:1px solid rgba(255,255,255,0.1); display:flex; flex-direction:column; height:100vh; position:sticky; top:0; }
#chat-header { padding:10px 14px; font-weight:bold; font-size:0.95em; border-bottom:1px solid rgba(255,255,255,0.1); color:#ffd700; }
#chat-messages { flex:1; overflow-y:auto; padding:10px; display:flex; flex-direction:column; gap:8px; }
.chat-msg { display:flex; flex-direction:column; max-width:90%; gap:2px; }
.chat-me { align-self:flex-end; align-items:flex-end; }
.chat-them { align-self:flex-start; align-items:flex-start; }
.chat-name { font-size:0.7em; color:#aaa; }
.chat-text { background:rgba(255,255,255,0.12); border-radius:10px; padding:6px 10px; font-size:0.88em; word-break:break-word; line-height:1.4; }
.chat-me .chat-text { background:rgba(255,215,0,0.2); border-bottom-right-radius:2px; }
.chat-them .chat-text { border-bottom-left-radius:2px; }
#chat-input-row { display:flex; gap:6px; padding:8px; border-top:1px solid rgba(255,255,255,0.1); }
#chat-input { flex:1; padding:8px; border-radius:6px; border:none; font-size:0.9em; background:rgba(255,255,255,0.15); color:#fff; outline:none; }
#chat-input::placeholder { color:#888; }
#chat-input-row button { padding:8px 10px; font-size:0.85em; }

/* ── MODAL ─────────────────────────────────────────────────────────────────── */
#leave-modal { position:fixed; inset:0; background:rgba(0,0,0,0.7); display:flex; align-items:center; justify-content:center; z-index:1000; }
.modal-box { background:#1a3d1a; border:2px solid #ffd700; border-radius:12px; padding:30px; max-width:340px; text-align:center; display:flex; flex-direction:column; gap:20px; }
.modal-box p { font-size:1.05em; line-height:1.5; }
.modal-buttons { display:flex; gap:12px; justify-content:center; }

/* ── END SCREEN ────────────────────────────────────────────────────────────── */
#end-screen { display:flex; align-items:center; justify-content:center; min-height:100vh; }
.end-box { background:rgba(0,0,0,0.75); border:2px solid #ffd700; border-radius:14px; padding:40px; text-align:center; display:flex; flex-direction:column; gap:16px; min-width:300px; }
#end-title { color:#ffd700; font-size:2em; }
#end-scores { font-size:1.1em; line-height:1.8; }

/* ── LEADERBOARD ───────────────────────────────────────────────────────────── */
#leaderboard { width:340px; background:rgba(0,0,0,0.3); border-radius:12px; padding:16px 20px; }
#leaderboard h3 { color:#ffd700; font-size:1em; margin-bottom:10px; text-align:center; letter-spacing:0.05em; }
.lb-row { display:flex; align-items:center; justify-content:space-between; padding:5px 0; border-bottom:1px solid rgba(255,255,255,0.08); font-size:0.9em; }
.lb-row:last-child { border-bottom:none; }
.lb-rank { width:24px; color:#888; font-size:0.85em; flex-shrink:0; }
.lb-rank.gold { color:#ffd700; font-weight:bold; }
.lb-rank.silver { color:#c0c0c0; font-weight:bold; }
.lb-rank.bronze { color:#cd7f32; font-weight:bold; }
.lb-name { flex:1; padding:0 8px; }
.lb-wins { color:#7fff7f; font-weight:bold; min-width:40px; text-align:right; }
#leaderboard-empty { color:#666; font-size:0.85em; text-align:center; padding:8px 0; }

/* ── MOBILE ────────────────────────────────────────────────────────────────── */
@media (max-width:700px) {
    #game { flex-direction:column !important; }
    #player-sidebar { width:100%; height:auto; flex-direction:row; flex-wrap:wrap; border-left:none; border-top:1px solid rgba(255,255,255,0.08); position:static; padding:8px; }
    .sidebar-player { min-width:120px; flex:1; }
    #chat-panel { width:100%; height:200px; position:static; border-left:none; border-top:1px solid rgba(255,255,255,0.1); }
    #lobby-room { flex-direction:column; }
    #lobby-chat-panel { width:100%; height:200px; position:static; border-left:none; border-top:1px solid rgba(255,255,255,0.1); }
}

/* Rummy card in hand — orange glow to show it must be played */
.card.rummy-card-hand {
    border-color: #ff6600;
    box-shadow: 0 0 8px rgba(255, 102, 0, 0.7);
}