/* ------------------------------------------------------------------ */
/* Mais Chess — thème "club d'échecs de nuit" : ardoise, laiton, feutre */
/* ------------------------------------------------------------------ */

:root {
  --bg: #15181d;
  --surface: #1e232b;
  --surface-2: #262c36;
  --line: #333b48;
  --text: #e8e4da;
  --text-dim: #9aa3ae;
  --brass: #c9a24b;
  --brass-soft: #e0c37e;
  --danger: #d06553;
  --ok: #7fb069;
  --sq-light: #b8a888;
  --sq-dark: #6f5f48;
  --sq-select: rgba(201, 162, 75, 0.65);
  --sq-last: rgba(224, 195, 126, 0.35);
  --sq-check: rgba(208, 101, 83, 0.65);
  --radius: 10px;
  --font-display: 'Spectral', Georgia, serif;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

/* ---------- Boutons & champs ---------- */

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15px;
  border: none;
  border-radius: var(--radius);
  padding: 12px 22px;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  background: var(--brass);
  color: #1a1508;
}
.btn-primary:hover:not(:disabled) { background: var(--brass-soft); }

.btn-big { font-size: 19px; padding: 16px 0; width: 100%; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-family: var(--font-body);
  font-size: 14px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }
.btn-danger:hover { color: var(--danger); border-color: var(--danger); }

input[type="text"], input[type="password"] {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px 14px;
  font-size: 15px;
  font-family: var(--font-body);
}
input:focus { outline: 2px solid var(--brass); outline-offset: -1px; border-color: transparent; }

.error { color: var(--danger); margin-top: 12px; font-size: 14px; text-align: center; }

/* ---------- Auth ---------- */

.auth-card, .lobby-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
}

.logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 34px;
  letter-spacing: .06em;
  text-align: center;
}
.logo-piece { color: var(--brass); margin: 0 4px; }

.tagline {
  text-align: center;
  color: var(--text-dim);
  font-size: 13.5px;
  margin: 6px 0 24px;
}

.tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--line);
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  padding: 10px 0;
  cursor: pointer;
}
.tab.active { color: var(--brass); border-bottom-color: var(--brass); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }

.elo-choice { margin-top: 4px; }
.elo-label { font-size: 13px; color: var(--text-dim); display: block; margin-bottom: 8px; }
.elo-pills { display: flex; gap: 8px; }
.elo-pills label { flex: 1; cursor: pointer; }
.elo-pills input { display: none; }
.elo-pills span {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--text-dim);
}
.elo-pills em { font-style: normal; font-weight: 600; font-size: 15px; color: var(--text); }
.elo-pills input:checked + span { border-color: var(--brass); background: rgba(201,162,75,.1); color: var(--text); }

/* ---------- Salon ---------- */

.lobby-head { display: flex; justify-content: space-between; align-items: center; }
.lobby-head h2 { font-family: var(--font-display); font-size: 24px; }

.lobby-elo {
  text-align: center;
  margin: 22px 0 4px;
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 700;
  color: var(--brass);
  line-height: 1;
}
.lobby-elo small {
  display: block;
  font-family: var(--font-body);
  font-size: 12px;
  letter-spacing: .25em;
  color: var(--text-dim);
  margin-top: 6px;
}

.lobby-stats { text-align: center; color: var(--text-dim); font-size: 14px; margin-bottom: 26px; }

.searching { text-align: center; margin-top: 20px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--brass);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.rules { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 14px; }
.rules summary { cursor: pointer; color: var(--text-dim); font-size: 14px; }
.rules ul { margin: 12px 0 0 18px; color: var(--text-dim); font-size: 13.5px; display: flex; flex-direction: column; gap: 8px; }
.rules strong { color: var(--text); }

/* ---------- Phase deck ---------- */

.deck-wrap { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 14px; }

.deck-head { display: flex; justify-content: space-between; align-items: center; }
.vs-label { font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--text-dim); }
.vs-name { font-family: var(--font-display); font-size: 20px; font-weight: 700; }

.big-timer {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 700;
  color: var(--brass);
  font-variant-numeric: tabular-nums;
}
.big-timer.urgent { color: var(--danger); }

.budget-bar { display: flex; align-items: center; gap: 12px; }
.budget-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.budget-fill { height: 100%; width: 0%; background: var(--brass); border-radius: 4px; transition: width .15s ease; }
.budget-fill.full { background: var(--ok); }
#budget-text { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.deck-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  border: 2px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 4 / 1;
}
.deck-hint { font-size: 12px; color: var(--text-dim); text-align: center; }

.palette { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.piece-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 58px;
}
.piece-btn .glyph { font-size: 26px; line-height: 1.1; }
.piece-btn em { font-style: normal; font-size: 11px; color: var(--text-dim); }
.piece-btn.selected { border-color: var(--brass); background: rgba(201,162,75,.12); }
.piece-btn:disabled { opacity: .35; cursor: not-allowed; }

.deck-actions { display: flex; gap: 10px; justify-content: center; }
.deck-actions .btn-primary { min-width: 130px; }
.deck-status { text-align: center; color: var(--text-dim); font-size: 14px; min-height: 20px; }
.deck-status.ok { color: var(--ok); }

/* ---------- Cases (partagées deck + plateau) ---------- */

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  cursor: pointer;
  aspect-ratio: 1;
}
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq .pc { font-size: min(7.2vw, 34px); line-height: 1; }
.pc.w { color: #f6f1e4; text-shadow: 0 1px 2px rgba(0,0,0,.75), 0 0 1px rgba(0,0,0,.9); }
.pc.b { color: #23201c; text-shadow: 0 1px 1px rgba(255,255,255,.22); }

.sq.selected { box-shadow: inset 0 0 0 3px var(--sq-select); }
.sq.last { box-shadow: inset 0 0 0 100px var(--sq-last); }
.sq.check { box-shadow: inset 0 0 0 100px var(--sq-check); }

.sq.target::after {
  content: '';
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(26, 21, 8, 0.45);
}
.sq.target.capture::after {
  width: 82%;
  height: 82%;
  background: transparent;
  border: 3px solid rgba(26, 21, 8, 0.5);
}

/* ---------- Partie ---------- */

.game-wrap { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 10px; }

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  border: 2px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 1;
}

.player-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.p-name { font-weight: 600; }
.p-clock {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}
.player-bar.active .p-clock { color: var(--brass); }
.p-clock.urgent { color: var(--danger) !important; }

.game-actions { display: flex; justify-content: space-between; align-items: center; }
.turn-indicator { color: var(--text-dim); font-size: 14px; }
.turn-indicator.me { color: var(--brass); font-weight: 600; }

.game-banner {
  text-align: center;
  background: rgba(208,101,83,.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 8px;
  font-size: 14px;
}

/* ---------- Modale ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 15, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  text-align: center;
  max-width: 360px;
  width: 100%;
}
.modal-card h2 { font-family: var(--font-display); font-size: 30px; margin-bottom: 6px; }
.modal-card p { color: var(--text-dim); margin-bottom: 8px; }
.over-elo { font-size: 20px; font-weight: 600; margin: 14px 0 20px !important; }
.over-elo.up { color: var(--ok); }
.over-elo.down { color: var(--danger); }

@media (max-width: 420px) {
  .piece-btn { min-width: 48px; padding: 6px 6px 4px; }
  .piece-btn .glyph { font-size: 22px; }
  .lobby-elo { font-size: 46px; }
}
