:root {
    --panel-bg: #0f172a;
    --panel-fg: #e2e8f0;
    --accent: #22c55e;
    --danger: #ef4444;
    --muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.15);
    --glass: rgba(15, 23, 42, 0.85);
}

body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(120deg, #0b1022, #10192f);
    color: var(--panel-fg);
    place-items: center;
}

header {
    background-color: #3a3a3a;
    display: flex;
    width: 100%;
    min-height: 56px;
    padding: 10px 16px;
    align-items: center;
}

.logo-container {
  display: flex;
  align-items: center;
  position: relative;     /* Penting untuk positioning elemen cahaya */
  overflow: hidden;       /* Penting: Memotong cahaya yang lewat di luar kotak */
}
.logo-container h1 {
    margin: 0;
}
.logo-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;            /* Mulai dari luar sebelah kiri */
    width: 50%;             /* Lebar pita cahaya */
    height: 100%;
    
    /* Membuat efek gradasi putih transparan */
    background: linear-gradient(
        to right, 
        rgba(255, 255, 255, 0) 0%, 
        rgba(255, 255, 255, 0.4) 50%, 
        rgba(255, 255, 255, 0) 100%
    );
    
    /* Memiringkan cahaya */
    transform: skewX(30deg);
    
    /* Agar cahaya tidak menghalangi klik pada link */
    pointer-events: none; 
    z-index: 2;
}

/* 4. Trigger Animasi Saat Hover */
.logo-container:hover::before {
    animation: shine 0.75s; /* Durasi animasi */
}

/* 5. Keyframes Gerakan */
@keyframes shine {
    100% {
        left: 125%; /* Bergerak sampai keluar ke sebelah kanan */
    }
}

.logo {
  width: 30px;
  height: 30px;
}

.logo:hover {
  width: 30px;
  height: 30px;
}

    
main {
    width: 100%;
    padding: 1px;
    display: flex; /* Gunakan flexbox untuk menumpuk vertikal */
    flex-direction: column;
    gap: 1px;
}
.side-panel {    /* Pastikan dia tidak flex-row (defaultnya block atau flex-column) */
    display: flex;
    overflow-y: auto;
    flex-direction: column;
    width: 100%;
    gap: 8px;
    padding: 8px;
    justify-content: flex-start;
    text-align: start;
}
.center-panel {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
}
/* --- Kolom Tengah (Main Box) --- */
.button-group-label {
    flex-basis: 100%;
}
.button-wrapper {
    background-color: rgba(255, 255, 255, 0.03); /* Latar kotak sangat tipis */
    /* Grid layout untuk 12 tombol (3 kolom x 4 baris) */
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 72px;
    gap: 6px;
    width: 100%;
}

/* --- Button Styles (Flat Design) --- */
.btn {
    flex-basis: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    outline: none;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 400;
    color: #95979b;
    border-radius: 2px;
    transition: all 0.2s ease;
    letter-spacing: 0.5px;
    text-align: center;
}

/* Tombol Samping (Kiri/Kanan) */
.side-btn {
    padding: 15px 0;
    background-color: #1f293a; /* Warna sedikit lebih terang dari background */
    border: 1px solid #2d3748;
}

.side-btn:hover {
    background-color: #2d3748;
    color: #63b3ed;
}

/* Tombol Grid (Tengah) */
.grid-btn {
    background-color: #1f293a; /* Warna biru flat */
    color: rgb(152, 152, 153);
    display: flex;
    align-items: center;
    justify-content: center;
}

.grid-btn:hover {
    background-color: #2b6cb0; /* Biru lebih gelap saat hover */
    transform: translateY(-2px); /* Efek naik sedikit */
}

/* Agar tombol mengisi penuh sel grid */
.grid-btn {
    width: 100%;
    height: 100%;
}
.bottom-text {
    margin-top: auto; /* KUNCI UTAMA: Mendorong elemen ini ke dasar container */
    
    /* Style kosmetik agar terlihat bagus */
    text-align: center;
    color: #64748b; /* Warna abu-abu redup agar tidak mencolok */
    font-size: 0.85rem;
    font-weight: 500;
    position: absolute;
    bottom: 0px;
}


