:root {
    --uno-red: #E52521;
    --uno-blue: #0072CE;
    --uno-green: #3AA935;
    --uno-yellow: #F5C700;
    --uno-black: #16161B;

    --table-center: #164b35;
    --table-mid: #0d3223;
    --table-edge: #081e15;
    --glass-bg: rgba(12, 18, 16, 0.78);
    --glass-border: rgba(255, 255, 255, 0.14);
    --accent: #238654;
    --text-main: #f4f7f5;
    --text-muted: #9eb3a8;

    --card-w: 108px;
    --card-h: 162px;
    --card-radius: 12px;
}

/* Themes */
body[data-theme="luxury"] {
    --table-center: #26201a;
    --table-mid: #16120f;
    --table-edge: #090807;
    --glass-bg: rgba(18, 15, 12, 0.85);
    --glass-border: rgba(212, 175, 55, 0.35);
    --accent: #b88a1e;
}

body[data-theme="cyber"] {
    --table-center: #1b1236;
    --table-mid: #0f0a21;
    --table-edge: #060410;
    --glass-bg: rgba(14, 10, 30, 0.82);
    --glass-border: rgba(0, 240, 255, 0.32);
    --accent: #7c3aed;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-drag: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--text-main);
    background: radial-gradient(ellipse at center, var(--table-center) 0%, var(--table-mid) 55%, var(--table-edge) 100%);
    transition: background 0.4s ease;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 0);
    background-size: 6px 6px;
    z-index: 0;
}

.app {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
}

/* Screen shake FX */
.app.shake {
    animation: screenShake 0.38s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes screenShake {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(-7px, 4px); }
    40% { transform: translate(7px, -4px); }
    60% { transform: translate(-5px, -3px); }
    80% { transform: translate(5px, 3px); }
}

/* Dynamic center table glow */
.table-glow {
    position: fixed;
    left: 50%;
    top: 48%;
    width: 520px;
    height: 520px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.28;
    filter: blur(80px);
    transition: background 0.55s ease;
}

.table-glow.glow-red { background: var(--uno-red); }
.table-glow.glow-blue { background: var(--uno-blue); }
.table-glow.glow-green { background: var(--uno-green); }
.table-glow.glow-yellow { background: var(--uno-yellow); }

/* HUD Bar */
.hud-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0) 100%);
    z-index: 10;
}

