:root {
  --parch: #f4ecd8;
  --parch-2: #e9dcbc;
  --parch-3: #d8c59a;
  --ink: #3b2a1a;
  --ink-soft: #6d5a43;
  --gold: #c99a22;
  --gold-d: #7d5e0e;
  --felt: #20372c;
  --felt-2: #2b4a3a;
  --accent: #ffd75e;
  --danger: #b3261e;
  --radius: 10px;
  --shadow: 0 6px 18px rgba(30, 20, 5, .25);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: var(--parch-2) radial-gradient(circle at 20% 10%, #f8f1df 0, transparent 60%);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.hidden, [hidden] { display: none !important; }
.muted { color: var(--ink-soft); font-size: .9em; }

/* ---------- Textes dans les SVG ---------- */
.pts { font-family: "Cormorant Garamond", Georgia, serif; font-weight: 700; font-size: 16px; fill: var(--ink); }
.pts.big { font-size: 20px; }
.tnum { font-family: "Cormorant Garamond", Georgia, serif; font-weight: 700; font-size: 17px; fill: var(--ink); }
.tnum.big { font-size: 21px; }
.tpawn { font-family: "Nunito", sans-serif; font-weight: 800; font-size: 9px; fill: #fff; }

.card-svg, .card-img { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; border-radius: 6%/9%; }
.card-svg { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .35)); overflow: visible; }

/* ---------- Boutons ---------- */
.btn {
  border: 1px solid var(--gold-d); background: linear-gradient(#fbf3dd, #ead9ae); color: var(--ink);
  padding: .55em 1.1em; border-radius: 8px; cursor: pointer; font-weight: 700;
  box-shadow: 0 2px 0 var(--gold-d);
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--gold-d); }
.btn.primary { background: linear-gradient(#f2d36c, #cf9f25); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: .3em .7em; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--gold-d);
  background: var(--parch); cursor: pointer; font-weight: 800; font-size: 16px; line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.icon-btn:hover { background: #fff8e6; }

/* ---------- Salon ---------- */
.screen { min-height: 100%; }
#lobby, #waiting { display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 40px; }
.lobby-box { width: 100%; max-width: 760px; text-align: center; }
.title { font-family: "UnifrakturMaguntia", serif; font-weight: 400; font-size: clamp(42px, 8vw, 72px); margin: 0; color: var(--ink); text-shadow: 0 2px 0 #fff8e6; }
.subtitle { font-family: "Cormorant Garamond", serif; font-size: 22px; margin: 0 0 28px; color: var(--ink-soft); }
#lobby-main { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.panel {
  background: var(--parch); border: 2px solid var(--gold); border-radius: var(--radius);
  padding: 20px 22px; text-align: left; box-shadow: var(--shadow); margin-bottom: 18px;
  outline: 1px solid var(--parch-3); outline-offset: -7px;
}
.panel h2 { font-family: "Cormorant Garamond", serif; font-size: 26px; margin: 0 0 14px; }
.panel label { display: block; font-weight: 700; margin-bottom: 14px; font-size: 14px; }
.panel input, .panel select {
  display: block; width: 100%; margin-top: 5px; padding: .55em .7em; border: 1px solid var(--parch-3);
  border-radius: 7px; background: #fffaf0;
}
.h-invite { font-weight: 800; color: var(--gold-d); font-size: 17px; margin: -4px 0 14px; }
.share { display: flex; gap: 8px; margin-bottom: 16px; }
.share input { flex: 1; padding: .55em .7em; border: 1px solid var(--parch-3); border-radius: 7px; background: #fffaf0; min-width: 0; }
.plist, .recent { list-style: none; padding: 0; margin: 0; }
.plist li, .recent li { padding: 6px 0; border-bottom: 1px dashed var(--parch-3); }
.recent a { color: var(--gold-d); font-weight: 700; }

/* ---------- Partie ---------- */
#game { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 6px 14px; flex: none;
  background: linear-gradient(#f7efda, #e7d7ae); border-bottom: 2px solid var(--gold);
}
.brand { font-family: "UnifrakturMaguntia", serif; font-size: 26px; white-space: nowrap; }
.status { flex: 1; text-align: center; font-weight: 700; font-size: 16px; }
.status .you { background: var(--accent); padding: 1px 8px; border-radius: 6px; }
.status .endflag { margin-left: 10px; color: #fff; background: var(--danger); padding: 2px 9px; border-radius: 6px; font-size: 13px; }
.top-actions { display: flex; gap: 6px; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 230px minmax(0, 1fr) 270px; }
.left, .right { overflow-y: auto; padding: 10px; background: rgba(255, 250, 235, .45); }
.left { border-right: 1px solid var(--parch-3); }
.right { border-left: 1px solid var(--parch-3); display: flex; flex-direction: column; gap: 10px; }
.block h3 { font-family: "Cormorant Garamond", serif; font-size: 18px; margin: 8px 0 6px; }
.track-wrap { width: 168px; margin: 0 auto 6px; }
.track { display: block; width: 100%; height: auto; filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .25)); }
.objs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ocard { cursor: help; }

.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.players { display: flex; gap: 8px; padding: 8px 10px; overflow-x: auto; flex: none; }
.pchip {
  background: var(--parch); border: 1px solid var(--parch-3); border-radius: 9px; padding: 6px 10px;
  cursor: pointer; min-width: 210px; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); position: relative;
}
.pchip.active { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.pchip.turn::after {
  content: "à son tour"; position: absolute; top: -8px; right: 8px; background: var(--accent);
  font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 6px; text-transform: uppercase;
}
.pline { display: flex; align-items: center; gap: 6px; }
.pawn-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .3); flex: none; }
.first { background: #222; color: #fff; font-size: 10px; border-radius: 6px; padding: 0 5px; font-weight: 800; }
.score { margin-left: auto; font-weight: 800; }
.botlvl { background: var(--parch-3); font-size: 10px; font-weight: 800; border-radius: 6px; padding: 0 5px; text-transform: uppercase; }
.syms { display: flex; gap: 7px; margin-top: 4px; font-size: 13px; font-weight: 700; }
.syms span { display: inline-flex; align-items: center; gap: 1px; }
.mini-hand { display: flex; gap: 3px; margin-top: 4px; }
.mini { width: 36px; display: block; }

.board-viewport {
  flex: 1; min-height: 200px; position: relative; overflow: hidden; cursor: grab; touch-action: none;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 255, 255, .06), transparent 70%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .015) 0 2px, transparent 2px 6px),
    var(--felt);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, .5);
}
.board-viewport.dragging { cursor: grabbing; }
.board-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.bcard { position: absolute; width: 150px; }
.bcard.last .card-svg { filter: drop-shadow(0 0 5px var(--accent)) drop-shadow(0 0 2px var(--accent)); }
.bpawn {
  position: absolute; width: 18px; height: 18px; border-radius: 50%; z-index: 1; pointer-events: none;
  border: 2px solid rgba(255, 255, 255, .9); box-shadow: 0 3px 4px rgba(0, 0, 0, .45), inset 0 -4px 6px rgba(0, 0, 0, .25);
}
.bpawn.black { background: #1b1b1b; }
.slot {
  position: absolute; width: 150px; height: 100px; z-index: 5000; cursor: pointer; border-radius: 9px;
  border: 2px dashed rgba(255, 236, 170, .85); background: rgba(255, 236, 170, .1);
  animation: glow 1.6s ease-in-out infinite;
}
.slot.bad { border-color: rgba(255, 120, 110, .9); background: rgba(255, 80, 70, .08); cursor: not-allowed; }
.slot .ghost { opacity: 0; transition: opacity .12s; pointer-events: none; }
.slot:hover .ghost { opacity: .9; }
.slot:hover { animation: none; border-color: transparent; background: none; }
@keyframes glow { 50% { background: rgba(255, 236, 170, .22); } }
.board-tools { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 6000; }
.board-hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 6000; pointer-events: none;
  background: rgba(20, 30, 25, .85); color: #f7efda; padding: 5px 14px; border-radius: 16px; font-size: 14px; white-space: nowrap;
}

