:root {
  --bg: #f6efe2;
  --sand: #ead9b8;
  --sand-dark: #d6bf93;
  --card: #fffaf1;
  --ink: #2d2418;
  --muted: #7a6a55;
  --accent: #c0692b;
  --accent-ink: #fff;
  --ok: #2e8b57;
  --bad: #c0392b;
  --border: #e2d3b5;

  --c-blue: #2f6fde;
  --c-green: #2e9e4f;
  --c-yellow: #f2c614;
  --c-red: #d93a3a;
  --c-purple: #8e44ad;

  --p-corail: #ff7f6e;
  --p-turquoise: #1fb5ac;
  --p-ambre: #f0a830;
  --p-ardoise: #5b6b7f;
  --p-menthe: #7fd88a;
  --p-framboise: #d6336c;
  --p-lavande: #a78bfa;
  --p-cacao: #8b5a2b;
  --p-ciel: #4dabf7;
  --p-olive: #8f9a3b;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
h1, h2, h3, h4 { margin: 0 0 .5rem; }
h3 { font-size: 1rem; }
h4 { font-size: .9rem; margin-top: .25rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.code { font-family: ui-monospace, monospace; letter-spacing: .15em; background: var(--sand); padding: 0 .35em; border-radius: 4px; }

button {
  font: inherit; cursor: pointer; border: 1px solid var(--sand-dark); background: #fff;
  color: var(--ink); padding: .45rem .8rem; border-radius: 8px; transition: background .15s, transform .1s;
}
button:hover:not(:disabled) { background: var(--sand); }
button:active:not(:disabled) { transform: scale(.97); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: #a5561f; }
button.selected { outline: 3px solid var(--ink); outline-offset: 1px; }
input {
  font: inherit; width: 100%; padding: .55rem .7rem; border: 1px solid var(--sand-dark);
  border-radius: 8px; margin-top: .25rem; background: #fff;
}
label { display: block; margin: .75rem 0; font-weight: 600; }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-family: ui-monospace, monospace; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }

/* Accueil / salle d'attente */
.screen { padding: 1rem; }
.home-card, .lobby-card { max-width: 440px; margin: 6vh auto; }
.home-card h1 { font-size: 1.6rem; }
.home-actions button, #btn-join { width: 100%; }
.sep { text-align: center; margin: 1rem 0; color: var(--muted); border-top: 1px solid var(--border); line-height: 0; }
.sep span { background: var(--card); padding: 0 .6rem; }
.lobby-players { list-style: none; padding: 0; margin: 0 0 1rem; }
.lobby-players li { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; }
.lobby-actions { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.color-picker { display: flex; flex-wrap: wrap; gap: .4rem; }
.color-swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; padding: 0; }
.color-swatch.mine { border-color: var(--ink); }
.color-swatch:disabled { opacity: .2; }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,.25); }

