/* Backgammon Cèdre : bois de cèdre, pointes terre cuite et encre, pions ivoire et ébène, safran en accent. */
:root {
  --bg: #1b1410;
  --surface: #2a1f18;
  --surface-2: #35281f;
  --line: #4a382a;
  --text: #f3eadb;
  --muted: #c4b39b;
  --accent: #e0a03a;
  --accent-ink: #1b1410;
  --terra: #a8462a;
  --ink: #24524f;
  --field: #e6d7b8;
  --frame: #3b2618;
  --danger: #e2735a;
  --title: "Baskerville", "Libre Baskerville", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  --ui: "Avenir Next", "Avenir", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--ui); font-size: 17px; line-height: 1.5; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#app { height: 100%; }
.screen { display: none; height: 100%; padding: calc(var(--sat) + 8px) calc(var(--sar) + 12px) calc(var(--sab) + 8px) calc(var(--sal) + 12px); }
.screen.active { display: flex; flex-direction: column; }

/* Boutons */
.btn { min-height: 48px; padding: 0 20px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; letter-spacing: .01em; cursor: pointer; transition: transform .12s, background .2s, opacity .2s; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 44px; padding: 0 14px; font-size: 15px; }
.btn[disabled] { opacity: .38; cursor: default; }
.btn[hidden] { display: none; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 10px; cursor: pointer; }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sound-toggle .cross { display: none; }
.sound-toggle[aria-pressed="true"] .cross { display: inline; }
.sound-toggle[aria-pressed="true"] .wave { display: none; }