.hud-left, .hud-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-badge {
    font-weight: 900;
    font-size: 1.15rem;
    letter-spacing: 1px;
    padding: 4px 12px;
    border-radius: 999px;
    background: linear-gradient(135deg, #e52521, #b31217);
    color: #ffd700;
    text-shadow: 1px 2px 0 #000;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
    border: 2px solid #fff;
}

.turn-banner, .stats-pill {
    font-size: 0.9rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.hud-btn {
    background: var(--glass-bg);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 7px 12px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.hud-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    transform: translateY(-1px);
}

/* Main Table Layout */
.table-area {
    position: relative;
    z-index: 2;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 4px 20px 14px;
    min-height: 0;
}

.seat {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: opacity 0.25s ease;
}

.seat.hidden-seat {
    visibility: hidden;
    pointer-events: none;
}

.middle-row {
    flex: 1;
    display: grid;
    grid-template-columns: 185px 1fr 185px;
    align-items: center;
    gap: 12px;
    min-height: 0;
}

/* Bot Chat Bubbles */
.chat-bubble {
    position: absolute;
    top: -34px;
    z-index: 20;
    background: rgba(18, 22, 26, 0.94);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 14px;
    padding: 5px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
    opacity: 0;
    transform: translateY(6px) scale(0.92);
    transition: opacity 0.22s ease, transform 0.22s ease;
    pointer-events: none;
}

.seat-top .chat-bubble {
    top: auto;
    bottom: -26px;
}

.chat-bubble.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.chat-bubble.thinking {
    opacity: 0.85;
    animation: pulseThink 1s ease-in-out infinite alternate;
}

@keyframes pulseThink {
    from { transform: translateY(0) scale(0.96); }
    to { transform: translateY(-2px) scale(1.03); }
}

.uno-card-mini.ai-card-pick {
    transform: translateY(-10px) scale(1.08) !important;
    box-shadow: 0 0 14px rgba(255, 215, 0, 0.75);
}

/* Player Badges */
.player-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px 6px 8px;
    border-radius: 999px;
    background: var(--glass-bg);
    border: 2px solid var(--glass-border);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
}

.seat.active-turn .player-badge {
    border-color: #ffd700;
    box-shadow: 0 0 22px rgba(255, 215, 0, 0.45), 0 6px 18px rgba(0, 0, 0, 0.4);
    transform: scale(1.04);
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
}

.player-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.player-name {
    font-weight: 700;
    font-size: 0.9rem;
}

.card-count {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.uno-tag {
    background: linear-gradient(135deg, #ff3b30, #c8102e);
    color: #ffd700;
    font-weight: 900;
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1.5px solid #fff;
    text-shadow: 1px 1px 0 #000;
    animation: pulseUno 1s infinite alternate;
}

@keyframes pulseUno {
    from { transform: scale(1); }
    to { transform: scale(1.12); }
}

/* AI Hands */
.ai-hand {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-hand-horizontal .uno-card-mini { margin-left: -26px; }
.ai-hand-horizontal .uno-card-mini:first-child { margin-left: 0; }
.ai-hand-vertical { flex-direction: column; }
.ai-hand-vertical .uno-card-mini { margin-top: -54px; transform: rotate(90deg); }
.ai-hand-vertical .uno-card-mini:first-child { margin-top: 0; }

.uno-card-mini {
    width: 52px;
    height: 78px;
    border-radius: 7px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45);
    flex-shrink: 0;
}

.uno-card-mini svg {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 7px;
}

/* Center Zone */
.center-zone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 250px;
}

.direction-ring {
    position: absolute;
    width: 300px;
    height: 300px;
    color: rgba(255, 255, 255, 0.24);
    pointer-events: none;
    animation: spinCW 18s linear infinite;
}

.direction-ring.ccw { animation: spinCCW 18s linear infinite; }
.direction-ring.ccw .direction-svg { transform: scaleX(-1); }

@keyframes spinCW { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes spinCCW { from { transform: rotate(0deg); } to { transform: rotate(0deg); } }

.piles-container {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 36px;
}

.pile-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.draw-pile {
    position: relative;
    width: var(--card-w);
    height: var(--card-h);
    cursor: pointer;
    transition: transform 0.18s ease;
}

.draw-pile:hover { transform: translateY(-4px) scale(1.03); }

.draw-pile.highlight-draw {
    filter: drop-shadow(0 0 18px rgba(255, 215, 0, 0.85));
    animation: drawPulse 1.2s ease-in-out infinite;
}

@keyframes drawPulse {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-5px) scale(1.04); }
}

.pile-stack-layer {
    position: absolute;
    inset: 0;
    border-radius: var(--card-radius);
    background: #16161b;
    border: 2px solid #fff;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

.pile-stack-layer.layer-3 { transform: translate(6px, 6px); opacity: 0.7; }
.pile-stack-layer.layer-2 { transform: translate(3px, 3px); opacity: 0.88; }
.pile-stack-layer.layer-1 { transform: translate(0, 0); overflow: hidden; }

.pile-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.35);
    padding: 2px 10px;
    border-radius: 999px;
}

.discard-pile {
    position: relative;
    width: var(--card-w);
    height: var(--card-h);
}

.discard-pile .uno-card {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.active-color-pill {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    font-size: 0.82rem;
    font-weight: 700;
}

.color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #888;
    box-shadow: 0 0 8px currentColor;
}

.color-dot.red { background: var(--uno-red); color: var(--uno-red); }
.color-dot.blue { background: var(--uno-blue); color: var(--uno-blue); }
.color-dot.green { background: var(--uno-green); color: var(--uno-green); }
.color-dot.yellow { background: var(--uno-yellow); color: var(--uno-yellow); }