/* Barre du haut */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.turn { padding: .35rem .8rem; border-radius: 20px; background: var(--sand); font-weight: 600; }
.turn.mine { background: var(--accent); color: #fff; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(192,105,43,.25); } }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; }
.side .card { max-height: none; }

/* Piste */
.track { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)) minmax(0, 1.4fr); gap: 4px; }
.cell {
  position: relative; background: var(--sand); border-radius: 6px; min-height: 190px;
  display: flex; flex-direction: column; padding: 2px; border: 2px solid transparent;
}
.cell .num { text-align: center; font-weight: 700; font-size: .8rem; color: var(--muted); }
.cell .stack { flex: 1; display: flex; flex-direction: column-reverse; align-items: center; justify-content: flex-start; gap: 2px; padding-bottom: 2px; }
.cell.finish { background: repeating-linear-gradient(45deg, #fff, #fff 8px, #e9e1d0 8px, #e9e1d0 16px); }
.cell.finish .stack { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: flex-end; }
.cell.finish .sub { display: flex; flex-direction: column-reverse; gap: 2px; }
.cell.valid { border-color: var(--ok); background: #dff1df; cursor: pointer; }
.cell.valid:hover { background: #c4e6c4; }
.desert-tile {
  font-size: .7rem; text-align: center; border-radius: 5px; padding: 1px 0; margin-bottom: 2px; font-weight: 700; color: #fff;
}
.desert-tile.oasis { background: #3c9a5f; }
.desert-tile.mirage { background: #9a7b3c; }
.desert-tile .owner { display: block; font-weight: 400; font-size: .62rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.desert-hint { margin-top: .5rem; padding: .4rem .6rem; background: #dff1df; border-radius: 6px; }

.camel { width: 100%; max-width: 46px; height: 28px; position: relative; will-change: transform; }
.camel svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 1px 0 rgba(0,0,0,.35)); }
.camel.moving { transition: transform .7s cubic-bezier(.3,.7,.3,1) .45s; }
.camel.leader::after { content: "★"; position: absolute; top: -6px; right: -2px; font-size: .7rem; color: #b8860b; }

/* Banque */
.bank { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 1rem; }
.leg-stacks { display: flex; gap: .4rem; flex-wrap: wrap; }
.leg-stack {
  width: 46px; height: 56px; border-radius: 8px; color: #fff; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-weight: 800; font-size: 1.2rem; box-shadow: 0 3px 0 rgba(0,0,0,.25);
}
.leg-stack small { font-size: .62rem; font-weight: 500; opacity: .9; }
.leg-stack.empty { opacity: .3; }
.pyramid-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.pyramid {
  width: 70px; height: 60px; background: linear-gradient(135deg, #e7c77a, #b88a3a); clip-path: polygon(50% 0, 100% 100%, 0 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 4px; color: #fff; font-weight: 800;
}
.pyramid small { font-size: .5rem; font-weight: 500; }
.dice-rolled { display: flex; gap: .3rem; flex-wrap: wrap; }
.die {
  width: 32px; height: 32px; border-radius: 7px; display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #fff; box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); text-shadow: 0 1px 1px rgba(0,0,0,.4);
}
.die.rolling { animation: roll .55s ease-out; }
@keyframes roll {
  0% { transform: rotate(-200deg) scale(.3); opacity: 0; }
  70% { transform: rotate(15deg) scale(1.2); opacity: 1; }
  100% { transform: rotate(0) scale(1); }
}
.race-piles { display: flex; gap: .5rem; flex-wrap: wrap; }
.race-pile { background: var(--sand); border-radius: 8px; padding: .4rem .6rem; display: flex; flex-direction: column; align-items: center; min-width: 80px; }
.race-pile b { font-size: 1.3rem; }

/* Actions */
.actions.disabled .action-group { opacity: .55; }
.action-group { padding: .5rem 0; border-top: 1px dashed var(--border); }
.action-group:first-of-type { border-top: 0; }
.btn-row { display: flex; gap: .4rem; flex-wrap: wrap; margin: .3rem 0; }
.camel-btn { color: #fff; font-weight: 700; border: 0; min-width: 72px; text-shadow: 0 1px 1px rgba(0,0,0,.4); }
.camel-btn:hover:not(:disabled) { filter: brightness(1.1); background: inherit; }
.face-btn.selected { background: var(--sand); }

.bg-blue { background: var(--c-blue) !important; }
.bg-green { background: var(--c-green) !important; }
.bg-yellow { background: var(--c-yellow) !important; color: #3a3000 !important; text-shadow: none !important; }
.bg-red { background: var(--c-red) !important; }
.bg-purple { background: var(--c-purple) !important; }

/* Joueurs */
.players { list-style: none; padding: 0; margin: 0; }
.players li { padding: .5rem; border-radius: 8px; margin-bottom: .35rem; border: 1px solid var(--border); background: #fff; }
.players li.current { border: 2px solid var(--accent); background: #fff3e6; }
.players li.offline { opacity: .55; }
.p-head { display: flex; align-items: center; gap: .4rem; }
.p-name { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-money { font-weight: 800; }
.p-info { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .3rem; font-size: .78rem; align-items: center; }
.chip { border-radius: 5px; padding: 0 .35rem; color: #fff; font-weight: 700; font-size: .78rem; }
.tag { background: var(--sand); border-radius: 5px; padding: 0 .35rem; }

/* Journal */
.log { margin: 0; padding-left: 0; list-style: none; max-height: 340px; overflow-y: auto; font-size: .83rem; }
.log li { margin-bottom: .3rem; padding-bottom: .3rem; border-bottom: 1px dotted var(--border); }
.log li.leg-start { font-weight: 700; }

/* Fenêtre */
.modal { position: fixed; inset: 0; background: rgba(30,20,10,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal-box { background: var(--card); border-radius: 14px; padding: 1.2rem; max-width: 640px; width: 100%; max-height: 90vh; overflow-y: auto; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; margin-bottom: .8rem; }
th, td { text-align: left; padding: .3rem .4rem; border-bottom: 1px solid var(--border); }
.pos { color: var(--ok); font-weight: 700; }
.neg { color: var(--bad); font-weight: 700; }
.reveal { animation: reveal .4s ease-out both; }
@keyframes reveal { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.podium li { font-size: 1.05rem; margin: .2rem 0; }

.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 8px; z-index: 60; max-width: 90vw; }
.conn { position: fixed; top: 0; left: 0; right: 0; background: var(--bad); color: #fff; text-align: center; padding: .35rem; z-index: 70; }

/* Téléphone / petit écran */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .bank { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .screen { padding: .5rem; }
  .track { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .cell { min-height: 165px; }
  .camel { height: 24px; }
  .topbar { font-size: .9rem; }
  .cell.finish { grid-column: span 2; }
}
