/* ------------------------------------------------------------------
   Backgammon — styles
   ------------------------------------------------------------------ */
:root {
  --bg: #071213;
  --felt: #0e2b2b;
  --felt-hi: #164042;
  --wood: #4a2f1d;
  --gold: #f2c14e;
  --gold-hi: #ffe39a;
  --text: #eef3ef;
  --muted: #9db7b1;
  --line: rgba(255, 255, 255, 0.1);
  --bar-w: 6%;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  display: flex;
  padding: clamp(12px, 3vw, 28px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1000px 600px at 50% -15%, #164042, var(--bg) 68%);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(100%, 780px);
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.6vw, 14px);
}

/* ---------- En-tête ---------- */
header { text-align: center; }

h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4.2vw, 2.2rem);
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--gold-hi), var(--gold) 55%, #d99a2b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: clamp(0.75rem, 2vw, 0.9rem);
}

/* ---------- Joueurs ---------- */
.players {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pcard {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.pcard.active {
  background: rgba(242, 193, 78, 0.07);
  border-color: rgba(242, 193, 78, 0.65);
  box-shadow: 0 0 0 1px rgba(242, 193, 78, 0.18), 0 0 18px rgba(242, 193, 78, 0.1);
}

.pdot {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

.pdot.white {
  background: radial-gradient(circle at 35% 30%, #fffdf4, #e6d7b6 65%, #c2ad87);
  border: 1px solid #9c8862;
}

.pdot.black {
  background: radial-gradient(circle at 35% 30%, #5b636e, #171c22 65%, #070a0d);
  border: 1px solid #000;
}

.pname {
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.poff {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.76rem;
  white-space: nowrap;
}

.poff strong { color: var(--gold); font-size: 0.92rem; }

/* ---------- Message ---------- */
.message {
  margin: 0;
  min-height: 1.35em;
  text-align: center;
  color: #c6dcd6;
  font-size: clamp(0.82rem, 2.1vw, 0.96rem);
}

/* ---------- Plateau ---------- */
.board {
  position: relative;
  width: 100%;
  height: clamp(264px, 58vw, 440px);
  padding: 8px;
  border: 7px solid var(--wood);
  border-radius: 18px;
  background:
    radial-gradient(120% 120% at 50% 0%, rgba(255, 255, 255, 0.06), transparent 55%),
    linear-gradient(180deg, #123c3a, #0a2422);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.5),
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    0 0 0 1px rgba(0, 0, 0, 0.5);
}

.rows {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 2px;
}

.half {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  gap: clamp(1px, 0.35vw, 3px);
}

.midgap { flex: 0 0 var(--bar-w); }

/* ---------- Points et triangles ---------- */
.point {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
}

.point .tri {
  position: absolute;
  inset: 0;
  border-radius: 3px;
}

.point.top .tri { clip-path: polygon(0 0, 100% 0, 50% 100%); }
.point.bottom .tri { clip-path: polygon(50% 0, 100% 100%, 0 100%); }

.point.light .tri { background: linear-gradient(180deg, #f4e7c8, #d6bd91); }
.point.bottom.light .tri { background: linear-gradient(0deg, #f4e7c8, #d6bd91); }
.point.dark .tri { background: linear-gradient(180deg, #1c7a72, #0b4a45); }
.point.bottom.dark .tri { background: linear-gradient(0deg, #1c7a72, #0b4a45); }

.point.selectable { cursor: pointer; }
.point.selectable:hover .tri { filter: brightness(1.12); }
.point.selected .tri { filter: brightness(1.32) saturate(1.1); }
.point.legal .tri { filter: brightness(1.3) saturate(1.15); }

.point.legal::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 26%;
  max-width: 14px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--gold-hi);
  box-shadow: 0 0 10px rgba(255, 220, 120, 0.9);
  transform: translateX(-50%);
  z-index: 4;
  animation: pulse 0.9s ease-in-out infinite;
}

.point.top.legal::after { bottom: 8%; }
.point.bottom.legal::after { top: 8%; }

@keyframes pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* ---------- Pions ---------- */
.stack {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2%;
  padding: 3px 0;
  pointer-events: none;
}

.point.top .stack { justify-content: flex-start; }
.point.bottom .stack { justify-content: flex-end; }

.point.selected .stack {
  filter: drop-shadow(0 0 6px rgba(242, 193, 78, 0.95));
}

.checker {
  position: relative;
  flex: 0 0 auto;
  width: 74%;
  max-width: 36px;
  aspect-ratio: 1;
  border-radius: 50%;
}

.checker.white {
  background: radial-gradient(circle at 34% 28%, #fffdf4, #f1e4c8 55%, #c7b38d 100%);
  border: 1px solid #8e7a54;
  box-shadow:
    0 2px 3px rgba(0, 0, 0, 0.45),
    inset 0 0 0 2px rgba(255, 255, 255, 0.45);
}

.checker.black {
  background: radial-gradient(circle at 34% 28%, #626a75, #262c34 55%, #0b0e12 100%);
  border: 1px solid #05070a;
  box-shadow:
    0 2px 3px rgba(0, 0, 0, 0.6),
    inset 0 0 0 2px rgba(255, 255, 255, 0.12);
}

.checker .count {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(9px, 1.5vw, 15px);
  font-weight: 800;
}

.checker.white .count { color: #5b4523; }
.checker.black .count { color: #ffe7b0; }

/* ---------- Numéros de points ---------- */
.num {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 1;
  font-size: clamp(6px, 1.1vw, 9px);
  font-weight: 700;
  color: rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.point.top .num { bottom: 2px; }
.point.bottom .num { top: 2px; }
.point.dark .num { color: rgba(255, 255, 255, 0.45); }

/* ---------- Barre centrale ---------- */
.bar {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 50%;
  width: var(--bar-w);
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  flex-direction: column;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.35));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 0 12px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.bar-half {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  pointer-events: none;
}

.bar-half.selectable {
  pointer-events: auto;
  cursor: pointer;
  background: rgba(242, 193, 78, 0.12);
}

.bar-half.selectable:hover { background: rgba(242, 193, 78, 0.2); }

.bar-half.selected {
  background: rgba(242, 193, 78, 0.26);
  box-shadow: inset 0 0 0 2px var(--gold);
}

.bar-badge {
  width: min(88%, 30px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(8px, 1.1vw, 12px);
  font-weight: 800;
  pointer-events: none;
}

.bar-badge.white {
  background: radial-gradient(circle at 35% 30%, #fffdf4, #e8d9b8);
  color: #5b4523;
  border: 1px solid #9b855d;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.bar-badge.black {
  background: radial-gradient(circle at 35% 30%, #5a626d, #151a20);
  color: #ffe7b0;
  border: 1px solid #000;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* ---------- Bandeau de fin ---------- */
.banner {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: 16px;
  background: rgba(4, 10, 10, 0.62);
  backdrop-filter: blur(2px);
}

.banner[hidden] { display: none; }

.banner-card {
  width: min(100%, 320px);
  padding: 18px 22px;
  text-align: center;
  background: linear-gradient(180deg, #173c3b, #0c2423);
  border: 1px solid rgba(242, 193, 78, 0.55);
  border-radius: 14px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.6);
}

.banner-card p {
  margin: 0 0 12px;
  color: var(--gold-hi);
  font-size: clamp(1rem, 2.6vw, 1.2rem);
  font-weight: 800;
}

/* ---------- Dés et boutons ---------- */
.tray {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.dice {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.die {
  width: clamp(36px, 8vw, 46px);
  aspect-ratio: 1;
  padding: 7px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 2px;
  background: linear-gradient(150deg, #fffdf6, #d9e2e6);
  border-radius: 10px;
  box-shadow: 0 3px 0 #7f8f96, 0 5px 10px rgba(0, 0, 0, 0.4);
  transition: opacity 0.15s, transform 0.15s;
}

.die .cell { display: flex; align-items: center; justify-content: center; }

.die .cell.pip::after {
  content: "";
  width: 74%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #12252a;
}

.die.used { opacity: 0.25; transform: scale(0.9); }

.die.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(255, 255, 255, 0.22);
  box-shadow: none;
  color: rgba(255, 255, 255, 0.3);
  font-size: 1.4rem;
  font-weight: 700;
}

.actions {
  width: 100%;
  max-width: 480px;
  display: flex;
  gap: 8px;
}

.actions .btn { flex: 1; }

.btn {
  padding: clamp(0.6rem, 1.6vw, 0.78rem) 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-family: inherit;
  font-size: clamp(0.82rem, 2vw, 0.95rem);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s, opacity 0.15s, box-shadow 0.15s;
}

.btn:hover:not(:disabled) { filter: brightness(1.1); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.32; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(180deg, #f6d276, #dfa13a);
  border-color: #ffe6a1;
  color: #2a1b06;
}

.btn.ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.18);
}

.btn.ready {
  box-shadow: 0 0 0 2px var(--gold), 0 0 18px rgba(242, 193, 78, 0.45);
}

.footer-controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.footer-controls .btn {
  padding: 0.5rem 0.85rem;
  font-size: 0.8rem;
}

/* ---------- Règles ---------- */
.rules {
  padding: 0.7rem 0.9rem;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  color: #c8dad5;
  font-size: 0.82rem;
  line-height: 1.5;
}

.rules summary {
  cursor: pointer;
  color: #f0cf7a;
  font-weight: 700;
}

.rules ul {
  margin: 0.55rem 0 0 1.1rem;
  padding: 0;
}

.rules li { margin: 0.18rem 0; }

.rules .note {
  margin: 0.5rem 0 0;
  color: #88a29c;
  font-size: 0.78rem;
}

/* ---------- Petits écrans ---------- */
@media (max-width: 430px) {
  .tagline { display: none; }
  .board { border-width: 6px; padding: 6px; }
  .bar { top: 6px; bottom: 6px; }
  .pcard { padding: 0.45rem 0.55rem; }
  .pname { font-size: 0.82rem; }
  .poff { font-size: 0.7rem; }
  .checker.white,
  .checker.black { border-width: 1px; }
}

@media (prefers-reduced-motion: reduce) {
  .point.legal::after { animation: none; }
  .btn, .die { transition: none; }
}
