* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top, #1d2b4f 0%, #07090f 45%, #020202 100%);
    color: white;
    font-family: Arial, sans-serif;
}

.game-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px;
}

h1 {
    text-align: center;
    margin-bottom: 20px;
    font-size: 38px;
    letter-spacing: 1px;
}

.game-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 30px;
    align-items: start;
}

.board-card,
.side-panel {
    background: rgba(15, 18, 26, 0.92);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 18px;
    box-shadow: 0 20px 45px rgba(0,0,0,0.55);
    padding: 22px;
}

#board {
    width: 640px;
    height: 640px;
    margin: auto;
    display: grid;
    grid-template-columns: repeat(8, 80px);
    grid-template-rows: repeat(8, 80px);
    border-radius: 12px;
    overflow: visible;
    border: 6px solid #151515;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.08);
}

.square {
    width: 80px;
    height: 80px;
    font-size: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: 0.15s ease;
}

.square:hover {
    filter: brightness(1.15);
}

.light {
    background: #eeeed2;
    color: #222;
}

.dark {
    background: #769656;
    color: #111;
}

.selected {
    outline: 5px solid #f7d64a;
    outline-offset: -5px;
    background: #f6f669 !important;
}

#status {
    font-size: 20px;
    font-weight: bold;
    padding: 14px;
    margin-bottom: 18px;
    border-radius: 12px;
    background: linear-gradient(135deg, #1455ff, #ef233c);
    box-shadow: 0 10px 24px rgba(0,0,0,0.35);
}

.panel-title {
    font-size: 24px;
    margin-bottom: 15px;
}

.info-box {
    background: rgba(255,255,255,0.07);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 14px;
    text-align: left;
}

.button-row {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}

button {
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    color: white;
    background: #2f80ed;
    transition: 0.15s ease;
}

button:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

button.danger {
    background: #c1121f;
}

@media (max-width: 1000px) {
    .game-layout {
        grid-template-columns: 1fr;
    }

    #board {
        width: 90vw;
        height: 90vw;
        grid-template-columns: repeat(8, 1fr);
        grid-template-rows: repeat(8, 1fr);
    }

    .square {
        width: auto;
        height: auto;
        font-size: 7vw;
    }
}

#moveHistory {
    max-height: 180px;
    overflow-y: auto;
    padding-left: 22px;
    margin: 10px 0 0;
}

#moveHistory li {
    margin-bottom: 6px;
    font-size: 14px;
}

#capturedWhite,
#capturedBlack {
    min-height: 32px;
    font-size: 28px;
    margin-top: 8px;
    letter-spacing: 4px;
}

.in-check {
    box-shadow: inset 0 0 0 5px red;
}

.legal-move {
    position: relative;
}

.legal-move::after {
    content: "";
    width: 22px;
    height: 22px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 50%;
    position: absolute;
}

select {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: none;
    background: #202636;
    color: white;
    font-size: 15px;
    margin-top: 8px;
}

input {
    width: 100%;
    padding: 13px;
    margin-bottom: 12px;
    border-radius: 10px;
    border: none;
    background: #202636;
    color: white;
    font-size: 15px;
}

a {
    color: #58a6ff;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.timer-box {
    background: rgba(255,255,255,0.08);
    border-radius: 14px;
    padding: 14px;
    margin-bottom: 14px;
    text-align: left;
    border: 1px solid rgba(255,255,255,0.12);
}

.timer-box div:first-child {
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 6px;
}

#whiteTimer,
#blackTimer {
    font-size: 34px;
    font-weight: bold;
    letter-spacing: 1px;
}

.timer-active {
    box-shadow: 0 0 18px rgba(88, 166, 255, 0.55);
}

.timer-low {
    color: #ff3b3b;
    animation: timerPulse 0.7s infinite alternate;
}

@keyframes timerPulse {
    from {
        opacity: 1;
    }
    to {
        opacity: 0.55;
    }
}

.square {
    position: relative;
}

.piece {
    z-index: 2;
}

.coord {
    position: absolute;
    font-size: 13px;
    font-weight: bold;
    opacity: 0.85;
    pointer-events: none;
    z-index: 3;
}

.rank-coord {
    top: 4px;
    left: 6px;
}

