:root {
    --bg: #10151c;
    --panel: #1b232e;
    --text: #f2f3f5;
    --muted: #8a93a3;
    --accent: #e8433a;
    --red: #e8433a;
    --yellow: #f2c94c;
    --green: #27ae60;
    --blue: #2f80ed;
    --wild: #2b2f36;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--panel);
    border-bottom: 1px solid #2a3340;
}

.brand { color: var(--text); font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.pseudo { margin-left: auto; color: var(--muted); }

.container { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }

.card {
    background: var(--panel);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid #2a3340;
}
.card.centered { max-width: 400px; margin: 2rem auto; text-align: center; }
.card.centered form { text-align: left; }
.card.centered > p { margin-top: 1rem; font-size: 0.9rem; color: var(--muted); }
.card.wide { grid-column: 1 / -1; }

.lobby-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
@media (max-width: 700px) {
    .lobby-grid { grid-template-columns: 1fr; }
}

form { display: flex; flex-direction: column; gap: 0.9rem; margin-top: 0.5rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.inline-form { display: inline-flex; margin: 0.3rem; }

input, button {
    font-size: 1rem;
    padding: 0.55rem 0.8rem;
    border-radius: 8px;
    border: 1px solid #2a3340;
    background: #0f1620;
    color: var(--text);
    width: 100%;
}

button {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    cursor: pointer;
    font-weight: 600;
    width: auto;
}
.auth-form > button[type="submit"] { width: 100%; margin-top: 0.3rem; }
button:disabled { opacity: 0.4; cursor: default; }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 0; width: auto; }

.error { color: var(--red); font-size: 0.85rem; margin: 0; }

.action-card { display: flex; flex-direction: column; }
.card-icon {
    width: 40px; height: 40px; border-radius: 10px;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; font-weight: 800; margin-bottom: 0.75rem;
}
.card-icon.icon-join { background: var(--blue); }
.card-subtitle { color: var(--muted); font-size: 0.85rem; margin: -0.5rem 0 0.75rem; }

.room-list { list-style: none; padding: 0; margin: 0; }
.room-list li + li { margin-top: 0.4rem; }
.room-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.6rem 0.8rem; border-radius: 8px;
    background: #0f1620; color: var(--text); text-decoration: none;
    border: 1px solid transparent;
    transition: border-color 0.15s ease, transform 0.15s ease;
}
.room-row:hover { border-color: var(--accent); transform: translateY(-2px); }
.room-code { font-weight: 700; letter-spacing: 0.05em; }
.room-meta { color: var(--muted); font-size: 0.85rem; margin-left: auto; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.status-dot.live { background: var(--green); box-shadow: 0 0 0 3px rgba(39, 174, 96, 0.25); }
.empty-hint { color: var(--muted); font-size: 0.9rem; }

.badge { font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 999px; background: #2a3340; color: var(--muted); }
.badge.ready { background: var(--green); color: white; }

/* ---- Salon d'attente (design "moderne") ---- */

.room-page {
    max-width: 560px;
    margin: 2rem auto;
    background: var(--panel);
    border: 1px solid #2a3340;
    border-radius: 16px;
    padding: 1.75rem;
}

.room-header { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1.5rem; }

.room-code-chip {
    display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
    background: #0f1620; border: 1px dashed #3a4453;
    border-radius: 10px; padding: 0.75rem 1rem;
}
.code-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.code-value { font-size: 1.4rem; font-weight: 800; letter-spacing: 0.12em; color: var(--text); }
.copy-btn { margin-left: auto; padding: 0.35rem 0.7rem; font-size: 0.8rem; width: auto; }

.room-progress { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); }
.progress-track { height: 8px; border-radius: 999px; background: #0f1620; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--yellow)); border-radius: 999px; transition: width 0.3s ease; }

.player-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.player-row {
    display: flex; align-items: center; gap: 0.7rem;
    padding: 0.6rem 0.8rem; border-radius: 10px;
    background: #0f1620; border: 1px solid transparent;
}
.player-row.is-ready { border-color: var(--green); }
.player-row .avatar {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem; font-weight: 700;
}
.player-row:nth-child(4n+2) .avatar { background: var(--blue); }
.player-row:nth-child(4n+3) .avatar { background: var(--green); }
.player-row:nth-child(4n+4) .avatar { background: var(--yellow); color: #10151c; }
.player-row .avatar.placeholder { background: transparent; border: 2px dashed #3a4453; color: var(--muted); }

.player-row .player-name { font-weight: 600; display: flex; align-items: center; gap: 0.35rem; }
.player-row .player-name.muted { color: var(--muted); font-style: italic; font-weight: 400; }
.player-row .crown { color: var(--yellow); font-size: 0.85rem; }

.status-pill {
    margin-left: auto; font-size: 0.75rem; font-weight: 600;
    padding: 0.2rem 0.6rem; border-radius: 999px;
    background: #2a3340; color: var(--muted);
}
.status-pill.ready { background: var(--green); color: #fff; }
.player-row.empty-seat { background: transparent; border: 1px dashed #2a3340; }

.actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; margin-top: 1.5rem; }
.actions .inline-form { margin: 0; }
button.secondary { background: transparent; border-color: #3a4453; color: var(--text); }

/* ---- Jeu ---- */

#game-root {
    display: grid;
    grid-template-columns: 1fr 300px;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "board voice"
        "board chat";
    gap: 0;
}

.voice-panel, .board, .chat-panel { background: var(--panel); border-radius: 12px; padding: 1rem; border: 1px solid #2a3340; }
.board { grid-area: board; }
.voice-panel { grid-area: voice; }
.chat-panel { grid-area: chat; }

.voice-controls { display: flex; gap: 0.5rem; }
.voice-controls button.active { background: var(--green); border-color: var(--green); }
.voice-participants { margin-top: 0.6rem; font-size: 0.85rem; color: var(--muted); }

.board { display: flex; flex-direction: column; gap: 1.25rem; }

/* Tapis de table façon table de jeu physique : feutre vert + bordure bois */
.table-felt {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    min-height: 300px;
    padding: 1.75rem 1.5rem;
    background:
        radial-gradient(ellipse at 50% 20%, #1f7a4f 0%, #145c3a 45%, #0d3f28 100%);
    border: 8px solid #4a2f1c;
    border-radius: 26px;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.45), 0 10px 26px rgba(0,0,0,0.4);
}

.opponents { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; }
.opponent {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.4rem 0.7rem; border-radius: 8px;
    background: rgba(10, 16, 24, 0.75); color: var(--muted); font-size: 0.85rem;
    border: 1px solid rgba(255,255,255,0.08);
    backdrop-filter: blur(2px);
}
.opponent.active { color: var(--text); border-color: var(--accent); box-shadow: 0 0 0 2px rgba(232, 67, 58, 0.25); }
.opponent-back {
    position: relative;
    width: 22px; height: 32px;
    border-radius: 4px;
    background: #14141f;
    border: 2px solid #fff;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.opponent-back .logo { font-size: 0.35rem; font-weight: 900; font-style: italic; color: var(--yellow); }
.opponent-name { font-weight: 600; color: var(--text); }
.opponent-count { color: var(--muted); }
.opponent button { margin-left: 0.3rem; padding: 0.25rem 0.5rem; font-size: 0.75rem; }

.table-center { display: flex; align-items: center; justify-content: center; gap: 2.5rem; }
.pile { text-align: center; }
.pile .label { color: rgba(255,255,255,0.7); font-size: 0.8rem; margin-bottom: 0.5rem; }

.turn-indicator {
    background: rgba(0,0,0,0.4);
    color: #fff;
    padding: 0.45rem 1.1rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid rgba(255,255,255,0.15);
    min-height: 1.2em;
}

/* ---- Cartes UNO (façon vraie carte : ovale incliné + repères de coin) ---- */

.uno-card, .card-back {
    position: relative;
    width: 74px; height: 108px;
    border-radius: 9px;
    border: 3px solid #fff;
    box-shadow: 0 3px 0 rgba(0,0,0,0.35), 0 4px 8px rgba(0,0,0,0.45);
    display: inline-flex; align-items: center; justify-content: center;
    overflow: hidden;
    padding: 0;
    flex-shrink: 0;
    font-family: Arial, Helvetica, sans-serif;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.uno-card {
    --suit-color: var(--red);
    background: var(--suit-color);
}
.uno-card.color-yellow { --suit-color: var(--yellow); }
.uno-card.color-green { --suit-color: var(--green); }
.uno-card.color-blue { --suit-color: var(--blue); }
.uno-card.color-wild { --suit-color: #1a1a1a; background: #1a1a1a; }

.hand .uno-card:not(:disabled):hover,
.card-back:not(:disabled):hover {
    transform: translateY(-10px);
    box-shadow: 0 8px 0 rgba(0,0,0,0.25), 0 12px 16px rgba(0,0,0,0.5);
}

.uno-card .oval {
    position: absolute;
    width: 58%; height: 88%;
    background: #fff;
    border-radius: 50%;
    transform: rotate(-22deg);
}
.uno-card.color-wild .oval {
    width: 52%; height: 52%;
    transform: none;
    background: conic-gradient(var(--red) 0 25%, var(--blue) 0 50%, var(--yellow) 0 75%, var(--green) 0 100%);
    box-shadow: 0 0 0 3px rgba(255,255,255,0.9);
}

.uno-card .value {
    position: relative;
    z-index: 2;
    font-size: 1.85rem;
    font-weight: 800;
    color: var(--suit-color);
    transform: rotate(-22deg);
    -webkit-text-stroke: 1.4px rgba(0,0,0,0.55);
}
.uno-card.color-yellow .value { color: #a86f00; }
.uno-card.color-wild .value {
    transform: none;
    z-index: 3;
    font-size: 0.95rem;
    color: #fff;
    -webkit-text-stroke: 0;
    background: rgba(0,0,0,0.6);
    border-radius: 50%;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
}

.uno-card .corner {
    position: absolute;
    z-index: 3;
    font-size: 0.65rem;
    font-weight: 800;
    color: #fff;
    line-height: 1;
    text-shadow: 0 1px 1px rgba(0,0,0,0.5);
}
.uno-card .corner.tl { top: 5px; left: 6px; }
.uno-card .corner.br { bottom: 5px; right: 6px; transform: rotate(180deg); }

.card-back {
    background: #14141f;
}
.card-back::before {
    content: "";
    position: absolute;
    width: 62%; height: 88%;
    background: var(--red);
    border: 3px solid #fff;
    border-radius: 50%;
    transform: rotate(-22deg);
}
.card-back .logo {
    position: relative; z-index: 2;
    font-style: italic; font-weight: 900;
    font-size: 1rem; letter-spacing: 0.02em;
    color: var(--yellow);
    -webkit-text-stroke: 1px rgba(0,0,0,0.6);
    transform: rotate(-22deg);
}

.discard-slot { border-radius: 13px; transition: box-shadow 0.2s ease; }

.hand-area { display: flex; align-items: center; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.hand { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: center; }
.uno-btn { background: var(--yellow); color: #10151c; border-color: var(--yellow); border-radius: 999px; padding: 0.7rem 1.2rem; }

.chat-panel { display: flex; flex-direction: column; min-height: 260px; overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.5rem; padding-right: 0.2rem; }
.chat-message {
    max-width: 85%;
    align-self: flex-start;
    background: #0f1620;
    border-radius: 10px;
    padding: 0.4rem 0.65rem;
    font-size: 0.85rem;
    word-break: break-word;
    overflow-wrap: anywhere;
    display: flex;
    flex-direction: column;
}
.chat-message .author { font-size: 0.7rem; font-weight: 700; color: var(--muted); }
.chat-message.own { align-self: flex-end; background: var(--accent); color: #fff; }
.chat-message.own .author { color: rgba(255,255,255,0.8); }
.chat-form { flex-direction: row; margin: 0; }
.chat-form input { flex: 1; }

.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
}
.modal[hidden] { display: none; }
.modal-content { background: var(--panel); padding: 2rem; border-radius: 12px; text-align: center; }
.color-choice { margin: 0.3rem; }
.color-choice[data-color="red"] { background: var(--red); border-color: var(--red); }
.color-choice[data-color="yellow"] { background: var(--yellow); border-color: var(--yellow); color: #10151c; }
.color-choice[data-color="green"] { background: var(--green); border-color: var(--green); }
.color-choice[data-color="blue"] { background: var(--blue); border-color: var(--blue); }

@media (max-width: 800px) {
    #game-root {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        grid-template-areas:
            "board"
            "voice"
            "chat";
    }
}