.app {
    width: 100%;
    padding: 1px;
    display: flex; /* Gunakan flexbox untuk menumpuk vertikal */
    flex-direction: column;
    gap: 1px;
}

.panel {
    /*height: 150vw;  /*kalau diaktifkan bakal terpotong di mobile, tombol2 ke bawah tidak terlihat */
    border-radius: 0;
    background: var(--glass);
    overflow: hidden;
}

/* Game Board Section */
.game-section {
    /* Pastikan dia tidak flex-row (defaultnya block atau flex-column) */
    display: flex;
    flex-direction: column; 
    
    /* Hapus height fix jika ada, biarkan isinya yang menentukan, 
       TAPI jika ini adalah bagian layout 60% tadi, pastikan overflow diatur */
    overflow-y: auto;
}

/* Pastikan container luar sudah benar (seperti sebelumnya) */
.board-container {
    width: 100%;
    aspect-ratio: 1 / 1; /* Ini yang menentukan kotak fisik */
    display: flex;
    gap: 3px;
}

#board {
    flex: 1; /* harus flex untuk yang bawah cg-wrap dan cg-board bisa jalan di hp*/
    height: 100%; /* Mengisi tinggi container */
    width: 100%;  /* Mengisi sisa lebar container */
    position: relative; /* Menjadi acuan koordinat */
}

/* --- PERBAIKAN INTI: memaksa internal Chessground memenuhi kotak --- */
/*sampai batas bertanda !!penting!! untuk memaksa cg memenuhi wadahnya */

/* Wrapper internal Chessground */
.cg-wrap {
    width: 100% !important;
    height: 100% !important;
    
    top: 0;
    left: 0;
    display: block !important;
}

/* Papan fisik Chessground */
.cg-board {
    width: 100% !important;
    height: 100% !important;
    
    top: 0;
    left: 0;
    background-size: cover; /* Agar gambar papan tidak gepeng */
}
/* !!penting!! batas */

