  :root {
    --bg-dark: #1e2a38;
    --bg-mid: #263244;
    --bg-light: #2f3e52;
    --orange: #e8622a;
    --orange-hover: #f0733b;
    --text: #ffffff;
    --text-muted: #9aadbe;
    --border: #374f66;
    --board-light: #f0d9b5;
    --board-dark: #b58863;
  }

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

  body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }

  /* NAVBAR */
  nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: var(--bg-mid);
    border-bottom: 1px solid var(--border);
  }
  .logo { display: flex; align-items: center; gap: 10px; font-size: 1.3rem; font-weight: 700; letter-spacing: -0.5px; }
  .logo-crown { font-size: 1.8rem; color: var(--orange); }
  .nav-btns { display: flex; gap: 10px; }
  .btn-outline {
    padding: 8px 20px; border: 2px solid var(--orange); color: var(--orange);
    background: transparent; border-radius: 6px; cursor: pointer; font-weight: 600;
    transition: all .2s;
  }
  .btn-outline:hover { background: var(--orange); color: white; }

  /* HERO */
  #hero {
    background: var(--bg-mid);
    text-align: center;
    padding: 60px 24px 50px;
    position: relative;
    overflow: hidden;
  }
  .hero-pieces {
    position: absolute; bottom: 0; left: 0; right: 0;
    font-size: 4rem; opacity: .06; letter-spacing: 10px;
    pointer-events: none; line-height: 1;
  }
  #hero h1 {
    font-size: clamp(2rem, 5vw, 3.2rem);
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: -1px;
    line-height: 1.1;
    margin-bottom: 20px;
  }
  .online-count {
    display: inline-flex; align-items: center; gap: 8px;
    color: var(--text-muted); font-size: .95rem; margin-bottom: 32px;
  }
  .dot { width: 8px; height: 8px; background: #4caf50; border-radius: 50%; animation: pulse 2s infinite; }
  @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

  .hero-actions { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 340px; margin: 0 auto; }
  .btn-primary {
    width: 100%; padding: 16px; background: var(--orange); color: white;
    border: none; border-radius: 8px; font-size: 1.05rem; font-weight: 700;
    cursor: pointer; transition: background .2s; letter-spacing: .3px;
  }
  .btn-primary:hover { background: var(--orange-hover); }
  .divider { width: 100%; display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: .85rem; }
  .divider::before,.divider::after { content:''; flex:1; height:1px; background: var(--border); }
  .guest-row { display: flex; gap: 8px; width: 100%; }
  .guest-input {
    flex: 1; padding: 12px 14px; background: var(--bg-light); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text); font-size: .95rem;
    outline: none; transition: border-color .2s;
  }
  .guest-input:focus { border-color: var(--orange); }
  .guest-input::placeholder { color: var(--text-muted); }
  .btn-secondary {
    padding: 12px 18px; background: var(--bg-light); border: 1px solid var(--border);
    color: var(--text); border-radius: 8px; font-weight: 600; cursor: pointer; white-space: nowrap;
    transition: background .2s;
  }
  .btn-secondary:hover { background: var(--border); }

  .difficulty-row { width: 100%; display: flex; align-items: center; gap: 10px; }
  .difficulty-label { font-size: .8rem; color: var(--text-muted); white-space: nowrap; }
  .difficulty-select {
    flex: 1; padding: 12px 14px; background: var(--bg-light); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text); font-size: .95rem; outline: none;
    cursor: pointer; transition: border-color .2s; color-scheme: dark;
  }
  .difficulty-select:focus { border-color: var(--orange); }

  /* GAME AREA */
  #game-area {
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 20px 16px;
    gap: 16px;
    max-width: 520px;
    margin: 0 auto;
    width: 100%;
  }
  #game-area.visible { display: flex; }

  .players-bar {
    width: 100%; background: var(--bg-mid);
    border-radius: 10px; overflow: hidden;
    border: 1px solid var(--border);
  }
  .player-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px;
  }
  .player-row:first-child { border-bottom: 1px solid var(--border); }
  .player-row.active { background: var(--bg-light); }
  .player-info { display: flex; align-items: center; gap: 10px; }
  .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--border); display:flex;align-items:center;justify-content:center; font-size:1.1rem; }
  .player-name { font-weight: 600; font-size: .95rem; }
  .player-rating { color: var(--text-muted); font-size: .8rem; display:flex;align-items:center;gap:4px; }
  .timer {
    font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums;
    color: var(--text);
  }
  .timer.active { color: var(--orange); }
  .timer.low { color: #e53935; animation: pulse .7s infinite; }

  #board-wrap { width: 100%; max-width: 480px; }
  #board { width: 100% !important; }

  /* Chessboard.js overrides */
  .board-b72b1 { border-radius: 6px; overflow: hidden; box-shadow: 0 8px 32px rgba(0,0,0,.5); }

  .game-controls {
    display: flex; gap: 10px; width: 100%; max-width: 480px;
  }
  .ctrl-btn {
    flex: 1; padding: 12px; background: var(--bg-mid); border: 1px solid var(--border);
    color: var(--text); border-radius: 8px; font-size: .9rem; font-weight: 600;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
    transition: background .2s;
  }
  .ctrl-btn:hover { background: var(--bg-light); }
  .ctrl-btn.resign { color: #e57373; }
  .ctrl-btn.resign:hover { border-color: #e57373; }

  .abort-link {
    color: var(--text-muted); font-size: .85rem; cursor: pointer; text-decoration: underline;
    background: none; border: none; transition: color .2s;
  }
  .abort-link:hover { color: var(--text); }

  /* STATUS */
  #status-bar {
    width: 100%; max-width: 480px; padding: 10px 16px;
    background: var(--bg-mid); border-radius: 8px; border: 1px solid var(--border);
    text-align: center; font-size: .9rem; color: var(--text-muted);
    display: none;
  }
  #status-bar.visible { display: block; }
  #status-bar.win { color: #81c784; border-color: #81c784; }
  #status-bar.draw { color: #ffb74d; border-color: #ffb74d; }

  /* MOVE HISTORY */
  #moves-panel {
    width: 100%; max-width: 480px; background: var(--bg-mid);
    border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px;
    display: none;
  }
  #moves-panel.visible { display: block; }
  .moves-title { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
  #moves-list {
    display: flex; flex-wrap: wrap; gap: 4px; font-size: .85rem; max-height: 80px; overflow-y: auto;
  }
  .move-pair { display: flex; gap: 4px; }
  .move-num { color: var(--text-muted); }
  .move-san {
    background: var(--bg-light); padding: 2px 7px; border-radius: 4px; cursor: pointer;
    transition: background .15s;
  }
  .move-san:hover { background: var(--border); }

  /* MODAL */
  .modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.7); z-index: 100;
    align-items: center; justify-content: center;
  }
  .modal-overlay.open { display: flex; }
  .modal {
    background: var(--bg-mid); border: 1px solid var(--border);
    border-radius: 12px; padding: 28px 32px; text-align: center; max-width: 320px; width: 90%;
  }
  .modal h2 { font-size: 1.4rem; margin-bottom: 8px; }
  .modal p { color: var(--text-muted); margin-bottom: 20px; font-size: .95rem; }
  .modal-btns { display: flex; gap: 10px; justify-content: center; }

  footer {
    margin-top: auto; padding: 20px; text-align: center;
    color: var(--text-muted); font-size: .8rem; border-top: 1px solid var(--border);
  }
