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

  :root {
    --bg: #2b2b2b;
    --header-bg: #3a3a3a;
    --accent: #cc2200;
    --text: #e8e8e8;
    --muted: #aaa;
    --panel-bg: #444;
    --dark-panel: #333;
    --player-active: #1a1a1a;
    --border: #555;
    --btn-bg: #5a5a5a;
    --btn-hover: #6a6a6a;
    --move-bg: #3d3d3d;
  }



  .logo {
    display: flex;
    align-items: center;
    align-self: center;
    gap: 0;
    text-decoration: none;
    flex-shrink: 0;
  }

  .logo-text {
    font-family: 'Rajdhani', sans-serif;
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -1px;
  }

  .logo-badge {
    width: 30px;
    height: 30px;
    background: var(--accent);
    color: white;
    font-family: 'Rajdhani', sans-serif;
    font-size: 22px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 2px;
    line-height: 1.2;
  }

  nav {
    flex-shrink: 1;
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
  }

  nav a {
    flex-shrink: 1;
    color: var(--text);
    text-decoration: none;
    font-family: 'Noto Sans', sans-serif;
    font-size: 15px;
    padding: 6px 14px;
    border-radius: 4px;
    transition: background 0.15s;
  }

  nav a:hover, nav a.active {
    background: rgba(255,255,255,0.1);
  }

  /* Profile dropdown */
  .profile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 4px;
    transition: background 0.15s;
    position: relative;
  }

  .profile-btn:hover { background: rgba(255,255,255,0.1); }

  .profile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background: #888;
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    overflow: hidden;
  }

  .profile-name {
    font-size: 15px;
  }

  .caret { font-size: 10px; color: var(--muted); }

  .dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--header-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    min-width: 140px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    z-index: 200;
  }

  .profile-btn:hover .dropdown,
  .profile-btn:focus-within .dropdown { display: block; }

  .dropdown a {
    display: block;
    padding: 10px 16px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
  }

  .dropdown a:hover { background: rgba(255,255,255,0.08); }

  /* LOGIN state */
  .nav-login {
    color: var(--text);
    text-decoration: none;
    font-size: 15px;
    padding: 6px 14px;
    border-radius: 4px;
    transition: background 0.15s;
  }

  .nav-login:hover { background: rgba(255,255,255,0.1); }

  /* MAIN LAYOUT */
  main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 0;
  }

  .game-wrapper {
    display: flex;
    gap: 16px;
    align-items: flex-start;
  }

  /* BOARD */
  .board-container {
    width: 560px;
    height: 560px;
    background: #b58863;
    border: 2px solid #555;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 14px;
    font-style: italic;
  }

  /* SIDE PANEL */
  .side-panel {
    width: 290px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .game-info {
    background: var(--panel-bg);
    padding: 16px 18px;
    border-radius: 4px;
    font-size: 14px;
    color: var(--muted);
    line-height: 1.8;
  }

  .game-info strong {
    color: var(--text);
    font-weight: 500;
  }

  /* Player bars */
  .player-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: 4px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.3px;
  }

  .player-bar.active {
    background: var(--player-active);
    color: white;
  }

  .player-bar.inactive {
    background: var(--dark-panel);
    color: var(--muted);
  }

  .player-name { display: flex; align-items: center; gap: 8px; }

  .online-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #44cc44;
    flex-shrink: 0;
  }

  .player-time { font-variant-numeric: tabular-nums; }

  /* Move list */
  .move-list {
    background: var(--panel-bg);
    border-radius: 4px;
    min-height: 120px;
    padding: 12px 16px;
    font-size: 14px;
    color: var(--text);
    line-height: 2;
    flex: 1;
  }

  .move-entry { display: inline; color: var(--muted); }
  .move-entry span { color: var(--text); margin-left: 4px; }

  /* Nav arrows */
  .nav-arrows {
    text-align: center;
    padding: 8px;
    background: var(--panel-bg);
    border-radius: 4px;
    font-size: 15px;
    color: var(--muted);
    letter-spacing: 4px;
    cursor: default;
  }

  /* Action buttons */
  .action-buttons {
    display: flex;
    gap: 8px;
  }

  .btn {
    flex: 1;
    padding: 10px 8px;
    border: none;
    border-radius: 4px;
    background: var(--btn-bg);
    color: var(--text);
    font-family: 'Noto Sans', sans-serif;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
  }

  .btn:hover { background: var(--btn-hover); }

  /* GAME OVER MODAL (overlay on board) */
  .board-wrapper {
    position: relative;
    width: 560px;
    height: 560px;
    flex-shrink: 0;
  }

  .modal-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
  }

  .modal {
    background: rgba(180,180,180,0.92);
    border-radius: 6px;
    padding: 32px 40px;
    text-align: center;
    min-width: 240px;
    color: #111;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  }

  .modal h2 {
    font-family: 'Rajdhani', sans-serif;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
  }

  .modal .sub { font-size: 14px; color: #444; margin-bottom: 24px; }

  .modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
  }

  .modal-btn {
    width: 160px;
    padding: 9px 0;
    border: none;
    border-radius: 4px;
    font-size: 15px;
    cursor: pointer;
    background: var(--btn-bg);
    color: var(--text);
    transition: background 0.15s;
  }

  .modal-btn:hover { background: var(--btn-hover); }

  .modal-btn-row {
    display: flex;
    gap: 8px;
  }

  .modal-btn-row .modal-btn { width: auto; flex: 1; padding: 9px 16px; }

  /* --- DEMO TABS --- */
  .demo-controls {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    background: rgba(0,0,0,0.7);
    padding: 8px 12px;
    border-radius: 30px;
    z-index: 999;
  }

  .demo-btn {
    padding: 6px 14px;
    border: 1px solid #555;
    border-radius: 20px;
    background: #333;
    color: #ccc;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
  }

  .demo-btn.active, .demo-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
  }

  /* Dropdown Menu (Tersembunyi by default) */