.control-panel {
    padding: 5px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.player-clocks {
	    display: none; /* Sembunyikan kontainer jam desktop di mobile */
}

.eval-bar {
    display: none;
    width: 6px;
    height: calc(100vw - 44px);
    background: #334155;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.eval-bar.visible {
    display: block;
    width: 6px;
    height: calc(100vw - 44px);
    background: #334155;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.eval-fill {
    width: 100%;
    background: var(--panel-fg);
    transition: height 0.5s ease;
    position: absolute;
    bottom: 0;

    height: 50%;
}
.move-history-list {
    height: 140px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
}

.analysisChart1 {
    display: none;
}


/* Style untuk Glyph (tanda seru/tanya kecil di atas) */
.move-glyph {
    font-size: 0.75em;
    font-weight: bold;
    margin-left: 2px;
    vertical-align: super;
}

/* Warna Kategori Analisis */

/* Best Move (Hijau/Teal) */
.move-best {
    color: #26c281 !important; /* Gunakan !important jika tertimpa warna default */
}
.move-glyph.move-best { color: #26c281; }

/* Excellent (Hijau Muda) */
.move-excellent {
    color: #a7d129 !important;
}

/* Good (Default Text Color) */
.move-good {
    /* Biasanya warna teks biasa */
    color: #e2ece6 !important;
}

/* Inaccuracy (Kuning) */
.move-inaccuracy {
    color: #f1c40f !important;
}

/* Mistake (Oranye) */
.move-mistake {
    color: #e67e22 !important;
}

/* Blunder (Merah) */
.move-blunder {
    color: #e74c3c !important;
}

/* Highlight saat dihover agar tetap terbaca */
.move-row span:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    cursor: pointer;
}
 /* Tablet and desktop adjustments */
@media (min-width: 768px) {

  /* HEADER */
    body {
        margin: 0;
        font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
        background: radial-gradient(ellipse at center, #3a3a3a 0%, #1e1e1e 100%);
        color: var(--panel-fg);
        width:100vw;
        min-height: auto;
        display: grid;
        place-items: center;
        /* padding: 24px; */
    }
    header {
        display: flex;
        align-self: left;
        justify-content: space-between;
        align-items: center;
        background-color: #3a3a3a; /* Biru khas FChess */
        padding: 14px 32px;
        min-height: 68px;
        /* Bayangan putih di atas (inset 0 1px) + Bayangan gelap di bawah (inset 0 -1px) */
        box-shadow: 0 2px 8px rgba(0,0,0,0.4);
        position: relative;
        z-index: 100;
    }
    #header-content {
        flex-shrink: 1;
        justify-content: center;
        width: 71%;
    }
    main {
        width: 71%;
        flex-direction: row;
        padding: 70px;
        gap: 30px; /* Jarak antar kolom utama */
    }
    .brand-name {
        color: white;
        font-size: 1.4rem;
        font-weight: bold;
        letter-spacing: 1px;
        }
    .center-panel {
        flex: 1;
        display: flex;
        flex-wrap: unset;
        flex-direction: column;
        padding: 0 20px;
        max-width: 540px;
        margin: 0 auto;
    }
    .button-wrapper {
        grid-auto-rows: 70px;
        gap: 10px;
    }
    .grid-btn {
        font-size: 0.9rem;
    }
    .button-group-label {
        flex-basis:0;
    }
    /* ====== Navigation Menu ====== */
    .nav {
        vertical-align: middle;
        margin-left: auto;
    }
    .nav ul {
        display: flex;
        list-style: none;
        gap: 5px 10px;
    }

    .nav a {
        text-decoration: none;
        color: white;
        font-size: 1rem;
        font-weight: 500;
        transition: color 0.2s ease-in-out;
    }

    .nav a:hover {
        color: #dfe6f0;
    }

    /* --- Kolom Kiri & Kanan (Side Panels) --- */
    .side-panel {
        flex: 0 0 220px;
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 0;
        width: 220px;
    }
    .side-btn {
        padding: 12px 14px;
        min-height: 48px;
    }
    main {
        align-items: flex-start;
    }

    .app {
        width: 71%;
        background-color: transparent;
        display: grid;
        gap: 20px;
        grid-template-columns: minmax(642px, 1fr) 500px;
        align-items: start;
        padding: 24px;
    }

    .player-clocks {
        display: flex; /* Tampilkan kembali kontainer jam desktop */
        flex-direction: column;
        gap: 8px;
    }

    /* Kembalikan ukuran papan ke normal untuk desktop */
    .board-section {
        padding: 20px;
    }
    #board {
        width: min(85vw, 800px);
        height: min(85vw, 800px);
    }
    .board-container .eval-bar {
        width: 16px;
        height: min(85vw, 600px);
    }
}

.move-entry {
    display: grid;
    grid-template-columns: 30px 1fr 1fr; /* No. | Langkah Putih | Langkah Hitam */
    gap: 8px;
    align-items: center;
    padding: 2px 0;
}

.move-notation {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Style untuk bilah evaluasi kecil */
.move-eval-bar {
    width: 50px; /* Lebar tetap */
    height: 12px;
    background-color: #555; /* Warna untuk bagian Hitam */
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.2);
}

.move-eval-fill {
    height: 100%;
    background-color: #f0f0f0; /* Warna untuk bagian Putih */
    width: 50%; /* Default 50% untuk posisi seimbang */
    transition: width 0.3s ease;
}        

.panel {
    background: var(--glass);
    border-radius: 0px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
    overflow: hidden;
}

.board-section {
    padding: 0;
}

/* Game Board Section */
.game-section {
    padding: 2px;
}

.board-container {
    display: flex;
    gap: 3px;
    align-items: stretch;
}

.eval-bar {
    display: none;
    width: 6px;
    height: calc(100vw - 44px);
    background: #334155;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.eval-bar.visible {
    display: block;
    width: 6px;
    height: calc(100vw - 44px);
    background: #334155;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.eval-fill {
    width: 100%;
    background: var(--panel-fg);
    transition: height 0.5s ease;
    position: absolute;
    bottom: 0;
    height: 50%;
}

