/* Bastide — DA « Plan de bastide » : encre sépia sur vélin, pigments du Sud-Ouest. */

@font-face { font-family: "Alegreya SC"; src: url("../fonts/alegreya-sc-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Alegreya SC"; src: url("../fonts/alegreya-sc-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url("../fonts/alegreya-sans-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url("../fonts/alegreya-sans-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Alegreya Sans"; src: url("../fonts/alegreya-sans-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  /* Papier & encre */
  --velin: #F3EAD7;
  --velin-fonce: #E8DCC2;
  --encre: #3A2A1E;
  --encre-douce: #6B5442;
  --filet: rgba(58, 42, 30, 0.28);

  /* Terroir (tuiles) */
  --pre: #AEBB7E;
  --pierre: #E6CFA0;
  --toit: #C2673E;
  --rempart: #7A5A3D;

  /* Pigments (couleurs des joueurs, phase 3) */
  --garance: #B23A2E;
  --pastel: #3F5E8C;
  --safran: #E0A526;
  --vert-de-gris: #4E8C7A;
  --tournesol: #6E4A7E;
  --noir-de-vigne: #2F2A28;

  --ok: var(--vert-de-gris);
  --ko: var(--garance);

  --titre: "Alegreya SC", "Iowan Old Style", Georgia, serif;
  --texte: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
  --ombre: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 6px 18px rgba(58, 42, 30, 0.18);
  --topbar: 60px;
}

* { box-sizing: border-box; }

/* L'attribut hidden doit gagner sur les display des composants (.btn…). */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background-color: var(--velin);
  background-image:
    radial-gradient(ellipse at 50% 40%, rgba(255, 250, 238, 0.7), transparent 70%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.23 0 0 0 0 0.16 0 0 0 0 0.12 0 0 0 0.07 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--encre);
  font: 17px/1.4 var(--texte);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
button, a, input, select, .meeple-spot { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* ——— Bandeau ——— */

.topbar {
  position: fixed;
  inset: 0 0 auto;
  height: var(--topbar);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: rgba(243, 234, 215, 0.92);
  border-bottom: 1px solid var(--filet);
  box-shadow: 0 3px 0 -2px var(--filet);
  backdrop-filter: blur(4px);
}

.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; color: inherit; text-decoration: none; min-width: 0; }
.brand > div { display: flex; flex-direction: column; min-width: 0; }
.brand-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32ch; }
.brand-mark { width: 30px; height: 30px; fill: var(--toit); stroke: var(--encre); stroke-width: 1.2; stroke-linejoin: round; }
.brand-mark .brand-door { fill: var(--encre); }
.brand-name { margin: 0; font: 700 26px/1 var(--titre); letter-spacing: 0.04em; }
.brand-sub { margin: 2px 0 0; font-size: 13px; color: var(--encre-douce); font-style: italic; }

.stats { display: flex; gap: 22px; margin: 0; }
.stats div { text-align: center; }
.stats dt { font: 500 12px/1 var(--titre); letter-spacing: 0.08em; color: var(--encre-douce); }
.stats dd { margin: 3px 0 0; font: 700 21px/1 var(--titre); font-variant-numeric: tabular-nums; }

.btn {
  padding: 8px 16px;
  border: 1.5px solid var(--encre);
  border-radius: 3px;
  background: var(--encre);
  color: var(--velin);
  font: 700 15px/1 var(--titre);
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn { display: inline-block; text-decoration: none; text-align: center; }
.btn:hover { background: var(--toit); border-color: var(--toit); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-small { padding: 6px 11px; font-size: 13px; }
.user-menu { display: flex; align-items: center; gap: 10px; }
.rules-link { display: inline-flex; align-items: center; gap: 6px; color: var(--encre); text-decoration: none; font: 500 15px/1 var(--titre); white-space: nowrap; }
.rules-link-icon { display: inline-grid; place-items: center; width: 26px; height: 26px; border: 1.5px solid var(--encre); border-radius: 50%; font: 700 15px/1 var(--titre); }
.rules-link:hover .rules-link-icon, .rules-link.is-current .rules-link-icon { background: var(--encre); color: var(--velin); }

/* ——— Page des règles ——— */
.rules { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 22px; align-items: start; max-width: 1120px; }
.rules-toc { position: sticky; top: calc(var(--topbar) + 20px); }
.rules-toc ol { margin: 0; padding-left: 1.2em; line-height: 1.8; }
.rules-toc a, .rules-body a:not(.btn) { color: var(--pastel); }
.rules-back { margin: 14px 0 0; }
.rules-body { padding: 24px 32px 32px; }
.rules-body h1 { font: 700 32px/1.1 var(--titre); letter-spacing: 0.04em; margin: 0 0 8px; text-align: left; }
.rules-body h2 { font: 700 23px/1.2 var(--titre); letter-spacing: 0.04em; margin: 34px 0 10px; text-align: left; padding-bottom: 6px; border-bottom: 1px solid var(--filet); }
.rules-body h3 { font: 700 17px/1.2 var(--titre); letter-spacing: 0.04em; margin: 18px 0 6px; color: var(--encre); }
.rules-body h3::after { display: none; }
.rules-body section { scroll-margin-top: calc(var(--topbar) + 16px); }
.rules-lead { font-size: 18px; font-style: italic; color: var(--encre-douce); }
.rules-body p, .rules-body li, .rules-body dd { line-height: 1.55; }
.rules-steps li { margin-bottom: 6px; }
.rule-figure, .rule-shot { margin: 16px 0; }
.rule-board svg { display: block; width: 100%; max-width: 520px; height: auto; max-height: 420px; margin: 0 auto; filter: drop-shadow(0 4px 8px rgba(58, 42, 30, 0.22)); }
.rule-figure figcaption, .rule-shot figcaption { margin-top: 10px; font-size: 15px; color: var(--encre-douce); text-align: center; }
.rule-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 18px; }
.rule-grid .rule-board svg { max-height: 300px; }
.rule-wash { mix-blend-mode: multiply; opacity: 0.5; }
.rule-bubble { font: 700 22px/1 var(--titre); stroke: var(--velin); stroke-width: 5px; paint-order: stroke; }
.rule-defs { position: absolute; width: 0; height: 0; }
.rule-shot img { display: block; width: 100%; height: auto; border: 1.5px solid var(--encre); border-radius: 3px; box-shadow: var(--ombre); }
.rule-shot-phone img { width: min(260px, 70%); margin: 0 auto; border-radius: 18px; }
.ok { color: var(--vert-de-gris); font-weight: 700; }
.ko { color: var(--garance); font-weight: 700; }
.rules-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; background: var(--velin-fonce); padding: 6px 16px 12px; border-radius: 3px; }
.rules-controls ul { padding-left: 1.1em; margin: 0; }
kbd { display: inline-block; padding: 1px 6px; border: 1px solid var(--encre-douce); border-bottom-width: 2px; border-radius: 3px; font: 600 13px/1.3 var(--texte); background: var(--velin); }
.rules-options dt { font: 700 16px/1.3 var(--titre); margin-top: 12px; }
.rules-options dd { margin: 4px 0 0; }
.user-name { font: 500 15px/1 var(--titre); white-space: nowrap; }
.btn-ghost { background: transparent; color: var(--encre); }
.btn-ghost:hover { background: var(--velin-fonce); border-color: var(--encre); }
.btn:focus-visible, .icon-btn:focus-visible, .hand-tile:focus-visible { outline: 2px solid var(--pastel); outline-offset: 2px; }

/* ——— Pages (connexion, lobby) ——— */

body.view-game { overflow: hidden; }
.page { padding: calc(var(--topbar) + 28px) 20px 40px; max-width: 1080px; margin: 0 auto; }
.page-center { display: grid; place-items: center; min-height: 100vh; }
.page h1 { margin: 0 0 4px; font: 700 34px/1 var(--titre); letter-spacing: 0.05em; text-align: center; }

.auth { width: min(100%, 400px); }
.auth-lead { margin: 0 0 18px; text-align: center; font-style: italic; color: var(--encre-douce); }
.tabs { display: flex; margin-bottom: 14px; border-bottom: 1px solid var(--filet); }
.tab { flex: 1; padding: 8px 4px; border: 0; border-bottom: 2px solid transparent; background: none; font: 500 15px/1 var(--titre); letter-spacing: 0.05em; color: var(--encre-douce); cursor: pointer; }
.tab.is-active { color: var(--encre); border-bottom-color: var(--toit); }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font: 500 14px/1.2 var(--titre); letter-spacing: 0.04em; }
.form input, .form select, .share input {
  font: 16px/1.3 var(--texte);
  padding: 8px 10px;
  border: 1.5px solid var(--encre-douce);
  border-radius: 3px;
  background: #FBF6EA;
  color: var(--encre);
}
.form input:focus, .form select:focus { outline: 2px solid var(--pastel); outline-offset: 1px; border-color: var(--encre); }
.form .btn { margin-top: 4px; padding: 10px 16px; }
.form-error { min-height: 1.3em; margin: 12px 0 0; color: var(--garance); text-align: center; }
.guest .hint { margin-top: 10px; }
.guest-login { margin: 14px 0 0; text-align: center; font-size: 14px; }
.guest-login a, .lobby a:not(.btn) { color: var(--pastel); }
.user-name em { font-weight: 400; color: var(--encre-douce); }

.lobby { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
.lobby-create { grid-row: span 2; }
.lobby .cartouche h2 { text-align: left; }
.game-list { list-style: none; margin: 0; padding: 0; }
.game-item { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px dotted var(--filet); }
.game-item:last-child { border-bottom: 0; }
.game-item.is-your-turn { background: linear-gradient(90deg, rgba(178, 58, 46, 0.08), transparent); }
.game-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.game-info strong { font: 500 17px/1.2 var(--titre); }
.game-meta { font-size: 14px; color: var(--encre-douce); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-empty { padding: 10px 2px; color: var(--encre-douce); font-style: italic; }
.badge { padding: 3px 8px; border-radius: 999px; font: 500 12px/1.2 var(--titre); letter-spacing: 0.04em; white-space: nowrap; border: 1px solid var(--filet); }
.badge-lobby { background: #F7E9C4; }
.badge-playing { background: #DCE6C8; }
.badge-finished { background: var(--velin-fonce); color: var(--encre-douce); }
.badge-turn { background: var(--garance); color: var(--velin); border-color: var(--garance); }
.badge-ext { background: #D9D2E6; border-color: #8C7FA6; font-size: 11px; padding: 1px 6px; vertical-align: 2px; }
.badge-fast { background: var(--safran); border-color: #B8861C; font-size: 11px; padding: 1px 6px; vertical-align: 2px; }
.form .check { flex-direction: row; align-items: center; gap: 8px; font: 15px/1.3 var(--texte); letter-spacing: 0; }
.form .check input { width: 18px; height: 18px; accent-color: var(--toit); }

/* ——— Plateau ——— */

.table { position: fixed; inset: var(--topbar) 0 0; }

.board { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; user-select: none; }
.board.is-panning { cursor: grabbing; }

/* Lavis aquarelle posé sur tout le plateau (motif aligné, donc sans couture entre tuiles). */
.layer-wash { mix-blend-mode: multiply; opacity: 0.55; pointer-events: none; }

.frontier { fill: rgba(58, 42, 30, 0.035); stroke: var(--encre-douce); stroke-opacity: 0.45; stroke-width: 1.4; stroke-dasharray: 5 5; }
.last-placed { fill: none; stroke: var(--safran); stroke-width: 3; stroke-dasharray: 10 4; }

.ghost { pointer-events: none; }

/* Animations (désactivées si le système demande moins de mouvement, cf. fin du fichier) */
.tile-enter { transform-origin: 50px 50px; animation: tile-drop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2) both; }
@keyframes tile-drop { from { transform: scale(1.18); opacity: 0; } 60% { opacity: 1; } to { transform: scale(1); opacity: 1; } }
.pawn-enter { animation: pawn-drop 0.4s cubic-bezier(0.3, 1.4, 0.5, 1) both; }
@keyframes pawn-drop { from { transform: translateY(-16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.cell-flash { fill: none; stroke: var(--pastel); stroke-width: 5; pointer-events: none; animation: cell-flash 0.55s ease-in-out 3; }
@keyframes cell-flash { 50% { stroke-opacity: 0.15; } }

/* Pions */
.pawn { pointer-events: none; }
.meeple-spot { cursor: pointer; }
.meeple-spot-halo { fill: rgba(243, 234, 215, 0.55); stroke: var(--encre); stroke-width: 1.5; stroke-dasharray: 3 2.5; animation: spot-pulse 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.meeple-spot-dot { stroke: var(--encre); stroke-width: 1.4; opacity: 0.85; }
.meeple-spot:hover .meeple-spot-dot { opacity: 1; }
.meeple-spot:hover .meeple-spot-halo { fill: rgba(243, 234, 215, 0.85); }
@keyframes spot-pulse { 50% { transform: scale(1.18); } }

.float-points {
  font: 700 26px/1 var(--titre);
  stroke: var(--velin);
  stroke-width: 4px;
  paint-order: stroke;
  pointer-events: none;
  animation: float-up 1.8s ease-out forwards;
}
@keyframes float-up { from { transform: translateY(0); opacity: 0; } 15% { opacity: 1; } to { transform: translateY(-34px); opacity: 0; } }
.ghost-tile { opacity: 0.88; }
.ghost-frame { fill: none; stroke-width: 4; }
.ghost.is-legal .ghost-frame { stroke: var(--ok); }
.ghost.is-illegal .ghost-tile { opacity: 0.55; filter: grayscale(0.6); }
.ghost.is-illegal .ghost-frame { stroke: var(--ko); stroke-dasharray: 8 5; }
.ghost-cross { stroke: var(--ko); stroke-width: 5; stroke-linecap: round; }

/* ——— Cartouche (panneau façon cartouche de carte ancienne) ——— */

.cartouche {
  background: var(--velin);
  border: 1.5px solid var(--encre);
  outline: 1px solid var(--encre);
  outline-offset: -6px;
  box-shadow: var(--ombre);
  border-radius: 2px;
  padding: 18px 20px;
}
.cartouche h2 { margin: 0 0 10px; font: 700 17px/1.1 var(--titre); letter-spacing: 0.06em; text-align: center; }
.cartouche h3 {
  margin: 16px 0 6px;
  font: 500 13px/1 var(--titre);
  letter-spacing: 0.08em;
  color: var(--encre-douce);
  display: flex;
  align-items: center;
  gap: 8px;
}
.cartouche h3::after { content: ""; flex: 1; border-top: 1px solid var(--filet); }

.hand { position: absolute; top: 16px; right: 16px; width: 236px; max-height: calc(100% - 32px); display: flex; flex-direction: column; }
.hand > * { flex-shrink: 0; }
.hand > .journal { flex-shrink: 1; }

.hand-tile {
  --rotation: 0deg;
  display: block;
  width: 128px;
  height: 128px;
  margin: 0 auto;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 3px 4px rgba(58, 42, 30, 0.3));
}
.hand-tile svg { display: block; width: 100%; height: 100%; transform: rotate(var(--rotation)); transition: transform 0.18s ease-out; }
.hand.is-empty .hand-tile, .hand.is-empty .hand-actions { display: none; }

.meeple-choice { display: none; text-align: center; }
.hand.is-meeple .meeple-choice { display: block; }
.hand.is-meeple .hand-tile, .hand.is-meeple .hand-actions, .hand.is-meeple .hand-name, .hand.is-meeple > .hint { display: none; }
.meeple-icon { --pawn: var(--garance); width: 48px; height: 52px; fill: var(--pawn); stroke: var(--encre); stroke-width: 1.1; stroke-linejoin: round; }
.meeple-left { margin: 4px 0 0; font: 500 15px/1.2 var(--titre); }
.meeple-types { display: flex; margin: 10px 0 0; border: 1.5px solid var(--encre); border-radius: 3px; overflow: hidden; }
.meeple-types button { flex: 1; min-height: 40px; padding: 6px 8px; border: 0; background: var(--velin); font: 500 14px/1.1 var(--titre); cursor: pointer; }
.meeple-types button + button { border-left: 1.5px solid var(--encre); }
.meeple-types button[aria-checked="true"] { background: var(--encre); color: var(--velin); }
.meeple-types button:disabled { opacity: 0.4; cursor: not-allowed; }
.meeple-choice .btn { margin-top: 12px; }

.stat-score dd { color: var(--garance); }

.hand-name { margin: 10px 0 4px; text-align: center; font: 500 16px/1.2 var(--titre); min-height: 1.2em; }
.touch-hint, .journal-toggle { display: none; }
/* Consigne de pose inutile quand ce n'est pas à soi de poser une tuile ; panneau du pion compact. */
.hand.is-waiting .touch-hint, .hand.is-empty .touch-hint, .hand.is-meeple .touch-hint, .hand.is-meeple .journal-toggle { display: none !important; }
.hand-actions { display: flex; justify-content: center; gap: 10px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1.5px solid var(--encre);
  border-radius: 50%;
  background: var(--velin);
  font: 700 20px/1 var(--titre);
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--velin-fonce); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.hint { margin: 10px 0 0; font-size: 13px; font-style: italic; color: var(--encre-douce); text-align: center; }

.journal { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; font-size: 14px; }
.journal li { padding: 4px 0; border-bottom: 1px dotted var(--filet); }
.journal li:first-child { font-weight: 700; }
.journal .is-warn { color: var(--garance); }
.journal .is-end { color: var(--pastel); }
.journal .is-score { color: var(--garance); font-weight: 700; }
.journal .is-link { cursor: pointer; }
.journal .is-link:hover, .journal .is-link:focus-visible { background: rgba(63, 94, 140, 0.08); outline: none; }
.journal-turn { display: inline-block; min-width: 2.4em; font: 500 11px/1.4 var(--titre); color: var(--encre-douce); }

/* Minuteur de la partie rapide */
.turn-timer { --left: 1; position: relative; height: 22px; margin: -2px 0 10px; border: 1.5px solid var(--encre); border-radius: 3px; background: var(--velin-fonce); overflow: hidden; }
.turn-timer-bar { position: absolute; inset: 0; transform-origin: left; transform: scaleX(var(--left)); background: var(--vert-de-gris); opacity: 0.45; transition: transform 0.25s linear; }
.turn-timer.is-mine .turn-timer-bar { opacity: 0.75; }
.turn-timer.is-urgent .turn-timer-bar { background: var(--garance); }
.turn-timer-text { position: relative; display: block; text-align: center; font: 700 13px/19px var(--titre); font-variant-numeric: tabular-nums; }
.turn-timer.is-urgent.is-mine { animation: timer-pulse 1s ease-in-out infinite; }
@keyframes timer-pulse { 50% { box-shadow: 0 0 0 3px rgba(178, 58, 46, 0.35); } }

.turn-banner {
  position: absolute; left: 50%; top: 22%; transform: translate(-50%, -50%) scale(0.9);
  padding: 14px 28px; background: var(--encre); color: var(--velin); border-radius: 3px;
  font: 700 26px/1 var(--titre); letter-spacing: 0.06em; box-shadow: var(--ombre);
  opacity: 0; pointer-events: none;
}
.turn-banner.is-visible { animation: banner 1.8s ease-out both; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); } 15%, 75% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1); } }

.net-status { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); padding: 6px 14px; background: var(--garance); color: var(--velin); border-radius: 999px; font-size: 14px; box-shadow: var(--ombre); z-index: 5; }

/* ——— Zoom, rose des vents, messages ——— */

.zoom { position: absolute; left: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; }

.compass { position: absolute; left: 72px; bottom: 16px; width: 72px; height: 72px; pointer-events: none; opacity: 0.7; overflow: visible; }

/* ——— Joueurs ——— */

.players { position: absolute; top: 16px; left: 16px; width: 236px; padding: 14px 16px; }
.players h2 { font-size: 15px; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list { list-style: none; margin: 0; padding: 0; }
.player { display: grid; grid-template-columns: 18px 1fr auto auto; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 3px; }
.player.is-current { background: rgba(58, 42, 30, 0.08); box-shadow: inset 3px 0 0 var(--encre); }
.player-pawn { --pawn: var(--garance); width: 14px; height: 14px; border-radius: 50%; background: var(--pawn); border: 1.5px solid var(--encre); }
.player-name { font: 500 15px/1.2 var(--titre); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player.is-you .player-name { font-weight: 700; }
.player-meta { font-size: 12px; color: var(--encre-douce); white-space: nowrap; }
.player-score { font: 700 17px/1 var(--titre); font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }

.waiting {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 440px);
  text-align: center;
}
.waiting h2 { font-size: 22px; }
.waiting-lead { margin: 0 0 12px; font-style: italic; color: var(--encre-douce); }
.waiting .player-list { text-align: left; margin-bottom: 12px; }
.share { display: flex; gap: 8px; margin: 6px 0 16px; }
.share input { flex: 1; min-width: 0; font-size: 14px; }
.waiting-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
body.is-lobby .hand, body.is-lobby .zoom, body.is-lobby .stats, body.is-lobby .players { visibility: hidden; }

.hand.is-waiting .hand-actions { display: none; }
.hand.is-waiting { box-shadow: var(--ombre), inset 0 4px 0 var(--turn-color); }
.hand.is-waiting .hand-tile { cursor: default; }
.end-ranking { list-style: none; margin: 4px 0 10px; padding: 0; text-align: left; }
.player.is-abandoned .player-name { text-decoration: line-through; color: var(--encre-douce); }
.players .abandon { display: block; width: 100%; margin-top: 8px; font-size: 12px; padding: 5px 8px; }
.badge-abandoned { background: var(--velin-fonce); color: var(--encre-douce); }
.bot-controls { display: flex; gap: 8px; justify-content: center; margin: 0 0 12px; }
.bot-controls select { font: 15px/1.2 var(--texte); padding: 6px 8px; border: 1.5px solid var(--encre-douce); border-radius: 3px; background: #FBF6EA; color: var(--encre); min-height: 40px; }
.player.is-bot .player-name::before { content: "⚙ "; color: var(--encre-douce); }
.player .bot-remove { margin-left: 4px; width: 28px; height: 28px; border: 1px solid var(--filet); border-radius: 50%; background: var(--velin); cursor: pointer; font-size: 16px; line-height: 1; }
.waiting .player { grid-template-columns: 18px 1fr auto auto auto; }
.color-picker { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 14px; }
.color-swatch { --swatch: #888; width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--encre); background: var(--swatch); cursor: pointer; position: relative; }
.color-swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--velin), 0 0 0 5px var(--encre); }
.color-swatch:disabled { opacity: 0.25; cursor: not-allowed; }
.color-swatch:disabled::after { content: ""; position: absolute; inset: 45% -2px; border-top: 2px solid var(--encre); transform: rotate(-45deg); }
.compass-ring { fill: none; stroke: var(--encre); stroke-width: 1.4; }
.compass-ring.thin { stroke-width: 0.7; stroke-dasharray: 2 2; }
.compass-star { fill: var(--velin); stroke: var(--encre); stroke-width: 1.2; stroke-linejoin: round; }
.compass-north { fill: var(--toit); }
.compass text { font: 700 13px/1 var(--titre); fill: var(--encre); }

.toast {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: min(90vw, 460px);
  padding: 10px 18px;
  background: var(--encre);
  color: var(--velin);
  border-radius: 3px;
  box-shadow: var(--ombre);
  font-size: 15px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--garance); }

.end-dialog { width: min(92vw, 380px); color: var(--encre); text-align: center; }
.end-dialog::backdrop { background: rgba(58, 42, 30, 0.35); }
.end-dialog p { margin: 0 0 8px; }
.end-score { font: 700 30px/1.1 var(--titre); color: var(--garance); }
.end-lines { list-style: none; margin: 4px 0 8px; padding: 0; font-size: 14px; text-align: left; max-height: 160px; overflow-y: auto; }
.end-lines li { padding: 3px 0; border-bottom: 1px dotted var(--filet); }
.end-actions { display: flex; justify-content: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ——— Mobile ——— */

@media (max-width: 900px) {
  .lobby { grid-template-columns: 1fr; }
  .lobby-create { grid-row: auto; }
  .players { width: 200px; }
}

/* ——— Téléphone (portrait) ——— */

@media (max-width: 720px) {
  :root { --topbar: 52px; --gutter: 12px; }
  body { font-size: 16px; }
  .topbar { gap: 10px; padding: 0 var(--gutter); padding-top: env(safe-area-inset-top); height: calc(var(--topbar) + env(safe-area-inset-top)); }
  .table { inset: calc(var(--topbar) + env(safe-area-inset-top)) 0 0; }
  .brand-sub, .user-name { display: none; }
  .brand-name { font-size: 21px; }
  .btn { padding: 9px 12px; font-size: 14px; }
  .btn-small { min-height: 40px; }
  .icon-btn { width: 44px; height: 44px; }
  .page { padding: calc(var(--topbar) + env(safe-area-inset-top) + 16px) 16px calc(32px + env(safe-area-inset-bottom)); }
  .lobby { gap: 14px; }
  .game-item { flex-wrap: wrap; }
  .game-item .btn { min-height: 40px; }

  /* En partie : le bandeau ne garde que l'emblème (retour au lobby) et les compteurs. */
  .view-game .brand-name, .view-game .user-menu { display: none; }
  .rules-link-text { display: none; }
  .rules { grid-template-columns: 1fr; }
  .rules-toc { position: static; }
  .rules-body { padding: 16px; }
  .rules-body h1 { font-size: 26px; }
  .view-game .brand-mark { display: block; width: 32px; height: 32px; }
  .view-game .brand { margin-right: 0; }
  .view-game .stats { flex: 1; justify-content: space-around; gap: 6px; }
  .stats dt { font-size: 11px; }
  .stats dd { font-size: 18px; }
  .stat-secondary { display: none; }

  .compass { display: none; }
  .players { top: var(--gutter); left: var(--gutter); width: auto; max-width: calc(100% - 84px); padding: 6px 8px; }
  .players h2 { display: none; }
  .player { grid-template-columns: 14px minmax(0, auto) auto; gap: 6px; padding: 3px 4px; }
  .player .player-meta { display: none; }
  .player-name { font-size: 13px; }
  .zoom { bottom: auto; top: var(--gutter); left: auto; right: var(--gutter); }

  .hand {
    top: auto;
    right: var(--gutter);
    left: var(--gutter);
    bottom: calc(var(--gutter) + env(safe-area-inset-bottom));
    width: auto;
    max-height: 70vh;
    padding: 10px 12px;
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    grid-template-areas: "timer timer" "tile name" "tile actions" "hint hint" "toggle toggle" "journal journal";
    column-gap: 12px;
    align-items: center;
  }
  .hand h2, .hand .journal-title, .hand > .hint { display: none; }
  .turn-timer { grid-area: timer; margin: 0 0 8px; }
  .hand-tile { grid-area: tile; width: 84px; height: 84px; }
  .hand-name { grid-area: name; margin: 0; text-align: left; align-self: end; font-size: 15px; }
  .hand-actions { grid-area: actions; justify-content: flex-start; align-self: start; margin-top: 6px; }
  .touch-hint { grid-area: hint; display: block; margin: 8px 0 0; font-size: 12.5px; font-style: italic; color: var(--encre-douce); }
  .journal-toggle { grid-area: toggle; display: block; justify-self: stretch; margin-top: 8px; }
  .journal { grid-area: journal; display: none; max-height: 34vh; margin-top: 6px; }
  .hand.show-journal .journal { display: block; }
  .hand.is-waiting .touch-hint, .hand.is-empty .touch-hint { display: none; }
  .hand.is-waiting h2 { display: block; grid-column: 1 / -1; text-align: left; font-size: 14px; margin: 0 0 6px; }

  .hand.is-meeple { display: block; text-align: center; }
  .hand.is-meeple h2 { display: block; font-size: 16px; }
  .hand.is-meeple .meeple-icon { width: 34px; height: 36px; }
  .hand.is-meeple .meeple-choice .hint { display: block; }
  .hand.is-meeple .meeple-choice .btn { width: 100%; min-height: 44px; }

  .waiting { width: calc(100vw - 2 * var(--gutter)); max-height: calc(100% - 2 * var(--gutter)); overflow-y: auto; }
  .end-dialog { width: calc(100vw - 2 * var(--gutter)); max-height: 88vh; overflow-y: auto; padding: 14px; }
  .end-score { font-size: 24px; }
  .end-actions .btn { flex: 1; min-height: 44px; }
  .toast { bottom: auto; top: 70px; }
  .turn-banner { top: 30%; font-size: 21px; padding: 12px 20px; }
  .net-status { top: 60px; }
}

/* ——— Téléphone à l'horizontale : panneau à droite, compact ——— */

@media (max-height: 500px) and (orientation: landscape) {
  :root { --topbar: 44px; }
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .view-game .brand-name, .view-game .user-menu, .brand-sub { display: none; }
  .stat-secondary { display: none; }
  .stats dd { font-size: 16px; }
  .compass { display: none; }
  .players { top: 8px; left: max(8px, env(safe-area-inset-left)); width: auto; max-width: 34vw; padding: 6px 8px; }
  .players h2, .player .player-meta { display: none; }
  .zoom { left: auto; right: calc(min(240px, 34vw) + 20px); bottom: 8px; flex-direction: row; }
  .hand {
    top: 8px; bottom: 8px; right: max(8px, env(safe-area-inset-right)); left: auto;
    width: min(240px, 34vw); max-height: none; padding: 10px; overflow-y: auto;
    display: flex; flex-direction: column;
  }
  .hand h2 { font-size: 14px; margin-bottom: 6px; }
  .hand-tile { width: 76px; height: 76px; }
  .hand > .hint, .hand .journal-title { display: none; }
  .touch-hint { display: block; margin: 6px 0 0; font-size: 12px; font-style: italic; text-align: center; color: var(--encre-douce); }
  .journal-toggle { display: block; margin-top: 8px; }
  .journal { display: none; }
  .hand.show-journal .journal { display: block; }
  .waiting, .end-dialog { max-height: calc(100% - 16px); overflow-y: auto; }
}

/* Écrans tactiles : pas d'infobulle de survol à attendre, consignes adaptées. */
@media (hover: none) and (pointer: coarse) and (min-width: 721px) {
  .hand > .hint { display: none; }
  .touch-hint { display: block; margin: 8px 0 0; font-size: 13px; font-style: italic; text-align: center; color: var(--encre-douce); }
}

@media (prefers-reduced-motion: reduce) {
  .hand-tile svg, .toast, .turn-timer-bar { transition: none; }
  .tile-enter, .pawn-enter, .cell-flash, .float-points, .meeple-spot-halo, .turn-timer { animation: none; }
  .turn-banner.is-visible { animation: none; opacity: 1; }
}
