/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f0e17;
    --bg-secondary: #1a1932;
    --bg-tertiary: #252347;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-hover: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.08);
    --text-primary: #fffffe;
    --text-secondary: #a7a9be;
    --text-muted: #5e5f7e;
    --accent: #7f5af0;
    --accent-glow: rgba(127, 90, 240, 0.35);
    --accent-secondary: #2cb67d;
    --danger: #e53170;
    --gold: #f5c542;

    --sq-light: #b8a690;
    --sq-dark: #6b4e3d;
    --sq-highlight: rgba(127, 90, 240, 0.45);
    --sq-move: rgba(44, 182, 125, 0.5);
    --sq-capture: rgba(229, 49, 112, 0.5);

    --piece-light: #f0e6d2;
    --piece-light-border: #d4c4a8;
    --piece-dark: #2a2a2a;
    --piece-dark-border: #444;

    --radius: 14px;
    --radius-sm: 8px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(127, 90, 240, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(44, 182, 125, 0.06) 0%, transparent 50%);
}

/* ===== SCREENS ===== */
.screen {
    display: none;
    width: 100%;
    min-height: 100vh;
}
.screen.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ===== MAIN MENU ===== */
.menu-container {
    text-align: center;
    padding: 3rem 2rem;
    position: relative;
}

.logo-glow {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
    pointer-events: none;
    animation: pulse-glow 4s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 0.5; transform: translateX(-50%) scale(1); }
    50% { opacity: 1; transform: translateX(-50%) scale(1.15); }
}

.game-title {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    position: relative;
    z-index: 1;
}

.game-subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 300;
    margin-bottom: 2.5rem;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 360px;
    margin: 0 auto 2rem;
}

.menu-btn {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition);
    backdrop-filter: blur(10px);
    text-align: left;
}
.menu-btn:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--accent-glow);
}
.menu-btn.primary {
    background: linear-gradient(135deg, rgba(127, 90, 240, 0.2), rgba(127, 90, 240, 0.05));
    border-color: rgba(127, 90, 240, 0.3);
}
.menu-btn.secondary {
    background: linear-gradient(135deg, rgba(44, 182, 125, 0.15), rgba(44, 182, 125, 0.03));
    border-color: rgba(44, 182, 125, 0.2);
}
.menu-btn .btn-icon {
    font-size: 2rem;
    line-height: 1;
}
.menu-btn .btn-text strong {
    display: block;
    font-weight: 600;
    font-size: 1.05rem;
}
.menu-btn .btn-text small {
    color: var(--text-secondary);
    font-size: 0.85rem;
}
.menu-btn.small {
    padding: 0.7rem 1.2rem;
    font-size: 0.9rem;
    gap: 0.5rem;
    justify-content: center;
}
.menu-btn.start-btn {
    margin-top: 1rem;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent), #6341d0);
    border-color: var(--accent);
    font-weight: 600;
    font-size: 1.05rem;
}
.menu-btn.start-btn:hover {
    box-shadow: 0 8px 40px var(--accent-glow);
}

/* Difficulty panel */
.difficulty-panel {
    max-width: 360px;
    margin: 0 auto;
    padding: 1.5rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    backdrop-filter: blur(10px);
    animation: slide-up 0.4s ease;
}
.difficulty-panel.hidden {
    display: none;
}
.difficulty-panel h3 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}
.difficulty-buttons {
    display: flex;
    gap: 0.5rem;
}
.diff-btn {
    flex: 1;
    padding: 0.65rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
}
.diff-btn:hover {
    background: var(--surface-hover);
}
.diff-btn.active {
    background: rgba(127, 90, 240, 0.2);
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--accent-glow);
}

@keyframes slide-up {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== GAME SCREEN ===== */
#game-screen.active {
    flex-direction: column;
    align-items: center;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 900px;
    padding: 1rem 1.5rem;
}

.icon-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
}
.icon-btn:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
}

.turn-indicator {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 1.2rem;
    border-radius: 50px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-weight: 500;
    font-size: 0.95rem;
}
.turn-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--piece-light);
    border: 2px solid var(--piece-light-border);
    transition: var(--transition);
    box-shadow: 0 0 8px rgba(240, 230, 210, 0.4);
}
.turn-indicator.dark .turn-dot {
    background: var(--piece-dark);
    border-color: var(--piece-dark-border);
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.4);
}

/* ===== GAME LAYOUT ===== */
.game-layout {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 1.5rem;
    padding: 0 1rem 2rem;
}

.side-panel {
    width: 140px;
    padding: 1rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    backdrop-filter: blur(10px);
    text-align: center;
}
.side-panel h3 {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.8rem;
}
.panel-player {
    display: block;
    font-weight: 600;
    font-size: 1rem;
    margin-top: 0.2rem;
}
.dark-label { color: #aaa; }
.light-label { color: #f0e6d2; }

.captured-pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    min-height: 60px;
    margin-bottom: 0.5rem;
}
.captured-piece {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    animation: pop-in 0.3s ease;
}
.captured-piece.light {
    background: radial-gradient(circle at 35% 35%, #fff, var(--piece-light));
    border: 1px solid var(--piece-light-border);
}
.captured-piece.dark {
    background: radial-gradient(circle at 35% 35%, #555, var(--piece-dark));
    border: 1px solid var(--piece-dark-border);
}

@keyframes pop-in {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.score-display {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
}

/* ===== BOARD ===== */
.board-wrapper {
    position: relative;
}

.board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    width: min(560px, 85vw);
    height: min(560px, 85vw);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow:
        0 0 0 3px var(--bg-tertiary),
        0 0 0 5px var(--border),
        0 20px 60px rgba(0, 0, 0, 0.5);
}

.info-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(15, 14, 23, 0.75);
    backdrop-filter: blur(4px);
    border: 1px solid var(--border);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 5;
    pointer-events: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.info-overlay span {
    color: var(--text-primary);
    font-weight: 700;
}

/* Scrollbar for stats */
#stats-content::-webkit-scrollbar {
    width: 6px;
}
#stats-content::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
}
#stats-content::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
}
#stats-content .stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
#stats-content .stat-row:last-child {
    border-bottom: none;
}

