/* ==========================================================================
   UNO — Dark crimson theme, CSS-rendered cards
   ========================================================================== */

:root {
    --bg: #0a0a0f;
    --bg-card: #14141f;
    --bg-elevated: #1a1a2a;
    --text: #e8e0d8;
    --text-muted: #8a8090;
    --accent: #c43c3c;
    --accent-glow: #ff4444;
    --green: #2ecc71;
    --gold: #f1c40f;

    /* UNO card colors */
    --uno-red: #e74c3c;
    --uno-blue: #3498db;
    --uno-green: #2ecc71;
    --uno-yellow: #f1c40f;
    --uno-wild: #2c2c3a;

    --radius: 12px;
    --shadow: 0 4px 20px rgba(0,0,0,0.5);
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ==========================================================================
   Layout
   ========================================================================== */
#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    text-align: center;
    padding: 20px;
    background: linear-gradient(180deg, var(--bg-elevated) 0%, transparent 100%);
}

header h1 {
    font-size: 2.5rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    background: linear-gradient(135deg, var(--uno-red), var(--uno-yellow), var(--uno-green), var(--uno-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header .subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 4px;
}

/* ==========================================================================
   Lobby
   ========================================================================== */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; flex: 1; }

#lobby-screen {
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 40px 20px;
}

.lobby-box {
    background: var(--bg-elevated);
    border-radius: var(--radius);
    padding: 30px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.lobby-box h2 {
    margin-bottom: 20px;
    font-size: 1.3rem;
    color: var(--accent);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #333;
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

input[type="text"]:focus {
    border-color: var(--accent);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
}
.btn-primary:hover:not(:disabled) {
    background: var(--accent-glow);
    box-shadow: 0 0 20px rgba(255, 68, 68, 0.3);
}

.btn-secondary {
    background: #333;
}
.btn-secondary:hover:not(:disabled) {
    background: #444;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.85rem;
}

.btn-block { width: 100%; }

.divider {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 10px 0;
}

/* ==========================================================================
   Waiting Room
   ========================================================================== */
#waiting-screen {
    align-items: center;
    padding: 40px 20px;
    gap: 20px;
}

.room-code {
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: 0.2em;
    color: var(--accent);
    background: var(--bg-elevated);
    padding: 12px 30px;
    border-radius: var(--radius);
    cursor: pointer;
    position: relative;
}

.room-code:hover::after {
    content: 'Click to copy';
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.player-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    max-width: 500px;
}

.player-chip {
    background: var(--bg-elevated);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.player-chip .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
}

.player-chip.ai .dot {
    background: var(--uno-blue);
}

.player-chip .host-badge {
    font-size: 0.7rem;
    background: var(--accent);
    padding: 2px 6px;
    border-radius: 4px;
}

/* ==========================================================================
   Game Board
   ========================================================================== */
#game-screen {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 300px;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
    overflow: hidden;
}

.opponents-bar {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    gap: 16px;
    padding: 12px 20px;
    overflow-x: auto;
    background: var(--bg-elevated);
    border-bottom: 1px solid #222;
}

.opponent {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-radius: 10px;
    background: var(--bg);
    min-width: fit-content;
    transition: all 0.3s;
}

.opponent.active {
    background: rgba(196, 60, 60, 0.15);
    box-shadow: 0 0 0 2px var(--accent);
}

.opponent .name {
    font-weight: 600;
    font-size: 0.9rem;
}

.opponent .card-count {
    background: var(--bg-elevated);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 700;
}

.opponent .card-count.low {
    background: var(--accent);
    animation: pulse 1s infinite;
}

.opponent .uno-badge {
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--uno-red);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* ==========================================================================
   Play Area (center)
   ========================================================================== */
.play-area {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 30px;
    padding: 20px;
    position: relative;
}

.table-center {
    display: flex;
    align-items: center;
    gap: 40px;
}

.deck-pile, .discard-pile {
    position: relative;
}

.deck-pile .card {
    background: linear-gradient(135deg, #1a1a3a, #2a2a4a);
    cursor: pointer;
    border: 3px solid #333;
}

.deck-pile .card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.5);
}

.deck-pile .card-back-pattern {
    font-size: 2rem;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 10px rgba(196, 60, 60, 0.5);
}

