:root {
    --bg-dark: #0f121d;
    --bg-card: rgba(26, 32, 53, 0.85);
    --bg-card-border: rgba(255, 255, 255, 0.1);
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent: #ec4899;
    --streamer-gold: #f59e0b;
    --streamer-gold-glow: rgba(245, 158, 11, 0.35);
    --viewer-cyan: #06b6d4;
    --viewer-cyan-glow: rgba(6, 182, 212, 0.35);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --board-light: #f1ebd9;
    --board-dark: #3b3a4a;
    --board-highlight: #22c55e;
    --board-capture: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: radial-gradient(circle at 50% 10%, #1e1b4b 0%, #0f121d 60%, #090a10 100%);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: rgba(15, 18, 29, 0.7);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--bg-card-border);
    z-index: 50;
}

.logo-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 1.8rem;
    animation: bounce 2s infinite ease-in-out;
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 900;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #a5b4fc, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-tag {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    padding: 2px 8px;
    border-radius: 12px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--bg-card-border);
    color: var(--text-main);
    width: 38px;
    height: 38px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

/* Room Pill in Header */
.room-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.room-pill:hover {
    background: rgba(99, 102, 241, 0.3);
    transform: scale(1.03);
}

.room-code-badge {
    color: #facc15;
    font-size: 1.05rem;
    font-family: monospace;
    letter-spacing: 2px;
}

/* Screens */
.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
}

.hidden {
    display: none !important;
}

/* Welcome Screen */
.welcome-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--bg-card-border);
    border-radius: 24px;
    padding: 32px;
    width: 100%;
    max-width: 460px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.welcome-card h2 {
    font-size: 1.8rem;
    font-weight: 900;
    margin-bottom: 8px;
}

.welcome-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 24px;
}

/* Tabs */
.tabs-switch {
    display: flex;
    background: rgba(0, 0, 0, 0.3);
    padding: 4px;
    border-radius: 14px;
    margin-bottom: 24px;
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 700;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

/* Avatar Picker */
.avatar-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    display: block;
    text-align: left;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.avatar-opt {
    font-size: 1.6rem;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.avatar-opt:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.1);
}

.avatar-opt.selected {
    border-color: #ec4899;
    background: rgba(236, 72, 153, 0.2);
    box-shadow: 0 0 12px rgba(236, 72, 153, 0.4);
}

/* Inputs */
.form-group {
    margin-bottom: 18px;
    text-align: left;
}

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

.input-field {
    width: 100%;
    padding: 12px 16px;
    background: rgba(15, 18, 29, 0.6);
    border: 1px solid var(--bg-card-border);
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
}

.input-field:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.code-input {
    text-transform: uppercase;
    font-family: monospace;
    font-size: 1.4rem;
    letter-spacing: 6px;
    text-align: center;
    font-weight: 900;
    color: #facc15;
}

/* Main Action Buttons */
.btn-primary {
    width: 100%;
    padding: 14px 20px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    border-radius: 14px;
    color: white;
    font-size: 1.05rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(99, 102, 241, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4);
}

.btn-success:hover {
    box-shadow: 0 12px 24px rgba(16, 185, 129, 0.5);
}

/* Lobby Screen */
.lobby-container {
    width: 100%;
    max-width: 800px;
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--bg-card-border);
    border-radius: 24px;
    padding: 28px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.lobby-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--bg-card-border);
    flex-wrap: wrap;
    gap: 16px;
}

.lobby-code-box {
    display: flex;
    align-items: center;
    gap: 12px;
}

.code-title {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.code-display {
    font-family: monospace;
    font-size: 2rem;
    font-weight: 900;
    color: #facc15;
    letter-spacing: 4px;
    background: rgba(0, 0, 0, 0.3);
    padding: 4px 16px;
    border-radius: 12px;
    border: 1px dashed rgba(250, 204, 21, 0.4);
}

.btn-copy-link {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--bg-card-border);
    color: white;
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-copy-link:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Lobby Players Grid (1 Streamer + 6 Viewers) */
.players-roster {
    margin-bottom: 24px;
}

.roster-title {
    font-size: 1.1rem;
    font-weight: 800;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.badge-count {
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    font-size: 0.85rem;
    padding: 2px 10px;
    border-radius: 12px;
}

.roster-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px;
}

.player-slot {
    background: rgba(15, 18, 29, 0.6);
    border: 1px solid var(--bg-card-border);
    border-radius: 16px;
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    transition: all 0.2s;
}

.player-slot.streamer-slot {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(15, 18, 29, 0.7));
    border-color: rgba(245, 158, 11, 0.5);
    box-shadow: 0 4px 16px var(--streamer-gold-glow);
}