.square {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s ease;
}
.square.light-sq {
    background: var(--sq-light);
}
.square.dark-sq {
    background: var(--sq-dark);
}
.square.highlighted {
    background: var(--sq-highlight);
    cursor: pointer;
}
.square.move-target {
    cursor: pointer;
}
.square.move-target::after {
    content: '';
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: var(--sq-move);
    box-shadow: 0 0 10px var(--sq-move);
    animation: dot-pulse 1.5s ease-in-out infinite;
}
.square.capture-target::after {
    width: 70%;
    height: 70%;
    border: 3px solid var(--danger);
    border-radius: 50%;
    background: var(--sq-capture);
    box-shadow: 0 0 15px var(--sq-capture);
}

.square.hint-sq::before {
    content: '';
    position: absolute;
    inset: 4px;
    border: 3px dashed var(--gold);
    border-radius: var(--radius-sm);
    z-index: 4;
    animation: spin-dash 4s linear infinite;
    pointer-events: none;
}

@keyframes spin-dash {
    to { transform: rotate(360deg); }
}

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

/* ===== PIECES ===== */
.piece {
    width: 78%;
    height: 78%;
    border-radius: 50%;
    cursor: pointer;
    position: absolute;
    transition: transform 0.15s ease, box-shadow 0.2s ease;
    z-index: 2;
}
.piece.light-piece {
    background: radial-gradient(circle at 38% 35%, #fff, var(--piece-light) 70%);
    border: 2.5px solid var(--piece-light-border);
    box-shadow:
        inset 0 -3px 6px rgba(0, 0, 0, 0.15),
        0 3px 8px rgba(0, 0, 0, 0.3);
}
.piece.dark-piece {
    background: radial-gradient(circle at 38% 35%, #666, var(--piece-dark) 70%);
    border: 2.5px solid var(--piece-dark-border);
    box-shadow:
        inset 0 -3px 6px rgba(0, 0, 0, 0.3),
        0 3px 8px rgba(0, 0, 0, 0.4);
}
.piece:hover {
    transform: scale(1.08);
    box-shadow:
        inset 0 -3px 6px rgba(0, 0, 0, 0.15),
        0 5px 20px rgba(0, 0, 0, 0.4);
}
.piece.selected {
    transform: scale(1.12);
    box-shadow:
        0 0 0 3px var(--accent),
        0 0 20px var(--accent-glow),
        0 5px 20px rgba(0, 0, 0, 0.4);
    z-index: 3;
}

/* King crown */
.piece.king::after {
    content: '♛';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.4rem;
    line-height: 1;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}
.piece.light-piece.king::after {
    color: var(--gold);
}
.piece.dark-piece.king::after {
    color: var(--gold);
}

/* Moving animation */
.piece.moving {
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100 !important;
}

/* Capture animation */
.piece.captured {
    animation: capture-fade 0.35s ease forwards;
    pointer-events: none;
}
@keyframes capture-fade {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.5; }
    100% { transform: scale(0); opacity: 0; }
}

/* Crown animation */
.piece.crowning {
    animation: crown-glow 0.6s ease;
}
@keyframes crown-glow {
    0% { box-shadow: 0 0 0 0 rgba(245, 197, 66, 0); }
    50% { box-shadow: 0 0 30px 10px rgba(245, 197, 66, 0.6); }
    100% { box-shadow: 0 3px 8px rgba(0,0,0,0.3); }
}

/* ===== GAME OVER ===== */
.game-over-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(15, 14, 23, 0.85);
    backdrop-filter: blur(6px);
    border-radius: var(--radius);
    z-index: 20;
    animation: fade-in 0.4s ease;
}
.game-over-overlay.hidden {
    display: none;
}
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
.game-over-box {
    text-align: center;
    padding: 2rem 2.5rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    backdrop-filter: blur(15px);
    animation: slide-up 0.5s ease;
}
.game-over-box h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--gold), #ff9a56);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.game-over-box p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}
.game-over-buttons {
    display: flex;
    gap: 0.8rem;
    justify-content: center;
}

/* ===== UTILITIES ===== */
.hidden { display: none !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 850px) {
    .side-panel { display: none; }
    .game-layout { gap: 0; }
}
@media (max-width: 500px) {
    .game-title { font-size: 2.4rem; }
    .game-header { padding: 0.8rem 0.5rem; }
}

/* ============ MULTIPLAYER / LOBBY ============ */
.menu-btn.accent {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    border-color: rgba(255, 255, 255, 0.2);
}

#lobby-panel {
    max-width: 400px;
    margin: 0 auto;
}

#lobby-auth {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

#input-username {
    flex: 1;
    padding: 0.8rem;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-family: inherit;
}

.game-list-container {
    margin-top: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    padding: 1rem;
    min-height: 150px;
}

#game-list {
    margin-top: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.game-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    transition: background 0.2s;
}

.game-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.game-info {
    text-align: left;
}

.empty-msg {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-style: italic;
    margin-top: 1rem;
}

.connection-status {
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
    background: var(--danger);
    color: white;
    margin-left: 0.5rem;
}

.connection-status.online {
    background: var(--accent-secondary);
}
