:root { padding-top: env(safe-area-inset-top, 0px); }
/* Mise en page : plateau plein écran, barre de scores en haut, dock de la tuile en bas.
   Palette : ardoise verte (table), laiton (accent), pierre claire (texte). Thème sombre unique, voulu. */
:root {
  --table: #1b2427;
  --table-2: #26343a;
  --panel: #2c3b41;
  --panel-2: #354a51;
  --line: #44595f;
  --ink: #edf1e8;
  --muted: #a3b4b0;
  --brass: #e0b24a;
  --brass-ink: #2b2108;
  --danger: #d9705c;
  --display: 'IM Fell English SC', Georgia, 'Times New Roman', serif;
  --body: 'Alegreya Sans', 'Trebuchet MS', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--table); color: var(--ink);
  font-family: var(--body); font-size: 16px; line-height: 1.35; overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }

#app { height: 100%; display: flex; flex-direction: column; }

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; background: var(--table-2); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 26px; height: 26px; flex: none; }
.brand h1 { font-family: var(--display); font-weight: 400; font-size: 1.5rem; letter-spacing: .06em; margin: 0; color: var(--brass); }
.bar__meta { color: var(--muted); font-size: .9rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar__meta b { color: var(--ink); font-weight: 700; }
.bar__btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.ghost {
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  padding: 0 12px; min-height: 40px; color: var(--ink); font-weight: 600; font-size: .92rem;
}
.ghost:hover { background: var(--panel); }

.scores {
  display: flex; gap: 8px; padding: 8px 16px; overflow-x: auto; background: var(--table);
  border-bottom: 1px solid var(--line); scrollbar-width: thin;
}
.chip {
  flex: 1 0 128px; max-width: 220px; display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; align-items: center;
  padding: 7px 12px; border-radius: 10px; background: var(--panel); border: 2px solid transparent;
}
.chip--cur { border-color: var(--brass); background: var(--panel-2); }
.chip__pawn { grid-row: span 2; width: 26px; height: 30px; }
.chip__name { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip__ai { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-left: 6px; font-weight: 600; }
.chip__score { grid-row: span 2; font-family: var(--display); font-size: 1.7rem; line-height: 1; font-variant-numeric: tabular-nums; }
.chip__dots { display: flex; gap: 3px; }
.chip__dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--dot); }
.chip__dots i.off { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }

