:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --board-dark: #4a3728;
    --board-light: #e8d5b7;
    --player-red: #e63946;
    --player-white: #f1faee;
    --valid-move: rgba(6, 214, 160, 0.5);
    --selected: #ffd60a;
    --accent: #7209b7;
    --accent-hover: #8a2be2;
    --text-primary: #edf2f4;
    --text-secondary: #8d99ae;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --radius: 16px;
    --radius-sm: 8px;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#lobby {
    justify-content: center;
    align-items: center;
    padding: 16px;
    background: 
        radial-gradient(ellipse at 20% 80%, rgba(114, 9, 183, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(230, 57, 70, 0.1) 0%, transparent 50%),
        var(--bg-primary);
}

.lobby-card {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    padding: 40px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
    text-align: center;
}

.lobby-card h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--player-red), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 1rem;
}

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

.input-group input {
    width: 100%;
    padding: 14px 16px;
    font-size: 1rem;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(114, 9, 183, 0.2);
}

.input-group input::placeholder {
    color: var(--text-secondary);
}

#roomCode {
    text-transform: uppercase;
    letter-spacing: 0.3em;
    font-size: 1.25rem;
    text-align: center;
    font-weight: 700;
}

.button-group {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.button-group .btn {
    flex: 1;
}

.btn {
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.2s, filter 0.2s;
}

.btn:hover {
    transform: scale(1.03);
    filter: brightness(1.1);
}

.btn:active {
    transform: scale(0.98);
}

.btn.primary {
    background: var(--accent);
    color: white;
}

.btn.secondary {
    background: transparent;
    border: 2px solid var(--accent);
    color: var(--accent);
}

.btn.small {
    padding: 10px 16px;
    font-size: 0.875rem;
}

.hidden {
    display: none !important;
}

.error {
    color: var(--player-red);
    margin-top: 12px;
    font-size: 0.875rem;
}

#game {
    flex-direction: column;
    height: 100vh;
    background: 
        radial-gradient(ellipse at 30% 70%, rgba(114, 9, 183, 0.1) 0%, transparent 50%),
        var(--bg-primary);
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
}

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

.room-code {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: var(--accent);
    background: rgba(114, 9, 183, 0.2);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
}

.turn-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.turn-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: background 0.3s;
}

.turn-dot.red {
    background: var(--player-red);
    box-shadow: 0 0 8px var(--player-red);
}

.turn-dot.white {
    background: var(--player-white);
    box-shadow: 0 0 8px var(--player-white);
}

.player-badge {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
}

.player-badge.red {
    background: var(--player-red);
    color: white;
}

.player-badge.white {
    background: var(--player-white);
    color: #333;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

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

.chat-toggle {
    position: relative;
}

.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--player-red);
    color: white;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.game-main {
    flex: 1;
    display: flex;
    padding: 16px;
    gap: 16px;
    overflow: hidden;
    position: relative;
}