.user-dropdown-menu {
    display: none; /* Hidden */
    position: absolute;
    top: 100%; /* Tepat di bawah nama user */
    right: 0;
    background-color: #0f7aac;
    min-width: 150px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.5);
    border-radius: 4px;
    z-index: 1000;
    border: 1px solid #0b577a;
    overflow: hidden;
}

/* Tampilkan saat class 'active' ditambahkan */
.dropdown.active {
    display: block;
}

/* Item di dalam Dropdown */
.dropdown-item {
    color: #ccc;
    padding: 8px 10px;
    text-decoration: none;
    display: block;
    font-size: 0.6 rem;
    cursor: pointer;
    transition: background 0.2s;
}

.dropdown-item:hover {
    background-color: #0b1022;
    color: white;
}

.dropdown-divider {
    height: 1px;
    background-color: #0b577a;
    margin: 0;
}

/* === Header: perbaikan tata letak (berlaku di semua halaman) === */
/* main.css punya .logo { width:30px; height:30px } -> teks "catur ID" meluber menimpa menu */
#header-content .logo { width: auto; height: auto; }
/* Dropdown profil diposisikan relatif ke tombol profil, bukan ke elemen jauh di bawah */
#header-content .nav-right {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
#header-content .dropdown { top: calc(100% + 6px); right: 0; left: auto; }

/* Tombol hamburger: hanya tampil di HP */
#header-content .nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border, #555);
    border-radius: 6px;
    color: #e8e8e8;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}
