:root {
    --bg: #1a2233;
    --bg2: #232c40;
    --bg3: #2b3550;
    --border: #3a4560;
    --text: #e8ecf4;
    --muted: #9aa7c0;
    --accent: #4f8cff;
    --accent2: #7d5bff;
    --green: #2ecc71;
    --amber: #f39c12;
    --red: #e74c3c;

    --card-red: #e74c3c;
    --card-blue: #3498db;
    --card-green: #2ecc71;
    --card-yellow: #f1c40f;
    --card-wild: #2c3e50;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: radial-gradient(ellipse at top, #263150 0%, var(--bg) 70%);
    color: var(--text);
    min-height: 100vh;
}

.hidden { display: none !important; }

.view { max-width: 1100px; margin: 0 auto; padding: 20px; }

/* ─── PANELS ─── */
.panel {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: 0 6px 20px rgba(0,0,0,.25);
}

h1 { font-size: 1.8rem; margin-bottom: 4px; }
h2 { font-size: 1.2rem; margin-bottom: 12px; }
h3 { font-size: 1rem; margin-bottom: 8px; color: var(--muted); }

.subtitle { color: var(--muted); margin-bottom: 20px; }
.muted { color: var(--muted); font-size: .9rem; }

/* ─── BUTTONS ─── */
.btn {
    display: inline-block;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
.btn.primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
}
.btn.primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn.secondary {
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn.secondary:hover { background: var(--border); }
.btn.small { padding: 6px 14px; font-size: .85rem; }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* ─── FORMS ─── */
label { display: block; margin-bottom: 12px; color: var(--muted); font-size: .85rem; }
input, select {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: .95rem;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

/* ─── TABS ─── */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tab-btn {
    flex: 1;
    padding: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    cursor: pointer;
    font-size: .9rem;
}
.tab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ─── ERROR ─── */
.error-msg { color: var(--red); font-size: .9rem; margin-top: 8px; padding: 8px; background: rgba(231,76,60,.1); border-radius: 6px; }

/* ─── AUTH ─── */
.auth-panel { max-width: 400px; margin: 60px auto; text-align: center; }
.auth-panel h1 { margin-bottom: 4px; }
.auth-panel .tabs { max-width: 200px; margin: 16px auto; }
.auth-form { text-align: left; }

/* ─── LOBBY ─── */
.lobby-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.header-right { display: flex; align-items: center; gap: 12px; }
#lobby-username { color: var(--accent); font-weight: 600; }
.lobby-columns { display: grid; grid-template-columns: 280px 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .lobby-columns { grid-template-columns: 1fr; } }

.game-list { max-height: 300px; overflow-y: auto; }
.game-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 6px;
    background: var(--bg);
}
.game-item:hover { border-color: var(--accent); }
.game-item .info { font-size: .9rem; }
.game-item .info .muted { font-size: .8rem; }

/* ─── GAME HEADER ─── */
.game-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}
#game-status-text { font-size: 1.1rem; font-weight: 600; }

/* ─── WAITING ROOM ─── */
#waiting-players { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.waiting-player {
    padding: 8px 16px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .9rem;
}
.waiting-player.you { border-color: var(--accent); color: var(--accent); }
.waiting-player.host::after { content: ' (host)'; color: var(--amber); font-size: .8rem; }

