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

:root {
    --bg:       #0d1117;
    --surface:  #161b22;
    --border:   #30363d;
    --accent:   #e94560;
    --accent2:  #58a6ff;
    --green:    #3fb950;
    --yellow:   #d29922;
    --text:     #e6edf3;
    --muted:    #8b949e;
    --radius:   10px;
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
a    { color: var(--accent2); text-decoration: none; }

/* ── AUTH ── */
.auth-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-box {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 40px; width: 100%; max-width: 420px;
    box-shadow: 0 16px 48px rgba(0,0,0,.5);
}
.auth-box .logo { text-align: center; font-size: 2rem; font-weight: 800; color: var(--accent); margin-bottom: 6px; }
.auth-box .sub  { text-align: center; color: var(--muted); font-size: .88rem; margin-bottom: 28px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 5px; }
.field input {
    width: 100%; padding: 10px 14px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text); font-size: .95rem; outline: none;
    transition: border-color .2s;
}
.field input:focus { border-color: var(--accent2); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 22px; border: none; border-radius: 8px;
    cursor: pointer; font-size: .9rem; font-weight: 600; transition: opacity .15s, transform .1s;
    text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary  { background: var(--accent);  color: #fff; width: 100%; }
.btn-outline  { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
.btn-green    { background: var(--green);   color: #fff; }
.btn-gray     { background: #21262d;        color: var(--text); border: 1px solid var(--border); }
.btn-blue     { background: var(--accent2); color: #000; }
.btn-sm       { padding: 6px 14px; font-size: .8rem; width: auto; }
.btn:hover    { opacity: .85; }

.flash { margin-top: 12px; text-align: center; font-size: .85rem; padding: 8px; border-radius: 6px; }
.flash.err  { background: rgba(233,69,96,.15); color: #ff6b81; border: 1px solid rgba(233,69,96,.3); }
.flash.ok   { background: rgba(63,185,80,.15);  color: #56d364; border: 1px solid rgba(63,185,80,.3); }

/* ── DASHBOARD ── */
.dash { display: flex; min-height: 100vh; }

/* Desktop sidebar */
.sidebar {
    width: 240px; background: var(--surface); border-right: 1px solid var(--border);
    padding: 20px 14px; display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar .logo { font-size: 1.2rem; font-weight: 800; color: var(--accent); text-align: center; margin-bottom: 20px; }
.sidebar .me   { text-align: center; margin-bottom: 20px; }
.avatar {
    width: 52px; height: 52px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #c0392b);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem; font-weight: 700; margin: 0 auto 8px;
}
.sidebar .me .uname { font-weight: 600; font-size: .95rem; }
.sidebar nav a {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 12px; border-radius: 8px; color: var(--muted);
    margin-bottom: 2px; font-size: .88rem; transition: background .15s, color .15s;
}
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(88,166,255,.1); color: var(--text); }
.sidebar .logout-btn { margin-top: auto; }

/* Mobile top bar (hidden on desktop) */
.mob-topbar {
    display: none;
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 0 16px;
    height: 56px; align-items: center; justify-content: space-between;
}
.mob-topbar .logo { font-size: 1.1rem; font-weight: 800; color: var(--accent); }
.mob-topbar .me-row { display: flex; align-items: center; gap: 8px; }
.mob-topbar .avatar-sm {
    width: 34px; height: 34px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #c0392b);
    display: flex; align-items: center; justify-content: center;
    font-size: .95rem; font-weight: 700;
}
.mob-topbar .uname-sm { font-size: .82rem; font-weight: 600; }

/* Mobile bottom nav (hidden on desktop) */
.mob-nav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
    background: var(--surface); border-top: 1px solid var(--border);
    height: 60px;
}
.mob-nav ul {
    list-style: none; display: flex; height: 100%;
}
.mob-nav ul li { flex: 1; }
.mob-nav ul li a, .mob-nav ul li button {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    width: 100%; height: 100%; gap: 3px;
    color: var(--muted); font-size: .65rem; font-weight: 600;
    background: none; border: none; cursor: pointer;
    text-decoration: none; transition: color .15s;
    -webkit-tap-highlight-color: transparent;
}
.mob-nav ul li a.active, .mob-nav ul li a:hover,
.mob-nav ul li button:hover { color: var(--accent2); }
.mob-nav .nav-icon { font-size: 1.3rem; line-height: 1; }
.mob-nav .nav-badge {
    position: absolute; top: 6px; right: calc(50% - 18px);
    background: var(--accent); color: #fff;
    border-radius: 8px; padding: 1px 5px; font-size: .6rem; font-weight: 700;
}
.mob-nav ul li { position: relative; }

.main { flex: 1; padding: 28px; overflow-y: auto; }
.main h2 { font-size: 1.3rem; margin-bottom: 18px; }

.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.card h3 { font-size: 1rem; color: var(--accent2); margin-bottom: 14px; }

/* Board size selector — pill style */
.size-selector {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 10px; padding: 10px 14px; margin-bottom: 14px;
}
.size-selector label { font-size: .82rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.size-selector input[type=range] {
    flex: 1; accent-color: var(--accent2); cursor: pointer; height: 4px;
}
.size-val {
    font-size: .9rem; font-weight: 700; color: var(--accent2);
    min-width: 44px; text-align: center;
    background: rgba(88,166,255,.12); border-radius: 6px; padding: 2px 8px;
}

.row-input { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.row-input input {
    flex: 1; padding: 10px 14px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text); outline: none; font-size: 1rem;
}
.row-input input:focus { border-color: var(--accent2); }

/* User list cards — touch friendly */
.user-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 0; border-bottom: 1px solid var(--border);
    gap: 10px;
}
.user-item:last-child { border-bottom: none; }
.user-item .info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-item .uname-wrap { display: flex; flex-direction: column; min-width: 0; }
.user-item .uname-wrap strong { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-item .uname-wrap small { font-size: .72rem; color: var(--muted); }

.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot.on  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.off { background: var(--muted); }

/* Invite items */
.invite-item {
    padding: 12px 0; border-bottom: 1px solid var(--border);
}
.invite-item:last-child { border-bottom: none; }
.invite-item .invite-info { font-size: .88rem; margin-bottom: 10px; line-height: 1.5; }
.invite-item .acts { display: flex; gap: 8px; }
.invite-item .acts .btn { flex: 1; justify-content: center; padding: 10px; font-size: .85rem; }

.badge {
    display: inline-block; background: var(--accent); color: #fff;
    border-radius: 10px; padding: 1px 7px; font-size: .72rem; font-weight: 700; margin-left: 6px;
}

/* ── GAME PAGE ── */
.game-wrap { display: flex; gap: 18px; padding: 18px; min-height: 100vh; align-items: flex-start; }
.game-center { flex: 1; min-width: 0; }
.game-side   { width: 270px; flex-shrink: 0; display: flex; flex-direction: column; gap: 14px; }

.info-bar {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px;
}
.player-tag { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.piece-dot  { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); }
.piece-dot.p1 { background: radial-gradient(circle at 35% 35%, #e74c3c, #922b21); }
.piece-dot.p2 { background: radial-gradient(circle at 35% 35%, #aaa, #333); }
.turn-badge { font-size: .82rem; font-weight: 700; padding: 4px 12px; border-radius: 20px; }
.turn-badge.mine { background: rgba(63,185,80,.2); color: var(--green); border: 1px solid rgba(63,185,80,.4); }
.turn-badge.theirs { background: rgba(139,148,158,.1); color: var(--muted); border: 1px solid var(--border); }

#board-scroll { overflow: auto; }
#board-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
#board-scroll::-webkit-scrollbar-track { background: var(--bg); }
#board-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#board-scroll::-webkit-scrollbar-thumb:hover { background: var(--muted); }
#checker-board { display: inline-block; border: 3px solid var(--border); border-radius: 4px; user-select: none; }
.board-row { display: flex; }
.cell {
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; position: relative; transition: filter .1s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}
.cell.light { background: #f0d9b5; }
.cell.dark  { background: #b58863; }
.cell.sel   { background: #6abf69 !important; }
.cell.hint  { background: #8fd68f !important; animation: hintPulse 1.5s infinite; }
.cell.hint::after {
    content: ''; width: 30%; height: 30%; background: rgba(0,100,0,.35);
    border-radius: 50%; position: absolute;
}
.cell.hint.multi-capture { background: #ffd700 !important; animation: multiCapturePulse 1s infinite; }
.cell.hint.multi-capture::after {
    content: '✂'; font-size: 1.2em; color: #c0392b; font-weight: bold;
    background: none; width: auto; height: auto;
}

@keyframes multiCapturePulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 10px rgba(255,215,0,0.8); }
    50% { opacity: 0.85; box-shadow: 0 0 20px rgba(255,215,0,1); }
}

@keyframes hintPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}
.cell.last-from { outline: 3px solid rgba(255,200,0,.7); outline-offset: -3px; }
.cell.last-to   { outline: 3px solid rgba(255,200,0,.9); outline-offset: -3px; }

.piece {
    border-radius: 50%; border: 3px solid rgba(255,255,255,.25);
    box-shadow: 0 3px 8px rgba(0,0,0,.5), inset 0 1px 3px rgba(255,255,255,.2);
    display: flex; align-items: center; justify-content: center;
    font-size: .9rem; transition: transform .12s, box-shadow .2s; position: relative; z-index: 1;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: none;
}
.piece:hover { transform: scale(1.1); box-shadow: 0 5px 15px rgba(0,0,0,.7), inset 0 1px 3px rgba(255,255,255,.2); }
.piece.p1 { background: radial-gradient(circle at 35% 35%, #e74c3c, #7b241c); }
.piece.p2 { background: radial-gradient(circle at 35% 35%, #bbb, #2c2c2c); }
.piece.king::after { content: '♛'; color: gold; text-shadow: 0 1px 2px rgba(0,0,0,.6); animation: kingGlow 2s infinite; }

@keyframes kingGlow {
    0%, 100% { filter: drop-shadow(0 0 3px gold); }
    50% { filter: drop-shadow(0 0 8px gold); }
}

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

@keyframes opponentMove {
    0%, 100% { box-shadow: 0 0 0 rgba(88,166,255,0); }
    50% { box-shadow: 0 0 30px rgba(88,166,255,0.8); }
}

/* ── SIDE PANELS ── */
.panel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px;
}
.panel h4 { font-size: .88rem; color: var(--accent2); margin-bottom: 10px; }

/* voice */
.voice-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.vdot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.vdot.live { background: var(--green); animation: blink 1.2s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }
#voice-status { font-size: .8rem; color: var(--muted); }

/* online status */
.online-row { display: flex; align-items: center; gap: 6px; font-size: .82rem; margin-bottom: 4px; }

/* score */
.score-row { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 6px; }
.score-row .score-num { font-weight: 700; color: var(--accent2); font-size: 1.1rem; }

/* stats */
.stats-grid { display: flex; flex-direction: column; gap: 6px; }
.stat-item { display: flex; justify-content: space-between; font-size: .82rem; padding: 4px 0; border-bottom: 1px solid var(--border); }
.stat-item:last-child { border-bottom: none; }
.stat-item span:last-child { font-weight: 700; color: var(--accent2); }

/* chat */
.chat-panel { display: flex; flex-direction: column; }
#chat-msgs {
    height: 160px; overflow-y: auto; margin-bottom: 8px;
    font-size: .8rem; display: flex; flex-direction: column; gap: 4px;
}
.chat-msg { padding: 4px 8px; border-radius: 6px; background: rgba(255,255,255,.04); }
.chat-msg .who { font-weight: 700; color: var(--accent2); margin-right: 4px; }
.chat-msg.mine .who { color: var(--green); }
.chat-input-row { display: flex; gap: 6px; }
.chat-input-row input {
    flex: 1; padding: 7px 10px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 7px; color: var(--text); font-size: .82rem; outline: none;
}
.chat-input-row input:focus { border-color: var(--accent2); }

/* move log */
#move-list { max-height: 130px; overflow-y: auto; font-size: .78rem; color: var(--muted); }
.move-log-item { padding: 5px 8px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.02); border-radius: 4px; margin-bottom: 3px; transition: background .2s; }
.move-log-item:hover { background: rgba(255,255,255,.05); }

/* game actions */
.game-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ── MODAL ── */
.modal-bg {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.75); z-index: 999;
    align-items: center; justify-content: center;
}
.modal-bg.show { display: flex; }
.modal {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 32px; text-align: center;
    max-width: 360px; width: 90%;
    animation: pop .2s ease;
}
@keyframes pop { from{transform:scale(.9);opacity:0} to{transform:scale(1);opacity:1} }
.modal h2 { font-size: 1.5rem; margin-bottom: 10px; }
.modal p  { color: var(--muted); margin-bottom: 20px; font-size: .9rem; }
.modal .acts { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
    .game-wrap { flex-direction: column; }
    .game-side  { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    .chat-panel { grid-column: 1 / -1; }
}

/* ── MOBILE (≤ 640px) ── */
@media (max-width: 640px) {

    /* Hide desktop sidebar, show mobile chrome */
    .sidebar    { display: none; }
    .mob-topbar { display: flex; }
    .mob-nav    { display: block; }

    /* Push content below topbar and above bottom nav */
    .dash { display: block; }
    .main {
        padding: 72px 14px 76px;
        min-height: 100vh;
    }
    .main h2 { font-size: 1.1rem; margin-bottom: 14px; }

    .card { padding: 14px; border-radius: 12px; }
    .card h3 { font-size: .95rem; }

    /* Bigger tap targets for buttons */
    .btn-sm { padding: 10px 16px; font-size: .85rem; }

    /* Search input full width on mobile */
    .row-input { flex-wrap: wrap; }
    .row-input input { font-size: 1rem; padding: 12px 14px; }
    .row-input .btn  { width: 100%; }

    /* User items — stack nicely */
    .user-item { padding: 14px 0; }
    .user-item .btn { padding: 10px 18px; font-size: .85rem; }

    /* Invite buttons full width */
    .invite-item .acts .btn { padding: 12px; font-size: .88rem; }

    /* Modal full-width on mobile */
    .modal { padding: 24px 18px; border-radius: 18px 18px 0 0; }
    .modal-bg.show { align-items: flex-end; }

    /* Auth pages */
    .auth-box { padding: 28px 20px; border-radius: 0; min-height: 100vh;
        display: flex; flex-direction: column; justify-content: center; }

    /* ── GAME PAGE MOBILE ── */
    .game-wrap { 
        flex-direction: column; 
        padding: 10px; 
        gap: 12px;
        padding-bottom: 20px;
    }
    
    .game-center { width: 100%; }
    
    .info-bar {
        flex-direction: column;
        gap: 10px;
        padding: 10px 12px;
    }
    
    .info-bar .player-tag {
        width: 100%;
        justify-content: center;
        font-size: .85rem;
    }
    
    .turn-badge {
        width: 100%;
        text-align: center;
        padding: 8px 12px;
        font-size: .85rem;
    }
    
    #board-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -10px;
        padding: 0 10px;
    }
    
    #checker-board {
        margin: 0 auto;
        display: block;
    }
    
    .game-actions {
        flex-direction: column;
        gap: 10px;
    }
    
    .game-actions .btn {
        width: 100%;
        padding: 12px;
        font-size: .9rem;
    }
    
    .game-side {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    
    .panel {
        padding: 12px;
    }
    
    .panel h4 {
        font-size: .85rem;
        margin-bottom: 8px;
    }
    
    /* Voice panel compact */
    .voice-row {
        margin-bottom: 8px;
    }
    
    #voice-status {
        font-size: .75rem;
    }
    
    #mute-btn {
        width: 100%;
        padding: 10px;
    }
    
    /* Online status compact */
    .online-row {
        font-size: .78rem;
    }
    
    /* Score compact */
    .score-row {
        font-size: .82rem;
    }
    
    .score-row .score-num {
        font-size: 1rem;
    }
    
    /* Stats compact */
    .stat-item {
        font-size: .78rem;
    }
    
    /* Chat panel mobile optimized */
    .chat-panel {
        order: -1; /* Move chat to top on mobile */
    }
    
    #chat-msgs {
        height: 120px;
        font-size: .78rem;
    }
    
    .chat-input-row input {
        font-size: .85rem;
        padding: 10px 12px;
    }
    
    .chat-input-row .btn {
        padding: 10px 14px;
        font-size: .8rem;
    }
    
    /* Move log compact */
    #move-list {
        max-height: 100px;
        font-size: .75rem;
    }
    
    .move-log-item {
        padding: 4px 6px;
        margin-bottom: 2px;
    }
    
    /* Piece dots smaller on mobile */
    .piece-dot {
        width: 18px;
        height: 18px;
    }
    
    /* Better touch targets for cells */
    .cell {
        min-width: 32px;
        min-height: 32px;
    }
    
    /* Winner modal mobile */
    #winner-modal .modal {
        width: 95%;
        padding: 28px 20px;
    }
    
    #winner-modal .modal h2 {
        font-size: 1.3rem;
    }
    
    #winner-modal .modal .acts {
        flex-direction: column;
        width: 100%;
    }
    
    #winner-modal .modal .acts .btn {
        width: 100%;
        padding: 14px;
    }
}