.file-coord {
    right: 6px;
    bottom: 4px;
}

.light .coord {
    color: #769656;
}

.dark .coord {
    color: #eeeed2;
}

.player-bar {
    width: 640px;
    margin: 12px auto;
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(255,255,255,0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid rgba(255,255,255,0.12);
}

.player-bar div:first-child {
    font-weight: bold;
    font-size: 16px;
}

.player-bar div:last-child {
    font-weight: bold;
    font-size: 28px;
}

.player-bar.timer-active {
    box-shadow: 0 0 18px rgba(88, 166, 255, 0.7);
}

.player-bar .timer-low {
    color: #ff3b3b;
    animation: timerPulse 0.7s infinite alternate;
}

@media (max-width: 1000px) {
    .player-bar {
        width: 90vw;
    }
}

input[type="file"] {
    background: #202636;
    padding: 12px;
    color: white;
}


/* POPUP OVERLAY */
.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.popup-overlay.show {
    display: flex;
}

.popup-box {
    width: 420px;
    max-width: 90vw;
    background: #111827;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 18px;
    padding: 28px;
    text-align: center;
    box-shadow: 0 30px 70px rgba(0,0,0,0.7);
}

.popup-box h2 {
    margin-top: 0;
    font-size: 30px;
}

.popup-box p {
    font-size: 18px;
    line-height: 1.4;
}

.popup-box {
    animation: popupScale 0.25s ease-out;
}

@keyframes popupScale {
    from {
        transform: scale(0.85);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}


/* Sidebar */
.sidebar-hover-zone {
    position: fixed;
    left: 0;
    top: 0;
    width: 18px;
    height: 100vh;
    z-index: 9998;
}

.main-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 270px;
    height: 100vh;
    background: rgba(13, 17, 25, 0.96);
    border-right: 1px solid rgba(255,255,255,0.12);
    padding: 18px;
    z-index: 9999;
    transform: translateX(-235px);
    transition: transform 0.25s ease;
    backdrop-filter: blur(14px);
}

.main-sidebar:hover,
.sidebar-hover-zone:hover + .main-sidebar {
    transform: translateX(0);
}

.sidebar-logo {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 22px;
}

.logo-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #1455ff, #ef233c);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 26px;
}

.sidebar-logo span,
.sidebar-profile span {
    display: block;
    font-size: 12px;
    opacity: 0.75;
}

.sidebar-profile {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border-radius: 14px;
    background: rgba(255,255,255,0.07);
    margin-bottom: 20px;
}

.sidebar-profile img {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    object-fit: cover;
    background: #222;
}

.sidebar-nav {
    display: grid;
    gap: 10px;
}

.sidebar-nav a {
    padding: 13px 14px;
    border-radius: 12px;
    color: white;
    text-decoration: none;
    background: rgba(255,255,255,0.06);
    transition: 0.18s ease;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: linear-gradient(135deg, #1455ff, #ef233c);
    transform: translateX(4px);
}

.danger-link {
    background: rgba(193,18,31,0.35) !important;
}

.page-content {
    padding-left: 48px;
}

@media (max-width: 800px) {
    .main-sidebar {
        width: 240px;
        transform: translateX(-205px);
    }

    .page-content {
        padding-left: 34px;
    }
}

/* Home Page */
.home-hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.hero-card {
    max-width: 950px;
    width: 100%;
    padding: 42px;
    border-radius: 24px;
    background: rgba(15, 18, 26, 0.92);
    border: 1px solid rgba(255,255,255,0.12);
    box-shadow: 0 30px 80px rgba(0,0,0,0.6);
    animation: fadeUp 0.45s ease;
}

.hero-card h1 {
    font-size: clamp(38px, 6vw, 72px);
    margin: 0 0 16px;
}

.hero-subtitle {
    font-size: 20px;
    opacity: 0.85;
    max-width: 750px;
    margin-bottom: 28px;
}

.hero-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.home-actions {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 26px;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(18px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 800px) {
    .home-hero {
        padding: 24px;
        align-items: flex-start;
    }

    .hero-card {
        padding: 26px;
    }

    .hero-grid {
        grid-template-columns: 1fr;
    }

    .home-actions button {
        width: 100%;
    }
}