/* ═══════════════════════════ Base ═══════════════════════════ */
:root {
  --bg: #0f1419;
  --bg-2: #171e26;
  --bg-3: #202a35;
  --line: #2c3947;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --accent: #f0b429;
  --danger: #ff6b6b;
  --ok: #4cd964;
  --sidebar-w: 360px;
  --chat-h: 280px;
  --radius: 10px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.4; }
button, input, select { font: inherit; }
h1 { margin: 0 0 8px; font-size: 26px; }
h2 { margin: 0 0 8px; font-size: 16px; }
h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-weight: 600; }
.spacer { flex: 1; }
code { background: var(--bg-3); padding: 1px 5px; border-radius: 4px; }

.screen { min-height: 100%; }
.screen[hidden] { display: none !important; }

/* ═══════════════════════════ Boutons / champs ═══════════════════════════ */
.btn {
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; transition: background .12s, transform .05s;
}
.btn:hover { background: #2a3745; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #1a1200; border-color: transparent; font-weight: 700; }
.btn.primary:hover { background: #ffc94a; }
.btn.danger { background: #5a1f1f; border-color: #7a2c2c; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.field > span { font-size: 12px; color: var(--muted); }
input, select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* ═══════════════════════════ Accueil / Lobby ═══════════════════════════ */
#screen-home, #screen-lobby { display: flex; align-items: center; justify-content: center; padding: 24px; }
#screen-home[hidden], #screen-lobby[hidden] { display: none; }
.home-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: 100%; max-width: 640px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.home-card.wide { max-width: 760px; }
.home-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }
.home-block { background: var(--bg-3); border-radius: var(--radius); padding: 14px; }
@media (max-width: 600px) { .home-columns { grid-template-columns: 1fr; } }

.invite { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.invite input { flex: 1; min-width: 200px; font-family: monospace; font-size: 12px; }
.lobby-players { list-style: none; padding: 0; margin: 14px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.lobby-players li { display: flex; align-items: center; gap: 8px; background: var(--bg-3); border-radius: 8px; padding: 8px 10px; }
.lobby-players li.empty { color: var(--muted); border: 1px dashed var(--line); background: transparent; }
.lobby-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex-shrink: 0; border: 2px solid rgba(255,255,255,.25); }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.tag.owner { color: var(--accent); }
.tag.bot { color: #a8b8ff; }
.tag.off { color: var(--danger); }
.tag.dead { text-decoration: line-through; }

/* ═══════════════════════════ Partie ═══════════════════════════ */
.screen.game { display: flex; flex-direction: column; height: 100vh; }
.topbar { display: flex; gap: 14px; align-items: center; padding: 5px 10px; background: var(--bg-2); border-bottom: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.game-header { display: flex; gap: 8px; align-items: center; }
.local-switcher { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.local-switcher[hidden] { display: none; }
.local-switcher .btn.active { outline: 2px solid var(--accent); }
.map-area { position: relative; flex: 1; min-height: 0; display: flex; }
#map { flex: 1; min-width: 0; }

/* Bandeau du bas : panneaux côte à côte, chacun défile seul si nécessaire */
.bottom { height: 260px; display: flex; border-top: 1px solid var(--line); background: var(--bg-2); flex-shrink: 0; }
.panels { flex: 1; display: flex; gap: 8px; padding: 8px; min-width: 0; }
.panels .panel { flex: 1 1 0; min-width: 0; overflow-y: auto; }
.panels .panel.phase { flex: 1.5 1 0; }
.panels .panel.gameover { flex: 0 0 200px; }
.panel { background: var(--bg-3); border-radius: var(--radius); padding: 10px 12px; }
.panel.active-turn { outline: 2px solid var(--accent); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.players li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 6px; align-items: center; padding: 3px 6px; border-radius: 6px; line-height: 1.3; }
.players .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .tag { padding: 0 2px; background: transparent; }
.players li.active { background: rgba(240,180,41,.12); box-shadow: inset 3px 0 0 var(--accent); }
.players li.dead { opacity: .45; }
.players li.me .pname { font-weight: 700; }
.players .stats { font-size: 11px; color: var(--muted); white-space: nowrap; }
.players .pname { cursor: pointer; }

.phase-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.phase-steps { display: flex; gap: 4px; margin: 6px 0 8px; }
.phase-steps span { flex: 1; text-align: center; font-size: 11px; padding: 3px 0; border-radius: 6px; background: var(--bg); color: var(--muted); }
.phase-steps span.on { background: var(--accent); color: #1a1200; font-weight: 700; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0; }
.big { font-size: 22px; font-weight: 800; color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; color: var(--text); padding: 4px 10px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #1a1200; font-weight: 700; }

.dice { display: flex; gap: 6px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.die { width: 26px; height: 26px; border-radius: 6px; display: inline-grid; place-items: center; font-weight: 800; font-size: 14px; }
.die.att { background: #ffe9e9; color: #8b1a1a; }
.die.def { background: #e6f0ff; color: #163a7a; }
.vs { color: var(--muted); font-size: 12px; margin: 0 4px; }

.cards { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
/* Carte territoire : parchemin, silhouette du territoire en fond, icône du rôle devant */
.card {
  position: relative; width: 72px; height: 98px; border-radius: 7px; overflow: hidden; cursor: pointer;
  background: linear-gradient(160deg, #f6ebcd, #dcc998); color: #2b2010; border: 1.5px solid #6b5a33;
  box-shadow: 1px 2px 4px rgba(0,0,0,.35); transition: transform .12s, box-shadow .12s;
}
.card:hover { transform: translateY(-2px); }
.card.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(240,180,41,.55), 1px 2px 6px rgba(0,0,0,.4); transform: translateY(-4px); }
.card-bg { position: absolute; inset: 14px 4px 16px; width: calc(100% - 8px); height: calc(100% - 30px); opacity: .55; }
.card-bg path { stroke: #2b2010; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.card-icon { position: absolute; left: 50%; top: 50%; width: 36px; height: 36px; transform: translate(-50%, -52%); fill: #1e1710; filter: drop-shadow(0 1px 0 rgba(255,248,225,.9)); }
.card-icon .stroke { fill: none; stroke: #1e1710; }
.card-icon .eye { fill: #f6ebcd; }
.card-sym { position: absolute; top: 3px; left: 0; right: 0; text-align: center; font-family: Georgia, serif; font-size: 8px; letter-spacing: .1em; text-transform: uppercase; color: #4a3d1e; }
.card-name { position: absolute; bottom: 3px; left: 3px; right: 3px; text-align: center; font-size: 9px; font-weight: 700; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-name b { color: #b7791f; }
.card.sym-joker { background: linear-gradient(160deg, #ffe9a8, #e8c766); }
.card.sym-joker .card-icon { fill: #b7791f; }

.log { list-style: none; margin: 0; padding: 0; font-size: 12px; display: flex; flex-direction: column; gap: 2px; }
.log li { padding: 2px 0; border-bottom: 1px dashed var(--line); color: var(--muted); }
.log li b { color: var(--text); }

.toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: #2b1414; color: #ffd0d0; border: 1px solid #6b2a2a;
  padding: 8px 14px; border-radius: 8px; font-weight: 600; z-index: 5; max-width: 80%;
}
.toast.info { background: #14232b; color: #d0ecff; border-color: #2a4f6b; }
.toast[hidden] { display: none; }

/* ═══════════════════════════ Mode spectateur ═══════════════════════════ */
.tag.spectator { background: rgba(138,138,138,.25); border: 1px solid #8a8a8a; color: #d7d7d7; padding: 1px 7px; border-radius: 999px; font-size: 11px; margin-left: 6px; }
.players li.spectator { opacity: .8; }
.players li.spectator .pname { font-style: italic; }
.spectator-dot { display: inline-block; width: 12px; text-align: center; font-size: 10px; background: none !important; }
#home-spectate { white-space: nowrap; }

/* ═══════════════════════════ Panneau des règles du tour ═══════════════════════════ */
.rules {
  position: absolute; top: 10px; right: 10px; width: 320px; max-width: calc(100% - 20px); max-height: calc(100% - 20px);
  overflow-y: auto; z-index: 5; background: rgba(255, 248, 225, .96); color: #2b2010; border: 2px solid #6b5a33; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35); font-size: 12.5px; line-height: 1.4;
}
.rules[hidden] { display: none; }
.rules-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-bottom: 1px solid #c9b688; font-family: Georgia, serif; font-size: 14px; }
.rules-close { background: none; border: 0; font-size: 16px; cursor: pointer; color: #6b5a33; padding: 0 4px; }
.rules-close:hover { color: #2b2010; }
.rules-body, .rules-general { padding: 8px 12px; }
.rules p { margin: 4px 0 6px; }
.rules ul { margin: 4px 0 6px; padding-left: 18px; }
.rules li { margin: 2px 0; }
.rules code { background: rgba(107,90,51,.15); padding: 0 4px; border-radius: 4px; }
.rules .warn { background: #ffe3a1; border-left: 3px solid #b7791f; padding: 4px 8px; border-radius: 4px; }
.rules .muted { color: #6b5a33; }
.rules-general { border-top: 1px solid #c9b688; }
.rules-general summary { cursor: pointer; font-weight: 700; color: #4a3d1e; }
.rules-continents { list-style: none; padding-left: 4px; columns: 2; }
.rules-continents .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; border: 1px solid rgba(0,0,0,.3); }
.rules-foot { padding: 6px 12px; border-top: 1px solid #c9b688; color: #6b5a33; font-size: 11px; }
#rules-toggle.active { outline: 2px solid var(--accent); }
.msg.system.private { background: rgba(240,180,41,.12); border-left: 2px solid var(--accent); }

/* ═══════════════════════════ Dés qui roulent sur le plateau ═══════════════════════════ */
.dice-overlay {
  position: absolute; z-index: 6; pointer-events: none; transform: translate(-50%, -100%);
  display: flex; align-items: center; gap: 14px; padding: 10px 14px 8px;
  background: rgba(255, 248, 225, .93); border: 2px solid #6b5a33; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.35);
  color: #2b2010; font-size: 12px; transition: opacity .35s;
}
.dice-overlay[hidden] { display: none; }
.dice-overlay.fading { opacity: 0; }
.dice-overlay::after { content: ''; position: absolute; left: 50%; bottom: -9px; width: 14px; height: 14px; background: rgba(255,248,225,.93); border-right: 2px solid #6b5a33; border-bottom: 2px solid #6b5a33; transform: translateX(-50%) rotate(45deg); }
.dice-group { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dice-label { font-weight: 700; font-size: 12px; white-space: nowrap; }
.dice-row { display: flex; gap: 8px; }
.dice-loss { height: 16px; font-weight: 800; color: var(--danger); font-size: 14px; }
.dice-vs { font-family: Georgia, serif; font-style: italic; color: #7d6a3c; }
.dice-place { position: absolute; left: 50%; top: -14px; transform: translateX(-50%); white-space: nowrap; font-family: Georgia, serif; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #3b2f14; background: rgba(255,248,225,.93); padding: 1px 8px; border-radius: 6px; border: 1px solid #6b5a33; }
.die {
  width: 38px; height: 38px; border-radius: 8px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: 5px; box-sizing: border-box; box-shadow: 2px 3px 6px rgba(0,0,0,.35), inset 0 0 0 1px rgba(0,0,0,.15);
  transition: transform .12s ease-out, opacity .3s, box-shadow .3s;
}
.die i { width: 7px; height: 7px; border-radius: 50%; place-self: center; opacity: 0; }
.die i.on { opacity: 1; }
.die.att { background: linear-gradient(145deg, #ff6b6b, #c0392b); }
.die.att i { background: #fff; }
.die.def { background: linear-gradient(145deg, #ffffff, #d5dbe6); }
.die.def i { background: #1f2a3a; }
.rolling .die { animation: tumble .18s linear infinite; }
.settled .die.win { box-shadow: 0 0 0 3px #f0b429, 0 0 14px #f0b429, 2px 3px 6px rgba(0,0,0,.35); }
.settled .die.lose { opacity: .4; filter: grayscale(.6); }
@keyframes tumble { 0% { translate: 0 0; } 50% { translate: 0 -5px; } 100% { translate: 0 0; } }

/* Bandeau fin de partie */
.gameover { text-align: center; padding: 14px; background: linear-gradient(135deg, #3b2a00, #1c1400); border: 1px solid var(--accent); }
.gameover .big { font-size: 26px; }

/* ═══════════════════════════ Modales ═══════════════════════════ */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 20; }
.modal[hidden] { display: none; }
.modal .box { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 20px; min-width: 320px; max-width: 480px; }
.modal input[type=range] { width: 100%; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

/* ═══════════════════════════ Chat ═══════════════════════════ */
.chat { width: 340px; flex-shrink: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chat-head { padding: 6px 10px; font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 10px; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.msg { padding: 3px 6px; border-radius: 6px; word-break: break-word; }
.msg .who { font-weight: 700; }
.msg .time { color: var(--muted); font-size: 10px; margin-right: 4px; }
.msg.system { color: var(--muted); font-style: italic; }
.msg.private { background: rgba(155, 89, 182, .18); border-left: 3px solid #9b59b6; }
.msg.private .lock { font-size: 11px; color: #c9a3dc; margin-right: 4px; }
.msg.mentions-me { background: rgba(240,180,41,.14); border-left: 3px solid var(--accent); }
.msg .mention { font-weight: 700; padding: 0 3px; border-radius: 4px; background: rgba(255,255,255,.08); }
.chat-form { display: flex; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; }
.chat-suggest { display: flex; gap: 4px; padding: 0 10px 6px; flex-wrap: wrap; }
.chat-suggest button { font-size: 11px; padding: 2px 8px; }

/* ═══════════════════════════ Carte SVG (parchemin, zoom, boucle) ═══════════════════════════ */
.map-area { background: #d8c48f; }
#map { position: relative; overflow: hidden; }
#map svg.worldmap { width: 100%; height: 100%; max-height: none; background: #d8c48f; touch-action: none; user-select: none; cursor: grab; display: block; }
.map-controls { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 4px; align-items: center; z-index: 3; }
.map-controls button { width: 30px; height: 30px; border-radius: 6px; border: 1px solid #6b5a33; background: rgba(255,248,225,.92); color: #3b2f14; font-weight: 800; font-size: 16px; cursor: pointer; }
.map-controls button:hover { background: #fff; }
.map-help { font-size: 11px; color: #4a3d1e; background: rgba(255,248,225,.75); padding: 3px 8px; border-radius: 6px; }

.worldmap * { pointer-events: none; }
.worldmap .ocean { fill: #d8c48f; }
.worldmap .ocean-label { font-family: Georgia, 'Times New Roman', serif; font-style: italic; font-size: 26px; letter-spacing: .25em; fill: #7d6a3c; text-anchor: middle; opacity: .8; }
.worldmap .continent-halo { fill: none; stroke-width: 11; stroke-linejoin: round; stroke-opacity: .55; }
.worldmap .zone { fill: #b9a87a; fill-opacity: .55; stroke: #8a7a4e; stroke-width: 1; stroke-dasharray: 8 6; }
.worldmap .zone-label { font-family: Georgia, 'Times New Roman', serif; font-size: 18px; letter-spacing: .3em; fill: #5a4a26; text-anchor: middle; opacity: .8; }
.worldmap .ridge { fill: #3a2c17; stroke: #1e1710; stroke-width: .8; stroke-linejoin: round; }
.worldmap .ridge-snow { fill: #f2e7cc; opacity: .8; }
.worldmap .sea-route { stroke: #3b2f14; stroke-width: 1.6; stroke-dasharray: 6 5; stroke-opacity: .6; }

/* Territoires : couleur du continent ; le propriétaire se lit sur la pastille.
   Mise en évidence = contour épais + calque de teinte (.overlay) + halo lumineux + pulsation. */
.worldmap .territory path.shape { stroke: #2b2010; stroke-width: 0.9; fill-opacity: .9; }
.worldmap .territory path.overlay { fill: none; stroke: none; }
.worldmap .territory.hover path.overlay { fill: #fff; fill-opacity: .22; }
.worldmap .territory.hover path.shape { stroke: #fff; stroke-width: 2.4; }

.worldmap .territory.selected path.shape { stroke: #fff; stroke-width: 5; filter: drop-shadow(0 0 7px #fff) drop-shadow(0 0 14px #fff); }
.worldmap .territory.selected path.overlay { fill: #fff; fill-opacity: .45; }

.worldmap .territory.target path.shape { stroke: #ff2020; stroke-width: 5; filter: drop-shadow(0 0 8px #ff2020); }
.worldmap .territory.target path.overlay { fill: #ff2020; fill-opacity: .5; animation: pulse 1s ease-in-out infinite; }

.worldmap .territory.reachable path.shape { stroke: #16e05a; stroke-width: 5; filter: drop-shadow(0 0 8px #16e05a); }
.worldmap .territory.reachable path.overlay { fill: #16e05a; fill-opacity: .45; animation: pulse 1.2s ease-in-out infinite; }

.worldmap .territory.placeable path.shape { stroke: #fff; stroke-width: 3.5; filter: drop-shadow(0 0 6px #ffe680); }
.worldmap .territory.placeable path.overlay { fill: #ffe680; fill-opacity: .45; animation: pulse 1.4s ease-in-out infinite; }

.worldmap .territory.dim path.shape { fill-opacity: .35; }
.worldmap .territory.dim path.overlay { fill: #1e1710; fill-opacity: .35; }
@keyframes pulse { 50% { fill-opacity: .15; } }

.worldmap .badge circle.body { stroke: #1e1710; stroke-width: 1.8; }
.worldmap .badge circle.ring { display: none; fill: none; stroke: var(--accent); stroke-width: 3.5; }
.worldmap .badge text.troops { font-size: 15px; font-weight: 800; fill: #fff; text-anchor: middle; dominant-baseline: central; paint-order: stroke; stroke: rgba(20,14,6,.85); stroke-width: 2.5px; }
.worldmap .badge text.name { font-size: 10px; font-weight: 700; fill: #fff; text-anchor: middle; paint-order: stroke; stroke: rgba(30,20,8,.85); stroke-width: 2.6px; letter-spacing: .02em; }
.worldmap .badge.dim { opacity: .45; }
.worldmap .badge.selected circle.ring { display: block; stroke: #fff; }
.worldmap .badge.target circle.ring { display: block; stroke: #ff2020; stroke-dasharray: 6 4; animation: spin 3s linear infinite; }
.worldmap .badge.reachable circle.ring { display: block; stroke: #16e05a; stroke-dasharray: 6 4; animation: spin 3s linear infinite; }
.worldmap .badge.placeable circle.ring { display: block; stroke: #ffe680; stroke-dasharray: 3 4; }
.worldmap .badge.hover circle.body { stroke: var(--accent); stroke-width: 2.5; }
.worldmap .badge.flash circle.body { animation: flash .6s ease-out; }
.worldmap .crown-bonus { font-family: Georgia, serif; font-weight: 700; font-size: 24px; text-anchor: middle; fill: #2b2010; }
.worldmap .crown-name { font-family: Georgia, serif; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; fill: #3b2f14; text-anchor: middle; }
.worldmap .laurel { fill: #2b2010; stroke: #2b2010; opacity: .85; }
.worldmap .laurel-branch { fill: none; stroke-width: 1.6; }
@keyframes spin { to { stroke-dashoffset: -90; } }
@keyframes flash { 0% { stroke: #fff; stroke-width: 8; } 100% { stroke-width: 1.6; } }

@media (max-width: 1000px) {
  .bottom { height: 48vh; flex-direction: column; overflow-y: auto; }
  .panels { flex-wrap: wrap; flex: none; }
  .panels .panel { flex: 1 1 45%; max-height: 220px; }
  .panels .panel.phase { flex: 1 1 100%; }
  .chat { width: auto; height: 260px; flex-shrink: 0; border-left: 0; border-top: 1px solid var(--line); }
}