.deck-count {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.turn-indicator {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    padding: 8px 20px;
    border-radius: 20px;
    background: var(--bg-elevated);
}

.turn-indicator.my-turn {
    background: rgba(196, 60, 60, 0.2);
    color: var(--accent-glow);
    animation: pulse 2s infinite;
}

.direction-indicator {
    font-size: 1.5rem;
    color: var(--text-muted);
    position: absolute;
    top: 20px;
    left: 20px;
}

.color-indicator {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
    width: 90px;
    height: 135px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 2rem;
    position: relative;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    user-select: none;
    flex-shrink: 0;
}

.card.red    { background: linear-gradient(135deg, #c0392b, #e74c3c); color: white; border: 3px solid #a93226; }
.card.blue   { background: linear-gradient(135deg, #2471a3, #3498db); color: white; border: 3px solid #1a5276; }
.card.green  { background: linear-gradient(135deg, #1e8449, #2ecc71); color: white; border: 3px solid #196f3d; }
.card.yellow { background: linear-gradient(135deg, #d4ac0d, #f1c40f); color: #333;  border: 3px solid #b7950b; }
.card.wild   { background: linear-gradient(135deg, #e74c3c 25%, #3498db 25%, #3498db 50%, #2ecc71 50%, #2ecc71 75%, #f1c40f 75%); color: white; border: 3px solid #555; }

.card .card-value {
    font-size: 2.2rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    z-index: 1;
}

.card .card-corner {
    position: absolute;
    font-size: 0.75rem;
    font-weight: 700;
}
.card .card-corner.top { top: 6px; left: 8px; }
.card .card-corner.bottom { bottom: 6px; right: 8px; transform: rotate(180deg); }

.card .card-oval {
    position: absolute;
    width: 55px;
    height: 85px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    transform: rotate(-30deg);
}

/* Discard pile card is larger */
.discard-pile .card {
    width: 100px;
    height: 150px;
}
.discard-pile .card .card-value {
    font-size: 2.6rem;
}

/* ==========================================================================
   Player's Hand
   ========================================================================== */
.hand-area {
    grid-column: 1;
    grid-row: 3;
    background: var(--bg-elevated);
    border-top: 1px solid #222;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    overflow: hidden;
}

.hand-cards {
    display: flex;
    overflow-x: auto;
    gap: 4px;
    padding: 5px 0 15px;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}

.hand-cards .card {
    cursor: pointer;
    width: 80px;
    height: 120px;
    flex-shrink: 0;
    margin-left: -20px;
    transition: all 0.15s ease;
}

.hand-cards .card:first-child {
    margin-left: 0;
}

.hand-cards .card:hover {
    transform: translateY(-15px) scale(1.08);
    z-index: 10;
    box-shadow: 0 12px 30px rgba(0,0,0,0.5);
}

.hand-cards .card.playable {
    box-shadow: 0 0 0 2px rgba(255,255,255,0.4), 0 4px 15px rgba(0,0,0,0.3);
}

.hand-cards .card:not(.playable) {
    opacity: 0.5;
    filter: grayscale(0.3);
}

.hand-cards .card:not(.playable):hover {
    transform: translateY(-5px);
    cursor: not-allowed;
}

.hand-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.uno-btn {
    background: var(--uno-red);
    font-size: 1.1rem;
    font-weight: 900;
    letter-spacing: 0.1em;
    padding: 12px 20px;
    border-radius: 50%;
    width: 65px;
    height: 65px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #a93226;
    cursor: pointer;
    color: white;
    transition: all 0.2s;
}

.uno-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 25px rgba(231, 76, 60, 0.5);
}

.uno-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

/* ==========================================================================
   Chat Panel
   ========================================================================== */
.chat-panel {
    grid-column: 2;
    grid-row: 1 / 4;
    background: var(--bg-card);
    border-left: 1px solid #222;
    display: flex;
    flex-direction: column;
}

.chat-header {
    padding: 12px 16px;
    border-bottom: 1px solid #222;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}

.chat-msg {
    font-size: 0.85rem;
    line-height: 1.4;
    padding: 4px 0;
}

.chat-msg .author {
    font-weight: 700;
    margin-right: 6px;
}

.chat-msg.system {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.8rem;
    padding: 6px 10px;
    background: rgba(255,255,255,0.03);
    border-radius: 6px;
}

.chat-input-area {
    padding: 10px;
    border-top: 1px solid #222;
    display: flex;
    gap: 8px;
}

.chat-input-area input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #333;
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
}

.chat-input-area input:focus {
    border-color: var(--accent);
}

.chat-input-area button {
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    padding: 8px 14px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
}

/* ==========================================================================
   Color Picker Modal
   ========================================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-overlay.hidden { display: none; }

.color-picker {
    background: var(--bg-elevated);
    border-radius: var(--radius);
    padding: 30px;
    text-align: center;
    box-shadow: var(--shadow);
}

.color-picker h3 {
    margin-bottom: 20px;
    font-size: 1.2rem;
}

.color-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.color-option {
    width: 80px;
    height: 80px;
    border-radius: 12px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.9rem;
    text-transform: uppercase;
}

.color-option:hover {
    transform: scale(1.1);
    border-color: white;
}

.color-option.red    { background: var(--uno-red); color: white; }
.color-option.blue   { background: var(--uno-blue); color: white; }
.color-option.green  { background: var(--uno-green); color: white; }
.color-option.yellow { background: var(--uno-yellow); color: #333; }

/* ==========================================================================
   Win Screen
   ========================================================================== */
.win-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
    gap: 20px;
}

.win-overlay.hidden { display: none; }

.win-overlay h2 {
    font-size: 3rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--uno-red), var(--gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.win-overlay p {
    font-size: 1.2rem;
    color: var(--text-muted);
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes cardDeal {
    from { transform: scale(0.5) rotate(-10deg); opacity: 0; }
    to { transform: scale(1) rotate(0); opacity: 1; }
}

.card-enter {
    animation: cardDeal 0.3s ease forwards;
}

/* ==========================================================================
   Toast notifications
   ========================================================================== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid #333;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 0.9rem;
    animation: slideUp 0.3s ease;
    box-shadow: var(--shadow);
    max-width: 300px;
}

.toast.action { border-left: 3px solid var(--accent); }
.toast.info { border-left: 3px solid var(--uno-blue); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 768px) {
    #game-screen {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto auto;
    }

    .chat-panel {
        grid-column: 1;
        grid-row: 4;
        max-height: 200px;
        border-left: none;
        border-top: 1px solid #222;
    }

    .card { width: 65px; height: 100px; }
    .card .card-value { font-size: 1.6rem; }
    .discard-pile .card { width: 80px; height: 120px; }

    .hand-cards .card {
        width: 60px;
        height: 90px;
        margin-left: -15px;
    }
}