/* Accueil */
#home { justify-content: center; align-items: center; }
.home-inner { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 40px; }
.brand-mark { width: 120px; height: 60px; display: block; margin-bottom: 18px; }
.brand h1 { font-family: var(--title); font-weight: 400; font-size: clamp(40px, 11vw, 60px); line-height: 1.02; margin: 0; letter-spacing: -.01em; }
.brand h1 span { display: block; font-style: italic; color: var(--accent); }
.tagline { color: var(--muted); margin: 14px 0 0; max-width: 32ch; }
.home-actions { display: flex; flex-direction: column; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.home-foot { display: flex; justify-content: space-between; align-items: center; color: var(--muted); }
.more-games { align-self: center; background: none; border: 0; padding: 10px 6px; min-height: 44px; color: var(--muted); font: inherit; font-size: 15px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.more-games[hidden] { display: none; }
.lang { display: flex; align-items: center; gap: 10px; font-size: 15px; }
select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-height: 44px; padding: 0 10px; }

/* Barre du haut */
.topbar { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.scoreline { flex: 1; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; min-width: 0; }
.pl { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 14px; padding: 4px 8px; border-radius: 8px; border: 1px solid transparent; }
.pl.turn { border-color: var(--accent); }
#pl0 { justify-content: flex-end; }
.pname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pscore { font-family: var(--title); font-size: 20px; }
.pip { color: var(--muted); font-size: 12px; white-space: nowrap; }
.chip { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; }
.chip.white { background: #f1e6cf; box-shadow: inset 0 0 0 2px #cbb88f; }
.chip.black { background: #1d1715; box-shadow: inset 0 0 0 2px #5b4a3c; }
.matchinfo { font-size: 12px; color: var(--muted); text-align: center; white-space: nowrap; }

/* Plateau */
.board-wrap { position: relative; flex: 1 1 0; overflow: hidden; min-height: 0; display: flex; align-items: center; justify-content: center; margin: 8px 0; }
.board-wrap { container-type: size; }
.board-box { position: relative; width: 100%; aspect-ratio: 5 / 4; }
#board { width: 100%; height: 100%; display: block; touch-action: none; }
.ck { transition: transform .34s cubic-bezier(.3,.7,.2,1); cursor: grab; }
.ck.drag { transition: none; cursor: grabbing; }
.ck.noanim { transition: none; }
.hl-src { stroke: var(--accent); stroke-width: 5; fill: none; }
.hl-dst { fill: rgba(224,160,58,.5); stroke: #f0b04a; stroke-width: 5; }
.hit:focus { outline: none; }
.hit:focus-visible .focusring { stroke: #fff; stroke-width: 4; stroke-dasharray: 10 6; }

/* Dés 3D */
.dice { position: absolute; top: 50%; display: flex; gap: 14px; transform: translateY(-50%); pointer-events: none; }
.dice.right { left: 68.4%; transform: translate(-50%, -50%); }
.dice.left { left: 21.8%; transform: translate(-50%, -50%); }
.die { --s: clamp(30px, 6.2vmin, 56px); width: var(--s); height: var(--s); perspective: 400px; }
.die.used { opacity: .35; }
.die .cube3 { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform .9s cubic-bezier(.2,.8,.25,1); }
.die .face { position: absolute; inset: 0; border-radius: 18%; background: #f6efe0; box-shadow: inset 0 0 0 1px #cdbb95, inset 0 -3px 0 rgba(0,0,0,.08); display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 14%; backface-visibility: hidden; }
.die.dark .face { background: #241c18; box-shadow: inset 0 0 0 1px #5b4a3c; }
.die .pip-d { width: 70%; height: 70%; margin: auto; border-radius: 50%; background: #2a1a12; }
.die.dark .pip-d { background: #e0a03a; }
.die .f1 { transform: rotateY(0deg) translateZ(calc(var(--s) / 2)); }
.die .f2 { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.die .f3 { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.die .f4 { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
.die .f5 { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.die .f6 { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }

/* Cube */
.cube { position: absolute; left: 45.1%; transform: translate(-50%, -50%); width: 6.4%; aspect-ratio: 1; border-radius: 8px; border: 0; display: grid; place-items: center; background: #efe4cc; color: #2a1a12; font-family: var(--title); font-size: clamp(16px, 3vmin, 22px); font-weight: 700; box-shadow: 0 2px 0 #a99572; transition: top .4s; pointer-events: none; }
.cube.c-mid { top: 50%; }
.cube.c-top { top: 12%; }
.cube.c-bot { top: 88%; }

.toast { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(27,20,16,.92); color: var(--text); padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); font-weight: 600; opacity: 0; transition: opacity .25s; pointer-events: none; text-align: center; max-width: 80%; }
.toast.show { opacity: 1; }

/* Bas */
.controls { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; }
.status { margin: 0; min-height: 1.5em; text-align: center; color: var(--muted); font-size: 15px; }
.ctl-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.ctl-btns .btn { flex: 1 1 0; max-width: 220px; }

.tutobox { flex: 0 0 auto; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; }
.tutobox p { margin: 0 0 10px; font-size: 16px; }
.tuto-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Fenêtres */
.modal { position: fixed; inset: 0; background: rgba(10,7,5,.66); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal[hidden] { display: none; }
.sheet { width: 100%; max-width: 480px; max-height: 88vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px; -webkit-user-select: text; user-select: text; }
.sheet h2 { font-family: var(--title); font-weight: 400; font-size: 28px; margin: 0 0 14px; line-height: 1.15; }
.sheet p, .sheet li { color: var(--text); max-width: 66ch; }
.sheet .muted { color: var(--muted); }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1 1 140px; }
fieldset { border: 0; padding: 0; margin: 0 0 16px; }
legend { font-weight: 600; margin-bottom: 8px; color: var(--muted); font-size: 14px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 22px; cursor: pointer; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.stats-grid { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin: 0; }
.stats-grid dt { color: var(--muted); }
.stats-grid dd { margin: 0; font-family: var(--title); font-size: 20px; text-align: right; }
.rules h3 { font-family: var(--title); font-weight: 400; font-size: 20px; margin: 18px 0 4px; }
.rules p { margin: 0 0 8px; }

/* Paysage : plateau à gauche, commandes à droite */
@media (orientation: landscape) and (max-height: 620px) {
  #game { display: none; }
  #game.active { display: grid; grid-template-columns: 1fr minmax(180px, 230px); grid-template-rows: auto 1fr auto; column-gap: 12px; }
  #game .topbar { grid-column: 1 / 3; }
  #game .board-wrap { grid-column: 1; grid-row: 2 / 4; margin: 4px 0 0; }
  #game .tutobox { grid-column: 2; grid-row: 2; align-self: start; }
  #game .controls { grid-column: 2; grid-row: 3; }
  #game .ctl-btns { flex-direction: column; }
  #game .ctl-btns .btn { max-width: none; flex: 0 0 auto; }
  .home-inner { max-width: 760px; display: grid; grid-template-columns: 1fr 1fr; gap: 24px 40px; align-items: center; }
  .home-foot { grid-column: 1 / 3; }
}
@media (min-width: 900px) and (min-height: 700px) {
  html, body { font-size: 18px; }
  .pl { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .ck, .die .cube3, .cube { transition: none !important; }
}
@media (max-width: 520px) {
  .scoreline { grid-template-columns: 1fr 1fr; }
  .matchinfo { display: none; }
  .pl { flex-wrap: wrap; gap: 0 6px; padding: 2px 6px; font-size: 13px; }
  .pip { flex-basis: 100%; }
  #pl0 { text-align: right; }
  #pl0 .pip { text-align: right; }
}

/* ---------- Ajouts : en ligne, tournoi, analyse ---------- */
.online-btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
.online-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 1.6; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.small { font-size: 14px; }
.sheet h3.sub, h3.sub { font-family: var(--title); font-weight: 400; font-size: 19px; margin: 18px 0 6px; }

#online { overflow-y: auto; align-items: center; }
.ol-inner { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 14px; padding-bottom: 12px; }
.ol-head { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 6px; }
.ol-head h2 { font-family: var(--title); font-weight: 400; font-size: 30px; margin: 0; }
.ol-conn { grid-column: 1 / 3; min-height: 1.4em; font-size: 14px; color: var(--muted); }
.ol-conn.warn { color: var(--danger); }
#ol-body { display: flex; flex-direction: column; gap: 14px; }
#ol-body[hidden] { display: none; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.card[hidden] { display: none; }
.card h3 { margin: 0; font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.card p { margin: 0; }
.me { display: flex; gap: 14px; align-items: center; }
.me-txt { flex: 1; min-width: 0; }
.me input, .join input { width: 100%; font: inherit; font-weight: 600; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; min-height: 44px; padding: 0 12px; -webkit-user-select: text; user-select: text; }
.me .muted, .card .muted { color: var(--muted); font-size: 14px; }
.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; flex: 0 0 auto; border-radius: 50%; }
.avatar svg { width: 100%; height: 100%; display: block; }
.avatar.big { width: 64px; height: 64px; }
.avatar.sm { width: 26px; height: 26px; }
.avatars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.avatar.pick { width: 100%; height: auto; aspect-ratio: 1; min-height: 34px; padding: 0; border: 2px solid transparent; background: none; cursor: pointer; }
.avatar.pick[aria-checked="true"] { border-color: var(--accent); }
#ol-save { align-self: flex-start; }
.ol-priv { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 480px) { .ol-priv { grid-template-columns: 1fr 1.3fr; } }
.join { display: flex; gap: 8px; }
.join input { text-transform: uppercase; letter-spacing: .2em; text-align: center; min-width: 0; }
.ol-wait { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.ol-wait[hidden] { display: none; }
#ol-search { flex-direction: row; align-items: center; flex-wrap: wrap; }
#ol-search p { flex: 1; }
.code { font-family: var(--title); font-size: 26px; letter-spacing: .18em; color: var(--accent); }
.ol-note { color: var(--muted); font-size: 13px; margin: 0; }
.spinner { display: inline-block; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn[hidden] { display: none; }

/* En partie en ligne */
.clock { font-variant-numeric: tabular-nums; color: var(--muted); }
.clock.urgent { color: var(--danger); font-weight: 600; }
.emote-pop { position: absolute; z-index: 40; right: calc(var(--sar) + 12px); top: calc(var(--sat) + 56px); width: min(320px, calc(100vw - 24px)); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-wrap: wrap; gap: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.emote-pop[hidden] { display: none; }
.em { min-height: 40px; padding: 0 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-size: 14px; }
.em.emo { font-size: 20px; padding: 0 8px; }
#game { position: relative; }
.bubble { position: absolute; left: 4%; background: #f3eadb; color: #2a1a12; border-radius: 14px; padding: 6px 12px; font-weight: 600; font-size: 15px; opacity: 0; transform: scale(.9); transition: opacity .2s, transform .2s; pointer-events: none; max-width: 40%; z-index: 5; }
.bubble.emo { font-size: 26px; padding: 2px 10px; }
.bubble.b1 { top: 6%; }
.bubble.b0 { bottom: 6%; }
.bubble.show { opacity: 1; transform: none; }

/* Analyse */
.inline-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.an-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.an-table th, .an-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; }
.an-table th[scope="row"] { text-align: left; color: var(--muted); font-weight: 400; }
.an-table thead th { font-weight: 600; overflow: hidden; text-overflow: ellipsis; max-width: 8em; white-space: nowrap; }
.pipchart { width: 100%; height: auto; background: var(--bg); border-radius: 8px; border: 1px solid var(--line); }
.pipchart polyline { fill: none; stroke-width: 2.2; stroke-linejoin: round; }
.pipchart .pc0 { stroke: #efe4cc; }
.pipchart .pc1 { stroke: var(--terra); }
.legend { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.worst { padding-left: 1.2em; margin: 0; }
.worst li { margin-bottom: 8px; font-size: 15px; }
.sheet .small { font-size: 13px; }

/* Tournoi */
.bracket { display: flex; flex-direction: column; gap: 4px; }
.br-match { display: flex; gap: 8px; align-items: baseline; margin: 2px 0; font-size: 15px; }
.br-match .vs { color: var(--muted); }
.br-match .win { font-weight: 700; }
.br-match .lose { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(196,179,155,.5); }
.br-match .me { color: var(--accent); }
.champ { font-family: var(--title); font-size: 20px; color: var(--accent); }

/* Classement */
.lb { list-style: none; padding: 0; margin: 0 0 12px; }
.lb li { display: grid; grid-template-columns: 2.2em 30px 1fr auto; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.lb li.me { color: var(--accent); }
.lb .rk { color: var(--muted); text-align: right; }
.lb .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .sc { font-family: var(--title); }
@media (orientation: landscape) and (max-height: 620px) {
  .ol-inner { max-width: 760px; }
}