.stack-badge {
    position: absolute;
    top: -18px;
    z-index: 5;
    background: linear-gradient(135deg, #ff3b30, #d6001c);
    color: #fff;
    font-weight: 900;
    font-size: 0.95rem;
    padding: 5px 14px;
    border-radius: 999px;
    border: 2px solid #ffd700;
    box-shadow: 0 6px 20px rgba(229, 37, 33, 0.6);
    animation: pulseUno 0.7s infinite alternate;
}

.action-toast {
    position: absolute;
    bottom: -24px;
    z-index: 6;
    padding: 6px 16px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 0.88rem;
    font-weight: 600;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
    white-space: nowrap;
}

.action-toast.show { opacity: 1; transform: translateY(0); }

/* Realistic UNO Card + 3D Holo Glare */
.uno-card {
    position: relative;
    width: var(--card-w);
    height: var(--card-h);
    border-radius: var(--card-radius);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45), 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.18s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.22s ease, filter 0.22s ease;
    flex-shrink: 0;
    overflow: hidden;
    background: #fff;
    transform-style: preserve-3d;
}

.uno-card svg {
    width: 100%;
    height: 100%;
    display: block;
}

.uno-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--card-radius);
    background: radial-gradient(circle at var(--glare-x, 30%) var(--glare-y, 20%), rgba(255, 255, 255, 0.36) 0%, rgba(255, 255, 255, 0.04) 45%, rgba(0, 0, 0, 0.1) 100%);
    pointer-events: none;
}

/* Human Player Hand */
.seat-bottom { width: 100%; gap: 10px; }

.player-controls-bar {
    width: 100%;
    max-width: 900px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.action-buttons { display: flex; align-items: center; gap: 10px; }

.action-btn {
    border: none;
    border-radius: 12px;
    padding: 9px 18px;
    font-weight: 800;
    font-size: 0.92rem;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.action-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }
.btn-secondary { background: var(--glass-bg); color: var(--text-main); border: 1px solid var(--glass-border); }
.btn-secondary:hover:not(:disabled) { background: rgba(255, 255, 255, 0.16); }

.btn-warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #111;
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.45);
    animation: pulseUno 0.8s infinite alternate;
}

.btn-uno {
    background: linear-gradient(135deg, #e52521, #b31217);
    color: #ffd700;
    border: 2px solid #fff;
    text-shadow: 1px 1px 0 #000;
    letter-spacing: 1px;
    box-shadow: 0 6px 20px rgba(229, 37, 33, 0.5);
}

.btn-uno.ready {
    animation: pulseUno 0.7s infinite alternate;
    box-shadow: 0 0 26px rgba(255, 215, 0, 0.85);
}

.player-hand-wrapper {
    width: 100%;
    max-width: 1080px;
    display: flex;
    justify-content: center;
    padding: 24px 24px 6px;
    overflow-x: auto;
    overflow-y: visible;
    scrollbar-width: thin;
}

.player-hand {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    min-height: calc(var(--card-h) + 12px);
    perspective: 900px;
}

.player-hand .uno-card {
    margin-left: -34px;
    cursor: pointer;
    transform-origin: bottom center;
}

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

.player-hand .uno-card.playable {
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5), 0 0 0 2.5px rgba(255, 215, 0, 0.8);
}

.player-hand .uno-card.jump-in {
    box-shadow: 0 10px 26px rgba(0, 240, 255, 0.65), 0 0 0 3px #00f0ff;
    animation: jumpInPulse 0.9s infinite alternate;
}

@keyframes jumpInPulse {
    from { filter: brightness(1); }
    to { filter: brightness(1.18); }
}

.player-hand .uno-card.unplayable {
    filter: brightness(0.62) saturate(0.75);
    cursor: not-allowed;
}

/* FX & Confetti */
.fx-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    overflow: hidden;
}

.flying-card {
    position: fixed;
    width: var(--card-w);
    height: var(--card-h);
    border-radius: var(--card-radius);
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.55);
    transition: transform 0.36s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.36s ease;
    will-change: transform;
}

.particle {
    position: fixed;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    pointer-events: none;
    will-change: transform, opacity;
}

