/* Jeu Royal d'Ur — Museum Premium : bois sombre, ivoire, lapis, or. */
:root {
  --bg: #141019;
  --bg-2: #1e1726;
  --board-wood: #3a2a1c;
  --ivory: #ead8b8;
  --lapis: #2b4a8f;
  --lapis-light: #4a6fc4;
  --gold: #c9a24b;
  --danger: #b0432f;
  --ok: #4d8a5b;
  --text: #efe6d4;
  --muted: #9c8f7a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 90% at 50% 0%, var(--bg-2), var(--bg) 70%);
  color: var(--text);
  font-family: Georgia, 'Times New Roman', serif;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.screen {
  width: min(100vw, 460px);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(env(safe-area-inset-top), 10px) 12px max(env(safe-area-inset-bottom), 10px);
}
.hidden { display: none !important; }

/* ---------- Accueil ---------- */
.logo {
  margin: 10vh 0 0;
  width: 100%;
  max-width: 380px;
  height: auto;
  filter: drop-shadow(0 2px 14px rgba(201, 162, 75, 0.3));
}
.subtitle { color: var(--muted); margin: 10px 0 30px; font-style: italic; }
.home-form { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 320px; }
.join-row { display: flex; gap: 8px; }
.join-row input { width: 40%; text-transform: uppercase; text-align: center; letter-spacing: 3px; }
.join-row .btn { flex: 1; }
input[type="text"] {
  background: var(--bg-2);
  border: 1px solid #3c3149;
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  width: 100%;
}
.stats { color: var(--muted); margin-top: 26px; font-size: 14px; }

.btn {
  background: var(--bg-2);
  border: 1px solid #4a3c5c;
  color: var(--text);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn-primary {
  background: linear-gradient(160deg, var(--gold), #a3781f);
  border-color: #d9b96a;
  color: #241a08;
  font-weight: bold;
}
.btn-resume { border-color: var(--ok); color: #bfe3c8; }

/* ---------- HUD ---------- */
.hud {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  flex-wrap: wrap;
}
.hud-bottom { flex-direction: column; align-items: stretch; gap: 6px; }
.player-tag { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot-p0 { background: var(--ivory); box-shadow: 0 0 6px rgba(234, 216, 184, 0.6); }
.dot-p1 { background: var(--lapis-light); box-shadow: 0 0 6px rgba(74, 111, 196, 0.7); }
.pool { color: var(--muted); font-size: 13px; margin-left: auto; }
.hud-bottom .player-tag { justify-content: space-between; }
.hud-bottom .pool { margin-left: 0; }

/* ---------- Plateau ---------- */
#board-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
}
#board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 4px;
  aspect-ratio: 3 / 8;
  height: 100%;
  max-height: min(64dvh, 560px);
  max-width: 100%;
  padding: 8px;
  background: linear-gradient(155deg, #46331f, var(--board-wood) 60%, #2c1f13);
  border: 2px solid #6b4e2e;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55), inset 0 0 30px rgba(0, 0, 0, 0.35);
}
.cell {
  position: relative;
  border-radius: 6px;
  background-color: var(--ivory);
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 1px rgba(60, 40, 20, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
  transition: box-shadow 0.15s ease;
}
.cell.target { box-shadow: 0 0 0 3px var(--ok), 0 0 14px rgba(77, 138, 91, 0.8); z-index: 2; }
.cell.capture-target { box-shadow: 0 0 0 3px var(--danger), 0 0 14px rgba(176, 67, 47, 0.8); z-index: 2; }
.notch { border-radius: 8px; background: rgba(0, 0, 0, 0.18); box-shadow: inset 0 0 10px rgba(0,0,0,0.3); }

/* ---------- Pions ---------- */
.piece {
  position: absolute;
  width: 9.5%;
  aspect-ratio: 1;
  border-radius: 50%;
  z-index: 3;
  transition: left 0.35s ease, top 0.35s ease, transform 0.35s ease, opacity 0.3s ease;
  cursor: pointer;
}
.piece-p0 {
  background: radial-gradient(circle at 32% 30%, #fff7e6, var(--ivory) 55%, #b39868);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6), inset 0 -2px 4px rgba(120, 90, 40, 0.5);
}
.piece-p1 {
  background: radial-gradient(circle at 32% 30%, #7fa1e8, var(--lapis) 60%, #16264d);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6), inset 0 -2px 4px rgba(10, 20, 50, 0.6);
}
.piece.playable {
  outline: 3px solid var(--gold);
  outline-offset: 1px;
  animation: pulse 1.1s ease-in-out infinite;
  z-index: 4;
}
.piece.off { opacity: 0; pointer-events: none; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 4px 1px rgba(201, 162, 75, 0.7); }
  50% { box-shadow: 0 0 16px 5px rgba(201, 162, 75, 0.9); }
}

.room-code {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 16, 25, 0.85);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 14px;
  letter-spacing: 1px;
  white-space: nowrap;
}

/* ---------- Dés / statut ---------- */
#dice-area { display: flex; align-items: center; gap: 12px; justify-content: center; }
.dice { display: flex; align-items: center; gap: 6px; min-width: 120px; min-height: 26px; }
.die {
  width: 18px; height: 18px;
  transform: rotate(45deg);
  border-radius: 4px;
  border: 1px solid #6b5a3a;
}
.die-on { background: var(--gold); box-shadow: 0 0 8px rgba(201, 162, 75, 0.8); }
.die-off { background: #2a2233; }
.die-total {
  font-size: 22px;
  color: var(--gold);
  font-weight: bold;
  margin-left: 6px;
  min-width: 20px;
  text-align: center;
}
#btn-roll { min-width: 130px; }
.status { text-align: center; color: var(--muted); font-size: 15px; min-height: 20px; font-style: italic; }

/* ---------- Toast / overlay ---------- */
.toast {
  position: fixed;
  bottom: 22dvh;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 16, 25, 0.92);
  border: 1px solid var(--gold);
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 15px;
  z-index: 20;
  white-space: nowrap;
}
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 14, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}
.overlay-card {
  background: var(--bg-2);
  border: 1px solid var(--gold);
  border-radius: 16px;
  padding: 28px 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 300px;
}
.overlay-card h2 { margin: 0; color: var(--gold); font-size: 30px; }
.overlay-card p { margin: 0 0 8px; color: var(--muted); }

/* ---------- Règles ---------- */
.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-size: 17px;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}
.btn-icon:active { transform: scale(0.94); }

.rules-card {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--gold);
  border-radius: 16px;
  padding: 20px 20px 14px;
  width: min(92vw, 380px);
  max-height: 84dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.rules-title { margin: 0; color: var(--gold); font-size: 22px; text-align: center; }
.rules-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  padding: 6px;
  cursor: pointer;
}
#rules-pages { flex: 1; overflow-y: auto; min-height: 210px; }
.rules-page h3 { margin: 0 0 10px; color: var(--ivory); font-size: 18px; }
.rules-page p { margin: 0 0 10px; color: var(--muted); font-style: italic; font-size: 14px; }
.rules-page ul {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rules-page li { color: var(--text); font-size: 15px; line-height: 1.45; }
.rules-page strong { color: var(--gold); font-weight: bold; }
.rules-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rules-nav .btn { min-width: 58px; padding: 8px 14px; }
.rules-dots { display: flex; gap: 6px; }
.rules-dot { width: 8px; height: 8px; border-radius: 50%; background: #4a3c5c; }
.rules-dot.on { background: var(--gold); }
.rules-src { margin: 0; text-align: center; color: var(--muted); font-size: 12px; font-style: italic; }