.player-slot.empty-slot {
    border-style: dashed;
    opacity: 0.4;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

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

.slot-info {
    flex: 1;
    overflow: hidden;
}

.slot-name {
    font-weight: 800;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.slot-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.slot-kick {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.1rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.slot-kick:hover {
    opacity: 1;
}

/* Settings Bar in Lobby */
.lobby-settings {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
}

.setting-select {
    background: rgba(15, 18, 29, 0.8);
    border: 1px solid var(--bg-card-border);
    color: white;
    padding: 6px 12px;
    border-radius: 10px;
    outline: none;
    font-size: 0.85rem;
}

/* Game Screen Layout */
.game-container {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Top Turn Banner */
.turn-banner {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--bg-card-border);
    border-radius: 18px;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.turn-player-box {
    display: flex;
    align-items: center;
    gap: 14px;
}

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

.turn-details h3 {
    font-size: 1.25rem;
    font-weight: 900;
}

.turn-details p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Turn Timer SVG Ring */
.turn-timer-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.timer-circle {
    position: relative;
    width: 60px;
    height: 60px;
}

.timer-circle svg {
    transform: rotate(-90deg);
}

.timer-circle-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 5;
}

.timer-circle-progress {
    fill: none;
    stroke: var(--viewer-cyan);
    stroke-width: 5;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.9s linear, stroke 0.3s;
}

.timer-circle-progress.urgent {
    stroke: #ef4444;
    animation: pulse 0.5s infinite;
}

.timer-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.3rem;
    font-weight: 900;
    font-family: monospace;
}

.infinite-time-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: #facc15;
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 0.9rem;
}

/* Viewer Queue Strip */
.queue-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 18, 29, 0.6);
    border: 1px solid var(--bg-card-border);
    border-radius: 14px;
    padding: 8px 16px;
    overflow-x: auto;
    font-size: 0.85rem;
}

.queue-label {
    color: var(--text-muted);
    font-weight: 700;
    white-space: nowrap;
}

.queue-items {
    display: flex;
    align-items: center;
    gap: 8px;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.06);
    padding: 4px 10px;
    border-radius: 10px;
    white-space: nowrap;
}

.queue-item.active {
    background: rgba(6, 182, 212, 0.25);
    border: 1px solid rgba(6, 182, 212, 0.5);
    color: #67e8f9;
    font-weight: 800;
}

/* Main Playing Area: Board + Chat */
.game-main {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    align-items: start;
}

/* Checkers Board Area */
.board-area {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.board-wrapper {
    position: relative;
    width: 100%;
    max-width: 540px;
    aspect-ratio: 1 / 1;
    background: #252836;
    border-radius: 18px;
    padding: 16px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
    border: 4px solid #1a1b24;
}

.board-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.board-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    user-select: none;
}

.board-cell.light {
    background-color: var(--board-light);
}

.board-cell.dark {
    background-color: var(--board-dark);
}

.board-cell.highlight-from {
    background-color: rgba(99, 102, 241, 0.5) !important;
}

.board-cell.highlight-move {
    cursor: pointer;
}

.board-cell.highlight-move::after {
    content: '';
    position: absolute;
    width: 24%;
    height: 24%;
    background-color: var(--board-highlight);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--board-highlight);
    animation: pulse 1s infinite;
}

.board-cell.highlight-capture {
    background-color: rgba(239, 68, 68, 0.4) !important;
    cursor: pointer;
}

.board-cell.highlight-capture::after {
    content: '';
    position: absolute;
    width: 32%;
    height: 32%;
    border: 3px solid var(--board-capture);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--board-capture);
    animation: pulse 0.7s infinite;
}