/* Modals */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(4, 10, 8, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.hidden { display: none !important; }

.modal-card {
    width: 100%;
    max-width: 460px;
    max-height: 92vh;
    overflow-y: auto;
    background: linear-gradient(160deg, #16231d 0%, #0d1512 100%);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 20px;
    padding: 26px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
    text-align: center;
}

.modal-logo { margin-bottom: 18px; }

.logo-oval {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 144px;
    height: 78px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e52521, #a80d12);
    border: 4px solid #fff;
    transform: rotate(-10deg);
    box-shadow: 0 10px 26px rgba(229, 37, 33, 0.45);
    margin-bottom: 8px;
}

.logo-oval span {
    font-size: 2.4rem;
    font-weight: 900;
    color: #ffd700;
    letter-spacing: 2px;
    text-shadow: 3px 3px 0 #000;
}

.modal-subtitle { color: var(--text-muted); font-size: 0.9rem; }

.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 20px;
    text-align: left;
}

.setting-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.setting-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.segmented {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 5px;
    background: rgba(0, 0, 0, 0.35);
    padding: 4px;
    border-radius: 11px;
}

.segmented button {
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 7px 6px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.segmented button.active { background: var(--accent); color: #fff; }

.setting-toggles {
    display: flex;
    flex-direction: column;
    gap: 9px;
    background: rgba(0, 0, 0, 0.25);
    padding: 12px 14px;
    border-radius: 12px;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88rem;
    cursor: pointer;
}

.toggle-row input { width: 16px; height: 16px; accent-color: var(--accent); }

.primary-cta {
    width: 100%;
    padding: 13px 20px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #27a363, #197a47);
    color: #fff;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(25, 122, 71, 0.45);
    transition: transform 0.15s ease, filter 0.15s ease;
}

.primary-cta:hover { transform: translateY(-2px); filter: brightness(1.08); }
.btn-danger { background: linear-gradient(135deg, #e52521, #b31217); box-shadow: 0 8px 20px rgba(229, 37, 33, 0.45); }

.secondary-cta {
    width: 100%;
    padding: 11px 20px;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
}

.color-wheel { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }

.color-choice {
    padding: 24px 12px;
    border: 3px solid rgba(255, 255, 255, 0.85);
    border-radius: 16px;
    font-size: 1.05rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    transition: transform 0.15s ease;
}

.color-choice:hover { transform: scale(1.05); }
.color-red { background: var(--uno-red); }
.color-blue { background: var(--uno-blue); }
.color-green { background: var(--uno-green); }
.color-yellow { background: var(--uno-yellow); color: #1b1b1b; text-shadow: none; }

.modal-desc { color: var(--text-muted); font-size: 0.92rem; margin: 8px 0 16px; }

.swap-targets { display: flex; flex-direction: column; gap: 10px; }

.swap-target-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    font-weight: 700;
    cursor: pointer;
}

.swap-target-btn:hover { background: rgba(35, 134, 84, 0.45); }

.gameover-icon { font-size: 3.2rem; margin-bottom: 6px; }

.scoreboard { display: flex; flex-direction: column; gap: 8px; margin: 16px 0 22px; text-align: left; }

.score-row {
    display: flex;
    justify-content: space-between;
    padding: 9px 14px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
    font-size: 0.9rem;
}

.score-row.winner { border: 1px solid #ffd700; background: rgba(255, 215, 0, 0.14); }
.gameover-actions { display: flex; flex-direction: column; gap: 10px; }

.rules-list {
    text-align: left;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 16px 0 22px;
    font-size: 0.88rem;
    line-height: 1.45;
    color: #d7e3dc;
}

.rules-list code { background: rgba(255, 255, 255, 0.12); padding: 2px 6px; border-radius: 5px; }

@media (max-width: 820px) {
    :root { --card-w: 84px; --card-h: 126px; }
    .middle-row { grid-template-columns: 110px 1fr 110px; }
    .player-hand .uno-card { margin-left: -26px; }
    .stats-pill { display: none; }
}