#board {
    width: calc(100vw - 44px); /* Papan mengisi lebar layar dikurangi padding dan eval bar */
    height: calc(100vw - 44px);
    max-width: 600px;
    max-height: 600px;
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.4);
}

/* Control Panel */
.control-panel {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.mobile-player-strip .clock {
    padding: 5px 8px; /* Atur padding jam di mobile */
}

.clock {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 8px;
    background: rgba(2,6,23,0.6);
    border: 2px solid transparent;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.clock.active {
    border-color: var(--accent);
}

.clock.timeout {
    border-color: var(--danger);
}

.player-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rating {
    font-size: 12px;
    color: var(--muted);
}

.status-panel {
    padding: 4px;
    background: rgba(2,6,23,0.6);
    border-radius: 12px;
    border: 1px solid var(--border);
    text-align: center;
    font-weight: 500;
}

/* Button Groups */
.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.btn {
    cursor: pointer;
    border: 1px solid var(--border);
    background: rgba(2,6,23,0.7);
    color: var(--panel-fg);
    padding: 10px 16px;
    border-radius: 10px;
    font-weight: 400;
    font-size: 12px;
    transition: all 0.2s ease;
}

/* PENAMBAHAN: Style untuk tombol disabled */
.btn:disabled {
    cursor: not-allowed;
    background: #334155;
    border-color: var(--border);
    color: var(--muted);
    transform: none;
}

.btn:hover:not(:disabled) {
    border-color: var(--panel-fg);
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #052e16;
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.btn-secondary {
    background: #3b82f6;
    border-color: #3b82f6;
}

/* Form Elements */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 14px;
    color: var(--muted);
    font-weight: 500;
}

.select, .input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(2,6,23,0.7);
    color: var(--panel-fg);
    border: 1px solid var(--border);
    font-size: 14px;
}

/* Log Panel */
.log-panel {
    height: 200px;
    overflow-y: auto;
    background: rgba(2,6,23,0.4);
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 12px;
    font-size: 12px;
    line-height: 1.4;
    font-family: 'Courier New', monospace;
}

/* PENAMBAHAN: Panel Riwayat Gerakan */
.move-history-panel {
    background: rgba(2,6,23,0.4);
    border-radius: 10px;
    border: 1px solid var(--border);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.move-history-list {
    height: 120px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
}
.move-history-list > div {
    display: grid;
    grid-template-columns: 20px 1fr 1fr;
    gap: 8px;
}
.move-history-list > div > span:first-child { color: var(--muted); }
.move-history-nav { display: flex; justify-content: center; gap: 8px; }
.move-history-nav button { font-size: 18px; padding: 4px 10px; }

.bar-column.selected .analysis-bar {
    /* Border putih agar kontras dengan background biru/merah */
    outline: 2px solid #ffffff; 
    box-shadow: 0 0 0 2px rgba(0,0,0,0.5); /* Shadow luar agar outline putih terlihat di background terang */
    filter: brightness(1.1); /* Sedikit lebih terang */
    z-index: 20; /* Pastikan di atas bar lain */
}

/* Opsional: Segitiga kecil penunjuk di bawah bar (seperti jarum) */
.bar-column.selected::after {
    content: '';
    position: absolute;
    bottom: -4px; /* Sesuaikan posisi */
    left: 50%;
    transform: translateX(-50%);
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 4px solid #ffffff; /* Warna penunjuk */
}


/* Modal Styles */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(2,6,23,0.8);
    backdrop-filter: blur(4px);
    display: none;
    place-items: center;
    z-index: 1000;
}

.modal.show {
    display: grid;
}

.modal-content {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    min-width: 320px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.modal-header {
    margin-bottom: 20px;
}

.modal-title {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 600;
}

.modal-subtitle {
    margin: 0;
    font-size: 14px;
    color: var(--muted);
}

/* Promotion Modal */
.promotion-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-top: 16px;
}

.piece-btn {
    padding: 16px;
    font-size: 24px;
    border-radius: 10px;
    color: wheat;
    background: rgba(2,6,23,0.7);
    border: 2px solid var(--border);
    cursor: pointer;
    transition: all 0.2s ease;
}

.piece-btn:hover {
    border-color: var(--accent);
    transform: scale(1.05);
}

/* Connection Status */
.connection-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    padding: 8px 12px;
    background: rgba(2,6,23,0.4);
    border-radius: 8px;
}