.board-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.board-coords {
    display: flex;
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.board-coords.top, .board-coords.bottom {
    gap: 0;
}

.board-coords.top span, .board-coords.bottom span {
    width: min(11vw, 60px);
    text-align: center;
}

.board-coords.left, .board-coords.right {
    flex-direction: column;
    gap: 0;
}

.board-coords.left span, .board-coords.right span {
    height: min(11vw, 60px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.board-wrapper {
    display: flex;
    gap: 4px;
}

.board {
    display: grid;
    grid-template-columns: repeat(8, min(11vw, 60px));
    grid-template-rows: repeat(8, min(11vw, 60px));
    border-radius: 4px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.square {
    width: min(11vw, 60px);
    height: min(11vw, 60px);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

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

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

.square.valid-move::after {
    content: '';
    position: absolute;
    width: 40%;
    height: 40%;
    background: var(--valid-move);
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

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

.square.valid-move.jump::after {
    width: 30%;
    height: 30%;
    background: rgba(230, 57, 70, 0.6);
}

.piece {
    width: 80%;
    height: 80%;
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    transition: transform 0.15s;
    border: 3px solid rgba(0, 0, 0, 0.3);
}

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

.piece.red {
    background: radial-gradient(circle at 30% 30%, #ff6b6b, var(--player-red), #b71c1c);
    box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.3), 0 4px 8px rgba(0, 0, 0, 0.3);
}

.piece.white {
    background: radial-gradient(circle at 30% 30%, #ffffff, var(--player-white), #c8d6e5);
    box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.15), 0 4px 8px rgba(0, 0, 0, 0.2);
}

.piece.selected {
    border-color: var(--selected);
    box-shadow: 0 0 12px var(--selected), inset 0 -4px 8px rgba(0, 0, 0, 0.3);
}

.piece.king::before {
    content: '♔';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    color: rgba(0, 0, 0, 0.5);
}

.piece.red.king::before {
    color: rgba(255, 255, 255, 0.7);
}

.chat-panel {
    width: 280px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    font-weight: 600;
}

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

.chat-message {
    font-size: 0.875rem;
    line-height: 1.4;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    word-break: break-word;
}

.chat-message.system {
    background: rgba(114, 9, 183, 0.2);
    color: var(--accent);
    text-align: center;
    font-size: 0.8rem;
}

.chat-message .msg-name {
    font-weight: 600;
    margin-right: 6px;
}

.chat-message.player-1 .msg-name {
    color: var(--player-red);
}

.chat-message.player-2 .msg-name {
    color: var(--player-white);
}

.chat-message.player-1 {
    background: rgba(230, 57, 70, 0.15);
}

.chat-message.player-2 {
    background: rgba(241, 250, 238, 0.1);
}

.chat-input {
    display: flex;
    gap: 8px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
}

.chat-input input {
    flex: 1;
    padding: 10px 12px;
    font-size: 0.875rem;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
}

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

.chat-input .btn {
    padding: 10px 14px;
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    background: var(--bg-secondary);
    padding: 40px;
    border-radius: var(--radius);
    text-align: center;
    max-width: 320px;
    box-shadow: var(--shadow);
}

.overlay-content h2 {
    font-size: 1.75rem;
    margin-bottom: 12px;
}

.overlay-content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

@media (max-width: 768px) {
    .lobby-card {
        padding: 32px 24px;
    }
    
    .lobby-card h1 {
        font-size: 2rem;
    }
    
    .game-main {
        padding: 12px;
        flex-direction: column;
    }
    
    .board-container {
        flex: 1;
        min-height: 0;
    }
    
    .square {
        width: min(12vw, 50px);
        height: min(12vw, 50px);
    }
    
    .board {
        grid-template-columns: repeat(8, min(12vw, 50px));
        grid-template-rows: repeat(8, min(12vw, 50px));
    }
    
    .board-coords.left span, .board-coords.right span {
        height: min(12vw, 50px);
    }
    
    .board-coords.top span, .board-coords.bottom span {
        width: min(12vw, 50px);
    }
    
    .chat-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 300px;
        border-radius: 0;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        z-index: 50;
    }
    
    .chat-panel.open {
        transform: translateX(0);
    }
    
    .game-main.chat-open .board-container {
        display: none;
    }
    
    .game-header {
        padding: 10px 12px;
    }
    
    .room-code {
        font-size: 1rem;
        padding: 4px 8px;
    }
    
    .turn-indicator {
        font-size: 0.8rem;
    }
}

@media (max-width: 400px) {
    .button-group {
        flex-direction: column;
    }
    
    .lobby-card {
        padding: 24px 20px;
    }
    
    .square {
        width: min(10.5vw, 42px);
        height: min(10.5vw, 42px);
    }
    
    .board {
        grid-template-columns: repeat(8, min(10.5vw, 42px));
        grid-template-rows: repeat(8, min(10.5vw, 42px));
    }
    
    .board-coords.left span, .board-coords.right span {
        height: min(10.5vw, 42px);
    }
    
    .board-coords.top span, .board-coords.bottom span {
        width: min(10.5vw, 42px);
    }
    
    .piece.king::before {
        font-size: 1.2rem;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .chat-panel {
        width: 240px;
    }
    
    .square {
        width: min(9vw, 55px);
        height: min(9vw, 55px);
    }
    
    .board {
        grid-template-columns: repeat(8, min(9vw, 55px));
        grid-template-rows: repeat(8, min(9vw, 55px));
    }
}
