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

  :root {
    --coord: 22px;
    --sq: min(58px, calc((100vw - 96px) / 8));
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --bg1: #0b1220;
    --bg2: #1c2740;
    --card: rgba(255,255,255,0.06);
    --border: rgba(255,255,255,0.12);
    --text: #e8ecf4;
    --muted: #94a3b8;
    --accent: #f59e0b;
    --accent-dark: #d97706;
  }
  :root[data-theme="green"] { --board-light: #eeeed2; --board-dark: #769656; }
  :root[data-theme="blue"]  { --board-light: #dee3e6; --board-dark: #8ca2ad; }
  :root[data-theme="night"] { --board-light: #a7b0be; --board-dark: #4b5563; }

  body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--text);
    background: linear-gradient(135deg, var(--bg1), var(--bg2));
    background-attachment: fixed;
    min-height: 100vh;
    padding: 16px;
  }

  #app { width: 100%; max-width: 940px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

  /* ---------- Barre du haut ---------- */
  #topbar { display: flex; justify-content: space-between; align-items: center; }
  .brand { display: flex; align-items: center; gap: 10px; }
  .brand .logo {
    width: 40px; height: 40px; border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; color: #1b1203;
  }
  .brand h1 { font-size: 22px; letter-spacing: 0.5px; }
  .top-actions { display: flex; gap: 8px; }
  .icon-btn {
    width: 40px; height: 40px; border-radius: 12px;
    border: 1px solid var(--border); background: var(--card);
    color: var(--text); font-size: 18px; cursor: pointer;
    transition: background 0.15s, transform 0.1s;
  }
  .icon-btn:hover { background: rgba(255,255,255,0.12); }
  .icon-btn:active { transform: scale(0.94); }

  /* ---------- Mise en page ---------- */
  main { display: flex; gap: 22px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
  #game { display: flex; flex-direction: column; gap: 10px; width: fit-content; }
  #side { width: 300px; max-width: 100%; display: flex; flex-direction: column; gap: 14px; }

  .card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
  }

  #status { font-size: 17px; font-weight: 600; line-height: 1.3; }
  #voice-msg { font-size: 13px; color: var(--muted); min-height: 36px; line-height: 1.4; }
  .hint { font-size: 13px; color: var(--muted); line-height: 1.5; }
  .hint b { color: var(--text); font-weight: 600; }
  .card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 600; }

  .btn-row { display: flex; flex-direction: column; gap: 8px; }
  .btn {
    font-size: 14px; font-weight: 600;
    padding: 10px 14px; border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.08);
    color: var(--text); cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    transition: background 0.15s, transform 0.1s;
  }
  .btn:hover { background: rgba(255,255,255,0.16); }
  .btn:active { transform: scale(0.98); }
  .btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: #1b1203; border-color: transparent; }
  .btn.primary:hover { filter: brightness(1.08); }
  .btn.primary.listening { background: linear-gradient(135deg, #ef4444, #b91c1c); color: #fff; animation: pulse 1.2s infinite; }
  .btn.small { padding: 6px 12px; font-size: 13px; }
  @keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); } 50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); } }

  kbd {
    font-family: inherit; font-size: 12px; font-weight: 700;
    padding: 2px 8px; border-radius: 6px;
    background: rgba(0,0,0,0.25); border: 1px solid rgba(255,255,255,0.25);
    border-bottom-width: 3px; color: inherit;
  }
  .btn.primary kbd { background: rgba(0,0,0,0.15); border-color: rgba(0,0,0,0.3); }
  kbd.big { font-size: 15px; padding: 4px 14px; }

  /* ---------- Barres joueurs ---------- */
  .player-bar {
    width: 0; min-width: 100%;
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; border-radius: 12px;
    background: var(--card); border: 1px solid transparent;
    min-height: 46px;
    transition: border-color 0.2s, box-shadow 0.2s;
  }
  .player-bar.active { border-color: var(--accent); box-shadow: 0 0 14px rgba(245,158,11,0.25); }
  .avatar {
    width: 30px; height: 30px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
  }
  .avatar.w { background: #f8fafc; color: #111; }
  .avatar.b { background: #0f172a; color: #fff; border: 1px solid rgba(255,255,255,0.3); }
  .pname { font-weight: 600; font-size: 14px; white-space: nowrap; }
  .cap-pills { display: inline-flex; flex-wrap: wrap; gap: 1px; background: #e8dcc4; border-radius: 8px; padding: 1px 6px; }
  .cap-pills:empty { display: none; }
  .cap-piece { font-size: 17px; line-height: 1.3; color: #111; }
  .cap-piece.w { color: #fdfdfd; text-shadow: 1px 0 #1e1e1e, -1px 0 #1e1e1e, 0 1px #1e1e1e, 0 -1px #1e1e1e; }
  .adv { font-size: 13px; font-weight: 700; color: var(--accent); margin-left: auto; }
  .clock {
    font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums;
    padding: 4px 10px; border-radius: 8px; min-width: 74px; text-align: center;
    background: rgba(0,0,0,0.35); color: var(--muted); flex-shrink: 0;
  }
  .clock.running { background: #f8fafc; color: #111; }
  .clock.low { color: #f87171; }
  .clock.running.low { background: #fee2e2; color: #b91c1c; }
  input.num {
    width: 64px; font-size: 13px; padding: 6px 8px; border-radius: 8px;
    border: 1px solid var(--border); background: #0f172a; color: var(--text);
  }
  input.num:disabled { opacity: 0.5; }

  /* ---------- Plateau + coordonnées ---------- */
  #board-wrap { display: flex; flex-direction: column; }
  #board-mid { display: flex; }

  .files { display: flex; padding: 0 calc(var(--coord) + 2px); height: var(--coord); }
  .files span {
    width: var(--sq); text-align: center;
    font-size: 12px; font-weight: 600; color: var(--muted);
    line-height: var(--coord);
  }
  .ranks { display: flex; flex-direction: column; width: var(--coord); margin: 2px 0; }
  .ranks span {
    height: var(--sq); display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600; color: var(--muted);
  }
  .no-coords .files, .no-coords .ranks { display: none; }

  #board {
    display: grid;
    grid-template-columns: repeat(8, var(--sq));
    grid-template-rows: repeat(8, var(--sq));
    border: 2px solid #0b1220;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  }

  .sq {
    width: var(--sq);
    height: var(--sq);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    user-select: none;
    font-size: calc(var(--sq) * 0.68);
    line-height: 1;
  }

  .sq.light { background: var(--board-light); }
  .sq.dark  { background: var(--board-dark); }
  .sq.selected      { background: #7cc4ff !important; }
  .sq.check         { background: #e74c3c !important; }
  .sq.lastmove      { background: #cdd16a !important; }
  .sq.lastmove.dark { background: #aaa23a !important; }

  .sq.move::after {
    content: '';
    position: absolute;
    width: 32%; height: 32%;
    border-radius: 50%;
    background: rgba(0,0,0,0.22);
    pointer-events: none;
    z-index: 1;
  }
  .sq.move.occupied::after {
    width: 100%; height: 100%;
    border-radius: 0;
    background: transparent;
    box-shadow: inset 0 0 0 5px rgba(0,0,0,0.28);
  }

  /* Pièces blanches pleines : intérieur blanc, contour sombre net (8 directions) + petite ombre */
  .piece-w {
    color: #fdfdfd;
    text-shadow:
      1.5px 0 #1e1e1e, -1.5px 0 #1e1e1e, 0 1.5px #1e1e1e, 0 -1.5px #1e1e1e,
      1px 1px #1e1e1e, -1px -1px #1e1e1e, 1px -1px #1e1e1e, -1px 1px #1e1e1e,
      0 3px 4px rgba(0,0,0,0.35);
    position: relative; z-index: 2;
  }
  .piece-b {
    color: #1a1a1a;
    text-shadow: 0 0 1px rgba(255,255,255,0.6), 0 3px 4px rgba(0,0,0,0.25);
    position: relative; z-index: 2;
  }

  @keyframes pop { 0% { transform: scale(0.7); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
  .sq.lastmove .piece-w, .sq.lastmove .piece-b { animation: pop 0.18s ease-out; }

  @keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
  #board.shake { animation: shake 0.18s ease-in-out; }

  /* ---------- Fenêtres (promotion + réglages) ---------- */
  .overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(2,6,15,0.65);
    backdrop-filter: blur(3px);
    align-items: center; justify-content: center;
    z-index: 100;
    padding: 16px;
  }
  .overlay.show { display: flex; }

  .panel {
    background: #17213a;
    border: 1px solid var(--border);
    border-radius: 18px;
    width: min(480px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    display: flex; flex-direction: column; gap: 18px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  }
  .panel-head { display: flex; justify-content: space-between; align-items: center; }
  .panel-head h2 { font-size: 20px; }

  #modal-box { align-items: center; width: auto; }
  #modal-box h2 { font-size: 18px; font-weight: 600; }
  .promo-row { display: flex; gap: 8px; }
  .promo-btn {
    font-size: 34px; cursor: pointer;
    padding: 8px 12px; border-radius: 10px;
    border: 1px solid var(--border); background: rgba(255,255,255,0.85); line-height: 1;
  }
  .promo-btn:hover { background: #fff; transform: translateY(-2px); }

  .section { display: flex; flex-direction: column; gap: 4px; }
  .section h3 {
    font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px;
    color: var(--accent); margin-bottom: 4px;
  }
  .row {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 9px 0; border-bottom: 1px solid rgba(255,255,255,0.07);
    font-size: 14px;
  }
  .row:last-child { border-bottom: none; }
  .row .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
  .row .ctrl { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

  select.opt-select:disabled { opacity: 0.5; cursor: not-allowed; }
  select.opt-select {
    font-size: 13px; padding: 7px 10px; border-radius: 10px;
    border: 1px solid var(--border); background: #0f172a; color: var(--text);
    cursor: pointer; max-width: 200px;
  }
  input[type=range] { accent-color: var(--accent); width: 140px; cursor: pointer; }
  .vol-val { width: 38px; text-align: right; font-size: 13px; color: var(--muted); }

  .switch { position: relative; width: 44px; height: 24px; display: inline-block; flex-shrink: 0; }
  .switch input { opacity: 0; width: 0; height: 0; }
  .slider {
    position: absolute; inset: 0; border-radius: 24px;
    background: rgba(255,255,255,0.18); cursor: pointer; transition: background 0.2s;
  }
  .slider::before {
    content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
    border-radius: 50%; background: #fff; transition: transform 0.2s;
  }
  .switch input:checked + .slider { background: var(--accent); }
  .switch input:checked + .slider::before { transform: translateX(20px); }

  .capturing { background: linear-gradient(135deg, #3b82f6, #1d4ed8) !important; color: #fff !important; animation: pulse 1.2s infinite; }

  /* ----- Mode en ligne ----- */
  .txt { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
         background: rgba(255,255,255,0.06); color: var(--text); font-size: 14px; font-family: inherit; }
  .txt:focus { outline: 2px solid var(--accent); }
  .tabs { display: flex; gap: 8px; margin-bottom: 4px; }
  .tabs .btn { flex: 1; }
  .tabs .btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: #1b1203; border-color: transparent; }
  #on-auth, #on-lobby, #on-config { gap: 10px; }
  #on-lobby h3 { margin-top: 10px; }
  .games-list { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
  .game-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 11px;
               border: 1px solid var(--border); border-radius: 10px; cursor: pointer; color: var(--text); }
  .game-item:hover { background: rgba(255,255,255,0.08); }
  .game-state { font-size: 12px; color: var(--muted); text-align: right; }
  .msg-err { color: #fca5a5; }
  .msg-ok { color: #86efac; }
  #online-msg { margin-top: 10px; min-height: 18px; }
  .code-row { display: flex; gap: 8px; align-items: center; }
  @media (max-width: 700px) {
    #side { width: 100%; }
  }

/* ----- Glisser-déposer, animation, clavier ----- */
#board { touch-action: none; user-select: none; -webkit-user-select: none; }
#board.reviewing { outline: 3px dashed var(--accent); outline-offset: 3px; }
.sq:focus { outline: none; }
.sq:focus-visible { box-shadow: inset 0 0 0 4px #3b82f6; z-index: 2; }
.sq.drag-src span { opacity: 0.25; }
.sq.drag-over { box-shadow: inset 0 0 0 4px rgba(255,255,255,0.75); }
.sq span { position: relative; }
.sq span.sliding { animation: none !important; }
.drag-ghost {
  position: fixed; z-index: 1000; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  line-height: 1; transform: scale(1.12); filter: drop-shadow(0 6px 8px rgba(0,0,0,0.45));
}

/* ----- Liste des coups ----- */
.moves {
  display: grid; grid-template-columns: 34px 1fr 1fr; gap: 2px 4px; align-content: start;
  max-height: 190px; overflow-y: auto; margin: 10px 0 8px;
  font-variant-numeric: tabular-nums; font-size: 14px;
}
.mv-num { color: var(--muted); padding: 4px 0; text-align: right; padding-right: 4px; }
.mv {
  text-align: left; padding: 4px 8px; border-radius: 6px; border: 0; cursor: pointer;
  background: transparent; color: var(--text); font: inherit;
}
.mv:hover { background: rgba(255,255,255,0.08); }
.mv.current { background: var(--accent); color: #111; font-weight: 700; }
.mv.empty { cursor: default; }
.mv-empty { grid-column: 1 / -1; color: var(--muted); font-size: 13px; padding: 4px 0; }
.mv-result { grid-column: 1 / -1; text-align: center; font-weight: 700; padding: 6px 0 2px; }
.nav-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tool-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 6px; }
.nav-row .btn, .tool-row .btn { justify-content: center; padding-left: 4px; padding-right: 4px; }

/* ----- Jeu en ligne : parties ouvertes, classement ----- */
.inline-refresh { display: inline-flex; margin-left: 6px; padding: 2px 8px; font-size: 12px; vertical-align: middle; }
.game-item .rank { color: var(--muted); min-width: 26px; display: inline-block; }
.game-item.me { outline: 1px solid var(--accent); }
button.game-item { width: 100%; font: inherit; color: var(--text); background: transparent; cursor: pointer; text-align: left; }
button.game-item:hover { background: rgba(255,255,255,0.08); }
html { background-color: #0b1220; }   /* fond de secours (défilement élastique sur téléphone) */