.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
    vertical-align: middle;
}

.status-dot.connected {
    background: #22c55e;
}

/* Loading Spinner */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--muted);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Hidden Elements */
.hidden {
    display: none !important;
}

.mobile-player-strip {
    display: none; /* Sembunyikan secara default di desktop */
    width: 100%;
}


@media (max-width: 380px) {
    #board {
        width: calc(100vw - 60px);
        height: calc(100vw - 60px);
    }

    .eval-bar {
        height: calc(100vw - 60px);
        width: 10px;
    }

    .btn {
        font-size: 12px;
        padding: 10px 12px;
    }
}

.brand-name {
  color: white;
  font-size: 1.3rem;
  font-weight: bold;
  letter-spacing: 1px;
}

.analysis-summary-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}
.player-summary p.accuracy {
    font-size: 18px;
    font-weight: 600;
}
.player-summary ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
    #analysisChart { 
        display: flex; 
        gap: 0px; /* Sedikit lebih rapat */
        align-items: center; /* PENTING: Agar bar berada di tengah secara vertikal */
        padding: 0 8px; 
        overflow-x: auto; 
        margin-top: 8px; 
        height: 70px; 
        background-color: #12283f; /* Opsional: warna background chart */
        border-bottom: 1px solid #ddd;
        position: relative;
    }

    /* Garis tengah (Zero line) */
    #analysisChart::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 0;
        right: 0;
        height: 1px;
        background-color: rgba(0,0,0,0.1);
        z-index: 0;
        pointer-events: none;
    }

    /* Container untuk satu bar (kolom vertikal penuh) */
    .bar-column {
        height: 85%;
        
        /* INI KUNCINYA: */
        flex: 1;           /* Tumbuh mengisi ruang kosong */
        min-width: 1px;    /* Lebar minimal 1 pixel */
        
        display: flex;
        flex-direction: column;
        justify-content: center;
        position: relative;
        cursor: pointer;
        
        /* Opsional: Memberi jarak visual 1px antar bar. 
        Menggunakan border transparan lebih aman daripada margin 
        supaya layout tidak pecah saat sangat sempit.
        border-right: 1px solid transparent; */
    }

    .analysis-bar { 
        width: 100%; 
        transition: height 0.2s, background 0.2s;
        position: absolute; /* Bar diposisikan absolut di dalam kolom */
        z-index: 1;
    }

    /* Hover effect */
    /* Agar saat dihover tetap terlihat jelas meski barnya tipis */
    .bar-column:hover {
        background-color: rgba(0,0,0,0.05); /* Highlight kolomnya */
        z-index: 10; /* Supaya tooltip/hover muncul di atas yang lain */
    }

    /* Bar Berwarna (Sama seperti sebelumnya) */
    .analysis-bar { 
        width: 100%; 
        transition: height 0.2s;
        position: absolute;
        z-index: 1;
    }

    .analysis-bar.positive { 
        background: #6babff; /* Warna putih unggul (biru/putih) */
        bottom: 50%; /* Tumbuh dari tengah ke atas */
    }

    .analysis-bar.negative { 
        background: #ff6b6b; /* Warna hitam unggul (merah/hitam) */
        top: 50%; /* Tumbuh dari tengah ke bawah */
    }
    /* Analysis chart styles */
    .move-highlight { background: rgba(255, 235, 59, 0.18); border-radius: 1px; }
    /* Improve move history visual so highlight is visible */
    .move-row { display: flex; gap: 10px; align-items: center; padding: 1px 1px; }
    .move-row span { display: inline-block; padding: 4px 6px; border-radius: 3px; }
    .move-row span.move-highlight { background: rgba(255, 235, 59, 0.25); }
    .move-row span.move-white { color: inherit; }
    .move-row span.move-black { color: inherit; }