.hand-bar { flex: none; background: linear-gradient(#e9dcbc, #dccb9f); border-top: 2px solid var(--gold); padding: 16px 10px 22px; }
.hand { display: flex; gap: 22px; justify-content: center; align-items: flex-end; min-height: 128px; flex-wrap: wrap; }
.hcard { width: 186px; position: relative; cursor: pointer; transition: transform .15s; border-radius: 10px; }
.hcard:hover { transform: translateY(-4px); }
.hcard.sel { transform: translateY(-10px); box-shadow: 0 0 0 3px var(--accent), 0 10px 22px rgba(0, 0, 0, .35); }
.hcard.unmet .card-svg { filter: grayscale(.45) drop-shadow(0 2px 3px rgba(0, 0, 0, .35)); }
.flip {
  position: absolute; left: 50%; bottom: -15px; transform: translateX(-50%); width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--gold-d); background: var(--parch); cursor: pointer; font-size: 17px; font-weight: 800; line-height: 1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
}
.flip:hover { background: var(--accent); }
.badge {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%); background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 10px; white-space: nowrap; pointer-events: none;
}
.hand-wait { width: 100%; text-align: center; margin: 4px 0 0; color: var(--ink-soft); }

.market-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.mcard { position: relative; border-radius: 8px; transition: transform .12s; }
.mcard.empty { aspect-ratio: 3 / 2; border: 2px dashed var(--parch-3); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--ink-soft); }
.mcard.drawable { cursor: pointer; box-shadow: 0 0 0 2px var(--accent); }
.mcard.drawable:hover { transform: translateY(-3px) scale(1.04); }
.market.active h3::after { content: " · cliquez pour prendre"; font-family: "Nunito"; font-size: 12px; color: var(--gold-d); }
.count {
  position: absolute; right: -4px; bottom: -4px; background: var(--ink); color: #fff; font-size: 11px; font-weight: 800;
  border-radius: 9px; padding: 1px 6px;
}
.journal { flex: 1; display: flex; flex-direction: column; min-height: 200px; }
.log { flex: 1; overflow-y: auto; background: #fffaf0; border: 1px solid var(--parch-3); border-radius: 8px; padding: 6px 8px; font-size: 13px; min-height: 120px; }
.logline { padding: 3px 0; border-bottom: 1px dotted var(--parch-3); }
.chatline { padding: 4px 6px; margin: 3px 0; background: #f3e9cf; border-radius: 6px; }
.chat { display: flex; gap: 6px; margin-top: 6px; }
.chat input { flex: 1; min-width: 0; padding: .4em .6em; border: 1px solid var(--parch-3); border-radius: 7px; background: #fffaf0; }

/* ---------- Fenêtres ---------- */
.modal { position: fixed; inset: 0; background: rgba(25, 18, 8, .55); z-index: 8000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box {
  background: var(--parch); border: 3px solid var(--gold); border-radius: 12px; padding: 20px 24px; width: 100%; max-width: 980px;
  max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .4); outline: 1px solid var(--parch-3); outline-offset: -8px;
}
.modal-box.wait, .modal-box.rules { max-width: 560px; }
.modal-box.wait { text-align: center; }
.modal-box h2 { font-family: "Cormorant Garamond", serif; font-size: 30px; margin: 0 0 12px; }
.modal-box h3 { font-size: 15px; margin: 0 0 4px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 26px; }
.setup-grid section { background: rgba(255, 255, 255, .35); border-radius: 9px; padding: 10px 12px; }
.choices { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.choice {
  border: 2px solid transparent; background: none; border-radius: 10px; padding: 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 700; text-transform: capitalize;
}
.choice:hover:not(:disabled) { background: rgba(255, 255, 255, .5); }
.choice.on { border-color: var(--gold); background: #fff6d8; box-shadow: 0 0 0 2px var(--accent); }
.choice:disabled { opacity: .3; cursor: not-allowed; }
.choice .sc { width: 160px; }
.colors .choice { width: 74px; }
.pawn-big { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, .4), inset 0 -5px 7px rgba(0, 0, 0, .25); }
.info .row { display: flex; gap: 8px; margin-bottom: 10px; }
.info .sc { width: 110px; }
.spinner { width: 34px; height: 34px; margin: 10px auto; border: 4px solid var(--parch-3); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.win { text-align: center; }
.results { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
.results th, .results td { padding: 8px 6px; border-bottom: 1px solid var(--parch-3); text-align: center; vertical-align: middle; }
.results th { font-size: 12px; text-transform: uppercase; color: var(--ink-soft); }
.results tr.winner { background: #fff3c4; }
.results .tot { font-size: 22px; font-weight: 800; }
.robj { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.mini-obj { width: 78px; display: block; }
.rules p { line-height: 1.5; margin: 0 0 10px; }

.preview { position: fixed; width: 330px; z-index: 9000; pointer-events: none; filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .45)); }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #2a1e10; color: #fbf3dd; z-index: 9500;
  padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); font-weight: 600;
}

/* ---------- Écrans étroits ---------- */
@media (max-width: 1100px) {
  #game { height: auto; min-height: 100vh; }
  .layout { grid-template-columns: 1fr; }
  .center { order: 1; }
  .board-viewport { height: 60vh; flex: none; }
  .left { order: 2; display: flex; gap: 16px; flex-wrap: wrap; border: 0; }
  .left .block { flex: 1; min-width: 240px; }
  .right { order: 3; border: 0; }
  .hcard { width: 150px; }
  .setup-grid { grid-template-columns: 1fr; }
  .brand { display: none; }
}
@media (max-width: 600px) {
  .hcard { width: 30vw; }
  .hand { gap: 10px; }
  .choice .sc { width: 130px; }
  .status { font-size: 14px; }
}