/* HP: baris 1 = logo + profil, menu navigasi dibuka lewat tombol ☰ */
@media (max-width: 767px) {
    #header-content {
        flex-wrap: wrap;
        align-items: center;
        column-gap: 8px;
        row-gap: 4px;
        padding: 8px 12px;
        min-height: 0;
    }
    #header-content .logo-text { font-size: 24px; }
    #header-content .logo-badge { width: auto; height: auto; font-size: 18px; padding: 1px 5px; }
    #header-content .nav-right { margin-left: auto; }
    /* Menu navigasi disembunyikan di balik tombol hamburger (☰) */
    #header-content .nav-toggle { display: inline-flex; order: 2; }  /* paling kanan, setelah profil */
    #header-content .main-nav {
        order: 3;
        flex: 1 0 100%;
        margin-left: 0;
        display: none;
        flex-direction: column;
        gap: 2px;
        padding: 4px 0 6px;
        border-top: 1px solid var(--border, #444);
    }
    #header-content.nav-open .main-nav { display: flex; }
    #header-content .main-nav a { padding: 10px 8px; font-size: 15px; white-space: nowrap; border-radius: 4px; }
    #header-content .main-nav a:active { background: rgba(255,255,255,0.08); }
    #header-content .profile-btn { padding: 4px 6px; }
    #header-content #profile-name {
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}
/* HP & tablet tegak (tata letak atas-bawah, <=900px): papan mengikuti lebar layar.
   Aturan .board-container 560px di atas hanya cocok untuk desktop; di HP membuat
   papan lebih lebar dari layar sehingga harus zoom out dulu. */
@media (max-width: 900px) {
    /* Halaman Play/vsAI memberi .app "width:auto; margin:auto" -> di HP lebarnya ikut panjang
       teks (mis. nama pembukaan) dan papan jadi kembang kempis. Kunci selebar layar. */
    body .app { width: 100% !important; max-width: 100%; box-sizing: border-box; }
    .app > * { min-width: 0; }
    .board-container {
        width: 100%;
        max-width: 560px;
        height: auto;
        margin: 0 auto;
    }
    .board-container #board {
        flex: 1 1 auto;
        min-width: 0;
        width: auto;
        height: auto;
        aspect-ratio: 1 / 1;
        align-self: flex-start;
        max-width: none;
        max-height: none;
    }
    .board-container .eval-bar,
    .board-container .eval-bar.visible { height: auto; }
}

/* Tablet landscape & layar pendek (tata letak kiri-kanan, >900px):
   ukuran papan mengikuti tinggi layar juga, supaya papan dan tombol navigasi
   langkah tidak terpotong. 130px = header + margin + padding di sekitar papan. */
@media (min-width: 901px) {
    :root { --board-size: max(260px, min(560px, calc(100vh - 130px))); }
    @supports (height: 100dvh) {
        :root { --board-size: max(260px, min(560px, calc(100dvh - 130px))); }
    }
    body .app .board-container {
        width: var(--board-size);
        height: var(--board-size);
    }
    body .app .board-container #board {
        flex: 1 1 auto;
        min-width: 0;
        width: auto;
        height: 100%;
        max-width: none;
        max-height: none;
    }
    body .app .board-container .eval-bar.visible { height: 100%; }
    /* Panel kanan setinggi papan; isinya di-scroll di dalam panel */
    body .app .control-panel {
        max-height: calc(var(--board-size) + 8px);
        overflow-y: auto;
        align-self: start;
    }
}
/* Layar pendek (umumnya tablet landscape): rapatkan jarak supaya papan bisa lebih besar */
@media (min-width: 901px) and (max-height: 820px) {
    :root { --board-size: max(260px, min(560px, calc(100vh - 100px))); }
    @supports (height: 100dvh) {
        :root { --board-size: max(260px, min(560px, calc(100dvh - 100px))); }
    }
    body .app {
        margin-top: 8px !important;
        margin-bottom: 8px !important;
        padding: 8px !important;
        gap: 12px !important;
    }
    body .app .control-panel { gap: 6px; padding: 8px; }
}

/* Nama pembukaan: satu baris, kepanjangan dipotong "…" (nama lengkap di tooltip) */
.opening-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