.stage { position: relative; flex: 1 1 0; min-height: 0; overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #2d3f45 0%, var(--table) 75%); }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; display: block; }
#board:active { cursor: grabbing; }
.toast {
  position: absolute; left: 50%; bottom: 14px; transform: translate(-50%, 8px); max-width: min(92%, 520px);
  background: rgba(20,28,30,.94); border: 1px solid var(--brass); border-radius: 10px; padding: 8px 14px;
  text-align: center; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast--on { opacity: 1; transform: translate(-50%, 0); }

.dock {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--table-2); border-top: 1px solid var(--line); flex-wrap: wrap;
}
.dock__tile { padding: 0; border: 2px solid var(--brass); border-radius: 8px; background: var(--panel); width: 68px; height: 68px; flex: none; overflow: hidden; }
.dock__tile canvas { width: 100%; height: 100%; display: block; }
.dock__tile:disabled { opacity: .45; border-color: var(--line); }
.dock__info { flex: 1 1 160px; min-width: 0; }
.dock__title { margin: 0; font-weight: 700; font-size: 1.05rem; }
.dock__hint { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.dock__actions { display: flex; gap: 8px; flex: 0 1 auto; }
.btn {
  min-height: 46px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); font-weight: 700;
}
.btn:hover:not(:disabled) { background: var(--panel-2); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn--gold { background: var(--brass); color: var(--brass-ink); border-color: var(--brass); }
.btn--gold:hover:not(:disabled) { background: #edc15f; }

.sheet {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(10,16,18,.78); overflow-y: auto;
}
.sheet__panel {
  width: min(100%, 520px); max-height: 100%; overflow-y: auto; background: var(--table-2);
  border: 1px solid var(--line); border-radius: 14px; padding: 22px 20px;
}
.sheet h2 { font-family: var(--display); font-weight: 400; font-size: 1.7rem; letter-spacing: .05em; margin: 0 0 4px; color: var(--brass); }
.sheet p.lede { margin: 0 0 16px; color: var(--muted); }
.seats { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.seat { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.seat svg { width: 26px; height: 30px; }
.seat input {
  min-width: 0; min-height: 44px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--table); color: var(--ink); padding: 0 12px; font: inherit; font-weight: 600;
}
.seat .toggle { min-height: 44px; min-width: 112px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); font-weight: 600; }
.seat .toggle[data-ai="1"] { border-color: var(--brass); color: var(--brass); }
.sheet__row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.sheet__row .count { color: var(--muted); font-size: .92rem; }
.rules-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.rules-list b { color: var(--brass); }
.rank { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rank li { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 10px; background: var(--panel); }
.rank li:first-child { border: 2px solid var(--brass); }
.rank .pos { font-family: var(--display); font-size: 1.3rem; color: var(--brass); }
.rank .pts { font-family: var(--display); font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.sheet__actions { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 520px) {
  .brand h1 { font-size: 1.25rem; }
  .bar__meta { display: none; }
  .dock { gap: 10px; }
  .dock__actions { width: 100%; }
  .dock__actions .btn { flex: 1; }
  .dock__hint { font-size: .85rem; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
[hidden] { display: none !important; }
@media (max-width: 520px) { .bar { gap: 8px; } .bar__btns { flex-wrap: nowrap; } .ghost { padding: 0 9px; font-size: .86rem; } }
.tips {
  position: absolute; top: 10px; left: 12px; right: 12px; max-width: 440px; z-index: 3;
  background: rgba(28,40,44,.95); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px 12px;
  font-size: .92rem; box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.tips p { margin: 4px 0 0; }
.tips__head { display: flex; align-items: center; justify-content: space-between; }
.tips__head b { font-family: var(--display); font-weight: 400; letter-spacing: .06em; color: var(--brass); font-size: 1.05rem; }
.tips__x { width: 36px; height: 36px; border-radius: 8px; border: 0; background: transparent; font-size: 1.4rem; line-height: 1; color: var(--muted); }
.tips__move { color: #bfe6c2; font-weight: 600; }
.btn--sm { min-height: 38px; padding: 0 14px; font-size: .9rem; margin-top: 8px; }
#btnTips[aria-pressed="true"] { border-color: var(--brass); color: var(--brass); }
@media (max-width: 520px) { .dock__actions { flex-wrap: wrap; } .dock__actions .btn { padding: 0 10px; } }

.foot { margin: 16px 0 0; color: var(--muted); font-size: .8rem; text-align: center; }
.screen { position: fixed; inset: 0; z-index: 12; background: var(--table); overflow-y: auto; padding: 0 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
.screen__in { max-width: 560px; margin: 0 auto; padding-top: 14px; }
.screen__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.screen__head h2 { font-family: var(--display); font-weight: 400; letter-spacing: .05em; font-size: 1.6rem; margin: 0; color: var(--brass); }
.ct-muted { color: var(--muted); font-size: .9rem; margin: 6px 0; }
.ct-intro { margin: 8px 0 14px; }
.ct-players { display: flex; flex-direction: column; gap: 8px; }
.ct-player { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 6px; background: var(--panel); border: 2px solid transparent; border-radius: 12px; padding: 4px 14px 4px 4px; }
.ct-player.is-sel { border-color: var(--brass); background: var(--panel-2); }
.ct-pick { width: 48px; height: 48px; border: 0; background: transparent; border-radius: 10px; display: grid; place-items: center; }
.ct-name { min-width: 0; min-height: 44px; border: 0; background: transparent; color: var(--ink); font: inherit; font-weight: 700; font-size: 1.05rem; }
.ct-score { font-family: var(--display); font-size: 2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.ct-player.is-lead .ct-score { color: var(--brass); }
.ct-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0 14px; }
.ct-card { background: var(--table-2); border: 1px solid var(--line); border-radius: 14px; padding: 14px 14px 16px; margin-bottom: 14px; }
.ct-card h3 { margin: 0 0 10px; font-family: var(--display); font-weight: 400; letter-spacing: .05em; font-size: 1.2rem; color: var(--brass); }
.ct-row h3 { margin: 0; }
.ct-seg { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.ct-tab { flex: 1 1 auto; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-weight: 600; padding: 0 12px; }
.ct-tab.on { background: var(--brass); color: var(--brass-ink); border-color: var(--brass); }
.ct-step { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; }
.ct-step__l { font-weight: 600; }
.ct-step__c { display: flex; align-items: center; gap: 12px; }
.ct-step output { min-width: 2.4ch; text-align: center; font-family: var(--display); font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.ct-b { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-size: 1.5rem; line-height: 1; }
.ct-b:active { background: var(--panel-2); }
.ct-sum { display: flex; align-items: baseline; justify-content: space-between; margin: 10px 0 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.ct-sum b { font-family: var(--display); font-size: 2.2rem; font-weight: 400; color: var(--brass); font-variant-numeric: tabular-nums; }
.ct-add { width: 100%; }
.ct-log { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ct-log li { display: grid; grid-template-columns: minmax(0, 7.5rem) minmax(0, 1fr) auto auto; align-items: center; gap: 8px; background: var(--panel); border-radius: 10px; padding: 6px 6px 6px 10px; font-size: .92rem; }
.ct-log__p { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 700; }
.ct-log__n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-log__d { color: var(--muted); min-width: 0; }
.ct-log__pts { font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.ct-x { width: 40px; height: 40px; border: 0; background: transparent; color: var(--muted); font-size: 1.3rem; border-radius: 8px; }
.ct-foot { display: flex; justify-content: center; padding: 6px 0 10px; }
@media (max-width: 420px) { .ct-log li { grid-template-columns: minmax(0, 5.5rem) minmax(0, 1fr) auto auto; font-size: .86rem; } }
.ct-row > span:last-child { flex: none; white-space: nowrap; }
.ct-seg .ct-tab { flex: 1 1 0; min-width: 0; padding: 0 6px; }
.ct-seg--2 .ct-tab { flex: 1 1 40%; }

/* Pas de zoom au double-tap : le zoom du plateau se fait au pincement ou à la molette */
* { touch-action: manipulation; }
#board { touch-action: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input { -webkit-user-select: text; user-select: text; }

/* ---- Page d'accueil ---- */
.home { position: fixed; inset: 0; z-index: 8; overflow-y: auto; background: radial-gradient(ellipse at 50% 30%, #2d3f45 0%, var(--table) 72%); }
.home[hidden] { display: none; }
.home__in { min-height: 100%; box-sizing: border-box; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: calc(24px + env(safe-area-inset-top, 0px)) 16px calc(20px + env(safe-area-inset-bottom, 0px)); max-width: 420px; margin: 0 auto; }
.home__tower { width: min(40vw, 150px); height: auto; overflow: visible; flex: none; }
.home-a { transform-box: fill-box; transform-origin: 50% 100%; opacity: 0; animation: spRise .7s cubic-bezier(.2,.8,.25,1) forwards; }
.home-a.sp-a1 { animation-delay: .1s; } .home-a.sp-a2 { animation-delay: .3s; } .home-a.sp-a3 { animation-delay: .5s; transform-origin: 50% 50%; }
@keyframes spRise { from { opacity: 0; transform: translateY(26px) scaleY(.6); } to { opacity: 1; transform: none; } }
.home__title { margin: 6px 0 0; font-family: var(--display); font-weight: 400; font-size: 2.8rem; letter-spacing: .12em; color: var(--brass); text-align: center; }
.home__tag { margin: 0 0 18px; color: var(--muted); letter-spacing: .04em; text-align: center; }
.home__menu { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.btn--big { width: 100%; min-height: 52px; font-size: 1.05rem; }
.home .foot { margin-top: 22px; }

/* ---- Pastille de pioche, à côté des joueurs ---- */
.chip--deck { flex: none; max-width: none; position: sticky; left: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 7px 12px; background: var(--table-2); border-color: var(--line); }
.chip--deck svg { width: 24px; height: 28px; flex: none; }
.chip__deckn { font-family: var(--display); font-size: 1.7rem; line-height: 1; font-variant-numeric: tabular-nums; }
.chip__decklbl { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); line-height: 1.1; }
.chip--deck.is-low .chip__deckn { color: var(--danger); }

/* ---- Confidentialité ---- */
.sheet__panel--wide { width: min(100%, 640px); }
.linkbtn { background: none; border: 0; padding: 4px 2px; color: var(--muted); text-decoration: underline; font-size: inherit; min-height: 32px; }
.policy h3 { font-family: var(--display); font-weight: 400; letter-spacing: .05em; color: var(--brass); font-size: 1.1rem; margin: 14px 0 4px; }
.policy p, .policy li { margin: 4px 0; font-size: .95rem; }
.policy ul { padding-left: 18px; margin: 4px 0; }
.policy { -webkit-user-select: text; user-select: text; }

/* ---- Partie en ligne ---- */
.ol-field { display: block; font-weight: 700; margin-bottom: 6px; }
#olName { width: 100%; min-height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--table); color: var(--ink); padding: 0 12px; font: inherit; font-weight: 600; }
.ol-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 16px; }
.ol-steps textarea { display: block; width: 100%; margin: 8px 0; border-radius: 8px; border: 1px solid var(--line); background: var(--table); color: var(--ink); padding: 8px 10px; font: .8rem/1.3 ui-monospace, Menlo, Consolas, monospace; word-break: break-all; resize: vertical; -webkit-user-select: text; user-select: text; }
.ol-row { display: flex; gap: 8px; flex-wrap: wrap; }
.ol-err { margin: 0 0 12px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--danger); color: #ffd3c9; background: rgba(217,112,92,.12); }
.ol-ok { margin: 0 0 12px; padding: 8px 12px; border-radius: 8px; border: 1px solid #5fae6a; color: #cdeed1; background: rgba(95,174,106,.12); font-weight: 600; }

/* ---- Décompte final ---- */
.fin { display: flex; flex-direction: column; gap: 10px; max-height: 58vh; overflow-y: auto; padding-right: 2px; }
.fin-card { background: var(--panel); border-radius: 12px; padding: 10px 12px 12px; }
.fin-head { display: flex; align-items: center; gap: 10px; }
.fin-head .nm { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fin-head .tot { font-family: var(--display); font-size: 1.2rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.fin-lines { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.fin-line { display: flex; justify-content: space-between; gap: 10px; font-size: .93rem; opacity: 0; transform: translateX(-8px); animation: finIn .4s var(--d, 0s) ease forwards; }
.fin-line b { font-variant-numeric: tabular-nums; color: var(--brass); white-space: nowrap; }
.fin-line.none { color: var(--muted); }
.fin-sum { display: flex; justify-content: space-between; margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); font-weight: 700; opacity: 0; animation: finIn .4s var(--d, 0s) ease forwards; }
.fin-sum b { font-family: var(--display); font-size: 1.3rem; color: var(--brass); font-variant-numeric: tabular-nums; }
@keyframes finIn { to { opacity: 1; transform: none; } }

/* ---- Gagnant ---- */
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 14; pointer-events: none; }
.sheet__panel--win { text-align: center; position: relative; padding-top: 34px; overflow: visible; }
.crown { width: 64px; height: 44px; position: absolute; left: 50%; top: -26px; margin-left: -32px; animation: crownDrop .9s cubic-bezier(.3,1.6,.5,1) both, crownGlow 2.2s 1s ease-in-out infinite; }
@keyframes crownDrop { from { transform: translateY(-60px) rotate(-18deg) scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes crownGlow { 0%, 100% { filter: drop-shadow(0 0 0 rgba(224,178,74,0)); } 50% { filter: drop-shadow(0 0 14px rgba(224,178,74,.9)); } }
.sheet__panel--win h2 { animation: winPop .8s .2s cubic-bezier(.3,1.5,.5,1) both; }
@keyframes winPop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet__panel--win .rank { text-align: left; }
.rank li { opacity: 0; transform: translateY(10px); animation: finIn .45s ease forwards; }
.rank li:nth-child(1) { animation-delay: .5s; } .rank li:nth-child(2) { animation-delay: .7s; } .rank li:nth-child(3) { animation-delay: .9s; } .rank li:nth-child(4) { animation-delay: 1.1s; } .rank li:nth-child(5) { animation-delay: 1.3s; }
.rank li.win { background: linear-gradient(100deg, var(--panel) 30%, #4a4126 50%, var(--panel) 70%); background-size: 220% 100%; animation: finIn .45s .5s ease forwards, shine 2.4s 1.2s linear infinite; }
.rank li.win svg { animation: pawnJump .9s 1s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes shine { from { background-position: 120% 0; } to { background-position: -120% 0; } }
@keyframes pawnJump { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-7px) scale(1.08); } }
@media (prefers-reduced-motion: reduce) {
  .home-a, .fin-line, .fin-sum, .rank li, .crown, .sheet__panel--win h2 { animation: none !important; opacity: 1; transform: none; }
  .rank li.win, .rank li.win svg { animation: none !important; }
}