/* ─── OPPONENTS ─── */
.opponents-row {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.opponent {
    text-align: center;
    padding: 10px 16px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    min-width: 100px;
}
.opponent.active-turn { border-color: var(--green); box-shadow: 0 0 12px rgba(46,204,113,.3); }
.opponent.eliminated { opacity: .4; }
.opponent .name { font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.opponent .card-count { color: var(--muted); font-size: .8rem; }
.opponent .card-count.danger { color: var(--red); font-weight: 600; }

/* ─── TABLE ─── */
.table-container {
    background: linear-gradient(135deg, #234b3a, #1c3a2e);
    border: 2px solid #3a6b50;
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 16px;
    min-height: 160px;
}
.table-center {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 32px;
}
.pile { position: relative; text-align: center; }
.pile-count {
    position: absolute;
    bottom: -8px;
    right: -8px;
    background: var(--bg);
    color: var(--muted);
    font-size: .75rem;
    padding: 2px 6px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

/* ─── CARDS ─── */
.card {
    width: 80px;
    height: 112px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    box-shadow: 0 3px 10px rgba(0,0,0,.3);
    cursor: default;
    user-select: none;
    transition: transform .15s, box-shadow .15s;
    position: relative;
    border: 2px solid rgba(0,0,0,.2);
}
.card .card-value { font-size: 1.6rem; line-height: 1; }
.card .card-value.long { font-size: .6rem; line-height: 1.1; }
.card .card-label { font-size: .55rem; text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; opacity: .85; }

.card-back {
    background: linear-gradient(135deg, #34495e, #2c3e50);
    color: var(--muted);
    border-color: #4a6278;
    font-size: .7rem;
    letter-spacing: 1px;
}

/* Card colors */
.card.color-red { background: linear-gradient(135deg, #e74c3c, #c0392b); color: #fff; }
.card.color-blue { background: linear-gradient(135deg, #3498db, #2980b9); color: #fff; }
.card.color-green { background: linear-gradient(135deg, #2ecc71, #27ae60); color: #fff; }
.card.color-yellow { background: linear-gradient(135deg, #f1c40f, #d4ac0d); color: #333; }
.card.color-wild { background: linear-gradient(135deg, #2c3e50, #1a252f); color: #f1c40f; border-color: #f1c40f; }

.card.small { width: 56px; height: 78px; }
.card.small .card-value { font-size: 1.1rem; }
.card.small .card-value.long { font-size: .42rem; }
.card.small .card-label { font-size: .45rem; }

/* ─── HAND ─── */
.hand-container { margin-bottom: 16px; text-align: center; }
.hand-container h3 { text-align: left; }
.hand {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 8px 0;
}
.hand .card {
    cursor: pointer;
    transform: translateY(0);
}
.hand .card:hover {
    transform: translateY(-8px);
    box-shadow: 0 8px 20px rgba(0,0,0,.4);
    z-index: 2;
}
.hand .card.selected {
    transform: translateY(-12px);
    box-shadow: 0 0 0 3px var(--accent), 0 8px 20px rgba(0,0,0,.4);
    z-index: 3;
}
.hand .card.playable {
    box-shadow: 0 0 0 2px var(--green), 0 3px 10px rgba(0,0,0,.3);
}

/* ─── CONTROLS ─── */
.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    min-height: 48px;
}

/* ─── LOG ─── */
.log-panel { max-height: 180px; overflow-y: auto; }
.game-log { font-size: .85rem; color: var(--muted); }
.game-log div { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,.04); }
.game-log div:last-child { border-bottom: none; }

/* ─── MODAL ─── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-content {
    min-width: 300px;
    max-width: 400px;
    text-align: center;
}
.modal-content h2 { margin-bottom: 16px; }
.color-options {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.color-btn {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    border: 3px solid transparent;
    cursor: pointer;
    font-size: .8rem;
    font-weight: 600;
    color: #fff;
    text-transform: uppercase;
    transition: transform .15s, border-color .15s;
}
.color-btn:hover { transform: scale(1.1); border-color: #fff; }
.color-btn.red { background: var(--card-red); }
.color-btn.blue { background: var(--card-blue); }
.color-btn.green { background: var(--card-green); }
.color-btn.yellow { background: var(--card-yellow); color: #333; }

.swap-options { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.swap-btn {
    padding: 10px 20px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    font-size: .9rem;
    transition: all .15s;
}
.swap-btn:hover { border-color: var(--accent); background: var(--accent); }

/* ─── TOAST ─── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 24px;
    border-radius: 8px;
    font-size: .9rem;
    box-shadow: 0 4px 16px rgba(0,0,0,.3);
    z-index: 200;
    animation: toast-in .3s ease;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── CELEBRATION ─── */
.celebration-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 300;
}
.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    top: -20px;
    border-radius: 2px;
    animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
    0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
.celebration-banner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.3);
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
    padding: 24px 48px;
    border-radius: 16px;
    font-size: 2rem;
    font-weight: 700;
    box-shadow: 0 8px 32px rgba(0,0,0,.5);
    z-index: 301;
    animation: banner-pop .6s ease forwards;
}
@keyframes banner-pop {
    0%   { transform: translate(-50%, -50%) scale(0.3); }
    70%  { transform: translate(-50%, -50%) scale(1.08); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

/* ─── ROULETTE REVEAL ─── */
.roulette-reveal {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 12px 0;
}
.roulette-reveal .card { animation: card-flip .3s ease backwards; }
@keyframes card-flip {
    from { transform: rotateY(90deg) scale(0.5); opacity: 0; }
    to   { transform: rotateY(0) scale(1); opacity: 1; }
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
