  :root{
    --bg: #14161a;
    --panel: #1c1f26;
    --panel-2: #232732;
    --light-sq: #f0dfc2;
    --dark-sq: #3d5a73;
    --accent: #c9a24b;
    --accent-2: #4b8ac9;
    --danger: #d9534f;
    --text: #eef0f3;
    --text-dim: #9aa2b1;
    --sel: rgba(201,162,75,0.55);
    --move-dot: rgba(75,138,201,0.65);
    --check-glow: rgba(217,83,79,0.75);
  }
  *{box-sizing:border-box;}
  html,body{
    margin:0; padding:0; height:100%;
    background: radial-gradient(circle at 30% 0%, #1e222b 0%, var(--bg) 60%);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  }
  .app{
    display:flex;
    flex-wrap:wrap;
    gap:20px;
    justify-content:center;
    align-items:flex-start;
    padding:20px;
    max-width:1100px;
    margin:0 auto;
  }
  h1{
    font-size:1.4rem;
    letter-spacing:3px;
    font-weight:600;
    margin:0 0 4px 0;
    color:var(--accent);
  }
  .subtitle{
    color:var(--text-dim);
    font-size:0.8rem;
    margin-bottom:14px;
  }
  .header{
    width:100%;
    text-align:center;
    margin-bottom:4px;
  }
  .board-wrap{
    background: var(--panel);
    padding:14px;
    border-radius:16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  }
  #board{
    display:grid;
    grid-template-columns: 26px repeat(8, minmax(38px, 62px));
    grid-template-rows: repeat(9, minmax(38px, 62px)) 22px;
    border: 3px solid #0e0f12;
    border-radius:6px;
    overflow:hidden;
    touch-action:none;
    user-select:none;
  }
  .coord-label{
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:0.7rem;
    font-weight:700;
    color: var(--text-dim);
    background: var(--panel);
    user-select:none;
  }
  .sq{
    position:relative;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size: clamp(22px, 4.2vw, 42px);
    cursor:pointer;
    transition: background-color .12s ease;
  }
  .sq.light{ background: var(--light-sq); }
  .sq.dark{ background: var(--dark-sq); }
  .sq.center-row{ box-shadow: inset 0 0 0 2px rgba(201,162,75,0.35); }
  .sq.selected{ background: var(--sel) !important; }
  .sq.last-move{ box-shadow: inset 0 0 0 3px rgba(201,162,75,0.55); }
  .sq.in-check{ box-shadow: inset 0 0 18px 6px var(--check-glow); }
  .sq .dot{
    position:absolute;
    width:26%;
    height:26%;
    border-radius:50%;
    background: var(--move-dot);
    pointer-events:none;
  }
  .sq .ring{
    position:absolute;
    width:82%;
    height:82%;
    border-radius:50%;
    box-shadow: inset 0 0 0 4px var(--move-dot);
    pointer-events:none;
  }
  .piece-slot{
    width:88%;
    height:88%;
    display:flex;
    align-items:center;
    justify-content:center;
    pointer-events:none;
  }
  .piece-glyph{
    line-height:1;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
  }
  .piece-glyph.white{
    color:#c99b5f;
    text-shadow:
      -1.5px 0 #241a0e, 1.5px 0 #241a0e,
      0 -1.5px #241a0e, 0 1.5px #241a0e,
      -1.5px -1.5px #241a0e, 1.5px 1.5px #241a0e,
      -1.5px 1.5px #241a0e, 1.5px -1.5px #241a0e;
  }
  .piece-glyph.black{
    color:#14161a;
    text-shadow:
      -1.3px 0 #e8dcb8, 1.3px 0 #e8dcb8,
      0 -1.3px #e8dcb8, 0 1.3px #e8dcb8,
      -1.3px -1.3px #e8dcb8, 1.3px 1.3px #e8dcb8,
      -1.3px 1.3px #e8dcb8, 1.3px -1.3px #e8dcb8;
  }

  .side-panel{
    background: var(--panel);
    border-radius:16px;
    padding:18px;
    width:280px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.45);
    display:flex;
    flex-direction:column;
    gap:14px;
  }
  .turn-indicator{
    display:flex;
    align-items:center;
    gap:10px;
    background: var(--panel-2);
    border-radius:10px;
    padding:10px 14px;
    font-weight:600;
  }
  .turn-dot{
    width:16px;height:16px;border-radius:50%;
    background:#fff;
    border:2px solid #333;
  }
  .turn-dot.black{ background:#222; border-color:#777; }
  .status-msg{
    font-size:0.85rem;
    color: var(--text-dim);
    min-height: 18px;
  }
  .status-msg.check{ color: var(--danger); font-weight:700; }
  .status-msg.mate{ color: var(--danger); font-weight:700; }

  .btn-row{ display:flex; gap:8px; flex-wrap:wrap; }
  button{
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid #333947;
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.82rem;
    flex:1;
    transition: background .15s ease, transform .05s ease;
  }
  button:hover{ background:#2b3040; }
  button:active{ transform: scale(0.97); }
  button.primary{ background: var(--accent); color:#1a1a1a; border-color:var(--accent); font-weight:700; }
  button.primary:hover{ filter:brightness(1.08); }

  .toggle-row{
    display:flex; align-items:center; justify-content:space-between;
    background: var(--panel-2);
    border-radius:10px;
    padding:10px 14px;
    font-size:0.85rem;
  }
  .switch{ position:relative; width:42px; height:22px; }
  .switch input{ opacity:0; width:0; height:0; }
  .slider{
    position:absolute; cursor:pointer; inset:0;
    background:#3a4050; border-radius:22px; transition:.2s;
  }
  .slider:before{
    content:""; position:absolute; height:16px; width:16px; left:3px; top:3px;
    background:#eee; border-radius:50%; transition:.2s;
  }
  input:checked + .slider{ background: var(--accent-2); }
  input:checked + .slider:before{ transform: translateX(20px); }

  #aiDifficultySelect{
    background: var(--panel);
    color: var(--text);
    border: 1px solid #333947;
    border-radius: 6px;
    padding: 5px 8px;
    font-size: 0.78rem;
  }

  .history-box{
    background: var(--panel-2);
    border-radius:10px;
    padding:10px 12px;
    height:220px;
    overflow-y:auto;
    font-size:0.82rem;
    font-family: 'Consolas', monospace;
  }
  .history-box::-webkit-scrollbar{ width:6px; }
  .history-box::-webkit-scrollbar-thumb{ background:#444; border-radius:3px; }
  .hist-row{ display:flex; gap:8px; padding:2px 0; }
  .hist-num{ color: var(--text-dim); width:22px; flex-shrink:0; }
  .hist-move{ flex:1; }

  .online-box{
    background: var(--panel-2);
    border-radius:10px;
    padding:10px 14px;
    display:flex;
    flex-direction:column;
    gap:8px;
  }
  .online-box .btn-row button{ font-size:0.78rem; padding:8px 10px; }
  .room-code-display{
    font-family:'Consolas', monospace;
    font-size:1.1rem;
    letter-spacing:3px;
    text-align:center;
    background:#14161a;
    border-radius:8px;
    padding:8px;
    color:var(--accent);
  }
  .label-small{
    font-size:0.7rem;
    text-transform:uppercase;
    letter-spacing:1px;
    color: var(--text-dim);
    margin-bottom:2px;
  }

  /* Game mode / color selection / draw controls */
  .radio-box{
    background: var(--panel-2);
    border-radius:10px;
    padding:10px 14px;
    display:flex;
    flex-direction:column;
    gap:6px;
    font-size:0.85rem;
  }
  .radio-box label{ display:flex; align-items:center; gap:8px; cursor:pointer; }
  .radio-box input{ accent-color: var(--accent); }
  .radio-line{ display:flex; gap:14px; flex-wrap:wrap; }
  .match-info{
    background: var(--panel-2);
    border-radius:10px;
    padding:8px 14px;
    font-weight:700;
    font-size:0.85rem;
    letter-spacing:1px;
    color: var(--accent);
    display:flex;
    justify-content:space-between;
    gap:10px;
  }
  .draw-info{ font-size:0.7rem; color: var(--text-dim); margin-top:-6px; }
  button:disabled{ opacity:0.4; cursor:not-allowed; }
  button:disabled:hover{ background: var(--panel-2); }
  button:disabled:active{ transform:none; }
  .status-msg.draw{ color: var(--accent); font-weight:700; }
  .hist-result{
    margin-top:6px; padding-top:6px;
    border-top:1px solid #333947;
    color: var(--accent); font-weight:700;
  }

  /* Promotion modal */
  .modal-overlay{
    position:fixed; inset:0; background:rgba(0,0,0,0.6);
    display:none; align-items:center; justify-content:center; z-index:50;
  }
  .modal-overlay.open{ display:flex; }
  .modal{
    background: var(--panel); padding:20px; border-radius:14px;
    text-align:center; box-shadow:0 10px 40px rgba(0,0,0,0.6);
  }
  .modal h3{ margin-top:0; color:var(--accent); }
  .promo-options{ display:flex; gap:10px; margin-top:10px; }
  .promo-btn{
    font-size:34px; width:56px; height:56px;
    background: var(--panel-2); border-radius:10px; border:1px solid #333947;
    cursor:pointer; display:flex; align-items:center; justify-content:center;
  }
  .promo-btn:hover{ background:#2b3040; }

  footer{
    width:100%;
    text-align:center;
    color: var(--text-dim);
    font-size:0.72rem;
    margin-top:10px;
    opacity:0.7;
  }

  @media (max-width: 720px){
    .app{ flex-direction:column; align-items:center; }
    .side-panel{ width: 100%; max-width: 420px; }
  }