/* Checkers Piece */
.piece {
    width: 82%;
    height: 82%;
    border-radius: 50%;
    position: relative;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.piece.white {
    background: radial-gradient(circle at 35% 35%, #ffffff 0%, #e2e8f0 60%, #cbd5e1 100%);
    box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.3), 0 4px 8px rgba(0, 0, 0, 0.4);
    border: 2px solid #94a3b8;
}

.piece.black {
    background: radial-gradient(circle at 35% 35%, #475569 0%, #1e293b 60%, #0f172a 100%);
    box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.6), 0 4px 8px rgba(0, 0, 0, 0.6);
    border: 2px solid #64748b;
}

.piece:hover {
    transform: scale(1.08);
}

.piece.selected {
    transform: scale(1.12);
    box-shadow: 0 0 16px #6366f1, inset 0 0 8px #818cf8;
}

.piece.is-king::before {
    content: '👑';
    font-size: 1.4rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
    animation: bounce 1.8s infinite;
}

/* Floating Reactions Overlay */
.reactions-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 40;
}

.floating-emoji {
    position: absolute;
    bottom: 20px;
    font-size: 2.2rem;
    animation: floatUp 3s cubic-bezier(0.2, 0.8, 0.4, 1) forwards;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
}

@keyframes floatUp {
    0% {
        opacity: 0;
        transform: translateY(0) scale(0.6) rotate(0deg);
    }
    15% {
        opacity: 1;
        transform: translateY(-40px) scale(1.2) rotate(10deg);
    }
    80% {
        opacity: 0.9;
        transform: translateY(-380px) scale(1) rotate(-10deg);
    }
    100% {
        opacity: 0;
        transform: translateY(-480px) scale(0.8) rotate(15deg);
    }
}

/* Quick Reaction Bar */
.reactions-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--bg-card-border);
    padding: 8px 16px;
    border-radius: 16px;
    width: 100%;
    max-width: 540px;
}

.reaction-btn {
    font-size: 1.6rem;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: transform 0.15s;
    padding: 4px;
    border-radius: 8px;
}

.reaction-btn:hover {
    transform: scale(1.35) rotate(-5deg);
    background: rgba(255, 255, 255, 0.1);
}

.reaction-btn:active {
    transform: scale(0.9);
}

/* Chat & Streamer Sidebar */
.game-sidebar {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--bg-card-border);
    border-radius: 20px;
    height: 580px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--bg-card-border);
    font-size: 0.95rem;
    font-weight: 800;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-messages {
    flex: 1;
    padding: 14px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-msg {
    font-size: 0.85rem;
    line-height: 1.4;
    word-break: break-word;
}

.chat-badge {
    font-size: 0.65rem;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 6px;
    text-transform: uppercase;
    margin-right: 4px;
}

.chat-badge.streamer {
    background: #f59e0b;
    color: black;
}

.chat-badge.viewer {
    background: #06b6d4;
    color: black;
}

.chat-badge.spectator {
    background: rgba(255, 255, 255, 0.15);
    color: #cbd5e1;
}

.chat-sender {
    font-weight: 800;
    color: #e2e8f0;
    margin-right: 6px;
}

.chat-input-bar {
    padding: 10px 14px;
    border-top: 1px solid var(--bg-card-border);
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    background: rgba(15, 18, 29, 0.7);
    border: 1px solid var(--bg-card-border);
    border-radius: 10px;
    padding: 8px 12px;
    color: white;
    font-size: 0.85rem;
    outline: none;
}

.chat-send-btn {
    background: var(--primary);
    border: none;
    color: white;
    padding: 0 14px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 700;
    transition: background 0.2s;
}

.chat-send-btn:hover {
    background: var(--primary-hover);
}

/* Game Over Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: 24px;
    padding: 36px;
    max-width: 440px;
    width: 100%;
    text-align: center;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
    animation: scaleIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-icon {
    font-size: 3.5rem;
    margin-bottom: 12px;
}

.modal-title {
    font-size: 1.8rem;
    font-weight: 900;
    margin-bottom: 8px;
}

.modal-desc {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 24px;
}

/* Animations */
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.15); }
}

@keyframes scaleIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Confetti Canvas */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 99;
}

/* Mobile Responsiveness */
@media (max-width: 860px) {
    .game-main {
        grid-template-columns: 1fr;
    }
    .game-sidebar {
        height: 320px;
    }
    .board-wrapper {
        max-width: 95vw;
    }
}
